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