1//
2//  pthread.c
3//  pthread
4//
5//  Created by Matt Wright on 9/13/12.
6//  Copyright (c) 2012 Matt Wright. All rights reserved.
7//
8
9#include <kern/thread.h>
10#include <kern/debug.h>
11#include "kern_internal.h"
12
13kern_return_t pthread_start(kmod_info_t * ki, void *d);
14kern_return_t pthread_stop(kmod_info_t *ki, void *d);
15
16pthread_callbacks_t pthread_kern;
17
18const struct pthread_functions_s pthread_internal_functions = {
19	.pthread_init = _pthread_init,
20	.fill_procworkqueue = _fill_procworkqueue,
21	.workqueue_init_lock = _workqueue_init_lock,
22	.workqueue_destroy_lock = _workqueue_destroy_lock,
23	.workqueue_exit = _workqueue_exit,
24	.workqueue_mark_exiting = _workqueue_mark_exiting,
25	.workqueue_thread_yielded = _workqueue_thread_yielded,
26	.workqueue_get_sched_callback = _workqueue_get_sched_callback,
27	.pth_proc_hashinit = _pth_proc_hashinit,
28	.pth_proc_hashdelete = _pth_proc_hashdelete,
29	.bsdthread_create = _bsdthread_create,
30	.bsdthread_register = _bsdthread_register,
31	.bsdthread_terminate = _bsdthread_terminate,
32	.bsdthread_ctl = _bsdthread_ctl,
33	.thread_selfid = _thread_selfid,
34	.workq_kernreturn = _workq_kernreturn,
35	.workq_open = _workq_open,
36
37	.psynch_mutexwait = _psynch_mutexwait,
38	.psynch_mutexdrop = _psynch_mutexdrop,
39	.psynch_cvbroad = _psynch_cvbroad,
40	.psynch_cvsignal = _psynch_cvsignal,
41	.psynch_cvwait = _psynch_cvwait,
42	.psynch_cvclrprepost = _psynch_cvclrprepost,
43	.psynch_rw_longrdlock = _psynch_rw_longrdlock,
44	.psynch_rw_rdlock = _psynch_rw_rdlock,
45	.psynch_rw_unlock = _psynch_rw_unlock,
46	.psynch_rw_wrlock = _psynch_rw_wrlock,
47	.psynch_rw_yieldwrlock = _psynch_rw_yieldwrlock,
48};
49
50kern_return_t pthread_start(__unused kmod_info_t * ki, __unused void *d)
51{
52	pthread_kext_register((pthread_functions_t)&pthread_internal_functions, &pthread_kern);
53	return KERN_SUCCESS;
54}
55
56kern_return_t pthread_stop(__unused kmod_info_t *ki, __unused void *d)
57{
58	return KERN_FAILURE;
59}
60
61struct uthread*
62current_uthread(void)
63{
64	thread_t th = current_thread();
65	return pthread_kern->get_bsdthread_info(th);
66}
67