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