1 | /* $Id: the-darwin-kernel.h 20525 2009-06-13 20:13:33Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - Include all necessary headers for the Darwing kernel.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | *
|
---|
26 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #ifndef ___the_darwin_kernel_h
|
---|
32 | #define ___the_darwin_kernel_h
|
---|
33 |
|
---|
34 | /* Problematic header(s) containing conflicts with IPRT first. */
|
---|
35 | #define __STDC_CONSTANT_MACROS
|
---|
36 | #define __STDC_LIMIT_MACROS
|
---|
37 | #include <sys/param.h>
|
---|
38 | #include <mach/vm_param.h>
|
---|
39 | #undef ALIGN
|
---|
40 | #undef MIN
|
---|
41 | #undef MAX
|
---|
42 | #undef PAGE_SIZE
|
---|
43 | #undef PAGE_SHIFT
|
---|
44 |
|
---|
45 | /* Include the IPRT definitions of the conflicting #defines & typedefs. */
|
---|
46 | #include <iprt/cdefs.h>
|
---|
47 | #include <iprt/types.h>
|
---|
48 | #include <iprt/param.h>
|
---|
49 |
|
---|
50 |
|
---|
51 | /* After including cdefs, we can check that this really is Darwin. */
|
---|
52 | #ifndef RT_OS_DARWIN
|
---|
53 | # error "RT_OS_DARWIN must be defined!"
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | /* now we're ready for including the rest of the Darwin headers. */
|
---|
57 | #include <kern/thread.h>
|
---|
58 | #include <kern/clock.h>
|
---|
59 | #include <kern/sched_prim.h>
|
---|
60 | #include <kern/locks.h>
|
---|
61 | #if defined(RT_ARCH_X86) && MAC_OS_X_VERSION_MIN_REQUIRED < 1060
|
---|
62 | # include <i386/mp_events.h>
|
---|
63 | #endif
|
---|
64 | #include <libkern/libkern.h>
|
---|
65 | #include <libkern/sysctl.h>
|
---|
66 | #include <mach/thread_act.h>
|
---|
67 | #include <mach/vm_map.h>
|
---|
68 | #include <pexpert/pexpert.h>
|
---|
69 | #include <sys/conf.h>
|
---|
70 | #include <sys/errno.h>
|
---|
71 | #include <sys/ioccom.h>
|
---|
72 | #include <sys/malloc.h>
|
---|
73 | #include <sys/proc.h>
|
---|
74 | #include <IOKit/IOTypes.h>
|
---|
75 | #include <IOKit/IOLib.h>
|
---|
76 | #include <IOKit/IOMemoryDescriptor.h>
|
---|
77 | #include <IOKit/IOBufferMemoryDescriptor.h>
|
---|
78 | #include <IOKit/IOMapper.h>
|
---|
79 |
|
---|
80 |
|
---|
81 | /* See osfmk/kern/ast.h. */
|
---|
82 | #ifndef AST_PREEMPT
|
---|
83 | # define AST_PREEMPT UINT32_C(1)
|
---|
84 | # define AST_QUANTUM UINT32_C(2)
|
---|
85 | # define AST_URGENT UINT32_C(4)
|
---|
86 | #endif
|
---|
87 |
|
---|
88 |
|
---|
89 | RT_C_DECLS_BEGIN
|
---|
90 |
|
---|
91 | /* mach/vm_types.h */
|
---|
92 | typedef struct pmap *pmap_t;
|
---|
93 |
|
---|
94 | /* vm/vm_kern.h */
|
---|
95 | extern vm_map_t kernel_map;
|
---|
96 |
|
---|
97 | /* vm/pmap.h */
|
---|
98 | extern pmap_t kernel_pmap;
|
---|
99 |
|
---|
100 | /* kern/task.h */
|
---|
101 | extern vm_map_t get_task_map(task_t);
|
---|
102 |
|
---|
103 | /* osfmk/i386/pmap.h */
|
---|
104 | extern ppnum_t pmap_find_phys(pmap_t, addr64_t);
|
---|
105 |
|
---|
106 | /* vm/vm_map.h */
|
---|
107 | extern kern_return_t vm_map_wire(vm_map_t, vm_map_offset_t, vm_map_offset_t, vm_prot_t, boolean_t);
|
---|
108 | extern kern_return_t vm_map_unwire(vm_map_t, vm_map_offset_t, vm_map_offset_t, boolean_t);
|
---|
109 |
|
---|
110 | /* mach/i386/thread_act.h */
|
---|
111 | extern kern_return_t thread_terminate(thread_t);
|
---|
112 |
|
---|
113 | /* osfmk/i386/mp.h */
|
---|
114 | extern void mp_rendezvous(void (*)(void *), void (*)(void *), void (*)(void *), void *);
|
---|
115 | extern void mp_rendezvous_no_intrs(void (*)(void *), void *);
|
---|
116 |
|
---|
117 | /* osfmk/i386/cpu_number.h */
|
---|
118 | extern int cpu_number(void);
|
---|
119 |
|
---|
120 | /* osfmk/vm/vm_user.c */
|
---|
121 | extern kern_return_t vm_protect(vm_map_t, vm_offset_t, vm_size_t, boolean_t, vm_prot_t);
|
---|
122 |
|
---|
123 | /* i386/machine_routines.h */
|
---|
124 | extern int ml_get_max_cpus(void);
|
---|
125 |
|
---|
126 | RT_C_DECLS_END
|
---|
127 |
|
---|
128 |
|
---|
129 | /*
|
---|
130 | * Internals of the Darwin Ring-0 IPRT.
|
---|
131 | */
|
---|
132 |
|
---|
133 | RT_C_DECLS_BEGIN
|
---|
134 | extern lck_grp_t *g_pDarwinLockGroup;
|
---|
135 | int rtThreadPreemptDarwinInit(void);
|
---|
136 | void rtThreadPreemptDarwinTerm(void);
|
---|
137 | RT_C_DECLS_END
|
---|
138 |
|
---|
139 |
|
---|
140 | /**
|
---|
141 | * Converts from nanoseconds to Darwin absolute time units.
|
---|
142 | * @returns Darwin absolute time.
|
---|
143 | * @param u64Nano Time interval in nanoseconds
|
---|
144 | */
|
---|
145 | DECLINLINE(uint64_t) rtDarwinAbsTimeFromNano(const uint64_t u64Nano)
|
---|
146 | {
|
---|
147 | uint64_t u64AbsTime;
|
---|
148 | nanoseconds_to_absolutetime(u64Nano, &u64AbsTime);
|
---|
149 | return u64AbsTime;
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | #include <iprt/err.h>
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Convert from mach kernel return code to IPRT status code.
|
---|
157 | * @todo put this where it belongs! (i.e. in a separate file and prototype in iprt/err.h)
|
---|
158 | */
|
---|
159 | DECLINLINE(int) RTErrConvertFromMachKernReturn(kern_return_t rc)
|
---|
160 | {
|
---|
161 | switch (rc)
|
---|
162 | {
|
---|
163 | case KERN_SUCCESS: return VINF_SUCCESS;
|
---|
164 | default: return VERR_GENERAL_FAILURE;
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | #endif
|
---|
169 |
|
---|