]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/stubs.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
24 * Copyright (c) 1993 NeXT Computer, Inc.
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/ioctl.h>
33 #include <sys/kauth.h>
34 #include <sys/ucred.h>
35 #include <sys/proc_internal.h>
37 #include <kern/task.h>
38 #include <kern/thread.h>
39 #include <vm/vm_map.h>
41 /* XXX should be elsewhere (cpeak) */
42 extern int set_bsduthreadargs(thread_t
, void *, void *);
43 extern void *get_bsduthreadarg(thread_t
);
44 extern int *get_bsduthreadrval(thread_t
);
45 extern int *get_bsduthreadlowpridelay(thread_t
);
48 * copy a null terminated string from the kernel address space into
49 * the user address space.
50 * - if the user is denied write access, return EFAULT.
51 * - if the end of string isn't found before
52 * maxlen bytes are copied, return ENAMETOOLONG,
53 * indicating an incomplete copy.
54 * - otherwise, return 0, indicating success.
55 * the number of bytes copied is always returned in lencopied.
58 copyoutstr(const void *from
, user_addr_t to
, size_t maxlen
, size_t *lencopied
)
64 slen
= strlen(from
) + 1;
68 len
= min(maxlen
,slen
);
69 if (copyout(from
, to
, len
))
78 * copy a null terminated string from one point to another in
79 * the kernel address space.
80 * - no access checks are performed.
81 * - if the end of string isn't found before
82 * maxlen bytes are copied, return ENAMETOOLONG,
83 * indicating an incomplete copy.
84 * - otherwise, return 0, indicating success.
85 * the number of bytes copied is always returned in lencopied.
87 /* from ppc/fault_copy.c -Titan1T4 VERSION */
89 copystr(const void *vfrom
, void *vto
, size_t maxlen
, size_t *lencopied
)
92 char const *from
= (char const *) vfrom
;
93 char *to
= (char *) vto
;
95 for (l
= 0; l
< maxlen
; l
++) {
96 if ((*to
++ = *from
++) == '\0') {
108 copywithin(void *src
, void *dst
, size_t count
)
110 bcopy(src
,dst
,count
);
115 set_bsduthreadargs(thread_t th
, void * pcb
, __unused
void *ignored_arg
)
118 struct proc
*p
= current_proc();
120 ut
= get_bsdthread_info(th
);
121 ut
->uu_ar0
= (int *)pcb
;
124 * Delayed binding of thread credential to process credential.
126 * XXX This doesn't really belong here, but the i386 code has a
127 * XXX number of seemingly gratuitous structural differences that
128 * XXX make this the most appropriate place to do the work.
130 if (ut
->uu_ucred
!= p
->p_ucred
&&
131 (ut
->uu_flag
& UT_SETUID
) == 0) {
132 kauth_cred_t old
= ut
->uu_ucred
;
134 ut
->uu_ucred
= p
->p_ucred
;
135 kauth_cred_ref(ut
->uu_ucred
);
138 kauth_cred_rele(old
);
145 get_bsduthreadarg(thread_t th
)
148 ut
= get_bsdthread_info(th
);
149 return((void *)(ut
->uu_arg
));
153 get_bsduthreadrval(thread_t th
)
156 ut
= get_bsdthread_info(th
);
157 return(&ut
->uu_rval
[0]);
161 get_bsduthreadlowpridelay(thread_t th
)
164 ut
= get_bsdthread_info(th
);
165 return(&ut
->uu_lowpri_delay
);