2 * Copyright (c) 2007 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 /***********************************************************************
26 * OS portability layer.
27 **********************************************************************/
32 #include <TargetConditionals.h>
33 #include "objc-config.h"
36 # define WORD_SHIFT 3UL
37 # define WORD_MASK 7UL
40 # define WORD_SHIFT 2UL
41 # define WORD_MASK 3UL
45 static inline uint32_t word_align(uint32_t x
) {
46 return (x
+ WORD_MASK
) & ~WORD_MASK
;
48 static inline size_t word_align(size_t x
) {
49 return (x
+ WORD_MASK
) & ~WORD_MASK
;
54 # ifndef __STDC_LIMIT_MACROS
55 # define __STDC_LIMIT_MACROS
72 # include <crt_externs.h>
73 # include <AssertMacros.h>
75 # include <Availability.h>
76 # include <TargetConditionals.h>
77 # include <sys/mman.h>
78 # include <sys/time.h>
79 # include <sys/stat.h>
80 # include <sys/param.h>
81 # include <mach/mach.h>
82 # include <mach/vm_param.h>
83 # include <mach-o/dyld.h>
84 # include <mach-o/ldsyms.h>
85 # include <mach-o/loader.h>
86 # include <mach-o/getsect.h>
87 # include <mach-o/dyld_priv.h>
88 # include <malloc/malloc.h>
89 # include <os/lock_private.h>
90 # include <libkern/OSAtomic.h>
91 # include <libkern/OSCacheControl.h>
92 # include <System/pthread_machdep.h>
93 # include "objc-probes.h" // generated dtrace probe definitions.
95 // Some libc functions call objc_msgSend()
96 // so we can't use them without deadlocks.
97 void syslog(int, const char *, ...) UNAVAILABLE_ATTRIBUTE
;
98 void vsyslog(int, const char *, va_list) UNAVAILABLE_ATTRIBUTE
;
101 #define ALWAYS_INLINE inline __attribute__((always_inline))
102 #define NEVER_INLINE inline __attribute__((noinline))
106 static ALWAYS_INLINE
uintptr_t
107 addc(uintptr_t lhs
, uintptr_t rhs
, uintptr_t carryin
, uintptr_t *carryout
)
109 return __builtin_addcl(lhs
, rhs
, carryin
, carryout
);
112 static ALWAYS_INLINE
uintptr_t
113 subc(uintptr_t lhs
, uintptr_t rhs
, uintptr_t carryin
, uintptr_t *carryout
)
115 return __builtin_subcl(lhs
, rhs
, carryin
, carryout
);
123 LoadExclusive(uintptr_t *src
)
126 asm("ldxr %x0, [%x1]"
128 : "r" (src
), "m" (*src
));
134 StoreExclusive(uintptr_t *dst
, uintptr_t oldvalue __unused
, uintptr_t value
)
137 asm("stxr %w0, %x2, [%x3]"
138 : "=r" (result
), "=m" (*dst
)
139 : "r" (value
), "r" (dst
));
146 StoreReleaseExclusive(uintptr_t *dst
, uintptr_t oldvalue __unused
, uintptr_t value
)
149 asm("stlxr %w0, %x2, [%x3]"
150 : "=r" (result
), "=m" (*dst
)
151 : "r" (value
), "r" (dst
));
160 LoadExclusive(uintptr_t *src
)
167 StoreExclusive(uintptr_t *dst
, uintptr_t oldvalue
, uintptr_t value
)
169 return OSAtomicCompareAndSwapPtr((void *)oldvalue
, (void *)value
,
175 StoreReleaseExclusive(uintptr_t *dst
, uintptr_t oldvalue
, uintptr_t value
)
177 return OSAtomicCompareAndSwapPtrBarrier((void *)oldvalue
, (void *)value
,
182 #elif __x86_64__ || __i386__
186 LoadExclusive(uintptr_t *src
)
193 StoreExclusive(uintptr_t *dst
, uintptr_t oldvalue
, uintptr_t value
)
196 return __sync_bool_compare_and_swap((void **)dst
, (void *)oldvalue
, (void *)value
);
201 StoreReleaseExclusive(uintptr_t *dst
, uintptr_t oldvalue
, uintptr_t value
)
203 return StoreExclusive(dst
, oldvalue
, value
);
207 # error unknown architecture
211 #define spinlock_t os_lock_handoff_s
212 #define spinlock_trylock(l) os_lock_trylock(l)
213 #define spinlock_lock(l) os_lock_lock(l)
214 #define spinlock_unlock(l) os_lock_unlock(l)
215 #define SPINLOCK_INITIALIZER OS_LOCK_HANDOFF_INIT
218 #if !TARGET_OS_IPHONE
219 # include <CrashReporterClient.h>
221 // CrashReporterClient not yet available on iOS
223 extern const char *CRSetCrashLogMessage(const char *msg
);
224 extern const char *CRGetCrashLogMessage(void);
225 extern const char *CRSetCrashLogMessage2(const char *msg
);
231 # include <algorithm>
232 # include <functional>
236 # define PRIVATE_EXTERN __attribute__((visibility("hidden")))
237 # undef __private_extern__
238 # define __private_extern__ use_PRIVATE_EXTERN_instead
239 # undef private_extern
240 # define private_extern use_PRIVATE_EXTERN_instead
242 /* Use this for functions that are intended to be breakpoint hooks.
243 If you do not, the compiler may optimize them away.
244 BREAKPOINT_FUNCTION( void stop_on_error(void) ); */
245 # define BREAKPOINT_FUNCTION(prototype) \
246 OBJC_EXTERN __attribute__((noinline, used, visibility("hidden"))) \
247 prototype { asm(""); }
249 #elif TARGET_OS_WIN32
251 # define WINVER 0x0501 // target Windows XP and later
252 # define _WIN32_WINNT 0x0501 // target Windows XP and later
253 # define WIN32_LEAN_AND_MEAN
254 // hack: windef.h typedefs BOOL as int
255 # define BOOL WINBOOL
256 # include <windows.h>
266 # include <Availability.h>
270 # include <algorithm>
271 # include <functional>
273 # define __BEGIN_DECLS extern "C" {
274 # define __END_DECLS }
276 # define __BEGIN_DECLS /*empty*/
277 # define __END_DECLS /*empty*/
280 # define PRIVATE_EXTERN
281 # define __attribute__(x)
282 # define inline __inline
284 /* Use this for functions that are intended to be breakpoint hooks.
285 If you do not, the compiler may optimize them away.
286 BREAKPOINT_FUNCTION( void MyBreakpointFunction(void) ); */
287 # define BREAKPOINT_FUNCTION(prototype) \
288 __declspec(noinline) prototype { __asm { } }
290 /* stub out dtrace probes */
291 # define OBJC_RUNTIME_OBJC_EXCEPTION_RETHROW() do {} while(0)
292 # define OBJC_RUNTIME_OBJC_EXCEPTION_THROW(arg0) do {} while(0)
299 #include <objc/objc.h>
300 #include <objc/objc-api.h>
304 extern void _objc_fatal(const char *fmt
, ...) __attribute__((noreturn
, format (printf
, 1, 2)));
306 #define INIT_ONCE_PTR(var, create, delete) \
309 typeof(var) v = create; \
311 if (OSAtomicCompareAndSwapPtrBarrier(0, (void*)v, (void**)&var)){ \
319 #define INIT_ONCE_32(var, create, delete) \
322 typeof(var) v = create; \
324 if (OSAtomicCompareAndSwap32Barrier(0, v, (volatile int32_t *)&var)) { \
333 // Thread keys reserved by libc for our use.
334 // Keys [0..4] are used by autozone.
335 #if defined(__PTK_FRAMEWORK_OBJC_KEY5)
336 # define SUPPORT_DIRECT_THREAD_KEYS 1
337 # define TLS_DIRECT_KEY ((tls_key_t)__PTK_FRAMEWORK_OBJC_KEY5)
338 # define SYNC_DATA_DIRECT_KEY ((tls_key_t)__PTK_FRAMEWORK_OBJC_KEY6)
339 # define SYNC_COUNT_DIRECT_KEY ((tls_key_t)__PTK_FRAMEWORK_OBJC_KEY7)
340 # define AUTORELEASE_POOL_KEY ((tls_key_t)__PTK_FRAMEWORK_OBJC_KEY8)
341 # if SUPPORT_RETURN_AUTORELEASE
342 # define AUTORELEASE_POOL_RECLAIM_KEY ((tls_key_t)__PTK_FRAMEWORK_OBJC_KEY9)
345 # define SUPPORT_DIRECT_THREAD_KEYS 0
351 // Compiler compatibility
355 #define strdup _strdup
357 #define issetugid() 0
359 #define MIN(x, y) ((x) < (y) ? (x) : (y))
361 static __inline
void bcopy(const void *src
, void *dst
, size_t size
) { memcpy(dst
, src
, size
); }
362 static __inline
void bzero(void *dst
, size_t size
) { memset(dst
, 0, size
); }
364 int asprintf(char **dstp
, const char *format
, ...);
366 typedef void * malloc_zone_t
;
368 static __inline malloc_zone_t
malloc_default_zone(void) { return (malloc_zone_t
)-1; }
369 static __inline
void *malloc_zone_malloc(malloc_zone_t z
, size_t size
) { return malloc(size
); }
370 static __inline
void *malloc_zone_calloc(malloc_zone_t z
, size_t size
, size_t count
) { return calloc(size
, count
); }
371 static __inline
void *malloc_zone_realloc(malloc_zone_t z
, void *p
, size_t size
) { return realloc(p
, size
); }
372 static __inline
void malloc_zone_free(malloc_zone_t z
, void *p
) { free(p
); }
373 static __inline malloc_zone_t
malloc_zone_from_ptr(const void *p
) { return (malloc_zone_t
)-1; }
374 static __inline
size_t malloc_size(const void *p
) { return _msize((void*)p
); /* fixme invalid pointer check? */ }
379 #define require_action_string(cond, dest, act, msg) do { if (!(cond)) { { act; } goto dest; } } while (0)
380 #define require_noerr_string(err, dest, msg) do { if (err) goto dest; } while (0)
381 #define require_string(cond, dest, msg) do { if (!(cond)) goto dest; } while (0)
386 static __inline BOOL
OSAtomicCompareAndSwapLong(long oldl
, long newl
, long volatile *dst
)
388 // fixme barrier is overkill
389 long original
= InterlockedCompareExchange(dst
, newl
, oldl
);
390 return (original
== oldl
);
393 static __inline BOOL
OSAtomicCompareAndSwapPtrBarrier(void *oldp
, void *newp
, void * volatile *dst
)
395 void *original
= InterlockedCompareExchangePointer(dst
, newp
, oldp
);
396 return (original
== oldp
);
399 static __inline BOOL
OSAtomicCompareAndSwap32Barrier(int32_t oldl
, int32_t newl
, int32_t volatile *dst
)
401 long original
= InterlockedCompareExchange((volatile long *)dst
, newl
, oldl
);
402 return (original
== oldl
);
405 static __inline
int32_t OSAtomicDecrement32Barrier(volatile int32_t *dst
)
407 return InterlockedDecrement((volatile long *)dst
);
410 static __inline
int32_t OSAtomicIncrement32Barrier(volatile int32_t *dst
)
412 return InterlockedIncrement((volatile long *)dst
);
416 // Internal data types
418 typedef DWORD objc_thread_t
; // thread ID
419 static __inline
int thread_equal(objc_thread_t t1
, objc_thread_t t2
) {
422 static __inline objc_thread_t
thread_self(void) {
423 return GetCurrentThreadId();
428 void (*dtor
)(void *);
430 static __inline tls_key_t
tls_create(void (*dtor
)(void*)) {
431 // fixme need dtor registry for DllMain to call on thread detach
437 static __inline
void *tls_get(tls_key_t k
) {
438 return TlsGetValue(k
.key
);
440 static __inline
void tls_set(tls_key_t k
, void *value
) {
441 TlsSetValue(k
.key
, value
);
445 CRITICAL_SECTION
*lock
;
447 #define MUTEX_INITIALIZER {0};
448 extern void mutex_init(mutex_t
*m
);
449 static __inline
int _mutex_lock_nodebug(mutex_t
*m
) {
454 EnterCriticalSection(m
->lock
);
457 static __inline
bool _mutex_try_lock_nodebug(mutex_t
*m
) {
462 return TryEnterCriticalSection(m
->lock
);
464 static __inline
int _mutex_unlock_nodebug(mutex_t
*m
) {
466 LeaveCriticalSection(m
->lock
);
471 typedef mutex_t spinlock_t
;
472 #define spinlock_lock(l) mutex_lock(l)
473 #define spinlock_unlock(l) mutex_unlock(l)
474 #define SPINLOCK_INITIALIZER MUTEX_INITIALIZER
480 #define RECURSIVE_MUTEX_INITIALIZER {0};
481 #define RECURSIVE_MUTEX_NOT_LOCKED 1
482 extern void recursive_mutex_init(recursive_mutex_t
*m
);
483 static __inline
int _recursive_mutex_lock_nodebug(recursive_mutex_t
*m
) {
485 return WaitForSingleObject(m
->mutex
, INFINITE
);
487 static __inline
bool _recursive_mutex_try_lock_nodebug(recursive_mutex_t
*m
) {
489 return (WAIT_OBJECT_0
== WaitForSingleObject(m
->mutex
, 0));
491 static __inline
int _recursive_mutex_unlock_nodebug(recursive_mutex_t
*m
) {
493 return ReleaseMutex(m
->mutex
) ? 0 : RECURSIVE_MUTEX_NOT_LOCKED
;
498 typedef HANDLE mutex_t;
499 static inline void mutex_init(HANDLE *m) { *m = CreateMutex(NULL, FALSE, NULL); }
500 static inline void _mutex_lock(mutex_t *m) { WaitForSingleObject(*m, INFINITE); }
501 static inline bool mutex_try_lock(mutex_t *m) { return WaitForSingleObject(*m, 0) == WAIT_OBJECT_0; }
502 static inline void _mutex_unlock(mutex_t *m) { ReleaseMutex(*m); }
505 // based on http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
506 // Vista-only CONDITION_VARIABLE would be better
509 HANDLE waiters
; // semaphore for those in cond_wait()
510 HANDLE waitersDone
; // auto-reset event after everyone gets a broadcast
511 CRITICAL_SECTION waitCountLock
; // guards waitCount and didBroadcast
512 unsigned int waitCount
;
515 #define MONITOR_INITIALIZER { 0 }
516 #define MONITOR_NOT_ENTERED 1
517 extern int monitor_init(monitor_t
*c
);
519 static inline int _monitor_enter_nodebug(monitor_t
*c
) {
521 int err
= monitor_init(c
);
524 return WaitForSingleObject(c
->mutex
, INFINITE
);
526 static inline int _monitor_exit_nodebug(monitor_t
*c
) {
527 if (!ReleaseMutex(c
->mutex
)) return MONITOR_NOT_ENTERED
;
530 static inline int _monitor_wait_nodebug(monitor_t
*c
) {
532 EnterCriticalSection(&c
->waitCountLock
);
534 LeaveCriticalSection(&c
->waitCountLock
);
536 SignalObjectAndWait(c
->mutex
, c
->waiters
, INFINITE
, FALSE
);
538 EnterCriticalSection(&c
->waitCountLock
);
540 last
= c
->didBroadcast
&& c
->waitCount
== 0;
541 LeaveCriticalSection(&c
->waitCountLock
);
544 // tell broadcaster that all waiters have awoken
545 SignalObjectAndWait(c
->waitersDone
, c
->mutex
, INFINITE
, FALSE
);
547 WaitForSingleObject(c
->mutex
, INFINITE
);
550 // fixme error checking
553 static inline int monitor_notify(monitor_t
*c
) {
556 EnterCriticalSection(&c
->waitCountLock
);
557 haveWaiters
= c
->waitCount
> 0;
558 LeaveCriticalSection(&c
->waitCountLock
);
561 ReleaseSemaphore(c
->waiters
, 1, 0);
564 // fixme error checking
567 static inline int monitor_notifyAll(monitor_t
*c
) {
568 EnterCriticalSection(&c
->waitCountLock
);
569 if (c
->waitCount
== 0) {
570 LeaveCriticalSection(&c
->waitCountLock
);
574 ReleaseSemaphore(c
->waiters
, c
->waitCount
, 0);
575 LeaveCriticalSection(&c
->waitCountLock
);
577 // fairness: wait for everyone to move from waiters to mutex
578 WaitForSingleObject(c
->waitersDone
, INFINITE
);
579 // not under waitCountLock, but still under mutex
582 // fixme error checking
587 // fixme no rwlock yet
589 #define rwlock_t mutex_t
590 #define rwlock_init(r) mutex_init(r)
591 #define _rwlock_read_nodebug(m) _mutex_lock_nodebug(m)
592 #define _rwlock_write_nodebug(m) _mutex_lock_nodebug(m)
593 #define _rwlock_try_read_nodebug(m) _mutex_try_lock_nodebug(m)
594 #define _rwlock_try_write_nodebug(m) _mutex_try_lock_nodebug(m)
595 #define _rwlock_unlock_read_nodebug(m) _mutex_unlock_nodebug(m)
596 #define _rwlock_unlock_write_nodebug(m) _mutex_unlock_nodebug(m)
599 typedef IMAGE_DOS_HEADER headerType
;
600 // fixme YES bundle? NO bundle? sometimes?
601 #define headerIsBundle(hi) YES
602 OBJC_EXTERN IMAGE_DOS_HEADER __ImageBase
;
603 #define libobjc_header ((headerType *)&__ImageBase)
612 #include <mach-o/loader.h>
614 # define SEGMENT_CMD LC_SEGMENT
616 # define SEGMENT_CMD LC_SEGMENT_64
619 #ifndef VM_MEMORY_OBJC_DISPATCHERS
620 # define VM_MEMORY_OBJC_DISPATCHERS 0
624 // Compiler compatibility
628 // Internal data types
630 typedef pthread_t objc_thread_t
;
632 static __inline
int thread_equal(objc_thread_t t1
, objc_thread_t t2
) {
633 return pthread_equal(t1
, t2
);
635 static __inline objc_thread_t
thread_self(void) {
636 return pthread_self();
640 typedef pthread_key_t tls_key_t
;
642 static inline tls_key_t
tls_create(void (*dtor
)(void*)) {
644 pthread_key_create(&k
, dtor
);
647 static inline void *tls_get(tls_key_t k
) {
648 return pthread_getspecific(k
);
650 static inline void tls_set(tls_key_t k
, void *value
) {
651 pthread_setspecific(k
, value
);
654 #if SUPPORT_DIRECT_THREAD_KEYS
657 static bool is_valid_direct_key(tls_key_t k
) {
658 return ( k
== SYNC_DATA_DIRECT_KEY
659 || k
== SYNC_COUNT_DIRECT_KEY
660 || k
== AUTORELEASE_POOL_KEY
661 # if SUPPORT_RETURN_AUTORELEASE
662 || k
== AUTORELEASE_POOL_RECLAIM_KEY
670 // rdar://9162780 _pthread_get/setspecific_direct are inefficient
671 // copied from libdispatch
673 __attribute__((const))
674 static ALWAYS_INLINE
void**
678 #if defined(__arm__) && defined(_ARM_ARCH_6)
679 __asm__("mrc p15, 0, %[p], c13, c0, 3" : [p
] "=&r" (p
));
680 return (void**)(p
& ~0x3ul
);
682 #error tls_base not implemented
687 static ALWAYS_INLINE
void
688 tls_set_direct(void **tsdb
, tls_key_t k
, void *v
)
690 assert(is_valid_direct_key(k
));
694 #define tls_set_direct(k, v) \
695 tls_set_direct(tls_base(), (k), (v))
698 static ALWAYS_INLINE
void *
699 tls_get_direct(void **tsdb
, tls_key_t k
)
701 assert(is_valid_direct_key(k
));
705 #define tls_get_direct(k) \
706 tls_get_direct(tls_base(), (k))
712 static inline void *tls_get_direct(tls_key_t k
)
714 assert(is_valid_direct_key(k
));
716 if (_pthread_has_direct_tsd()) {
717 return _pthread_getspecific_direct(k
);
719 return pthread_getspecific(k
);
722 static inline void tls_set_direct(tls_key_t k
, void *value
)
724 assert(is_valid_direct_key(k
));
726 if (_pthread_has_direct_tsd()) {
727 _pthread_setspecific_direct(k
, value
);
729 pthread_setspecific(k
, value
);
736 // SUPPORT_DIRECT_THREAD_KEYS
740 typedef pthread_mutex_t mutex_t
;
741 #define MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER;
743 static inline int _mutex_lock_nodebug(mutex_t
*m
) {
744 return pthread_mutex_lock(m
);
746 static inline bool _mutex_try_lock_nodebug(mutex_t
*m
) {
747 return !pthread_mutex_trylock(m
);
749 static inline int _mutex_unlock_nodebug(mutex_t
*m
) {
750 return pthread_mutex_unlock(m
);
755 pthread_mutex_t
*mutex
;
757 #define RECURSIVE_MUTEX_INITIALIZER {0};
758 #define RECURSIVE_MUTEX_NOT_LOCKED EPERM
759 extern void recursive_mutex_init(recursive_mutex_t
*m
);
761 static inline int _recursive_mutex_lock_nodebug(recursive_mutex_t
*m
) {
763 return pthread_mutex_lock(m
->mutex
);
765 static inline bool _recursive_mutex_try_lock_nodebug(recursive_mutex_t
*m
) {
767 return !pthread_mutex_trylock(m
->mutex
);
769 static inline int _recursive_mutex_unlock_nodebug(recursive_mutex_t
*m
) {
771 return pthread_mutex_unlock(m
->mutex
);
776 pthread_mutex_t mutex
;
779 #define MONITOR_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER }
780 #define MONITOR_NOT_ENTERED EPERM
782 static inline int monitor_init(monitor_t
*c
) {
783 int err
= pthread_mutex_init(&c
->mutex
, NULL
);
785 err
= pthread_cond_init(&c
->cond
, NULL
);
787 pthread_mutex_destroy(&c
->mutex
);
792 static inline int _monitor_enter_nodebug(monitor_t
*c
) {
793 return pthread_mutex_lock(&c
->mutex
);
795 static inline int _monitor_exit_nodebug(monitor_t
*c
) {
796 return pthread_mutex_unlock(&c
->mutex
);
798 static inline int _monitor_wait_nodebug(monitor_t
*c
) {
799 return pthread_cond_wait(&c
->cond
, &c
->mutex
);
801 static inline int monitor_notify(monitor_t
*c
) {
802 return pthread_cond_signal(&c
->cond
);
804 static inline int monitor_notifyAll(monitor_t
*c
) {
805 return pthread_cond_broadcast(&c
->cond
);
809 // semaphore_create formatted for INIT_ONCE use
810 static inline semaphore_t
create_semaphore(void)
814 k
= semaphore_create(mach_task_self(), &sem
, SYNC_POLICY_FIFO
, 0);
815 if (k
) _objc_fatal("semaphore_create failed (0x%x)", k
);
820 /* Custom read-write lock
821 - reader is atomic add/subtract
822 - writer is pthread mutex plus atomic add/subtract
823 - fairness: new readers wait if a writer wants in
824 - fairness: when writer completes, readers (probably) precede new writer
826 state: xxxxxxxx xxxxxxxx yyyyyyyy yyyyyyyz
827 x: blocked reader count
828 y: active reader count
829 z: readers allowed flag
832 pthread_rwlock_t rwl
;
835 static inline void rwlock_init(rwlock_t
*l
)
837 int err __unused
= pthread_rwlock_init(&l
->rwl
, NULL
);
841 static inline void _rwlock_read_nodebug(rwlock_t
*l
)
843 int err __unused
= pthread_rwlock_rdlock(&l
->rwl
);
847 static inline void _rwlock_unlock_read_nodebug(rwlock_t
*l
)
849 int err __unused
= pthread_rwlock_unlock(&l
->rwl
);
854 static inline bool _rwlock_try_read_nodebug(rwlock_t
*l
)
856 int err
= pthread_rwlock_tryrdlock(&l
->rwl
);
857 assert(err
== 0 || err
== EBUSY
);
862 static inline void _rwlock_write_nodebug(rwlock_t
*l
)
864 int err __unused
= pthread_rwlock_wrlock(&l
->rwl
);
868 static inline void _rwlock_unlock_write_nodebug(rwlock_t
*l
)
870 int err __unused
= pthread_rwlock_unlock(&l
->rwl
);
874 static inline bool _rwlock_try_write_nodebug(rwlock_t
*l
)
876 int err
= pthread_rwlock_trywrlock(&l
->rwl
);
877 assert(err
== 0 || err
== EBUSY
);
883 typedef struct mach_header headerType
;
884 typedef struct segment_command segmentType
;
885 typedef struct section sectionType
;
887 typedef struct mach_header_64 headerType
;
888 typedef struct segment_command_64 segmentType
;
889 typedef struct section_64 sectionType
;
891 #define headerIsBundle(hi) (hi->mhdr->filetype == MH_BUNDLE)
892 #define libobjc_header ((headerType *)&_mh_dylib_header)
896 /* Secure /tmp usage */
897 extern int secure_open(const char *filename
, int flags
, uid_t euid
);