]>
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>
40 #include <machine/machine_routines.h>
42 /* XXX should be elsewhere (cpeak) */
43 extern struct proc
*i386_current_proc(void);
44 extern void *get_bsduthreadarg(thread_t
);
45 extern int *get_bsduthreadrval(thread_t
);
46 extern void *find_user_regs(thread_t
);
49 * copy a null terminated string from the kernel address space into
50 * the user address space.
51 * - if the user is denied write access, return EFAULT.
52 * - if the end of string isn't found before
53 * maxlen bytes are copied, return ENAMETOOLONG,
54 * indicating an incomplete copy.
55 * - otherwise, return 0, indicating success.
56 * the number of bytes copied is always returned in lencopied.
59 copyoutstr(const void *from
, user_addr_t to
, size_t maxlen
, size_t *lencopied
)
65 slen
= strlen(from
) + 1;
69 len
= min(maxlen
,slen
);
70 if (copyout(from
, to
, len
))
79 * copy a null terminated string from one point to another in
80 * the kernel address space.
81 * - no access checks are performed.
82 * - if the end of string isn't found before
83 * maxlen bytes are copied, return ENAMETOOLONG,
84 * indicating an incomplete copy.
85 * - otherwise, return 0, indicating success.
86 * the number of bytes copied is always returned in lencopied.
88 /* from ppc/fault_copy.c -Titan1T4 VERSION */
90 copystr(const void *vfrom
, void *vto
, size_t maxlen
, size_t *lencopied
)
93 char const *from
= (char const *) vfrom
;
94 char *to
= (char *) vto
;
96 for (l
= 0; l
< maxlen
; l
++) {
97 if ((*to
++ = *from
++) == '\0') {
109 copywithin(void *src
, void *dst
, size_t count
)
111 bcopy(src
,dst
,count
);
116 * This is just current_proc() from bsd/kern/bsd_stubs.c, but instead of
117 * returning kernproc in the non-vfork() case, it can return NULL. This is
118 * needed because the system call entry point is in osfmk/i386/bsd_i386.c
119 * instead of bsd/dev/i386, and therefore cannot see some BSD thread
120 * internals. We need to distinguish kernproc defaulting in the vfork and
121 * non-vfork cases vs. actually being the real process context.
124 i386_current_proc(void)
128 thread_t thr_act
= current_thread();
130 ut
= (struct uthread
*)get_bsdthread_info(thr_act
);
131 if (ut
&& (ut
->uu_flag
& UT_VFORK
)) {
134 if ((p
->p_flag
& P_INVFORK
) == 0)
135 panic("returning child proc not under vfork");
136 if (p
->p_vforkact
!= (void *)thr_act
)
137 panic("returning child proc which is not cur_act");
144 /* Not in vfork - may return NULL */
145 p
= (struct proc
*)get_bsdtask_info(current_task());
151 get_bsduthreadarg(thread_t th
)
156 ut
= get_bsdthread_info(th
);
158 if (ml_thread_is64bit(th
) == TRUE
)
159 arg_ptr
= (void *)saved_state64(find_user_regs(th
));
161 arg_ptr
= (void *)(ut
->uu_arg
);
167 get_bsduthreadrval(thread_t th
)
171 ut
= get_bsdthread_info(th
);
172 return(&ut
->uu_rval
[0]);