]>
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 | #include <sys/time.h> | |
23 | #include <kern/task.h> | |
24 | #include <kern/thread.h> | |
25 | #include <mach/mach_types.h> | |
26 | #include <mach/vm_prot.h> | |
27 | #include <vm/vm_kern.h> | |
28 | #include <vm/vm_map.h> | |
29 | #include <sys/systm.h> | |
30 | #include <sys/conf.h> | |
91447636 | 31 | #include <sys/proc_internal.h> |
1c79356b | 32 | #include <sys/buf.h> /* for SET */ |
0b4e3aa0 | 33 | #include <sys/user.h> |
1c79356b A |
34 | |
35 | /* Just to satisfy pstat command */ | |
36 | int dmmin, dmmax, dmtext; | |
37 | ||
91447636 | 38 | vm_offset_t |
1c79356b A |
39 | kmem_mb_alloc(vm_map_t mbmap, int size) |
40 | { | |
41 | vm_offset_t addr; | |
42 | if (kernel_memory_allocate(mbmap, &addr, size, | |
43 | 0, | |
44 | KMA_NOPAGEWAIT|KMA_KOBJECT) == KERN_SUCCESS) | |
55e303ae | 45 | return(addr); |
1c79356b A |
46 | else |
47 | return(0); | |
48 | ||
49 | } | |
50 | ||
91447636 A |
51 | /* |
52 | * XXX this function only exists to be exported and do nothing. | |
53 | */ | |
54 | void | |
55 | pcb_synch(void) | |
56 | { | |
57 | } | |
1c79356b A |
58 | |
59 | struct proc * | |
60 | current_proc(void) | |
61 | { | |
62 | /* Never returns a NULL */ | |
0b4e3aa0 A |
63 | struct uthread * ut; |
64 | struct proc *p; | |
91447636 | 65 | thread_t thr_act = current_thread(); |
0b4e3aa0 A |
66 | |
67 | ut = (struct uthread *)get_bsdthread_info(thr_act); | |
91447636 | 68 | if (ut && (ut->uu_flag & UT_VFORK) && ut->uu_proc) { |
0b4e3aa0 A |
69 | p = ut->uu_proc; |
70 | if ((p->p_flag & P_INVFORK) == 0) | |
71 | panic("returning child proc not under vfork"); | |
72 | if (p->p_vforkact != (void *)thr_act) | |
73 | panic("returning child proc which is not cur_act"); | |
74 | return(p); | |
75 | } | |
76 | ||
77 | p = (struct proc *)get_bsdtask_info(current_task()); | |
78 | ||
1c79356b | 79 | if (p == NULL) |
0b4e3aa0 A |
80 | return (kernproc); |
81 | ||
1c79356b A |
82 | return (p); |
83 | } | |
84 | ||
85 | /* Device switch add delete routines */ | |
86 | ||
87 | extern int nblkdev, nchrdev; | |
88 | ||
89 | struct bdevsw nobdev = NO_BDEVICE; | |
90 | struct cdevsw nocdev = NO_CDEVICE; | |
91 | /* | |
92 | * if index is -1, return a free slot if avaliable | |
93 | * else see whether the index is free | |
94 | * return the major number that is free else -1 | |
95 | * | |
96 | */ | |
97 | int | |
98 | bdevsw_isfree(int index) | |
99 | { | |
100 | struct bdevsw *devsw; | |
101 | if (index == -1) { | |
102 | devsw = bdevsw; | |
103 | for(index=0; index < nblkdev; index++, devsw++) { | |
104 | if(memcmp((char *)devsw, | |
105 | (char *)&nobdev, | |
106 | sizeof(struct bdevsw)) == 0) | |
107 | break; | |
108 | } | |
55e303ae A |
109 | } else { |
110 | /* NB: Not used below unless index is in range */ | |
111 | devsw = &bdevsw[index]; | |
1c79356b A |
112 | } |
113 | ||
114 | if ((index < 0) || (index >= nblkdev) || | |
115 | (memcmp((char *)devsw, | |
116 | (char *)&nobdev, | |
117 | sizeof(struct bdevsw)) != 0)) { | |
118 | return(-1); | |
119 | } | |
120 | return(index); | |
121 | } | |
122 | ||
123 | /* | |
124 | * if index is -1, find a free slot to add | |
125 | * else see whether the slot is free | |
126 | * return the major number that is used else -1 | |
127 | */ | |
128 | int | |
129 | bdevsw_add(int index, struct bdevsw * bsw) | |
130 | { | |
131 | struct bdevsw *devsw; | |
132 | ||
133 | if (index == -1) { | |
55e303ae | 134 | devsw = &bdevsw[1]; /* Start at slot 1 - this is a hack to fix the index=1 hack */ |
9bccf70c A |
135 | /* yes, start at 1 to avoid collision with volfs (Radar 2842228) */ |
136 | for(index=1; index < nblkdev; index++, devsw++) { | |
1c79356b A |
137 | if(memcmp((char *)devsw, |
138 | (char *)&nobdev, | |
139 | sizeof(struct bdevsw)) == 0) | |
140 | break; | |
141 | } | |
142 | } | |
143 | devsw = &bdevsw[index]; | |
144 | if ((index < 0) || (index >= nblkdev) || | |
145 | (memcmp((char *)devsw, | |
146 | (char *)&nobdev, | |
147 | sizeof(struct bdevsw)) != 0)) { | |
148 | return(-1); | |
149 | } | |
150 | bdevsw[index] = *bsw; | |
151 | return(index); | |
152 | } | |
153 | /* | |
154 | * if the slot has the same bsw, then remove | |
155 | * else -1 | |
156 | */ | |
157 | int | |
158 | bdevsw_remove(int index, struct bdevsw * bsw) | |
159 | { | |
160 | struct bdevsw *devsw; | |
161 | ||
162 | devsw = &bdevsw[index]; | |
163 | if ((index < 0) || (index >= nblkdev) || | |
164 | (memcmp((char *)devsw, | |
165 | (char *)bsw, | |
166 | sizeof(struct bdevsw)) != 0)) { | |
167 | return(-1); | |
168 | } | |
169 | bdevsw[index] = nobdev; | |
170 | return(index); | |
171 | } | |
172 | ||
173 | /* | |
174 | * if index is -1, return a free slot if avaliable | |
175 | * else see whether the index is free | |
176 | * return the major number that is free else -1 | |
177 | */ | |
178 | int | |
179 | cdevsw_isfree(int index) | |
180 | { | |
181 | struct cdevsw *devsw; | |
182 | ||
183 | if (index == -1) { | |
184 | devsw = cdevsw; | |
185 | for(index=0; index < nchrdev; index++, devsw++) { | |
186 | if(memcmp((char *)devsw, | |
187 | (char *)&nocdev, | |
188 | sizeof(struct cdevsw)) == 0) | |
189 | break; | |
190 | } | |
191 | } | |
192 | devsw = &cdevsw[index]; | |
193 | if ((index < 0) || (index >= nchrdev) || | |
194 | (memcmp((char *)devsw, | |
195 | (char *)&nocdev, | |
196 | sizeof(struct cdevsw)) != 0)) { | |
197 | return(-1); | |
198 | } | |
199 | return(index); | |
200 | } | |
201 | ||
202 | /* | |
203 | * if index is -1, find a free slot to add | |
204 | * else see whether the slot is free | |
205 | * return the major number that is used else -1 | |
206 | */ | |
207 | int | |
208 | cdevsw_add(int index, struct cdevsw * csw) | |
209 | { | |
210 | struct cdevsw *devsw; | |
211 | ||
212 | if (index == -1) { | |
213 | devsw = cdevsw; | |
214 | for(index=0; index < nchrdev; index++, devsw++) { | |
215 | if(memcmp((char *)devsw, | |
216 | (char *)&nocdev, | |
217 | sizeof(struct cdevsw)) == 0) | |
218 | break; | |
219 | } | |
220 | } | |
221 | devsw = &cdevsw[index]; | |
222 | if ((index < 0) || (index >= nchrdev) || | |
223 | (memcmp((char *)devsw, | |
224 | (char *)&nocdev, | |
225 | sizeof(struct cdevsw)) != 0)) { | |
226 | return(-1); | |
227 | } | |
228 | cdevsw[index] = *csw; | |
229 | return(index); | |
230 | } | |
231 | /* | |
232 | * if the index has the same bsw, then remove | |
233 | * else -1 | |
234 | */ | |
235 | int | |
236 | cdevsw_remove(int index, struct cdevsw * csw) | |
237 | { | |
238 | struct cdevsw *devsw; | |
239 | ||
240 | devsw = &cdevsw[index]; | |
241 | if ((index < 0) || (index >= nchrdev) || | |
242 | (memcmp((char *)devsw, | |
243 | (char *)csw, | |
244 | sizeof(struct cdevsw)) != 0)) { | |
245 | return(-1); | |
246 | } | |
247 | cdevsw[index] = nocdev; | |
248 | return(index); | |
249 | } | |
250 | ||
9bccf70c A |
251 | static int |
252 | cdev_set_bdev(int cdev, int bdev) | |
253 | { | |
254 | extern int chrtoblk_add(int cdev, int bdev); | |
255 | ||
256 | return (chrtoblk_set(cdev, bdev)); | |
257 | } | |
258 | ||
259 | int | |
260 | cdevsw_add_with_bdev(int index, struct cdevsw * csw, int bdev) | |
261 | { | |
262 | index = cdevsw_add(index, csw); | |
263 | if (index < 0) { | |
264 | return (index); | |
265 | } | |
266 | if (cdev_set_bdev(index, bdev) < 0) { | |
267 | cdevsw_remove(index, csw); | |
268 | return (-1); | |
269 | } | |
270 | return (index); | |
271 | } | |
272 | ||
1c79356b A |
273 | issingleuser(void) |
274 | { | |
275 | char namep[16]; | |
276 | ||
277 | ||
278 | if (PE_parse_boot_arg("-s", namep)) { | |
279 | return(1); | |
280 | } else { | |
281 | return(0); | |
282 | } | |
283 | } | |
284 | ||
285 | void * | |
286 | tbeproc(void *procp) | |
287 | { | |
288 | struct proc *p = procp; | |
289 | ||
290 | if (p) | |
291 | SET(p->p_flag, P_TBE); | |
292 | return; | |
293 | } | |
294 |