]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/pthread_shims.h
xnu-3248.60.10.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@
5 *
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.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
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.
25 *
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
36#include <kern/clock.h>
37#include <kern/kern_types.h>
38#include <kern/locks.h>
39#include <sys/_types.h>
40#include <sys/_types/_sigset_t.h>
41#include <sys/kernel_types.h>
42#include <sys/proc_info.h>
43
44#ifndef PTHREAD_INTERNAL
45struct uthread;
46#define M_PROC 41
47#endif
48
49#ifdef NEEDS_SCHED_CALL_T
50typedef void (*sched_call_t)(int type, thread_t thread);
51#endif
52
3e170ce0
A
53typedef struct workq_reqthreads_req_s {unsigned long priority; int count;} *workq_reqthreads_req_t;
54
fe8ab488
A
55/*
56 * Increment each time new reserved slots are used. When the pthread
57 * kext registers this table, it will include the version of the xnu
58 * headers that it was built against.
59 */
60#define PTHREAD_FUNCTIONS_TABLE_VERSION 1
61
39236c6e
A
62typedef struct pthread_functions_s {
63 int version;
64
65 /* internal calls, kernel core -> kext */
66 void (*pthread_init)(void);
67 int (*fill_procworkqueue)(proc_t p, struct proc_workqueueinfo * pwqinfo);
68 void (*workqueue_init_lock)(proc_t p);
69 void (*workqueue_destroy_lock)(proc_t p);
70 void (*workqueue_exit)(struct proc *p);
71 void (*workqueue_mark_exiting)(struct proc *p);
72 void (*workqueue_thread_yielded)(void);
73 void (*pth_proc_hashinit)(proc_t p);
74 void (*pth_proc_hashdelete)(proc_t p);
75
76 /* syscall stubs */
77 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);
78 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);
79 int (*bsdthread_terminate)(struct proc *p, user_addr_t stackaddr, size_t size, uint32_t kthport, uint32_t sem, int32_t *retval);
80 int (*thread_selfid)(struct proc *p, uint64_t *retval);
81 int (*workq_kernreturn)(struct proc *p, int options, user_addr_t item, int affinity, int prio, int32_t *retval);
82 int (*workq_open)(struct proc *p, int32_t *retval);
83
84 /* psynch syscalls */
85 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);
86 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);
87 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);
88 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);
89 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);
90 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);
91 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);
92 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);
93 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);
94 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);
95 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);
96
97 sched_call_t (*workqueue_get_sched_callback)(void);
98
fe8ab488
A
99 /* New register function with TSD offset */
100 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);
101
102 /* New pthreadctl system. */
103 int (*bsdthread_ctl)(struct proc *p, user_addr_t cmd, user_addr_t arg1, user_addr_t arg2, user_addr_t arg3, int *retval);
104
3e170ce0
A
105 /* Request threads to deliver kevents */
106 thread_t (*workq_reqthreads)(struct proc *p, int requests_count, workq_reqthreads_req_t requests);
107
108 /* Resolve a pthread_priority_t to a QoS/relative pri */
109 integer_t (*thread_qos_from_pthread_priority)(unsigned long pthread_priority, unsigned long *flags);
110
39236c6e 111 /* padding for future */
3e170ce0 112 void* _pad[95];
39236c6e
A
113} *pthread_functions_t;
114
115typedef struct pthread_callbacks_s {
116 int version;
117
118 /* config information */
119 uint32_t config_thread_max;
120 uint32_t (*get_task_threadmax)(void);
121
122 /* proc.h accessors */
123 uint64_t (*proc_get_register)(struct proc *t);
124 void (*proc_set_register)(struct proc *t);
125
126 user_addr_t (*proc_get_threadstart)(struct proc *t);
127 void (*proc_set_threadstart)(struct proc *t, user_addr_t addr);
128 user_addr_t (*proc_get_wqthread)(struct proc *t);
129 void (*proc_set_wqthread)(struct proc *t, user_addr_t addr);
130 int (*proc_get_pthsize)(struct proc *t);
131 void (*proc_set_pthsize)(struct proc *t, int size);
132 user_addr_t (*proc_get_targconc)(struct proc *t);
133 void (*proc_set_targconc)(struct proc *t, user_addr_t addr);
134 uint64_t (*proc_get_dispatchqueue_offset)(struct proc *t);
135 void (*proc_set_dispatchqueue_offset)(struct proc *t, uint64_t offset);
136 lck_spin_t* (*proc_get_wqlockptr)(struct proc *t);
137 boolean_t* (*proc_get_wqinitingptr)(struct proc *t);
138 void* (*proc_get_wqptr)(struct proc *t);
139 void (*proc_set_wqptr)(struct proc *t, void* ptr);
140 int (*proc_get_wqsize)(struct proc *t);
141 void (*proc_set_wqsize)(struct proc *t, int sz);
142 void (*proc_lock)(struct proc *t);
143 void (*proc_unlock)(struct proc *t);
144 task_t (*proc_get_task)(struct proc *t);
145 void* (*proc_get_pthhash)(struct proc *t);
146 void (*proc_set_pthhash)(struct proc *t, void* ptr);
147
148 /* bsd/sys/user.h */
149 void* (*uthread_get_threadlist)(struct uthread *t);
150 void (*uthread_set_threadlist)(struct uthread *t, void* threadlist);
151 sigset_t (*uthread_get_sigmask)(struct uthread *t);
152 void (*uthread_set_sigmask)(struct uthread *t, sigset_t s);
153 void* (*uthread_get_uukwe)(struct uthread *t);
154 int (*uthread_get_returnval)(struct uthread *t);
155 void (*uthread_set_returnval)(struct uthread *t, int val);
156 int (*uthread_is_cancelled)(struct uthread *t);
157
158 /* vm_protos.h calls */
159 ipc_space_t (*task_get_ipcspace)(task_t t);
160 mach_port_name_t (*ipc_port_copyout_send)(ipc_port_t sright, ipc_space_t space);
161
162 /* osfmk/vm/vm_map.h */
163 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);
164 vm_map_t (*vm_map_switch)(vm_map_t map);
165
166 /* wq functions */
167 kern_return_t (*thread_set_wq_state32)(thread_t thread, thread_state_t state);
168 kern_return_t (*thread_set_wq_state64)(thread_t thread, thread_state_t state);
169
170 /* sched_prim.h */
171 void (*thread_exception_return)();
172 void (*thread_bootstrap_return)();
173
174 /* kern/clock.h */
175 void (*absolutetime_to_microtime)(uint64_t abstime, clock_sec_t *secs, clock_usec_t *microsecs);
176
177 /* osfmk/kern/task.h */
178 int (*proc_restore_workq_bgthreadpolicy)(thread_t t);
179 int (*proc_apply_workq_bgthreadpolicy)(thread_t t);
180
181 /* osfmk/kern/thread.h */
182 struct uthread* (*get_bsdthread_info)(thread_t th);
183 void (*thread_sched_call)(thread_t t, sched_call_t call);
184 void (*thread_static_param)(thread_t t, boolean_t state);
185 kern_return_t (*thread_create_workq)(task_t t, thread_continue_t c, thread_t *new_t);
186 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);
187
188 /* osfmk/kern/affinity.h */
189 kern_return_t (*thread_affinity_set)(thread_t thread, uint32_t tag);
190
191 /* bsd/sys/systm.h */
192 void (*unix_syscall_return)(int error);
193
194 /* osfmk/kern/zalloc.h */
195 void* (*zalloc)(zone_t zone);
196 void (*zfree)(zone_t zone, void* ptr);
197 zone_t (*zinit)(vm_size_t, vm_size_t maxmem, vm_size_t alloc, const char *name);
198
199 /* bsd/kerb/kern_sig.c */
200 void (*__pthread_testcancel)(int);
201
202 /* calls without portfolio */
203 kern_return_t (*mach_port_deallocate)(ipc_space_t space, mach_port_name_t name);
204 kern_return_t (*semaphore_signal_internal_trap)(mach_port_name_t sema_name);
205 vm_map_t (*current_map)(void);
206
207 /* osfmk/kern/thread.h */
208 ipc_port_t (*convert_thread_to_port)(thread_t th);
209
210 /* mach/task.h */
211 kern_return_t (*thread_create)(task_t parent_task, thread_act_t *child_act);
212
213 /* mach/thread_act.h */
214 kern_return_t (*thread_resume)(thread_act_t target_act);
215
216 /* osfmk/<arch>/machine_routines.h */
217 int (*ml_get_max_cpus)(void);
218
219
220 /* <rdar://problem/12809089> xnu: struct proc p_dispatchqueue_serialno_offset additions */
221 uint64_t (*proc_get_dispatchqueue_serialno_offset)(struct proc *p);
222 void (*proc_set_dispatchqueue_serialno_offset)(struct proc *p, uint64_t offset);
223
fe8ab488
A
224 user_addr_t (*proc_get_stack_addr_hint)(struct proc *p);
225 void (*proc_set_stack_addr_hint)(struct proc *p, user_addr_t stack_addr_hint);
226
227 uint32_t (*proc_get_pthread_tsd_offset)(struct proc *p);
228 void (*proc_set_pthread_tsd_offset)(struct proc *p, uint32_t pthread_tsd_offset);
229
230 kern_return_t (*thread_set_tsd_base)(thread_t thread, mach_vm_offset_t tsd_base);
231
232 int (*proc_usynch_get_requested_thread_qos)(struct uthread *);
233 boolean_t (*proc_usynch_thread_qos_add_override)(struct uthread *, uint64_t tid, int override_qos, boolean_t first_override_for_resource);
234 boolean_t (*proc_usynch_thread_qos_remove_override)(struct uthread *, uint64_t tid);
235
236 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);
237 boolean_t (*qos_main_thread_active)(void);
238
239 kern_return_t (*thread_set_voucher_name)(mach_port_name_t voucher_name);
240
a1c7dba1
A
241 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);
242 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);
243 boolean_t (*proc_usynch_thread_qos_reset_override_for_resource)(task_t task, struct uthread *, uint64_t tid, user_addr_t resource, int resource_type);
244
39236c6e 245 /* padding for future */
a1c7dba1 246 void* _pad[84];
39236c6e
A
247
248} *pthread_callbacks_t;
249
250void
251pthread_kext_register(pthread_functions_t fns, pthread_callbacks_t *callbacks);
252
253#ifdef BSD_KERNEL_PRIVATE
254void workqueue_mark_exiting(struct proc *);
255void workqueue_exit(struct proc *);
256void workqueue_thread_yielded(void);
257sched_call_t workqueue_get_sched_callback(void);
258void pthread_init(void);
259
260extern pthread_callbacks_t pthread_kern;
261extern pthread_functions_t pthread_functions;
262#endif
263
264#endif /* ASSEMBLER */
265#endif /* _PTHREAD_SHIMS_H_ */
266#endif /* KERNEL_PRIVATE */