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