- // unused, purely for detecting copied mutexes and smashes during debugging:
- mutex->reserved2[0] = ~(uintptr_t)mutex; // use ~ to hide from leaks
- mutex->reserved2[1] = (uintptr_t)sig;
+#if PTHREAD_MUTEX_INIT_UNUSED
+ // For detecting copied mutexes and smashes during debugging
+ uint32_t sig32 = (uint32_t)sig;
+#if defined(__LP64__)
+ uintptr_t guard = ~(uintptr_t)mutex; // use ~ to hide from leaks
+ __builtin_memcpy(mutex->_reserved, &guard, sizeof(guard));
+ mutex->_reserved[2] = sig32;
+ mutex->_reserved[3] = sig32;
+ mutex->_pad = sig32;
+#else
+ mutex->_reserved[0] = sig32;
+#endif
+#endif // PTHREAD_MUTEX_INIT_UNUSED