sunos_misc.c revision 1.54 1 1.54 thorpej /* $NetBSD: sunos_misc.c,v 1.54 1995/09/19 22:42:04 thorpej Exp $ */
2 1.30 cgd
3 1.1 deraadt /*
4 1.1 deraadt * Copyright (c) 1992, 1993
5 1.1 deraadt * The Regents of the University of California. All rights reserved.
6 1.1 deraadt *
7 1.1 deraadt * This software was developed by the Computer Systems Engineering group
8 1.1 deraadt * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 deraadt * contributed to Berkeley.
10 1.1 deraadt *
11 1.1 deraadt * All advertising materials mentioning features or use of this software
12 1.1 deraadt * must display the following acknowledgement:
13 1.1 deraadt * This product includes software developed by the University of
14 1.1 deraadt * California, Lawrence Berkeley Laboratory.
15 1.1 deraadt *
16 1.1 deraadt * Redistribution and use in source and binary forms, with or without
17 1.1 deraadt * modification, are permitted provided that the following conditions
18 1.1 deraadt * are met:
19 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
20 1.1 deraadt * notice, this list of conditions and the following disclaimer.
21 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
23 1.1 deraadt * documentation and/or other materials provided with the distribution.
24 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
25 1.1 deraadt * must display the following acknowledgement:
26 1.1 deraadt * This product includes software developed by the University of
27 1.1 deraadt * California, Berkeley and its contributors.
28 1.1 deraadt * 4. Neither the name of the University nor the names of its contributors
29 1.1 deraadt * may be used to endorse or promote products derived from this software
30 1.1 deraadt * without specific prior written permission.
31 1.1 deraadt *
32 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 deraadt * SUCH DAMAGE.
43 1.1 deraadt *
44 1.33 deraadt * @(#)sunos_misc.c 8.1 (Berkeley) 6/18/93
45 1.1 deraadt *
46 1.33 deraadt * Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
47 1.1 deraadt */
48 1.1 deraadt
49 1.1 deraadt /*
50 1.1 deraadt * SunOS compatibility module.
51 1.1 deraadt *
52 1.1 deraadt * SunOS system calls that are implemented differently in BSD are
53 1.1 deraadt * handled here.
54 1.1 deraadt */
55 1.1 deraadt
56 1.1 deraadt #include <sys/param.h>
57 1.1 deraadt #include <sys/systm.h>
58 1.10 deraadt #include <sys/namei.h>
59 1.1 deraadt #include <sys/proc.h>
60 1.27 pk #include <sys/dir.h>
61 1.1 deraadt #include <sys/file.h>
62 1.10 deraadt #include <sys/stat.h>
63 1.1 deraadt #include <sys/filedesc.h>
64 1.1 deraadt #include <sys/ioctl.h>
65 1.8 deraadt #include <sys/kernel.h>
66 1.44 christos #include <sys/reboot.h>
67 1.1 deraadt #include <sys/malloc.h>
68 1.1 deraadt #include <sys/mbuf.h>
69 1.1 deraadt #include <sys/mman.h>
70 1.1 deraadt #include <sys/mount.h>
71 1.35 deraadt #include <sys/ptrace.h>
72 1.1 deraadt #include <sys/resource.h>
73 1.1 deraadt #include <sys/resourcevar.h>
74 1.1 deraadt #include <sys/signal.h>
75 1.1 deraadt #include <sys/signalvar.h>
76 1.1 deraadt #include <sys/socket.h>
77 1.1 deraadt #include <sys/vnode.h>
78 1.1 deraadt #include <sys/uio.h>
79 1.1 deraadt #include <sys/wait.h>
80 1.8 deraadt #include <sys/utsname.h>
81 1.12 deraadt #include <sys/unistd.h>
82 1.33 deraadt #include <sys/syscallargs.h>
83 1.33 deraadt #include <compat/sunos/sunos.h>
84 1.33 deraadt #include <compat/sunos/sunos_syscallargs.h>
85 1.48 pk #include <compat/sunos/sunos_util.h>
86 1.1 deraadt
87 1.10 deraadt #include <netinet/in.h>
88 1.10 deraadt
89 1.7 deraadt #include <miscfs/specfs/specdev.h>
90 1.1 deraadt
91 1.27 pk #include <nfs/rpcv2.h>
92 1.27 pk #include <nfs/nfsv2.h>
93 1.27 pk #include <nfs/nfs.h>
94 1.27 pk
95 1.1 deraadt #include <vm/vm.h>
96 1.1 deraadt
97 1.33 deraadt int
98 1.54 thorpej sunos_wait4(p, v, retval)
99 1.1 deraadt struct proc *p;
100 1.54 thorpej void *v;
101 1.32 cgd register_t *retval;
102 1.1 deraadt {
103 1.54 thorpej struct sunos_wait4_args *uap = v;
104 1.33 deraadt if (SCARG(uap, pid) == 0)
105 1.33 deraadt SCARG(uap, pid) = WAIT_ANY;
106 1.54 thorpej return (wait4(p, uap, retval));
107 1.1 deraadt }
108 1.1 deraadt
109 1.33 deraadt int
110 1.54 thorpej sunos_creat(p, v, retval)
111 1.1 deraadt struct proc *p;
112 1.54 thorpej void *v;
113 1.32 cgd register_t *retval;
114 1.1 deraadt {
115 1.54 thorpej struct sunos_creat_args *uap = v;
116 1.33 deraadt struct sunos_open_args ouap;
117 1.1 deraadt
118 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
119 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
120 1.48 pk
121 1.33 deraadt SCARG(&ouap, path) = SCARG(uap, path);
122 1.33 deraadt SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
123 1.33 deraadt SCARG(&ouap, mode) = SCARG(uap, mode);
124 1.33 deraadt return (open(p, &ouap, retval));
125 1.1 deraadt }
126 1.1 deraadt
127 1.33 deraadt int
128 1.54 thorpej sunos_access(p, v, retval)
129 1.48 pk struct proc *p;
130 1.54 thorpej void *v;
131 1.48 pk register_t *retval;
132 1.48 pk {
133 1.54 thorpej struct sunos_access_args *uap = v;
134 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
135 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
136 1.48 pk
137 1.48 pk return (access(p, uap, retval));
138 1.48 pk }
139 1.48 pk
140 1.48 pk int
141 1.54 thorpej sunos_stat(p, v, retval)
142 1.48 pk struct proc *p;
143 1.54 thorpej void *v;
144 1.48 pk register_t *retval;
145 1.48 pk {
146 1.54 thorpej struct sunos_stat_args *uap = v;
147 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
148 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
149 1.48 pk
150 1.48 pk return (compat_43_stat(p, uap, retval));
151 1.48 pk }
152 1.48 pk
153 1.48 pk int
154 1.54 thorpej sunos_lstat(p, v, retval)
155 1.48 pk struct proc *p;
156 1.54 thorpej void *v;
157 1.48 pk register_t *retval;
158 1.48 pk {
159 1.54 thorpej struct sunos_lstat_args *uap = v;
160 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
161 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
162 1.48 pk
163 1.48 pk return (compat_43_lstat(p, uap, retval));
164 1.48 pk }
165 1.48 pk
166 1.48 pk int
167 1.54 thorpej sunos_execv(p, v, retval)
168 1.1 deraadt struct proc *p;
169 1.54 thorpej void *v;
170 1.32 cgd register_t *retval;
171 1.1 deraadt {
172 1.54 thorpej struct sunos_execv_args *uap = v;
173 1.33 deraadt struct execve_args ouap;
174 1.1 deraadt
175 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
176 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
177 1.48 pk
178 1.33 deraadt SCARG(&ouap, path) = SCARG(uap, path);
179 1.33 deraadt SCARG(&ouap, argp) = SCARG(uap, argp);
180 1.33 deraadt SCARG(&ouap, envp) = NULL;
181 1.33 deraadt return (execve(p, &ouap, retval));
182 1.1 deraadt }
183 1.1 deraadt
184 1.33 deraadt int
185 1.54 thorpej sunos_omsync(p, v, retval)
186 1.1 deraadt struct proc *p;
187 1.54 thorpej void *v;
188 1.32 cgd register_t *retval;
189 1.1 deraadt {
190 1.54 thorpej struct sunos_omsync_args *uap = v;
191 1.33 deraadt struct msync_args ouap;
192 1.1 deraadt
193 1.33 deraadt if (SCARG(uap, flags))
194 1.1 deraadt return (EINVAL);
195 1.33 deraadt SCARG(&ouap, addr) = SCARG(uap, addr);
196 1.33 deraadt SCARG(&ouap, len) = SCARG(uap, len);
197 1.33 deraadt return (msync(p, &ouap, retval));
198 1.1 deraadt }
199 1.1 deraadt
200 1.33 deraadt int
201 1.54 thorpej sunos_unmount(p, v, retval)
202 1.33 deraadt struct proc *p;
203 1.54 thorpej void *v;
204 1.32 cgd register_t *retval;
205 1.1 deraadt {
206 1.54 thorpej struct sunos_unmount_args *uap = 0;
207 1.54 thorpej
208 1.33 deraadt SCARG(uap, flags) = 0;
209 1.33 deraadt return (unmount(p, (struct unmount_args *)uap, retval));
210 1.33 deraadt }
211 1.1 deraadt
212 1.33 deraadt int
213 1.54 thorpej sunos_mount(p, v, retval)
214 1.1 deraadt struct proc *p;
215 1.54 thorpej void *v;
216 1.32 cgd register_t *retval;
217 1.1 deraadt {
218 1.54 thorpej struct sunos_mount_args *uap = v;
219 1.51 briggs struct emul *e = p->p_emul;
220 1.33 deraadt int oflags = SCARG(uap, flags), nflags, error;
221 1.16 deraadt char fsname[MFSNAMELEN];
222 1.16 deraadt
223 1.1 deraadt if (oflags & (SUNM_NOSUB | SUNM_SYS5))
224 1.1 deraadt return (EINVAL);
225 1.16 deraadt if ((oflags & SUNM_NEWTYPE) == 0)
226 1.16 deraadt return (EINVAL);
227 1.1 deraadt nflags = 0;
228 1.1 deraadt if (oflags & SUNM_RDONLY)
229 1.1 deraadt nflags |= MNT_RDONLY;
230 1.1 deraadt if (oflags & SUNM_NOSUID)
231 1.1 deraadt nflags |= MNT_NOSUID;
232 1.1 deraadt if (oflags & SUNM_REMOUNT)
233 1.1 deraadt nflags |= MNT_UPDATE;
234 1.33 deraadt SCARG(uap, flags) = nflags;
235 1.10 deraadt
236 1.33 deraadt if (error = copyinstr((caddr_t)SCARG(uap, type), fsname,
237 1.42 mycroft sizeof fsname, (size_t *)0))
238 1.16 deraadt return (error);
239 1.16 deraadt
240 1.49 cgd if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
241 1.33 deraadt SCARG(uap, type) = STACKGAPBASE;
242 1.33 deraadt if (error = copyout("ufs", SCARG(uap, type), sizeof("ufs")))
243 1.16 deraadt return (error);
244 1.49 cgd } else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
245 1.33 deraadt struct sunos_nfs_args sna;
246 1.10 deraadt struct sockaddr_in sain;
247 1.10 deraadt struct nfs_args na;
248 1.10 deraadt struct sockaddr sa;
249 1.10 deraadt
250 1.33 deraadt if (error = copyin(SCARG(uap, data), &sna, sizeof sna))
251 1.10 deraadt return (error);
252 1.10 deraadt if (error = copyin(sna.addr, &sain, sizeof sain))
253 1.10 deraadt return (error);
254 1.10 deraadt bcopy(&sain, &sa, sizeof sa);
255 1.10 deraadt sa.sa_len = sizeof(sain);
256 1.33 deraadt SCARG(uap, data) = STACKGAPBASE;
257 1.33 deraadt na.addr = (struct sockaddr *)((int)SCARG(uap, data) + sizeof na);
258 1.29 pk na.addrlen = sizeof(struct sockaddr);
259 1.10 deraadt na.sotype = SOCK_DGRAM;
260 1.10 deraadt na.proto = IPPROTO_UDP;
261 1.10 deraadt na.fh = (nfsv2fh_t *)sna.fh;
262 1.10 deraadt na.flags = sna.flags;
263 1.10 deraadt na.wsize = sna.wsize;
264 1.10 deraadt na.rsize = sna.rsize;
265 1.10 deraadt na.timeo = sna.timeo;
266 1.10 deraadt na.retrans = sna.retrans;
267 1.10 deraadt na.hostname = sna.hostname;
268 1.10 deraadt
269 1.10 deraadt if (error = copyout(&sa, na.addr, sizeof sa))
270 1.10 deraadt return (error);
271 1.33 deraadt if (error = copyout(&na, SCARG(uap, data), sizeof na))
272 1.10 deraadt return (error);
273 1.10 deraadt }
274 1.33 deraadt return (mount(p, (struct mount_args *)uap, retval));
275 1.1 deraadt }
276 1.1 deraadt
277 1.28 deraadt #if defined(NFSCLIENT)
278 1.33 deraadt int
279 1.27 pk async_daemon(p, uap, retval)
280 1.27 pk struct proc *p;
281 1.27 pk void *uap;
282 1.32 cgd register_t *retval;
283 1.27 pk {
284 1.33 deraadt struct nfssvc_args ouap;
285 1.27 pk
286 1.33 deraadt SCARG(&ouap, flag) = NFSSVC_BIOD;
287 1.33 deraadt SCARG(&ouap, argp) = NULL;
288 1.33 deraadt return nfssvc(p, &ouap, retval);
289 1.27 pk }
290 1.28 deraadt #endif /* NFSCLIENT */
291 1.27 pk
292 1.33 deraadt int
293 1.54 thorpej sunos_sigpending(p, v, retval)
294 1.1 deraadt struct proc *p;
295 1.54 thorpej void *v;
296 1.32 cgd register_t *retval;
297 1.1 deraadt {
298 1.54 thorpej struct sunos_sigpending_args *uap = v;
299 1.21 deraadt int mask = p->p_siglist & p->p_sigmask;
300 1.1 deraadt
301 1.33 deraadt return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
302 1.1 deraadt }
303 1.1 deraadt
304 1.1 deraadt /*
305 1.1 deraadt * Read Sun-style directory entries. We suck them into kernel space so
306 1.1 deraadt * that they can be massaged before being copied out to user code. Like
307 1.1 deraadt * SunOS, we squish out `empty' entries.
308 1.1 deraadt *
309 1.1 deraadt * This is quite ugly, but what do you expect from compatibility code?
310 1.1 deraadt */
311 1.33 deraadt int
312 1.54 thorpej sunos_getdents(p, v, retval)
313 1.1 deraadt struct proc *p;
314 1.54 thorpej void *v;
315 1.32 cgd register_t *retval;
316 1.1 deraadt {
317 1.54 thorpej register struct sunos_getdents_args *uap = v;
318 1.1 deraadt register struct vnode *vp;
319 1.1 deraadt register caddr_t inp, buf; /* BSD-format */
320 1.1 deraadt register int len, reclen; /* BSD-format */
321 1.1 deraadt register caddr_t outp; /* Sun-format */
322 1.1 deraadt register int resid; /* Sun-format */
323 1.1 deraadt struct file *fp;
324 1.1 deraadt struct uio auio;
325 1.1 deraadt struct iovec aiov;
326 1.1 deraadt off_t off; /* true file offset */
327 1.1 deraadt long soff; /* Sun file offset */
328 1.1 deraadt int buflen, error, eofflag;
329 1.1 deraadt #define BSD_DIRENT(cp) ((struct dirent *)(cp))
330 1.33 deraadt #define SUNOS_RECLEN(reclen) (reclen + sizeof(long))
331 1.1 deraadt
332 1.33 deraadt if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
333 1.1 deraadt return (error);
334 1.1 deraadt if ((fp->f_flag & FREAD) == 0)
335 1.1 deraadt return (EBADF);
336 1.1 deraadt vp = (struct vnode *)fp->f_data;
337 1.1 deraadt if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
338 1.1 deraadt return (EINVAL);
339 1.33 deraadt buflen = min(MAXBSIZE, SCARG(uap, nbytes));
340 1.1 deraadt buf = malloc(buflen, M_TEMP, M_WAITOK);
341 1.1 deraadt VOP_LOCK(vp);
342 1.1 deraadt off = fp->f_offset;
343 1.1 deraadt again:
344 1.1 deraadt aiov.iov_base = buf;
345 1.1 deraadt aiov.iov_len = buflen;
346 1.1 deraadt auio.uio_iov = &aiov;
347 1.1 deraadt auio.uio_iovcnt = 1;
348 1.1 deraadt auio.uio_rw = UIO_READ;
349 1.1 deraadt auio.uio_segflg = UIO_SYSSPACE;
350 1.1 deraadt auio.uio_procp = p;
351 1.1 deraadt auio.uio_resid = buflen;
352 1.1 deraadt auio.uio_offset = off;
353 1.1 deraadt /*
354 1.1 deraadt * First we read into the malloc'ed buffer, then
355 1.1 deraadt * we massage it into user space, one record at a time.
356 1.1 deraadt */
357 1.33 deraadt if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag,
358 1.33 deraadt (u_long *)0, 0))
359 1.1 deraadt goto out;
360 1.1 deraadt inp = buf;
361 1.33 deraadt outp = SCARG(uap, buf);
362 1.33 deraadt resid = SCARG(uap, nbytes);
363 1.1 deraadt if ((len = buflen - auio.uio_resid) == 0)
364 1.1 deraadt goto eof;
365 1.1 deraadt for (; len > 0; len -= reclen) {
366 1.1 deraadt reclen = ((struct dirent *)inp)->d_reclen;
367 1.1 deraadt if (reclen & 3)
368 1.33 deraadt panic("sunos_getdents");
369 1.1 deraadt off += reclen; /* each entry points to next */
370 1.1 deraadt if (BSD_DIRENT(inp)->d_fileno == 0) {
371 1.1 deraadt inp += reclen; /* it is a hole; squish it out */
372 1.1 deraadt continue;
373 1.1 deraadt }
374 1.33 deraadt if (reclen > len || resid < SUNOS_RECLEN(reclen)) {
375 1.1 deraadt /* entry too big for buffer, so just stop */
376 1.1 deraadt outp++;
377 1.1 deraadt break;
378 1.1 deraadt }
379 1.1 deraadt /*
380 1.1 deraadt * Massage in place to make a Sun-shaped dirent (otherwise
381 1.1 deraadt * we have to worry about touching user memory outside of
382 1.1 deraadt * the copyout() call).
383 1.1 deraadt */
384 1.33 deraadt BSD_DIRENT(inp)->d_reclen = SUNOS_RECLEN(reclen);
385 1.4 deraadt #if notdef
386 1.4 deraadt BSD_DIRENT(inp)->d_type = 0; /* 4.4 specific */
387 1.4 deraadt #endif
388 1.1 deraadt soff = off;
389 1.1 deraadt if ((error = copyout((caddr_t)&soff, outp, sizeof soff)) != 0 ||
390 1.1 deraadt (error = copyout(inp, outp + sizeof soff, reclen)) != 0)
391 1.1 deraadt goto out;
392 1.1 deraadt /* advance past this real entry */
393 1.1 deraadt inp += reclen;
394 1.1 deraadt /* advance output past Sun-shaped entry */
395 1.33 deraadt outp += SUNOS_RECLEN(reclen);
396 1.33 deraadt resid -= SUNOS_RECLEN(reclen);
397 1.1 deraadt }
398 1.1 deraadt /* if we squished out the whole block, try again */
399 1.33 deraadt if (outp == SCARG(uap, buf))
400 1.1 deraadt goto again;
401 1.1 deraadt fp->f_offset = off; /* update the vnode offset */
402 1.1 deraadt eof:
403 1.33 deraadt *retval = SCARG(uap, nbytes) - resid;
404 1.1 deraadt out:
405 1.1 deraadt VOP_UNLOCK(vp);
406 1.1 deraadt free(buf, M_TEMP);
407 1.1 deraadt return (error);
408 1.1 deraadt }
409 1.1 deraadt
410 1.33 deraadt #define SUNOS__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
411 1.4 deraadt
412 1.33 deraadt int
413 1.54 thorpej sunos_mmap(p, v, retval)
414 1.1 deraadt register struct proc *p;
415 1.54 thorpej void *v;
416 1.32 cgd register_t *retval;
417 1.1 deraadt {
418 1.54 thorpej register struct sunos_mmap_args *uap = v;
419 1.33 deraadt struct mmap_args ouap;
420 1.1 deraadt register struct filedesc *fdp;
421 1.1 deraadt register struct file *fp;
422 1.1 deraadt register struct vnode *vp;
423 1.1 deraadt
424 1.1 deraadt /*
425 1.14 cgd * Verify the arguments.
426 1.1 deraadt */
427 1.33 deraadt if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
428 1.14 cgd return (EINVAL); /* XXX still needed? */
429 1.4 deraadt
430 1.33 deraadt if ((SCARG(uap, flags) & SUNOS__MAP_NEW) == 0)
431 1.1 deraadt return (EINVAL);
432 1.1 deraadt
433 1.34 deraadt SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUNOS__MAP_NEW;
434 1.34 deraadt SCARG(&ouap, addr) = SCARG(uap, addr);
435 1.34 deraadt
436 1.34 deraadt if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
437 1.34 deraadt SCARG(&ouap, addr) != 0 &&
438 1.34 deraadt SCARG(&ouap, addr) < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
439 1.34 deraadt SCARG(&ouap, addr) = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
440 1.34 deraadt
441 1.34 deraadt SCARG(&ouap, len) = SCARG(uap, len);
442 1.34 deraadt SCARG(&ouap, prot) = SCARG(uap, prot);
443 1.34 deraadt SCARG(&ouap, fd) = SCARG(uap, fd);
444 1.34 deraadt SCARG(&ouap, pos) = SCARG(uap, pos);
445 1.10 deraadt
446 1.1 deraadt /*
447 1.1 deraadt * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
448 1.1 deraadt */
449 1.1 deraadt fdp = p->p_fd;
450 1.34 deraadt if ((unsigned)SCARG(&ouap, fd) < fdp->fd_nfiles && /*XXX*/
451 1.34 deraadt (fp = fdp->fd_ofiles[SCARG(&ouap, fd)]) != NULL && /*XXX*/
452 1.1 deraadt fp->f_type == DTYPE_VNODE && /*XXX*/
453 1.1 deraadt (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
454 1.23 deraadt iszerodev(vp->v_rdev)) { /*XXX*/
455 1.34 deraadt SCARG(&ouap, flags) |= MAP_ANON;
456 1.34 deraadt SCARG(&ouap, fd) = -1;
457 1.14 cgd }
458 1.4 deraadt
459 1.34 deraadt return (mmap(p, &ouap, retval));
460 1.1 deraadt }
461 1.1 deraadt
462 1.1 deraadt #define MC_SYNC 1
463 1.1 deraadt #define MC_LOCK 2
464 1.1 deraadt #define MC_UNLOCK 3
465 1.1 deraadt #define MC_ADVISE 4
466 1.1 deraadt #define MC_LOCKAS 5
467 1.1 deraadt #define MC_UNLOCKAS 6
468 1.1 deraadt
469 1.33 deraadt int
470 1.54 thorpej sunos_mctl(p, v, retval)
471 1.1 deraadt register struct proc *p;
472 1.54 thorpej void *v;
473 1.32 cgd register_t *retval;
474 1.1 deraadt {
475 1.54 thorpej register struct sunos_mctl_args *uap = v;
476 1.1 deraadt
477 1.33 deraadt switch (SCARG(uap, func)) {
478 1.1 deraadt case MC_ADVISE: /* ignore for now */
479 1.1 deraadt return (0);
480 1.1 deraadt case MC_SYNC: /* translate to msync */
481 1.1 deraadt return (msync(p, uap, retval));
482 1.1 deraadt default:
483 1.1 deraadt return (EINVAL);
484 1.1 deraadt }
485 1.1 deraadt }
486 1.1 deraadt
487 1.33 deraadt int
488 1.54 thorpej sunos_setsockopt(p, v, retval)
489 1.1 deraadt struct proc *p;
490 1.54 thorpej void *v;
491 1.32 cgd register_t *retval;
492 1.1 deraadt {
493 1.54 thorpej register struct sunos_setsockopt_args *uap = v;
494 1.1 deraadt struct file *fp;
495 1.1 deraadt struct mbuf *m = NULL;
496 1.1 deraadt int error;
497 1.1 deraadt
498 1.33 deraadt if (error = getsock(p->p_fd, SCARG(uap, s), &fp))
499 1.1 deraadt return (error);
500 1.1 deraadt #define SO_DONTLINGER (~SO_LINGER)
501 1.33 deraadt if (SCARG(uap, name) == SO_DONTLINGER) {
502 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
503 1.1 deraadt if (m == NULL)
504 1.1 deraadt return (ENOBUFS);
505 1.1 deraadt mtod(m, struct linger *)->l_onoff = 0;
506 1.1 deraadt m->m_len = sizeof(struct linger);
507 1.33 deraadt return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
508 1.1 deraadt SO_LINGER, m));
509 1.1 deraadt }
510 1.37 pk if (SCARG(uap, level) == IPPROTO_IP) {
511 1.37 pk #define SUNOS_IP_MULTICAST_IF 2
512 1.37 pk #define SUNOS_IP_MULTICAST_TTL 3
513 1.37 pk #define SUNOS_IP_MULTICAST_LOOP 4
514 1.37 pk #define SUNOS_IP_ADD_MEMBERSHIP 5
515 1.37 pk #define SUNOS_IP_DROP_MEMBERSHIP 6
516 1.37 pk static int ipoptxlat[] = {
517 1.37 pk IP_MULTICAST_IF,
518 1.37 pk IP_MULTICAST_TTL,
519 1.37 pk IP_MULTICAST_LOOP,
520 1.37 pk IP_ADD_MEMBERSHIP,
521 1.37 pk IP_DROP_MEMBERSHIP
522 1.37 pk };
523 1.37 pk if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
524 1.37 pk SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
525 1.37 pk SCARG(uap, name) =
526 1.37 pk ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
527 1.37 pk }
528 1.37 pk }
529 1.33 deraadt if (SCARG(uap, valsize) > MLEN)
530 1.1 deraadt return (EINVAL);
531 1.33 deraadt if (SCARG(uap, val)) {
532 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
533 1.1 deraadt if (m == NULL)
534 1.1 deraadt return (ENOBUFS);
535 1.33 deraadt if (error = copyin(SCARG(uap, val), mtod(m, caddr_t),
536 1.33 deraadt (u_int)SCARG(uap, valsize))) {
537 1.1 deraadt (void) m_free(m);
538 1.1 deraadt return (error);
539 1.1 deraadt }
540 1.33 deraadt m->m_len = SCARG(uap, valsize);
541 1.1 deraadt }
542 1.33 deraadt return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
543 1.33 deraadt SCARG(uap, name), m));
544 1.1 deraadt }
545 1.1 deraadt
546 1.33 deraadt int
547 1.54 thorpej sunos_fchroot(p, v, retval)
548 1.1 deraadt register struct proc *p;
549 1.54 thorpej void *v;
550 1.32 cgd register_t *retval;
551 1.1 deraadt {
552 1.54 thorpej register struct sunos_fchroot_args *uap = v;
553 1.1 deraadt register struct filedesc *fdp = p->p_fd;
554 1.1 deraadt register struct vnode *vp;
555 1.1 deraadt struct file *fp;
556 1.1 deraadt int error;
557 1.1 deraadt
558 1.1 deraadt if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
559 1.1 deraadt return (error);
560 1.33 deraadt if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
561 1.1 deraadt return (error);
562 1.1 deraadt vp = (struct vnode *)fp->f_data;
563 1.1 deraadt VOP_LOCK(vp);
564 1.1 deraadt if (vp->v_type != VDIR)
565 1.1 deraadt error = ENOTDIR;
566 1.1 deraadt else
567 1.1 deraadt error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
568 1.1 deraadt VOP_UNLOCK(vp);
569 1.1 deraadt if (error)
570 1.1 deraadt return (error);
571 1.1 deraadt VREF(vp);
572 1.1 deraadt if (fdp->fd_rdir != NULL)
573 1.1 deraadt vrele(fdp->fd_rdir);
574 1.1 deraadt fdp->fd_rdir = vp;
575 1.1 deraadt return (0);
576 1.3 deraadt }
577 1.3 deraadt
578 1.3 deraadt /*
579 1.3 deraadt * XXX: This needs cleaning up.
580 1.3 deraadt */
581 1.33 deraadt int
582 1.40 deraadt sunos_auditsys(p, uap, retval)
583 1.40 deraadt struct proc *p;
584 1.40 deraadt void *uap;
585 1.40 deraadt register_t *retval;
586 1.3 deraadt {
587 1.3 deraadt return 0;
588 1.8 deraadt }
589 1.8 deraadt
590 1.33 deraadt int
591 1.54 thorpej sunos_uname(p, v, retval)
592 1.8 deraadt struct proc *p;
593 1.54 thorpej void *v;
594 1.32 cgd register_t *retval;
595 1.8 deraadt {
596 1.54 thorpej struct sunos_uname_args *uap = v;
597 1.33 deraadt struct sunos_utsname sut;
598 1.22 deraadt extern char ostype[], machine[], osrelease[];
599 1.8 deraadt
600 1.22 deraadt bzero(&sut, sizeof(sut));
601 1.8 deraadt
602 1.22 deraadt bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
603 1.22 deraadt bcopy(hostname, sut.nodename, sizeof(sut.nodename));
604 1.22 deraadt sut.nodename[sizeof(sut.nodename)-1] = '\0';
605 1.22 deraadt bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
606 1.22 deraadt bcopy("1", sut.version, sizeof(sut.version) - 1);
607 1.22 deraadt bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
608 1.8 deraadt
609 1.33 deraadt return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
610 1.33 deraadt sizeof(struct sunos_utsname));
611 1.8 deraadt }
612 1.8 deraadt
613 1.8 deraadt int
614 1.54 thorpej sunos_setpgid(p, v, retval)
615 1.8 deraadt struct proc *p;
616 1.54 thorpej void *v;
617 1.32 cgd register_t *retval;
618 1.8 deraadt {
619 1.54 thorpej struct sunos_setpgid_args *uap = v;
620 1.54 thorpej
621 1.8 deraadt /*
622 1.8 deraadt * difference to our setpgid call is to include backwards
623 1.8 deraadt * compatibility to pre-setsid() binaries. Do setsid()
624 1.8 deraadt * instead of setpgid() in those cases where the process
625 1.8 deraadt * tries to create a new session the old way.
626 1.8 deraadt */
627 1.33 deraadt if (!SCARG(uap, pgid) && (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
628 1.8 deraadt return setsid(p, uap, retval);
629 1.8 deraadt else
630 1.8 deraadt return setpgid(p, uap, retval);
631 1.8 deraadt }
632 1.8 deraadt
633 1.33 deraadt int
634 1.54 thorpej sunos_open(p, v, retval)
635 1.8 deraadt struct proc *p;
636 1.54 thorpej void *v;
637 1.32 cgd register_t *retval;
638 1.8 deraadt {
639 1.54 thorpej struct sunos_open_args *uap = v;
640 1.8 deraadt int l, r;
641 1.39 pk int noctty;
642 1.8 deraadt int ret;
643 1.8 deraadt
644 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
645 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
646 1.48 pk
647 1.8 deraadt /* convert mode into NetBSD mode */
648 1.39 pk l = SCARG(uap, flags);
649 1.39 pk noctty = l & 0x8000;
650 1.8 deraadt r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
651 1.8 deraadt r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
652 1.8 deraadt r |= ((l & 0x0080) ? O_SHLOCK : 0);
653 1.8 deraadt r |= ((l & 0x0100) ? O_EXLOCK : 0);
654 1.8 deraadt r |= ((l & 0x2000) ? O_FSYNC : 0);
655 1.8 deraadt
656 1.39 pk SCARG(uap, flags) = r;
657 1.33 deraadt ret = open(p, (struct open_args *)uap, retval);
658 1.8 deraadt
659 1.20 cgd if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
660 1.8 deraadt struct filedesc *fdp = p->p_fd;
661 1.8 deraadt struct file *fp = fdp->fd_ofiles[*retval];
662 1.8 deraadt
663 1.8 deraadt /* ignore any error, just give it a try */
664 1.8 deraadt if (fp->f_type == DTYPE_VNODE)
665 1.8 deraadt (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
666 1.8 deraadt }
667 1.8 deraadt return ret;
668 1.10 deraadt }
669 1.10 deraadt
670 1.11 chopps #if defined (NFSSERVER)
671 1.33 deraadt int
672 1.54 thorpej sunos_nfssvc(p, v, retval)
673 1.10 deraadt struct proc *p;
674 1.54 thorpej void *v;
675 1.32 cgd register_t *retval;
676 1.10 deraadt {
677 1.54 thorpej struct sunos_nfssvc_args *uap = v;
678 1.51 briggs struct emul *e = p->p_emul;
679 1.10 deraadt struct nfssvc_args outuap;
680 1.33 deraadt struct nfsd_srvargs nfsdarg;
681 1.10 deraadt struct sockaddr sa;
682 1.10 deraadt int error;
683 1.10 deraadt
684 1.33 deraadt #if 0
685 1.10 deraadt bzero(&outuap, sizeof outuap);
686 1.33 deraadt SCARG(&outuap, fd) = SCARG(uap, fd);
687 1.33 deraadt SCARG(&outuap, mskval) = STACKGAPBASE;
688 1.33 deraadt SCARG(&outuap, msklen) = sizeof sa;
689 1.33 deraadt SCARG(&outuap, mtchval) = SCARG(&outuap, mskval) + sizeof sa;
690 1.33 deraadt SCARG(&outuap, mtchlen) = sizeof sa;
691 1.10 deraadt
692 1.10 deraadt bzero(&sa, sizeof sa);
693 1.33 deraadt if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
694 1.10 deraadt return (error);
695 1.33 deraadt if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
696 1.10 deraadt return (error);
697 1.10 deraadt
698 1.10 deraadt return nfssvc(p, &outuap, retval);
699 1.33 deraadt #else
700 1.33 deraadt return (ENOSYS);
701 1.33 deraadt #endif
702 1.10 deraadt }
703 1.11 chopps #endif /* NFSSERVER */
704 1.10 deraadt
705 1.33 deraadt int
706 1.54 thorpej sunos_ustat(p, v, retval)
707 1.10 deraadt struct proc *p;
708 1.54 thorpej void *v;
709 1.32 cgd register_t *retval;
710 1.10 deraadt {
711 1.54 thorpej struct sunos_ustat_args *uap = v;
712 1.33 deraadt struct sunos_ustat us;
713 1.10 deraadt int error;
714 1.10 deraadt
715 1.10 deraadt bzero(&us, sizeof us);
716 1.10 deraadt
717 1.10 deraadt /*
718 1.10 deraadt * XXX: should set f_tfree and f_tinode at least
719 1.33 deraadt * How do we translate dev -> fstat? (and then to sunos_ustat)
720 1.10 deraadt */
721 1.10 deraadt
722 1.33 deraadt if (error = copyout(&us, SCARG(uap, buf), sizeof us))
723 1.10 deraadt return (error);
724 1.10 deraadt return 0;
725 1.10 deraadt }
726 1.10 deraadt
727 1.33 deraadt int
728 1.54 thorpej sunos_quotactl(p, v, retval)
729 1.10 deraadt struct proc *p;
730 1.54 thorpej void *v;
731 1.32 cgd register_t *retval;
732 1.10 deraadt {
733 1.54 thorpej struct sunos_quotactl_args *uap = v;
734 1.54 thorpej
735 1.10 deraadt return EINVAL;
736 1.10 deraadt }
737 1.10 deraadt
738 1.33 deraadt int
739 1.33 deraadt sunos_vhangup(p, uap, retval)
740 1.10 deraadt struct proc *p;
741 1.10 deraadt void *uap;
742 1.32 cgd register_t *retval;
743 1.10 deraadt {
744 1.10 deraadt return 0;
745 1.10 deraadt }
746 1.10 deraadt
747 1.10 deraadt static
748 1.10 deraadt sunstatfs(sp, buf)
749 1.10 deraadt struct statfs *sp;
750 1.10 deraadt caddr_t buf;
751 1.10 deraadt {
752 1.33 deraadt struct sunos_statfs ssfs;
753 1.10 deraadt
754 1.10 deraadt bzero(&ssfs, sizeof ssfs);
755 1.10 deraadt ssfs.f_type = 0;
756 1.16 deraadt ssfs.f_bsize = sp->f_bsize;
757 1.10 deraadt ssfs.f_blocks = sp->f_blocks;
758 1.10 deraadt ssfs.f_bfree = sp->f_bfree;
759 1.10 deraadt ssfs.f_bavail = sp->f_bavail;
760 1.10 deraadt ssfs.f_files = sp->f_files;
761 1.10 deraadt ssfs.f_ffree = sp->f_ffree;
762 1.10 deraadt ssfs.f_fsid = sp->f_fsid;
763 1.10 deraadt return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
764 1.10 deraadt }
765 1.10 deraadt
766 1.33 deraadt int
767 1.54 thorpej sunos_statfs(p, v, retval)
768 1.10 deraadt struct proc *p;
769 1.54 thorpej void *v;
770 1.32 cgd register_t *retval;
771 1.10 deraadt {
772 1.54 thorpej struct sunos_statfs_args *uap = v;
773 1.10 deraadt register struct mount *mp;
774 1.10 deraadt register struct statfs *sp;
775 1.10 deraadt int error;
776 1.10 deraadt struct nameidata nd;
777 1.10 deraadt
778 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
779 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
780 1.48 pk
781 1.33 deraadt NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
782 1.27 pk if (error = namei(&nd))
783 1.10 deraadt return (error);
784 1.27 pk mp = nd.ni_vp->v_mount;
785 1.10 deraadt sp = &mp->mnt_stat;
786 1.27 pk vrele(nd.ni_vp);
787 1.10 deraadt if (error = VFS_STATFS(mp, sp, p))
788 1.10 deraadt return (error);
789 1.10 deraadt sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
790 1.33 deraadt return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
791 1.10 deraadt }
792 1.10 deraadt
793 1.33 deraadt int
794 1.54 thorpej sunos_fstatfs(p, v, retval)
795 1.10 deraadt struct proc *p;
796 1.54 thorpej void *v;
797 1.32 cgd register_t *retval;
798 1.10 deraadt {
799 1.54 thorpej struct sunos_fstatfs_args *uap = v;
800 1.10 deraadt struct file *fp;
801 1.10 deraadt struct mount *mp;
802 1.10 deraadt register struct statfs *sp;
803 1.10 deraadt int error;
804 1.10 deraadt
805 1.33 deraadt if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
806 1.10 deraadt return (error);
807 1.10 deraadt mp = ((struct vnode *)fp->f_data)->v_mount;
808 1.10 deraadt sp = &mp->mnt_stat;
809 1.10 deraadt if (error = VFS_STATFS(mp, sp, p))
810 1.10 deraadt return (error);
811 1.10 deraadt sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
812 1.33 deraadt return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
813 1.10 deraadt }
814 1.10 deraadt
815 1.33 deraadt int
816 1.54 thorpej sunos_exportfs(p, v, retval)
817 1.10 deraadt struct proc *p;
818 1.54 thorpej void *v;
819 1.32 cgd register_t *retval;
820 1.10 deraadt {
821 1.54 thorpej struct sunos_exportfs_args *uap = v;
822 1.54 thorpej
823 1.10 deraadt /*
824 1.10 deraadt * XXX: should perhaps translate into a mount(2)
825 1.10 deraadt * with MOUNT_EXPORT?
826 1.10 deraadt */
827 1.10 deraadt return 0;
828 1.10 deraadt }
829 1.10 deraadt
830 1.33 deraadt int
831 1.54 thorpej sunos_mknod(p, v, retval)
832 1.10 deraadt struct proc *p;
833 1.54 thorpej void *v;
834 1.32 cgd register_t *retval;
835 1.10 deraadt {
836 1.54 thorpej struct sunos_mknod_args *uap = v;
837 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
838 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
839 1.48 pk
840 1.33 deraadt if (S_ISFIFO(SCARG(uap, mode)))
841 1.10 deraadt return mkfifo(p, uap, retval);
842 1.10 deraadt
843 1.33 deraadt return mknod(p, (struct mknod_args *)uap, retval);
844 1.12 deraadt }
845 1.12 deraadt
846 1.33 deraadt #define SUNOS_SC_ARG_MAX 1
847 1.33 deraadt #define SUNOS_SC_CHILD_MAX 2
848 1.33 deraadt #define SUNOS_SC_CLK_TCK 3
849 1.33 deraadt #define SUNOS_SC_NGROUPS_MAX 4
850 1.33 deraadt #define SUNOS_SC_OPEN_MAX 5
851 1.33 deraadt #define SUNOS_SC_JOB_CONTROL 6
852 1.33 deraadt #define SUNOS_SC_SAVED_IDS 7
853 1.33 deraadt #define SUNOS_SC_VERSION 8
854 1.12 deraadt
855 1.33 deraadt int
856 1.54 thorpej sunos_sysconf(p, v, retval)
857 1.12 deraadt struct proc *p;
858 1.54 thorpej void *v;
859 1.32 cgd register_t *retval;
860 1.12 deraadt {
861 1.54 thorpej struct sunos_sysconf_args *uap = v;
862 1.24 deraadt extern int maxfiles;
863 1.12 deraadt
864 1.33 deraadt switch(SCARG(uap, name)) {
865 1.33 deraadt case SUNOS_SC_ARG_MAX:
866 1.12 deraadt *retval = ARG_MAX;
867 1.13 deraadt break;
868 1.33 deraadt case SUNOS_SC_CHILD_MAX:
869 1.12 deraadt *retval = maxproc;
870 1.13 deraadt break;
871 1.33 deraadt case SUNOS_SC_CLK_TCK:
872 1.12 deraadt *retval = 60; /* should this be `hz', ie. 100? */
873 1.13 deraadt break;
874 1.33 deraadt case SUNOS_SC_NGROUPS_MAX:
875 1.12 deraadt *retval = NGROUPS_MAX;
876 1.13 deraadt break;
877 1.33 deraadt case SUNOS_SC_OPEN_MAX:
878 1.24 deraadt *retval = maxfiles;
879 1.13 deraadt break;
880 1.33 deraadt case SUNOS_SC_JOB_CONTROL:
881 1.12 deraadt *retval = 1;
882 1.13 deraadt break;
883 1.33 deraadt case SUNOS_SC_SAVED_IDS:
884 1.12 deraadt #ifdef _POSIX_SAVED_IDS
885 1.12 deraadt *retval = 1;
886 1.12 deraadt #else
887 1.12 deraadt *retval = 0;
888 1.12 deraadt #endif
889 1.13 deraadt break;
890 1.33 deraadt case SUNOS_SC_VERSION:
891 1.12 deraadt *retval = 198808;
892 1.13 deraadt break;
893 1.12 deraadt default:
894 1.12 deraadt return EINVAL;
895 1.12 deraadt }
896 1.12 deraadt return 0;
897 1.17 pk }
898 1.17 pk
899 1.33 deraadt #define SUNOS_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */
900 1.33 deraadt #define SUNOS_RLIM_NLIMITS 7
901 1.17 pk
902 1.33 deraadt int
903 1.54 thorpej sunos_getrlimit(p, v, retval)
904 1.17 pk struct proc *p;
905 1.54 thorpej void *v;
906 1.32 cgd register_t *retval;
907 1.17 pk {
908 1.54 thorpej struct sunos_getrlimit_args *uap = v;
909 1.54 thorpej
910 1.33 deraadt if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
911 1.17 pk return EINVAL;
912 1.17 pk
913 1.33 deraadt if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
914 1.33 deraadt SCARG(uap, which) = RLIMIT_NOFILE;
915 1.17 pk
916 1.33 deraadt return compat_43_getrlimit(p, uap, retval);
917 1.17 pk }
918 1.17 pk
919 1.33 deraadt int
920 1.54 thorpej sunos_setrlimit(p, v, retval)
921 1.17 pk struct proc *p;
922 1.54 thorpej void *v;
923 1.32 cgd register_t *retval;
924 1.17 pk {
925 1.54 thorpej struct sunos_getrlimit_args *uap = v;
926 1.54 thorpej
927 1.33 deraadt if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
928 1.17 pk return EINVAL;
929 1.17 pk
930 1.33 deraadt if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
931 1.33 deraadt SCARG(uap, which) = RLIMIT_NOFILE;
932 1.17 pk
933 1.33 deraadt return compat_43_setrlimit(p, uap, retval);
934 1.35 deraadt }
935 1.36 deraadt
936 1.36 deraadt /* for the m68k machines */
937 1.36 deraadt #ifndef PT_GETFPREGS
938 1.36 deraadt #define PT_GETFPREGS -1
939 1.36 deraadt #endif
940 1.36 deraadt #ifndef PT_SETFPREGS
941 1.36 deraadt #define PT_SETFPREGS -1
942 1.36 deraadt #endif
943 1.35 deraadt
944 1.35 deraadt static int sreq2breq[] = {
945 1.35 deraadt PT_TRACE_ME, PT_READ_I, PT_READ_D, -1,
946 1.35 deraadt PT_WRITE_I, PT_WRITE_D, -1, PT_CONTINUE,
947 1.35 deraadt PT_KILL, -1, PT_ATTACH, PT_DETACH,
948 1.35 deraadt PT_GETREGS, PT_SETREGS, PT_GETFPREGS, PT_SETFPREGS
949 1.35 deraadt };
950 1.35 deraadt static int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
951 1.35 deraadt
952 1.54 thorpej sunos_ptrace(p, v, retval)
953 1.35 deraadt struct proc *p;
954 1.54 thorpej void *v;
955 1.35 deraadt int *retval;
956 1.35 deraadt {
957 1.54 thorpej struct sunos_ptrace_args *uap = v;
958 1.35 deraadt struct ptrace_args pa;
959 1.35 deraadt int req;
960 1.35 deraadt
961 1.35 deraadt req = SCARG(uap, req);
962 1.35 deraadt
963 1.35 deraadt if (req < 0 || req >= nreqs)
964 1.35 deraadt return (EINVAL);
965 1.35 deraadt
966 1.35 deraadt req = sreq2breq[req];
967 1.35 deraadt if (req == -1)
968 1.35 deraadt return (EINVAL);
969 1.35 deraadt
970 1.35 deraadt SCARG(&pa, req) = req;
971 1.35 deraadt SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
972 1.35 deraadt SCARG(&pa, addr) = (caddr_t)SCARG(uap, addr);
973 1.35 deraadt SCARG(&pa, data) = SCARG(uap, data);
974 1.35 deraadt
975 1.35 deraadt return ptrace(p, &pa, retval);
976 1.35 deraadt }
977 1.35 deraadt
978 1.35 deraadt static void
979 1.35 deraadt sunos_pollscan(p, pl, nfd, retval)
980 1.35 deraadt struct proc *p;
981 1.35 deraadt struct sunos_pollfd *pl;
982 1.35 deraadt int nfd;
983 1.35 deraadt register_t *retval;
984 1.35 deraadt {
985 1.35 deraadt register struct filedesc *fdp = p->p_fd;
986 1.35 deraadt register int msk, i;
987 1.35 deraadt struct file *fp;
988 1.35 deraadt int n = 0;
989 1.35 deraadt static int flag[3] = { FREAD, FWRITE, 0 };
990 1.35 deraadt static int pflag[3] = { SUNOS_POLLIN|SUNOS_POLLRDNORM,
991 1.35 deraadt SUNOS_POLLOUT, SUNOS_POLLERR };
992 1.35 deraadt
993 1.35 deraadt /*
994 1.35 deraadt * XXX: We need to implement the rest of the flags.
995 1.35 deraadt */
996 1.35 deraadt for (i = 0; i < nfd; i++) {
997 1.35 deraadt fp = fdp->fd_ofiles[pl[i].fd];
998 1.35 deraadt if (fp == NULL) {
999 1.35 deraadt if (pl[i].events & SUNOS_POLLNVAL) {
1000 1.35 deraadt pl[i].revents |= SUNOS_POLLNVAL;
1001 1.35 deraadt n++;
1002 1.35 deraadt }
1003 1.35 deraadt continue;
1004 1.35 deraadt }
1005 1.35 deraadt for (msk = 0; msk < 3; msk++) {
1006 1.35 deraadt if (pl[i].events & pflag[msk]) {
1007 1.35 deraadt if ((*fp->f_ops->fo_select)(fp, flag[msk], p)) {
1008 1.35 deraadt pl[i].revents |=
1009 1.35 deraadt pflag[msk] & pl[i].events;
1010 1.35 deraadt n++;
1011 1.35 deraadt }
1012 1.35 deraadt }
1013 1.35 deraadt }
1014 1.35 deraadt }
1015 1.35 deraadt *retval = n;
1016 1.35 deraadt }
1017 1.35 deraadt
1018 1.35 deraadt
1019 1.35 deraadt /*
1020 1.35 deraadt * We are using the same mechanism as select only we encode/decode args
1021 1.35 deraadt * differently.
1022 1.35 deraadt */
1023 1.35 deraadt int
1024 1.54 thorpej sunos_poll(p, v, retval)
1025 1.35 deraadt struct proc *p;
1026 1.54 thorpej void *v;
1027 1.35 deraadt register_t *retval;
1028 1.35 deraadt {
1029 1.54 thorpej struct sunos_poll_args *uap = v;
1030 1.35 deraadt int i, s;
1031 1.35 deraadt int error, error2;
1032 1.35 deraadt size_t sz = sizeof(struct sunos_pollfd) * SCARG(uap, nfds);
1033 1.35 deraadt struct sunos_pollfd *pl;
1034 1.35 deraadt int msec = SCARG(uap, timeout);
1035 1.35 deraadt struct timeval atv;
1036 1.35 deraadt int timo;
1037 1.35 deraadt u_int ni;
1038 1.35 deraadt int ncoll;
1039 1.35 deraadt extern int nselcoll, selwait;
1040 1.35 deraadt
1041 1.35 deraadt pl = (struct sunos_pollfd *) malloc(sz, M_TEMP, M_WAITOK);
1042 1.35 deraadt
1043 1.35 deraadt if (error = copyin(SCARG(uap, fds), pl, sz))
1044 1.35 deraadt goto bad;
1045 1.35 deraadt
1046 1.35 deraadt for (i = 0; i < SCARG(uap, nfds); i++)
1047 1.35 deraadt pl[i].revents = 0;
1048 1.35 deraadt
1049 1.35 deraadt if (msec != -1) {
1050 1.35 deraadt atv.tv_sec = msec / 1000;
1051 1.35 deraadt atv.tv_usec = (msec - (atv.tv_sec * 1000)) * 1000;
1052 1.35 deraadt
1053 1.35 deraadt if (itimerfix(&atv)) {
1054 1.35 deraadt error = EINVAL;
1055 1.35 deraadt goto done;
1056 1.35 deraadt }
1057 1.35 deraadt s = splclock();
1058 1.43 mycroft timeradd(&atv, &time, &atv);
1059 1.35 deraadt timo = hzto(&atv);
1060 1.35 deraadt /*
1061 1.35 deraadt * Avoid inadvertently sleeping forever.
1062 1.35 deraadt */
1063 1.35 deraadt if (timo == 0)
1064 1.35 deraadt timo = 1;
1065 1.35 deraadt splx(s);
1066 1.35 deraadt } else
1067 1.35 deraadt timo = 0;
1068 1.35 deraadt
1069 1.35 deraadt retry:
1070 1.35 deraadt ncoll = nselcoll;
1071 1.35 deraadt p->p_flag |= P_SELECT;
1072 1.35 deraadt sunos_pollscan(p, pl, SCARG(uap, nfds), retval);
1073 1.35 deraadt if (*retval)
1074 1.35 deraadt goto done;
1075 1.35 deraadt s = splhigh();
1076 1.35 deraadt if (timo && timercmp(&time, &atv, >=)) {
1077 1.35 deraadt splx(s);
1078 1.35 deraadt goto done;
1079 1.35 deraadt }
1080 1.35 deraadt if ((p->p_flag & P_SELECT) == 0 || nselcoll != ncoll) {
1081 1.35 deraadt splx(s);
1082 1.35 deraadt goto retry;
1083 1.35 deraadt }
1084 1.35 deraadt p->p_flag &= ~P_SELECT;
1085 1.35 deraadt error = tsleep((caddr_t)&selwait, PSOCK | PCATCH, "sunos_poll", timo);
1086 1.35 deraadt splx(s);
1087 1.35 deraadt if (error == 0)
1088 1.35 deraadt goto retry;
1089 1.35 deraadt
1090 1.35 deraadt done:
1091 1.35 deraadt p->p_flag &= ~P_SELECT;
1092 1.35 deraadt /* poll is not restarted after signals... */
1093 1.35 deraadt if (error == ERESTART)
1094 1.35 deraadt error = EINTR;
1095 1.35 deraadt if (error == EWOULDBLOCK)
1096 1.35 deraadt error = 0;
1097 1.35 deraadt
1098 1.35 deraadt if (error2 = copyout(pl, SCARG(uap, fds), sz))
1099 1.35 deraadt error = error2;
1100 1.35 deraadt
1101 1.35 deraadt bad:
1102 1.35 deraadt free((char *) pl, M_TEMP);
1103 1.35 deraadt
1104 1.35 deraadt return (error);
1105 1.44 christos }
1106 1.44 christos
1107 1.44 christos /*
1108 1.44 christos * SunOS reboot system call (for compatibility).
1109 1.44 christos * Sun lets you pass in a boot string which the PROM
1110 1.44 christos * saves and provides to the next boot program.
1111 1.44 christos */
1112 1.44 christos static struct sunos_howto_conv {
1113 1.46 gwr int sun_howto;
1114 1.44 christos int bsd_howto;
1115 1.44 christos } sunos_howto_conv[] = {
1116 1.44 christos { 0x001, RB_ASKNAME },
1117 1.44 christos { 0x002, RB_SINGLE },
1118 1.44 christos { 0x004, RB_NOSYNC },
1119 1.44 christos { 0x008, RB_HALT },
1120 1.44 christos { 0x080, RB_DUMP },
1121 1.44 christos { 0x000, 0 },
1122 1.44 christos };
1123 1.46 gwr #define SUNOS_RB_STRING 0x200
1124 1.44 christos
1125 1.46 gwr int
1126 1.54 thorpej sunos_reboot(p, v, retval)
1127 1.44 christos struct proc *p;
1128 1.54 thorpej void *v;
1129 1.46 gwr register_t *retval;
1130 1.44 christos {
1131 1.54 thorpej struct sunos_reboot_args *uap = v;
1132 1.44 christos struct sunos_howto_conv *convp;
1133 1.46 gwr int error, bsd_howto, sun_howto;
1134 1.44 christos
1135 1.44 christos if (error = suser(p->p_ucred, &p->p_acflag))
1136 1.44 christos return (error);
1137 1.44 christos
1138 1.44 christos /*
1139 1.44 christos * Convert howto bits to BSD format.
1140 1.44 christos */
1141 1.46 gwr sun_howto = SCARG(uap, howto);
1142 1.44 christos bsd_howto = 0;
1143 1.44 christos convp = sunos_howto_conv;
1144 1.46 gwr while (convp->sun_howto) {
1145 1.46 gwr if (sun_howto & convp->sun_howto)
1146 1.44 christos bsd_howto |= convp->bsd_howto;
1147 1.44 christos convp++;
1148 1.44 christos }
1149 1.44 christos
1150 1.47 christos #ifdef sun3
1151 1.44 christos /*
1152 1.44 christos * Sun RB_STRING (Get user supplied bootstring.)
1153 1.46 gwr * If the machine supports passing a string to the
1154 1.46 gwr * next booted kernel, add the machine name above
1155 1.46 gwr * and provide a reboot2() function (see sun3).
1156 1.44 christos */
1157 1.46 gwr if (sun_howto & SUNOS_RB_STRING) {
1158 1.46 gwr char bs[128];
1159 1.46 gwr
1160 1.47 christos error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0);
1161 1.47 christos if (error)
1162 1.47 christos return error;
1163 1.46 gwr
1164 1.46 gwr return (reboot2(bsd_howto, bs));
1165 1.44 christos }
1166 1.47 christos #endif /* sun3 */
1167 1.44 christos
1168 1.46 gwr return (boot(bsd_howto));
1169 1.50 christos }
1170 1.50 christos
1171 1.50 christos /*
1172 1.50 christos * Generalized interface signal handler, 4.3-compatible.
1173 1.50 christos */
1174 1.50 christos /* ARGSUSED */
1175 1.50 christos int
1176 1.54 thorpej sunos_sigvec(p, v, retval)
1177 1.50 christos struct proc *p;
1178 1.54 thorpej void *v;
1179 1.54 thorpej register_t *retval;
1180 1.54 thorpej {
1181 1.52 pk register struct sunos_sigvec_args /* {
1182 1.50 christos syscallarg(int) signum;
1183 1.50 christos syscallarg(struct sigvec *) nsv;
1184 1.50 christos syscallarg(struct sigvec *) osv;
1185 1.54 thorpej } */ *uap = v;
1186 1.50 christos struct sigvec vec;
1187 1.50 christos register struct sigacts *ps = p->p_sigacts;
1188 1.50 christos register struct sigvec *sv;
1189 1.50 christos register int signum;
1190 1.50 christos int bit, error;
1191 1.50 christos
1192 1.50 christos signum = SCARG(uap, signum);
1193 1.50 christos if (signum <= 0 || signum >= NSIG ||
1194 1.50 christos signum == SIGKILL || signum == SIGSTOP)
1195 1.50 christos return (EINVAL);
1196 1.50 christos sv = &vec;
1197 1.50 christos if (SCARG(uap, osv)) {
1198 1.50 christos *(sig_t *)&sv->sv_handler = ps->ps_sigact[signum];
1199 1.50 christos sv->sv_mask = ps->ps_catchmask[signum];
1200 1.50 christos bit = sigmask(signum);
1201 1.50 christos sv->sv_flags = 0;
1202 1.50 christos if ((ps->ps_sigonstack & bit) != 0)
1203 1.50 christos sv->sv_flags |= SV_ONSTACK;
1204 1.50 christos if ((ps->ps_sigintr & bit) != 0)
1205 1.50 christos sv->sv_flags |= SV_INTERRUPT;
1206 1.50 christos if (error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv),
1207 1.50 christos sizeof (vec)))
1208 1.50 christos return (error);
1209 1.50 christos }
1210 1.50 christos if (SCARG(uap, nsv)) {
1211 1.50 christos if (error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv,
1212 1.50 christos sizeof (vec)))
1213 1.50 christos return (error);
1214 1.50 christos /*
1215 1.53 gwr * SunOS uses the mask 0x0004 as SV_RESETHAND
1216 1.53 gwr * meaning: `reset to SIG_DFL on delivery'.
1217 1.53 gwr * We support only the bits in: 0xF
1218 1.53 gwr * (those bits are the same as ours)
1219 1.50 christos */
1220 1.53 gwr if (sv->sv_flags & ~0xF)
1221 1.53 gwr return (EINVAL);
1222 1.53 gwr /* SunOS binaries have a user-mode trampoline. */
1223 1.53 gwr sv->sv_flags |= SA_USERTRAMP;
1224 1.53 gwr /* Convert sigvec:SV_INTERRUPT to sigaction:SA_RESTART */
1225 1.53 gwr sv->sv_flags ^= SA_RESTART; /* same bit, inverted */
1226 1.50 christos setsigvec(p, signum, (struct sigaction *)sv);
1227 1.50 christos }
1228 1.50 christos return (0);
1229 1.1 deraadt }
1230