sunos_misc.c revision 1.143 1 1.143 elad /* $NetBSD: sunos_misc.c,v 1.143 2006/11/14 13:34:30 elad 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.125 agc * 3. Neither the name of the University nor the names of its contributors
25 1.1 deraadt * may be used to endorse or promote products derived from this software
26 1.1 deraadt * without specific prior written permission.
27 1.1 deraadt *
28 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 1.1 deraadt * SUCH DAMAGE.
39 1.1 deraadt *
40 1.33 deraadt * @(#)sunos_misc.c 8.1 (Berkeley) 6/18/93
41 1.1 deraadt *
42 1.131 perry * Header: sunos_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
43 1.1 deraadt */
44 1.1 deraadt
45 1.1 deraadt /*
46 1.1 deraadt * SunOS compatibility module.
47 1.1 deraadt *
48 1.1 deraadt * SunOS system calls that are implemented differently in BSD are
49 1.1 deraadt * handled here.
50 1.1 deraadt */
51 1.111 lukem
52 1.111 lukem #include <sys/cdefs.h>
53 1.143 elad __KERNEL_RCSID(0, "$NetBSD: sunos_misc.c,v 1.143 2006/11/14 13:34:30 elad Exp $");
54 1.87 thorpej
55 1.109 mrg #if defined(_KERNEL_OPT)
56 1.91 hannken #include "opt_nfsserver.h"
57 1.141 he #include "opt_ptrace.h"
58 1.87 thorpej #include "fs_nfs.h"
59 1.107 jdolecek #endif
60 1.1 deraadt
61 1.1 deraadt #include <sys/param.h>
62 1.1 deraadt #include <sys/systm.h>
63 1.10 deraadt #include <sys/namei.h>
64 1.1 deraadt #include <sys/proc.h>
65 1.63 gwr #include <sys/dirent.h>
66 1.1 deraadt #include <sys/file.h>
67 1.10 deraadt #include <sys/stat.h>
68 1.1 deraadt #include <sys/filedesc.h>
69 1.1 deraadt #include <sys/ioctl.h>
70 1.8 deraadt #include <sys/kernel.h>
71 1.44 christos #include <sys/reboot.h>
72 1.1 deraadt #include <sys/malloc.h>
73 1.1 deraadt #include <sys/mbuf.h>
74 1.1 deraadt #include <sys/mman.h>
75 1.1 deraadt #include <sys/mount.h>
76 1.35 deraadt #include <sys/ptrace.h>
77 1.1 deraadt #include <sys/resource.h>
78 1.1 deraadt #include <sys/resourcevar.h>
79 1.1 deraadt #include <sys/signal.h>
80 1.1 deraadt #include <sys/signalvar.h>
81 1.1 deraadt #include <sys/socket.h>
82 1.60 pk #include <sys/tty.h>
83 1.1 deraadt #include <sys/vnode.h>
84 1.1 deraadt #include <sys/uio.h>
85 1.1 deraadt #include <sys/wait.h>
86 1.8 deraadt #include <sys/utsname.h>
87 1.12 deraadt #include <sys/unistd.h>
88 1.117 thorpej #include <sys/sa.h>
89 1.142 matt #include <sys/syscall.h>
90 1.33 deraadt #include <sys/syscallargs.h>
91 1.64 christos #include <sys/conf.h>
92 1.64 christos #include <sys/socketvar.h>
93 1.73 christos #include <sys/exec.h>
94 1.93 mrg #include <sys/swap.h>
95 1.138 yamt #include <sys/kauth.h>
96 1.55 mycroft
97 1.133 he #include <compat/sys/signal.h>
98 1.133 he
99 1.33 deraadt #include <compat/sunos/sunos.h>
100 1.33 deraadt #include <compat/sunos/sunos_syscallargs.h>
101 1.106 jdolecek #include <compat/common/compat_util.h>
102 1.56 mycroft #include <compat/sunos/sunos_dirent.h>
103 1.1 deraadt
104 1.10 deraadt #include <netinet/in.h>
105 1.10 deraadt
106 1.7 deraadt #include <miscfs/specfs/specdev.h>
107 1.1 deraadt
108 1.27 pk #include <nfs/rpcv2.h>
109 1.61 pk #include <nfs/nfsproto.h>
110 1.27 pk #include <nfs/nfs.h>
111 1.90 fvdl #include <nfs/nfsmount.h>
112 1.1 deraadt
113 1.127 hannken static int sunstatfs __P((struct statvfs *, caddr_t));
114 1.70 christos
115 1.70 christos int
116 1.117 thorpej sunos_sys_stime(l, v, retval)
117 1.117 thorpej struct lwp *l;
118 1.70 christos void *v;
119 1.70 christos register_t *retval;
120 1.70 christos {
121 1.70 christos struct sunos_sys_stime_args *uap = v;
122 1.70 christos struct sys_settimeofday_args ap;
123 1.117 thorpej struct proc *p = l->l_proc;
124 1.114 christos caddr_t sg = stackgap_init(p, 0);
125 1.75 cjs struct timeval tv, *sgtvp;
126 1.70 christos int error;
127 1.70 christos
128 1.70 christos error = copyin(SCARG(uap, tp), &tv.tv_sec, sizeof(tv.tv_sec));
129 1.70 christos if (error)
130 1.70 christos return error;
131 1.70 christos tv.tv_usec = 0;
132 1.70 christos
133 1.114 christos SCARG(&ap, tv) = sgtvp = stackgap_alloc(p, &sg, sizeof(struct timeval));
134 1.70 christos SCARG(&ap, tzp) = NULL;
135 1.70 christos
136 1.75 cjs error = copyout(&tv, sgtvp, sizeof(struct timeval));
137 1.70 christos if (error)
138 1.70 christos return error;
139 1.70 christos
140 1.117 thorpej return sys_settimeofday(l, &ap, retval);
141 1.70 christos }
142 1.70 christos
143 1.33 deraadt int
144 1.117 thorpej sunos_sys_wait4(l, v, retval)
145 1.117 thorpej struct lwp *l;
146 1.54 thorpej void *v;
147 1.32 cgd register_t *retval;
148 1.1 deraadt {
149 1.55 mycroft struct sunos_sys_wait4_args *uap = v;
150 1.33 deraadt if (SCARG(uap, pid) == 0)
151 1.33 deraadt SCARG(uap, pid) = WAIT_ANY;
152 1.117 thorpej return (sys_wait4(l, uap, retval));
153 1.1 deraadt }
154 1.1 deraadt
155 1.33 deraadt int
156 1.117 thorpej sunos_sys_creat(l, v, retval)
157 1.117 thorpej struct lwp *l;
158 1.54 thorpej void *v;
159 1.32 cgd register_t *retval;
160 1.1 deraadt {
161 1.55 mycroft struct sunos_sys_creat_args *uap = v;
162 1.117 thorpej struct proc *p = l->l_proc;
163 1.55 mycroft struct sys_open_args ouap;
164 1.1 deraadt
165 1.114 christos caddr_t sg = stackgap_init(p, 0);
166 1.134 christos CHECK_ALT_CREAT(l, &sg, SCARG(uap, path));
167 1.48 pk
168 1.33 deraadt SCARG(&ouap, path) = SCARG(uap, path);
169 1.33 deraadt SCARG(&ouap, flags) = O_WRONLY | O_CREAT | O_TRUNC;
170 1.33 deraadt SCARG(&ouap, mode) = SCARG(uap, mode);
171 1.55 mycroft
172 1.117 thorpej return (sys_open(l, &ouap, retval));
173 1.1 deraadt }
174 1.1 deraadt
175 1.33 deraadt int
176 1.117 thorpej sunos_sys_access(l, v, retval)
177 1.117 thorpej struct lwp *l;
178 1.54 thorpej void *v;
179 1.48 pk register_t *retval;
180 1.48 pk {
181 1.55 mycroft struct sunos_sys_access_args *uap = v;
182 1.117 thorpej struct proc *p = l->l_proc;
183 1.114 christos caddr_t sg = stackgap_init(p, 0);
184 1.134 christos CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
185 1.48 pk
186 1.117 thorpej return (sys_access(l, uap, retval));
187 1.48 pk }
188 1.48 pk
189 1.48 pk int
190 1.117 thorpej sunos_sys_stat(l, v, retval)
191 1.117 thorpej struct lwp *l;
192 1.54 thorpej void *v;
193 1.48 pk register_t *retval;
194 1.48 pk {
195 1.55 mycroft struct sunos_sys_stat_args *uap = v;
196 1.117 thorpej struct proc *p = l->l_proc;
197 1.114 christos caddr_t sg = stackgap_init(p, 0);
198 1.134 christos CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
199 1.48 pk
200 1.117 thorpej return (compat_43_sys_stat(l, uap, retval));
201 1.48 pk }
202 1.48 pk
203 1.48 pk int
204 1.117 thorpej sunos_sys_lstat(l, v, retval)
205 1.117 thorpej struct lwp *l;
206 1.54 thorpej void *v;
207 1.48 pk register_t *retval;
208 1.48 pk {
209 1.55 mycroft struct sunos_sys_lstat_args *uap = v;
210 1.117 thorpej struct proc *p = l->l_proc;
211 1.114 christos caddr_t sg = stackgap_init(p, 0);
212 1.134 christos CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
213 1.48 pk
214 1.117 thorpej return (compat_43_sys_lstat(l, uap, retval));
215 1.48 pk }
216 1.48 pk
217 1.48 pk int
218 1.117 thorpej sunos_sys_execv(l, v, retval)
219 1.117 thorpej struct lwp *l;
220 1.54 thorpej void *v;
221 1.32 cgd register_t *retval;
222 1.1 deraadt {
223 1.71 mycroft struct sunos_sys_execv_args /* {
224 1.99 christos syscallarg(const char *) path;
225 1.71 mycroft syscallarg(char **) argv;
226 1.71 mycroft } */ *uap = v;
227 1.117 thorpej struct proc *p = l->l_proc;
228 1.71 mycroft struct sys_execve_args ap;
229 1.71 mycroft caddr_t sg;
230 1.1 deraadt
231 1.114 christos sg = stackgap_init(p, 0);
232 1.134 christos CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
233 1.48 pk
234 1.71 mycroft SCARG(&ap, path) = SCARG(uap, path);
235 1.71 mycroft SCARG(&ap, argp) = SCARG(uap, argp);
236 1.71 mycroft SCARG(&ap, envp) = NULL;
237 1.69 thorpej
238 1.117 thorpej return (sys_execve(l, &ap, retval));
239 1.69 thorpej }
240 1.69 thorpej
241 1.69 thorpej int
242 1.117 thorpej sunos_sys_execve(l, v, retval)
243 1.117 thorpej struct lwp *l;
244 1.69 thorpej void *v;
245 1.69 thorpej register_t *retval;
246 1.69 thorpej {
247 1.71 mycroft struct sunos_sys_execve_args /* {
248 1.99 christos syscallarg(const char *) path;
249 1.71 mycroft syscallarg(char **) argv;
250 1.71 mycroft syscallarg(char **) envp;
251 1.71 mycroft } */ *uap = v;
252 1.71 mycroft struct sys_execve_args ap;
253 1.117 thorpej struct proc *p = l->l_proc;
254 1.71 mycroft caddr_t sg;
255 1.71 mycroft
256 1.114 christos sg = stackgap_init(p, 0);
257 1.134 christos CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
258 1.71 mycroft
259 1.71 mycroft SCARG(&ap, path) = SCARG(uap, path);
260 1.71 mycroft SCARG(&ap, argp) = SCARG(uap, argp);
261 1.71 mycroft SCARG(&ap, envp) = SCARG(uap, envp);
262 1.55 mycroft
263 1.117 thorpej return (sys_execve(l, &ap, retval));
264 1.1 deraadt }
265 1.1 deraadt
266 1.33 deraadt int
267 1.117 thorpej sunos_sys_omsync(l, v, retval)
268 1.117 thorpej struct lwp *l;
269 1.54 thorpej void *v;
270 1.32 cgd register_t *retval;
271 1.1 deraadt {
272 1.55 mycroft struct sunos_sys_omsync_args *uap = v;
273 1.86 fvdl struct sys___msync13_args ouap;
274 1.1 deraadt
275 1.33 deraadt SCARG(&ouap, addr) = SCARG(uap, addr);
276 1.33 deraadt SCARG(&ouap, len) = SCARG(uap, len);
277 1.86 fvdl SCARG(&ouap, flags) = SCARG(uap, flags);
278 1.55 mycroft
279 1.117 thorpej return (sys___msync13(l, &ouap, retval));
280 1.1 deraadt }
281 1.1 deraadt
282 1.33 deraadt int
283 1.117 thorpej sunos_sys_unmount(l, v, retval)
284 1.117 thorpej struct lwp *l;
285 1.54 thorpej void *v;
286 1.32 cgd register_t *retval;
287 1.1 deraadt {
288 1.55 mycroft struct sunos_sys_unmount_args *uap = v;
289 1.55 mycroft struct sys_unmount_args ouap;
290 1.54 thorpej
291 1.55 mycroft SCARG(&ouap, path) = SCARG(uap, path);
292 1.55 mycroft SCARG(&ouap, flags) = 0;
293 1.55 mycroft
294 1.117 thorpej return (sys_unmount(l, &ouap, retval));
295 1.33 deraadt }
296 1.1 deraadt
297 1.61 pk /*
298 1.61 pk * Conversion table for SunOS NFS mount flags.
299 1.61 pk */
300 1.61 pk static struct {
301 1.61 pk int sun_flg;
302 1.61 pk int bsd_flg;
303 1.61 pk } sunnfs_flgtab[] = {
304 1.61 pk { SUNNFS_SOFT, NFSMNT_SOFT },
305 1.61 pk { SUNNFS_WSIZE, NFSMNT_WSIZE },
306 1.61 pk { SUNNFS_RSIZE, NFSMNT_RSIZE },
307 1.61 pk { SUNNFS_TIMEO, NFSMNT_TIMEO },
308 1.61 pk { SUNNFS_RETRANS, NFSMNT_RETRANS },
309 1.61 pk { SUNNFS_HOSTNAME, 0 }, /* Ignored */
310 1.61 pk { SUNNFS_INT, NFSMNT_INT },
311 1.61 pk { SUNNFS_NOAC, 0 }, /* Ignored */
312 1.61 pk { SUNNFS_ACREGMIN, 0 }, /* Ignored */
313 1.61 pk { SUNNFS_ACREGMAX, 0 }, /* Ignored */
314 1.61 pk { SUNNFS_ACDIRMIN, 0 }, /* Ignored */
315 1.61 pk { SUNNFS_ACDIRMAX, 0 }, /* Ignored */
316 1.61 pk { SUNNFS_SECURE, 0 }, /* Ignored */
317 1.61 pk { SUNNFS_NOCTO, 0 }, /* Ignored */
318 1.61 pk { SUNNFS_POSIX, 0 } /* Ignored */
319 1.61 pk };
320 1.61 pk
321 1.33 deraadt int
322 1.117 thorpej sunos_sys_mount(l, v, retval)
323 1.117 thorpej struct lwp *l;
324 1.54 thorpej void *v;
325 1.32 cgd register_t *retval;
326 1.1 deraadt {
327 1.55 mycroft struct sunos_sys_mount_args *uap = v;
328 1.117 thorpej struct proc *p = l->l_proc;
329 1.33 deraadt int oflags = SCARG(uap, flags), nflags, error;
330 1.16 deraadt char fsname[MFSNAMELEN];
331 1.114 christos caddr_t sg = stackgap_init(p, 0);
332 1.16 deraadt
333 1.1 deraadt if (oflags & (SUNM_NOSUB | SUNM_SYS5))
334 1.1 deraadt return (EINVAL);
335 1.16 deraadt if ((oflags & SUNM_NEWTYPE) == 0)
336 1.16 deraadt return (EINVAL);
337 1.1 deraadt nflags = 0;
338 1.1 deraadt if (oflags & SUNM_RDONLY)
339 1.1 deraadt nflags |= MNT_RDONLY;
340 1.1 deraadt if (oflags & SUNM_NOSUID)
341 1.1 deraadt nflags |= MNT_NOSUID;
342 1.1 deraadt if (oflags & SUNM_REMOUNT)
343 1.1 deraadt nflags |= MNT_UPDATE;
344 1.33 deraadt SCARG(uap, flags) = nflags;
345 1.10 deraadt
346 1.64 christos error = copyinstr((caddr_t)SCARG(uap, type), fsname,
347 1.64 christos sizeof fsname, (size_t *)0);
348 1.64 christos if (error)
349 1.16 deraadt return (error);
350 1.16 deraadt
351 1.49 cgd if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
352 1.114 christos SCARG(uap, type) = stackgap_alloc(p, &sg, sizeof("ffs"));
353 1.64 christos error = copyout("ffs", SCARG(uap, type), sizeof("ffs"));
354 1.64 christos if (error)
355 1.16 deraadt return (error);
356 1.49 cgd } else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
357 1.33 deraadt struct sunos_nfs_args sna;
358 1.10 deraadt struct sockaddr_in sain;
359 1.10 deraadt struct nfs_args na;
360 1.10 deraadt struct sockaddr sa;
361 1.61 pk int n;
362 1.10 deraadt
363 1.64 christos error = copyin(SCARG(uap, data), &sna, sizeof sna);
364 1.64 christos if (error)
365 1.10 deraadt return (error);
366 1.64 christos error = copyin(sna.addr, &sain, sizeof sain);
367 1.64 christos if (error)
368 1.10 deraadt return (error);
369 1.92 perry memcpy(&sa, &sain, sizeof sa);
370 1.10 deraadt sa.sa_len = sizeof(sain);
371 1.114 christos SCARG(uap, data) = stackgap_alloc(p, &sg, sizeof(na));
372 1.61 pk na.version = NFS_ARGSVERSION;
373 1.114 christos na.addr = stackgap_alloc(p, &sg, sizeof(struct sockaddr));
374 1.29 pk na.addrlen = sizeof(struct sockaddr);
375 1.10 deraadt na.sotype = SOCK_DGRAM;
376 1.10 deraadt na.proto = IPPROTO_UDP;
377 1.61 pk na.fh = (void *)sna.fh;
378 1.61 pk na.fhsize = NFSX_V2FH;
379 1.61 pk na.flags = 0;
380 1.61 pk n = sizeof(sunnfs_flgtab) / sizeof(sunnfs_flgtab[0]);
381 1.61 pk while (--n >= 0)
382 1.61 pk if (sna.flags & sunnfs_flgtab[n].sun_flg)
383 1.61 pk na.flags |= sunnfs_flgtab[n].bsd_flg;
384 1.10 deraadt na.wsize = sna.wsize;
385 1.10 deraadt na.rsize = sna.rsize;
386 1.62 pk if (na.flags & NFSMNT_RSIZE) {
387 1.62 pk na.flags |= NFSMNT_READDIRSIZE;
388 1.62 pk na.readdirsize = na.rsize;
389 1.62 pk }
390 1.10 deraadt na.timeo = sna.timeo;
391 1.10 deraadt na.retrans = sna.retrans;
392 1.108 fvdl na.hostname = (char *)(u_long)sna.hostname;
393 1.10 deraadt
394 1.64 christos error = copyout(&sa, na.addr, sizeof sa);
395 1.64 christos if (error)
396 1.10 deraadt return (error);
397 1.64 christos error = copyout(&na, SCARG(uap, data), sizeof na);
398 1.64 christos if (error)
399 1.10 deraadt return (error);
400 1.10 deraadt }
401 1.117 thorpej return (sys_mount(l, (struct sys_mount_args *)uap, retval));
402 1.1 deraadt }
403 1.1 deraadt
404 1.76 thorpej #if defined(NFS)
405 1.33 deraadt int
406 1.117 thorpej async_daemon(l, v, retval)
407 1.117 thorpej struct lwp *l;
408 1.55 mycroft void *v;
409 1.32 cgd register_t *retval;
410 1.27 pk {
411 1.55 mycroft struct sys_nfssvc_args ouap;
412 1.27 pk
413 1.33 deraadt SCARG(&ouap, flag) = NFSSVC_BIOD;
414 1.33 deraadt SCARG(&ouap, argp) = NULL;
415 1.55 mycroft
416 1.117 thorpej return (sys_nfssvc(l, &ouap, retval));
417 1.27 pk }
418 1.76 thorpej #endif /* NFS */
419 1.27 pk
420 1.95 pk void native_to_sunos_sigset __P((const sigset_t *, int *));
421 1.95 pk void sunos_to_native_sigset __P((const int, sigset_t *));
422 1.95 pk
423 1.135 perry inline void
424 1.95 pk native_to_sunos_sigset(ss, mask)
425 1.95 pk const sigset_t *ss;
426 1.95 pk int *mask;
427 1.95 pk {
428 1.95 pk *mask = ss->__bits[0];
429 1.95 pk }
430 1.95 pk
431 1.135 perry inline void
432 1.95 pk sunos_to_native_sigset(mask, ss)
433 1.95 pk const int mask;
434 1.95 pk sigset_t *ss;
435 1.95 pk {
436 1.95 pk
437 1.95 pk ss->__bits[0] = mask;
438 1.95 pk ss->__bits[1] = 0;
439 1.95 pk ss->__bits[2] = 0;
440 1.95 pk ss->__bits[3] = 0;
441 1.95 pk }
442 1.95 pk
443 1.33 deraadt int
444 1.117 thorpej sunos_sys_sigpending(l, v, retval)
445 1.117 thorpej struct lwp *l;
446 1.54 thorpej void *v;
447 1.32 cgd register_t *retval;
448 1.1 deraadt {
449 1.55 mycroft struct sunos_sys_sigpending_args *uap = v;
450 1.95 pk sigset_t ss;
451 1.95 pk int mask;
452 1.95 pk
453 1.117 thorpej sigpending1(l->l_proc, &ss);
454 1.95 pk native_to_sunos_sigset(&ss, &mask);
455 1.1 deraadt
456 1.33 deraadt return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
457 1.1 deraadt }
458 1.1 deraadt
459 1.131 perry int
460 1.117 thorpej sunos_sys_sigsuspend(l, v, retval)
461 1.117 thorpej struct lwp *l;
462 1.95 pk void *v;
463 1.95 pk register_t *retval;
464 1.95 pk {
465 1.95 pk struct sunos_sys_sigsuspend_args /* {
466 1.95 pk syscallarg(int) mask;
467 1.95 pk } */ *uap = v;
468 1.95 pk int mask;
469 1.95 pk sigset_t ss;
470 1.131 perry
471 1.95 pk mask = SCARG(uap, mask);
472 1.95 pk sunos_to_native_sigset(mask, &ss);
473 1.117 thorpej return (sigsuspend1(l->l_proc, &ss));
474 1.95 pk }
475 1.95 pk
476 1.1 deraadt /*
477 1.1 deraadt * Read Sun-style directory entries. We suck them into kernel space so
478 1.1 deraadt * that they can be massaged before being copied out to user code. Like
479 1.1 deraadt * SunOS, we squish out `empty' entries.
480 1.1 deraadt *
481 1.1 deraadt * This is quite ugly, but what do you expect from compatibility code?
482 1.1 deraadt */
483 1.33 deraadt int
484 1.117 thorpej sunos_sys_getdents(l, v, retval)
485 1.117 thorpej struct lwp *l;
486 1.54 thorpej void *v;
487 1.32 cgd register_t *retval;
488 1.1 deraadt {
489 1.56 mycroft struct sunos_sys_getdents_args *uap = v;
490 1.117 thorpej struct proc *p = l->l_proc;
491 1.56 mycroft struct dirent *bdp;
492 1.56 mycroft struct vnode *vp;
493 1.56 mycroft caddr_t inp, buf; /* BSD-format */
494 1.56 mycroft int len, reclen; /* BSD-format */
495 1.56 mycroft caddr_t outp; /* Sun-format */
496 1.56 mycroft int resid, sunos_reclen;/* Sun-format */
497 1.1 deraadt struct file *fp;
498 1.1 deraadt struct uio auio;
499 1.1 deraadt struct iovec aiov;
500 1.56 mycroft struct sunos_dirent idb;
501 1.1 deraadt off_t off; /* true file offset */
502 1.1 deraadt int buflen, error, eofflag;
503 1.90 fvdl off_t *cookiebuf, *cookie;
504 1.56 mycroft int ncookies;
505 1.1 deraadt
506 1.101 thorpej /* getvnode() will use the descriptor for us */
507 1.33 deraadt if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
508 1.1 deraadt return (error);
509 1.56 mycroft
510 1.101 thorpej if ((fp->f_flag & FREAD) == 0) {
511 1.101 thorpej error = EBADF;
512 1.101 thorpej goto out1;
513 1.101 thorpej }
514 1.56 mycroft
515 1.1 deraadt vp = (struct vnode *)fp->f_data;
516 1.101 thorpej if (vp->v_type != VDIR) {
517 1.101 thorpej error = EINVAL;
518 1.101 thorpej goto out1;
519 1.101 thorpej }
520 1.56 mycroft
521 1.33 deraadt buflen = min(MAXBSIZE, SCARG(uap, nbytes));
522 1.1 deraadt buf = malloc(buflen, M_TEMP, M_WAITOK);
523 1.88 fvdl vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
524 1.1 deraadt off = fp->f_offset;
525 1.1 deraadt again:
526 1.1 deraadt aiov.iov_base = buf;
527 1.1 deraadt aiov.iov_len = buflen;
528 1.1 deraadt auio.uio_iov = &aiov;
529 1.1 deraadt auio.uio_iovcnt = 1;
530 1.1 deraadt auio.uio_rw = UIO_READ;
531 1.1 deraadt auio.uio_resid = buflen;
532 1.1 deraadt auio.uio_offset = off;
533 1.136 yamt UIO_SETUP_SYSSPACE(&auio);
534 1.1 deraadt /*
535 1.1 deraadt * First we read into the malloc'ed buffer, then
536 1.1 deraadt * we massage it into user space, one record at a time.
537 1.1 deraadt */
538 1.88 fvdl error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
539 1.88 fvdl &ncookies);
540 1.59 ghudson if (error)
541 1.59 ghudson goto out;
542 1.56 mycroft
543 1.1 deraadt inp = buf;
544 1.33 deraadt outp = SCARG(uap, buf);
545 1.33 deraadt resid = SCARG(uap, nbytes);
546 1.83 fvdl if ((len = buflen - auio.uio_resid) == 0)
547 1.1 deraadt goto eof;
548 1.56 mycroft
549 1.56 mycroft for (cookie = cookiebuf; len > 0; len -= reclen) {
550 1.56 mycroft bdp = (struct dirent *)inp;
551 1.56 mycroft reclen = bdp->d_reclen;
552 1.1 deraadt if (reclen & 3)
553 1.33 deraadt panic("sunos_getdents");
554 1.82 fvdl if ((*cookie >> 32) != 0) {
555 1.82 fvdl compat_offseterr(vp, "sunos_getdents");
556 1.82 fvdl error = EINVAL;
557 1.82 fvdl goto out;
558 1.82 fvdl }
559 1.56 mycroft if (bdp->d_fileno == 0) {
560 1.1 deraadt inp += reclen; /* it is a hole; squish it out */
561 1.132 christos if (cookie)
562 1.132 christos off = *cookie++;
563 1.132 christos else
564 1.132 christos off += reclen;
565 1.1 deraadt continue;
566 1.1 deraadt }
567 1.56 mycroft sunos_reclen = SUNOS_RECLEN(&idb, bdp->d_namlen);
568 1.56 mycroft if (reclen > len || resid < sunos_reclen) {
569 1.1 deraadt /* entry too big for buffer, so just stop */
570 1.1 deraadt outp++;
571 1.1 deraadt break;
572 1.1 deraadt }
573 1.132 christos if (cookie)
574 1.132 christos off = *cookie++; /* each entry points to next */
575 1.132 christos else
576 1.132 christos off += reclen;
577 1.1 deraadt /*
578 1.1 deraadt * Massage in place to make a Sun-shaped dirent (otherwise
579 1.1 deraadt * we have to worry about touching user memory outside of
580 1.1 deraadt * the copyout() call).
581 1.1 deraadt */
582 1.56 mycroft idb.d_fileno = bdp->d_fileno;
583 1.56 mycroft idb.d_off = off;
584 1.56 mycroft idb.d_reclen = sunos_reclen;
585 1.56 mycroft idb.d_namlen = bdp->d_namlen;
586 1.121 itojun strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
587 1.56 mycroft if ((error = copyout((caddr_t)&idb, outp, sunos_reclen)) != 0)
588 1.1 deraadt goto out;
589 1.1 deraadt /* advance past this real entry */
590 1.1 deraadt inp += reclen;
591 1.1 deraadt /* advance output past Sun-shaped entry */
592 1.56 mycroft outp += sunos_reclen;
593 1.56 mycroft resid -= sunos_reclen;
594 1.1 deraadt }
595 1.56 mycroft
596 1.1 deraadt /* if we squished out the whole block, try again */
597 1.33 deraadt if (outp == SCARG(uap, buf))
598 1.1 deraadt goto again;
599 1.1 deraadt fp->f_offset = off; /* update the vnode offset */
600 1.56 mycroft
601 1.1 deraadt eof:
602 1.33 deraadt *retval = SCARG(uap, nbytes) - resid;
603 1.1 deraadt out:
604 1.88 fvdl VOP_UNLOCK(vp, 0);
605 1.90 fvdl free(cookiebuf, M_TEMP);
606 1.1 deraadt free(buf, M_TEMP);
607 1.101 thorpej out1:
608 1.134 christos FILE_UNUSE(fp, l);
609 1.1 deraadt return (error);
610 1.1 deraadt }
611 1.1 deraadt
612 1.33 deraadt #define SUNOS__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
613 1.4 deraadt
614 1.33 deraadt int
615 1.117 thorpej sunos_sys_mmap(l, v, retval)
616 1.117 thorpej struct lwp *l;
617 1.54 thorpej void *v;
618 1.32 cgd register_t *retval;
619 1.1 deraadt {
620 1.104 augustss struct sunos_sys_mmap_args *uap = v;
621 1.55 mycroft struct sys_mmap_args ouap;
622 1.1 deraadt
623 1.1 deraadt /*
624 1.14 cgd * Verify the arguments.
625 1.1 deraadt */
626 1.33 deraadt if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
627 1.14 cgd return (EINVAL); /* XXX still needed? */
628 1.4 deraadt
629 1.33 deraadt if ((SCARG(uap, flags) & SUNOS__MAP_NEW) == 0)
630 1.1 deraadt return (EINVAL);
631 1.1 deraadt
632 1.34 deraadt SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUNOS__MAP_NEW;
633 1.34 deraadt SCARG(&ouap, addr) = SCARG(uap, addr);
634 1.34 deraadt SCARG(&ouap, len) = SCARG(uap, len);
635 1.34 deraadt SCARG(&ouap, prot) = SCARG(uap, prot);
636 1.34 deraadt SCARG(&ouap, fd) = SCARG(uap, fd);
637 1.34 deraadt SCARG(&ouap, pos) = SCARG(uap, pos);
638 1.4 deraadt
639 1.117 thorpej return (sys_mmap(l, &ouap, retval));
640 1.1 deraadt }
641 1.1 deraadt
642 1.1 deraadt #define MC_SYNC 1
643 1.1 deraadt #define MC_LOCK 2
644 1.1 deraadt #define MC_UNLOCK 3
645 1.1 deraadt #define MC_ADVISE 4
646 1.1 deraadt #define MC_LOCKAS 5
647 1.1 deraadt #define MC_UNLOCKAS 6
648 1.1 deraadt
649 1.33 deraadt int
650 1.117 thorpej sunos_sys_mctl(l, v, retval)
651 1.117 thorpej struct lwp *l;
652 1.54 thorpej void *v;
653 1.32 cgd register_t *retval;
654 1.1 deraadt {
655 1.104 augustss struct sunos_sys_mctl_args *uap = v;
656 1.1 deraadt
657 1.33 deraadt switch (SCARG(uap, func)) {
658 1.1 deraadt case MC_ADVISE: /* ignore for now */
659 1.1 deraadt return (0);
660 1.1 deraadt case MC_SYNC: /* translate to msync */
661 1.117 thorpej return (sys___msync13(l, uap, retval));
662 1.1 deraadt default:
663 1.1 deraadt return (EINVAL);
664 1.1 deraadt }
665 1.1 deraadt }
666 1.1 deraadt
667 1.33 deraadt int
668 1.117 thorpej sunos_sys_setsockopt(l, v, retval)
669 1.117 thorpej struct lwp *l;
670 1.54 thorpej void *v;
671 1.32 cgd register_t *retval;
672 1.1 deraadt {
673 1.104 augustss struct sunos_sys_setsockopt_args *uap = v;
674 1.117 thorpej struct proc *p = l->l_proc;
675 1.1 deraadt struct file *fp;
676 1.1 deraadt struct mbuf *m = NULL;
677 1.1 deraadt int error;
678 1.1 deraadt
679 1.101 thorpej /* getsock() will use the descriptor for us */
680 1.64 christos if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
681 1.1 deraadt return (error);
682 1.1 deraadt #define SO_DONTLINGER (~SO_LINGER)
683 1.33 deraadt if (SCARG(uap, name) == SO_DONTLINGER) {
684 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
685 1.1 deraadt mtod(m, struct linger *)->l_onoff = 0;
686 1.1 deraadt m->m_len = sizeof(struct linger);
687 1.101 thorpej error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
688 1.101 thorpej SO_LINGER, m);
689 1.101 thorpej goto out;
690 1.1 deraadt }
691 1.37 pk if (SCARG(uap, level) == IPPROTO_IP) {
692 1.37 pk #define SUNOS_IP_MULTICAST_IF 2
693 1.37 pk #define SUNOS_IP_MULTICAST_TTL 3
694 1.37 pk #define SUNOS_IP_MULTICAST_LOOP 4
695 1.37 pk #define SUNOS_IP_ADD_MEMBERSHIP 5
696 1.37 pk #define SUNOS_IP_DROP_MEMBERSHIP 6
697 1.128 matt static const int ipoptxlat[] = {
698 1.37 pk IP_MULTICAST_IF,
699 1.37 pk IP_MULTICAST_TTL,
700 1.37 pk IP_MULTICAST_LOOP,
701 1.37 pk IP_ADD_MEMBERSHIP,
702 1.37 pk IP_DROP_MEMBERSHIP
703 1.37 pk };
704 1.37 pk if (SCARG(uap, name) >= SUNOS_IP_MULTICAST_IF &&
705 1.37 pk SCARG(uap, name) <= SUNOS_IP_DROP_MEMBERSHIP) {
706 1.37 pk SCARG(uap, name) =
707 1.37 pk ipoptxlat[SCARG(uap, name) - SUNOS_IP_MULTICAST_IF];
708 1.37 pk }
709 1.37 pk }
710 1.101 thorpej if (SCARG(uap, valsize) > MLEN) {
711 1.101 thorpej error = EINVAL;
712 1.101 thorpej goto out;
713 1.101 thorpej }
714 1.33 deraadt if (SCARG(uap, val)) {
715 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
716 1.64 christos error = copyin(SCARG(uap, val), mtod(m, caddr_t),
717 1.64 christos (u_int)SCARG(uap, valsize));
718 1.64 christos if (error) {
719 1.1 deraadt (void) m_free(m);
720 1.101 thorpej goto out;
721 1.1 deraadt }
722 1.33 deraadt m->m_len = SCARG(uap, valsize);
723 1.1 deraadt }
724 1.101 thorpej error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
725 1.101 thorpej SCARG(uap, name), m);
726 1.101 thorpej out:
727 1.134 christos FILE_UNUSE(fp, l);
728 1.101 thorpej return (error);
729 1.113 mrg }
730 1.113 mrg
731 1.135 perry static inline int sunos_sys_socket_common(struct lwp *, register_t *,
732 1.113 mrg int type);
733 1.135 perry static inline int
734 1.117 thorpej sunos_sys_socket_common(l, retval, type)
735 1.117 thorpej struct lwp *l;
736 1.113 mrg register_t *retval;
737 1.113 mrg int type;
738 1.113 mrg {
739 1.113 mrg struct socket *so;
740 1.113 mrg struct file *fp;
741 1.113 mrg int error, fd;
742 1.113 mrg
743 1.113 mrg /* getsock() will use the descriptor for us */
744 1.113 mrg fd = (int)*retval;
745 1.117 thorpej if ((error = getsock(l->l_proc->p_fd, fd, &fp)) == 0) {
746 1.113 mrg so = (struct socket *)fp->f_data;
747 1.113 mrg if (type == SOCK_DGRAM)
748 1.113 mrg so->so_options |= SO_BROADCAST;
749 1.113 mrg }
750 1.134 christos FILE_UNUSE(fp, l);
751 1.113 mrg return (error);
752 1.113 mrg }
753 1.113 mrg
754 1.113 mrg int
755 1.117 thorpej sunos_sys_socket(l, v, retval)
756 1.117 thorpej struct lwp *l;
757 1.113 mrg void *v;
758 1.113 mrg register_t *retval;
759 1.113 mrg {
760 1.113 mrg struct sunos_sys_socket_args /* {
761 1.113 mrg syscallarg(int) domain;
762 1.113 mrg syscallarg(int) type;
763 1.113 mrg syscallarg(int) protocol;
764 1.113 mrg } */ *uap = v;
765 1.113 mrg int error;
766 1.113 mrg
767 1.139 mrg error = compat_30_sys_socket(l, v, retval);
768 1.113 mrg if (error)
769 1.113 mrg return (error);
770 1.117 thorpej return sunos_sys_socket_common(l, retval, SCARG(uap, type));
771 1.113 mrg }
772 1.113 mrg
773 1.113 mrg int
774 1.117 thorpej sunos_sys_socketpair(l, v, retval)
775 1.117 thorpej struct lwp *l;
776 1.113 mrg void *v;
777 1.113 mrg register_t *retval;
778 1.113 mrg {
779 1.113 mrg struct sunos_sys_socketpair_args /* {
780 1.113 mrg syscallarg(int) domain;
781 1.113 mrg syscallarg(int) type;
782 1.113 mrg syscallarg(int) protocol;
783 1.113 mrg syscallarg(int *) rsv;
784 1.113 mrg } */ *uap = v;
785 1.113 mrg int error;
786 1.113 mrg
787 1.117 thorpej error = sys_socketpair(l, v, retval);
788 1.113 mrg if (error)
789 1.113 mrg return (error);
790 1.117 thorpej return sunos_sys_socket_common(l, retval, SCARG(uap, type));
791 1.3 deraadt }
792 1.3 deraadt
793 1.3 deraadt /*
794 1.3 deraadt * XXX: This needs cleaning up.
795 1.3 deraadt */
796 1.33 deraadt int
797 1.117 thorpej sunos_sys_auditsys(l, v, retval)
798 1.117 thorpej struct lwp *l;
799 1.55 mycroft void *v;
800 1.40 deraadt register_t *retval;
801 1.3 deraadt {
802 1.3 deraadt return 0;
803 1.8 deraadt }
804 1.8 deraadt
805 1.33 deraadt int
806 1.117 thorpej sunos_sys_uname(l, v, retval)
807 1.117 thorpej struct lwp *l;
808 1.54 thorpej void *v;
809 1.32 cgd register_t *retval;
810 1.8 deraadt {
811 1.55 mycroft struct sunos_sys_uname_args *uap = v;
812 1.33 deraadt struct sunos_utsname sut;
813 1.8 deraadt
814 1.92 perry memset(&sut, 0, sizeof(sut));
815 1.8 deraadt
816 1.92 perry memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
817 1.92 perry memcpy(sut.nodename, hostname, sizeof(sut.nodename));
818 1.22 deraadt sut.nodename[sizeof(sut.nodename)-1] = '\0';
819 1.92 perry memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
820 1.92 perry memcpy(sut.version, "1", sizeof(sut.version) - 1);
821 1.92 perry memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
822 1.8 deraadt
823 1.33 deraadt return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
824 1.33 deraadt sizeof(struct sunos_utsname));
825 1.8 deraadt }
826 1.8 deraadt
827 1.8 deraadt int
828 1.117 thorpej sunos_sys_setpgrp(l, v, retval)
829 1.117 thorpej struct lwp *l;
830 1.54 thorpej void *v;
831 1.32 cgd register_t *retval;
832 1.8 deraadt {
833 1.55 mycroft struct sunos_sys_setpgrp_args *uap = v;
834 1.117 thorpej struct proc *p = l->l_proc;
835 1.54 thorpej
836 1.8 deraadt /*
837 1.8 deraadt * difference to our setpgid call is to include backwards
838 1.8 deraadt * compatibility to pre-setsid() binaries. Do setsid()
839 1.8 deraadt * instead of setpgid() in those cases where the process
840 1.8 deraadt * tries to create a new session the old way.
841 1.8 deraadt */
842 1.55 mycroft if (!SCARG(uap, pgid) &&
843 1.55 mycroft (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
844 1.117 thorpej return sys_setsid(l, uap, retval);
845 1.8 deraadt else
846 1.117 thorpej return sys_setpgid(l, uap, retval);
847 1.8 deraadt }
848 1.8 deraadt
849 1.33 deraadt int
850 1.117 thorpej sunos_sys_open(l, v, retval)
851 1.117 thorpej struct lwp *l;
852 1.54 thorpej void *v;
853 1.32 cgd register_t *retval;
854 1.8 deraadt {
855 1.55 mycroft struct sunos_sys_open_args *uap = v;
856 1.117 thorpej struct proc *p = l->l_proc;
857 1.117 thorpej int smode, nmode;
858 1.39 pk int noctty;
859 1.8 deraadt int ret;
860 1.131 perry
861 1.114 christos caddr_t sg = stackgap_init(p, 0);
862 1.48 pk
863 1.8 deraadt /* convert mode into NetBSD mode */
864 1.117 thorpej smode = SCARG(uap, flags);
865 1.117 thorpej noctty = smode & 0x8000;
866 1.117 thorpej nmode = smode &
867 1.117 thorpej (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800);
868 1.117 thorpej nmode |= ((smode & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
869 1.117 thorpej nmode |= ((smode & 0x0080) ? O_SHLOCK : 0);
870 1.117 thorpej nmode |= ((smode & 0x0100) ? O_EXLOCK : 0);
871 1.117 thorpej nmode |= ((smode & 0x2000) ? O_FSYNC : 0);
872 1.8 deraadt
873 1.117 thorpej if (nmode & O_CREAT)
874 1.134 christos CHECK_ALT_CREAT(l, &sg, SCARG(uap, path));
875 1.99 christos else
876 1.134 christos CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
877 1.99 christos
878 1.117 thorpej SCARG(uap, flags) = nmode;
879 1.117 thorpej ret = sys_open(l, (struct sys_open_args *)uap, retval);
880 1.8 deraadt
881 1.20 cgd if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
882 1.8 deraadt struct filedesc *fdp = p->p_fd;
883 1.110 thorpej struct file *fp;
884 1.110 thorpej
885 1.110 thorpej fp = fd_getfile(fdp, *retval);
886 1.120 pk simple_unlock(&fp->f_slock);
887 1.8 deraadt
888 1.8 deraadt /* ignore any error, just give it a try */
889 1.110 thorpej if (fp != NULL && fp->f_type == DTYPE_VNODE)
890 1.134 christos (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t)0, l);
891 1.8 deraadt }
892 1.8 deraadt return ret;
893 1.10 deraadt }
894 1.10 deraadt
895 1.11 chopps #if defined (NFSSERVER)
896 1.33 deraadt int
897 1.117 thorpej sunos_sys_nfssvc(l, v, retval)
898 1.117 thorpej struct lwp *l;
899 1.54 thorpej void *v;
900 1.32 cgd register_t *retval;
901 1.10 deraadt {
902 1.64 christos #if 0
903 1.55 mycroft struct sunos_sys_nfssvc_args *uap = v;
904 1.117 thorpej struct proc *p = l->l_proc;
905 1.51 briggs struct emul *e = p->p_emul;
906 1.55 mycroft struct sys_nfssvc_args outuap;
907 1.10 deraadt struct sockaddr sa;
908 1.10 deraadt int error;
909 1.114 christos caddr_t sg = stackgap_init(p, 0);
910 1.10 deraadt
911 1.92 perry memset(&outuap, 0, sizeof outuap);
912 1.33 deraadt SCARG(&outuap, fd) = SCARG(uap, fd);
913 1.114 christos SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof(sa));
914 1.74 christos SCARG(&outuap, msklen) = sizeof(sa);
915 1.114 christos SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof(sa));
916 1.74 christos SCARG(&outuap, mtchlen) = sizeof(sa);
917 1.10 deraadt
918 1.92 perry memset(&sa, 0, sizeof sa);
919 1.33 deraadt if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
920 1.10 deraadt return (error);
921 1.33 deraadt if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
922 1.10 deraadt return (error);
923 1.10 deraadt
924 1.117 thorpej return nfssvc(l, &outuap, retval);
925 1.33 deraadt #else
926 1.33 deraadt return (ENOSYS);
927 1.33 deraadt #endif
928 1.10 deraadt }
929 1.11 chopps #endif /* NFSSERVER */
930 1.10 deraadt
931 1.33 deraadt int
932 1.117 thorpej sunos_sys_ustat(l, v, retval)
933 1.117 thorpej struct lwp *l;
934 1.54 thorpej void *v;
935 1.32 cgd register_t *retval;
936 1.10 deraadt {
937 1.55 mycroft struct sunos_sys_ustat_args *uap = v;
938 1.33 deraadt struct sunos_ustat us;
939 1.10 deraadt int error;
940 1.10 deraadt
941 1.92 perry memset(&us, 0, sizeof us);
942 1.10 deraadt
943 1.10 deraadt /*
944 1.10 deraadt * XXX: should set f_tfree and f_tinode at least
945 1.33 deraadt * How do we translate dev -> fstat? (and then to sunos_ustat)
946 1.10 deraadt */
947 1.10 deraadt
948 1.64 christos if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
949 1.10 deraadt return (error);
950 1.10 deraadt return 0;
951 1.10 deraadt }
952 1.10 deraadt
953 1.33 deraadt int
954 1.117 thorpej sunos_sys_quotactl(l, v, retval)
955 1.117 thorpej struct lwp *l;
956 1.54 thorpej void *v;
957 1.32 cgd register_t *retval;
958 1.10 deraadt {
959 1.54 thorpej
960 1.10 deraadt return EINVAL;
961 1.10 deraadt }
962 1.10 deraadt
963 1.33 deraadt int
964 1.117 thorpej sunos_sys_vhangup(l, v, retval)
965 1.117 thorpej struct lwp *l;
966 1.55 mycroft void *v;
967 1.32 cgd register_t *retval;
968 1.10 deraadt {
969 1.117 thorpej struct proc *p = l->l_proc;
970 1.60 pk struct session *sp = p->p_session;
971 1.60 pk
972 1.60 pk if (sp->s_ttyvp == 0)
973 1.60 pk return 0;
974 1.60 pk
975 1.60 pk if (sp->s_ttyp && sp->s_ttyp->t_session == sp && sp->s_ttyp->t_pgrp)
976 1.60 pk pgsignal(sp->s_ttyp->t_pgrp, SIGHUP, 1);
977 1.60 pk
978 1.60 pk (void) ttywait(sp->s_ttyp);
979 1.60 pk if (sp->s_ttyvp)
980 1.90 fvdl VOP_REVOKE(sp->s_ttyvp, REVOKEALL);
981 1.60 pk if (sp->s_ttyvp)
982 1.60 pk vrele(sp->s_ttyvp);
983 1.60 pk sp->s_ttyvp = NULL;
984 1.55 mycroft
985 1.10 deraadt return 0;
986 1.10 deraadt }
987 1.10 deraadt
988 1.64 christos static int
989 1.10 deraadt sunstatfs(sp, buf)
990 1.126 christos struct statvfs *sp;
991 1.10 deraadt caddr_t buf;
992 1.10 deraadt {
993 1.33 deraadt struct sunos_statfs ssfs;
994 1.10 deraadt
995 1.92 perry memset(&ssfs, 0, sizeof ssfs);
996 1.10 deraadt ssfs.f_type = 0;
997 1.16 deraadt ssfs.f_bsize = sp->f_bsize;
998 1.10 deraadt ssfs.f_blocks = sp->f_blocks;
999 1.10 deraadt ssfs.f_bfree = sp->f_bfree;
1000 1.10 deraadt ssfs.f_bavail = sp->f_bavail;
1001 1.10 deraadt ssfs.f_files = sp->f_files;
1002 1.10 deraadt ssfs.f_ffree = sp->f_ffree;
1003 1.126 christos ssfs.f_fsid = sp->f_fsidx;
1004 1.10 deraadt return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
1005 1.131 perry }
1006 1.10 deraadt
1007 1.33 deraadt int
1008 1.117 thorpej sunos_sys_statfs(l, v, retval)
1009 1.117 thorpej struct lwp *l;
1010 1.54 thorpej void *v;
1011 1.32 cgd register_t *retval;
1012 1.10 deraadt {
1013 1.55 mycroft struct sunos_sys_statfs_args *uap = v;
1014 1.117 thorpej struct proc *p = l->l_proc;
1015 1.104 augustss struct mount *mp;
1016 1.127 hannken struct statvfs *sp;
1017 1.10 deraadt int error;
1018 1.10 deraadt struct nameidata nd;
1019 1.10 deraadt
1020 1.114 christos caddr_t sg = stackgap_init(p, 0);
1021 1.134 christos CHECK_ALT_EXIST(l, &sg, SCARG(uap, path));
1022 1.48 pk
1023 1.134 christos NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, path), l);
1024 1.64 christos if ((error = namei(&nd)) != 0)
1025 1.10 deraadt return (error);
1026 1.27 pk mp = nd.ni_vp->v_mount;
1027 1.10 deraadt sp = &mp->mnt_stat;
1028 1.27 pk vrele(nd.ni_vp);
1029 1.134 christos if ((error = VFS_STATVFS(mp, sp, l)) != 0)
1030 1.10 deraadt return (error);
1031 1.127 hannken sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
1032 1.33 deraadt return sunstatfs(sp, (caddr_t)SCARG(uap, buf));
1033 1.10 deraadt }
1034 1.10 deraadt
1035 1.33 deraadt int
1036 1.117 thorpej sunos_sys_fstatfs(l, v, retval)
1037 1.117 thorpej struct lwp *l;
1038 1.54 thorpej void *v;
1039 1.32 cgd register_t *retval;
1040 1.10 deraadt {
1041 1.55 mycroft struct sunos_sys_fstatfs_args *uap = v;
1042 1.117 thorpej struct proc *p = l->l_proc;
1043 1.10 deraadt struct file *fp;
1044 1.10 deraadt struct mount *mp;
1045 1.127 hannken struct statvfs *sp;
1046 1.10 deraadt int error;
1047 1.10 deraadt
1048 1.101 thorpej /* getvnode() will use the descriptor for us */
1049 1.64 christos if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
1050 1.10 deraadt return (error);
1051 1.10 deraadt mp = ((struct vnode *)fp->f_data)->v_mount;
1052 1.10 deraadt sp = &mp->mnt_stat;
1053 1.134 christos if ((error = VFS_STATVFS(mp, sp, l)) != 0)
1054 1.101 thorpej goto out;
1055 1.127 hannken sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
1056 1.101 thorpej error = sunstatfs(sp, (caddr_t)SCARG(uap, buf));
1057 1.101 thorpej out:
1058 1.134 christos FILE_UNUSE(fp, l);
1059 1.101 thorpej return (error);
1060 1.10 deraadt }
1061 1.10 deraadt
1062 1.33 deraadt int
1063 1.117 thorpej sunos_sys_exportfs(l, v, retval)
1064 1.117 thorpej struct lwp *l;
1065 1.54 thorpej void *v;
1066 1.32 cgd register_t *retval;
1067 1.10 deraadt {
1068 1.10 deraadt /*
1069 1.10 deraadt * XXX: should perhaps translate into a mount(2)
1070 1.10 deraadt * with MOUNT_EXPORT?
1071 1.10 deraadt */
1072 1.10 deraadt return 0;
1073 1.10 deraadt }
1074 1.10 deraadt
1075 1.33 deraadt int
1076 1.117 thorpej sunos_sys_mknod(l, v, retval)
1077 1.117 thorpej struct lwp *l;
1078 1.54 thorpej void *v;
1079 1.32 cgd register_t *retval;
1080 1.10 deraadt {
1081 1.55 mycroft struct sunos_sys_mknod_args *uap = v;
1082 1.117 thorpej struct proc *p = l->l_proc;
1083 1.55 mycroft
1084 1.114 christos caddr_t sg = stackgap_init(p, 0);
1085 1.134 christos CHECK_ALT_CREAT(l, &sg, SCARG(uap, path));
1086 1.48 pk
1087 1.33 deraadt if (S_ISFIFO(SCARG(uap, mode)))
1088 1.117 thorpej return sys_mkfifo(l, uap, retval);
1089 1.10 deraadt
1090 1.117 thorpej return sys_mknod(l, (struct sys_mknod_args *)uap, retval);
1091 1.12 deraadt }
1092 1.12 deraadt
1093 1.33 deraadt #define SUNOS_SC_ARG_MAX 1
1094 1.33 deraadt #define SUNOS_SC_CHILD_MAX 2
1095 1.33 deraadt #define SUNOS_SC_CLK_TCK 3
1096 1.33 deraadt #define SUNOS_SC_NGROUPS_MAX 4
1097 1.33 deraadt #define SUNOS_SC_OPEN_MAX 5
1098 1.33 deraadt #define SUNOS_SC_JOB_CONTROL 6
1099 1.33 deraadt #define SUNOS_SC_SAVED_IDS 7
1100 1.33 deraadt #define SUNOS_SC_VERSION 8
1101 1.12 deraadt
1102 1.33 deraadt int
1103 1.117 thorpej sunos_sys_sysconf(l, v, retval)
1104 1.117 thorpej struct lwp *l;
1105 1.54 thorpej void *v;
1106 1.32 cgd register_t *retval;
1107 1.12 deraadt {
1108 1.55 mycroft struct sunos_sys_sysconf_args *uap = v;
1109 1.24 deraadt extern int maxfiles;
1110 1.12 deraadt
1111 1.33 deraadt switch(SCARG(uap, name)) {
1112 1.33 deraadt case SUNOS_SC_ARG_MAX:
1113 1.12 deraadt *retval = ARG_MAX;
1114 1.13 deraadt break;
1115 1.33 deraadt case SUNOS_SC_CHILD_MAX:
1116 1.12 deraadt *retval = maxproc;
1117 1.13 deraadt break;
1118 1.33 deraadt case SUNOS_SC_CLK_TCK:
1119 1.12 deraadt *retval = 60; /* should this be `hz', ie. 100? */
1120 1.13 deraadt break;
1121 1.33 deraadt case SUNOS_SC_NGROUPS_MAX:
1122 1.12 deraadt *retval = NGROUPS_MAX;
1123 1.13 deraadt break;
1124 1.33 deraadt case SUNOS_SC_OPEN_MAX:
1125 1.24 deraadt *retval = maxfiles;
1126 1.13 deraadt break;
1127 1.33 deraadt case SUNOS_SC_JOB_CONTROL:
1128 1.12 deraadt *retval = 1;
1129 1.13 deraadt break;
1130 1.33 deraadt case SUNOS_SC_SAVED_IDS:
1131 1.12 deraadt #ifdef _POSIX_SAVED_IDS
1132 1.12 deraadt *retval = 1;
1133 1.12 deraadt #else
1134 1.12 deraadt *retval = 0;
1135 1.12 deraadt #endif
1136 1.13 deraadt break;
1137 1.33 deraadt case SUNOS_SC_VERSION:
1138 1.12 deraadt *retval = 198808;
1139 1.13 deraadt break;
1140 1.12 deraadt default:
1141 1.12 deraadt return EINVAL;
1142 1.12 deraadt }
1143 1.12 deraadt return 0;
1144 1.17 pk }
1145 1.17 pk
1146 1.33 deraadt #define SUNOS_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */
1147 1.33 deraadt #define SUNOS_RLIM_NLIMITS 7
1148 1.17 pk
1149 1.33 deraadt int
1150 1.117 thorpej sunos_sys_getrlimit(l, v, retval)
1151 1.117 thorpej struct lwp *l;
1152 1.54 thorpej void *v;
1153 1.32 cgd register_t *retval;
1154 1.17 pk {
1155 1.55 mycroft struct sunos_sys_getrlimit_args *uap = v;
1156 1.54 thorpej
1157 1.33 deraadt if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1158 1.17 pk return EINVAL;
1159 1.17 pk
1160 1.33 deraadt if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1161 1.33 deraadt SCARG(uap, which) = RLIMIT_NOFILE;
1162 1.17 pk
1163 1.117 thorpej return compat_43_sys_getrlimit(l, uap, retval);
1164 1.17 pk }
1165 1.17 pk
1166 1.33 deraadt int
1167 1.117 thorpej sunos_sys_setrlimit(l, v, retval)
1168 1.117 thorpej struct lwp *l;
1169 1.54 thorpej void *v;
1170 1.32 cgd register_t *retval;
1171 1.17 pk {
1172 1.55 mycroft struct sunos_sys_getrlimit_args *uap = v;
1173 1.54 thorpej
1174 1.33 deraadt if (SCARG(uap, which) >= SUNOS_RLIM_NLIMITS)
1175 1.17 pk return EINVAL;
1176 1.17 pk
1177 1.33 deraadt if (SCARG(uap, which) == SUNOS_RLIMIT_NOFILE)
1178 1.33 deraadt SCARG(uap, which) = RLIMIT_NOFILE;
1179 1.17 pk
1180 1.117 thorpej return compat_43_sys_setrlimit(l, uap, retval);
1181 1.35 deraadt }
1182 1.36 deraadt
1183 1.142 matt #if defined(PTRACE) || defined(_LKM)
1184 1.36 deraadt /* for the m68k machines */
1185 1.36 deraadt #ifndef PT_GETFPREGS
1186 1.36 deraadt #define PT_GETFPREGS -1
1187 1.36 deraadt #endif
1188 1.36 deraadt #ifndef PT_SETFPREGS
1189 1.36 deraadt #define PT_SETFPREGS -1
1190 1.36 deraadt #endif
1191 1.35 deraadt
1192 1.129 matt static const int sreq2breq[] = {
1193 1.35 deraadt PT_TRACE_ME, PT_READ_I, PT_READ_D, -1,
1194 1.35 deraadt PT_WRITE_I, PT_WRITE_D, -1, PT_CONTINUE,
1195 1.35 deraadt PT_KILL, -1, PT_ATTACH, PT_DETACH,
1196 1.35 deraadt PT_GETREGS, PT_SETREGS, PT_GETFPREGS, PT_SETFPREGS
1197 1.35 deraadt };
1198 1.129 matt static const int nreqs = sizeof(sreq2breq) / sizeof(sreq2breq[0]);
1199 1.142 matt #endif /* PTRACE || _LKM */
1200 1.35 deraadt
1201 1.64 christos int
1202 1.117 thorpej sunos_sys_ptrace(l, v, retval)
1203 1.117 thorpej struct lwp *l;
1204 1.54 thorpej void *v;
1205 1.55 mycroft register_t *retval;
1206 1.35 deraadt {
1207 1.142 matt #if defined(PTRACE) || defined(_LKM)
1208 1.55 mycroft struct sunos_sys_ptrace_args *uap = v;
1209 1.55 mycroft struct sys_ptrace_args pa;
1210 1.35 deraadt int req;
1211 1.35 deraadt
1212 1.142 matt #ifdef _LKM
1213 1.142 matt #define sys_ptrace sysent[SYS_ptrace].sy_call
1214 1.142 matt if (sys_ptrace == sys_nosys)
1215 1.142 matt return ENOSYS;
1216 1.142 matt #endif
1217 1.142 matt
1218 1.35 deraadt req = SCARG(uap, req);
1219 1.35 deraadt
1220 1.35 deraadt if (req < 0 || req >= nreqs)
1221 1.35 deraadt return (EINVAL);
1222 1.35 deraadt
1223 1.35 deraadt req = sreq2breq[req];
1224 1.35 deraadt if (req == -1)
1225 1.35 deraadt return (EINVAL);
1226 1.35 deraadt
1227 1.35 deraadt SCARG(&pa, req) = req;
1228 1.35 deraadt SCARG(&pa, pid) = (pid_t)SCARG(uap, pid);
1229 1.35 deraadt SCARG(&pa, addr) = (caddr_t)SCARG(uap, addr);
1230 1.35 deraadt SCARG(&pa, data) = SCARG(uap, data);
1231 1.35 deraadt
1232 1.117 thorpej return sys_ptrace(l, &pa, retval);
1233 1.142 matt #else
1234 1.142 matt return ENOSYS;
1235 1.142 matt #endif /* PTRACE || _LKM */
1236 1.44 christos }
1237 1.44 christos
1238 1.44 christos /*
1239 1.44 christos * SunOS reboot system call (for compatibility).
1240 1.44 christos * Sun lets you pass in a boot string which the PROM
1241 1.44 christos * saves and provides to the next boot program.
1242 1.44 christos */
1243 1.68 mrg
1244 1.68 mrg #define SUNOS_RB_ASKNAME 0x001
1245 1.68 mrg #define SUNOS_RB_SINGLE 0x002
1246 1.68 mrg #define SUNOS_RB_NOSYNC 0x004
1247 1.68 mrg #define SUNOS_RB_HALT 0x008
1248 1.68 mrg #define SUNOS_RB_DUMP 0x080
1249 1.68 mrg #define SUNOS_RB_STRING 0x200
1250 1.68 mrg
1251 1.44 christos static struct sunos_howto_conv {
1252 1.46 gwr int sun_howto;
1253 1.44 christos int bsd_howto;
1254 1.44 christos } sunos_howto_conv[] = {
1255 1.68 mrg { SUNOS_RB_ASKNAME, RB_ASKNAME },
1256 1.68 mrg { SUNOS_RB_SINGLE, RB_SINGLE },
1257 1.68 mrg { SUNOS_RB_NOSYNC, RB_NOSYNC },
1258 1.68 mrg { SUNOS_RB_HALT, RB_HALT },
1259 1.68 mrg { SUNOS_RB_DUMP, RB_DUMP },
1260 1.68 mrg { SUNOS_RB_STRING, RB_STRING },
1261 1.68 mrg { 0x000, 0 },
1262 1.44 christos };
1263 1.44 christos
1264 1.46 gwr int
1265 1.117 thorpej sunos_sys_reboot(l, v, retval)
1266 1.117 thorpej struct lwp *l;
1267 1.54 thorpej void *v;
1268 1.46 gwr register_t *retval;
1269 1.44 christos {
1270 1.55 mycroft struct sunos_sys_reboot_args *uap = v;
1271 1.68 mrg struct sys_reboot_args ua;
1272 1.44 christos struct sunos_howto_conv *convp;
1273 1.46 gwr int error, bsd_howto, sun_howto;
1274 1.68 mrg char *bootstr;
1275 1.44 christos
1276 1.143 elad if ((error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_REBOOT,
1277 1.143 elad 0, NULL, NULL, NULL)) != 0)
1278 1.44 christos return (error);
1279 1.44 christos
1280 1.44 christos /*
1281 1.44 christos * Convert howto bits to BSD format.
1282 1.44 christos */
1283 1.46 gwr sun_howto = SCARG(uap, howto);
1284 1.44 christos bsd_howto = 0;
1285 1.44 christos convp = sunos_howto_conv;
1286 1.46 gwr while (convp->sun_howto) {
1287 1.68 mrg if (sun_howto & convp->sun_howto)
1288 1.44 christos bsd_howto |= convp->bsd_howto;
1289 1.44 christos convp++;
1290 1.44 christos }
1291 1.44 christos
1292 1.44 christos /*
1293 1.44 christos * Sun RB_STRING (Get user supplied bootstring.)
1294 1.46 gwr * If the machine supports passing a string to the
1295 1.67 mrg * next booted kernel.
1296 1.44 christos */
1297 1.46 gwr if (sun_howto & SUNOS_RB_STRING) {
1298 1.46 gwr char bs[128];
1299 1.46 gwr
1300 1.47 christos error = copyinstr(SCARG(uap, bootstr), bs, sizeof(bs), 0);
1301 1.67 mrg
1302 1.68 mrg if (error)
1303 1.68 mrg bootstr = NULL;
1304 1.68 mrg else
1305 1.68 mrg bootstr = bs;
1306 1.67 mrg } else
1307 1.68 mrg bootstr = NULL;
1308 1.46 gwr
1309 1.68 mrg SCARG(&ua, opt) = bsd_howto;
1310 1.68 mrg SCARG(&ua, bootstr) = bootstr;
1311 1.117 thorpej sys_reboot(l, &ua, retval);
1312 1.68 mrg return(0);
1313 1.50 christos }
1314 1.50 christos
1315 1.50 christos /*
1316 1.50 christos * Generalized interface signal handler, 4.3-compatible.
1317 1.50 christos */
1318 1.50 christos /* ARGSUSED */
1319 1.50 christos int
1320 1.117 thorpej sunos_sys_sigvec(l, v, retval)
1321 1.117 thorpej struct lwp *l;
1322 1.54 thorpej void *v;
1323 1.54 thorpej register_t *retval;
1324 1.54 thorpej {
1325 1.95 pk struct sunos_sys_sigvec_args /* {
1326 1.50 christos syscallarg(int) signum;
1327 1.50 christos syscallarg(struct sigvec *) nsv;
1328 1.50 christos syscallarg(struct sigvec *) osv;
1329 1.54 thorpej } */ *uap = v;
1330 1.95 pk struct sigvec nsv, osv;
1331 1.95 pk struct sigaction nsa, osa;
1332 1.95 pk int error;
1333 1.95 pk /*XXX*/extern void compat_43_sigvec_to_sigaction
1334 1.95 pk __P((const struct sigvec *, struct sigaction *));
1335 1.95 pk /*XXX*/extern void compat_43_sigaction_to_sigvec
1336 1.95 pk __P((const struct sigaction *, struct sigvec *));
1337 1.95 pk
1338 1.50 christos if (SCARG(uap, nsv)) {
1339 1.95 pk error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
1340 1.95 pk if (error != 0)
1341 1.50 christos return (error);
1342 1.95 pk
1343 1.50 christos /*
1344 1.53 gwr * SunOS uses the mask 0x0004 as SV_RESETHAND
1345 1.53 gwr * meaning: `reset to SIG_DFL on delivery'.
1346 1.53 gwr * We support only the bits in: 0xF
1347 1.53 gwr * (those bits are the same as ours)
1348 1.50 christos */
1349 1.95 pk if (nsv.sv_flags & ~0xF)
1350 1.53 gwr return (EINVAL);
1351 1.95 pk
1352 1.95 pk compat_43_sigvec_to_sigaction(&nsv, &nsa);
1353 1.95 pk }
1354 1.117 thorpej error = sigaction1(l->l_proc, SCARG(uap, signum),
1355 1.95 pk SCARG(uap, nsv) ? &nsa : 0,
1356 1.115 thorpej SCARG(uap, osv) ? &osa : 0,
1357 1.115 thorpej NULL, 0);
1358 1.95 pk if (error != 0)
1359 1.95 pk return (error);
1360 1.95 pk
1361 1.95 pk if (SCARG(uap, osv)) {
1362 1.95 pk compat_43_sigaction_to_sigvec(&osa, &osv);
1363 1.96 pk error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
1364 1.95 pk if (error != 0)
1365 1.95 pk return (error);
1366 1.50 christos }
1367 1.95 pk
1368 1.50 christos return (0);
1369 1.1 deraadt }
1370