2 * Copyright (c) 2010-2014 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #include "_libkernel_init.h"
32 extern _libkernel_functions_t _libkernel_functions
;
33 extern void mig_os_release(void* ptr
);
35 __attribute__((visibility("hidden")))
39 return _libkernel_functions
->malloc(size
);
42 __attribute__((visibility("hidden")))
46 return _libkernel_functions
->free(ptr
);
49 __attribute__((visibility("hidden")))
51 realloc(void *ptr
, size_t size
)
53 return _libkernel_functions
->realloc(ptr
, size
);
56 __attribute__((visibility("hidden")))
58 reallocf(void *ptr
, size_t size
)
60 void *nptr
= realloc(ptr
, size
);
67 __attribute__((visibility("hidden")))
69 _pthread_exit_if_canceled(int error
)
71 return _libkernel_functions
->_pthread_exit_if_canceled(error
);
74 __attribute__((visibility("hidden")))
76 _pthread_set_self(void *ptr
__attribute__((__unused__
)))
80 __attribute__((visibility("hidden")))
82 _pthread_clear_qos_tsd(mach_port_t thread_port
)
84 if (_libkernel_functions
->version
>= 3 &&
85 _libkernel_functions
->pthread_clear_qos_tsd
) {
86 return _libkernel_functions
->pthread_clear_qos_tsd(thread_port
);
91 * Upcalls to optimized libplatform string functions
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
,
105 static _libkernel_string_functions_t _libkernel_string_functions
=
106 &_libkernel_generic_string_functions
;
109 __libkernel_platform_init(_libkernel_string_functions_t fns
)
111 _libkernel_string_functions
= fns
;
115 __attribute__((visibility("hidden")))
117 bzero(void *s
, size_t n
)
119 return _libkernel_string_functions
->bzero(s
, n
);
122 __attribute__((visibility("hidden")))
124 memchr(const void *s
, int c
, size_t n
)
126 return _libkernel_string_functions
->memchr(s
, c
, n
);
129 __attribute__((visibility("hidden")))
131 memcmp(const void *s1
, const void *s2
, size_t n
)
133 return _libkernel_string_functions
->memcmp(s1
, s2
, n
);
136 __attribute__((visibility("hidden")))
138 memmove(void *dst
, const void *src
, size_t n
)
140 return _libkernel_string_functions
->memmove(dst
, src
, n
);
143 __attribute__((visibility("hidden")))
145 memcpy(void *dst
, const void *src
, size_t n
)
147 return _libkernel_string_functions
->memmove(dst
, src
, n
);
150 __attribute__((visibility("hidden")))
152 memccpy(void *__restrict dst
, const void *__restrict src
, int c
, size_t n
)
154 return _libkernel_string_functions
->memccpy(dst
, src
, c
, n
);
157 __attribute__((visibility("hidden")))
159 memset(void *b
, int c
, size_t len
)
161 return _libkernel_string_functions
->memset(b
, c
, len
);
164 __attribute__((visibility("hidden")))
166 strchr(const char *s
, int c
)
168 return _libkernel_string_functions
->strchr(s
, c
);
171 __attribute__((visibility("hidden")))
173 index(const char *s
, int c
)
175 return _libkernel_string_functions
->strchr(s
, c
);
178 __attribute__((visibility("hidden")))
180 strcmp(const char *s1
, const char *s2
)
182 return _libkernel_string_functions
->strcmp(s1
, s2
);
185 __attribute__((visibility("hidden")))
187 strcpy(char * restrict dst
, const char * restrict src
)
189 return _libkernel_string_functions
->strcpy(dst
, src
);
192 __attribute__((visibility("hidden")))
194 strlcat(char * restrict dst
, const char * restrict src
, size_t maxlen
)
196 return _libkernel_string_functions
->strlcat(dst
, src
, maxlen
);
199 __attribute__((visibility("hidden")))
201 strlcpy(char * restrict dst
, const char * restrict src
, size_t maxlen
)
203 return _libkernel_string_functions
->strlcpy(dst
, src
, maxlen
);
206 __attribute__((visibility("hidden")))
208 strlen(const char *str
)
210 return _libkernel_string_functions
->strlen(str
);
213 __attribute__((visibility("hidden")))
215 strncmp(const char *s1
, const char *s2
, size_t n
)
217 return _libkernel_string_functions
->strncmp(s1
, s2
, n
);
220 __attribute__((visibility("hidden")))
222 strncpy(char * restrict dst
, const char * restrict src
, size_t maxlen
)
224 return _libkernel_string_functions
->strncpy(dst
, src
, maxlen
);
227 __attribute__((visibility("hidden")))
229 strnlen(const char *s
, size_t maxlen
)
231 return _libkernel_string_functions
->strnlen(s
, maxlen
);
234 __attribute__((visibility("hidden")))
236 strstr(const char *s
, const char *find
)
238 return _libkernel_string_functions
->strstr(s
, find
);
242 * mach/mach.h voucher_mach_msg API
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
;
251 __libkernel_voucher_init(_libkernel_voucher_functions_t fns
)
253 _libkernel_voucher_functions
= fns
;
258 voucher_mach_msg_set(mach_msg_header_t
*msg
)
260 if (_libkernel_voucher_functions
->voucher_mach_msg_set
) {
261 return _libkernel_voucher_functions
->voucher_mach_msg_set(msg
);
267 voucher_mach_msg_clear(mach_msg_header_t
*msg
)
269 if (_libkernel_voucher_functions
->voucher_mach_msg_clear
) {
270 return _libkernel_voucher_functions
->voucher_mach_msg_clear(msg
);
274 voucher_mach_msg_state_t
275 voucher_mach_msg_adopt(mach_msg_header_t
*msg
)
277 if (_libkernel_voucher_functions
->voucher_mach_msg_adopt
) {
278 return _libkernel_voucher_functions
->voucher_mach_msg_adopt(msg
);
280 return VOUCHER_MACH_MSG_STATE_UNCHANGED
;
284 voucher_mach_msg_revert(voucher_mach_msg_state_t state
)
286 if (_libkernel_voucher_functions
->voucher_mach_msg_revert
) {
287 return _libkernel_voucher_functions
->voucher_mach_msg_revert(state
);