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