ultrix_misc.c revision 1.79 1 /* $NetBSD: ultrix_misc.c,v 1.79 2002/09/21 21:15:01 manu 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.79 2002/09/21 21:15:01 manu 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/syscallargs.h>
129
130 #include <compat/ultrix/ultrix_syscall.h>
131 #include <compat/ultrix/ultrix_syscallargs.h>
132 #include <compat/common/compat_util.h>
133
134 #include <netinet/in.h>
135
136 #include <miscfs/specfs/specdev.h>
137
138 #include <nfs/rpcv2.h>
139 #include <nfs/nfsproto.h>
140 #include <nfs/nfs.h>
141
142 #include <sys/socketvar.h> /* sosetopt() */
143
144 #include <compat/ultrix/ultrix_flock.h>
145
146 #ifdef __mips
147 #include <mips/cachectl.h>
148 #endif
149
150 static int ultrix_to_bsd_flock __P((struct ultrix_flock *, struct flock *));
151 static void bsd_to_ultrix_flock __P((struct flock *, struct ultrix_flock *));
152
153 extern struct sysent ultrix_sysent[];
154 extern const char * const ultrix_syscallnames[];
155 extern char ultrix_sigcode[], ultrix_esigcode[];
156 #ifdef __HAVE_SYSCALL_INTERN
157 void syscall_intern(struct proc *);
158 #else
159 void syscall __P((void));
160 #endif
161
162 const struct emul emul_ultrix = {
163 "ultrix",
164 "/emul/ultrix",
165 #ifndef __HAVE_MINIMAL_EMUL
166 0,
167 NULL,
168 ULTRIX_SYS_syscall,
169 ULTRIX_SYS_MAXSYSCALL,
170 #endif
171 ultrix_sysent,
172 ultrix_syscallnames,
173 sendsig,
174 trapsignal,
175 ultrix_sigcode,
176 ultrix_esigcode,
177 setregs,
178 NULL,
179 NULL,
180 NULL,
181 #ifdef __HAVE_SYSCALL_INTERN
182 syscall_intern,
183 #else
184 syscall,
185 #endif
186 NULL,
187 NULL,
188 };
189
190 #define GSI_PROG_ENV 1
191
192 int
193 ultrix_sys_getsysinfo(p, v, retval)
194 struct proc *p;
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(p, v, retval)
216 struct proc *p;
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(p, v, retval)
231 struct proc *p;
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(p, &ua, retval));
244 }
245
246 int
247 ultrix_sys_wait3(p, v, retval)
248 struct proc *p;
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(p, &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(p, v, retval)
272 struct proc *p;
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(p, (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(p, v, retval)
310 struct proc *p;
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(p, &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(p, v, retval)
328 struct proc *p;
329 void *v;
330 register_t *retval;
331 {
332 struct ultrix_sys_mmap_args *uap = v;
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(p, &ouap, retval));
373 }
374
375 int
376 ultrix_sys_setsockopt(p, v, retval)
377 struct proc *p;
378 void *v;
379 register_t *retval;
380 {
381 struct ultrix_sys_setsockopt_args *uap = v;
382 struct file *fp;
383 struct mbuf *m = NULL;
384 int error;
385
386 /* getsock() will use the descriptor for us */
387 if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
388 return (error);
389 #define SO_DONTLINGER (~SO_LINGER)
390 if (SCARG(uap, name) == SO_DONTLINGER) {
391 m = m_get(M_WAIT, MT_SOOPTS);
392 mtod(m, struct linger *)->l_onoff = 0;
393 m->m_len = sizeof(struct linger);
394 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
395 SO_LINGER, m);
396 }
397 if (SCARG(uap, level) == IPPROTO_IP) {
398 #define EMUL_IP_MULTICAST_IF 2
399 #define EMUL_IP_MULTICAST_TTL 3
400 #define EMUL_IP_MULTICAST_LOOP 4
401 #define EMUL_IP_ADD_MEMBERSHIP 5
402 #define EMUL_IP_DROP_MEMBERSHIP 6
403 static int ipoptxlat[] = {
404 IP_MULTICAST_IF,
405 IP_MULTICAST_TTL,
406 IP_MULTICAST_LOOP,
407 IP_ADD_MEMBERSHIP,
408 IP_DROP_MEMBERSHIP
409 };
410 if (SCARG(uap, name) >= EMUL_IP_MULTICAST_IF &&
411 SCARG(uap, name) <= EMUL_IP_DROP_MEMBERSHIP) {
412 SCARG(uap, name) =
413 ipoptxlat[SCARG(uap, name) - EMUL_IP_MULTICAST_IF];
414 }
415 }
416 if (SCARG(uap, valsize) > MLEN) {
417 error = EINVAL;
418 goto out;
419 }
420 if (SCARG(uap, val)) {
421 m = m_get(M_WAIT, MT_SOOPTS);
422 error = copyin(SCARG(uap, val), mtod(m, caddr_t),
423 (u_int)SCARG(uap, valsize));
424 if (error) {
425 (void) m_free(m);
426 goto out;
427 }
428 m->m_len = SCARG(uap, valsize);
429 }
430 error = sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
431 SCARG(uap, name), m);
432 out:
433 FILE_UNUSE(fp, p);
434 return (error);
435 }
436
437 #define ULTRIX__SYS_NMLN 32
438
439 struct ultrix_utsname {
440 char sysname[ULTRIX__SYS_NMLN];
441 char nodename[ULTRIX__SYS_NMLN];
442 char release[ULTRIX__SYS_NMLN];
443 char version[ULTRIX__SYS_NMLN];
444 char machine[ULTRIX__SYS_NMLN];
445 };
446
447 int
448 ultrix_sys_uname(p, v, retval)
449 struct proc *p;
450 void *v;
451 register_t *retval;
452 {
453 struct ultrix_sys_uname_args *uap = v;
454 struct ultrix_utsname sut;
455 const char *cp;
456 char *dp, *ep;
457
458 memset(&sut, 0, sizeof(sut));
459
460 strncpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
461 strncpy(sut.nodename, hostname, sizeof(sut.nodename) - 1);
462 strncpy(sut.release, osrelease, sizeof(sut.release) - 1);
463 dp = sut.version;
464 ep = &sut.version[sizeof(sut.version) - 1];
465 for (cp = version; *cp && *cp != '('; cp++)
466 ;
467 for (cp++; *cp && *cp != ')' && dp < ep; cp++)
468 *dp++ = *cp;
469 for (; *cp && *cp != '#'; cp++)
470 ;
471 for (; *cp && *cp != ':' && dp < ep; cp++)
472 *dp++ = *cp;
473 *dp = '\0';
474 strncpy(sut.machine, machine, sizeof(sut.machine) - 1);
475
476 return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
477 sizeof(struct ultrix_utsname));
478 }
479
480 int
481 ultrix_sys_setpgrp(p, v, retval)
482 struct proc *p;
483 void *v;
484 register_t *retval;
485 {
486 struct ultrix_sys_setpgrp_args *uap = v;
487
488 /*
489 * difference to our setpgid call is to include backwards
490 * compatibility to pre-setsid() binaries. Do setsid()
491 * instead of setpgid() in those cases where the process
492 * tries to create a new session the old way.
493 */
494 if (!SCARG(uap, pgid) &&
495 (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
496 return sys_setsid(p, uap, retval);
497 else
498 return sys_setpgid(p, uap, retval);
499 }
500
501 #if defined (NFSSERVER)
502 int
503 ultrix_sys_nfssvc(p, v, retval)
504 struct proc *p;
505 void *v;
506 register_t *retval;
507 {
508
509 #if 0 /* XXX */
510 struct ultrix_sys_nfssvc_args *uap = v;
511 struct emul *e = p->p_emul;
512 struct sys_nfssvc_args outuap;
513 struct sockaddr sa;
514 int error;
515 caddr_t sg = stackgap_init(p, 0);
516
517 memset(&outuap, 0, sizeof outuap);
518 SCARG(&outuap, fd) = SCARG(uap, fd);
519 SCARG(&outuap, mskval) = stackgap_alloc(p, &sg, sizeof sa);
520 SCARG(&outuap, msklen) = sizeof sa;
521 SCARG(&outuap, mtchval) = stackgap_alloc(p, &sg, sizeof sa);
522 SCARG(&outuap, mtchlen) = sizeof sa;
523
524 memset(&sa, 0, sizeof sa);
525 if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
526 return (error);
527 if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
528 return (error);
529
530 return nfssvc(p, &outuap, retval);
531 #else
532 return (ENOSYS);
533 #endif
534 }
535 #endif /* NFSSERVER */
536
537 struct ultrix_ustat {
538 daddr_t f_tfree; /* total free */
539 ino_t f_tinode; /* total inodes free */
540 char f_fname[6]; /* filsys name */
541 char f_fpack[6]; /* filsys pack name */
542 };
543
544 int
545 ultrix_sys_ustat(p, v, retval)
546 struct proc *p;
547 void *v;
548 register_t *retval;
549 {
550 struct ultrix_sys_ustat_args *uap = v;
551 struct ultrix_ustat us;
552 int error;
553
554 memset(&us, 0, sizeof us);
555
556 /*
557 * XXX: should set f_tfree and f_tinode at least
558 * How do we translate dev -> fstat? (and then to ultrix_ustat)
559 */
560
561 if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
562 return (error);
563 return 0;
564 }
565
566 int
567 ultrix_sys_quotactl(p, v, retval)
568 struct proc *p;
569 void *v;
570 register_t *retval;
571 {
572
573 #ifdef notyet
574 struct ultrix_sys_quotactl_args *uap = v;
575 #endif
576
577 return EINVAL;
578 }
579
580 int
581 ultrix_sys_vhangup(p, v, retval)
582 struct proc *p;
583 void *v;
584 register_t *retval;
585 {
586
587 return 0;
588 }
589
590
591 /*
592 * RISC Ultrix cache control syscalls
593 */
594 #ifdef __mips
595 int
596 ultrix_sys_cacheflush(p, v, retval)
597 struct proc *p;
598 void *v;
599 register_t *retval;
600 {
601 struct ultrix_sys_cacheflush_args /* {
602 syscallarg(void *) addr;
603 syscallarg(int) nbytes;
604 syscallarg(int) flag;
605 } */ *uap = v;
606 vaddr_t va = (vaddr_t)SCARG(uap, addr);
607 int nbytes = SCARG(uap, nbytes);
608 int whichcache = SCARG(uap, whichcache);
609
610 return (mips_user_cacheflush(p, va, nbytes, whichcache));
611 }
612
613
614 int
615 ultrix_sys_cachectl(p, v, retval)
616 struct proc *p;
617 void *v;
618 register_t *retval;
619 {
620 struct ultrix_sys_cachectl_args /* {
621 syscallarg(void *) addr;
622 syscallarg(int) nbytes;
623 syscallarg(int) cacheop;
624 } */ *uap = v;
625 vaddr_t va = (vaddr_t)SCARG(uap, addr);
626 int nbytes = SCARG(uap, nbytes);
627 int cacheop = SCARG(uap, cacheop);
628
629 return mips_user_cachectl(p, va, nbytes, cacheop);
630 }
631
632 #endif /* __mips */
633
634
635 int
636 ultrix_sys_exportfs(p, v, retval)
637 struct proc *p;
638 void *v;
639 register_t *retval;
640 {
641 #ifdef notyet
642 struct ultrix_sys_exportfs_args *uap = v;
643 #endif
644
645 /*
646 * XXX: should perhaps translate into a mount(2)
647 * with MOUNT_EXPORT?
648 */
649 return 0;
650 }
651
652 int
653 ultrix_sys_sigpending(p, v, retval)
654 struct proc *p;
655 void *v;
656 register_t *retval;
657 {
658 struct ultrix_sys_sigpending_args *uap = v;
659 sigset_t ss;
660 int mask;
661
662 sigpending1(p, &ss);
663 mask = ss.__bits[0];
664
665 return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
666 }
667
668 int
669 ultrix_sys_sigreturn(p, v, retval)
670 struct proc *p;
671 void *v;
672 register_t *retval;
673 {
674 struct ultrix_sys_sigreturn_args *uap = v;
675
676 /* struct sigcontext13 is close enough to Ultrix */
677
678 return (compat_13_sys_sigreturn(p, uap, retval));
679 }
680
681 int
682 ultrix_sys_sigcleanup(p, v, retval)
683 struct proc *p;
684 void *v;
685 register_t *retval;
686 {
687 struct ultrix_sys_sigcleanup_args *uap = v;
688
689 /* struct sigcontext13 is close enough to Ultrix */
690
691 return (compat_13_sys_sigreturn(p, uap, retval));
692 }
693
694 int
695 ultrix_sys_sigsuspend(p, v, retval)
696 struct proc *p;
697 void *v;
698 register_t *retval;
699 {
700 struct ultrix_sys_sigsuspend_args *uap = v;
701 int mask = SCARG(uap, mask);
702 sigset_t ss;
703
704 ss.__bits[0] = mask;
705 ss.__bits[1] = 0;
706 ss.__bits[2] = 0;
707 ss.__bits[3] = 0;
708
709 return (sigsuspend1(p, &ss));
710 }
711
712 #define ULTRIX_SV_ONSTACK 0x0001 /* take signal on signal stack */
713 #define ULTRIX_SV_INTERRUPT 0x0002 /* do not restart system on signal return */
714 #define ULTRIX_SV_OLDSIG 0x1000 /* Emulate old signal() for POSIX */
715
716 int
717 ultrix_sys_sigvec(p, v, retval)
718 struct proc *p;
719 void *v;
720 register_t *retval;
721 {
722 struct ultrix_sys_sigvec_args *uap = v;
723 struct sigvec nsv, osv;
724 struct sigaction nsa, osa;
725 int error;
726
727 if (SCARG(uap, nsv)) {
728 error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
729 if (error)
730 return (error);
731 nsa.sa_handler = nsv.sv_handler;
732 #if 0 /* documentation */
733 /* ONSTACK is identical */
734 nsa.sa_flags = nsv.sv_flags & ULTRIX_SV_ONSTACK;
735 if ((nsv.sv_flags & ULTRIX_SV_OLDSIG)
736 /* old signal() - always restart */
737 || (!(nsv.sv_flags & ULTRIX_SV_INTERRUPT))
738 /* inverted meaning (same bit) */
739 )
740 nsa.sa_flags |= SA_RESTART;
741 #else /* optimized - assuming ULTRIX_SV_OLDSIG=>!ULTRIX_SV_INTERRUPT */
742 nsa.sa_flags = nsv.sv_flags & ~ULTRIX_SV_OLDSIG;
743 nsa.sa_flags ^= SA_RESTART;
744 #endif
745 native_sigset13_to_sigset(&nsv.sv_mask, &nsa.sa_mask);
746 }
747 error = sigaction1(p, SCARG(uap, signum),
748 SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0,
749 NULL, 0);
750 if (error)
751 return (error);
752 if (SCARG(uap, osv)) {
753 osv.sv_handler = osa.sa_handler;
754 osv.sv_flags = osa.sa_flags ^ SA_RESTART;
755 osv.sv_flags &= (ULTRIX_SV_ONSTACK | ULTRIX_SV_INTERRUPT);
756 native_sigset_to_sigset13(&osa.sa_mask, &osv.sv_mask);
757 error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
758 if (error)
759 return (error);
760 }
761 return (0);
762 }
763
764 int
765 ultrix_sys_shmsys(p, v, retval)
766 struct proc *p;
767 void *v;
768 register_t *retval;
769 {
770
771 #ifdef SYSVSHM
772
773 /* Ultrix SVSHM weirndess: */
774 struct ultrix_sys_shmsys_args *uap = v;
775 struct sys_shmat_args shmat_args;
776 struct compat_14_sys_shmctl_args shmctl_args;
777 struct sys_shmdt_args shmdt_args;
778 struct sys_shmget_args shmget_args;
779
780
781 switch (SCARG(uap, shmop)) {
782 case 0: /* Ultrix shmat() */
783 SCARG(&shmat_args, shmid) = SCARG(uap, a2);
784 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
785 SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
786 return (sys_shmat(p, &shmat_args, retval));
787
788 case 1: /* Ultrix shmctl() */
789 SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
790 SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
791 SCARG(&shmctl_args, buf) = (struct shmid_ds14 *)SCARG(uap, a4);
792 return (compat_14_sys_shmctl(p, &shmctl_args, retval));
793
794 case 2: /* Ultrix shmdt() */
795 SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2);
796 return (sys_shmdt(p, &shmdt_args, retval));
797
798 case 3: /* Ultrix shmget() */
799 SCARG(&shmget_args, key) = SCARG(uap, a2);
800 SCARG(&shmget_args, size) = SCARG(uap, a3);
801 SCARG(&shmget_args, shmflg) = SCARG(uap, a4)
802 & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
803 return (sys_shmget(p, &shmget_args, retval));
804
805 default:
806 return (EINVAL);
807 }
808 #else
809 return (EOPNOTSUPP);
810 #endif /* SYSVSHM */
811 }
812
813 static int
814 ultrix_to_bsd_flock(ufl, fl)
815 struct ultrix_flock *ufl;
816 struct flock *fl;
817 {
818
819 fl->l_start = ufl->l_start;
820 fl->l_len = ufl->l_len;
821 fl->l_pid = ufl->l_pid;
822 fl->l_whence = ufl->l_whence;
823
824 switch (ufl->l_type) {
825 case ULTRIX_F_RDLCK:
826 fl->l_type = F_RDLCK;
827 break;
828 case ULTRIX_F_WRLCK:
829 fl->l_type = F_WRLCK;
830 break;
831 case ULTRIX_F_UNLCK:
832 fl->l_type = F_UNLCK;
833 break;
834 default:
835 return (EINVAL);
836 }
837
838 return (0);
839 }
840
841 static void
842 bsd_to_ultrix_flock(fl, ufl)
843 struct flock *fl;
844 struct ultrix_flock *ufl;
845 {
846
847 ufl->l_start = fl->l_start;
848 ufl->l_len = fl->l_len;
849 ufl->l_pid = fl->l_pid;
850 ufl->l_whence = fl->l_whence;
851
852 switch (fl->l_type) {
853 case F_RDLCK:
854 ufl->l_type = ULTRIX_F_RDLCK;
855 break;
856 case F_WRLCK:
857 ufl->l_type = ULTRIX_F_WRLCK;
858 break;
859 case F_UNLCK:
860 ufl->l_type = ULTRIX_F_UNLCK;
861 break;
862 }
863 }
864
865 int
866 ultrix_sys_fcntl(p, v, retval)
867 struct proc *p;
868 void *v;
869 register_t *retval;
870 {
871 struct ultrix_sys_fcntl_args *uap = v;
872 int error;
873 struct ultrix_flock ufl;
874 struct flock fl, *flp;
875 caddr_t sg;
876 struct sys_fcntl_args *args, fca;
877
878 switch (SCARG(uap, cmd)) {
879 case F_GETLK:
880 case F_SETLK:
881 case F_SETLKW:
882 error = copyin(SCARG(uap, arg), &ufl, sizeof(ufl));
883 if (error)
884 return (error);
885 error = ultrix_to_bsd_flock(&ufl, &fl);
886 if (error)
887 return (error);
888 sg = stackgap_init(p, 0);
889 flp = (struct flock *)stackgap_alloc(p, &sg, sizeof(*flp));
890 error = copyout(&fl, flp, sizeof(*flp));
891 if (error)
892 return (error);
893
894 SCARG(&fca, fd) = SCARG(uap, fd);
895 SCARG(&fca, cmd) = SCARG(uap, cmd);
896 SCARG(&fca, arg) = flp;
897 args = &fca;
898 break;
899 default:
900 args = v;
901 break;
902 }
903
904 error = sys_fcntl(p, args, retval);
905 if (error)
906 return (error);
907
908 switch (SCARG(uap, cmd)) {
909 case F_GETLK:
910 error = copyin(flp, &fl, sizeof(fl));
911 if (error)
912 return (error);
913 bsd_to_ultrix_flock(&fl, &ufl);
914 error = copyout(&ufl, SCARG(uap, arg), sizeof(ufl));
915 break;
916 }
917
918 return (error);
919 }
920