]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/pthread_shims.h
xnu-6153.41.3.tar.gz
[apple/xnu.git] / bsd / sys / pthread_shims.h
CommitLineData
39236c6e
A
1/*
2 * Copyright (c) 2012 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
d9a64523 5 *
39236c6e
A
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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
d9a64523 14 *
39236c6e
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
d9a64523 17 *
39236c6e
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
d9a64523 25 *
39236c6e
A
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifdef KERNEL_PRIVATE
30
31#ifndef _PTHREAD_SHIMS_H_
32#define _PTHREAD_SHIMS_H_
33
34#ifndef ASSEMBLER
35
d9a64523 36#include <kern/block_hint.h>
39236c6e
A
37#include <kern/clock.h>
38#include <kern/kern_types.h>
813fb2f6 39#include <kern/kcdata.h>
39236c6e 40#include <kern/locks.h>
d9a64523
A
41#include <kern/turnstile.h>
42#include <pthread/priority_private.h>
5ba3f43e 43#include <sys/user.h>
39236c6e
A
44#include <sys/_types.h>
45#include <sys/_types/_sigset_t.h>
46#include <sys/kernel_types.h>
39236c6e
A
47
48#ifndef PTHREAD_INTERNAL
49struct uthread;
d9a64523 50struct ksyn_waitq_element;
39236c6e
A
51#define M_PROC 41
52#endif
53
5ba3f43e
A
54#if !defined(_SCHED_CALL_T_DEFINED)
55#define _SCHED_CALL_T_DEFINED
39236c6e
A
56typedef void (*sched_call_t)(int type, thread_t thread);
57#endif
58
fe8ab488
A
59/*
60 * Increment each time new reserved slots are used. When the pthread
61 * kext registers this table, it will include the version of the xnu
62 * headers that it was built against.
63 */
64#define PTHREAD_FUNCTIONS_TABLE_VERSION 1
65
39037602 66typedef const struct pthread_functions_s {
39236c6e
A
67 int version;
68
69 /* internal calls, kernel core -> kext */
70 void (*pthread_init)(void);
39037602 71
d9a64523
A
72 void *__unused_was_fill_procworkqueue;
73 void *__unused1;
74 void *__unused2;
75 void *__unused_was_workqueue_exit;
76 void *__unused_was_workqueue_mark_exiting;
77 void *__unused_was_workqueue_thread_yielded;
39037602 78
39236c6e
A
79 void (*pth_proc_hashinit)(proc_t p);
80 void (*pth_proc_hashdelete)(proc_t p);
81
82 /* syscall stubs */
83 int (*bsdthread_create)(struct proc *p, user_addr_t user_func, user_addr_t user_funcarg, user_addr_t user_stack, user_addr_t user_pthread, uint32_t flags, user_addr_t *retval);
84 int (*bsdthread_register)(struct proc *p, user_addr_t threadstart, user_addr_t wqthread, int pthsize, user_addr_t dummy_value, user_addr_t targetconc_ptr, uint64_t dispatchqueue_offset, int32_t *retval);
85 int (*bsdthread_terminate)(struct proc *p, user_addr_t stackaddr, size_t size, uint32_t kthport, uint32_t sem, int32_t *retval);
86 int (*thread_selfid)(struct proc *p, uint64_t *retval);
d9a64523
A
87 void *__unused_was_workq_kernreturn;
88 void *__unused_was_workq_open;
39236c6e
A
89
90 /* psynch syscalls */
0a7de745
A
91 int (*psynch_mutexwait)(proc_t p, user_addr_t mutex, uint32_t mgen, uint32_t ugen, uint64_t tid, uint32_t flags, uint32_t *retval);
92 int (*psynch_mutexdrop)(proc_t p, user_addr_t mutex, uint32_t mgen, uint32_t ugen, uint64_t tid, uint32_t flags, uint32_t *retval);
39236c6e
A
93 int (*psynch_cvbroad)(proc_t p, user_addr_t cv, uint64_t cvlsgen, uint64_t cvudgen, uint32_t flags, user_addr_t mutex, uint64_t mugen, uint64_t tid, uint32_t *retval);
94 int (*psynch_cvsignal)(proc_t p, user_addr_t cv, uint64_t cvlsgen, uint32_t cvugen, int thread_port, user_addr_t mutex, uint64_t mugen, uint64_t tid, uint32_t flags, uint32_t *retval);
0a7de745 95 int (*psynch_cvwait)(proc_t p, user_addr_t cv, uint64_t cvlsgen, uint32_t cvugen, user_addr_t mutex, uint64_t mugen, uint32_t flags, int64_t sec, uint32_t nsec, uint32_t * retval);
39236c6e
A
96 int (*psynch_cvclrprepost)(proc_t p, user_addr_t cv, uint32_t cvgen, uint32_t cvugen, uint32_t cvsgen, uint32_t prepocnt, uint32_t preposeq, uint32_t flags, int *retval);
97 int (*psynch_rw_longrdlock)(proc_t p, user_addr_t rwlock, uint32_t lgenval, uint32_t ugenval, uint32_t rw_wc, int flags, uint32_t *retval);
98 int (*psynch_rw_rdlock)(proc_t p, user_addr_t rwlock, uint32_t lgenval, uint32_t ugenval, uint32_t rw_wc, int flags, uint32_t *retval);
99 int (*psynch_rw_unlock)(proc_t p, user_addr_t rwlock, uint32_t lgenval, uint32_t ugenval, uint32_t rw_wc, int flags, uint32_t *retval);
100 int (*psynch_rw_wrlock)(proc_t p, user_addr_t rwlock, uint32_t lgenval, uint32_t ugenval, uint32_t rw_wc, int flags, uint32_t *retval);
101 int (*psynch_rw_yieldwrlock)(proc_t p, user_addr_t rwlock, uint32_t lgenval, uint32_t ugenval, uint32_t rw_wc, int flags, uint32_t *retval);
102
d9a64523 103 void *__unused_was_workqueue_get_sched_callback;
39236c6e 104
fe8ab488
A
105 /* New register function with TSD offset */
106 int (*bsdthread_register2)(struct proc *p, user_addr_t threadstart, user_addr_t wqthread, uint32_t flags, user_addr_t stack_addr_hint, user_addr_t targetconc_ptr, uint32_t dispatchqueue_offset, uint32_t tsd_offset, int32_t *retval);
107
d9a64523
A
108 void *__unused_was_bsdthread_ctl;
109 void *__unused_was_workq_reqthreads;
110
111 void *__unused_was_thread_qos_from_pthread_priority;
112 void *__unused_was_get_pwq_state_kdp;
113 void *__unused3;
114 void *__unused_was_pthread_priority_canonicalize2;
115 void *__unused_was_workq_thread_has_been_unbound;
fe8ab488 116
d9a64523
A
117 void (*pthread_find_owner)(thread_t thread, struct stackshot_thread_waitinfo *waitinfo);
118 void *(*pthread_get_thread_kwq)(thread_t thread);
3e170ce0 119
d9a64523 120 void *__unused_was_workq_threadreq;
3e170ce0 121
d9a64523 122 int (*workq_handle_stack_events)(proc_t p, thread_t th, vm_map_t map,
0a7de745
A
123 user_addr_t stackaddr, mach_port_name_t kport,
124 user_addr_t events, int nevents, int upcall_flags);
39037602 125
d9a64523 126 int (*workq_create_threadstack)(proc_t p, vm_map_t vmap,
0a7de745 127 mach_vm_offset_t *out_addr);
39037602 128
d9a64523 129 int (*workq_destroy_threadstack)(proc_t p, vm_map_t vmap,
0a7de745 130 mach_vm_offset_t stackaddr);
5ba3f43e 131
d9a64523 132 void (*workq_setup_thread)(proc_t p, thread_t th, vm_map_t map,
0a7de745
A
133 user_addr_t stackaddr, mach_port_name_t kport, int th_qos,
134 int setup_flags, int upcall_flags);
813fb2f6 135
d9a64523 136 void (*workq_markfree_threadstack)(proc_t p, thread_t, vm_map_t map,
0a7de745 137 user_addr_t stackaddr);
5ba3f43e 138
39236c6e 139 /* padding for future */
d9a64523 140 void * _pad[83];
39037602 141} * pthread_functions_t;
39236c6e 142
39037602 143typedef const struct pthread_callbacks_s {
39236c6e
A
144 int version;
145
146 /* config information */
147 uint32_t config_thread_max;
148 uint32_t (*get_task_threadmax)(void);
149
150 /* proc.h accessors */
151 uint64_t (*proc_get_register)(struct proc *t);
152 void (*proc_set_register)(struct proc *t);
153
154 user_addr_t (*proc_get_threadstart)(struct proc *t);
155 void (*proc_set_threadstart)(struct proc *t, user_addr_t addr);
156 user_addr_t (*proc_get_wqthread)(struct proc *t);
157 void (*proc_set_wqthread)(struct proc *t, user_addr_t addr);
158 int (*proc_get_pthsize)(struct proc *t);
159 void (*proc_set_pthsize)(struct proc *t, int size);
d9a64523
A
160
161 thread_t (*task_findtid)(task_t t, uint64_t tid);
162 void (*thread_deallocate_safe)(thread_t);
163 void *__unused_was_proc_get_dispatchqueue_offset;
39236c6e 164 void (*proc_set_dispatchqueue_offset)(struct proc *t, uint64_t offset);
d9a64523
A
165 void *__unused_was_proc_get_wqlockptr;
166 void *__unused_was_proc_get_wqinitingptr;
167 void *__unused_was_proc_get_wqptr;
168
169 wait_result_t (*psynch_wait_prepare)(uintptr_t kwq,
0a7de745
A
170 struct turnstile **tstore, thread_t owner, block_hint_t block_hint,
171 uint64_t deadline);
d9a64523
A
172
173 void (*psynch_wait_update_complete)(struct turnstile *turnstile);
174
175 void (*psynch_wait_complete)(uintptr_t kwq, struct turnstile **tstore);
176
177 void (*psynch_wait_cleanup)(void);
178
179 kern_return_t (*psynch_wait_wakeup)(uintptr_t kwq,
0a7de745 180 struct ksyn_waitq_element *kwe, struct turnstile **tstore);
d9a64523
A
181
182 void (*psynch_wait_update_owner)(uintptr_t kwq, thread_t owner,
0a7de745 183 struct turnstile **tstore);
d9a64523 184
39236c6e
A
185 void* (*proc_get_pthhash)(struct proc *t);
186 void (*proc_set_pthhash)(struct proc *t, void* ptr);
187
188 /* bsd/sys/user.h */
d9a64523
A
189 void *__unused_was_uthread_get_threadlist;
190 void *__unused_was_uthread_set_threadlist;
191 void *__unused_was_uthread_get_sigmask;
192 void *__unused_was_uthread_set_sigmask;
193
39236c6e 194 void* (*uthread_get_uukwe)(struct uthread *t);
d9a64523 195 void *__unused_was_uthread_get_returnval;
39236c6e
A
196 void (*uthread_set_returnval)(struct uthread *t, int val);
197 int (*uthread_is_cancelled)(struct uthread *t);
198
199 /* vm_protos.h calls */
200 ipc_space_t (*task_get_ipcspace)(task_t t);
201 mach_port_name_t (*ipc_port_copyout_send)(ipc_port_t sright, ipc_space_t space);
202
203 /* osfmk/vm/vm_map.h */
204 kern_return_t (*vm_map_page_info)(vm_map_t map, vm_map_offset_t offset, vm_page_info_flavor_t flavor, vm_page_info_t info, mach_msg_type_number_t *count);
d9a64523 205 void *__unused_was_vm_map_switch;
39236c6e
A
206
207 /* wq functions */
208 kern_return_t (*thread_set_wq_state32)(thread_t thread, thread_state_t state);
5ba3f43e 209#if !defined(__arm__)
39236c6e 210 kern_return_t (*thread_set_wq_state64)(thread_t thread, thread_state_t state);
5ba3f43e 211#endif
39236c6e
A
212
213 /* sched_prim.h */
5ba3f43e
A
214 void (*thread_exception_return)(void);
215 void (*thread_bootstrap_return)(void);
39236c6e 216
d9a64523
A
217 void *__unused_was_absolutetime_to_microtime;
218 void *__unused_was_thread_set_workq_pri;
219 void *__unused_was_thread_set_workq_qos;
39236c6e
A
220
221 /* osfmk/kern/thread.h */
222 struct uthread* (*get_bsdthread_info)(thread_t th);
d9a64523
A
223 void *__unused_was_thread_sched_call;
224 void *__unused_was_thread_static_param;
225 void *__unused_was_thread_create_workq_waiting_parameter;
39236c6e
A
226 kern_return_t (*thread_policy_set_internal)(thread_t t, thread_policy_flavor_t flavour, thread_policy_t info, mach_msg_type_number_t count);
227
d9a64523 228 void *__unused_was_thread_affinity_set;
39236c6e
A
229
230 /* bsd/sys/systm.h */
231 void (*unix_syscall_return)(int error);
232
d9a64523
A
233 void *__unused_was_zalloc;
234 void *__unused_was_zfree;
235 void *__unused_was_zinit;
39236c6e 236
cb323159 237 /* bsd/kern/kern_sig.c */
39236c6e
A
238 void (*__pthread_testcancel)(int);
239
240 /* calls without portfolio */
241 kern_return_t (*mach_port_deallocate)(ipc_space_t space, mach_port_name_t name);
242 kern_return_t (*semaphore_signal_internal_trap)(mach_port_name_t sema_name);
243 vm_map_t (*current_map)(void);
244
245 /* osfmk/kern/thread.h */
246 ipc_port_t (*convert_thread_to_port)(thread_t th);
247
248 /* mach/task.h */
249 kern_return_t (*thread_create)(task_t parent_task, thread_act_t *child_act);
250
251 /* mach/thread_act.h */
252 kern_return_t (*thread_resume)(thread_act_t target_act);
253
cb323159
A
254 /* bsd/sys/event.h */
255 int (*kevent_workq_internal)(struct proc *p,
256 user_addr_t changelist, int nchanges,
257 user_addr_t eventlist, int nevents,
258 user_addr_t data_out, user_size_t *data_available,
259 unsigned int flags, int32_t *retval);
260
d9a64523
A
261#if defined(__arm__)
262 void *__unused_was_map_is_1gb;
263#endif
39236c6e 264
d9a64523
A
265 void *__unused_was_proc_get_dispatchqueue_serialno_offset;
266 void *__unused_was_proc_set_dispatchqueue_serialno_offset;
39236c6e 267
d9a64523
A
268 void *__unused_was_proc_usynch_thread_qos_add_override_for_resource_check_owner;
269 void *__unused_was_proc_set_stack_addr_hint;
fe8ab488
A
270
271 uint32_t (*proc_get_pthread_tsd_offset)(struct proc *p);
272 void (*proc_set_pthread_tsd_offset)(struct proc *p, uint32_t pthread_tsd_offset);
273
274 kern_return_t (*thread_set_tsd_base)(thread_t thread, mach_vm_offset_t tsd_base);
275
0a7de745 276 int (*proc_usynch_get_requested_thread_qos)(struct uthread *);
5ba3f43e
A
277 uint64_t (*proc_get_mach_thread_self_tsd_offset)(struct proc *p);
278 void (*proc_set_mach_thread_self_tsd_offset)(struct proc *p, uint64_t mach_thread_self_tsd_offset);
fe8ab488
A
279
280 kern_return_t (*thread_policy_get)(thread_t t, thread_policy_flavor_t flavor, thread_policy_t info, mach_msg_type_number_t *count, boolean_t *get_default);
281 boolean_t (*qos_main_thread_active)(void);
282
d9a64523 283 kern_return_t (*thread_set_voucher_name)(mach_port_name_t name);
fe8ab488 284
a1c7dba1
A
285 boolean_t (*proc_usynch_thread_qos_add_override_for_resource)(task_t task, struct uthread *, uint64_t tid, int override_qos, boolean_t first_override_for_resource, user_addr_t resource, int resource_type);
286 boolean_t (*proc_usynch_thread_qos_remove_override_for_resource)(task_t task, struct uthread *, uint64_t tid, user_addr_t resource, int resource_type);
d9a64523 287 void *__unused_was_proc_usynch_thread_qos_reset_override_for_resource;
a1c7dba1 288
d9a64523 289 void *__unused_was_proc_init_wqptr_or_wait;
39037602
A
290
291 uint16_t (*thread_set_tag)(thread_t thread, uint16_t tag);
292 uint16_t (*thread_get_tag)(thread_t thread);
293
d9a64523
A
294 void *__unused_was_proc_usynch_thread_qos_squash_override_for_resource;
295 void *__unused_was_task_get_default_manager_qos;
296 void *__unused_was_thread_create_workq_waiting;
39037602
A
297
298 user_addr_t (*proc_get_stack_addr_hint)(struct proc *p);
299 void (*proc_set_stack_addr_hint)(struct proc *p, user_addr_t stack_addr_hint);
300
d9a64523 301 void *__unused_was_proc_get_return_to_kernel_offset;
5ba3f43e
A
302 void (*proc_set_return_to_kernel_offset)(struct proc *t, uint64_t offset);
303
d9a64523 304 void *__unused_was_workloop_fulfill_threadreq;
5ba3f43e
A
305 void (*thread_will_park_or_terminate)(thread_t thread);
306
d9a64523 307 void *__unused_was_qos_max_parallelism;
5ba3f43e
A
308
309 /* proc_internal.h: struct proc user_stack accessor */
310 user_addr_t (*proc_get_user_stack)(struct proc *p);
d9a64523 311 void *__unused_was_proc_set_user_stack;
5ba3f43e 312
39236c6e 313 /* padding for future */
5ba3f43e 314 void* _pad[69];
39236c6e
A
315} *pthread_callbacks_t;
316
317void
318pthread_kext_register(pthread_functions_t fns, pthread_callbacks_t *callbacks);
319
320#ifdef BSD_KERNEL_PRIVATE
d9a64523 321void thread_will_park_or_terminate(thread_t thread);
39236c6e 322void pthread_init(void);
39236c6e
A
323extern pthread_callbacks_t pthread_kern;
324extern pthread_functions_t pthread_functions;
325#endif
326
327#endif /* ASSEMBLER */
328#endif /* _PTHREAD_SHIMS_H_ */
329#endif /* KERNEL_PRIVATE */