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