]>
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 | |
39037602 A |
89 | /* Move an aligned 32 or 64-bit word from user space to kernel space |
90 | * using a single read instruction | |
91 | * | |
92 | * when reading a 32-bit word, the value is 0-extended into the kernel space | |
93 | * 64-bit buffer passed as `kernel_addr` | |
94 | * (think `*kernel_addr = *(uint32_t *)user_addr`) | |
95 | */ | |
96 | extern int copyin_word( | |
97 | const user_addr_t user_addr, | |
98 | uint64_t *kernel_addr, | |
99 | vm_size_t nbytes); | |
100 | ||
1c79356b | 101 | /* Move a NUL-terminated string from a user space to kernel space */ |
91447636 A |
102 | extern int copyinstr( |
103 | const user_addr_t user_addr, | |
104 | char *kernel_addr, | |
105 | vm_size_t max, | |
106 | vm_size_t *actual); | |
1c79356b A |
107 | |
108 | /* Move arbitrarily-aligned data from a user space to kernel space */ | |
91447636 A |
109 | extern int copyinmsg( |
110 | const user_addr_t user_addr, | |
111 | char *kernel_addr, | |
112 | mach_msg_size_t nbytes); | |
1c79356b | 113 | |
1c79356b | 114 | /* Move arbitrarily-aligned data from a kernel space to user space */ |
91447636 A |
115 | extern int copyoutmsg( |
116 | const char *kernel_addr, | |
117 | user_addr_t user_addr, | |
1c79356b A |
118 | mach_msg_size_t nbytes); |
119 | ||
0c530ab8 | 120 | /* Invalidate copy window(s) cache */ |
6d2010ae A |
121 | extern void inval_copy_windows(thread_t); |
122 | extern void copy_window_fault(thread_t, vm_map_t, int); | |
0c530ab8 | 123 | |
316670eb A |
124 | extern int copyin_validate(const user_addr_t, uintptr_t, vm_size_t); |
125 | extern int copyout_validate(uintptr_t, const user_addr_t, vm_size_t); | |
126 | ||
0a7de745 | 127 | extern int sscanf(const char *input, const char *fmt, ...) __scanflike(2, 3); |
0c530ab8 | 128 | |
0a7de745 | 129 | /* sprintf() is being deprecated. Please use snprintf() instead. */ |
2d21ac55 | 130 | extern integer_t sprintf(char *buf, const char *fmt, ...) __deprecated; |
1c79356b | 131 | |
0a7de745 | 132 | extern int printf(const char *format, ...) __printflike(1, 2); |
39037602 | 133 | extern int vprintf(const char *format, va_list ap); |
1c79356b | 134 | |
b0d623f7 A |
135 | #if KERNEL_PRIVATE |
136 | int _consume_printf_args(int, ...); | |
137 | #endif | |
138 | ||
139 | #if CONFIG_NO_PRINTF_STRINGS | |
140 | #if KERNEL_PRIVATE | |
141 | #define printf(x, ...) _consume_printf_args( 0, ## __VA_ARGS__ ) | |
142 | #else | |
143 | #define printf(x, ...) do {} while (0) | |
144 | #endif | |
145 | #endif | |
146 | ||
0a7de745 | 147 | extern int paniclog_append_noflush(const char *format, ...) __printflike(1, 2); |
5ba3f43e | 148 | |
0a7de745 | 149 | extern int kdb_printf(const char *format, ...) __printflike(1, 2); |
9bccf70c | 150 | |
0a7de745 | 151 | extern int kdb_log(const char *format, ...) __printflike(1, 2); |
c910b4d9 | 152 | |
0a7de745 | 153 | extern int kdb_printf_unbuffered(const char *format, ...) __printflike(1, 2); |
b0d623f7 | 154 | |
1c79356b A |
155 | extern void printf_init(void); |
156 | ||
0a7de745 | 157 | extern int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); |
593a1d5f | 158 | |
1c79356b A |
159 | extern void log(int level, char *fmt, ...); |
160 | ||
0a7de745 | 161 | void |
1c79356b | 162 | _doprnt( |
0a7de745 A |
163 | const char *fmt, |
164 | va_list *argp, | |
165 | void (*putc)(char), | |
166 | int radix); | |
3e170ce0 A |
167 | |
168 | void | |
169 | _doprnt_log( | |
0a7de745 A |
170 | const char *fmt, |
171 | va_list *argp, | |
172 | void (*putc)(char), | |
173 | int radix); | |
3e170ce0 | 174 | |
9bccf70c A |
175 | int |
176 | __doprnt( | |
0a7de745 A |
177 | const char *fmt, |
178 | va_list argp, | |
179 | void (*putc)(int, void *), | |
9bccf70c | 180 | void *arg, |
0a7de745 A |
181 | int radix, |
182 | int is_log); | |
1c79356b A |
183 | |
184 | extern void safe_gets( | |
0a7de745 A |
185 | char *str, |
186 | int maxlen); | |
1c79356b A |
187 | |
188 | extern void cnputcusr(char); | |
189 | ||
5ba3f43e A |
190 | extern void cnputsusr(char *, int); |
191 | ||
9bccf70c A |
192 | extern void conslog_putc(char); |
193 | ||
6d2010ae A |
194 | extern void cons_putc_locked(char); |
195 | ||
9bccf70c A |
196 | extern void consdebug_putc(char); |
197 | ||
c910b4d9 A |
198 | extern void consdebug_log(char); |
199 | ||
b0d623f7 A |
200 | extern void consdebug_putc_unbuffered(char); |
201 | ||
1c79356b A |
202 | extern void cnputc(char); |
203 | ||
b0d623f7 A |
204 | extern void cnputc_unbuffered(char); |
205 | ||
39037602 A |
206 | extern void console_write(char *, int); |
207 | ||
208 | extern void console_suspend(void); | |
209 | ||
210 | extern void console_resume(void); | |
211 | ||
1c79356b A |
212 | extern int cngetc(void); |
213 | ||
214 | extern int cnmaygetc(void); | |
215 | ||
216 | extern int _setjmp( | |
0a7de745 | 217 | jmp_buf_t *jmp_buf); |
1c79356b A |
218 | |
219 | extern int _longjmp( | |
0a7de745 A |
220 | jmp_buf_t *jmp_buf, |
221 | int value); | |
1c79356b A |
222 | |
223 | extern void bootstrap_create(void); | |
224 | ||
0a7de745 A |
225 | #if DIPC |
226 | extern boolean_t no_bootstrap_task(void); | |
227 | extern ipc_port_t get_root_master_device_port(void); | |
228 | #endif /* DIPC */ | |
1c79356b | 229 | |
0a7de745 A |
230 | extern kern_return_t kernel_set_special_port( |
231 | host_priv_t host_priv, | |
232 | int which, | |
233 | ipc_port_t port); | |
55e303ae | 234 | |
0a7de745 A |
235 | extern kern_return_t kernel_get_special_port( |
236 | host_priv_t host_priv, | |
237 | int which, | |
238 | ipc_port_t *portp); | |
39037602 | 239 | |
2d21ac55 A |
240 | user_addr_t get_useraddr(void); |
241 | ||
242 | /* symbol lookup */ | |
243 | struct kmod_info_t; | |
244 | ||
316670eb A |
245 | extern uint64_t early_random(void); |
246 | ||
0a7de745 | 247 | #endif /* _MISC_PROTOS_H_ */ |