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