ultrix_misc.c revision 1.81 1 /* $NetBSD: ultrix_misc.c,v 1.81 2003/01/18 08:49:22 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1995, 1997 Jonathan Stone (hereinafter referred to as the author)
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Jonathan Stone for
18 * the NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 /*
36 * Copyright (c) 1992, 1993
37 * The Regents of the University of California. All rights reserved.
38 *
39 * This software was developed by the Computer Systems Engineering group
40 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
41 * contributed to Berkeley.
42 *
43 * All advertising materials mentioning features or use of this software
44 * must display the following acknowledgement:
45 * This product includes software developed by the University of
46 * California, Lawrence Berkeley Laboratory.
47 *
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
50 * are met:
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
56 * 3. All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement:
58 * This product includes software developed by the University of
59 * California, Berkeley and its contributors.
60 * 4. Neither the name of the University nor the names of its contributors
61 * may be used to endorse or promote products derived from this software
62 * without specific prior written permission.
63 *
64 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * SUCH DAMAGE.
75 *
76 *
77 * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
78 *
79 * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
80 */
81
82 #include <sys/cdefs.h>
83 __KERNEL_RCSID(0, "$NetBSD: ultrix_misc.c,v 1.81 2003/01/18 08:49:22 thorpej Exp $");
84
85 #if defined(_KERNEL_OPT)
86 #include "opt_nfsserver.h"
87 #include "opt_sysv.h"
88 #endif
89
90 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
91
92 /*
93 * Ultrix compatibility module.
94 *
95 * Ultrix system calls that are implemented differently in BSD are
96 * handled here.
97 */
98
99 #if defined(_KERNEL_OPT)
100 #include "fs_nfs.h"
101 #endif
102
103 #include <sys/param.h>
104 #include <sys/systm.h>
105 #include <sys/namei.h>
106 #include <sys/dirent.h>
107 #include <sys/proc.h>
108 #include <sys/file.h>
109 #include <sys/filedesc.h>
110 #include <sys/kernel.h>
111 #include <sys/exec.h>
112 #include <sys/malloc.h>
113 #include <sys/mbuf.h>
114 #include <sys/mman.h>
115 #include <sys/mount.h>
116 #include <sys/resource.h>
117 #include <sys/resourcevar.h>
118 #include <sys/signal.h>
119 #include <sys/signalvar.h>
120 #include <sys/socket.h>
121 #include <sys/vnode.h>
122 #include <sys/uio.h>
123 #include <sys/wait.h>
124 #include <sys/utsname.h>
125 #include <sys/unistd.h>
126 #include <sys/ipc.h>
127
128 #include <sys/sa.h>
129 #include <sys/syscallargs.h>
130
131 #include <compat/ultrix/ultrix_syscall.h>
132 #include <compat/ultrix/ultrix_syscallargs.h>
133 #include <compat/common/compat_util.h>
134
135 #include <netinet/in.h>
136
137 #include <miscfs/specfs/specdev.h>
138
139 #include <nfs/rpcv2.h>
140 #include <nfs/nfsproto.h>
141 #include <nfs/nfs.h>
142
143 #include <sys/socketvar.h> /* sosetopt() */
144
145 #include <compat/ultrix/ultrix_flock.h>
146
147 #ifdef __mips
148 #include <mips/cachectl.h>
149 #endif
150
151 static int ultrix_to_bsd_flock __P((struct ultrix_flock *, struct flock *));
152 static void bsd_to_ultrix_flock __P((struct flock *, struct ultrix_flock *));
153
154 extern struct sysent ultrix_sysent[];
155 extern const char * const ultrix_syscallnames[];
156 extern char ultrix_sigcode[], ultrix_esigcode[];
157 #ifdef __HAVE_SYSCALL_INTERN
158 void syscall_intern(struct proc *);
159 #else
160 void syscall __P((void));
161 #endif
162
163 const struct emul emul_ultrix = {
164 "ultrix",
165 "/emul/ultrix",
166 #ifndef __HAVE_MINIMAL_EMUL
167 0,
168 NULL,
169 ULTRIX_SYS_syscall,
170 ULTRIX_SYS_NSYSENT,
171 #endif
172 ultrix_sysent,
173 ultrix_syscallnames,
174 sendsig,
175 trapsignal,
176 ultrix_sigcode,
177 ultrix_esigcode,
178 setregs,
179 NULL,
180 NULL,
181 NULL,
182 #ifdef __HAVE_SYSCALL_INTERN
183 syscall_intern,
184 #else
185 syscall,
186 #endif
187 NULL,
188 NULL,
189 };
190
191 #define GSI_PROG_ENV 1
192
193 int
194 ultrix_sys_getsysinfo(l, v, retval)
195 struct lwp *l;
196 void *v;
197 register_t *retval;
198 {
199 struct ultrix_sys_getsysinfo_args *uap = v;
200 static short progenv = 0;
201
202 switch (SCARG(uap, op)) {
203 /* operations implemented: */
204 case GSI_PROG_ENV:
205 if (SCARG(uap, nbytes) < sizeof(short))
206 return EINVAL;
207 *retval = 1;
208 return (copyout(&progenv, SCARG(uap, buffer), sizeof(short)));
209 default:
210 *retval = 0; /* info unavail */
211 return 0;
212 }
213 }
214
215 int
216 ultrix_sys_setsysinfo(l, v, retval)
217 struct lwp *l;
218 void *v;
219 register_t *retval;
220 {
221
222 #ifdef notyet
223 struct ultrix_sys_setsysinfo_args *uap = v;
224 #endif
225
226 *retval = 0;
227 return 0;
228 }
229
230 int
231 ultrix_sys_waitpid(l, v, retval)
232 struct lwp *l;
233 void *v;
234 register_t *retval;
235 {
236 struct ultrix_sys_waitpid_args *uap = v;
237 struct sys_wait4_args ua;
238
239 SCARG(&ua, pid) = SCARG(uap, pid);
240 SCARG(&ua, status) = SCARG(uap, status);
241 SCARG(&ua, options) = SCARG(uap, options);
242 SCARG(&ua, rusage) = 0;
243
244 return (sys_wait4(l, &ua, retval));
245 }
246
247 int
248 ultrix_sys_wait3(l, v, retval)
249 struct lwp *l;
250 void *v;
251 register_t *retval;
252 {
253 struct ultrix_sys_wait3_args *uap = v;
254 struct sys_wait4_args ua;
255
256 SCARG(&ua, pid) = -1;
257 SCARG(&ua, status) = SCARG(uap, status);
258 SCARG(&ua, options) = SCARG(uap, options);
259 SCARG(&ua, rusage) = SCARG(uap, rusage);
260
261 return (sys_wait4(l, &ua, retval));
262 }
263
264 /*
265 * Ultrix binaries pass in FD_MAX as the first arg to select().
266 * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select()
267 * can handle.
268 * Since we can't have more than the (native) FD_MAX descriptors open,
269 * limit nfds to at most FD_MAX.
270 */
271 int
272 ultrix_sys_select(l, v, retval)
273 struct lwp *l;
274 void *v;
275 register_t *retval;
276 {
277 struct sys_select_args *uap = v;
278 struct timeval atv;
279 int error;
280
281 /* Limit number of FDs selected on to the native maximum */
282
283 if (SCARG(uap, nd) > FD_SETSIZE)
284 SCARG(uap, nd) = FD_SETSIZE;
285
286 /* Check for negative timeval */
287 if (SCARG(uap, tv)) {
288 error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv,
289 sizeof(atv));
290 if (error)
291 goto done;
292 #ifdef DEBUG
293 /* Ultrix clients sometimes give negative timeouts? */
294 if (atv.tv_sec < 0 || atv.tv_usec < 0)
295 printf("ultrix select( %ld, %ld): negative timeout\n",
296 atv.tv_sec, atv.tv_usec);
297 #endif
298
299 }
300 error = sys_select(l, (void*) uap, retval);
301 if (error == EINVAL)
302 printf("ultrix select: bad args?\n");
303
304 done:
305 return error;
306 }
307
308 #if defined(NFS)
309 int
310 async_daemon(l, v, retval)
311 struct lwp *l;
312 void *v;
313 register_t *retval;
314 {
315 struct sys_nfssvc_args ouap;
316
317 SCARG(&ouap, flag) = NFSSVC_BIOD;
318 SCARG(&ouap, argp) = NULL;
319
320 return (sys_nfssvc(l, &ouap, retval));
321 }
322 #endif /* NFS */
323
324
325 #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
326
327 int
328 ultrix_sys_mmap(l, v, retval)
329 struct lwp *l;
330 void *v;
331 register_t *retval;
332 {
333 struct ultrix_sys_mmap_args *uap = v;
334 struct proc *p = l->l_proc;
335 struct sys_mmap_args ouap;
336 struct filedesc *fdp;
337 struct file *fp;
338 struct vnode *vp;
339
340 /*
341 * Verify the arguments.
342 */
343 if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
344 return (EINVAL); /* XXX still needed? */
345
346 if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
347 return (EINVAL);
348
349 SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
350 SCARG(&ouap, addr) = SCARG(uap, addr);
351
352 if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
353 SCARG(&ouap, addr) != 0 &&
354 SCARG(&ouap, addr) < (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ))
355 SCARG(&ouap, addr) = (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ);
356
357 SCARG(&ouap, len) = SCARG(uap, len);
358 SCARG(&ouap, prot) = SCARG(uap, prot);
359 SCARG(&ouap, fd) = SCARG(uap, fd);
360 SCARG(&ouap, pos) = SCARG(uap, pos);
361
362 /*
363 * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
364 */
365 fdp = p->p_fd;
366 if ((fp = fd_getfile(fdp, SCARG(&ouap, fd))) != NULL && /*XXX*/
367 fp->f_type == DTYPE_VNODE && /*XXX*/
368 (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
369 vp->v_rdev == zerodev) { /*XXX*/
370 SCARG(&ouap, flags) |= MAP_ANON;
371 SCARG(&ouap, fd) = -1;
372 }
373
374 return (sys_mmap(l, &ouap, retval));
375 }
376
377 int
378 ultrix_sys_setsockopt(l, v, retval)
379 struct lwp *l;
380 void *v;
381 register_t *retval;
382 {
383 struct ultrix_sys_setsockopt_args *uap = v;
384 struct proc *p = l->l_proc;
385 struct file *fp;
386 struct mbuf *m = NULL;
387 int error;
388
389 /* getsock() will use the descriptor for us */
390 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
391 return (error);
392 #define SO_DONTLINGER (~SO_LINGER)
393 if (SCARG(uap, name) == SO_DONTLINGER) {
394 m = m_get(M_WAIT, MT_SOOPTS);
395 mtod(m, struct linger *)->l_onoff = 0;
396 m->m_len = sizeof(struct linger);
397 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
398 SO_LINGER, m);
399 }
400 if (SCARG(uap, level) == IPPROTO_IP) {
401 #define EMUL_IP_MULTICAST_IF 2
402 #define EMUL_IP_MULTICAST_TTL 3
403 #define EMUL_IP_MULTICAST_LOOP 4
404 #define EMUL_IP_ADD_MEMBERSHIP 5
405 #define EMUL_IP_DROP_MEMBERSHIP 6
406 static int ipoptxlat[] = {
407 IP_MULTICAST_IF,
408 IP_MULTICAST_TTL,
409 IP_MULTICAST_LOOP,
410 IP_ADD_MEMBERSHIP,
411 IP_DROP_MEMBERSHIP
412 };
413 if (SCARG(uap, name) >= EMUL_IP_MULTICAST_IF &&
414 SCARG(uap, name) <= EMUL_IP_DROP_MEMBERSHIP) {
415 SCARG(uap, name) =
416 ipoptxlat[SCARG(uap, name) - EMUL_IP_MULTICAST_IF];
417 }
418 }
419 if (SCARG(uap, valsize) > MLEN) {
420 error = EINVAL;
421 goto out;
422 }
423 if (SCARG(uap, val)) {
424 m = m_get(M_WAIT, MT_SOOPTS);
425 error = copyin(SCARG(uap, val), mtod(m, caddr_t),
426 (u_int)SCARG(uap, valsize));
427 if (error) {
428 (void) m_free(m);
429 goto out;
430 }
431 m->m_len = SCARG(uap, valsize);
432 }
433 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
434 SCARG(uap, name), m);
435 out:
436 FILE_UNUSE(fp, p);
437 return (error);
438 }
439
440 #define ULTRIX__SYS_NMLN 32
441
442 struct ultrix_utsname {
443 char sysname[ULTRIX__SYS_NMLN];
444 char nodename[ULTRIX__SYS_NMLN];
445 char release[ULTRIX__SYS_NMLN];
446 char version[ULTRIX__SYS_NMLN];
447 char machine[ULTRIX__SYS_NMLN];
448 };
449
450 int
451 ultrix_sys_uname(l, v, retval)
452 struct lwp *l;
453 void *v;
454 register_t *retval;
455 {
456 struct ultrix_sys_uname_args *uap = v;
457 struct ultrix_utsname sut;
458 const char *cp;
459 char *dp, *ep;
460
461 memset(&sut, 0, sizeof(sut));
462
463 strncpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
464 strncpy(sut.nodename, hostname, sizeof(sut.nodename) - 1);
465 strncpy(sut.release, osrelease, sizeof(sut.release) - 1);
466 dp = sut.version;
467 ep = &sut.version[sizeof(sut.version) - 1];
468 for (cp = version; *cp && *cp != '('; cp++)
469 ;
470 for (cp++; *cp && *cp != ')' && dp < ep; cp++)
471 *dp++ = *cp;
472 for (; *cp && *cp != '#'; cp++)
473 ;
474 for (; *cp && *cp != ':' && dp < ep; cp++)
475 *dp++ = *cp;
476 *dp = '\0';
477 strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
478
479 return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
480 sizeof(struct ultrix_utsname));
481 }
482
483 int
484 ultrix_sys_setpgrp(l, v, retval)
485 struct lwp *l;
486 void *v;
487 register_t *retval;
488 {
489 struct ultrix_sys_setpgrp_args *uap = v;
490 struct proc *p = l->l_proc;
491
492 /*
493 * difference to our setpgid call is to include backwards
494 * compatibility to pre-setsid() binaries. Do setsid()
495 * instead of setpgid() in those cases where the process
496 * tries to create a new session the old way.
497 */
498 if (!SCARG(uap, pgid) &&
499 (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
500 return sys_setsid(l, uap, retval);
501 else
502 return sys_setpgid(l, uap, retval);
503 }
504
505 #if defined (NFSSERVER)
506 int
507 ultrix_sys_nfssvc(l, v, retval)
508 struct lwp *l;
509 void *v;
510 register_t *retval;
511 {
512
513 #if 0 /* XXX */
514 struct ultrix_sys_nfssvc_args *uap = v;
515 struct emul *e = p->p_emul;
516 struct sys_nfssvc_args outuap;
517 struct sockaddr sa;
518 int error;
519 caddr_t sg = stackgap_init(p, 0);
520
521 memset(&outuap, 0, sizeof outuap);
522 SCARG(&outuap, fd) = SCARG(uap, fd);
523 SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof sa);
524 SCARG(&outuap, msklen) = sizeof sa;
525 SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof sa);
526 SCARG(&outuap, mtchlen) = sizeof sa;
527
528 memset(&sa, 0, sizeof sa);
529 if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
530 return (error);
531 if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
532 return (error);
533
534 return nfssvc(l, &outuap, retval);
535 #else
536 return (ENOSYS);
537 #endif
538 }
539 #endif /* NFSSERVER */
540
541 struct ultrix_ustat {
542 daddr_t f_tfree; /* total free */
543 ino_t f_tinode; /* total inodes free */
544 char f_fname[6]; /* filsys name */
545 char f_fpack[6]; /* filsys pack name */
546 };
547
548 int
549 ultrix_sys_ustat(l, v, retval)
550 struct lwp *l;
551 void *v;
552 register_t *retval;
553 {
554 struct ultrix_sys_ustat_args *uap = v;
555 struct ultrix_ustat us;
556 int error;
557
558 memset(&us, 0, sizeof us);
559
560 /*
561 * XXX: should set f_tfree and f_tinode at least
562 * How do we translate dev -> fstat? (and then to ultrix_ustat)
563 */
564
565 if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
566 return (error);
567 return 0;
568 }
569
570 int
571 ultrix_sys_quotactl(l, v, retval)
572 struct lwp *l;
573 void *v;
574 register_t *retval;
575 {
576
577 #ifdef notyet
578 struct ultrix_sys_quotactl_args *uap = v;
579 #endif
580
581 return EINVAL;
582 }
583
584 int
585 ultrix_sys_vhangup(l, v, retval)
586 struct lwp *l;
587 void *v;
588 register_t *retval;
589 {
590
591 return 0;
592 }
593
594
595 /*
596 * RISC Ultrix cache control syscalls
597 */
598 #ifdef __mips
599 int
600 ultrix_sys_cacheflush(l, v, retval)
601 struct lwp *l;
602 void *v;
603 register_t *retval;
604 {
605 struct ultrix_sys_cacheflush_args /* {
606 syscallarg(void *) addr;
607 syscallarg(int) nbytes;
608 syscallarg(int) flag;
609 } */ *uap = v;
610 struct proc *p = l->l_proc;
611 vaddr_t va = (vaddr_t)SCARG(uap, addr);
612 int nbytes = SCARG(uap, nbytes);
613 int whichcache = SCARG(uap, whichcache);
614
615 return (mips_user_cacheflush(p, va, nbytes, whichcache));
616 }
617
618
619 int
620 ultrix_sys_cachectl(l, v, retval)
621 struct lwp *l;
622 void *v;
623 register_t *retval;
624 {
625 struct ultrix_sys_cachectl_args /* {
626 syscallarg(void *) addr;
627 syscallarg(int) nbytes;
628 syscallarg(int) cacheop;
629 } */ *uap = v;
630 struct proc *p = l->l_proc;
631 vaddr_t va = (vaddr_t)SCARG(uap, addr);
632 int nbytes = SCARG(uap, nbytes);
633 int cacheop = SCARG(uap, cacheop);
634
635 return mips_user_cachectl(p, va, nbytes, cacheop);
636 }
637
638 #endif /* __mips */
639
640
641 int
642 ultrix_sys_exportfs(l, v, retval)
643 struct lwp *l;
644 void *v;
645 register_t *retval;
646 {
647 #ifdef notyet
648 struct ultrix_sys_exportfs_args *uap = v;
649 #endif
650
651 /*
652 * XXX: should perhaps translate into a mount(2)
653 * with MOUNT_EXPORT?
654 */
655 return 0;
656 }
657
658 int
659 ultrix_sys_sigpending(l, v, retval)
660 struct lwp *l;
661 void *v;
662 register_t *retval;
663 {
664 struct ultrix_sys_sigpending_args *uap = v;
665 sigset_t ss;
666 int mask;
667
668 sigpending1(l->l_proc, &ss);
669 mask = ss.__bits[0];
670
671 return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
672 }
673
674 int
675 ultrix_sys_sigreturn(l, v, retval)
676 struct lwp *l;
677 void *v;
678 register_t *retval;
679 {
680 struct ultrix_sys_sigreturn_args *uap = v;
681
682 /* struct sigcontext13 is close enough to Ultrix */
683
684 return (compat_13_sys_sigreturn(l, uap, retval));
685 }
686
687 int
688 ultrix_sys_sigcleanup(l, v, retval)
689 struct lwp *l;
690 void *v;
691 register_t *retval;
692 {
693 struct ultrix_sys_sigcleanup_args *uap = v;
694
695 /* struct sigcontext13 is close enough to Ultrix */
696
697 return (compat_13_sys_sigreturn(l, uap, retval));
698 }
699
700 int
701 ultrix_sys_sigsuspend(l, v, retval)
702 struct lwp *l;
703 void *v;
704 register_t *retval;
705 {
706 struct ultrix_sys_sigsuspend_args *uap = v;
707 int mask = SCARG(uap, mask);
708 sigset_t ss;
709
710 ss.__bits[0] = mask;
711 ss.__bits[1] = 0;
712 ss.__bits[2] = 0;
713 ss.__bits[3] = 0;
714
715 return (sigsuspend1(l->l_proc, &ss));
716 }
717
718 #define ULTRIX_SV_ONSTACK 0x0001 /* take signal on signal stack */
719 #define ULTRIX_SV_INTERRUPT 0x0002 /* do not restart system on signal return */
720 #define ULTRIX_SV_OLDSIG 0x1000 /* Emulate old signal() for POSIX */
721
722 int
723 ultrix_sys_sigvec(l, v, retval)
724 struct lwp *l;
725 void *v;
726 register_t *retval;
727 {
728 struct ultrix_sys_sigvec_args *uap = v;
729 struct sigvec nsv, osv;
730 struct sigaction nsa, osa;
731 int error;
732
733 if (SCARG(uap, nsv)) {
734 error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
735 if (error)
736 return (error);
737 nsa.sa_handler = nsv.sv_handler;
738 #if 0 /* documentation */
739 /* ONSTACK is identical */
740 nsa.sa_flags = nsv.sv_flags & ULTRIX_SV_ONSTACK;
741 if ((nsv.sv_flags & ULTRIX_SV_OLDSIG)
742 /* old signal() - always restart */
743 || (!(nsv.sv_flags & ULTRIX_SV_INTERRUPT))
744 /* inverted meaning (same bit) */
745 )
746 nsa.sa_flags |= SA_RESTART;
747 #else /* optimized - assuming ULTRIX_SV_OLDSIG=>!ULTRIX_SV_INTERRUPT */
748 nsa.sa_flags = nsv.sv_flags & ~ULTRIX_SV_OLDSIG;
749 nsa.sa_flags ^= SA_RESTART;
750 #endif
751 native_sigset13_to_sigset(&nsv.sv_mask, &nsa.sa_mask);
752 }
753 error = sigaction1(l->l_proc, SCARG(uap, signum),
754 SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
755 NULL, 0);
756 if (error)
757 return (error);
758 if (SCARG(uap, osv)) {
759 osv.sv_handler = osa.sa_handler;
760 osv.sv_flags = osa.sa_flags ^ SA_RESTART;
761 osv.sv_flags &= (ULTRIX_SV_ONSTACK | ULTRIX_SV_INTERRUPT);
762 native_sigset_to_sigset13(&osa.sa_mask, &osv.sv_mask);
763 error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
764 if (error)
765 return (error);
766 }
767 return (0);
768 }
769
770 int
771 ultrix_sys_shmsys(l, v, retval)
772 struct lwp *l;
773 void *v;
774 register_t *retval;
775 {
776
777 #ifdef SYSVSHM
778
779 /* Ultrix SVSHM weirndess: */
780 struct ultrix_sys_shmsys_args *uap = v;
781 struct sys_shmat_args shmat_args;
782 struct compat_14_sys_shmctl_args shmctl_args;
783 struct sys_shmdt_args shmdt_args;
784 struct sys_shmget_args shmget_args;
785
786
787 switch (SCARG(uap, shmop)) {
788 case 0: /* Ultrix shmat() */
789 SCARG(&shmat_args, shmid) = SCARG(uap, a2);
790 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
791 SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
792 return (sys_shmat(l, &shmat_args, retval));
793
794 case 1: /* Ultrix shmctl() */
795 SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
796 SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
797 SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
798 return (compat_14_sys_shmctl(l, &shmctl_args, retval));
799
800 case 2: /* Ultrix shmdt() */
801 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2);
802 return (sys_shmdt(l, &shmdt_args, retval));
803
804 case 3: /* Ultrix shmget() */
805 SCARG(&shmget_args, key) = SCARG(uap, a2);
806 SCARG(&shmget_args, size) = SCARG(uap, a3);
807 SCARG(&shmget_args, shmflg) = SCARG(uap, a4)
808 & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
809 return (sys_shmget(l, &shmget_args, retval));
810
811 default:
812 return (EINVAL);
813 }
814 #else
815 return (EOPNOTSUPP);
816 #endif /* SYSVSHM */
817 }
818
819 static int
820 ultrix_to_bsd_flock(ufl, fl)
821 struct ultrix_flock *ufl;
822 struct flock *fl;
823 {
824
825 fl->l_start = ufl->l_start;
826 fl->l_len = ufl->l_len;
827 fl->l_pid = ufl->l_pid;
828 fl->l_whence = ufl->l_whence;
829
830 switch (ufl->l_type) {
831 case ULTRIX_F_RDLCK:
832 fl->l_type = F_RDLCK;
833 break;
834 case ULTRIX_F_WRLCK:
835 fl->l_type = F_WRLCK;
836 break;
837 case ULTRIX_F_UNLCK:
838 fl->l_type = F_UNLCK;
839 break;
840 default:
841 return (EINVAL);
842 }
843
844 return (0);
845 }
846
847 static void
848 bsd_to_ultrix_flock(fl, ufl)
849 struct flock *fl;
850 struct ultrix_flock *ufl;
851 {
852
853 ufl->l_start = fl->l_start;
854 ufl->l_len = fl->l_len;
855 ufl->l_pid = fl->l_pid;
856 ufl->l_whence = fl->l_whence;
857
858 switch (fl->l_type) {
859 case F_RDLCK:
860 ufl->l_type = ULTRIX_F_RDLCK;
861 break;
862 case F_WRLCK:
863 ufl->l_type = ULTRIX_F_WRLCK;
864 break;
865 case F_UNLCK:
866 ufl->l_type = ULTRIX_F_UNLCK;
867 break;
868 }
869 }
870
871 int
872 ultrix_sys_fcntl(l, v, retval)
873 struct lwp *l;
874 void *v;
875 register_t *retval;
876 {
877 struct ultrix_sys_fcntl_args *uap = v;
878 struct proc *p = l->l_proc;
879 int error;
880 struct ultrix_flock ufl;
881 struct flock fl, *flp;
882 caddr_t sg;
883 struct sys_fcntl_args *args, fca;
884
885 switch (SCARG(uap, cmd)) {
886 case F_GETLK:
887 case F_SETLK:
888 case F_SETLKW:
889 error = copyin(SCARG(uap, arg), &ufl, sizeof(ufl));
890 if (error)
891 return (error);
892 error = ultrix_to_bsd_flock(&ufl, &fl);
893 if (error)
894 return (error);
895 sg = stackgap_init(p, 0);
896 flp = (struct flock *)stackgap_alloc(p, &sg, sizeof(*flp));
897 error = copyout(&fl, flp, sizeof(*flp));
898 if (error)
899 return (error);
900
901 SCARG(&fca, fd) = SCARG(uap, fd);
902 SCARG(&fca, cmd) = SCARG(uap, cmd);
903 SCARG(&fca, arg) = flp;
904 args = &fca;
905 break;
906 default:
907 args = v;
908 break;
909 }
910
911 error = sys_fcntl(l, args, retval);
912 if (error)
913 return (error);
914
915 switch (SCARG(uap, cmd)) {
916 case F_GETLK:
917 error = copyin(flp, &fl, sizeof(fl));
918 if (error)
919 return (error);
920 bsd_to_ultrix_flock(&fl, &ufl);
921 error = copyout(&ufl, SCARG(uap, arg), sizeof(ufl));
922 break;
923 }
924
925 return (error);
926 }
927