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