]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/stubs.c
512c730b1107dfae05e9f98f7eb7597dc8215afc
2 * Copyright (c) 2000 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>
48 #include <machine/machine_routines.h>
50 /* XXX should be elsewhere (cpeak) */
51 extern struct proc
*i386_current_proc(void);
52 extern void *get_bsduthreadarg(thread_t
);
53 extern int *get_bsduthreadrval(thread_t
);
54 extern void *find_user_regs(thread_t
);
57 * copy a null terminated string from the kernel address space into
58 * the user address space.
59 * - if the user is denied write access, return EFAULT.
60 * - if the end of string isn't found before
61 * maxlen bytes are copied, return ENAMETOOLONG,
62 * indicating an incomplete copy.
63 * - otherwise, return 0, indicating success.
64 * the number of bytes copied is always returned in lencopied.
67 copyoutstr(const void *from
, user_addr_t to
, size_t maxlen
, size_t *lencopied
)
73 slen
= strlen(from
) + 1;
77 len
= min(maxlen
,slen
);
78 if (copyout(from
, to
, len
))
87 * copy a null terminated string from one point to another in
88 * the kernel address space.
89 * - no access checks are performed.
90 * - if the end of string isn't found before
91 * maxlen bytes are copied, return ENAMETOOLONG,
92 * indicating an incomplete copy.
93 * - otherwise, return 0, indicating success.
94 * the number of bytes copied is always returned in lencopied.
96 /* from ppc/fault_copy.c -Titan1T4 VERSION */
98 copystr(const void *vfrom
, void *vto
, size_t maxlen
, size_t *lencopied
)
101 char const *from
= (char const *) vfrom
;
102 char *to
= (char *) vto
;
104 for (l
= 0; l
< maxlen
; l
++) {
105 if ((*to
++ = *from
++) == '\0') {
117 copywithin(void *src
, void *dst
, size_t count
)
119 bcopy(src
,dst
,count
);
124 * This is just current_proc() from bsd/kern/bsd_stubs.c, but instead of
125 * returning kernproc in the non-vfork() case, it can return NULL. This is
126 * needed because the system call entry point is in osfmk/i386/bsd_i386.c
127 * instead of bsd/dev/i386, and therefore cannot see some BSD thread
128 * internals. We need to distinguish kernproc defaulting in the vfork and
129 * non-vfork cases vs. actually being the real process context.
132 i386_current_proc(void)
136 thread_t thr_act
= current_thread();
138 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
139 if (ut
&& (ut
->uu_flag
& UT_VFORK
)) {
142 if ((p
->p_flag
& P_INVFORK
) == 0)
143 panic("returning child proc not under vfork");
144 if (p
->p_vforkact
!= (void *)thr_act
)
145 panic("returning child proc which is not cur_act");
152 /* Not in vfork - may return NULL */
153 p
= (struct proc
*)get_bsdtask_info(current_task());
159 get_bsduthreadarg(thread_t th
)
164 ut
= get_bsdthread_info(th
);
166 if (ml_thread_is64bit(th
) == TRUE
)
167 arg_ptr
= (void *)saved_state64(find_user_regs(th
));
169 arg_ptr
= (void *)(ut
->uu_arg
);
175 get_bsduthreadrval(thread_t th
)
179 ut
= get_bsdthread_info(th
);
180 return(&ut
->uu_rval
[0]);