]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/misc_protos.h
xnu-4570.1.46.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
50 #ifndef MIN
51 #define MIN(a,b) (((a)<(b))?(a):(b))
52 #endif /* MIN */
53 #ifndef MAX
54 #define MAX(a,b) (((a)>(b))?(a):(b))
55 #endif /* MAX */
56
57 /* Set a bit in a bit array */
58 extern void setbit(
59 int which,
60 int *bitmap);
61
62 /* Clear a bit in a bit array */
63 extern void clrbit(
64 int which,
65 int *bitmap);
66
67 /* Find the first set bit in a bit array */
68 extern int ffsbit(
69 int *bitmap);
70 extern int ffs(
71 unsigned int mask);
72 extern int ffsll(
73 unsigned long long mask);
74
75 /* Find the last set bit in a bit array */
76 extern int fls(
77 unsigned int mask);
78 extern int flsll(
79 unsigned long long mask);
80
81 /*
82 * Test if indicated bit is set in bit string.
83 */
84 extern int testbit(
85 int which,
86 int *bitmap);
87
88 /* Move arbitrarily-aligned data from a user space to kernel space */
89 extern int copyin(
90 const user_addr_t user_addr,
91 char *kernel_addr,
92 vm_size_t nbytes);
93
94 /* Move an aligned 32 or 64-bit word from user space to kernel space
95 * using a single read instruction
96 *
97 * when reading a 32-bit word, the value is 0-extended into the kernel space
98 * 64-bit buffer passed as `kernel_addr`
99 * (think `*kernel_addr = *(uint32_t *)user_addr`)
100 */
101 extern int copyin_word(
102 const user_addr_t user_addr,
103 uint64_t *kernel_addr,
104 vm_size_t nbytes);
105
106 /* Move a NUL-terminated string from a user space to kernel space */
107 extern int copyinstr(
108 const user_addr_t user_addr,
109 char *kernel_addr,
110 vm_size_t max,
111 vm_size_t *actual);
112
113 /* Move arbitrarily-aligned data from a user space to kernel space */
114 extern int copyinmsg(
115 const user_addr_t user_addr,
116 char *kernel_addr,
117 mach_msg_size_t nbytes);
118
119 /* Move arbitrarily-aligned data from a kernel space to user space */
120 extern int copyout(
121 const void *kernel_addr,
122 user_addr_t user_addr,
123 vm_size_t nbytes);
124
125 /* Move arbitrarily-aligned data from a kernel space to user space */
126 extern int copyoutmsg(
127 const char *kernel_addr,
128 user_addr_t user_addr,
129 mach_msg_size_t nbytes);
130
131 /* Invalidate copy window(s) cache */
132 extern void inval_copy_windows(thread_t);
133 extern void copy_window_fault(thread_t, vm_map_t, int);
134
135 extern int copyin_validate(const user_addr_t, uintptr_t, vm_size_t);
136 extern int copyout_validate(uintptr_t, const user_addr_t, vm_size_t);
137
138 extern int sscanf(const char *input, const char *fmt, ...) __scanflike(2,3);
139
140 /* sprintf() is being deprecated. Please use snprintf() instead. */
141 extern integer_t sprintf(char *buf, const char *fmt, ...) __deprecated;
142
143 extern int printf(const char *format, ...) __printflike(1,2);
144 extern int vprintf(const char *format, va_list ap);
145
146 #if KERNEL_PRIVATE
147 int _consume_printf_args(int, ...);
148 #endif
149
150 #if CONFIG_NO_PRINTF_STRINGS
151 #if KERNEL_PRIVATE
152 #define printf(x, ...) _consume_printf_args( 0, ## __VA_ARGS__ )
153 #else
154 #define printf(x, ...) do {} while (0)
155 #endif
156 #endif
157
158 extern int paniclog_append_noflush(const char *format, ...) __printflike(1,2);
159
160 extern int kdb_printf(const char *format, ...) __printflike(1,2);
161
162 extern int kdb_log(const char *format, ...) __printflike(1,2);
163
164 extern int kdb_printf_unbuffered(const char *format, ...) __printflike(1,2);
165
166 extern void printf_init(void);
167
168 extern int snprintf(char *, size_t, const char *, ...) __printflike(3,4);
169
170 extern void log(int level, char *fmt, ...);
171
172 void
173 _doprnt(
174 const char *fmt,
175 va_list *argp,
176 void (*putc)(char),
177 int radix);
178
179 void
180 _doprnt_log(
181 const char *fmt,
182 va_list *argp,
183 void (*putc)(char),
184 int radix);
185
186 int
187 __doprnt(
188 const char *fmt,
189 va_list argp,
190 void (*putc)(int, void *),
191 void *arg,
192 int radix,
193 int is_log);
194
195 extern void safe_gets(
196 char *str,
197 int maxlen);
198
199 extern void cnputcusr(char);
200
201 extern void cnputsusr(char *, int);
202
203 extern void conslog_putc(char);
204
205 extern void cons_putc_locked(char);
206
207 extern void consdebug_putc(char);
208
209 extern void consdebug_log(char);
210
211 extern void consdebug_putc_unbuffered(char);
212
213 extern void cnputc(char);
214
215 extern void cnputc_unbuffered(char);
216
217 extern void console_write(char *, int);
218
219 extern void console_suspend(void);
220
221 extern void console_resume(void);
222
223 extern int cngetc(void);
224
225 extern int cnmaygetc(void);
226
227 extern int _setjmp(
228 jmp_buf_t *jmp_buf);
229
230 extern int _longjmp(
231 jmp_buf_t *jmp_buf,
232 int value);
233
234 extern void bootstrap_create(void);
235
236 #if DIPC
237 extern boolean_t no_bootstrap_task(void);
238 extern ipc_port_t get_root_master_device_port(void);
239 #endif /* DIPC */
240
241 extern kern_return_t kernel_set_special_port(
242 host_priv_t host_priv,
243 int which,
244 ipc_port_t port);
245
246 extern kern_return_t kernel_get_special_port(
247 host_priv_t host_priv,
248 int which,
249 ipc_port_t *portp);
250
251 user_addr_t get_useraddr(void);
252
253 /* symbol lookup */
254 struct kmod_info_t;
255
256 extern uint64_t early_random(void);
257
258 #endif /* _MISC_PROTOS_H_ */