sunos_misc.c revision 1.60 1 1.60 pk /* $NetBSD: sunos_misc.c,v 1.60 1996/01/05 16:53:14 pk 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.60 pk #include <sys/tty.h>
78 1.1 deraadt #include <sys/vnode.h>
79 1.1 deraadt #include <sys/uio.h>
80 1.1 deraadt #include <sys/wait.h>
81 1.8 deraadt #include <sys/utsname.h>
82 1.12 deraadt #include <sys/unistd.h>
83 1.33 deraadt #include <sys/syscallargs.h>
84 1.55 mycroft
85 1.33 deraadt #include <compat/sunos/sunos.h>
86 1.33 deraadt #include <compat/sunos/sunos_syscallargs.h>
87 1.48 pk #include <compat/sunos/sunos_util.h>
88 1.56 mycroft #include <compat/sunos/sunos_dirent.h>
89 1.1 deraadt
90 1.10 deraadt #include <netinet/in.h>
91 1.10 deraadt
92 1.7 deraadt #include <miscfs/specfs/specdev.h>
93 1.1 deraadt
94 1.27 pk #include <nfs/rpcv2.h>
95 1.27 pk #include <nfs/nfsv2.h>
96 1.27 pk #include <nfs/nfs.h>
97 1.27 pk
98 1.1 deraadt #include <vm/vm.h>
99 1.1 deraadt
100 1.33 deraadt int
101 1.55 mycroft sunos_sys_wait4(p, v, retval)
102 1.1 deraadt struct proc *p;
103 1.54 thorpej void *v;
104 1.32 cgd register_t *retval;
105 1.1 deraadt {
106 1.55 mycroft struct sunos_sys_wait4_args *uap = v;
107 1.33 deraadt if (SCARG(uap, pid) == 0)
108 1.33 deraadt SCARG(uap, pid) = WAIT_ANY;
109 1.55 mycroft return (sys_wait4(p, uap, retval));
110 1.1 deraadt }
111 1.1 deraadt
112 1.33 deraadt int
113 1.55 mycroft sunos_sys_creat(p, v, retval)
114 1.1 deraadt struct proc *p;
115 1.54 thorpej void *v;
116 1.32 cgd register_t *retval;
117 1.1 deraadt {
118 1.55 mycroft struct sunos_sys_creat_args *uap = v;
119 1.55 mycroft struct sys_open_args ouap;
120 1.1 deraadt
121 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
122 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
123 1.48 pk
124 1.33 deraadt SCARG(&ouap, path) = SCARG(uap, path);
125 1.33 deraadt SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
126 1.33 deraadt SCARG(&ouap, mode) = SCARG(uap, mode);
127 1.55 mycroft
128 1.55 mycroft return (sys_open(p, &ouap, retval));
129 1.1 deraadt }
130 1.1 deraadt
131 1.33 deraadt int
132 1.55 mycroft sunos_sys_access(p, v, retval)
133 1.48 pk struct proc *p;
134 1.54 thorpej void *v;
135 1.48 pk register_t *retval;
136 1.48 pk {
137 1.55 mycroft struct sunos_sys_access_args *uap = v;
138 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
139 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
140 1.48 pk
141 1.55 mycroft return (sys_access(p, uap, retval));
142 1.48 pk }
143 1.48 pk
144 1.48 pk int
145 1.55 mycroft sunos_sys_stat(p, v, retval)
146 1.48 pk struct proc *p;
147 1.54 thorpej void *v;
148 1.48 pk register_t *retval;
149 1.48 pk {
150 1.55 mycroft struct sunos_sys_stat_args *uap = v;
151 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
152 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
153 1.48 pk
154 1.55 mycroft return (compat_43_sys_stat(p, uap, retval));
155 1.48 pk }
156 1.48 pk
157 1.48 pk int
158 1.55 mycroft sunos_sys_lstat(p, v, retval)
159 1.48 pk struct proc *p;
160 1.54 thorpej void *v;
161 1.48 pk register_t *retval;
162 1.48 pk {
163 1.55 mycroft struct sunos_sys_lstat_args *uap = v;
164 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
165 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
166 1.48 pk
167 1.55 mycroft return (compat_43_sys_lstat(p, uap, retval));
168 1.48 pk }
169 1.48 pk
170 1.48 pk int
171 1.55 mycroft sunos_sys_execv(p, v, retval)
172 1.1 deraadt struct proc *p;
173 1.54 thorpej void *v;
174 1.32 cgd register_t *retval;
175 1.1 deraadt {
176 1.55 mycroft struct sunos_sys_execv_args *uap = v;
177 1.55 mycroft struct sys_execve_args ouap;
178 1.1 deraadt
179 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
180 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
181 1.48 pk
182 1.33 deraadt SCARG(&ouap, path) = SCARG(uap, path);
183 1.33 deraadt SCARG(&ouap, argp) = SCARG(uap, argp);
184 1.33 deraadt SCARG(&ouap, envp) = NULL;
185 1.55 mycroft
186 1.55 mycroft return (sys_execve(p, &ouap, retval));
187 1.1 deraadt }
188 1.1 deraadt
189 1.33 deraadt int
190 1.55 mycroft sunos_sys_omsync(p, v, retval)
191 1.1 deraadt struct proc *p;
192 1.54 thorpej void *v;
193 1.32 cgd register_t *retval;
194 1.1 deraadt {
195 1.55 mycroft struct sunos_sys_omsync_args *uap = v;
196 1.55 mycroft struct sys_msync_args ouap;
197 1.1 deraadt
198 1.33 deraadt if (SCARG(uap, flags))
199 1.1 deraadt return (EINVAL);
200 1.33 deraadt SCARG(&ouap, addr) = SCARG(uap, addr);
201 1.33 deraadt SCARG(&ouap, len) = SCARG(uap, len);
202 1.55 mycroft
203 1.55 mycroft return (sys_msync(p, &ouap, retval));
204 1.1 deraadt }
205 1.1 deraadt
206 1.33 deraadt int
207 1.55 mycroft sunos_sys_unmount(p, v, retval)
208 1.33 deraadt struct proc *p;
209 1.54 thorpej void *v;
210 1.32 cgd register_t *retval;
211 1.1 deraadt {
212 1.55 mycroft struct sunos_sys_unmount_args *uap = v;
213 1.55 mycroft struct sys_unmount_args ouap;
214 1.54 thorpej
215 1.55 mycroft SCARG(&ouap, path) = SCARG(uap, path);
216 1.55 mycroft SCARG(&ouap, flags) = 0;
217 1.55 mycroft
218 1.55 mycroft return (sys_unmount(p, &ouap, retval));
219 1.33 deraadt }
220 1.1 deraadt
221 1.33 deraadt int
222 1.55 mycroft sunos_sys_mount(p, v, retval)
223 1.1 deraadt struct proc *p;
224 1.54 thorpej void *v;
225 1.32 cgd register_t *retval;
226 1.1 deraadt {
227 1.55 mycroft struct sunos_sys_mount_args *uap = v;
228 1.51 briggs struct emul *e = p->p_emul;
229 1.33 deraadt int oflags = SCARG(uap, flags), nflags, error;
230 1.16 deraadt char fsname[MFSNAMELEN];
231 1.16 deraadt
232 1.1 deraadt if (oflags & (SUNM_NOSUB | SUNM_SYS5))
233 1.1 deraadt return (EINVAL);
234 1.16 deraadt if ((oflags & SUNM_NEWTYPE) == 0)
235 1.16 deraadt return (EINVAL);
236 1.1 deraadt nflags = 0;
237 1.1 deraadt if (oflags & SUNM_RDONLY)
238 1.1 deraadt nflags |= MNT_RDONLY;
239 1.1 deraadt if (oflags & SUNM_NOSUID)
240 1.1 deraadt nflags |= MNT_NOSUID;
241 1.1 deraadt if (oflags & SUNM_REMOUNT)
242 1.1 deraadt nflags |= MNT_UPDATE;
243 1.33 deraadt SCARG(uap, flags) = nflags;
244 1.10 deraadt
245 1.33 deraadt if (error = copyinstr((caddr_t)SCARG(uap, type), fsname,
246 1.42 mycroft sizeof fsname, (size_t *)0))
247 1.16 deraadt return (error);
248 1.16 deraadt
249 1.49 cgd if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
250 1.33 deraadt SCARG(uap, type) = STACKGAPBASE;
251 1.58 gwr if (error = copyout("ffs", SCARG(uap, type), sizeof("ffs")))
252 1.16 deraadt return (error);
253 1.49 cgd } else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
254 1.33 deraadt struct sunos_nfs_args sna;
255 1.10 deraadt struct sockaddr_in sain;
256 1.10 deraadt struct nfs_args na;
257 1.10 deraadt struct sockaddr sa;
258 1.10 deraadt
259 1.33 deraadt if (error = copyin(SCARG(uap, data), &sna, sizeof sna))
260 1.10 deraadt return (error);
261 1.10 deraadt if (error = copyin(sna.addr, &sain, sizeof sain))
262 1.10 deraadt return (error);
263 1.10 deraadt bcopy(&sain, &sa, sizeof sa);
264 1.10 deraadt sa.sa_len = sizeof(sain);
265 1.33 deraadt SCARG(uap, data) = STACKGAPBASE;
266 1.33 deraadt na.addr = (struct sockaddr *)((int)SCARG(uap, data) + sizeof na);
267 1.29 pk na.addrlen = sizeof(struct sockaddr);
268 1.10 deraadt na.sotype = SOCK_DGRAM;
269 1.10 deraadt na.proto = IPPROTO_UDP;
270 1.10 deraadt na.fh = (nfsv2fh_t *)sna.fh;
271 1.10 deraadt na.flags = sna.flags;
272 1.10 deraadt na.wsize = sna.wsize;
273 1.10 deraadt na.rsize = sna.rsize;
274 1.10 deraadt na.timeo = sna.timeo;
275 1.10 deraadt na.retrans = sna.retrans;
276 1.10 deraadt na.hostname = sna.hostname;
277 1.10 deraadt
278 1.10 deraadt if (error = copyout(&sa, na.addr, sizeof sa))
279 1.10 deraadt return (error);
280 1.33 deraadt if (error = copyout(&na, SCARG(uap, data), sizeof na))
281 1.10 deraadt return (error);
282 1.10 deraadt }
283 1.55 mycroft return (sys_mount(p, (struct sys_mount_args *)uap, retval));
284 1.1 deraadt }
285 1.1 deraadt
286 1.28 deraadt #if defined(NFSCLIENT)
287 1.33 deraadt int
288 1.55 mycroft async_daemon(p, v, retval)
289 1.27 pk struct proc *p;
290 1.55 mycroft void *v;
291 1.32 cgd register_t *retval;
292 1.27 pk {
293 1.55 mycroft struct sys_nfssvc_args ouap;
294 1.27 pk
295 1.33 deraadt SCARG(&ouap, flag) = NFSSVC_BIOD;
296 1.33 deraadt SCARG(&ouap, argp) = NULL;
297 1.55 mycroft
298 1.55 mycroft return (sys_nfssvc(p, &ouap, retval));
299 1.27 pk }
300 1.28 deraadt #endif /* NFSCLIENT */
301 1.27 pk
302 1.33 deraadt int
303 1.55 mycroft sunos_sys_sigpending(p, v, retval)
304 1.1 deraadt struct proc *p;
305 1.54 thorpej void *v;
306 1.32 cgd register_t *retval;
307 1.1 deraadt {
308 1.55 mycroft struct sunos_sys_sigpending_args *uap = v;
309 1.21 deraadt int mask = p->p_siglist & p->p_sigmask;
310 1.1 deraadt
311 1.33 deraadt return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
312 1.1 deraadt }
313 1.1 deraadt
314 1.1 deraadt /*
315 1.1 deraadt * Read Sun-style directory entries. We suck them into kernel space so
316 1.1 deraadt * that they can be massaged before being copied out to user code. Like
317 1.1 deraadt * SunOS, we squish out `empty' entries.
318 1.1 deraadt *
319 1.1 deraadt * This is quite ugly, but what do you expect from compatibility code?
320 1.1 deraadt */
321 1.33 deraadt int
322 1.55 mycroft sunos_sys_getdents(p, v, retval)
323 1.1 deraadt struct proc *p;
324 1.54 thorpej void *v;
325 1.32 cgd register_t *retval;
326 1.1 deraadt {
327 1.56 mycroft struct sunos_sys_getdents_args *uap = v;
328 1.56 mycroft struct dirent *bdp;
329 1.56 mycroft struct vnode *vp;
330 1.56 mycroft caddr_t inp, buf; /* BSD-format */
331 1.56 mycroft int len, reclen; /* BSD-format */
332 1.56 mycroft caddr_t outp; /* Sun-format */
333 1.56 mycroft int resid, sunos_reclen;/* Sun-format */
334 1.1 deraadt struct file *fp;
335 1.1 deraadt struct uio auio;
336 1.1 deraadt struct iovec aiov;
337 1.56 mycroft struct sunos_dirent idb;
338 1.1 deraadt off_t off; /* true file offset */
339 1.1 deraadt int buflen, error, eofflag;
340 1.56 mycroft u_long *cookiebuf, *cookie;
341 1.56 mycroft int ncookies;
342 1.1 deraadt
343 1.33 deraadt if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
344 1.1 deraadt return (error);
345 1.56 mycroft
346 1.1 deraadt if ((fp->f_flag & FREAD) == 0)
347 1.1 deraadt return (EBADF);
348 1.56 mycroft
349 1.1 deraadt vp = (struct vnode *)fp->f_data;
350 1.56 mycroft
351 1.1 deraadt if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
352 1.1 deraadt return (EINVAL);
353 1.56 mycroft
354 1.33 deraadt buflen = min(MAXBSIZE, SCARG(uap, nbytes));
355 1.1 deraadt buf = malloc(buflen, M_TEMP, M_WAITOK);
356 1.56 mycroft ncookies = buflen / 16;
357 1.56 mycroft cookiebuf = malloc(ncookies * sizeof(*cookiebuf), M_TEMP, M_WAITOK);
358 1.1 deraadt VOP_LOCK(vp);
359 1.1 deraadt off = fp->f_offset;
360 1.1 deraadt again:
361 1.1 deraadt aiov.iov_base = buf;
362 1.1 deraadt aiov.iov_len = buflen;
363 1.1 deraadt auio.uio_iov = &aiov;
364 1.1 deraadt auio.uio_iovcnt = 1;
365 1.1 deraadt auio.uio_rw = UIO_READ;
366 1.1 deraadt auio.uio_segflg = UIO_SYSSPACE;
367 1.1 deraadt auio.uio_procp = p;
368 1.1 deraadt auio.uio_resid = buflen;
369 1.1 deraadt auio.uio_offset = off;
370 1.1 deraadt /*
371 1.1 deraadt * First we read into the malloc'ed buffer, then
372 1.1 deraadt * we massage it into user space, one record at a time.
373 1.1 deraadt */
374 1.56 mycroft error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, cookiebuf,
375 1.56 mycroft ncookies);
376 1.59 ghudson if (error)
377 1.59 ghudson goto out;
378 1.56 mycroft
379 1.1 deraadt inp = buf;
380 1.33 deraadt outp = SCARG(uap, buf);
381 1.33 deraadt resid = SCARG(uap, nbytes);
382 1.1 deraadt if ((len = buflen - auio.uio_resid) == 0)
383 1.1 deraadt goto eof;
384 1.56 mycroft
385 1.56 mycroft for (cookie = cookiebuf; len > 0; len -= reclen) {
386 1.56 mycroft bdp = (struct dirent *)inp;
387 1.56 mycroft reclen = bdp->d_reclen;
388 1.1 deraadt if (reclen & 3)
389 1.33 deraadt panic("sunos_getdents");
390 1.56 mycroft off = *cookie++; /* each entry points to next */
391 1.56 mycroft if (bdp->d_fileno == 0) {
392 1.1 deraadt inp += reclen; /* it is a hole; squish it out */
393 1.1 deraadt continue;
394 1.1 deraadt }
395 1.56 mycroft sunos_reclen = SUNOS_RECLEN(&idb, bdp->d_namlen);
396 1.56 mycroft if (reclen > len || resid < sunos_reclen) {
397 1.1 deraadt /* entry too big for buffer, so just stop */
398 1.1 deraadt outp++;
399 1.1 deraadt break;
400 1.1 deraadt }
401 1.1 deraadt /*
402 1.1 deraadt * Massage in place to make a Sun-shaped dirent (otherwise
403 1.1 deraadt * we have to worry about touching user memory outside of
404 1.1 deraadt * the copyout() call).
405 1.1 deraadt */
406 1.56 mycroft idb.d_fileno = bdp->d_fileno;
407 1.56 mycroft idb.d_off = off;
408 1.56 mycroft idb.d_reclen = sunos_reclen;
409 1.56 mycroft idb.d_namlen = bdp->d_namlen;
410 1.56 mycroft strcpy(idb.d_name, bdp->d_name);
411 1.56 mycroft if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0)
412 1.1 deraadt goto out;
413 1.1 deraadt /* advance past this real entry */
414 1.1 deraadt inp += reclen;
415 1.1 deraadt /* advance output past Sun-shaped entry */
416 1.56 mycroft outp += sunos_reclen;
417 1.56 mycroft resid -= sunos_reclen;
418 1.1 deraadt }
419 1.56 mycroft
420 1.1 deraadt /* if we squished out the whole block, try again */
421 1.33 deraadt if (outp == SCARG(uap, buf))
422 1.1 deraadt goto again;
423 1.1 deraadt fp->f_offset = off; /* update the vnode offset */
424 1.56 mycroft
425 1.1 deraadt eof:
426 1.33 deraadt *retval = SCARG(uap, nbytes) - resid;
427 1.1 deraadt out:
428 1.1 deraadt VOP_UNLOCK(vp);
429 1.56 mycroft free(cookiebuf, M_TEMP);
430 1.1 deraadt free(buf, M_TEMP);
431 1.1 deraadt return (error);
432 1.1 deraadt }
433 1.1 deraadt
434 1.33 deraadt #define SUNOS__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
435 1.4 deraadt
436 1.33 deraadt int
437 1.55 mycroft sunos_sys_mmap(p, v, retval)
438 1.1 deraadt register struct proc *p;
439 1.54 thorpej void *v;
440 1.32 cgd register_t *retval;
441 1.1 deraadt {
442 1.55 mycroft register struct sunos_sys_mmap_args *uap = v;
443 1.55 mycroft struct sys_mmap_args ouap;
444 1.1 deraadt register struct filedesc *fdp;
445 1.1 deraadt register struct file *fp;
446 1.1 deraadt register struct vnode *vp;
447 1.1 deraadt
448 1.1 deraadt /*
449 1.14 cgd * Verify the arguments.
450 1.1 deraadt */
451 1.33 deraadt if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
452 1.14 cgd return (EINVAL); /* XXX still needed? */
453 1.4 deraadt
454 1.33 deraadt if ((SCARG(uap, flags) & SUNOS__MAP_NEW) == 0)
455 1.1 deraadt return (EINVAL);
456 1.1 deraadt
457 1.34 deraadt SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUNOS__MAP_NEW;
458 1.34 deraadt SCARG(&ouap, addr) = SCARG(uap, addr);
459 1.34 deraadt
460 1.34 deraadt if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
461 1.34 deraadt SCARG(&ouap, addr) != 0 &&
462 1.34 deraadt SCARG(&ouap, addr) < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
463 1.34 deraadt SCARG(&ouap, addr) = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
464 1.34 deraadt
465 1.34 deraadt SCARG(&ouap, len) = SCARG(uap, len);
466 1.34 deraadt SCARG(&ouap, prot) = SCARG(uap, prot);
467 1.34 deraadt SCARG(&ouap, fd) = SCARG(uap, fd);
468 1.34 deraadt SCARG(&ouap, pos) = SCARG(uap, pos);
469 1.10 deraadt
470 1.1 deraadt /*
471 1.1 deraadt * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
472 1.1 deraadt */
473 1.1 deraadt fdp = p->p_fd;
474 1.34 deraadt if ((unsigned)SCARG(&ouap, fd) < fdp->fd_nfiles && /*XXX*/
475 1.34 deraadt (fp = fdp->fd_ofiles[SCARG(&ouap, fd)]) != NULL && /*XXX*/
476 1.1 deraadt fp->f_type == DTYPE_VNODE && /*XXX*/
477 1.1 deraadt (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
478 1.23 deraadt iszerodev(vp->v_rdev)) { /*XXX*/
479 1.34 deraadt SCARG(&ouap, flags) |= MAP_ANON;
480 1.34 deraadt SCARG(&ouap, fd) = -1;
481 1.14 cgd }
482 1.4 deraadt
483 1.55 mycroft return (sys_mmap(p, &ouap, retval));
484 1.1 deraadt }
485 1.1 deraadt
486 1.1 deraadt #define MC_SYNC 1
487 1.1 deraadt #define MC_LOCK 2
488 1.1 deraadt #define MC_UNLOCK 3
489 1.1 deraadt #define MC_ADVISE 4
490 1.1 deraadt #define MC_LOCKAS 5
491 1.1 deraadt #define MC_UNLOCKAS 6
492 1.1 deraadt
493 1.33 deraadt int
494 1.55 mycroft sunos_sys_mctl(p, v, retval)
495 1.1 deraadt register struct proc *p;
496 1.54 thorpej void *v;
497 1.32 cgd register_t *retval;
498 1.1 deraadt {
499 1.55 mycroft register struct sunos_sys_mctl_args *uap = v;
500 1.1 deraadt
501 1.33 deraadt switch (SCARG(uap, func)) {
502 1.1 deraadt case MC_ADVISE: /* ignore for now */
503 1.1 deraadt return (0);
504 1.1 deraadt case MC_SYNC: /* translate to msync */
505 1.55 mycroft return (sys_msync(p, uap, retval));
506 1.1 deraadt default:
507 1.1 deraadt return (EINVAL);
508 1.1 deraadt }
509 1.1 deraadt }
510 1.1 deraadt
511 1.33 deraadt int
512 1.55 mycroft sunos_sys_setsockopt(p, v, retval)
513 1.1 deraadt struct proc *p;
514 1.54 thorpej void *v;
515 1.32 cgd register_t *retval;
516 1.1 deraadt {
517 1.55 mycroft register struct sunos_sys_setsockopt_args *uap = v;
518 1.1 deraadt struct file *fp;
519 1.1 deraadt struct mbuf *m = NULL;
520 1.1 deraadt int error;
521 1.1 deraadt
522 1.33 deraadt if (error = getsock(p->p_fd, SCARG(uap, s), &fp))
523 1.1 deraadt return (error);
524 1.1 deraadt #define SO_DONTLINGER (~SO_LINGER)
525 1.33 deraadt if (SCARG(uap, name) == SO_DONTLINGER) {
526 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
527 1.1 deraadt if (m == NULL)
528 1.1 deraadt return (ENOBUFS);
529 1.1 deraadt mtod(m, struct linger *)->l_onoff = 0;
530 1.1 deraadt m->m_len = sizeof(struct linger);
531 1.33 deraadt return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
532 1.1 deraadt SO_LINGER, m));
533 1.1 deraadt }
534 1.37 pk if (SCARG(uap, level) == IPPROTO_IP) {
535 1.37 pk #define SUNOS_IP_MULTICAST_IF 2
536 1.37 pk #define SUNOS_IP_MULTICAST_TTL 3
537 1.37 pk #define SUNOS_IP_MULTICAST_LOOP 4
538 1.37 pk #define SUNOS_IP_ADD_MEMBERSHIP 5
539 1.37 pk #define SUNOS_IP_DROP_MEMBERSHIP 6
540 1.37 pk static int ipoptxlat[] = {
541 1.37 pk IP_MULTICAST_IF,
542 1.37 pk IP_MULTICAST_TTL,
543 1.37 pk IP_MULTICAST_LOOP,
544 1.37 pk IP_ADD_MEMBERSHIP,
545 1.37 pk IP_DROP_MEMBERSHIP
546 1.37 pk };
547 1.37 pk if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
548 1.37 pk SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
549 1.37 pk SCARG(uap, name) =
550 1.37 pk ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
551 1.37 pk }
552 1.37 pk }
553 1.33 deraadt if (SCARG(uap, valsize) > MLEN)
554 1.1 deraadt return (EINVAL);
555 1.33 deraadt if (SCARG(uap, val)) {
556 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
557 1.1 deraadt if (m == NULL)
558 1.1 deraadt return (ENOBUFS);
559 1.33 deraadt if (error = copyin(SCARG(uap, val), mtod(m, caddr_t),
560 1.33 deraadt (u_int)SCARG(uap, valsize))) {
561 1.1 deraadt (void) m_free(m);
562 1.1 deraadt return (error);
563 1.1 deraadt }
564 1.33 deraadt m->m_len = SCARG(uap, valsize);
565 1.1 deraadt }
566 1.33 deraadt return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
567 1.33 deraadt SCARG(uap, name), m));
568 1.1 deraadt }
569 1.1 deraadt
570 1.33 deraadt int
571 1.55 mycroft sunos_sys_fchroot(p, v, retval)
572 1.1 deraadt register struct proc *p;
573 1.54 thorpej void *v;
574 1.32 cgd register_t *retval;
575 1.1 deraadt {
576 1.55 mycroft register struct sunos_sys_fchroot_args *uap = v;
577 1.1 deraadt register struct filedesc *fdp = p->p_fd;
578 1.1 deraadt register struct vnode *vp;
579 1.1 deraadt struct file *fp;
580 1.1 deraadt int error;
581 1.1 deraadt
582 1.1 deraadt if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
583 1.1 deraadt return (error);
584 1.33 deraadt if ((error = getvnode(fdp, SCARG(uap, fd), &fp)) != 0)
585 1.1 deraadt return (error);
586 1.1 deraadt vp = (struct vnode *)fp->f_data;
587 1.1 deraadt VOP_LOCK(vp);
588 1.1 deraadt if (vp->v_type != VDIR)
589 1.1 deraadt error = ENOTDIR;
590 1.1 deraadt else
591 1.1 deraadt error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
592 1.1 deraadt VOP_UNLOCK(vp);
593 1.1 deraadt if (error)
594 1.1 deraadt return (error);
595 1.1 deraadt VREF(vp);
596 1.1 deraadt if (fdp->fd_rdir != NULL)
597 1.1 deraadt vrele(fdp->fd_rdir);
598 1.1 deraadt fdp->fd_rdir = vp;
599 1.1 deraadt return (0);
600 1.3 deraadt }
601 1.3 deraadt
602 1.3 deraadt /*
603 1.3 deraadt * XXX: This needs cleaning up.
604 1.3 deraadt */
605 1.33 deraadt int
606 1.55 mycroft sunos_sys_auditsys(p, v, retval)
607 1.40 deraadt struct proc *p;
608 1.55 mycroft void *v;
609 1.40 deraadt register_t *retval;
610 1.3 deraadt {
611 1.3 deraadt return 0;
612 1.8 deraadt }
613 1.8 deraadt
614 1.33 deraadt int
615 1.55 mycroft sunos_sys_uname(p, v, retval)
616 1.8 deraadt struct proc *p;
617 1.54 thorpej void *v;
618 1.32 cgd register_t *retval;
619 1.8 deraadt {
620 1.55 mycroft struct sunos_sys_uname_args *uap = v;
621 1.33 deraadt struct sunos_utsname sut;
622 1.22 deraadt extern char ostype[], machine[], osrelease[];
623 1.8 deraadt
624 1.22 deraadt bzero(&sut, sizeof(sut));
625 1.8 deraadt
626 1.22 deraadt bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
627 1.22 deraadt bcopy(hostname, sut.nodename, sizeof(sut.nodename));
628 1.22 deraadt sut.nodename[sizeof(sut.nodename)-1] = '\0';
629 1.22 deraadt bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
630 1.22 deraadt bcopy("1", sut.version, sizeof(sut.version) - 1);
631 1.22 deraadt bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
632 1.8 deraadt
633 1.33 deraadt return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
634 1.33 deraadt sizeof(struct sunos_utsname));
635 1.8 deraadt }
636 1.8 deraadt
637 1.8 deraadt int
638 1.55 mycroft sunos_sys_setpgrp(p, v, retval)
639 1.8 deraadt struct proc *p;
640 1.54 thorpej void *v;
641 1.32 cgd register_t *retval;
642 1.8 deraadt {
643 1.55 mycroft struct sunos_sys_setpgrp_args *uap = v;
644 1.54 thorpej
645 1.8 deraadt /*
646 1.8 deraadt * difference to our setpgid call is to include backwards
647 1.8 deraadt * compatibility to pre-setsid() binaries. Do setsid()
648 1.8 deraadt * instead of setpgid() in those cases where the process
649 1.8 deraadt * tries to create a new session the old way.
650 1.8 deraadt */
651 1.55 mycroft if (!SCARG(uap, pgid) &&
652 1.55 mycroft (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
653 1.55 mycroft return sys_setsid(p, uap, retval);
654 1.8 deraadt else
655 1.55 mycroft return sys_setpgid(p, uap, retval);
656 1.8 deraadt }
657 1.8 deraadt
658 1.33 deraadt int
659 1.55 mycroft sunos_sys_open(p, v, retval)
660 1.8 deraadt struct proc *p;
661 1.54 thorpej void *v;
662 1.32 cgd register_t *retval;
663 1.8 deraadt {
664 1.55 mycroft struct sunos_sys_open_args *uap = v;
665 1.8 deraadt int l, r;
666 1.39 pk int noctty;
667 1.8 deraadt int ret;
668 1.8 deraadt
669 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
670 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
671 1.48 pk
672 1.8 deraadt /* convert mode into NetBSD mode */
673 1.39 pk l = SCARG(uap, flags);
674 1.39 pk noctty = l & 0x8000;
675 1.8 deraadt r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
676 1.8 deraadt r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
677 1.8 deraadt r |= ((l & 0x0080) ? O_SHLOCK : 0);
678 1.8 deraadt r |= ((l & 0x0100) ? O_EXLOCK : 0);
679 1.8 deraadt r |= ((l & 0x2000) ? O_FSYNC : 0);
680 1.8 deraadt
681 1.39 pk SCARG(uap, flags) = r;
682 1.55 mycroft ret = sys_open(p, (struct sys_open_args *)uap, retval);
683 1.8 deraadt
684 1.20 cgd if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
685 1.8 deraadt struct filedesc *fdp = p->p_fd;
686 1.8 deraadt struct file *fp = fdp->fd_ofiles[*retval];
687 1.8 deraadt
688 1.8 deraadt /* ignore any error, just give it a try */
689 1.8 deraadt if (fp->f_type == DTYPE_VNODE)
690 1.55 mycroft (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, p);
691 1.8 deraadt }
692 1.8 deraadt return ret;
693 1.10 deraadt }
694 1.10 deraadt
695 1.11 chopps #if defined (NFSSERVER)
696 1.33 deraadt int
697 1.55 mycroft sunos_sys_nfssvc(p, v, retval)
698 1.10 deraadt struct proc *p;
699 1.54 thorpej void *v;
700 1.32 cgd register_t *retval;
701 1.10 deraadt {
702 1.55 mycroft struct sunos_sys_nfssvc_args *uap = v;
703 1.51 briggs struct emul *e = p->p_emul;
704 1.55 mycroft struct sys_nfssvc_args outuap;
705 1.10 deraadt struct sockaddr sa;
706 1.10 deraadt int error;
707 1.10 deraadt
708 1.33 deraadt #if 0
709 1.10 deraadt bzero(&outuap, sizeof outuap);
710 1.33 deraadt SCARG(&outuap, fd) = SCARG(uap, fd);
711 1.33 deraadt SCARG(&outuap, mskval) = STACKGAPBASE;
712 1.33 deraadt SCARG(&outuap, msklen) = sizeof sa;
713 1.33 deraadt SCARG(&outuap, mtchval) = SCARG(&outuap, mskval) + sizeof sa;
714 1.33 deraadt SCARG(&outuap, mtchlen) = sizeof sa;
715 1.10 deraadt
716 1.10 deraadt bzero(&sa, sizeof sa);
717 1.33 deraadt if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
718 1.10 deraadt return (error);
719 1.33 deraadt if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
720 1.10 deraadt return (error);
721 1.10 deraadt
722 1.10 deraadt return nfssvc(p, &outuap, retval);
723 1.33 deraadt #else
724 1.33 deraadt return (ENOSYS);
725 1.33 deraadt #endif
726 1.10 deraadt }
727 1.11 chopps #endif /* NFSSERVER */
728 1.10 deraadt
729 1.33 deraadt int
730 1.55 mycroft sunos_sys_ustat(p, v, retval)
731 1.10 deraadt struct proc *p;
732 1.54 thorpej void *v;
733 1.32 cgd register_t *retval;
734 1.10 deraadt {
735 1.55 mycroft struct sunos_sys_ustat_args *uap = v;
736 1.33 deraadt struct sunos_ustat us;
737 1.10 deraadt int error;
738 1.10 deraadt
739 1.10 deraadt bzero(&us, sizeof us);
740 1.10 deraadt
741 1.10 deraadt /*
742 1.10 deraadt * XXX: should set f_tfree and f_tinode at least
743 1.33 deraadt * How do we translate dev -> fstat? (and then to sunos_ustat)
744 1.10 deraadt */
745 1.10 deraadt
746 1.33 deraadt if (error = copyout(&us, SCARG(uap, buf), sizeof us))
747 1.10 deraadt return (error);
748 1.10 deraadt return 0;
749 1.10 deraadt }
750 1.10 deraadt
751 1.33 deraadt int
752 1.55 mycroft sunos_sys_quotactl(p, v, retval)
753 1.10 deraadt struct proc *p;
754 1.54 thorpej void *v;
755 1.32 cgd register_t *retval;
756 1.10 deraadt {
757 1.55 mycroft struct sunos_sys_quotactl_args *uap = v;
758 1.54 thorpej
759 1.10 deraadt return EINVAL;
760 1.10 deraadt }
761 1.10 deraadt
762 1.33 deraadt int
763 1.55 mycroft sunos_sys_vhangup(p, v, retval)
764 1.10 deraadt struct proc *p;
765 1.55 mycroft void *v;
766 1.32 cgd register_t *retval;
767 1.10 deraadt {
768 1.60 pk struct sunos_vhangup_args *uap = v;
769 1.60 pk struct session *sp = p->p_session;
770 1.60 pk
771 1.60 pk if (sp->s_ttyvp == 0)
772 1.60 pk return 0;
773 1.60 pk
774 1.60 pk if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
775 1.60 pk pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
776 1.60 pk
777 1.60 pk (void) ttywait(sp->s_ttyp);
778 1.60 pk if (sp->s_ttyvp)
779 1.60 pk vgoneall(sp->s_ttyvp);
780 1.60 pk if (sp->s_ttyvp)
781 1.60 pk vrele(sp->s_ttyvp);
782 1.60 pk sp->s_ttyvp = NULL;
783 1.55 mycroft
784 1.10 deraadt return 0;
785 1.10 deraadt }
786 1.10 deraadt
787 1.10 deraadt static
788 1.10 deraadt sunstatfs(sp, buf)
789 1.10 deraadt struct statfs *sp;
790 1.10 deraadt caddr_t buf;
791 1.10 deraadt {
792 1.33 deraadt struct sunos_statfs ssfs;
793 1.10 deraadt
794 1.10 deraadt bzero(&ssfs, sizeof ssfs);
795 1.10 deraadt ssfs.f_type = 0;
796 1.16 deraadt ssfs.f_bsize = sp->f_bsize;
797 1.10 deraadt ssfs.f_blocks = sp->f_blocks;
798 1.10 deraadt ssfs.f_bfree = sp->f_bfree;
799 1.10 deraadt ssfs.f_bavail = sp->f_bavail;
800 1.10 deraadt ssfs.f_files = sp->f_files;
801 1.10 deraadt ssfs.f_ffree = sp->f_ffree;
802 1.10 deraadt ssfs.f_fsid = sp->f_fsid;
803 1.10 deraadt return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
804 1.10 deraadt }
805 1.10 deraadt
806 1.33 deraadt int
807 1.55 mycroft sunos_sys_statfs(p, v, retval)
808 1.10 deraadt struct proc *p;
809 1.54 thorpej void *v;
810 1.32 cgd register_t *retval;
811 1.10 deraadt {
812 1.55 mycroft struct sunos_sys_statfs_args *uap = v;
813 1.10 deraadt register struct mount *mp;
814 1.10 deraadt register struct statfs *sp;
815 1.10 deraadt int error;
816 1.10 deraadt struct nameidata nd;
817 1.10 deraadt
818 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
819 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
820 1.48 pk
821 1.33 deraadt NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), p);
822 1.27 pk if (error = namei(&nd))
823 1.10 deraadt return (error);
824 1.27 pk mp = nd.ni_vp->v_mount;
825 1.10 deraadt sp = &mp->mnt_stat;
826 1.27 pk vrele(nd.ni_vp);
827 1.10 deraadt if (error = VFS_STATFS(mp, sp, p))
828 1.10 deraadt return (error);
829 1.10 deraadt sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
830 1.33 deraadt return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
831 1.10 deraadt }
832 1.10 deraadt
833 1.33 deraadt int
834 1.55 mycroft sunos_sys_fstatfs(p, v, retval)
835 1.10 deraadt struct proc *p;
836 1.54 thorpej void *v;
837 1.32 cgd register_t *retval;
838 1.10 deraadt {
839 1.55 mycroft struct sunos_sys_fstatfs_args *uap = v;
840 1.10 deraadt struct file *fp;
841 1.10 deraadt struct mount *mp;
842 1.10 deraadt register struct statfs *sp;
843 1.10 deraadt int error;
844 1.10 deraadt
845 1.33 deraadt if (error = getvnode(p->p_fd, SCARG(uap, fd), &fp))
846 1.10 deraadt return (error);
847 1.10 deraadt mp = ((struct vnode *)fp->f_data)->v_mount;
848 1.10 deraadt sp = &mp->mnt_stat;
849 1.10 deraadt if (error = VFS_STATFS(mp, sp, p))
850 1.10 deraadt return (error);
851 1.10 deraadt sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
852 1.33 deraadt return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
853 1.10 deraadt }
854 1.10 deraadt
855 1.33 deraadt int
856 1.55 mycroft sunos_sys_exportfs(p, v, retval)
857 1.10 deraadt struct proc *p;
858 1.54 thorpej void *v;
859 1.32 cgd register_t *retval;
860 1.10 deraadt {
861 1.55 mycroft struct sunos_sys_exportfs_args *uap = v;
862 1.54 thorpej
863 1.10 deraadt /*
864 1.10 deraadt * XXX: should perhaps translate into a mount(2)
865 1.10 deraadt * with MOUNT_EXPORT?
866 1.10 deraadt */
867 1.10 deraadt return 0;
868 1.10 deraadt }
869 1.10 deraadt
870 1.33 deraadt int
871 1.55 mycroft sunos_sys_mknod(p, v, retval)
872 1.10 deraadt struct proc *p;
873 1.54 thorpej void *v;
874 1.32 cgd register_t *retval;
875 1.10 deraadt {
876 1.55 mycroft struct sunos_sys_mknod_args *uap = v;
877 1.55 mycroft
878 1.50 christos caddr_t sg = stackgap_init(p->p_emul);
879 1.50 christos SUNOS_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
880 1.48 pk
881 1.33 deraadt if (S_ISFIFO(SCARG(uap, mode)))
882 1.55 mycroft return sys_mkfifo(p, uap, retval);
883 1.10 deraadt
884 1.55 mycroft return sys_mknod(p, (struct sys_mknod_args *)uap, retval);
885 1.12 deraadt }
886 1.12 deraadt
887 1.33 deraadt #define SUNOS_SC_ARG_MAX 1
888 1.33 deraadt #define SUNOS_SC_CHILD_MAX 2
889 1.33 deraadt #define SUNOS_SC_CLK_TCK 3
890 1.33 deraadt #define SUNOS_SC_NGROUPS_MAX 4
891 1.33 deraadt #define SUNOS_SC_OPEN_MAX 5
892 1.33 deraadt #define SUNOS_SC_JOB_CONTROL 6
893 1.33 deraadt #define SUNOS_SC_SAVED_IDS 7
894 1.33 deraadt #define SUNOS_SC_VERSION 8
895 1.12 deraadt
896 1.33 deraadt int
897 1.55 mycroft sunos_sys_sysconf(p, v, retval)
898 1.12 deraadt struct proc *p;
899 1.54 thorpej void *v;
900 1.32 cgd register_t *retval;
901 1.12 deraadt {
902 1.55 mycroft struct sunos_sys_sysconf_args *uap = v;
903 1.24 deraadt extern int maxfiles;
904 1.12 deraadt
905 1.33 deraadt switch(SCARG(uap, name)) {
906 1.33 deraadt case SUNOS_SC_ARG_MAX:
907 1.12 deraadt *retval = ARG_MAX;
908 1.13 deraadt break;
909 1.33 deraadt case SUNOS_SC_CHILD_MAX:
910 1.12 deraadt *retval = maxproc;
911 1.13 deraadt break;
912 1.33 deraadt case SUNOS_SC_CLK_TCK:
913 1.12 deraadt *retval = 60; /* should this be `hz', ie. 100? */
914 1.13 deraadt break;
915 1.33 deraadt case SUNOS_SC_NGROUPS_MAX:
916 1.12 deraadt *retval = NGROUPS_MAX;
917 1.13 deraadt break;
918 1.33 deraadt case SUNOS_SC_OPEN_MAX:
919 1.24 deraadt *retval = maxfiles;
920 1.13 deraadt break;
921 1.33 deraadt case SUNOS_SC_JOB_CONTROL:
922 1.12 deraadt *retval = 1;
923 1.13 deraadt break;
924 1.33 deraadt case SUNOS_SC_SAVED_IDS:
925 1.12 deraadt #ifdef _POSIX_SAVED_IDS
926 1.12 deraadt *retval = 1;
927 1.12 deraadt #else
928 1.12 deraadt *retval = 0;
929 1.12 deraadt #endif
930 1.13 deraadt break;
931 1.33 deraadt case SUNOS_SC_VERSION:
932 1.12 deraadt *retval = 198808;
933 1.13 deraadt break;
934 1.12 deraadt default:
935 1.12 deraadt return EINVAL;
936 1.12 deraadt }
937 1.12 deraadt return 0;
938 1.17 pk }
939 1.17 pk
940 1.33 deraadt #define SUNOS_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */
941 1.33 deraadt #define SUNOS_RLIM_NLIMITS 7
942 1.17 pk
943 1.33 deraadt int
944 1.55 mycroft sunos_sys_getrlimit(p, v, retval)
945 1.17 pk struct proc *p;
946 1.54 thorpej void *v;
947 1.32 cgd register_t *retval;
948 1.17 pk {
949 1.55 mycroft struct sunos_sys_getrlimit_args *uap = v;
950 1.54 thorpej
951 1.33 deraadt if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
952 1.17 pk return EINVAL;
953 1.17 pk
954 1.33 deraadt if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
955 1.33 deraadt SCARG(uap, which) = RLIMIT_NOFILE;
956 1.17 pk
957 1.55 mycroft return compat_43_sys_getrlimit(p, uap, retval);
958 1.17 pk }
959 1.17 pk
960 1.33 deraadt int
961 1.55 mycroft sunos_sys_setrlimit(p, v, retval)
962 1.17 pk struct proc *p;
963 1.54 thorpej void *v;
964 1.32 cgd register_t *retval;
965 1.17 pk {
966 1.55 mycroft struct sunos_sys_getrlimit_args *uap = v;
967 1.54 thorpej
968 1.33 deraadt if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
969 1.17 pk return EINVAL;
970 1.17 pk
971 1.33 deraadt if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
972 1.33 deraadt SCARG(uap, which) = RLIMIT_NOFILE;
973 1.17 pk
974 1.55 mycroft return compat_43_sys_setrlimit(p, uap, retval);
975 1.35 deraadt }
976 1.36 deraadt
977 1.36 deraadt /* for the m68k machines */
978 1.36 deraadt #ifndef PT_GETFPREGS
979 1.36 deraadt #define PT_GETFPREGS -1
980 1.36 deraadt #endif
981 1.36 deraadt #ifndef PT_SETFPREGS
982 1.36 deraadt #define PT_SETFPREGS -1
983 1.36 deraadt #endif
984 1.35 deraadt
985 1.35 deraadt static int sreq2breq[] = {
986 1.35 deraadt PT_TRACE_ME, PT_READ_I, PT_READ_D, -1,
987 1.35 deraadt PT_WRITE_I, PT_WRITE_D, -1, PT_CONTINUE,
988 1.35 deraadt PT_KILL, -1, PT_ATTACH, PT_DETACH,
989 1.35 deraadt PT_GETREGS, PT_SETREGS, PT_GETFPREGS, PT_SETFPREGS
990 1.35 deraadt };
991 1.35 deraadt static int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
992 1.35 deraadt
993 1.55 mycroft sunos_sys_ptrace(p, v, retval)
994 1.35 deraadt struct proc *p;
995 1.54 thorpej void *v;
996 1.55 mycroft register_t *retval;
997 1.35 deraadt {
998 1.55 mycroft struct sunos_sys_ptrace_args *uap = v;
999 1.55 mycroft struct sys_ptrace_args pa;
1000 1.35 deraadt int req;
1001 1.35 deraadt
1002 1.35 deraadt req = SCARG(uap, req);
1003 1.35 deraadt
1004 1.35 deraadt if (req < 0 || req >= nreqs)
1005 1.35 deraadt return (EINVAL);
1006 1.35 deraadt
1007 1.35 deraadt req = sreq2breq[req];
1008 1.35 deraadt if (req == -1)
1009 1.35 deraadt return (EINVAL);
1010 1.35 deraadt
1011 1.35 deraadt SCARG(&pa, req) = req;
1012 1.35 deraadt SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
1013 1.35 deraadt SCARG(&pa, addr) = (caddr_t)SCARG(uap, addr);
1014 1.35 deraadt SCARG(&pa, data) = SCARG(uap, data);
1015 1.35 deraadt
1016 1.55 mycroft return sys_ptrace(p, &pa, retval);
1017 1.35 deraadt }
1018 1.35 deraadt
1019 1.35 deraadt static void
1020 1.35 deraadt sunos_pollscan(p, pl, nfd, retval)
1021 1.35 deraadt struct proc *p;
1022 1.35 deraadt struct sunos_pollfd *pl;
1023 1.35 deraadt int nfd;
1024 1.35 deraadt register_t *retval;
1025 1.35 deraadt {
1026 1.35 deraadt register struct filedesc *fdp = p->p_fd;
1027 1.35 deraadt register int msk, i;
1028 1.35 deraadt struct file *fp;
1029 1.35 deraadt int n = 0;
1030 1.35 deraadt static int flag[3] = { FREAD, FWRITE, 0 };
1031 1.35 deraadt static int pflag[3] = { SUNOS_POLLIN|SUNOS_POLLRDNORM,
1032 1.35 deraadt SUNOS_POLLOUT, SUNOS_POLLERR };
1033 1.35 deraadt
1034 1.35 deraadt /*
1035 1.35 deraadt * XXX: We need to implement the rest of the flags.
1036 1.35 deraadt */
1037 1.35 deraadt for (i = 0; i < nfd; i++) {
1038 1.35 deraadt fp = fdp->fd_ofiles[pl[i].fd];
1039 1.35 deraadt if (fp == NULL) {
1040 1.35 deraadt if (pl[i].events & SUNOS_POLLNVAL) {
1041 1.35 deraadt pl[i].revents |= SUNOS_POLLNVAL;
1042 1.35 deraadt n++;
1043 1.35 deraadt }
1044 1.35 deraadt continue;
1045 1.35 deraadt }
1046 1.35 deraadt for (msk = 0; msk < 3; msk++) {
1047 1.35 deraadt if (pl[i].events & pflag[msk]) {
1048 1.35 deraadt if ((*fp->f_ops->fo_select)(fp, flag[msk], p)) {
1049 1.35 deraadt pl[i].revents |=
1050 1.35 deraadt pflag[msk] & pl[i].events;
1051 1.35 deraadt n++;
1052 1.35 deraadt }
1053 1.35 deraadt }
1054 1.35 deraadt }
1055 1.35 deraadt }
1056 1.35 deraadt *retval = n;
1057 1.35 deraadt }
1058 1.35 deraadt
1059 1.35 deraadt
1060 1.35 deraadt /*
1061 1.35 deraadt * We are using the same mechanism as select only we encode/decode args
1062 1.35 deraadt * differently.
1063 1.35 deraadt */
1064 1.35 deraadt int
1065 1.55 mycroft sunos_sys_poll(p, v, retval)
1066 1.35 deraadt struct proc *p;
1067 1.54 thorpej void *v;
1068 1.35 deraadt register_t *retval;
1069 1.35 deraadt {
1070 1.55 mycroft struct sunos_sys_poll_args *uap = v;
1071 1.35 deraadt int i, s;
1072 1.35 deraadt int error, error2;
1073 1.35 deraadt size_t sz = sizeof(struct sunos_pollfd) * SCARG(uap, nfds);
1074 1.35 deraadt struct sunos_pollfd *pl;
1075 1.35 deraadt int msec = SCARG(uap, timeout);
1076 1.35 deraadt struct timeval atv;
1077 1.35 deraadt int timo;
1078 1.35 deraadt u_int ni;
1079 1.35 deraadt int ncoll;
1080 1.35 deraadt extern int nselcoll, selwait;
1081 1.35 deraadt
1082 1.35 deraadt pl = (struct sunos_pollfd *) malloc(sz, M_TEMP, M_WAITOK);
1083 1.35 deraadt
1084 1.35 deraadt if (error = copyin(SCARG(uap, fds), pl, sz))
1085 1.35 deraadt goto bad;
1086 1.35 deraadt
1087 1.35 deraadt for (i = 0; i < SCARG(uap, nfds); i++)
1088 1.35 deraadt pl[i].revents = 0;
1089 1.35 deraadt
1090 1.35 deraadt if (msec != -1) {
1091 1.35 deraadt atv.tv_sec = msec / 1000;
1092 1.35 deraadt atv.tv_usec = (msec - (atv.tv_sec * 1000)) * 1000;
1093 1.35 deraadt
1094 1.35 deraadt if (itimerfix(&atv)) {
1095 1.35 deraadt error = EINVAL;
1096 1.35 deraadt goto done;
1097 1.35 deraadt }
1098 1.35 deraadt s = splclock();
1099 1.43 mycroft timeradd(&atv, &time, &atv);
1100 1.35 deraadt timo = hzto(&atv);
1101 1.35 deraadt /*
1102 1.35 deraadt * Avoid inadvertently sleeping forever.
1103 1.35 deraadt */
1104 1.35 deraadt if (timo == 0)
1105 1.35 deraadt timo = 1;
1106 1.35 deraadt splx(s);
1107 1.35 deraadt } else
1108 1.35 deraadt timo = 0;
1109 1.35 deraadt
1110 1.35 deraadt retry:
1111 1.35 deraadt ncoll = nselcoll;
1112 1.35 deraadt p->p_flag |= P_SELECT;
1113 1.35 deraadt sunos_pollscan(p, pl, SCARG(uap, nfds), retval);
1114 1.35 deraadt if (*retval)
1115 1.35 deraadt goto done;
1116 1.35 deraadt s = splhigh();
1117 1.35 deraadt if (timo && timercmp(&time, &atv, >=)) {
1118 1.35 deraadt splx(s);
1119 1.35 deraadt goto done;
1120 1.35 deraadt }
1121 1.35 deraadt if ((p->p_flag & P_SELECT) == 0 || nselcoll != ncoll) {
1122 1.35 deraadt splx(s);
1123 1.35 deraadt goto retry;
1124 1.35 deraadt }
1125 1.35 deraadt p->p_flag &= ~P_SELECT;
1126 1.35 deraadt error = tsleep((caddr_t)&selwait, PSOCK | PCATCH, "sunos_poll", timo);
1127 1.35 deraadt splx(s);
1128 1.35 deraadt if (error == 0)
1129 1.35 deraadt goto retry;
1130 1.35 deraadt
1131 1.35 deraadt done:
1132 1.35 deraadt p->p_flag &= ~P_SELECT;
1133 1.35 deraadt /* poll is not restarted after signals... */
1134 1.35 deraadt if (error == ERESTART)
1135 1.35 deraadt error = EINTR;
1136 1.35 deraadt if (error == EWOULDBLOCK)
1137 1.35 deraadt error = 0;
1138 1.35 deraadt
1139 1.35 deraadt if (error2 = copyout(pl, SCARG(uap, fds), sz))
1140 1.35 deraadt error = error2;
1141 1.35 deraadt
1142 1.35 deraadt bad:
1143 1.35 deraadt free((char *) pl, M_TEMP);
1144 1.35 deraadt
1145 1.35 deraadt return (error);
1146 1.44 christos }
1147 1.44 christos
1148 1.44 christos /*
1149 1.44 christos * SunOS reboot system call (for compatibility).
1150 1.44 christos * Sun lets you pass in a boot string which the PROM
1151 1.44 christos * saves and provides to the next boot program.
1152 1.44 christos */
1153 1.44 christos static struct sunos_howto_conv {
1154 1.46 gwr int sun_howto;
1155 1.44 christos int bsd_howto;
1156 1.44 christos } sunos_howto_conv[] = {
1157 1.44 christos { 0x001, RB_ASKNAME },
1158 1.44 christos { 0x002, RB_SINGLE },
1159 1.44 christos { 0x004, RB_NOSYNC },
1160 1.44 christos { 0x008, RB_HALT },
1161 1.44 christos { 0x080, RB_DUMP },
1162 1.44 christos { 0x000, 0 },
1163 1.44 christos };
1164 1.46 gwr #define SUNOS_RB_STRING 0x200
1165 1.44 christos
1166 1.46 gwr int
1167 1.55 mycroft sunos_sys_reboot(p, v, retval)
1168 1.44 christos struct proc *p;
1169 1.54 thorpej void *v;
1170 1.46 gwr register_t *retval;
1171 1.44 christos {
1172 1.55 mycroft struct sunos_sys_reboot_args *uap = v;
1173 1.44 christos struct sunos_howto_conv *convp;
1174 1.46 gwr int error, bsd_howto, sun_howto;
1175 1.44 christos
1176 1.44 christos if (error = suser(p->p_ucred, &p->p_acflag))
1177 1.44 christos return (error);
1178 1.44 christos
1179 1.44 christos /*
1180 1.44 christos * Convert howto bits to BSD format.
1181 1.44 christos */
1182 1.46 gwr sun_howto = SCARG(uap, howto);
1183 1.44 christos bsd_howto = 0;
1184 1.44 christos convp = sunos_howto_conv;
1185 1.46 gwr while (convp->sun_howto) {
1186 1.46 gwr if (sun_howto & convp->sun_howto)
1187 1.44 christos bsd_howto |= convp->bsd_howto;
1188 1.44 christos convp++;
1189 1.44 christos }
1190 1.44 christos
1191 1.47 christos #ifdef sun3
1192 1.44 christos /*
1193 1.44 christos * Sun RB_STRING (Get user supplied bootstring.)
1194 1.46 gwr * If the machine supports passing a string to the
1195 1.46 gwr * next booted kernel, add the machine name above
1196 1.46 gwr * and provide a reboot2() function (see sun3).
1197 1.44 christos */
1198 1.46 gwr if (sun_howto & SUNOS_RB_STRING) {
1199 1.46 gwr char bs[128];
1200 1.46 gwr
1201 1.47 christos error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0);
1202 1.47 christos if (error)
1203 1.47 christos return error;
1204 1.46 gwr
1205 1.46 gwr return (reboot2(bsd_howto, bs));
1206 1.44 christos }
1207 1.47 christos #endif /* sun3 */
1208 1.44 christos
1209 1.46 gwr return (boot(bsd_howto));
1210 1.50 christos }
1211 1.50 christos
1212 1.50 christos /*
1213 1.50 christos * Generalized interface signal handler, 4.3-compatible.
1214 1.50 christos */
1215 1.50 christos /* ARGSUSED */
1216 1.50 christos int
1217 1.55 mycroft sunos_sys_sigvec(p, v, retval)
1218 1.50 christos struct proc *p;
1219 1.54 thorpej void *v;
1220 1.54 thorpej register_t *retval;
1221 1.54 thorpej {
1222 1.55 mycroft register struct sunos_sys_sigvec_args /* {
1223 1.50 christos syscallarg(int) signum;
1224 1.50 christos syscallarg(struct sigvec *) nsv;
1225 1.50 christos syscallarg(struct sigvec *) osv;
1226 1.54 thorpej } */ *uap = v;
1227 1.50 christos struct sigvec vec;
1228 1.50 christos register struct sigacts *ps = p->p_sigacts;
1229 1.50 christos register struct sigvec *sv;
1230 1.50 christos register int signum;
1231 1.50 christos int bit, error;
1232 1.50 christos
1233 1.50 christos signum = SCARG(uap, signum);
1234 1.50 christos if (signum <= 0 || signum >= NSIG ||
1235 1.50 christos signum == SIGKILL || signum == SIGSTOP)
1236 1.50 christos return (EINVAL);
1237 1.50 christos sv = &vec;
1238 1.50 christos if (SCARG(uap, osv)) {
1239 1.50 christos *(sig_t *)&sv->sv_handler = ps->ps_sigact[signum];
1240 1.50 christos sv->sv_mask = ps->ps_catchmask[signum];
1241 1.50 christos bit = sigmask(signum);
1242 1.50 christos sv->sv_flags = 0;
1243 1.50 christos if ((ps->ps_sigonstack & bit) != 0)
1244 1.50 christos sv->sv_flags |= SV_ONSTACK;
1245 1.50 christos if ((ps->ps_sigintr & bit) != 0)
1246 1.50 christos sv->sv_flags |= SV_INTERRUPT;
1247 1.55 mycroft if ((ps->ps_sigreset & bit) != 0)
1248 1.55 mycroft sv->sv_flags |= SA_RESETHAND;
1249 1.55 mycroft sv->sv_mask &= ~bit;
1250 1.50 christos if (error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, osv),
1251 1.50 christos sizeof (vec)))
1252 1.50 christos return (error);
1253 1.50 christos }
1254 1.50 christos if (SCARG(uap, nsv)) {
1255 1.50 christos if (error = copyin((caddr_t)SCARG(uap, nsv), (caddr_t)sv,
1256 1.50 christos sizeof (vec)))
1257 1.50 christos return (error);
1258 1.50 christos /*
1259 1.53 gwr * SunOS uses the mask 0x0004 as SV_RESETHAND
1260 1.53 gwr * meaning: `reset to SIG_DFL on delivery'.
1261 1.53 gwr * We support only the bits in: 0xF
1262 1.53 gwr * (those bits are the same as ours)
1263 1.50 christos */
1264 1.53 gwr if (sv->sv_flags & ~0xF)
1265 1.53 gwr return (EINVAL);
1266 1.53 gwr /* SunOS binaries have a user-mode trampoline. */
1267 1.53 gwr sv->sv_flags |= SA_USERTRAMP;
1268 1.53 gwr /* Convert sigvec:SV_INTERRUPT to sigaction:SA_RESTART */
1269 1.53 gwr sv->sv_flags ^= SA_RESTART; /* same bit, inverted */
1270 1.50 christos setsigvec(p, signum, (struct sigaction *)sv);
1271 1.50 christos }
1272 1.50 christos return (0);
1273 1.1 deraadt }
1274