]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/misc_protos.h
xnu-7195.81.3.tar.gz
[apple/xnu.git] / osfmk / kern / misc_protos.h
CommitLineData
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 */
59extern void setbit(
0a7de745
A
60 int which,
61 int *bitmap);
1c79356b
A
62
63/* Clear a bit in a bit array */
64extern void clrbit(
0a7de745
A
65 int which,
66 int *bitmap);
1c79356b
A
67
68/* Find the first set bit in a bit array */
69extern int ffsbit(
0a7de745 70 int *bitmap);
1c79356b 71extern int ffs(
0a7de745 72 unsigned int mask);
5ba3f43e
A
73extern int ffsll(
74 unsigned long long mask);
75
76/* Find the last set bit in a bit array */
77extern int fls(
0a7de745 78 unsigned int mask);
5ba3f43e
A
79extern int flsll(
80 unsigned long long mask);
1c79356b
A
81
82/*
83 * Test if indicated bit is set in bit string.
84 */
85extern 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 */
93extern int copyin_atomic32(
94 const user_addr_t user_addr,
95 uint32_t *kernel_addr);
96
97extern 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 112extern 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 */
120extern int copyout_atomic32(
121 uint32_t u32,
122 user_addr_t user_addr);
123
124extern 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
129extern 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
136extern 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
142extern int copyoutmsg(
143 const char *kernel_addr,
144 user_addr_t user_addr,
1c79356b
A
145 mach_msg_size_t nbytes);
146
0a7de745 147extern int sscanf(const char *input, const char *fmt, ...) __scanflike(2, 3);
0c530ab8 148
0a7de745 149/* sprintf() is being deprecated. Please use snprintf() instead. */
f427ee49 150extern integer_t sprintf(char *buf, const char *fmt, ...) __printflike(2, 3) __deprecated;
1c79356b 151
0a7de745 152extern int printf(const char *format, ...) __printflike(1, 2);
39037602 153extern int vprintf(const char *format, va_list ap);
1c79356b 154
b0d623f7
A
155#if KERNEL_PRIVATE
156int _consume_printf_args(int, ...);
157#endif
158
159#if CONFIG_NO_PRINTF_STRINGS
160#if KERNEL_PRIVATE
161#define printf(x, ...) _consume_printf_args( 0, ## __VA_ARGS__ )
162#else
163#define printf(x, ...) do {} while (0)
164#endif
165#endif
166
0a7de745 167extern int paniclog_append_noflush(const char *format, ...) __printflike(1, 2);
5ba3f43e 168
0a7de745 169extern int kdb_printf(const char *format, ...) __printflike(1, 2);
9bccf70c 170
0a7de745 171extern int kdb_log(const char *format, ...) __printflike(1, 2);
c910b4d9 172
0a7de745 173extern int kdb_printf_unbuffered(const char *format, ...) __printflike(1, 2);
b0d623f7 174
0a7de745 175extern int snprintf(char *, size_t, const char *, ...) __printflike(3, 4);
4ba76501 176extern int scnprintf(char *, size_t, const char *, ...) __printflike(3, 4);
593a1d5f 177
f427ee49 178extern void log(int level, char *fmt, ...) __printflike(2, 3);
1c79356b 179
0a7de745 180void
1c79356b 181_doprnt(
0a7de745
A
182 const char *fmt,
183 va_list *argp,
184 void (*putc)(char),
185 int radix);
3e170ce0
A
186
187void
188_doprnt_log(
0a7de745
A
189 const char *fmt,
190 va_list *argp,
191 void (*putc)(char),
192 int radix);
3e170ce0 193
9bccf70c
A
194int
195__doprnt(
0a7de745
A
196 const char *fmt,
197 va_list argp,
198 void (*putc)(int, void *),
9bccf70c 199 void *arg,
0a7de745
A
200 int radix,
201 int is_log);
1c79356b
A
202
203extern void safe_gets(
0a7de745
A
204 char *str,
205 int maxlen);
1c79356b
A
206
207extern void cnputcusr(char);
208
5ba3f43e
A
209extern void cnputsusr(char *, int);
210
9bccf70c
A
211extern void conslog_putc(char);
212
6d2010ae
A
213extern void cons_putc_locked(char);
214
9bccf70c
A
215extern void consdebug_putc(char);
216
c910b4d9
A
217extern void consdebug_log(char);
218
b0d623f7
A
219extern void consdebug_putc_unbuffered(char);
220
1c79356b
A
221extern void cnputc(char);
222
b0d623f7
A
223extern void cnputc_unbuffered(char);
224
39037602
A
225extern void console_write(char *, int);
226
227extern void console_suspend(void);
228
229extern void console_resume(void);
230
1c79356b
A
231extern int cngetc(void);
232
233extern int cnmaygetc(void);
234
235extern int _setjmp(
0a7de745 236 jmp_buf_t *jmp_buf);
1c79356b
A
237
238extern int _longjmp(
0a7de745
A
239 jmp_buf_t *jmp_buf,
240 int value);
1c79356b
A
241
242extern void bootstrap_create(void);
243
0a7de745
A
244#if DIPC
245extern boolean_t no_bootstrap_task(void);
246extern ipc_port_t get_root_master_device_port(void);
247#endif /* DIPC */
1c79356b 248
0a7de745
A
249extern kern_return_t kernel_set_special_port(
250 host_priv_t host_priv,
251 int which,
252 ipc_port_t port);
55e303ae 253
0a7de745
A
254extern kern_return_t kernel_get_special_port(
255 host_priv_t host_priv,
256 int which,
257 ipc_port_t *portp);
39037602 258
2d21ac55
A
259user_addr_t get_useraddr(void);
260
261/* symbol lookup */
f427ee49 262#ifndef __cplusplus
2d21ac55 263struct kmod_info_t;
f427ee49 264#endif
2d21ac55 265
316670eb
A
266extern uint64_t early_random(void);
267
0a7de745 268#endif /* _MISC_PROTOS_H_ */