2 * Copyright (c) 2008-2013 Apple Inc. All rights reserved.
4 * @APPLE_APACHE_LICENSE_HEADER_START@
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * @APPLE_APACHE_LICENSE_HEADER_END@
22 * IMPORTANT: This header file describes INTERNAL interfaces to libdispatch
23 * which are subject to change in future releases of Mac OS X. Any applications
24 * relying on these interfaces WILL break.
27 #ifndef __DISPATCH_INTERNAL__
28 #define __DISPATCH_INTERNAL__
30 #include <config/config.h>
32 #define __DISPATCH_BUILDING_DISPATCH__
33 #define __DISPATCH_INDIRECT__
36 #include <Availability.h>
37 #include <TargetConditionals.h>
41 #if !defined(DISPATCH_MACH_SPI) && TARGET_OS_MAC
42 #define DISPATCH_MACH_SPI 1
44 #if !defined(OS_VOUCHER_CREATION_SPI) && TARGET_OS_MAC
45 #define OS_VOUCHER_CREATION_SPI 1
47 #if !defined(OS_VOUCHER_ACTIVITY_SPI) && TARGET_OS_MAC
48 #define OS_VOUCHER_ACTIVITY_SPI 1
50 #if !defined(OS_VOUCHER_ACTIVITY_BUFFER_SPI) && TARGET_OS_MAC && \
51 __has_include(<atm/atm_types.h>)
52 #define OS_VOUCHER_ACTIVITY_BUFFER_SPI 1
54 #if !defined(DISPATCH_LAYOUT_SPI) && TARGET_OS_MAC
55 #define DISPATCH_LAYOUT_SPI 1
58 #if !defined(USE_OBJC) && HAVE_OBJC
62 #if USE_OBJC && ((!TARGET_IPHONE_SIMULATOR && defined(__i386__)) || \
63 (!TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED < 1080))
64 // Disable Objective-C support on platforms with legacy objc runtime
70 #define OS_OBJECT_HAVE_OBJC_SUPPORT 1
72 #define OS_OBJECT_USE_OBJC 1
74 #define OS_OBJECT_USE_OBJC 0
77 #define OS_OBJECT_HAVE_OBJC_SUPPORT 0
80 #include <dispatch/dispatch.h>
81 #include <dispatch/base.h>
84 #include <os/object.h>
85 #include <dispatch/time.h>
86 #include <dispatch/object.h>
87 #include <dispatch/queue.h>
88 #include <dispatch/block.h>
89 #include <dispatch/source.h>
90 #include <dispatch/group.h>
91 #include <dispatch/semaphore.h>
92 #include <dispatch/once.h>
93 #include <dispatch/data.h>
95 #include <dispatch/io.h>
98 #define DISPATCH_STRUCT_DECL(type, name, ...) \
99 struct type __VA_ARGS__ name
101 // Visual Studio C++ does not support C99 designated initializers.
102 // This means that static declarations should be zero initialized and cannot
103 // be const since we must fill in the values during DLL initialization.
105 #define DISPATCH_STRUCT_INSTANCE(type, name, ...) \
106 struct type name = { \
110 #define DISPATCH_STRUCT_INSTANCE(type, name, ...) \
111 struct type name = { 0 }
115 #define DISPATCH_CONST_STRUCT_DECL(type, name, ...) \
116 const DISPATCH_STRUCT_DECL(type, name, __VA_ARGS__)
118 #define DISPATCH_CONST_STRUCT_INSTANCE(type, name, ...) \
119 const DISPATCH_STRUCT_INSTANCE(type, name, __VA_ARGS__)
121 #define DISPATCH_CONST_STRUCT_DECL(type, name, ...) \
122 DISPATCH_STRUCT_DECL(type, name, __VA_ARGS__)
124 #define DISPATCH_CONST_STRUCT_INSTANCE(type, name, ...) \
125 DISPATCH_STRUCT_INSTANCE(type, name, __VA_ARGS__)
128 /* private.h must be included last to avoid picking up installed headers. */
129 #include "object_private.h"
130 #include "queue_private.h"
131 #include "source_private.h"
132 #include "mach_private.h"
133 #include "data_private.h"
135 #include "io_private.h"
137 #include "voucher_private.h"
138 #include "voucher_activity_private.h"
139 #include "layout_private.h"
140 #include "benchmark.h"
143 /* SPI for Libsystem-internal use */
144 DISPATCH_EXPORT DISPATCH_NOTHROW
void libdispatch_init(void);
146 DISPATCH_EXPORT DISPATCH_NOTHROW
void dispatch_atfork_prepare(void);
147 DISPATCH_EXPORT DISPATCH_NOTHROW
void dispatch_atfork_parent(void);
148 DISPATCH_EXPORT DISPATCH_NOTHROW
void dispatch_atfork_child(void);
151 /* More #includes at EOF (dependent on the contents of internal.h) ... */
153 // Abort on uncaught exceptions thrown from client callouts rdar://8577499
154 #if !defined(DISPATCH_USE_CLIENT_CALLOUT)
155 #define DISPATCH_USE_CLIENT_CALLOUT 1
158 /* The "_debug" library build */
159 #ifndef DISPATCH_DEBUG
160 #define DISPATCH_DEBUG 0
163 #ifndef DISPATCH_PROFILE
164 #define DISPATCH_PROFILE 0
167 #if (!TARGET_OS_EMBEDDED || DISPATCH_DEBUG || DISPATCH_PROFILE) && \
168 !defined(DISPATCH_USE_DTRACE)
169 #define DISPATCH_USE_DTRACE 1
172 #if DISPATCH_USE_DTRACE && (DISPATCH_INTROSPECTION || DISPATCH_DEBUG || \
173 DISPATCH_PROFILE) && !defined(DISPATCH_USE_DTRACE_INTROSPECTION)
174 #define DISPATCH_USE_DTRACE_INTROSPECTION 1
177 #if HAVE_LIBKERN_OSCROSSENDIAN_H
178 #include <libkern/OSCrossEndian.h>
180 #if HAVE_LIBKERN_OSATOMIC_H
181 #include <libkern/OSAtomic.h>
184 #include <mach/boolean.h>
185 #include <mach/clock_types.h>
186 #include <mach/clock.h>
187 #include <mach/exception.h>
188 #include <mach/mach.h>
189 #include <mach/mach_error.h>
190 #include <mach/mach_host.h>
191 #include <mach/mach_interface.h>
192 #include <mach/mach_time.h>
193 #include <mach/mach_traps.h>
194 #include <mach/message.h>
195 #include <mach/mig_errors.h>
196 #include <mach/host_special_ports.h>
197 #include <mach/host_info.h>
198 #include <mach/notify.h>
199 #include <mach/mach_vm.h>
200 #include <mach/vm_map.h>
201 #endif /* HAVE_MACH */
202 #if HAVE_MALLOC_MALLOC_H
203 #include <malloc/malloc.h>
206 #include <sys/stat.h>
209 #include <sys/event.h>
210 #include <sys/mount.h>
211 #include <sys/queue.h>
212 #include <sys/sysctl.h>
213 #include <sys/socket.h>
214 #include <sys/time.h>
215 #include <sys/mman.h>
216 #include <netinet/in.h>
218 #include "sys_queue.h"
222 #include <Block_private.h>
224 #endif /* __BLOCKS__ */
234 #include <semaphore.h>
247 #ifndef __has_builtin
248 #define __has_builtin(x) 0
250 #ifndef __has_include
251 #define __has_include(x) 0
253 #ifndef __has_feature
254 #define __has_feature(x) 0
256 #ifndef __has_attribute
257 #define __has_attribute(x) 0
261 #define DISPATCH_NOINLINE __attribute__((__noinline__))
262 #define DISPATCH_USED __attribute__((__used__))
263 #define DISPATCH_UNUSED __attribute__((__unused__))
264 #define DISPATCH_WEAK __attribute__((__weak__))
265 #define DISPATCH_OVERLOADABLE __attribute__((__overloadable__))
267 #define DISPATCH_ALWAYS_INLINE_NDEBUG
269 #define DISPATCH_ALWAYS_INLINE_NDEBUG __attribute__((__always_inline__))
272 #define DISPATCH_NOINLINE
273 #define DISPATCH_USED
274 #define DISPATCH_UNUSED
275 #define DISPATCH_WEAK
276 #define DISPATCH_ALWAYS_INLINE_NDEBUG
277 #endif /* __GNUC__ */
279 #define DISPATCH_CONCAT(x,y) DISPATCH_CONCAT1(x,y)
280 #define DISPATCH_CONCAT1(x,y) x ## y
282 // workaround 6368156
292 #define NSEC_PER_SEC 1000000000ull
293 #define USEC_PER_SEC 1000000ull
294 #define NSEC_PER_USEC 1000ull
296 /* I wish we had __builtin_expect_range() */
298 #define fastpath(x) ((typeof(x))__builtin_expect((long)(x), ~0l))
299 #define slowpath(x) ((typeof(x))__builtin_expect((long)(x), 0l))
301 #define fastpath(x) (x)
302 #define slowpath(x) (x)
306 void _dispatch_bug(size_t line
, long val
);
310 void _dispatch_bug_client(const char* msg
);
312 void _dispatch_bug_mach_client(const char *msg
, mach_msg_return_t kr
);
314 void _dispatch_bug_kevent_client(const char* msg
, const char* filter
,
315 const char *operation
, int err
);
318 DISPATCH_NOINLINE DISPATCH_NORETURN
319 void _dispatch_abort(size_t line
, long val
);
321 #if !defined(DISPATCH_USE_OS_DEBUG_LOG) && DISPATCH_DEBUG
322 #if __has_include(<os/debug_private.h>)
323 #define DISPATCH_USE_OS_DEBUG_LOG 1
324 #include <os/debug_private.h>
326 #endif // DISPATCH_USE_OS_DEBUG_LOG
328 #if !defined(DISPATCH_USE_SIMPLE_ASL) && !DISPATCH_USE_OS_DEBUG_LOG
329 #if __has_include(<_simple.h>)
330 #define DISPATCH_USE_SIMPLE_ASL 1
333 #endif // DISPATCH_USE_SIMPLE_ASL
335 #if !DISPATCH_USE_SIMPLE_ASL && !DISPATCH_USE_OS_DEBUG_LOG && !TARGET_OS_WIN32
339 #if DISPATCH_USE_OS_DEBUG_LOG
340 #define _dispatch_log(msg, ...) os_debug_log("libdispatch", msg, ## __VA_ARGS__)
342 DISPATCH_NOINLINE
__attribute__((__format__(__printf__
,1,2)))
343 void _dispatch_log(const char *msg
, ...);
344 #endif // DISPATCH_USE_OS_DEBUG_LOG
346 #define dsnprintf(...) \
347 ({ int _r = snprintf(__VA_ARGS__); _r < 0 ? 0u : (size_t)_r; })
350 * For reporting bugs within libdispatch when using the "_debug" version of the
354 #define dispatch_assert(e) do { \
355 if (__builtin_constant_p(e)) { \
356 char __compile_time_assert__[(bool)(e) ? 1 : -1] DISPATCH_UNUSED; \
358 typeof(e) _e = fastpath(e); /* always eval 'e' */ \
359 if (DISPATCH_DEBUG && !_e) { \
360 _dispatch_abort(__LINE__, (long)_e); \
365 static inline void _dispatch_assert(long e
, long line
) {
366 if (DISPATCH_DEBUG
&& !e
) _dispatch_abort(line
, e
);
368 #define dispatch_assert(e) _dispatch_assert((long)(e), __LINE__)
369 #endif /* __GNUC__ */
373 * A lot of API return zero upon success and not-zero on fail. Let's capture
374 * and log the non-zero value
376 #define dispatch_assert_zero(e) do { \
377 if (__builtin_constant_p(e)) { \
378 char __compile_time_assert__[(bool)(e) ? -1 : 1] DISPATCH_UNUSED; \
380 typeof(e) _e = slowpath(e); /* always eval 'e' */ \
381 if (DISPATCH_DEBUG && _e) { \
382 _dispatch_abort(__LINE__, (long)_e); \
387 static inline void _dispatch_assert_zero(long e
, long line
) {
388 if (DISPATCH_DEBUG
&& e
) _dispatch_abort(line
, e
);
390 #define dispatch_assert_zero(e) _dispatch_assert((long)(e), __LINE__)
391 #endif /* __GNUC__ */
394 * For reporting bugs or impedance mismatches between libdispatch and external
395 * subsystems. These do NOT abort(), and are always compiled into the product.
397 * In particular, we wrap all system-calls with assume() macros.
400 #define dispatch_assume(e) ({ \
401 typeof(e) _e = fastpath(e); /* always eval 'e' */ \
403 if (__builtin_constant_p(e)) { \
404 char __compile_time_assert__[(bool)(e) ? 1 : -1]; \
405 (void)__compile_time_assert__; \
407 _dispatch_bug(__LINE__, (long)_e); \
412 static inline long _dispatch_assume(long e
, long line
) {
413 if (!e
) _dispatch_bug(line
, e
);
416 #define dispatch_assume(e) _dispatch_assume((long)(e), __LINE__)
417 #endif /* __GNUC__ */
420 * A lot of API return zero upon success and not-zero on fail. Let's capture
421 * and log the non-zero value
424 #define dispatch_assume_zero(e) ({ \
425 typeof(e) _e = slowpath(e); /* always eval 'e' */ \
427 if (__builtin_constant_p(e)) { \
428 char __compile_time_assert__[(bool)(e) ? -1 : 1]; \
429 (void)__compile_time_assert__; \
431 _dispatch_bug(__LINE__, (long)_e); \
436 static inline long _dispatch_assume_zero(long e
, long line
) {
437 if (e
) _dispatch_bug(line
, e
);
440 #define dispatch_assume_zero(e) _dispatch_assume_zero((long)(e), __LINE__)
441 #endif /* __GNUC__ */
444 * For reporting bugs in clients when using the "_debug" version of the library.
447 #define dispatch_debug_assert(e, msg, args...) do { \
448 if (__builtin_constant_p(e)) { \
449 char __compile_time_assert__[(bool)(e) ? 1 : -1] DISPATCH_UNUSED; \
451 typeof(e) _e = fastpath(e); /* always eval 'e' */ \
452 if (DISPATCH_DEBUG && !_e) { \
453 _dispatch_log("%s() 0x%lx: " msg, __func__, (long)_e, ##args); \
459 #define dispatch_debug_assert(e, msg, args...) do { \
460 long _e = (long)fastpath(e); /* always eval 'e' */ \
461 if (DISPATCH_DEBUG && !_e) { \
462 _dispatch_log("%s() 0x%lx: " msg, __FUNCTION__, _e, ##args); \
466 #endif /* __GNUC__ */
468 /* Make sure the debug statments don't get too stale */
469 #define _dispatch_debug(x, args...) do { \
470 if (DISPATCH_DEBUG) { \
471 _dispatch_log("%u\t%p\t" x, __LINE__, \
472 (void *)_dispatch_thread_self(), ##args); \
478 DISPATCH_NOINLINE DISPATCH_USED
479 void dispatch_debug_machport(mach_port_t name
, const char* str
);
484 /* This is the private version of the deprecated dispatch_debug() */
485 DISPATCH_NONNULL2 DISPATCH_NOTHROW
486 __attribute__((__format__(printf
,2,3)))
488 _dispatch_object_debug(dispatch_object_t object
, const char *message
, ...);
490 #define _dispatch_object_debug(object, message, ...)
491 #endif // DISPATCH_DEBUG
494 #define _dispatch_Block_invoke(bb) \
495 ((dispatch_function_t)((struct Block_layout *)bb)->invoke)
497 dispatch_block_t
_dispatch_Block_copy(dispatch_block_t block
);
498 #define _dispatch_Block_copy(x) ((typeof(x))_dispatch_Block_copy(x))
500 dispatch_block_t
_dispatch_Block_copy(const void *block
);
502 void _dispatch_call_block_and_release(void *block
);
503 #endif /* __BLOCKS__ */
505 void _dispatch_temporary_resource_shortage(void);
506 void *_dispatch_calloc(size_t num_items
, size_t size
);
507 void _dispatch_vtable_init(void);
508 char *_dispatch_get_build(void);
510 uint64_t _dispatch_timeout(dispatch_time_t when
);
512 extern bool _dispatch_safe_fork
, _dispatch_child_of_unsafe_fork
;
514 #if !defined(DISPATCH_USE_OS_SEMAPHORE_CACHE) && !(TARGET_IPHONE_SIMULATOR)
515 // rdar://problem/15492045
516 #if __has_include(<os/semaphore_private.h>)
517 #define DISPATCH_USE_OS_SEMAPHORE_CACHE 1
518 #include <os/semaphore_private.h>
522 /* #includes dependent on internal.h */
525 // Older Mac OS X and iOS Simulator fallbacks
527 #if HAVE_PTHREAD_WORKQUEUES
528 #ifndef WORKQ_ADDTHREADS_OPTION_OVERCOMMIT
529 #define WORKQ_ADDTHREADS_OPTION_OVERCOMMIT 0x00000001
531 #if TARGET_IPHONE_SIMULATOR && IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED < 1080
532 #ifndef DISPATCH_USE_LEGACY_WORKQUEUE_FALLBACK
533 #define DISPATCH_USE_LEGACY_WORKQUEUE_FALLBACK 1
536 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED < 1080
537 #undef HAVE_PTHREAD_WORKQUEUE_SETDISPATCH_NP
538 #define HAVE_PTHREAD_WORKQUEUE_SETDISPATCH_NP 0
540 #if TARGET_IPHONE_SIMULATOR && \
541 IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED < 101000
542 #ifndef DISPATCH_USE_NOQOS_WORKQUEUE_FALLBACK
543 #define DISPATCH_USE_NOQOS_WORKQUEUE_FALLBACK 1
546 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
547 #undef HAVE__PTHREAD_WORKQUEUE_INIT
548 #define HAVE__PTHREAD_WORKQUEUE_INIT 0
550 #endif // HAVE_PTHREAD_WORKQUEUES
551 #if HAVE__PTHREAD_WORKQUEUE_INIT && PTHREAD_WORKQUEUE_SPI_VERSION >= 20140213 \
552 && !defined(HAVE_PTHREAD_WORKQUEUE_QOS)
553 #define HAVE_PTHREAD_WORKQUEUE_QOS 1
557 #if !defined(MACH_NOTIFY_SEND_POSSIBLE) || (TARGET_IPHONE_SIMULATOR && \
558 IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED < 1070)
559 #undef MACH_NOTIFY_SEND_POSSIBLE
560 #define MACH_NOTIFY_SEND_POSSIBLE MACH_NOTIFY_DEAD_NAME
564 #ifdef EVFILT_MEMORYSTATUS
565 #ifndef DISPATCH_USE_MEMORYSTATUS
566 #define DISPATCH_USE_MEMORYSTATUS 1
568 #endif // EVFILT_MEMORYSTATUS
570 #if defined(EVFILT_VM) && !DISPATCH_USE_MEMORYSTATUS
571 #ifndef DISPATCH_USE_VM_PRESSURE
572 #define DISPATCH_USE_VM_PRESSURE 1
576 #if TARGET_IPHONE_SIMULATOR
577 #undef DISPATCH_USE_MEMORYSTATUS_SOURCE
578 #define DISPATCH_USE_MEMORYSTATUS_SOURCE 0
579 #undef DISPATCH_USE_VM_PRESSURE_SOURCE
580 #define DISPATCH_USE_VM_PRESSURE_SOURCE 0
581 #endif // TARGET_IPHONE_SIMULATOR
582 #if !defined(DISPATCH_USE_MEMORYSTATUS_SOURCE) && DISPATCH_USE_MEMORYSTATUS
583 #define DISPATCH_USE_MEMORYSTATUS_SOURCE 1
584 #elif !defined(DISPATCH_USE_VM_PRESSURE_SOURCE) && DISPATCH_USE_VM_PRESSURE
585 #define DISPATCH_USE_VM_PRESSURE_SOURCE 1
588 #if !defined(NOTE_LEEWAY) || (TARGET_IPHONE_SIMULATOR && \
589 IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED < 1090)
591 #define NOTE_LEEWAY 0
593 #define NOTE_CRITICAL 0
594 #undef NOTE_BACKGROUND
595 #define NOTE_BACKGROUND 0
596 #endif // NOTE_LEEWAY
598 #if HAVE_DECL_NOTE_REAP
599 #if defined(NOTE_REAP) && defined(__APPLE__)
601 #define NOTE_REAP 0x10000000 // <rdar://problem/13338526>
603 #endif // HAVE_DECL_NOTE_REAP
605 #if defined(F_SETNOSIGPIPE) && defined(F_GETNOSIGPIPE)
606 #if TARGET_IPHONE_SIMULATOR && IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED < 1070
607 #undef DISPATCH_USE_SETNOSIGPIPE
608 #define DISPATCH_USE_SETNOSIGPIPE 0
610 #ifndef DISPATCH_USE_SETNOSIGPIPE
611 #define DISPATCH_USE_SETNOSIGPIPE 1
613 #endif // F_SETNOSIGPIPE
615 #if defined(MACH_SEND_NOIMPORTANCE)
616 #ifndef DISPATCH_USE_CHECKIN_NOIMPORTANCE
617 #define DISPATCH_USE_CHECKIN_NOIMPORTANCE 1 // rdar://problem/16996737
619 #endif // MACH_SEND_NOIMPORTANCE
622 #if HAVE_LIBPROC_INTERNAL_H
624 #include <libproc_internal.h>
625 #if TARGET_IPHONE_SIMULATOR && IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED < 1090
626 #undef DISPATCH_USE_IMPORTANCE_ASSERTION
627 #define DISPATCH_USE_IMPORTANCE_ASSERTION 0
629 #if !TARGET_OS_IPHONE && __MAC_OS_X_VERSION_MIN_REQUIRED < 1090
630 #undef DISPATCH_USE_IMPORTANCE_ASSERTION
631 #define DISPATCH_USE_IMPORTANCE_ASSERTION 0
633 #ifndef DISPATCH_USE_IMPORTANCE_ASSERTION
634 #define DISPATCH_USE_IMPORTANCE_ASSERTION 1
636 #endif // HAVE_LIBPROC_INTERNAL_H
638 #if HAVE_SYS_GUARDED_H
639 #include <sys/guarded.h>
640 #if TARGET_IPHONE_SIMULATOR && IPHONE_SIMULATOR_HOST_MIN_VERSION_REQUIRED < 1090
641 #undef DISPATCH_USE_GUARDED_FD
642 #define DISPATCH_USE_GUARDED_FD 0
644 #ifndef DISPATCH_USE_GUARDED_FD
645 #define DISPATCH_USE_GUARDED_FD 1
647 // change_fdguard_np() requires GUARD_DUP <rdar://problem/11814513>
648 #if DISPATCH_USE_GUARDED_FD && RDAR_11814513
649 #define DISPATCH_USE_GUARDED_FD_CHANGE_FDGUARD 1
651 #endif // HAVE_SYS_GUARDED_H
654 #ifndef MACH_MSGH_BITS_VOUCHER_MASK
655 #define MACH_MSGH_BITS_VOUCHER_MASK 0x001f0000
656 #define MACH_MSGH_BITS_SET_PORTS(remote, local, voucher) \
657 (((remote) & MACH_MSGH_BITS_REMOTE_MASK) | \
658 (((local) << 8) & MACH_MSGH_BITS_LOCAL_MASK) | \
659 (((voucher) << 16) & MACH_MSGH_BITS_VOUCHER_MASK))
660 #define MACH_MSGH_BITS_VOUCHER(bits) \
661 (((bits) & MACH_MSGH_BITS_VOUCHER_MASK) >> 16)
662 #define MACH_MSGH_BITS_HAS_VOUCHER(bits) \
663 (MACH_MSGH_BITS_VOUCHER(bits) != MACH_MSGH_BITS_ZERO)
664 #define msgh_voucher_port msgh_reserved
665 #define mach_voucher_t mach_port_t
666 #define MACH_VOUCHER_NULL MACH_PORT_NULL
667 #define MACH_SEND_INVALID_VOUCHER 0x10000005
670 #define _dispatch_hardware_crash() \
671 __asm__(""); __builtin_trap() // <rdar://problem/17464981>
673 #define _dispatch_set_crash_log_message(msg)
676 // MIG_REPLY_MISMATCH means either:
677 // 1) A signal handler is NOT using async-safe API. See the sigaction(2) man
678 // page for more info.
679 // 2) A hand crafted call to mach_msg*() screwed up. Use MIG.
680 #define DISPATCH_VERIFY_MIG(x) do { \
681 if ((x) == MIG_REPLY_MISMATCH) { \
682 _dispatch_set_crash_log_message("MIG_REPLY_MISMATCH"); \
683 _dispatch_hardware_crash(); \
688 #define DISPATCH_CRASH(x) do { \
689 _dispatch_set_crash_log_message("BUG IN LIBDISPATCH: " x); \
690 _dispatch_hardware_crash(); \
693 #define DISPATCH_CLIENT_CRASH(x) do { \
694 _dispatch_set_crash_log_message("BUG IN CLIENT OF LIBDISPATCH: " x); \
695 _dispatch_hardware_crash(); \
698 #define _OS_OBJECT_CLIENT_CRASH(x) do { \
699 _dispatch_set_crash_log_message("API MISUSE: " x); \
700 _dispatch_hardware_crash(); \
703 extern int _dispatch_set_qos_class_enabled
;
704 #define DISPATCH_NO_VOUCHER ((voucher_t)(void*)~0ul)
705 #define DISPATCH_NO_PRIORITY ((pthread_priority_t)~0ul)
706 #define DISPATCH_PRIORITY_ENFORCE 0x1
707 static inline void _dispatch_adopt_priority_and_replace_voucher(
708 pthread_priority_t priority
, voucher_t voucher
, unsigned long flags
);
710 static inline void _dispatch_set_priority_and_mach_voucher(
711 pthread_priority_t priority
, mach_voucher_t kv
);
712 mach_port_t
_dispatch_get_mach_host_port(void);
716 /* #includes dependent on internal.h */
717 #include "object_internal.h"
718 #include "semaphore_internal.h"
719 #include "introspection_internal.h"
720 #include "queue_internal.h"
721 #include "source_internal.h"
722 #include "voucher_internal.h"
723 #include "data_internal.h"
725 #include "io_internal.h"
727 #include "inline_internal.h"
729 #endif /* __DISPATCH_INTERNAL__ */