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