]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5ba3f43e | 2 | * Copyright (c) 2000-2016 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
0a7de745 | 5 | * |
2d21ac55 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. | |
0a7de745 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
0a7de745 | 17 | * |
2d21ac55 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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
0a7de745 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
2d21ac55 A |
31 | /* |
32 | * NOTICE: This file was modified by McAfee Research in 2004 to introduce | |
33 | * support for mandatory and extensible security protections. This notice | |
34 | * is included in support of clause 2.2 (b) of the Apple Public License, | |
35 | * Version 2.0. | |
36 | */ | |
1c79356b | 37 | |
0a7de745 A |
38 | #ifndef _MISC_PROTOS_H_ |
39 | #define _MISC_PROTOS_H_ | |
1c79356b A |
40 | |
41 | #include <stdarg.h> | |
42 | #include <string.h> | |
43 | #include <machine/setjmp.h> | |
44 | #include <mach/boolean.h> | |
45 | #include <mach/message.h> | |
46 | #include <mach/machine/vm_types.h> | |
47 | #include <ipc/ipc_types.h> | |
91447636 | 48 | #include <kern/debug.h> |
d9a64523 | 49 | #include <libkern/copyio.h> |
1c79356b | 50 | |
2d21ac55 | 51 | #ifndef MIN |
0a7de745 | 52 | #define MIN(a, b) (((a)<(b))?(a):(b)) |
2d21ac55 A |
53 | #endif /* MIN */ |
54 | #ifndef MAX | |
0a7de745 | 55 | #define MAX(a, b) (((a)>(b))?(a):(b)) |
2d21ac55 A |
56 | #endif /* MAX */ |
57 | ||
1c79356b A |
58 | /* Set a bit in a bit array */ |
59 | extern void setbit( | |
0a7de745 A |
60 | int which, |
61 | int *bitmap); | |
1c79356b A |
62 | |
63 | /* Clear a bit in a bit array */ | |
64 | extern void clrbit( | |
0a7de745 A |
65 | int which, |
66 | int *bitmap); | |
1c79356b A |
67 | |
68 | /* Find the first set bit in a bit array */ | |
69 | extern int ffsbit( | |
0a7de745 | 70 | int *bitmap); |
1c79356b | 71 | extern int ffs( |
0a7de745 | 72 | unsigned int mask); |
5ba3f43e A |
73 | extern int ffsll( |
74 | unsigned long long mask); | |
75 | ||
76 | /* Find the last set bit in a bit array */ | |
77 | extern int fls( | |
0a7de745 | 78 | unsigned int mask); |
5ba3f43e A |
79 | extern int flsll( |
80 | unsigned long long mask); | |
1c79356b A |
81 | |
82 | /* | |
83 | * Test if indicated bit is set in bit string. | |
84 | */ | |
85 | extern int testbit( | |
0a7de745 A |
86 | int which, |
87 | int *bitmap); | |
1c79356b | 88 | |
cb323159 A |
89 | /* |
90 | * Move an aligned 32 or 64-bit word from user space to kernel space | |
39037602 | 91 | * using a single read instruction |
cb323159 A |
92 | */ |
93 | extern int copyin_atomic32( | |
94 | const user_addr_t user_addr, | |
95 | uint32_t *kernel_addr); | |
96 | ||
97 | extern int copyin_atomic64( | |
98 | const user_addr_t user_addr, | |
99 | uint64_t *kernel_addr); | |
100 | ||
101 | /* | |
102 | * Does an atomic copyin at the specified user_address and compares | |
103 | * it to the passed in value, and if it matches, waits. | |
39037602 | 104 | * |
cb323159 A |
105 | * This is used to implement adaptive spinning for userspace synchronization |
106 | * | |
107 | * Returns: | |
108 | * 0: the value mached, and it paused efficiently for the platform | |
109 | * ESTALE: the value didn't match, and it returned immediately | |
110 | * other: the copyin failed (EFAULT, EINVAL, ...) | |
39037602 | 111 | */ |
cb323159 | 112 | extern int copyin_atomic32_wait_if_equals( |
39037602 | 113 | const user_addr_t user_addr, |
cb323159 A |
114 | uint32_t value); |
115 | ||
116 | /* | |
117 | * Move a 32 or 64-bit word from kernel space to user space | |
118 | * using a single write instruction | |
119 | */ | |
120 | extern int copyout_atomic32( | |
121 | uint32_t u32, | |
122 | user_addr_t user_addr); | |
123 | ||
124 | extern int copyout_atomic64( | |
125 | uint64_t u64, | |
126 | user_addr_t user_addr); | |
39037602 | 127 | |
1c79356b | 128 | /* Move a NUL-terminated string from a user space to kernel space */ |
91447636 A |
129 | extern int copyinstr( |
130 | const user_addr_t user_addr, | |
131 | char *kernel_addr, | |
132 | vm_size_t max, | |
133 | vm_size_t *actual); | |
1c79356b A |
134 | |
135 | /* Move arbitrarily-aligned data from a user space to kernel space */ | |
91447636 A |
136 | extern int copyinmsg( |
137 | const user_addr_t user_addr, | |
138 | char *kernel_addr, | |
139 | mach_msg_size_t nbytes); | |
1c79356b | 140 | |
1c79356b | 141 | /* Move arbitrarily-aligned data from a kernel space to user space */ |
91447636 A |
142 | extern int copyoutmsg( |
143 | const char *kernel_addr, | |
144 | user_addr_t user_addr, | |
1c79356b A |
145 | mach_msg_size_t nbytes); |
146 | ||
0c530ab8 | 147 | /* Invalidate copy window(s) cache */ |
6d2010ae A |
148 | extern void inval_copy_windows(thread_t); |
149 | extern void copy_window_fault(thread_t, vm_map_t, int); | |
0c530ab8 | 150 | |
0a7de745 | 151 | extern int sscanf(const char *input, const char *fmt, ...) __scanflike(2, 3); |
0c530ab8 | 152 | |
0a7de745 | 153 | /* sprintf() is being deprecated. Please use snprintf() instead. */ |
2d21ac55 | 154 | extern integer_t sprintf(char *buf, const char *fmt, ...) __deprecated; |
1c79356b | 155 | |
0a7de745 | 156 | extern int printf(const char *format, ...) __printflike(1, 2); |
39037602 | 157 | extern int vprintf(const char *format, va_list ap); |
1c79356b | 158 | |
b0d623f7 A |
159 | #if KERNEL_PRIVATE |
160 | int _consume_printf_args(int, ...); | |
161 | #endif | |
162 | ||
163 | #if CONFIG_NO_PRINTF_STRINGS | |
164 | #if KERNEL_PRIVATE | |
165 | #define printf(x, ...) _consume_printf_args( 0, ## __VA_ARGS__ ) | |
166 | #else | |
167 | #define printf(x, ...) do {} while (0) | |
168 | #endif | |
169 | #endif | |
170 | ||
0a7de745 | 171 | extern int paniclog_append_noflush(const char *format, ...) __printflike(1, 2); |
5ba3f43e | 172 | |
0a7de745 | 173 | extern int kdb_printf(const char *format, ...) __printflike(1, 2); |
9bccf70c | 174 | |
0a7de745 | 175 | extern int kdb_log(const char *format, ...) __printflike(1, 2); |
c910b4d9 | 176 | |
0a7de745 | 177 | extern int kdb_printf_unbuffered(const char *format, ...) __printflike(1, 2); |
b0d623f7 | 178 | |
1c79356b A |
179 | extern void printf_init(void); |
180 | ||
0a7de745 | 181 | extern int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); |
593a1d5f | 182 | |
1c79356b A |
183 | extern void log(int level, char *fmt, ...); |
184 | ||
0a7de745 | 185 | void |
1c79356b | 186 | _doprnt( |
0a7de745 A |
187 | const char *fmt, |
188 | va_list *argp, | |
189 | void (*putc)(char), | |
190 | int radix); | |
3e170ce0 A |
191 | |
192 | void | |
193 | _doprnt_log( | |
0a7de745 A |
194 | const char *fmt, |
195 | va_list *argp, | |
196 | void (*putc)(char), | |
197 | int radix); | |
3e170ce0 | 198 | |
9bccf70c A |
199 | int |
200 | __doprnt( | |
0a7de745 A |
201 | const char *fmt, |
202 | va_list argp, | |
203 | void (*putc)(int, void *), | |
9bccf70c | 204 | void *arg, |
0a7de745 A |
205 | int radix, |
206 | int is_log); | |
1c79356b A |
207 | |
208 | extern void safe_gets( | |
0a7de745 A |
209 | char *str, |
210 | int maxlen); | |
1c79356b A |
211 | |
212 | extern void cnputcusr(char); | |
213 | ||
5ba3f43e A |
214 | extern void cnputsusr(char *, int); |
215 | ||
9bccf70c A |
216 | extern void conslog_putc(char); |
217 | ||
6d2010ae A |
218 | extern void cons_putc_locked(char); |
219 | ||
9bccf70c A |
220 | extern void consdebug_putc(char); |
221 | ||
c910b4d9 A |
222 | extern void consdebug_log(char); |
223 | ||
b0d623f7 A |
224 | extern void consdebug_putc_unbuffered(char); |
225 | ||
1c79356b A |
226 | extern void cnputc(char); |
227 | ||
b0d623f7 A |
228 | extern void cnputc_unbuffered(char); |
229 | ||
39037602 A |
230 | extern void console_write(char *, int); |
231 | ||
232 | extern void console_suspend(void); | |
233 | ||
234 | extern void console_resume(void); | |
235 | ||
1c79356b A |
236 | extern int cngetc(void); |
237 | ||
238 | extern int cnmaygetc(void); | |
239 | ||
240 | extern int _setjmp( | |
0a7de745 | 241 | jmp_buf_t *jmp_buf); |
1c79356b A |
242 | |
243 | extern int _longjmp( | |
0a7de745 A |
244 | jmp_buf_t *jmp_buf, |
245 | int value); | |
1c79356b A |
246 | |
247 | extern void bootstrap_create(void); | |
248 | ||
0a7de745 A |
249 | #if DIPC |
250 | extern boolean_t no_bootstrap_task(void); | |
251 | extern ipc_port_t get_root_master_device_port(void); | |
252 | #endif /* DIPC */ | |
1c79356b | 253 | |
0a7de745 A |
254 | extern kern_return_t kernel_set_special_port( |
255 | host_priv_t host_priv, | |
256 | int which, | |
257 | ipc_port_t port); | |
55e303ae | 258 | |
0a7de745 A |
259 | extern kern_return_t kernel_get_special_port( |
260 | host_priv_t host_priv, | |
261 | int which, | |
262 | ipc_port_t *portp); | |
39037602 | 263 | |
2d21ac55 A |
264 | user_addr_t get_useraddr(void); |
265 | ||
266 | /* symbol lookup */ | |
267 | struct kmod_info_t; | |
268 | ||
316670eb A |
269 | extern uint64_t early_random(void); |
270 | ||
0a7de745 | 271 | #endif /* _MISC_PROTOS_H_ */ |