]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/stubs.c
ddb4174d4390c35f3d238216e7a15b52e1fadd42
[apple/xnu.git] / bsd / dev / ppc / stubs.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved
27 * Copyright (c) 1993 NeXT Computer, Inc.
28 *
29 */
30
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/buf.h>
34 #include <sys/ioctl.h>
35 #include <sys/tty.h>
36 #include <sys/conf.h>
37 #include <sys/proc.h>
38 #include <sys/user.h>
39 #include <kern/thread.h>
40 #include <kern/thread_act.h>
41 #include <kern/task.h>
42 #include <vm/vm_map.h>
43
44
45 /*
46 * copy a null terminated string from the kernel address space into
47 * the user address space.
48 * - if the user is denied write access, return EFAULT.
49 * - if the end of string isn't found before
50 * maxlen bytes are copied, return ENAMETOOLONG,
51 * indicating an incomplete copy.
52 * - otherwise, return 0, indicating success.
53 * the number of bytes copied is always returned in lencopied.
54 */
55 int
56 copyoutstr(from, to, maxlen, lencopied)
57 void * from, * to;
58 size_t maxlen, *lencopied;
59 {
60 int slen,len,error=0;
61
62 /* XXX Must optimize this */
63
64 slen = strlen(from) + 1;
65 if (slen > maxlen)
66 error = ENAMETOOLONG;
67
68 len = min(maxlen,slen);
69 if (copyout(from, to, len))
70 error = EFAULT;
71 *lencopied = len;
72
73 return error;
74 }
75
76
77 /*
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.
86 */
87 /* from ppc/fault_copy.c -Titan1T4 VERSION */
88 int
89 copystr(vfrom, vto, maxlen, lencopied)
90 register void * vfrom, *vto;
91 size_t maxlen, *lencopied;
92 {
93 register unsigned l;
94 int error;
95 caddr_t from, to;
96
97 from = vfrom;
98 to = vto;
99 for (l = 0; l < maxlen; l++)
100 if ((*to++ = *from++) == '\0') {
101 if (lencopied)
102 *lencopied = l + 1;
103 return 0;
104 }
105 if (lencopied)
106 *lencopied = maxlen;
107 return ENAMETOOLONG;
108 }
109
110 int copywithin(src, dst, count)
111 void * src, *dst;
112 size_t count;
113 {
114 bcopy(src,dst,count);
115 return 0;
116 }
117
118 struct unix_syscallargs {
119 int flavor;
120 int r3;
121 int arg1, arg2,arg3,arg4,arg5,arg6,arg7;
122 };
123
124 set_bsduthreadargs(thread_t th, void * pcb, struct unix_syscallargs * sarg)
125 {
126 struct uthread * ut;
127
128 ut = get_bsdthread_info(th);
129 ut->uu_ar0 = (int *)pcb;
130
131 if (sarg->flavor)
132 {
133 ut->uu_arg[0] = sarg->arg1;
134 ut->uu_arg[1] = sarg->arg2;
135 ut->uu_arg[2] = sarg->arg3;
136 ut->uu_arg[3] = sarg->arg4;
137 ut->uu_arg[4] = sarg->arg5;
138 ut->uu_arg[5] = sarg->arg6;
139 ut->uu_arg[7] = sarg->arg7;
140 }
141 else
142 {
143 ut->uu_arg[0] = sarg->r3;
144 ut->uu_arg[1] = sarg->arg1;
145 ut->uu_arg[2] = sarg->arg2;
146 ut->uu_arg[3] = sarg->arg3;
147 ut->uu_arg[4] = sarg->arg4;
148 ut->uu_arg[5] = sarg->arg5;
149 ut->uu_arg[6] = sarg->arg6;
150 ut->uu_arg[7] = sarg->arg7;
151 }
152
153 return(1);
154 }
155
156 void *
157 get_bsduthreadarg(thread_t th)
158 {
159 struct uthread *ut;
160 ut = get_bsdthread_info(th);
161 return((void *)(ut->uu_arg));
162 }
163
164 int *
165 get_bsduthreadrval(thread_act_t th)
166 {
167 struct uthread *ut;
168 ut = get_bsdthread_info(th);
169 return(&ut->uu_rval[0]);
170 }
171