]> git.saurik.com Git - apple/libdispatch.git/blob - src/shims.h
libdispatch-187.5.tar.gz
[apple/libdispatch.git] / src / shims.h
1 /*
2 * Copyright (c) 2008-2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_APACHE_LICENSE_HEADER_START@
5 *
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
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 *
18 * @APPLE_APACHE_LICENSE_HEADER_END@
19 */
20
21 /*
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.
25 */
26
27 #ifndef __DISPATCH_OS_SHIMS__
28 #define __DISPATCH_OS_SHIMS__
29
30 #include <pthread.h>
31 #if HAVE_PTHREAD_WORKQUEUES
32 #include <pthread_workqueue.h>
33 #endif
34 #if HAVE_PTHREAD_NP_H
35 #include <pthread_np.h>
36 #endif
37
38 #if !HAVE_DECL_FD_COPY
39 #define FD_COPY(f, t) (void)(*(t) = *(f))
40 #endif
41
42 #if !HAVE_NORETURN_BUILTIN_TRAP
43 /*
44 * XXXRW: Work-around for possible clang bug in which __builtin_trap() is not
45 * marked noreturn, leading to a build error as dispatch_main() *is* marked
46 * noreturn. Mask by marking __builtin_trap() as noreturn locally.
47 */
48 DISPATCH_NORETURN
49 void __builtin_trap(void);
50 #endif
51
52 #include "shims/atomic.h"
53 #include "shims/tsd.h"
54 #include "shims/hw_config.h"
55 #include "shims/perfmon.h"
56
57 #include "shims/getprogname.h"
58 #include "shims/malloc_zone.h"
59 #include "shims/time.h"
60
61 #ifdef __APPLE__
62 // Clear the stack before calling long-running thread-handler functions that
63 // never return (and don't take arguments), to facilitate leak detection and
64 // provide cleaner backtraces. <rdar://problem/9050566>
65 #define _dispatch_clear_stack(s) do { \
66 void *a[(s)/sizeof(void*) ? (s)/sizeof(void*) : 1]; \
67 a[0] = pthread_get_stackaddr_np(pthread_self()); \
68 bzero((void*)&a[1], a[0] - (void*)&a[1]); \
69 } while (0)
70 #else
71 #define _dispatch_clear_stack(s)
72 #endif
73
74 #endif