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