]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
e5568f75 A |
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. | |
1c79356b | 11 | * |
e5568f75 A |
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 | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
e5568f75 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1997 by Apple Computer, Inc., all rights reserved | |
24 | * Copyright (c) 1993 NeXT Computer, Inc. | |
25 | * | |
26 | */ | |
27 | ||
28 | #include <sys/param.h> | |
29 | #include <sys/systm.h> | |
30 | #include <sys/buf.h> | |
31 | #include <sys/ioctl.h> | |
32 | #include <sys/tty.h> | |
33 | #include <sys/conf.h> | |
34 | #include <sys/proc.h> | |
35 | #include <sys/user.h> | |
36 | #include <kern/task.h> | |
37 | #include <kern/thread.h> | |
38 | #include <kern/thread_act.h> | |
39 | #include <vm/vm_map.h> | |
40 | ||
41 | ||
42 | /* | |
43 | * copy a null terminated string from the kernel address space into | |
44 | * the user address space. | |
45 | * - if the user is denied write access, return EFAULT. | |
46 | * - if the end of string isn't found before | |
47 | * maxlen bytes are copied, return ENAMETOOLONG, | |
48 | * indicating an incomplete copy. | |
49 | * - otherwise, return 0, indicating success. | |
50 | * the number of bytes copied is always returned in lencopied. | |
51 | */ | |
52 | int | |
53 | copyoutstr(from, to, maxlen, lencopied) | |
54 | void * from, * to; | |
55 | size_t maxlen, *lencopied; | |
56 | { | |
57 | int slen,len,error=0; | |
58 | ||
59 | slen = strlen(from) + 1; | |
55e303ae A |
60 | if (slen > maxlen) |
61 | error = ENAMETOOLONG; | |
1c79356b A |
62 | |
63 | len = min(maxlen,slen); | |
64 | if (copyout(from, to, len)) | |
55e303ae | 65 | error = EFAULT; |
1c79356b A |
66 | *lencopied = len; |
67 | ||
68 | return error; | |
69 | } | |
70 | ||
71 | ||
72 | /* | |
73 | * copy a null terminated string from one point to another in | |
74 | * the kernel address space. | |
75 | * - no access checks are performed. | |
76 | * - if the end of string isn't found before | |
77 | * maxlen bytes are copied, return ENAMETOOLONG, | |
78 | * indicating an incomplete copy. | |
79 | * - otherwise, return 0, indicating success. | |
80 | * the number of bytes copied is always returned in lencopied. | |
81 | */ | |
82 | /* from ppc/fault_copy.c -Titan1T4 VERSION */ | |
83 | int | |
84 | copystr(vfrom, vto, maxlen, lencopied) | |
85 | register void * vfrom, *vto; | |
86 | size_t maxlen, *lencopied; | |
87 | { | |
88 | register unsigned l; | |
89 | int error; | |
90 | caddr_t from, to; | |
91 | ||
92 | from = vfrom; | |
93 | to = vto; | |
94 | for (l = 0; l < maxlen; l++) | |
95 | if ((*to++ = *from++) == '\0') { | |
96 | if (lencopied) | |
97 | *lencopied = l + 1; | |
98 | return 0; | |
99 | } | |
100 | if (lencopied) | |
101 | *lencopied = maxlen; | |
102 | return ENAMETOOLONG; | |
103 | } | |
104 | ||
105 | int copywithin(src, dst, count) | |
106 | void * src, *dst; | |
107 | size_t count; | |
108 | { | |
109 | bcopy(src,dst,count); | |
110 | return 0; | |
111 | } | |
112 | ||
1c79356b A |
113 | set_bsduthreadargs(thread_t th, void * pcb, void *ignored_arg) |
114 | { | |
115 | struct uthread * ut; | |
116 | ||
117 | ut = get_bsdthread_info(th); | |
118 | ut->uu_ar0 = (int *)pcb; | |
119 | ||
120 | return(1); | |
121 | } | |
122 | ||
123 | void * | |
124 | get_bsduthreadarg(thread_t th) | |
125 | { | |
126 | struct uthread *ut; | |
127 | ut = get_bsdthread_info(th); | |
128 | return((void *)(ut->uu_arg)); | |
129 | } | |
130 | ||
131 | int * | |
132 | get_bsduthreadrval(thread_act_t th) | |
133 | { | |
134 | struct uthread *ut; | |
135 | ut = get_bsdthread_info(th); | |
136 | return(&ut->uu_rval[0]); | |
137 | } |