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