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