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