1*bbb1b6f9SApple OSS Distributions /*
2*bbb1b6f9SApple OSS Distributions * Copyright (c) 2010-2014 Apple Inc. All rights reserved.
3*bbb1b6f9SApple OSS Distributions *
4*bbb1b6f9SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*bbb1b6f9SApple OSS Distributions *
6*bbb1b6f9SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
7*bbb1b6f9SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
8*bbb1b6f9SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
9*bbb1b6f9SApple OSS Distributions * compliance with the License. The rights granted to you under the License
10*bbb1b6f9SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
11*bbb1b6f9SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
12*bbb1b6f9SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
13*bbb1b6f9SApple OSS Distributions * terms of an Apple operating system software license agreement.
14*bbb1b6f9SApple OSS Distributions *
15*bbb1b6f9SApple OSS Distributions * Please obtain a copy of the License at
16*bbb1b6f9SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*bbb1b6f9SApple OSS Distributions *
18*bbb1b6f9SApple OSS Distributions * The Original Code and all software distributed under the License are
19*bbb1b6f9SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*bbb1b6f9SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*bbb1b6f9SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*bbb1b6f9SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*bbb1b6f9SApple OSS Distributions * Please see the License for the specific language governing rights and
24*bbb1b6f9SApple OSS Distributions * limitations under the License.
25*bbb1b6f9SApple OSS Distributions *
26*bbb1b6f9SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*bbb1b6f9SApple OSS Distributions */
28*bbb1b6f9SApple OSS Distributions
29*bbb1b6f9SApple OSS Distributions #include "_libkernel_init.h"
30*bbb1b6f9SApple OSS Distributions #include "strings.h"
31*bbb1b6f9SApple OSS Distributions
32*bbb1b6f9SApple OSS Distributions extern _libkernel_functions_t _libkernel_functions;
33*bbb1b6f9SApple OSS Distributions extern void mig_os_release(void* ptr);
34*bbb1b6f9SApple OSS Distributions
35*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
36*bbb1b6f9SApple OSS Distributions void *
malloc(size_t size)37*bbb1b6f9SApple OSS Distributions malloc(size_t size)
38*bbb1b6f9SApple OSS Distributions {
39*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->malloc) {
40*bbb1b6f9SApple OSS Distributions return _libkernel_functions->malloc(size);
41*bbb1b6f9SApple OSS Distributions }
42*bbb1b6f9SApple OSS Distributions return NULL;
43*bbb1b6f9SApple OSS Distributions }
44*bbb1b6f9SApple OSS Distributions
45*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
46*bbb1b6f9SApple OSS Distributions void
free(void * ptr)47*bbb1b6f9SApple OSS Distributions free(void *ptr)
48*bbb1b6f9SApple OSS Distributions {
49*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->free) {
50*bbb1b6f9SApple OSS Distributions _libkernel_functions->free(ptr);
51*bbb1b6f9SApple OSS Distributions }
52*bbb1b6f9SApple OSS Distributions }
53*bbb1b6f9SApple OSS Distributions
54*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
55*bbb1b6f9SApple OSS Distributions void *
realloc(void * ptr,size_t size)56*bbb1b6f9SApple OSS Distributions realloc(void *ptr, size_t size)
57*bbb1b6f9SApple OSS Distributions {
58*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->realloc) {
59*bbb1b6f9SApple OSS Distributions return _libkernel_functions->realloc(ptr, size);
60*bbb1b6f9SApple OSS Distributions }
61*bbb1b6f9SApple OSS Distributions return NULL;
62*bbb1b6f9SApple OSS Distributions }
63*bbb1b6f9SApple OSS Distributions
64*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
65*bbb1b6f9SApple OSS Distributions void *
reallocf(void * ptr,size_t size)66*bbb1b6f9SApple OSS Distributions reallocf(void *ptr, size_t size)
67*bbb1b6f9SApple OSS Distributions {
68*bbb1b6f9SApple OSS Distributions void *nptr = realloc(ptr, size);
69*bbb1b6f9SApple OSS Distributions if (!nptr && ptr) {
70*bbb1b6f9SApple OSS Distributions free(ptr);
71*bbb1b6f9SApple OSS Distributions }
72*bbb1b6f9SApple OSS Distributions return nptr;
73*bbb1b6f9SApple OSS Distributions }
74*bbb1b6f9SApple OSS Distributions
75*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
76*bbb1b6f9SApple OSS Distributions void *
malloc_type_malloc(size_t size,malloc_type_id_t type_id)77*bbb1b6f9SApple OSS Distributions malloc_type_malloc(size_t size, malloc_type_id_t type_id)
78*bbb1b6f9SApple OSS Distributions {
79*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->version >= 5) {
80*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->malloc_type_malloc) {
81*bbb1b6f9SApple OSS Distributions return _libkernel_functions->malloc_type_malloc(size, type_id);
82*bbb1b6f9SApple OSS Distributions }
83*bbb1b6f9SApple OSS Distributions }
84*bbb1b6f9SApple OSS Distributions return malloc(size);
85*bbb1b6f9SApple OSS Distributions }
86*bbb1b6f9SApple OSS Distributions
87*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
88*bbb1b6f9SApple OSS Distributions void
malloc_type_free(void * ptr,malloc_type_id_t type_id)89*bbb1b6f9SApple OSS Distributions malloc_type_free(void *ptr, malloc_type_id_t type_id)
90*bbb1b6f9SApple OSS Distributions {
91*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->version >= 5) {
92*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->malloc_type_free) {
93*bbb1b6f9SApple OSS Distributions return _libkernel_functions->malloc_type_free(ptr, type_id);
94*bbb1b6f9SApple OSS Distributions }
95*bbb1b6f9SApple OSS Distributions }
96*bbb1b6f9SApple OSS Distributions return free(ptr);
97*bbb1b6f9SApple OSS Distributions }
98*bbb1b6f9SApple OSS Distributions
99*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
100*bbb1b6f9SApple OSS Distributions void *
malloc_type_realloc(void * ptr,size_t size,malloc_type_id_t type_id)101*bbb1b6f9SApple OSS Distributions malloc_type_realloc(void *ptr, size_t size, malloc_type_id_t type_id)
102*bbb1b6f9SApple OSS Distributions {
103*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->version >= 5) {
104*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->malloc_type_realloc) {
105*bbb1b6f9SApple OSS Distributions return _libkernel_functions->malloc_type_realloc(ptr, size, type_id);
106*bbb1b6f9SApple OSS Distributions }
107*bbb1b6f9SApple OSS Distributions }
108*bbb1b6f9SApple OSS Distributions return realloc(ptr, size);
109*bbb1b6f9SApple OSS Distributions }
110*bbb1b6f9SApple OSS Distributions
111*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
112*bbb1b6f9SApple OSS Distributions void *
malloc_type_reallocf(void * ptr,size_t size,malloc_type_id_t type_id)113*bbb1b6f9SApple OSS Distributions malloc_type_reallocf(void *ptr, size_t size, malloc_type_id_t type_id)
114*bbb1b6f9SApple OSS Distributions {
115*bbb1b6f9SApple OSS Distributions void *nptr = malloc_type_realloc(ptr, size, type_id);
116*bbb1b6f9SApple OSS Distributions if (!nptr && ptr) {
117*bbb1b6f9SApple OSS Distributions free(ptr);
118*bbb1b6f9SApple OSS Distributions }
119*bbb1b6f9SApple OSS Distributions return nptr;
120*bbb1b6f9SApple OSS Distributions }
121*bbb1b6f9SApple OSS Distributions
122*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
123*bbb1b6f9SApple OSS Distributions void
_pthread_exit_if_canceled(int error)124*bbb1b6f9SApple OSS Distributions _pthread_exit_if_canceled(int error)
125*bbb1b6f9SApple OSS Distributions {
126*bbb1b6f9SApple OSS Distributions return _libkernel_functions->_pthread_exit_if_canceled(error);
127*bbb1b6f9SApple OSS Distributions }
128*bbb1b6f9SApple OSS Distributions
129*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
130*bbb1b6f9SApple OSS Distributions void
_pthread_set_self(void * ptr)131*bbb1b6f9SApple OSS Distributions _pthread_set_self(void *ptr __attribute__((__unused__)))
132*bbb1b6f9SApple OSS Distributions {
133*bbb1b6f9SApple OSS Distributions }
134*bbb1b6f9SApple OSS Distributions
135*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
136*bbb1b6f9SApple OSS Distributions void
_pthread_clear_qos_tsd(mach_port_t thread_port)137*bbb1b6f9SApple OSS Distributions _pthread_clear_qos_tsd(mach_port_t thread_port)
138*bbb1b6f9SApple OSS Distributions {
139*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->version >= 3 &&
140*bbb1b6f9SApple OSS Distributions _libkernel_functions->pthread_clear_qos_tsd) {
141*bbb1b6f9SApple OSS Distributions return _libkernel_functions->pthread_clear_qos_tsd(thread_port);
142*bbb1b6f9SApple OSS Distributions }
143*bbb1b6f9SApple OSS Distributions }
144*bbb1b6f9SApple OSS Distributions
145*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
146*bbb1b6f9SApple OSS Distributions int
pthread_current_stack_contains_np(const void * addr,size_t len)147*bbb1b6f9SApple OSS Distributions pthread_current_stack_contains_np(const void *addr, size_t len)
148*bbb1b6f9SApple OSS Distributions {
149*bbb1b6f9SApple OSS Distributions if (_libkernel_functions->version >= 4 &&
150*bbb1b6f9SApple OSS Distributions _libkernel_functions->pthread_current_stack_contains_np) {
151*bbb1b6f9SApple OSS Distributions return _libkernel_functions->pthread_current_stack_contains_np(addr, len);
152*bbb1b6f9SApple OSS Distributions }
153*bbb1b6f9SApple OSS Distributions
154*bbb1b6f9SApple OSS Distributions return 0;
155*bbb1b6f9SApple OSS Distributions }
156*bbb1b6f9SApple OSS Distributions
157*bbb1b6f9SApple OSS Distributions /*
158*bbb1b6f9SApple OSS Distributions * Upcalls to optimized libplatform string functions
159*bbb1b6f9SApple OSS Distributions */
160*bbb1b6f9SApple OSS Distributions
161*bbb1b6f9SApple OSS Distributions static const struct _libkernel_string_functions
162*bbb1b6f9SApple OSS Distributions _libkernel_generic_string_functions = {
163*bbb1b6f9SApple OSS Distributions .bzero = _libkernel_bzero,
164*bbb1b6f9SApple OSS Distributions .memmove = _libkernel_memmove,
165*bbb1b6f9SApple OSS Distributions .memset = _libkernel_memset,
166*bbb1b6f9SApple OSS Distributions .strchr = _libkernel_strchr,
167*bbb1b6f9SApple OSS Distributions .strcmp = _libkernel_strcmp,
168*bbb1b6f9SApple OSS Distributions .strcpy = _libkernel_strcpy,
169*bbb1b6f9SApple OSS Distributions .strlcpy = _libkernel_strlcpy,
170*bbb1b6f9SApple OSS Distributions .strlen = _libkernel_strlen,
171*bbb1b6f9SApple OSS Distributions };
172*bbb1b6f9SApple OSS Distributions static _libkernel_string_functions_t _libkernel_string_functions =
173*bbb1b6f9SApple OSS Distributions &_libkernel_generic_string_functions;
174*bbb1b6f9SApple OSS Distributions
175*bbb1b6f9SApple OSS Distributions kern_return_t
__libkernel_platform_init(_libkernel_string_functions_t fns)176*bbb1b6f9SApple OSS Distributions __libkernel_platform_init(_libkernel_string_functions_t fns)
177*bbb1b6f9SApple OSS Distributions {
178*bbb1b6f9SApple OSS Distributions _libkernel_string_functions = fns;
179*bbb1b6f9SApple OSS Distributions return KERN_SUCCESS;
180*bbb1b6f9SApple OSS Distributions }
181*bbb1b6f9SApple OSS Distributions
182*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
183*bbb1b6f9SApple OSS Distributions void
bzero(void * s,size_t n)184*bbb1b6f9SApple OSS Distributions bzero(void *s, size_t n)
185*bbb1b6f9SApple OSS Distributions {
186*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->bzero(s, n);
187*bbb1b6f9SApple OSS Distributions }
188*bbb1b6f9SApple OSS Distributions
189*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
190*bbb1b6f9SApple OSS Distributions void
__bzero(void * s,size_t n)191*bbb1b6f9SApple OSS Distributions __bzero(void *s, size_t n)
192*bbb1b6f9SApple OSS Distributions {
193*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->bzero(s, n);
194*bbb1b6f9SApple OSS Distributions }
195*bbb1b6f9SApple OSS Distributions
196*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
197*bbb1b6f9SApple OSS Distributions void *
memchr(const void * s,int c,size_t n)198*bbb1b6f9SApple OSS Distributions memchr(const void *s, int c, size_t n)
199*bbb1b6f9SApple OSS Distributions {
200*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->memchr(s, c, n);
201*bbb1b6f9SApple OSS Distributions }
202*bbb1b6f9SApple OSS Distributions
203*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
204*bbb1b6f9SApple OSS Distributions int
memcmp(const void * s1,const void * s2,size_t n)205*bbb1b6f9SApple OSS Distributions memcmp(const void *s1, const void *s2, size_t n)
206*bbb1b6f9SApple OSS Distributions {
207*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->memcmp(s1, s2, n);
208*bbb1b6f9SApple OSS Distributions }
209*bbb1b6f9SApple OSS Distributions
210*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
211*bbb1b6f9SApple OSS Distributions void *
memmove(void * dst,const void * src,size_t n)212*bbb1b6f9SApple OSS Distributions memmove(void *dst, const void *src, size_t n)
213*bbb1b6f9SApple OSS Distributions {
214*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->memmove(dst, src, n);
215*bbb1b6f9SApple OSS Distributions }
216*bbb1b6f9SApple OSS Distributions
217*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
218*bbb1b6f9SApple OSS Distributions void *
memcpy(void * dst,const void * src,size_t n)219*bbb1b6f9SApple OSS Distributions memcpy(void *dst, const void *src, size_t n)
220*bbb1b6f9SApple OSS Distributions {
221*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->memmove(dst, src, n);
222*bbb1b6f9SApple OSS Distributions }
223*bbb1b6f9SApple OSS Distributions
224*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
225*bbb1b6f9SApple OSS Distributions void *
memccpy(void * __restrict dst,const void * __restrict src,int c,size_t n)226*bbb1b6f9SApple OSS Distributions memccpy(void *__restrict dst, const void *__restrict src, int c, size_t n)
227*bbb1b6f9SApple OSS Distributions {
228*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->memccpy(dst, src, c, n);
229*bbb1b6f9SApple OSS Distributions }
230*bbb1b6f9SApple OSS Distributions
231*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
232*bbb1b6f9SApple OSS Distributions void *
memset(void * b,int c,size_t len)233*bbb1b6f9SApple OSS Distributions memset(void *b, int c, size_t len)
234*bbb1b6f9SApple OSS Distributions {
235*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->memset(b, c, len);
236*bbb1b6f9SApple OSS Distributions }
237*bbb1b6f9SApple OSS Distributions
238*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
239*bbb1b6f9SApple OSS Distributions char *
strchr(const char * s,int c)240*bbb1b6f9SApple OSS Distributions strchr(const char *s, int c)
241*bbb1b6f9SApple OSS Distributions {
242*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strchr(s, c);
243*bbb1b6f9SApple OSS Distributions }
244*bbb1b6f9SApple OSS Distributions
245*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
246*bbb1b6f9SApple OSS Distributions char *
index(const char * s,int c)247*bbb1b6f9SApple OSS Distributions index(const char *s, int c)
248*bbb1b6f9SApple OSS Distributions {
249*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strchr(s, c);
250*bbb1b6f9SApple OSS Distributions }
251*bbb1b6f9SApple OSS Distributions
252*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
253*bbb1b6f9SApple OSS Distributions int
strcmp(const char * s1,const char * s2)254*bbb1b6f9SApple OSS Distributions strcmp(const char *s1, const char *s2)
255*bbb1b6f9SApple OSS Distributions {
256*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strcmp(s1, s2);
257*bbb1b6f9SApple OSS Distributions }
258*bbb1b6f9SApple OSS Distributions
259*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
260*bbb1b6f9SApple OSS Distributions char *
strcpy(char * restrict dst,const char * restrict src)261*bbb1b6f9SApple OSS Distributions strcpy(char * restrict dst, const char * restrict src)
262*bbb1b6f9SApple OSS Distributions {
263*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strcpy(dst, src);
264*bbb1b6f9SApple OSS Distributions }
265*bbb1b6f9SApple OSS Distributions
266*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
267*bbb1b6f9SApple OSS Distributions size_t
strlcat(char * restrict dst,const char * restrict src,size_t maxlen)268*bbb1b6f9SApple OSS Distributions strlcat(char * restrict dst, const char * restrict src, size_t maxlen)
269*bbb1b6f9SApple OSS Distributions {
270*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strlcat(dst, src, maxlen);
271*bbb1b6f9SApple OSS Distributions }
272*bbb1b6f9SApple OSS Distributions
273*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
274*bbb1b6f9SApple OSS Distributions size_t
strlcpy(char * restrict dst,const char * restrict src,size_t maxlen)275*bbb1b6f9SApple OSS Distributions strlcpy(char * restrict dst, const char * restrict src, size_t maxlen)
276*bbb1b6f9SApple OSS Distributions {
277*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strlcpy(dst, src, maxlen);
278*bbb1b6f9SApple OSS Distributions }
279*bbb1b6f9SApple OSS Distributions
280*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
281*bbb1b6f9SApple OSS Distributions size_t
strlen(const char * str)282*bbb1b6f9SApple OSS Distributions strlen(const char *str)
283*bbb1b6f9SApple OSS Distributions {
284*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strlen(str);
285*bbb1b6f9SApple OSS Distributions }
286*bbb1b6f9SApple OSS Distributions
287*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
288*bbb1b6f9SApple OSS Distributions int
strncmp(const char * s1,const char * s2,size_t n)289*bbb1b6f9SApple OSS Distributions strncmp(const char *s1, const char *s2, size_t n)
290*bbb1b6f9SApple OSS Distributions {
291*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strncmp(s1, s2, n);
292*bbb1b6f9SApple OSS Distributions }
293*bbb1b6f9SApple OSS Distributions
294*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
295*bbb1b6f9SApple OSS Distributions char *
strncpy(char * restrict dst,const char * restrict src,size_t maxlen)296*bbb1b6f9SApple OSS Distributions strncpy(char * restrict dst, const char * restrict src, size_t maxlen)
297*bbb1b6f9SApple OSS Distributions {
298*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strncpy(dst, src, maxlen);
299*bbb1b6f9SApple OSS Distributions }
300*bbb1b6f9SApple OSS Distributions
301*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
302*bbb1b6f9SApple OSS Distributions size_t
strnlen(const char * s,size_t maxlen)303*bbb1b6f9SApple OSS Distributions strnlen(const char *s, size_t maxlen)
304*bbb1b6f9SApple OSS Distributions {
305*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strnlen(s, maxlen);
306*bbb1b6f9SApple OSS Distributions }
307*bbb1b6f9SApple OSS Distributions
308*bbb1b6f9SApple OSS Distributions __attribute__((visibility("hidden")))
309*bbb1b6f9SApple OSS Distributions char *
strstr(const char * s,const char * find)310*bbb1b6f9SApple OSS Distributions strstr(const char *s, const char *find)
311*bbb1b6f9SApple OSS Distributions {
312*bbb1b6f9SApple OSS Distributions return _libkernel_string_functions->strstr(s, find);
313*bbb1b6f9SApple OSS Distributions }
314*bbb1b6f9SApple OSS Distributions
315*bbb1b6f9SApple OSS Distributions /*
316*bbb1b6f9SApple OSS Distributions * mach/mach.h voucher_mach_msg API
317*bbb1b6f9SApple OSS Distributions */
318*bbb1b6f9SApple OSS Distributions
319*bbb1b6f9SApple OSS Distributions static const struct _libkernel_voucher_functions
320*bbb1b6f9SApple OSS Distributions _libkernel_voucher_functions_empty;
321*bbb1b6f9SApple OSS Distributions static _libkernel_voucher_functions_t _libkernel_voucher_functions =
322*bbb1b6f9SApple OSS Distributions &_libkernel_voucher_functions_empty;
323*bbb1b6f9SApple OSS Distributions
324*bbb1b6f9SApple OSS Distributions kern_return_t
__libkernel_voucher_init(_libkernel_voucher_functions_t fns)325*bbb1b6f9SApple OSS Distributions __libkernel_voucher_init(_libkernel_voucher_functions_t fns)
326*bbb1b6f9SApple OSS Distributions {
327*bbb1b6f9SApple OSS Distributions _libkernel_voucher_functions = fns;
328*bbb1b6f9SApple OSS Distributions return KERN_SUCCESS;
329*bbb1b6f9SApple OSS Distributions }
330*bbb1b6f9SApple OSS Distributions
331*bbb1b6f9SApple OSS Distributions boolean_t
voucher_mach_msg_set(mach_msg_header_t * msg)332*bbb1b6f9SApple OSS Distributions voucher_mach_msg_set(mach_msg_header_t *msg)
333*bbb1b6f9SApple OSS Distributions {
334*bbb1b6f9SApple OSS Distributions if (_libkernel_voucher_functions->voucher_mach_msg_set) {
335*bbb1b6f9SApple OSS Distributions return _libkernel_voucher_functions->voucher_mach_msg_set(msg);
336*bbb1b6f9SApple OSS Distributions }
337*bbb1b6f9SApple OSS Distributions return FALSE;
338*bbb1b6f9SApple OSS Distributions }
339*bbb1b6f9SApple OSS Distributions
340*bbb1b6f9SApple OSS Distributions void
voucher_mach_msg_clear(mach_msg_header_t * msg)341*bbb1b6f9SApple OSS Distributions voucher_mach_msg_clear(mach_msg_header_t *msg)
342*bbb1b6f9SApple OSS Distributions {
343*bbb1b6f9SApple OSS Distributions if (_libkernel_voucher_functions->voucher_mach_msg_clear) {
344*bbb1b6f9SApple OSS Distributions _libkernel_voucher_functions->voucher_mach_msg_clear(msg);
345*bbb1b6f9SApple OSS Distributions }
346*bbb1b6f9SApple OSS Distributions }
347*bbb1b6f9SApple OSS Distributions
348*bbb1b6f9SApple OSS Distributions voucher_mach_msg_state_t
voucher_mach_msg_adopt(mach_msg_header_t * msg)349*bbb1b6f9SApple OSS Distributions voucher_mach_msg_adopt(mach_msg_header_t *msg)
350*bbb1b6f9SApple OSS Distributions {
351*bbb1b6f9SApple OSS Distributions if (_libkernel_voucher_functions->voucher_mach_msg_adopt) {
352*bbb1b6f9SApple OSS Distributions return _libkernel_voucher_functions->voucher_mach_msg_adopt(msg);
353*bbb1b6f9SApple OSS Distributions }
354*bbb1b6f9SApple OSS Distributions return VOUCHER_MACH_MSG_STATE_UNCHANGED;
355*bbb1b6f9SApple OSS Distributions }
356*bbb1b6f9SApple OSS Distributions
357*bbb1b6f9SApple OSS Distributions void
voucher_mach_msg_revert(voucher_mach_msg_state_t state)358*bbb1b6f9SApple OSS Distributions voucher_mach_msg_revert(voucher_mach_msg_state_t state)
359*bbb1b6f9SApple OSS Distributions {
360*bbb1b6f9SApple OSS Distributions if (_libkernel_voucher_functions->voucher_mach_msg_revert) {
361*bbb1b6f9SApple OSS Distributions _libkernel_voucher_functions->voucher_mach_msg_revert(state);
362*bbb1b6f9SApple OSS Distributions }
363*bbb1b6f9SApple OSS Distributions }
364*bbb1b6f9SApple OSS Distributions
365*bbb1b6f9SApple OSS Distributions mach_msg_size_t
voucher_mach_msg_fill_aux(mach_msg_aux_header_t * aux_hdr,mach_msg_size_t sz)366*bbb1b6f9SApple OSS Distributions voucher_mach_msg_fill_aux(mach_msg_aux_header_t *aux_hdr, mach_msg_size_t sz)
367*bbb1b6f9SApple OSS Distributions {
368*bbb1b6f9SApple OSS Distributions if (_libkernel_voucher_functions->version < 3) {
369*bbb1b6f9SApple OSS Distributions return 0;
370*bbb1b6f9SApple OSS Distributions }
371*bbb1b6f9SApple OSS Distributions if (_libkernel_voucher_functions->voucher_mach_msg_fill_aux) {
372*bbb1b6f9SApple OSS Distributions return _libkernel_voucher_functions->voucher_mach_msg_fill_aux(aux_hdr, sz);
373*bbb1b6f9SApple OSS Distributions }
374*bbb1b6f9SApple OSS Distributions return 0;
375*bbb1b6f9SApple OSS Distributions }
376*bbb1b6f9SApple OSS Distributions
377*bbb1b6f9SApple OSS Distributions boolean_t
voucher_mach_msg_fill_aux_supported(void)378*bbb1b6f9SApple OSS Distributions voucher_mach_msg_fill_aux_supported(void)
379*bbb1b6f9SApple OSS Distributions {
380*bbb1b6f9SApple OSS Distributions if (_libkernel_voucher_functions->version < 3) {
381*bbb1b6f9SApple OSS Distributions return FALSE;
382*bbb1b6f9SApple OSS Distributions }
383*bbb1b6f9SApple OSS Distributions return NULL != _libkernel_voucher_functions->voucher_mach_msg_fill_aux;
384*bbb1b6f9SApple OSS Distributions }
385