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