]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/stubs.c
f4a56c042d455856c84a780f3ab68e90c25687a2
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
32 * Copyright (c) 1993 NeXT Computer, Inc.
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/ioctl.h>
41 #include <sys/kauth.h>
42 #include <sys/ucred.h>
43 #include <sys/proc_internal.h>
45 #include <kern/task.h>
46 #include <kern/thread.h>
47 #include <vm/vm_map.h>
49 /* XXX should be elsewhere (cpeak) */
50 extern int set_bsduthreadargs(thread_t
, void *, void *);
51 extern void *get_bsduthreadarg(thread_t
);
52 extern int *get_bsduthreadrval(thread_t
);
53 extern int *get_bsduthreadlowpridelay(thread_t
);
56 * copy a null terminated string from the kernel address space into
57 * the user address space.
58 * - if the user is denied write access, return EFAULT.
59 * - if the end of string isn't found before
60 * maxlen bytes are copied, return ENAMETOOLONG,
61 * indicating an incomplete copy.
62 * - otherwise, return 0, indicating success.
63 * the number of bytes copied is always returned in lencopied.
66 copyoutstr(const void *from
, user_addr_t to
, size_t maxlen
, size_t *lencopied
)
72 slen
= strlen(from
) + 1;
76 len
= min(maxlen
,slen
);
77 if (copyout(from
, to
, len
))
86 * copy a null terminated string from one point to another in
87 * the kernel address space.
88 * - no access checks are performed.
89 * - if the end of string isn't found before
90 * maxlen bytes are copied, return ENAMETOOLONG,
91 * indicating an incomplete copy.
92 * - otherwise, return 0, indicating success.
93 * the number of bytes copied is always returned in lencopied.
95 /* from ppc/fault_copy.c -Titan1T4 VERSION */
97 copystr(const void *vfrom
, void *vto
, size_t maxlen
, size_t *lencopied
)
100 char const *from
= (char const *) vfrom
;
101 char *to
= (char *) vto
;
103 for (l
= 0; l
< maxlen
; l
++) {
104 if ((*to
++ = *from
++) == '\0') {
116 copywithin(void *src
, void *dst
, size_t count
)
118 bcopy(src
,dst
,count
);
123 set_bsduthreadargs(thread_t th
, void * pcb
, __unused
void *ignored_arg
)
126 struct proc
*p
= current_proc();
128 ut
= get_bsdthread_info(th
);
129 ut
->uu_ar0
= (int *)pcb
;
132 * Delayed binding of thread credential to process credential.
134 * XXX This doesn't really belong here, but the i386 code has a
135 * XXX number of seemingly gratuitous structural differences that
136 * XXX make this the most appropriate place to do the work.
138 if (ut
->uu_ucred
!= p
->p_ucred
&&
139 (ut
->uu_flag
& UT_SETUID
) == 0) {
140 kauth_cred_t old
= ut
->uu_ucred
;
142 ut
->uu_ucred
= p
->p_ucred
;
143 kauth_cred_ref(ut
->uu_ucred
);
146 kauth_cred_rele(old
);
153 get_bsduthreadarg(thread_t th
)
156 ut
= get_bsdthread_info(th
);
157 return((void *)(ut
->uu_arg
));
161 get_bsduthreadrval(thread_t th
)
164 ut
= get_bsdthread_info(th
);
165 return(&ut
->uu_rval
[0]);
169 get_bsduthreadlowpridelay(thread_t th
)
172 ut
= get_bsdthread_info(th
);
173 return(&ut
->uu_lowpri_delay
);