]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
fe8ab488 | 2 | * Copyright (c) 2010-2014 Apple Inc. All rights reserved. |
5d5c5d0d | 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 | 27 | */ |
1c79356b | 28 | |
39236c6e | 29 | #include "_libkernel_init.h" |
d9a64523 A |
30 | #include "strings.h" |
31 | ||
39236c6e | 32 | extern _libkernel_functions_t _libkernel_functions; |
fe8ab488 | 33 | extern void mig_os_release(void* ptr); |
6d2010ae | 34 | |
39236c6e A |
35 | __attribute__((visibility("hidden"))) |
36 | void * | |
37 | malloc(size_t size) | |
38 | { | |
39 | return _libkernel_functions->malloc(size); | |
40 | } | |
1c79356b | 41 | |
39236c6e | 42 | __attribute__((visibility("hidden"))) |
6d2010ae | 43 | void |
39236c6e | 44 | free(void *ptr) |
1c79356b | 45 | { |
39236c6e | 46 | return _libkernel_functions->free(ptr); |
1c79356b A |
47 | } |
48 | ||
39236c6e A |
49 | __attribute__((visibility("hidden"))) |
50 | void * | |
51 | realloc(void *ptr, size_t size) | |
1c79356b | 52 | { |
39236c6e | 53 | return _libkernel_functions->realloc(ptr, size); |
1c79356b | 54 | } |
91447636 | 55 | |
39236c6e A |
56 | __attribute__((visibility("hidden"))) |
57 | void * | |
58 | reallocf(void *ptr, size_t size) | |
1c79356b | 59 | { |
39236c6e | 60 | void *nptr = realloc(ptr, size); |
0a7de745 | 61 | if (!nptr && ptr) { |
39236c6e | 62 | free(ptr); |
0a7de745 A |
63 | } |
64 | return nptr; | |
1c79356b A |
65 | } |
66 | ||
39236c6e | 67 | __attribute__((visibility("hidden"))) |
6d2010ae | 68 | void |
39236c6e | 69 | _pthread_exit_if_canceled(int error) |
6d2010ae | 70 | { |
39236c6e | 71 | return _libkernel_functions->_pthread_exit_if_canceled(error); |
6d2010ae | 72 | } |
91447636 | 73 | |
39236c6e | 74 | __attribute__((visibility("hidden"))) |
6d2010ae | 75 | void |
0a7de745 A |
76 | _pthread_set_self(void *ptr __attribute__((__unused__))) |
77 | { | |
78 | } | |
fe8ab488 A |
79 | |
80 | __attribute__((visibility("hidden"))) | |
81 | void | |
82 | _pthread_clear_qos_tsd(mach_port_t thread_port) | |
83 | { | |
84 | if (_libkernel_functions->version >= 3 && | |
0a7de745 | 85 | _libkernel_functions->pthread_clear_qos_tsd) { |
fe8ab488 A |
86 | return _libkernel_functions->pthread_clear_qos_tsd(thread_port); |
87 | } | |
88 | } | |
89 | ||
ea3f0419 A |
90 | __attribute__((visibility("hidden"))) |
91 | int | |
92 | pthread_current_stack_contains_np(const void *addr, size_t len) | |
93 | { | |
94 | if (_libkernel_functions->version >= 4 && | |
95 | _libkernel_functions->pthread_current_stack_contains_np) { | |
96 | return _libkernel_functions->pthread_current_stack_contains_np(addr, len); | |
97 | } | |
98 | ||
99 | return 0; | |
100 | } | |
101 | ||
d9a64523 A |
102 | /* |
103 | * Upcalls to optimized libplatform string functions | |
104 | */ | |
105 | ||
106 | static const struct _libkernel_string_functions | |
0a7de745 | 107 | _libkernel_generic_string_functions = { |
d9a64523 A |
108 | .bzero = _libkernel_bzero, |
109 | .memmove = _libkernel_memmove, | |
110 | .memset = _libkernel_memset, | |
111 | .strchr = _libkernel_strchr, | |
112 | .strcmp = _libkernel_strcmp, | |
113 | .strcpy = _libkernel_strcpy, | |
114 | .strlcpy = _libkernel_strlcpy, | |
115 | .strlen = _libkernel_strlen, | |
116 | }; | |
117 | static _libkernel_string_functions_t _libkernel_string_functions = | |
0a7de745 | 118 | &_libkernel_generic_string_functions; |
d9a64523 A |
119 | |
120 | kern_return_t | |
121 | __libkernel_platform_init(_libkernel_string_functions_t fns) | |
122 | { | |
123 | _libkernel_string_functions = fns; | |
124 | return KERN_SUCCESS; | |
125 | } | |
126 | ||
127 | __attribute__((visibility("hidden"))) | |
128 | void | |
129 | bzero(void *s, size_t n) | |
130 | { | |
131 | return _libkernel_string_functions->bzero(s, n); | |
132 | } | |
133 | ||
f427ee49 A |
134 | __attribute__((visibility("hidden"))) |
135 | void | |
136 | __bzero(void *s, size_t n) | |
137 | { | |
138 | return _libkernel_string_functions->bzero(s, n); | |
139 | } | |
140 | ||
d9a64523 A |
141 | __attribute__((visibility("hidden"))) |
142 | void * | |
143 | memchr(const void *s, int c, size_t n) | |
144 | { | |
145 | return _libkernel_string_functions->memchr(s, c, n); | |
146 | } | |
147 | ||
148 | __attribute__((visibility("hidden"))) | |
149 | int | |
150 | memcmp(const void *s1, const void *s2, size_t n) | |
151 | { | |
152 | return _libkernel_string_functions->memcmp(s1, s2, n); | |
153 | } | |
154 | ||
155 | __attribute__((visibility("hidden"))) | |
156 | void * | |
157 | memmove(void *dst, const void *src, size_t n) | |
158 | { | |
159 | return _libkernel_string_functions->memmove(dst, src, n); | |
160 | } | |
161 | ||
162 | __attribute__((visibility("hidden"))) | |
163 | void * | |
164 | memcpy(void *dst, const void *src, size_t n) | |
165 | { | |
166 | return _libkernel_string_functions->memmove(dst, src, n); | |
167 | } | |
168 | ||
169 | __attribute__((visibility("hidden"))) | |
170 | void * | |
171 | memccpy(void *__restrict dst, const void *__restrict src, int c, size_t n) | |
172 | { | |
173 | return _libkernel_string_functions->memccpy(dst, src, c, n); | |
174 | } | |
175 | ||
176 | __attribute__((visibility("hidden"))) | |
177 | void * | |
178 | memset(void *b, int c, size_t len) | |
179 | { | |
180 | return _libkernel_string_functions->memset(b, c, len); | |
181 | } | |
182 | ||
183 | __attribute__((visibility("hidden"))) | |
184 | char * | |
185 | strchr(const char *s, int c) | |
186 | { | |
187 | return _libkernel_string_functions->strchr(s, c); | |
188 | } | |
189 | ||
190 | __attribute__((visibility("hidden"))) | |
191 | char * | |
192 | index(const char *s, int c) | |
193 | { | |
194 | return _libkernel_string_functions->strchr(s, c); | |
195 | } | |
196 | ||
197 | __attribute__((visibility("hidden"))) | |
198 | int | |
199 | strcmp(const char *s1, const char *s2) | |
200 | { | |
201 | return _libkernel_string_functions->strcmp(s1, s2); | |
202 | } | |
203 | ||
204 | __attribute__((visibility("hidden"))) | |
205 | char * | |
206 | strcpy(char * restrict dst, const char * restrict src) | |
207 | { | |
208 | return _libkernel_string_functions->strcpy(dst, src); | |
209 | } | |
210 | ||
211 | __attribute__((visibility("hidden"))) | |
212 | size_t | |
213 | strlcat(char * restrict dst, const char * restrict src, size_t maxlen) | |
214 | { | |
215 | return _libkernel_string_functions->strlcat(dst, src, maxlen); | |
216 | } | |
217 | ||
218 | __attribute__((visibility("hidden"))) | |
219 | size_t | |
220 | strlcpy(char * restrict dst, const char * restrict src, size_t maxlen) | |
221 | { | |
222 | return _libkernel_string_functions->strlcpy(dst, src, maxlen); | |
223 | } | |
224 | ||
225 | __attribute__((visibility("hidden"))) | |
226 | size_t | |
227 | strlen(const char *str) | |
228 | { | |
229 | return _libkernel_string_functions->strlen(str); | |
230 | } | |
231 | ||
232 | __attribute__((visibility("hidden"))) | |
233 | int | |
234 | strncmp(const char *s1, const char *s2, size_t n) | |
235 | { | |
236 | return _libkernel_string_functions->strncmp(s1, s2, n); | |
237 | } | |
238 | ||
239 | __attribute__((visibility("hidden"))) | |
240 | char * | |
241 | strncpy(char * restrict dst, const char * restrict src, size_t maxlen) | |
242 | { | |
243 | return _libkernel_string_functions->strncpy(dst, src, maxlen); | |
244 | } | |
245 | ||
246 | __attribute__((visibility("hidden"))) | |
247 | size_t | |
248 | strnlen(const char *s, size_t maxlen) | |
249 | { | |
250 | return _libkernel_string_functions->strnlen(s, maxlen); | |
251 | } | |
252 | ||
253 | __attribute__((visibility("hidden"))) | |
254 | char * | |
255 | strstr(const char *s, const char *find) | |
256 | { | |
257 | return _libkernel_string_functions->strstr(s, find); | |
258 | } | |
259 | ||
fe8ab488 A |
260 | /* |
261 | * mach/mach.h voucher_mach_msg API | |
262 | */ | |
263 | ||
264 | static const struct _libkernel_voucher_functions | |
0a7de745 | 265 | _libkernel_voucher_functions_empty; |
fe8ab488 | 266 | static _libkernel_voucher_functions_t _libkernel_voucher_functions = |
0a7de745 | 267 | &_libkernel_voucher_functions_empty; |
fe8ab488 A |
268 | |
269 | kern_return_t | |
270 | __libkernel_voucher_init(_libkernel_voucher_functions_t fns) | |
271 | { | |
272 | _libkernel_voucher_functions = fns; | |
273 | return KERN_SUCCESS; | |
274 | } | |
275 | ||
276 | boolean_t | |
277 | voucher_mach_msg_set(mach_msg_header_t *msg) | |
278 | { | |
279 | if (_libkernel_voucher_functions->voucher_mach_msg_set) { | |
280 | return _libkernel_voucher_functions->voucher_mach_msg_set(msg); | |
281 | } | |
282 | return 0; | |
283 | } | |
284 | ||
285 | void | |
286 | voucher_mach_msg_clear(mach_msg_header_t *msg) | |
287 | { | |
288 | if (_libkernel_voucher_functions->voucher_mach_msg_clear) { | |
289 | return _libkernel_voucher_functions->voucher_mach_msg_clear(msg); | |
290 | } | |
291 | } | |
292 | ||
293 | voucher_mach_msg_state_t | |
294 | voucher_mach_msg_adopt(mach_msg_header_t *msg) | |
295 | { | |
296 | if (_libkernel_voucher_functions->voucher_mach_msg_adopt) { | |
297 | return _libkernel_voucher_functions->voucher_mach_msg_adopt(msg); | |
298 | } | |
299 | return VOUCHER_MACH_MSG_STATE_UNCHANGED; | |
300 | } | |
301 | ||
302 | void | |
303 | voucher_mach_msg_revert(voucher_mach_msg_state_t state) | |
304 | { | |
305 | if (_libkernel_voucher_functions->voucher_mach_msg_revert) { | |
306 | return _libkernel_voucher_functions->voucher_mach_msg_revert(state); | |
307 | } | |
308 | } |