]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. |
3 | * | |
8f6c56a5 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
8f6c56a5 A |
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 License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
8ad349bb | 24 | * limitations under the License. |
8f6c56a5 A |
25 | * |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
1c79356b A |
27 | */ |
28 | #include <sys/time.h> | |
29 | #include <kern/task.h> | |
30 | #include <kern/thread.h> | |
31 | #include <mach/mach_types.h> | |
32 | #include <mach/vm_prot.h> | |
33 | #include <vm/vm_kern.h> | |
34 | #include <vm/vm_map.h> | |
35 | #include <sys/systm.h> | |
36 | #include <sys/conf.h> | |
91447636 | 37 | #include <sys/proc_internal.h> |
1c79356b | 38 | #include <sys/buf.h> /* for SET */ |
0b4e3aa0 | 39 | #include <sys/user.h> |
1c79356b A |
40 | |
41 | /* Just to satisfy pstat command */ | |
42 | int dmmin, dmmax, dmtext; | |
43 | ||
91447636 | 44 | vm_offset_t |
1c79356b A |
45 | kmem_mb_alloc(vm_map_t mbmap, int size) |
46 | { | |
47 | vm_offset_t addr; | |
48 | if (kernel_memory_allocate(mbmap, &addr, size, | |
49 | 0, | |
21362eb3 | 50 | KMA_NOPAGEWAIT|KMA_KOBJECT) == KERN_SUCCESS) |
55e303ae | 51 | return(addr); |
1c79356b A |
52 | else |
53 | return(0); | |
54 | ||
55 | } | |
56 | ||
91447636 A |
57 | /* |
58 | * XXX this function only exists to be exported and do nothing. | |
59 | */ | |
60 | void | |
61 | pcb_synch(void) | |
62 | { | |
63 | } | |
1c79356b A |
64 | |
65 | struct proc * | |
66 | current_proc(void) | |
67 | { | |
68 | /* Never returns a NULL */ | |
0b4e3aa0 A |
69 | struct uthread * ut; |
70 | struct proc *p; | |
91447636 | 71 | thread_t thr_act = current_thread(); |
0b4e3aa0 A |
72 | |
73 | ut = (struct uthread *)get_bsdthread_info(thr_act); | |
91447636 | 74 | if (ut && (ut->uu_flag & UT_VFORK) && ut->uu_proc) { |
0b4e3aa0 A |
75 | p = ut->uu_proc; |
76 | if ((p->p_flag & P_INVFORK) == 0) | |
77 | panic("returning child proc not under vfork"); | |
78 | if (p->p_vforkact != (void *)thr_act) | |
79 | panic("returning child proc which is not cur_act"); | |
80 | return(p); | |
81 | } | |
82 | ||
83 | p = (struct proc *)get_bsdtask_info(current_task()); | |
84 | ||
1c79356b | 85 | if (p == NULL) |
0b4e3aa0 A |
86 | return (kernproc); |
87 | ||
1c79356b A |
88 | return (p); |
89 | } | |
90 | ||
91 | /* Device switch add delete routines */ | |
92 | ||
93 | extern int nblkdev, nchrdev; | |
94 | ||
95 | struct bdevsw nobdev = NO_BDEVICE; | |
96 | struct cdevsw nocdev = NO_CDEVICE; | |
97 | /* | |
98 | * if index is -1, return a free slot if avaliable | |
99 | * else see whether the index is free | |
100 | * return the major number that is free else -1 | |
101 | * | |
102 | */ | |
103 | int | |
104 | bdevsw_isfree(int index) | |
105 | { | |
106 | struct bdevsw *devsw; | |
107 | if (index == -1) { | |
108 | devsw = bdevsw; | |
109 | for(index=0; index < nblkdev; index++, devsw++) { | |
110 | if(memcmp((char *)devsw, | |
111 | (char *)&nobdev, | |
112 | sizeof(struct bdevsw)) == 0) | |
113 | break; | |
114 | } | |
55e303ae A |
115 | } else { |
116 | /* NB: Not used below unless index is in range */ | |
117 | devsw = &bdevsw[index]; | |
1c79356b A |
118 | } |
119 | ||
120 | if ((index < 0) || (index >= nblkdev) || | |
121 | (memcmp((char *)devsw, | |
122 | (char *)&nobdev, | |
123 | sizeof(struct bdevsw)) != 0)) { | |
124 | return(-1); | |
125 | } | |
126 | return(index); | |
127 | } | |
128 | ||
129 | /* | |
130 | * if index is -1, find a free slot to add | |
131 | * else see whether the slot is free | |
132 | * return the major number that is used else -1 | |
133 | */ | |
134 | int | |
135 | bdevsw_add(int index, struct bdevsw * bsw) | |
136 | { | |
137 | struct bdevsw *devsw; | |
138 | ||
139 | if (index == -1) { | |
55e303ae | 140 | devsw = &bdevsw[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */ |
9bccf70c A |
141 | /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */ |
142 | for(index=1; index < nblkdev; index++, devsw++) { | |
1c79356b A |
143 | if(memcmp((char *)devsw, |
144 | (char *)&nobdev, | |
145 | sizeof(struct bdevsw)) == 0) | |
146 | break; | |
147 | } | |
148 | } | |
149 | devsw = &bdevsw[index]; | |
150 | if ((index < 0) || (index >= nblkdev) || | |
151 | (memcmp((char *)devsw, | |
152 | (char *)&nobdev, | |
153 | sizeof(struct bdevsw)) != 0)) { | |
154 | return(-1); | |
155 | } | |
156 | bdevsw[index] = *bsw; | |
157 | return(index); | |
158 | } | |
159 | /* | |
160 | * if the slot has the same bsw, then remove | |
161 | * else -1 | |
162 | */ | |
163 | int | |
164 | bdevsw_remove(int index, struct bdevsw * bsw) | |
165 | { | |
166 | struct bdevsw *devsw; | |
167 | ||
168 | devsw = &bdevsw[index]; | |
169 | if ((index < 0) || (index >= nblkdev) || | |
170 | (memcmp((char *)devsw, | |
171 | (char *)bsw, | |
172 | sizeof(struct bdevsw)) != 0)) { | |
173 | return(-1); | |
174 | } | |
175 | bdevsw[index] = nobdev; | |
176 | return(index); | |
177 | } | |
178 | ||
179 | /* | |
180 | * if index is -1, return a free slot if avaliable | |
181 | * else see whether the index is free | |
182 | * return the major number that is free else -1 | |
183 | */ | |
184 | int | |
185 | cdevsw_isfree(int index) | |
186 | { | |
187 | struct cdevsw *devsw; | |
188 | ||
189 | if (index == -1) { | |
190 | devsw = cdevsw; | |
191 | for(index=0; index < nchrdev; index++, devsw++) { | |
192 | if(memcmp((char *)devsw, | |
193 | (char *)&nocdev, | |
194 | sizeof(struct cdevsw)) == 0) | |
195 | break; | |
196 | } | |
197 | } | |
198 | devsw = &cdevsw[index]; | |
199 | if ((index < 0) || (index >= nchrdev) || | |
200 | (memcmp((char *)devsw, | |
201 | (char *)&nocdev, | |
202 | sizeof(struct cdevsw)) != 0)) { | |
203 | return(-1); | |
204 | } | |
205 | return(index); | |
206 | } | |
207 | ||
208 | /* | |
209 | * if index is -1, find a free slot to add | |
210 | * else see whether the slot is free | |
211 | * return the major number that is used else -1 | |
212 | */ | |
213 | int | |
214 | cdevsw_add(int index, struct cdevsw * csw) | |
215 | { | |
216 | struct cdevsw *devsw; | |
217 | ||
218 | if (index == -1) { | |
219 | devsw = cdevsw; | |
220 | for(index=0; index < nchrdev; index++, devsw++) { | |
221 | if(memcmp((char *)devsw, | |
222 | (char *)&nocdev, | |
223 | sizeof(struct cdevsw)) == 0) | |
224 | break; | |
225 | } | |
226 | } | |
227 | devsw = &cdevsw[index]; | |
228 | if ((index < 0) || (index >= nchrdev) || | |
229 | (memcmp((char *)devsw, | |
230 | (char *)&nocdev, | |
231 | sizeof(struct cdevsw)) != 0)) { | |
232 | return(-1); | |
233 | } | |
234 | cdevsw[index] = *csw; | |
235 | return(index); | |
236 | } | |
237 | /* | |
238 | * if the index has the same bsw, then remove | |
239 | * else -1 | |
240 | */ | |
241 | int | |
242 | cdevsw_remove(int index, struct cdevsw * csw) | |
243 | { | |
244 | struct cdevsw *devsw; | |
245 | ||
246 | devsw = &cdevsw[index]; | |
247 | if ((index < 0) || (index >= nchrdev) || | |
248 | (memcmp((char *)devsw, | |
249 | (char *)csw, | |
250 | sizeof(struct cdevsw)) != 0)) { | |
251 | return(-1); | |
252 | } | |
253 | cdevsw[index] = nocdev; | |
254 | return(index); | |
255 | } | |
256 | ||
9bccf70c A |
257 | static int |
258 | cdev_set_bdev(int cdev, int bdev) | |
259 | { | |
260 | extern int chrtoblk_add(int cdev, int bdev); | |
261 | ||
262 | return (chrtoblk_set(cdev, bdev)); | |
263 | } | |
264 | ||
265 | int | |
266 | cdevsw_add_with_bdev(int index, struct cdevsw * csw, int bdev) | |
267 | { | |
268 | index = cdevsw_add(index, csw); | |
269 | if (index < 0) { | |
270 | return (index); | |
271 | } | |
272 | if (cdev_set_bdev(index, bdev) < 0) { | |
273 | cdevsw_remove(index, csw); | |
274 | return (-1); | |
275 | } | |
276 | return (index); | |
277 | } | |
278 | ||
1c79356b A |
279 | issingleuser(void) |
280 | { | |
281 | char namep[16]; | |
282 | ||
283 | ||
284 | if (PE_parse_boot_arg("-s", namep)) { | |
285 | return(1); | |
286 | } else { | |
287 | return(0); | |
288 | } | |
289 | } | |
290 | ||
291 | void * | |
292 | tbeproc(void *procp) | |
293 | { | |
294 | struct proc *p = procp; | |
295 | ||
296 | if (p) | |
297 | SET(p->p_flag, P_TBE); | |
298 | return; | |
299 | } | |
300 |