ultrix_misc.c revision 1.68.2.9 1 /* $NetBSD: ultrix_misc.c,v 1.68.2.9 2002/09/17 21:19: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.9 2002/09/17 21:19: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/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_MAXSYSCALL,
171 #endif
172 ultrix_sysent,
173 ultrix_syscallnames,
174 sendsig,
175 trapsignal,
176 ultrix_sigcode,
177 ultrix_esigcode,
178 setregs,
179 NULL,
180 NULL,
181 NULL,
182 #ifdef __HAVE_SYSCALL_INTERN
183 syscall_intern,
184 #else
185 syscall,
186 #endif
187 };
188
189 #define GSI_PROG_ENV 1
190
191 int
192 ultrix_sys_getsysinfo(l, v, retval)
193 struct lwp *l;
194 void *v;
195 register_t *retval;
196 {
197 struct ultrix_sys_getsysinfo_args *uap = v;
198 static short progenv = 0;
199
200 switch (SCARG(uap, op)) {
201 /* operations implemented: */
202 case GSI_PROG_ENV:
203 if (SCARG(uap, nbytes) < sizeof(short))
204 return EINVAL;
205 *retval = 1;
206 return (copyout(&progenv, SCARG(uap, buffer), sizeof(short)));
207 default:
208 *retval = 0; /* info unavail */
209 return 0;
210 }
211 }
212
213 int
214 ultrix_sys_setsysinfo(l, v, retval)
215 struct lwp *l;
216 void *v;
217 register_t *retval;
218 {
219
220 #ifdef notyet
221 struct ultrix_sys_setsysinfo_args *uap = v;
222 #endif
223
224 *retval = 0;
225 return 0;
226 }
227
228 int
229 ultrix_sys_waitpid(l, v, retval)
230 struct lwp *l;
231 void *v;
232 register_t *retval;
233 {
234 struct ultrix_sys_waitpid_args *uap = v;
235 struct sys_wait4_args ua;
236
237 SCARG(&ua, pid) = SCARG(uap, pid);
238 SCARG(&ua, status) = SCARG(uap, status);
239 SCARG(&ua, options) = SCARG(uap, options);
240 SCARG(&ua, rusage) = 0;
241
242 return (sys_wait4(l, &ua, retval));
243 }
244
245 int
246 ultrix_sys_wait3(l, v, retval)
247 struct lwp *l;
248 void *v;
249 register_t *retval;
250 {
251 struct ultrix_sys_wait3_args *uap = v;
252 struct sys_wait4_args ua;
253
254 SCARG(&ua, pid) = -1;
255 SCARG(&ua, status) = SCARG(uap, status);
256 SCARG(&ua, options) = SCARG(uap, options);
257 SCARG(&ua, rusage) = SCARG(uap, rusage);
258
259 return (sys_wait4(l, &ua, retval));
260 }
261
262 /*
263 * Ultrix binaries pass in FD_MAX as the first arg to select().
264 * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select()
265 * can handle.
266 * Since we can't have more than the (native) FD_MAX descriptors open,
267 * limit nfds to at most FD_MAX.
268 */
269 int
270 ultrix_sys_select(l, v, retval)
271 struct lwp *l;
272 void *v;
273 register_t *retval;
274 {
275 struct sys_select_args *uap = v;
276 struct timeval atv;
277 int error;
278
279 /* Limit number of FDs selected on to the native maximum */
280
281 if (SCARG(uap, nd) > FD_SETSIZE)
282 SCARG(uap, nd) = FD_SETSIZE;
283
284 /* Check for negative timeval */
285 if (SCARG(uap, tv)) {
286 error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv,
287 sizeof(atv));
288 if (error)
289 goto done;
290 #ifdef DEBUG
291 /* Ultrix clients sometimes give negative timeouts? */
292 if (atv.tv_sec < 0 || atv.tv_usec < 0)
293 printf("ultrix select( %ld, %ld): negative timeout\n",
294 atv.tv_sec, atv.tv_usec);
295 #endif
296
297 }
298 error = sys_select(l, (void*) uap, retval);
299 if (error == EINVAL)
300 printf("ultrix select: bad args?\n");
301
302 done:
303 return error;
304 }
305
306 #if defined(NFS)
307 int
308 async_daemon(l, v, retval)
309 struct lwp *l;
310 void *v;
311 register_t *retval;
312 {
313 struct sys_nfssvc_args ouap;
314
315 SCARG(&ouap, flag) = NFSSVC_BIOD;
316 SCARG(&ouap, argp) = NULL;
317
318 return (sys_nfssvc(l, &ouap, retval));
319 }
320 #endif /* NFS */
321
322
323 #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
324
325 int
326 ultrix_sys_mmap(l, v, retval)
327 struct lwp *l;
328 void *v;
329 register_t *retval;
330 {
331 struct ultrix_sys_mmap_args *uap = v;
332 struct proc *p = l->l_proc;
333 struct sys_mmap_args ouap;
334 struct filedesc *fdp;
335 struct file *fp;
336 struct vnode *vp;
337
338 /*
339 * Verify the arguments.
340 */
341 if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
342 return (EINVAL); /* XXX still needed? */
343
344 if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
345 return (EINVAL);
346
347 SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
348 SCARG(&ouap, addr) = SCARG(uap, addr);
349
350 if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
351 SCARG(&ouap, addr) != 0 &&
352 SCARG(&ouap, addr) < (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ))
353 SCARG(&ouap, addr) = (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ);
354
355 SCARG(&ouap, len) = SCARG(uap, len);
356 SCARG(&ouap, prot) = SCARG(uap, prot);
357 SCARG(&ouap, fd) = SCARG(uap, fd);
358 SCARG(&ouap, pos) = SCARG(uap, pos);
359
360 /*
361 * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
362 */
363 fdp = p->p_fd;
364 if ((fp = fd_getfile(fdp, SCARG(&ouap, fd))) != NULL && /*XXX*/
365 fp->f_type == DTYPE_VNODE && /*XXX*/
366 (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
367 vp->v_rdev == zerodev) { /*XXX*/
368 SCARG(&ouap, flags) |= MAP_ANON;
369 SCARG(&ouap, fd) = -1;
370 }
371
372 return (sys_mmap(l, &ouap, retval));
373 }
374
375 int
376 ultrix_sys_setsockopt(l, v, retval)
377 struct lwp *l;
378 void *v;
379 register_t *retval;
380 {
381 struct ultrix_sys_setsockopt_args *uap = v;
382 struct proc *p = l->l_proc;
383 struct file *fp;
384 struct mbuf *m = NULL;
385 int error;
386
387 /* getsock() will use the descriptor for us */
388 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
389 return (error);
390 #define SO_DONTLINGER (~SO_LINGER)
391 if (SCARG(uap, name) == SO_DONTLINGER) {
392 m = m_get(M_WAIT, MT_SOOPTS);
393 mtod(m, struct linger *)->l_onoff = 0;
394 m->m_len = sizeof(struct linger);
395 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
396 SO_LINGER, m);
397 }
398 if (SCARG(uap, level) == IPPROTO_IP) {
399 #define EMUL_IP_MULTICAST_IF 2
400 #define EMUL_IP_MULTICAST_TTL 3
401 #define EMUL_IP_MULTICAST_LOOP 4
402 #define EMUL_IP_ADD_MEMBERSHIP 5
403 #define EMUL_IP_DROP_MEMBERSHIP 6
404 static int ipoptxlat[] = {
405 IP_MULTICAST_IF,
406 IP_MULTICAST_TTL,
407 IP_MULTICAST_LOOP,
408 IP_ADD_MEMBERSHIP,
409 IP_DROP_MEMBERSHIP
410 };
411 if (SCARG(uap, name) >= EMUL_IP_MULTICAST_IF &&
412 SCARG(uap, name) <= EMUL_IP_DROP_MEMBERSHIP) {
413 SCARG(uap, name) =
414 ipoptxlat[SCARG(uap, name) - EMUL_IP_MULTICAST_IF];
415 }
416 }
417 if (SCARG(uap, valsize) > MLEN) {
418 error = EINVAL;
419 goto out;
420 }
421 if (SCARG(uap, val)) {
422 m = m_get(M_WAIT, MT_SOOPTS);
423 error = copyin(SCARG(uap, val), mtod(m, caddr_t),
424 (u_int)SCARG(uap, valsize));
425 if (error) {
426 (void) m_free(m);
427 goto out;
428 }
429 m->m_len = SCARG(uap, valsize);
430 }
431 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
432 SCARG(uap, name), m);
433 out:
434 FILE_UNUSE(fp, p);
435 return (error);
436 }
437
438 #define ULTRIX__SYS_NMLN 32
439
440 struct ultrix_utsname {
441 char sysname[ULTRIX__SYS_NMLN];
442 char nodename[ULTRIX__SYS_NMLN];
443 char release[ULTRIX__SYS_NMLN];
444 char version[ULTRIX__SYS_NMLN];
445 char machine[ULTRIX__SYS_NMLN];
446 };
447
448 int
449 ultrix_sys_uname(l, v, retval)
450 struct lwp *l;
451 void *v;
452 register_t *retval;
453 {
454 struct ultrix_sys_uname_args *uap = v;
455 struct ultrix_utsname sut;
456 const char *cp;
457 char *dp, *ep;
458
459 memset(&sut, 0, sizeof(sut));
460
461 strncpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
462 strncpy(sut.nodename, hostname, sizeof(sut.nodename) - 1);
463 strncpy(sut.release, osrelease, sizeof(sut.release) - 1);
464 dp = sut.version;
465 ep = &sut.version[sizeof(sut.version) - 1];
466 for (cp = version; *cp && *cp != '('; cp++)
467 ;
468 for (cp++; *cp && *cp != ')' && dp < ep; cp++)
469 *dp++ = *cp;
470 for (; *cp && *cp != '#'; cp++)
471 ;
472 for (; *cp && *cp != ':' && dp < ep; cp++)
473 *dp++ = *cp;
474 *dp = '\0';
475 strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
476
477 return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
478 sizeof(struct ultrix_utsname));
479 }
480
481 int
482 ultrix_sys_setpgrp(l, v, retval)
483 struct lwp *l;
484 void *v;
485 register_t *retval;
486 {
487 struct ultrix_sys_setpgrp_args *uap = v;
488 struct proc *p = l->l_proc;
489
490 /*
491 * difference to our setpgid call is to include backwards
492 * compatibility to pre-setsid() binaries. Do setsid()
493 * instead of setpgid() in those cases where the process
494 * tries to create a new session the old way.
495 */
496 if (!SCARG(uap, pgid) &&
497 (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
498 return sys_setsid(l, uap, retval);
499 else
500 return sys_setpgid(l, uap, retval);
501 }
502
503 #if defined (NFSSERVER)
504 int
505 ultrix_sys_nfssvc(l, v, retval)
506 struct lwp *l;
507 void *v;
508 register_t *retval;
509 {
510
511 #if 0 /* XXX */
512 struct ultrix_sys_nfssvc_args *uap = v;
513 struct emul *e = p->p_emul;
514 struct sys_nfssvc_args outuap;
515 struct sockaddr sa;
516 int error;
517 caddr_t sg = stackgap_init(p, 0);
518
519 memset(&outuap, 0, sizeof outuap);
520 SCARG(&outuap, fd) = SCARG(uap, fd);
521 SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof sa);
522 SCARG(&outuap, msklen) = sizeof sa;
523 SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof sa);
524 SCARG(&outuap, mtchlen) = sizeof sa;
525
526 memset(&sa, 0, sizeof sa);
527 if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
528 return (error);
529 if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
530 return (error);
531
532 return nfssvc(l, &outuap, retval);
533 #else
534 return (ENOSYS);
535 #endif
536 }
537 #endif /* NFSSERVER */
538
539 struct ultrix_ustat {
540 daddr_t f_tfree; /* total free */
541 ino_t f_tinode; /* total inodes free */
542 char f_fname[6]; /* filsys name */
543 char f_fpack[6]; /* filsys pack name */
544 };
545
546 int
547 ultrix_sys_ustat(l, v, retval)
548 struct lwp *l;
549 void *v;
550 register_t *retval;
551 {
552 struct ultrix_sys_ustat_args *uap = v;
553 struct ultrix_ustat us;
554 int error;
555
556 memset(&us, 0, sizeof us);
557
558 /*
559 * XXX: should set f_tfree and f_tinode at least
560 * How do we translate dev -> fstat? (and then to ultrix_ustat)
561 */
562
563 if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
564 return (error);
565 return 0;
566 }
567
568 int
569 ultrix_sys_quotactl(l, v, retval)
570 struct lwp *l;
571 void *v;
572 register_t *retval;
573 {
574
575 #ifdef notyet
576 struct ultrix_sys_quotactl_args *uap = v;
577 #endif
578
579 return EINVAL;
580 }
581
582 int
583 ultrix_sys_vhangup(l, v, retval)
584 struct lwp *l;
585 void *v;
586 register_t *retval;
587 {
588
589 return 0;
590 }
591
592
593 /*
594 * RISC Ultrix cache control syscalls
595 */
596 #ifdef __mips
597 int
598 ultrix_sys_cacheflush(l, v, retval)
599 struct lwp *l;
600 void *v;
601 register_t *retval;
602 {
603 struct ultrix_sys_cacheflush_args /* {
604 syscallarg(void *) addr;
605 syscallarg(int) nbytes;
606 syscallarg(int) flag;
607 } */ *uap = v;
608 struct proc *p = l->l_proc;
609 vaddr_t va = (vaddr_t)SCARG(uap, addr);
610 int nbytes = SCARG(uap, nbytes);
611 int whichcache = SCARG(uap, whichcache);
612
613 return (mips_user_cacheflush(p, va, nbytes, whichcache));
614 }
615
616
617 int
618 ultrix_sys_cachectl(l, v, retval)
619 struct lwp *l;
620 void *v;
621 register_t *retval;
622 {
623 struct ultrix_sys_cachectl_args /* {
624 syscallarg(void *) addr;
625 syscallarg(int) nbytes;
626 syscallarg(int) cacheop;
627 } */ *uap = v;
628 struct proc *p = l->l_proc;
629 vaddr_t va = (vaddr_t)SCARG(uap, addr);
630 int nbytes = SCARG(uap, nbytes);
631 int cacheop = SCARG(uap, cacheop);
632
633 return mips_user_cachectl(p, va, nbytes, cacheop);
634 }
635
636 #endif /* __mips */
637
638
639 int
640 ultrix_sys_exportfs(l, v, retval)
641 struct lwp *l;
642 void *v;
643 register_t *retval;
644 {
645 #ifdef notyet
646 struct ultrix_sys_exportfs_args *uap = v;
647 #endif
648
649 /*
650 * XXX: should perhaps translate into a mount(2)
651 * with MOUNT_EXPORT?
652 */
653 return 0;
654 }
655
656 int
657 ultrix_sys_sigpending(l, v, retval)
658 struct lwp *l;
659 void *v;
660 register_t *retval;
661 {
662 struct ultrix_sys_sigpending_args *uap = v;
663 sigset_t ss;
664 int mask;
665
666 sigpending1(l->l_proc, &ss);
667 mask = ss.__bits[0];
668
669 return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
670 }
671
672 int
673 ultrix_sys_sigreturn(l, v, retval)
674 struct lwp *l;
675 void *v;
676 register_t *retval;
677 {
678 struct ultrix_sys_sigreturn_args *uap = v;
679
680 /* struct sigcontext13 is close enough to Ultrix */
681
682 return (compat_13_sys_sigreturn(l, uap, retval));
683 }
684
685 int
686 ultrix_sys_sigcleanup(l, v, retval)
687 struct lwp *l;
688 void *v;
689 register_t *retval;
690 {
691 struct ultrix_sys_sigcleanup_args *uap = v;
692
693 /* struct sigcontext13 is close enough to Ultrix */
694
695 return (compat_13_sys_sigreturn(l, uap, retval));
696 }
697
698 int
699 ultrix_sys_sigsuspend(l, v, retval)
700 struct lwp *l;
701 void *v;
702 register_t *retval;
703 {
704 struct ultrix_sys_sigsuspend_args *uap = v;
705 int mask = SCARG(uap, mask);
706 sigset_t ss;
707
708 ss.__bits[0] = mask;
709 ss.__bits[1] = 0;
710 ss.__bits[2] = 0;
711 ss.__bits[3] = 0;
712
713 return (sigsuspend1(l->l_proc, &ss));
714 }
715
716 #define ULTRIX_SV_ONSTACK 0x0001 /* take signal on signal stack */
717 #define ULTRIX_SV_INTERRUPT 0x0002 /* do not restart system on signal return */
718 #define ULTRIX_SV_OLDSIG 0x1000 /* Emulate old signal() for POSIX */
719
720 int
721 ultrix_sys_sigvec(l, v, retval)
722 struct lwp *l;
723 void *v;
724 register_t *retval;
725 {
726 struct ultrix_sys_sigvec_args *uap = v;
727 struct sigvec nsv, osv;
728 struct sigaction nsa, osa;
729 int error;
730
731 if (SCARG(uap, nsv)) {
732 error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
733 if (error)
734 return (error);
735 nsa.sa_handler = nsv.sv_handler;
736 #if 0 /* documentation */
737 /* ONSTACK is identical */
738 nsa.sa_flags = nsv.sv_flags & ULTRIX_SV_ONSTACK;
739 if ((nsv.sv_flags & ULTRIX_SV_OLDSIG)
740 /* old signal() - always restart */
741 || (!(nsv.sv_flags & ULTRIX_SV_INTERRUPT))
742 /* inverted meaning (same bit) */
743 )
744 nsa.sa_flags |= SA_RESTART;
745 #else /* optimized - assuming ULTRIX_SV_OLDSIG=>!ULTRIX_SV_INTERRUPT */
746 nsa.sa_flags = nsv.sv_flags & ~ULTRIX_SV_OLDSIG;
747 nsa.sa_flags ^= SA_RESTART;
748 #endif
749 native_sigset13_to_sigset(&nsv.sv_mask, &nsa.sa_mask);
750 }
751 error = sigaction1(l->l_proc, SCARG(uap, signum),
752 SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
753 NULL, 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