]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/misc_protos.h
xnu-6153.61.1.tar.gz
[apple/xnu.git] / osfmk / kern / misc_protos.h
1 /*
2 * Copyright (c) 2000-2016 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 * @OSF_COPYRIGHT@
30 */
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 */
37
38 #ifndef _MISC_PROTOS_H_
39 #define _MISC_PROTOS_H_
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>
48 #include <kern/debug.h>
49 #include <libkern/copyio.h>
50
51 #ifndef MIN
52 #define MIN(a, b) (((a)<(b))?(a):(b))
53 #endif /* MIN */
54 #ifndef MAX
55 #define MAX(a, b) (((a)>(b))?(a):(b))
56 #endif /* MAX */
57
58 /* Set a bit in a bit array */
59 extern void setbit(
60 int which,
61 int *bitmap);
62
63 /* Clear a bit in a bit array */
64 extern void clrbit(
65 int which,
66 int *bitmap);
67
68 /* Find the first set bit in a bit array */
69 extern int ffsbit(
70 int *bitmap);
71 extern int ffs(
72 unsigned int mask);
73 extern int ffsll(
74 unsigned long long mask);
75
76 /* Find the last set bit in a bit array */
77 extern int fls(
78 unsigned int mask);
79 extern int flsll(
80 unsigned long long mask);
81
82 /*
83 * Test if indicated bit is set in bit string.
84 */
85 extern int testbit(
86 int which,
87 int *bitmap);
88
89 /*
90 * Move an aligned 32 or 64-bit word from user space to kernel space
91 * using a single read instruction
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.
104 *
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, ...)
111 */
112 extern int copyin_atomic32_wait_if_equals(
113 const user_addr_t user_addr,
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);
127
128 /* Move a NUL-terminated string from a user space to kernel space */
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);
134
135 /* Move arbitrarily-aligned data from a user space to kernel space */
136 extern int copyinmsg(
137 const user_addr_t user_addr,
138 char *kernel_addr,
139 mach_msg_size_t nbytes);
140
141 /* Move arbitrarily-aligned data from a kernel space to user space */
142 extern int copyoutmsg(
143 const char *kernel_addr,
144 user_addr_t user_addr,
145 mach_msg_size_t nbytes);
146
147 /* Invalidate copy window(s) cache */
148 extern void inval_copy_windows(thread_t);
149 extern void copy_window_fault(thread_t, vm_map_t, int);
150
151 extern int sscanf(const char *input, const char *fmt, ...) __scanflike(2, 3);
152
153 /* sprintf() is being deprecated. Please use snprintf() instead. */
154 extern integer_t sprintf(char *buf, const char *fmt, ...) __deprecated;
155
156 extern int printf(const char *format, ...) __printflike(1, 2);
157 extern int vprintf(const char *format, va_list ap);
158
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
171 extern int paniclog_append_noflush(const char *format, ...) __printflike(1, 2);
172
173 extern int kdb_printf(const char *format, ...) __printflike(1, 2);
174
175 extern int kdb_log(const char *format, ...) __printflike(1, 2);
176
177 extern int kdb_printf_unbuffered(const char *format, ...) __printflike(1, 2);
178
179 extern void printf_init(void);
180
181 extern int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
182 extern int scnprintf(char *, size_t, const char *, ...) __printflike(3, 4);
183
184 extern void log(int level, char *fmt, ...);
185
186 void
187 _doprnt(
188 const char *fmt,
189 va_list *argp,
190 void (*putc)(char),
191 int radix);
192
193 void
194 _doprnt_log(
195 const char *fmt,
196 va_list *argp,
197 void (*putc)(char),
198 int radix);
199
200 int
201 __doprnt(
202 const char *fmt,
203 va_list argp,
204 void (*putc)(int, void *),
205 void *arg,
206 int radix,
207 int is_log);
208
209 extern void safe_gets(
210 char *str,
211 int maxlen);
212
213 extern void cnputcusr(char);
214
215 extern void cnputsusr(char *, int);
216
217 extern void conslog_putc(char);
218
219 extern void cons_putc_locked(char);
220
221 extern void consdebug_putc(char);
222
223 extern void consdebug_log(char);
224
225 extern void consdebug_putc_unbuffered(char);
226
227 extern void cnputc(char);
228
229 extern void cnputc_unbuffered(char);
230
231 extern void console_write(char *, int);
232
233 extern void console_suspend(void);
234
235 extern void console_resume(void);
236
237 extern int cngetc(void);
238
239 extern int cnmaygetc(void);
240
241 extern int _setjmp(
242 jmp_buf_t *jmp_buf);
243
244 extern int _longjmp(
245 jmp_buf_t *jmp_buf,
246 int value);
247
248 extern void bootstrap_create(void);
249
250 #if DIPC
251 extern boolean_t no_bootstrap_task(void);
252 extern ipc_port_t get_root_master_device_port(void);
253 #endif /* DIPC */
254
255 extern kern_return_t kernel_set_special_port(
256 host_priv_t host_priv,
257 int which,
258 ipc_port_t port);
259
260 extern kern_return_t kernel_get_special_port(
261 host_priv_t host_priv,
262 int which,
263 ipc_port_t *portp);
264
265 user_addr_t get_useraddr(void);
266
267 /* symbol lookup */
268 struct kmod_info_t;
269
270 extern uint64_t early_random(void);
271
272 #endif /* _MISC_PROTOS_H_ */