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