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