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