ultrix_misc.c revision 1.68.2.6 1 /* $NetBSD: ultrix_misc.c,v 1.68.2.6 2002/05/29 21:33:08 nathanw 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.68.2.6 2002/05/29 21:33:08 nathanw 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/lwp.h>
109 #include <sys/file.h>
110 #include <sys/filedesc.h>
111 #include <sys/kernel.h>
112 #include <sys/exec.h>
113 #include <sys/malloc.h>
114 #include <sys/mbuf.h>
115 #include <sys/mman.h>
116 #include <sys/mount.h>
117 #include <sys/resource.h>
118 #include <sys/resourcevar.h>
119 #include <sys/signal.h>
120 #include <sys/signalvar.h>
121 #include <sys/socket.h>
122 #include <sys/vnode.h>
123 #include <sys/uio.h>
124 #include <sys/wait.h>
125 #include <sys/utsname.h>
126 #include <sys/unistd.h>
127 #include <sys/ipc.h>
128
129 #include <sys/sa.h>
130 #include <sys/syscallargs.h>
131
132 #include <compat/ultrix/ultrix_syscall.h>
133 #include <compat/ultrix/ultrix_syscallargs.h>
134 #include <compat/common/compat_util.h>
135
136 #include <netinet/in.h>
137
138 #include <miscfs/specfs/specdev.h>
139
140 #include <nfs/rpcv2.h>
141 #include <nfs/nfsproto.h>
142 #include <nfs/nfs.h>
143
144 #include <sys/conf.h> /* iszerodev() */
145 #include <sys/socketvar.h> /* sosetopt() */
146
147 #include <compat/ultrix/ultrix_flock.h>
148
149 #ifdef __mips
150 #include <mips/cachectl.h>
151 #endif
152
153 static int ultrix_to_bsd_flock __P((struct ultrix_flock *, struct flock *));
154 static void bsd_to_ultrix_flock __P((struct flock *, struct ultrix_flock *));
155
156 extern struct sysent ultrix_sysent[];
157 extern const char * const ultrix_syscallnames[];
158 extern char ultrix_sigcode[], ultrix_esigcode[];
159 #ifdef __HAVE_SYSCALL_INTERN
160 void syscall_intern(struct proc *);
161 #else
162 void syscall __P((void));
163 #endif
164
165 const struct emul emul_ultrix = {
166 "ultrix",
167 "/emul/ultrix",
168 #ifndef __HAVE_MINIMAL_EMUL
169 0,
170 NULL,
171 ULTRIX_SYS_syscall,
172 ULTRIX_SYS_MAXSYSCALL,
173 #endif
174 ultrix_sysent,
175 ultrix_syscallnames,
176 sendsig,
177 trapsignal,
178 ultrix_sigcode,
179 ultrix_esigcode,
180 setregs,
181 NULL,
182 NULL,
183 NULL,
184 #ifdef __HAVE_SYSCALL_INTERN
185 syscall_intern,
186 #else
187 syscall,
188 #endif
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 iszerodev(vp->v_rdev)) { /*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 if (error)
756 return (error);
757 if (SCARG(uap, osv)) {
758 osv.sv_handler = osa.sa_handler;
759 osv.sv_flags = osa.sa_flags ^ SA_RESTART;
760 osv.sv_flags &= (ULTRIX_SV_ONSTACK | ULTRIX_SV_INTERRUPT);
761 native_sigset_to_sigset13(&osa.sa_mask, &osv.sv_mask);
762 error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
763 if (error)
764 return (error);
765 }
766 return (0);
767 }
768
769 int
770 ultrix_sys_shmsys(l, v, retval)
771 struct lwp *l;
772 void *v;
773 register_t *retval;
774 {
775
776 #ifdef SYSVSHM
777
778 /* Ultrix SVSHM weirndess: */
779 struct ultrix_sys_shmsys_args *uap = v;
780 struct sys_shmat_args shmat_args;
781 struct compat_14_sys_shmctl_args shmctl_args;
782 struct sys_shmdt_args shmdt_args;
783 struct sys_shmget_args shmget_args;
784
785
786 switch (SCARG(uap, shmop)) {
787 case 0: /* Ultrix shmat() */
788 SCARG(&shmat_args, shmid) = SCARG(uap, a2);
789 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
790 SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
791 return (sys_shmat(l, &shmat_args, retval));
792
793 case 1: /* Ultrix shmctl() */
794 SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
795 SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
796 SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
797 return (compat_14_sys_shmctl(l, &shmctl_args, retval));
798
799 case 2: /* Ultrix shmdt() */
800 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2);
801 return (sys_shmdt(l, &shmdt_args, retval));
802
803 case 3: /* Ultrix shmget() */
804 SCARG(&shmget_args, key) = SCARG(uap, a2);
805 SCARG(&shmget_args, size) = SCARG(uap, a3);
806 SCARG(&shmget_args, shmflg) = SCARG(uap, a4)
807 & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
808 return (sys_shmget(l, &shmget_args, retval));
809
810 default:
811 return (EINVAL);
812 }
813 #else
814 return (EOPNOTSUPP);
815 #endif /* SYSVSHM */
816 }
817
818 static int
819 ultrix_to_bsd_flock(ufl, fl)
820 struct ultrix_flock *ufl;
821 struct flock *fl;
822 {
823
824 fl->l_start = ufl->l_start;
825 fl->l_len = ufl->l_len;
826 fl->l_pid = ufl->l_pid;
827 fl->l_whence = ufl->l_whence;
828
829 switch (ufl->l_type) {
830 case ULTRIX_F_RDLCK:
831 fl->l_type = F_RDLCK;
832 break;
833 case ULTRIX_F_WRLCK:
834 fl->l_type = F_WRLCK;
835 break;
836 case ULTRIX_F_UNLCK:
837 fl->l_type = F_UNLCK;
838 break;
839 default:
840 return (EINVAL);
841 }
842
843 return (0);
844 }
845
846 static void
847 bsd_to_ultrix_flock(fl, ufl)
848 struct flock *fl;
849 struct ultrix_flock *ufl;
850 {
851
852 ufl->l_start = fl->l_start;
853 ufl->l_len = fl->l_len;
854 ufl->l_pid = fl->l_pid;
855 ufl->l_whence = fl->l_whence;
856
857 switch (fl->l_type) {
858 case F_RDLCK:
859 ufl->l_type = ULTRIX_F_RDLCK;
860 break;
861 case F_WRLCK:
862 ufl->l_type = ULTRIX_F_WRLCK;
863 break;
864 case F_UNLCK:
865 ufl->l_type = ULTRIX_F_UNLCK;
866 break;
867 }
868 }
869
870 int
871 ultrix_sys_fcntl(l, v, retval)
872 struct lwp *l;
873 void *v;
874 register_t *retval;
875 {
876 struct ultrix_sys_fcntl_args *uap = v;
877 struct proc *p = l->l_proc;
878 int error;
879 struct ultrix_flock ufl;
880 struct flock fl, *flp;
881 caddr_t sg;
882 struct sys_fcntl_args *args, fca;
883
884 switch (SCARG(uap, cmd)) {
885 case F_GETLK:
886 case F_SETLK:
887 case F_SETLKW:
888 error = copyin(SCARG(uap, arg), &ufl, sizeof(ufl));
889 if (error)
890 return (error);
891 error = ultrix_to_bsd_flock(&ufl, &fl);
892 if (error)
893 return (error);
894 sg = stackgap_init(p, 0);
895 flp = (struct flock *)stackgap_alloc(p, &sg, sizeof(*flp));
896 error = copyout(&fl, flp, sizeof(*flp));
897 if (error)
898 return (error);
899
900 SCARG(&fca, fd) = SCARG(uap, fd);
901 SCARG(&fca, cmd) = SCARG(uap, cmd);
902 SCARG(&fca, arg) = flp;
903 args = &fca;
904 break;
905 default:
906 args = v;
907 break;
908 }
909
910 error = sys_fcntl(l, args, retval);
911 if (error)
912 return (error);
913
914 switch (SCARG(uap, cmd)) {
915 case F_GETLK:
916 error = copyin(flp, &fl, sizeof(fl));
917 if (error)
918 return (error);
919 bsd_to_ultrix_flock(&fl, &ufl);
920 error = copyout(&ufl, SCARG(uap, arg), sizeof(ufl));
921 break;
922 }
923
924 return (error);
925 }
926