ultrix_misc.c revision 1.77 1 /* $NetBSD: ultrix_misc.c,v 1.77 2002/07/04 23:32:14 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.77 2002/07/04 23:32:14 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/syscallargs.h>
129
130 #include <compat/ultrix/ultrix_syscall.h>
131 #include <compat/ultrix/ultrix_syscallargs.h>
132 #include <compat/common/compat_util.h>
133
134 #include <netinet/in.h>
135
136 #include <miscfs/specfs/specdev.h>
137
138 #include <nfs/rpcv2.h>
139 #include <nfs/nfsproto.h>
140 #include <nfs/nfs.h>
141
142 #include <sys/conf.h> /* iszerodev() */
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_MAXSYSCALL,
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 };
188
189 #define GSI_PROG_ENV 1
190
191 int
192 ultrix_sys_getsysinfo(p, v, retval)
193 struct proc *p;
194 void *v;
195 register_t *retval;
196 {
197 struct ultrix_sys_getsysinfo_args *uap = v;
198 static short progenv = 0;
199
200 switch (SCARG(uap, op)) {
201 /* operations implemented: */
202 case GSI_PROG_ENV:
203 if (SCARG(uap, nbytes) < sizeof(short))
204 return EINVAL;
205 *retval = 1;
206 return (copyout(&progenv, SCARG(uap, buffer), sizeof(short)));
207 default:
208 *retval = 0; /* info unavail */
209 return 0;
210 }
211 }
212
213 int
214 ultrix_sys_setsysinfo(p, v, retval)
215 struct proc *p;
216 void *v;
217 register_t *retval;
218 {
219
220 #ifdef notyet
221 struct ultrix_sys_setsysinfo_args *uap = v;
222 #endif
223
224 *retval = 0;
225 return 0;
226 }
227
228 int
229 ultrix_sys_waitpid(p, v, retval)
230 struct proc *p;
231 void *v;
232 register_t *retval;
233 {
234 struct ultrix_sys_waitpid_args *uap = v;
235 struct sys_wait4_args ua;
236
237 SCARG(&ua, pid) = SCARG(uap, pid);
238 SCARG(&ua, status) = SCARG(uap, status);
239 SCARG(&ua, options) = SCARG(uap, options);
240 SCARG(&ua, rusage) = 0;
241
242 return (sys_wait4(p, &ua, retval));
243 }
244
245 int
246 ultrix_sys_wait3(p, v, retval)
247 struct proc *p;
248 void *v;
249 register_t *retval;
250 {
251 struct ultrix_sys_wait3_args *uap = v;
252 struct sys_wait4_args ua;
253
254 SCARG(&ua, pid) = -1;
255 SCARG(&ua, status) = SCARG(uap, status);
256 SCARG(&ua, options) = SCARG(uap, options);
257 SCARG(&ua, rusage) = SCARG(uap, rusage);
258
259 return (sys_wait4(p, &ua, retval));
260 }
261
262 /*
263 * Ultrix binaries pass in FD_MAX as the first arg to select().
264 * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select()
265 * can handle.
266 * Since we can't have more than the (native) FD_MAX descriptors open,
267 * limit nfds to at most FD_MAX.
268 */
269 int
270 ultrix_sys_select(p, v, retval)
271 struct proc *p;
272 void *v;
273 register_t *retval;
274 {
275 struct sys_select_args *uap = v;
276 struct timeval atv;
277 int error;
278
279 /* Limit number of FDs selected on to the native maximum */
280
281 if (SCARG(uap, nd) > FD_SETSIZE)
282 SCARG(uap, nd) = FD_SETSIZE;
283
284 /* Check for negative timeval */
285 if (SCARG(uap, tv)) {
286 error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv,
287 sizeof(atv));
288 if (error)
289 goto done;
290 #ifdef DEBUG
291 /* Ultrix clients sometimes give negative timeouts? */
292 if (atv.tv_sec < 0 || atv.tv_usec < 0)
293 printf("ultrix select( %ld, %ld): negative timeout\n",
294 atv.tv_sec, atv.tv_usec);
295 #endif
296
297 }
298 error = sys_select(p, (void*) uap, retval);
299 if (error == EINVAL)
300 printf("ultrix select: bad args?\n");
301
302 done:
303 return error;
304 }
305
306 #if defined(NFS)
307 int
308 async_daemon(p, v, retval)
309 struct proc *p;
310 void *v;
311 register_t *retval;
312 {
313 struct sys_nfssvc_args ouap;
314
315 SCARG(&ouap, flag) = NFSSVC_BIOD;
316 SCARG(&ouap, argp) = NULL;
317
318 return (sys_nfssvc(p, &ouap, retval));
319 }
320 #endif /* NFS */
321
322
323 #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
324
325 int
326 ultrix_sys_mmap(p, v, retval)
327 struct proc *p;
328 void *v;
329 register_t *retval;
330 {
331 struct ultrix_sys_mmap_args *uap = v;
332 struct sys_mmap_args ouap;
333 struct filedesc *fdp;
334 struct file *fp;
335 struct vnode *vp;
336
337 /*
338 * Verify the arguments.
339 */
340 if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
341 return (EINVAL); /* XXX still needed? */
342
343 if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
344 return (EINVAL);
345
346 SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
347 SCARG(&ouap, addr) = SCARG(uap, addr);
348
349 if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
350 SCARG(&ouap, addr) != 0 &&
351 SCARG(&ouap, addr) < (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ))
352 SCARG(&ouap, addr) = (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ);
353
354 SCARG(&ouap, len) = SCARG(uap, len);
355 SCARG(&ouap, prot) = SCARG(uap, prot);
356 SCARG(&ouap, fd) = SCARG(uap, fd);
357 SCARG(&ouap, pos) = SCARG(uap, pos);
358
359 /*
360 * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
361 */
362 fdp = p->p_fd;
363 if ((fp = fd_getfile(fdp, SCARG(&ouap, fd))) != NULL && /*XXX*/
364 fp->f_type == DTYPE_VNODE && /*XXX*/
365 (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
366 iszerodev(vp->v_rdev)) { /*XXX*/
367 SCARG(&ouap, flags) |= MAP_ANON;
368 SCARG(&ouap, fd) = -1;
369 }
370
371 return (sys_mmap(p, &ouap, retval));
372 }
373
374 int
375 ultrix_sys_setsockopt(p, v, retval)
376 struct proc *p;
377 void *v;
378 register_t *retval;
379 {
380 struct ultrix_sys_setsockopt_args *uap = v;
381 struct file *fp;
382 struct mbuf *m = NULL;
383 int error;
384
385 /* getsock() will use the descriptor for us */
386 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
387 return (error);
388 #define SO_DONTLINGER (~SO_LINGER)
389 if (SCARG(uap, name) == SO_DONTLINGER) {
390 m = m_get(M_WAIT, MT_SOOPTS);
391 mtod(m, struct linger *)->l_onoff = 0;
392 m->m_len = sizeof(struct linger);
393 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
394 SO_LINGER, m);
395 }
396 if (SCARG(uap, level) == IPPROTO_IP) {
397 #define EMUL_IP_MULTICAST_IF 2
398 #define EMUL_IP_MULTICAST_TTL 3
399 #define EMUL_IP_MULTICAST_LOOP 4
400 #define EMUL_IP_ADD_MEMBERSHIP 5
401 #define EMUL_IP_DROP_MEMBERSHIP 6
402 static int ipoptxlat[] = {
403 IP_MULTICAST_IF,
404 IP_MULTICAST_TTL,
405 IP_MULTICAST_LOOP,
406 IP_ADD_MEMBERSHIP,
407 IP_DROP_MEMBERSHIP
408 };
409 if (SCARG(uap, name) >= EMUL_IP_MULTICAST_IF &&
410 SCARG(uap, name) <= EMUL_IP_DROP_MEMBERSHIP) {
411 SCARG(uap, name) =
412 ipoptxlat[SCARG(uap, name) - EMUL_IP_MULTICAST_IF];
413 }
414 }
415 if (SCARG(uap, valsize) > MLEN) {
416 error = EINVAL;
417 goto out;
418 }
419 if (SCARG(uap, val)) {
420 m = m_get(M_WAIT, MT_SOOPTS);
421 error = copyin(SCARG(uap, val), mtod(m, caddr_t),
422 (u_int)SCARG(uap, valsize));
423 if (error) {
424 (void) m_free(m);
425 goto out;
426 }
427 m->m_len = SCARG(uap, valsize);
428 }
429 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
430 SCARG(uap, name), m);
431 out:
432 FILE_UNUSE(fp, p);
433 return (error);
434 }
435
436 #define ULTRIX__SYS_NMLN 32
437
438 struct ultrix_utsname {
439 char sysname[ULTRIX__SYS_NMLN];
440 char nodename[ULTRIX__SYS_NMLN];
441 char release[ULTRIX__SYS_NMLN];
442 char version[ULTRIX__SYS_NMLN];
443 char machine[ULTRIX__SYS_NMLN];
444 };
445
446 int
447 ultrix_sys_uname(p, v, retval)
448 struct proc *p;
449 void *v;
450 register_t *retval;
451 {
452 struct ultrix_sys_uname_args *uap = v;
453 struct ultrix_utsname sut;
454 const char *cp;
455 char *dp, *ep;
456
457 memset(&sut, 0, sizeof(sut));
458
459 strncpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
460 strncpy(sut.nodename, hostname, sizeof(sut.nodename) - 1);
461 strncpy(sut.release, osrelease, sizeof(sut.release) - 1);
462 dp = sut.version;
463 ep = &sut.version[sizeof(sut.version) - 1];
464 for (cp = version; *cp && *cp != '('; cp++)
465 ;
466 for (cp++; *cp && *cp != ')' && dp < ep; cp++)
467 *dp++ = *cp;
468 for (; *cp && *cp != '#'; cp++)
469 ;
470 for (; *cp && *cp != ':' && dp < ep; cp++)
471 *dp++ = *cp;
472 *dp = '\0';
473 strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
474
475 return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
476 sizeof(struct ultrix_utsname));
477 }
478
479 int
480 ultrix_sys_setpgrp(p, v, retval)
481 struct proc *p;
482 void *v;
483 register_t *retval;
484 {
485 struct ultrix_sys_setpgrp_args *uap = v;
486
487 /*
488 * difference to our setpgid call is to include backwards
489 * compatibility to pre-setsid() binaries. Do setsid()
490 * instead of setpgid() in those cases where the process
491 * tries to create a new session the old way.
492 */
493 if (!SCARG(uap, pgid) &&
494 (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
495 return sys_setsid(p, uap, retval);
496 else
497 return sys_setpgid(p, uap, retval);
498 }
499
500 #if defined (NFSSERVER)
501 int
502 ultrix_sys_nfssvc(p, v, retval)
503 struct proc *p;
504 void *v;
505 register_t *retval;
506 {
507
508 #if 0 /* XXX */
509 struct ultrix_sys_nfssvc_args *uap = v;
510 struct emul *e = p->p_emul;
511 struct sys_nfssvc_args outuap;
512 struct sockaddr sa;
513 int error;
514 caddr_t sg = stackgap_init(p, 0);
515
516 memset(&outuap, 0, sizeof outuap);
517 SCARG(&outuap, fd) = SCARG(uap, fd);
518 SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof sa);
519 SCARG(&outuap, msklen) = sizeof sa;
520 SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof sa);
521 SCARG(&outuap, mtchlen) = sizeof sa;
522
523 memset(&sa, 0, sizeof sa);
524 if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
525 return (error);
526 if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
527 return (error);
528
529 return nfssvc(p, &outuap, retval);
530 #else
531 return (ENOSYS);
532 #endif
533 }
534 #endif /* NFSSERVER */
535
536 struct ultrix_ustat {
537 daddr_t f_tfree; /* total free */
538 ino_t f_tinode; /* total inodes free */
539 char f_fname[6]; /* filsys name */
540 char f_fpack[6]; /* filsys pack name */
541 };
542
543 int
544 ultrix_sys_ustat(p, v, retval)
545 struct proc *p;
546 void *v;
547 register_t *retval;
548 {
549 struct ultrix_sys_ustat_args *uap = v;
550 struct ultrix_ustat us;
551 int error;
552
553 memset(&us, 0, sizeof us);
554
555 /*
556 * XXX: should set f_tfree and f_tinode at least
557 * How do we translate dev -> fstat? (and then to ultrix_ustat)
558 */
559
560 if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
561 return (error);
562 return 0;
563 }
564
565 int
566 ultrix_sys_quotactl(p, v, retval)
567 struct proc *p;
568 void *v;
569 register_t *retval;
570 {
571
572 #ifdef notyet
573 struct ultrix_sys_quotactl_args *uap = v;
574 #endif
575
576 return EINVAL;
577 }
578
579 int
580 ultrix_sys_vhangup(p, v, retval)
581 struct proc *p;
582 void *v;
583 register_t *retval;
584 {
585
586 return 0;
587 }
588
589
590 /*
591 * RISC Ultrix cache control syscalls
592 */
593 #ifdef __mips
594 int
595 ultrix_sys_cacheflush(p, v, retval)
596 struct proc *p;
597 void *v;
598 register_t *retval;
599 {
600 struct ultrix_sys_cacheflush_args /* {
601 syscallarg(void *) addr;
602 syscallarg(int) nbytes;
603 syscallarg(int) flag;
604 } */ *uap = v;
605 vaddr_t va = (vaddr_t)SCARG(uap, addr);
606 int nbytes = SCARG(uap, nbytes);
607 int whichcache = SCARG(uap, whichcache);
608
609 return (mips_user_cacheflush(p, va, nbytes, whichcache));
610 }
611
612
613 int
614 ultrix_sys_cachectl(p, v, retval)
615 struct proc *p;
616 void *v;
617 register_t *retval;
618 {
619 struct ultrix_sys_cachectl_args /* {
620 syscallarg(void *) addr;
621 syscallarg(int) nbytes;
622 syscallarg(int) cacheop;
623 } */ *uap = v;
624 vaddr_t va = (vaddr_t)SCARG(uap, addr);
625 int nbytes = SCARG(uap, nbytes);
626 int cacheop = SCARG(uap, cacheop);
627
628 return mips_user_cachectl(p, va, nbytes, cacheop);
629 }
630
631 #endif /* __mips */
632
633
634 int
635 ultrix_sys_exportfs(p, v, retval)
636 struct proc *p;
637 void *v;
638 register_t *retval;
639 {
640 #ifdef notyet
641 struct ultrix_sys_exportfs_args *uap = v;
642 #endif
643
644 /*
645 * XXX: should perhaps translate into a mount(2)
646 * with MOUNT_EXPORT?
647 */
648 return 0;
649 }
650
651 int
652 ultrix_sys_sigpending(p, v, retval)
653 struct proc *p;
654 void *v;
655 register_t *retval;
656 {
657 struct ultrix_sys_sigpending_args *uap = v;
658 sigset_t ss;
659 int mask;
660
661 sigpending1(p, &ss);
662 mask = ss.__bits[0];
663
664 return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
665 }
666
667 int
668 ultrix_sys_sigreturn(p, v, retval)
669 struct proc *p;
670 void *v;
671 register_t *retval;
672 {
673 struct ultrix_sys_sigreturn_args *uap = v;
674
675 /* struct sigcontext13 is close enough to Ultrix */
676
677 return (compat_13_sys_sigreturn(p, uap, retval));
678 }
679
680 int
681 ultrix_sys_sigcleanup(p, v, retval)
682 struct proc *p;
683 void *v;
684 register_t *retval;
685 {
686 struct ultrix_sys_sigcleanup_args *uap = v;
687
688 /* struct sigcontext13 is close enough to Ultrix */
689
690 return (compat_13_sys_sigreturn(p, uap, retval));
691 }
692
693 int
694 ultrix_sys_sigsuspend(p, v, retval)
695 struct proc *p;
696 void *v;
697 register_t *retval;
698 {
699 struct ultrix_sys_sigsuspend_args *uap = v;
700 int mask = SCARG(uap, mask);
701 sigset_t ss;
702
703 ss.__bits[0] = mask;
704 ss.__bits[1] = 0;
705 ss.__bits[2] = 0;
706 ss.__bits[3] = 0;
707
708 return (sigsuspend1(p, &ss));
709 }
710
711 #define ULTRIX_SV_ONSTACK 0x0001 /* take signal on signal stack */
712 #define ULTRIX_SV_INTERRUPT 0x0002 /* do not restart system on signal return */
713 #define ULTRIX_SV_OLDSIG 0x1000 /* Emulate old signal() for POSIX */
714
715 int
716 ultrix_sys_sigvec(p, v, retval)
717 struct proc *p;
718 void *v;
719 register_t *retval;
720 {
721 struct ultrix_sys_sigvec_args *uap = v;
722 struct sigvec nsv, osv;
723 struct sigaction nsa, osa;
724 int error;
725
726 if (SCARG(uap, nsv)) {
727 error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
728 if (error)
729 return (error);
730 nsa.sa_handler = nsv.sv_handler;
731 #if 0 /* documentation */
732 /* ONSTACK is identical */
733 nsa.sa_flags = nsv.sv_flags & ULTRIX_SV_ONSTACK;
734 if ((nsv.sv_flags & ULTRIX_SV_OLDSIG)
735 /* old signal() - always restart */
736 || (!(nsv.sv_flags & ULTRIX_SV_INTERRUPT))
737 /* inverted meaning (same bit) */
738 )
739 nsa.sa_flags |= SA_RESTART;
740 #else /* optimized - assuming ULTRIX_SV_OLDSIG=>!ULTRIX_SV_INTERRUPT */
741 nsa.sa_flags = nsv.sv_flags & ~ULTRIX_SV_OLDSIG;
742 nsa.sa_flags ^= SA_RESTART;
743 #endif
744 native_sigset13_to_sigset(&nsv.sv_mask, &nsa.sa_mask);
745 }
746 error = sigaction1(p, SCARG(uap, signum),
747 SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
748 NULL, 0);
749 if (error)
750 return (error);
751 if (SCARG(uap, osv)) {
752 osv.sv_handler = osa.sa_handler;
753 osv.sv_flags = osa.sa_flags ^ SA_RESTART;
754 osv.sv_flags &= (ULTRIX_SV_ONSTACK | ULTRIX_SV_INTERRUPT);
755 native_sigset_to_sigset13(&osa.sa_mask, &osv.sv_mask);
756 error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
757 if (error)
758 return (error);
759 }
760 return (0);
761 }
762
763 int
764 ultrix_sys_shmsys(p, v, retval)
765 struct proc *p;
766 void *v;
767 register_t *retval;
768 {
769
770 #ifdef SYSVSHM
771
772 /* Ultrix SVSHM weirndess: */
773 struct ultrix_sys_shmsys_args *uap = v;
774 struct sys_shmat_args shmat_args;
775 struct compat_14_sys_shmctl_args shmctl_args;
776 struct sys_shmdt_args shmdt_args;
777 struct sys_shmget_args shmget_args;
778
779
780 switch (SCARG(uap, shmop)) {
781 case 0: /* Ultrix shmat() */
782 SCARG(&shmat_args, shmid) = SCARG(uap, a2);
783 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
784 SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
785 return (sys_shmat(p, &shmat_args, retval));
786
787 case 1: /* Ultrix shmctl() */
788 SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
789 SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
790 SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
791 return (compat_14_sys_shmctl(p, &shmctl_args, retval));
792
793 case 2: /* Ultrix shmdt() */
794 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2);
795 return (sys_shmdt(p, &shmdt_args, retval));
796
797 case 3: /* Ultrix shmget() */
798 SCARG(&shmget_args, key) = SCARG(uap, a2);
799 SCARG(&shmget_args, size) = SCARG(uap, a3);
800 SCARG(&shmget_args, shmflg) = SCARG(uap, a4)
801 & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
802 return (sys_shmget(p, &shmget_args, retval));
803
804 default:
805 return (EINVAL);
806 }
807 #else
808 return (EOPNOTSUPP);
809 #endif /* SYSVSHM */
810 }
811
812 static int
813 ultrix_to_bsd_flock(ufl, fl)
814 struct ultrix_flock *ufl;
815 struct flock *fl;
816 {
817
818 fl->l_start = ufl->l_start;
819 fl->l_len = ufl->l_len;
820 fl->l_pid = ufl->l_pid;
821 fl->l_whence = ufl->l_whence;
822
823 switch (ufl->l_type) {
824 case ULTRIX_F_RDLCK:
825 fl->l_type = F_RDLCK;
826 break;
827 case ULTRIX_F_WRLCK:
828 fl->l_type = F_WRLCK;
829 break;
830 case ULTRIX_F_UNLCK:
831 fl->l_type = F_UNLCK;
832 break;
833 default:
834 return (EINVAL);
835 }
836
837 return (0);
838 }
839
840 static void
841 bsd_to_ultrix_flock(fl, ufl)
842 struct flock *fl;
843 struct ultrix_flock *ufl;
844 {
845
846 ufl->l_start = fl->l_start;
847 ufl->l_len = fl->l_len;
848 ufl->l_pid = fl->l_pid;
849 ufl->l_whence = fl->l_whence;
850
851 switch (fl->l_type) {
852 case F_RDLCK:
853 ufl->l_type = ULTRIX_F_RDLCK;
854 break;
855 case F_WRLCK:
856 ufl->l_type = ULTRIX_F_WRLCK;
857 break;
858 case F_UNLCK:
859 ufl->l_type = ULTRIX_F_UNLCK;
860 break;
861 }
862 }
863
864 int
865 ultrix_sys_fcntl(p, v, retval)
866 struct proc *p;
867 void *v;
868 register_t *retval;
869 {
870 struct ultrix_sys_fcntl_args *uap = v;
871 int error;
872 struct ultrix_flock ufl;
873 struct flock fl, *flp;
874 caddr_t sg;
875 struct sys_fcntl_args *args, fca;
876
877 switch (SCARG(uap, cmd)) {
878 case F_GETLK:
879 case F_SETLK:
880 case F_SETLKW:
881 error = copyin(SCARG(uap, arg), &ufl, sizeof(ufl));
882 if (error)
883 return (error);
884 error = ultrix_to_bsd_flock(&ufl, &fl);
885 if (error)
886 return (error);
887 sg = stackgap_init(p, 0);
888 flp = (struct flock *)stackgap_alloc(p, &sg, sizeof(*flp));
889 error = copyout(&fl, flp, sizeof(*flp));
890 if (error)
891 return (error);
892
893 SCARG(&fca, fd) = SCARG(uap, fd);
894 SCARG(&fca, cmd) = SCARG(uap, cmd);
895 SCARG(&fca, arg) = flp;
896 args = &fca;
897 break;
898 default:
899 args = v;
900 break;
901 }
902
903 error = sys_fcntl(p, args, retval);
904 if (error)
905 return (error);
906
907 switch (SCARG(uap, cmd)) {
908 case F_GETLK:
909 error = copyin(flp, &fl, sizeof(fl));
910 if (error)
911 return (error);
912 bsd_to_ultrix_flock(&fl, &ufl);
913 error = copyout(&ufl, SCARG(uap, arg), sizeof(ufl));
914 break;
915 }
916
917 return (error);
918 }
919