Annotation of sys/compat/ultrix/ultrix_misc.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: ultrix_misc.c,v 1.30 2007/06/06 17:15:13 deraadt Exp $ */
2: /* $NetBSD: ultrix_misc.c,v 1.23 1996/04/07 17:23:04 jonathan Exp $ */
3:
4: /*
5: * Copyright (c) 1995
6: * Jonathan Stone (hereinafter referred to as the author)
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. The name of the author may not be used to endorse or promote products
17: * derived from this software without specific prior written permission.
18: *
19: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
20: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
23: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29: * SUCH DAMAGE.
30: */
31:
32: /*
33: * Copyright (c) 1992, 1993
34: * The Regents of the University of California. All rights reserved.
35: *
36: * This software was developed by the Computer Systems Engineering group
37: * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
38: * contributed to Berkeley.
39: *
40: * All advertising materials mentioning features or use of this software
41: * must display the following acknowledgement:
42: * This product includes software developed by the University of
43: * California, Lawrence Berkeley Laboratory.
44: *
45: * Redistribution and use in source and binary forms, with or without
46: * modification, are permitted provided that the following conditions
47: * are met:
48: * 1. Redistributions of source code must retain the above copyright
49: * notice, this list of conditions and the following disclaimer.
50: * 2. Redistributions in binary form must reproduce the above copyright
51: * notice, this list of conditions and the following disclaimer in the
52: * documentation and/or other materials provided with the distribution.
53: * 3. Neither the name of the University nor the names of its contributors
54: * may be used to endorse or promote products derived from this software
55: * without specific prior written permission.
56: *
57: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67: * SUCH DAMAGE.
68: *
69: *
70: * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
71: *
72: * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
73: */
74:
75: /*
76: * SunOS compatibility module.
77: *
78: * SunOS system calls that are implemented differently in BSD are
79: * handled here.
80: */
81:
82: #include <sys/param.h>
83: #include <sys/systm.h>
84: #include <sys/namei.h>
85: #include <sys/dirent.h>
86: #include <sys/proc.h>
87: #include <sys/file.h>
88: #include <sys/filedesc.h>
89: /*#include <sys/stat.h>*/
90: /*#include <sys/ioctl.h>*/
91: #include <sys/kernel.h>
92: #include <sys/exec.h>
93: #include <sys/malloc.h>
94: #include <sys/mbuf.h>
95: #include <sys/mman.h>
96: #include <sys/mount.h>
97: #include <sys/resource.h>
98: #include <sys/resourcevar.h>
99: #include <sys/signal.h>
100: #include <sys/signalvar.h>
101: #include <sys/socket.h>
102: #include <sys/vnode.h>
103: #include <sys/uio.h>
104: #include <sys/wait.h>
105: #include <sys/utsname.h>
106: #include <sys/unistd.h>
107:
108: #include <sys/syscallargs.h>
109:
110: #include <compat/ultrix/ultrix_syscall.h>
111: #include <compat/ultrix/ultrix_syscallargs.h>
112: #include <compat/ultrix/ultrix_util.h>
113:
114: #include <netinet/in.h>
115:
116: #include <miscfs/specfs/specdev.h>
117:
118: #include <nfs/rpcv2.h>
119: #include <nfs/nfsproto.h>
120: #include <nfs/nfs.h>
121:
122: #include <uvm/uvm_extern.h>
123:
124: #include <sys/conf.h> /* iszerodev() */
125: #include <sys/socketvar.h> /* sosetopt() */
126:
127: extern struct sysent ultrix_sysent[];
128: #ifdef SYSCALL_DEBUG
129: extern char *ultrix_syscallnames[];
130: #endif
131:
132: /*
133: * Select the appropriate setregs callback for the target architecture.
134: */
135: #ifdef __mips__
136: #define ULTRIX_EXEC_SETREGS cpu_exec_ecoff_setregs
137: #endif /* __mips__ */
138:
139: #ifdef __vax__
140: #define ULTRIX_EXEC_SETREGS setregs
141: #endif /* __vax__ */
142:
143:
144: extern void ULTRIX_EXEC_SETREGS(struct proc *, struct exec_package *,
145: u_long, register_t *);
146: extern char sigcode[], esigcode[];
147:
148: struct emul emul_ultrix = {
149: "ultrix",
150: NULL,
151: sendsig,
152: ULTRIX_SYS_syscall,
153: ULTRIX_SYS_MAXSYSCALL,
154: ultrix_sysent,
155: #ifdef SYSCALL_DEBUG
156: ultrix_syscallnames,
157: #else
158: NULL,
159: #endif
160: 0,
161: copyargs,
162: ULTRIX_EXEC_SETREGS,
163: NULL,
164: sigcode,
165: esigcode,
166: };
167:
168: #define GSI_PROG_ENV 1
169:
170: int
171: ultrix_sys_getsysinfo(p, v, retval)
172: struct proc *p;
173: void *v;
174: register_t *retval;
175: {
176: struct ultrix_sys_getsysinfo_args *uap = v;
177: static short progenv = 0;
178:
179: switch (SCARG(uap, op)) {
180: /* operations implemented: */
181: case GSI_PROG_ENV:
182: if (SCARG(uap, nbytes) < sizeof(short))
183: return EINVAL;
184: *retval = 1;
185: return (copyout(&progenv, SCARG(uap, buffer), sizeof(short)));
186: default:
187: *retval = 0; /* info unavail */
188: return 0;
189: }
190: }
191:
192: int
193: ultrix_sys_setsysinfo(p, v, retval)
194: struct proc *p;
195: void *v;
196: register_t *retval;
197: {
198:
199: #ifdef notyet
200: struct ultrix_sys_setsysinfo_args *uap = v;
201: #endif
202:
203: *retval = 0;
204: return 0;
205: }
206:
207: int
208: ultrix_sys_waitpid(p, v, retval)
209: struct proc *p;
210: void *v;
211: register_t *retval;
212: {
213: struct ultrix_sys_waitpid_args *uap = v;
214: struct sys_wait4_args ua;
215:
216: SCARG(&ua, pid) = SCARG(uap, pid);
217: SCARG(&ua, status) = SCARG(uap, status);
218: SCARG(&ua, options) = SCARG(uap, options);
219: SCARG(&ua, rusage) = 0;
220:
221: return (sys_wait4(p, &ua, retval));
222: }
223:
224: int
225: ultrix_sys_wait3(p, v, retval)
226: struct proc *p;
227: void *v;
228: register_t *retval;
229: {
230: struct ultrix_sys_wait3_args *uap = v;
231: struct sys_wait4_args ua;
232:
233: SCARG(&ua, pid) = -1;
234: SCARG(&ua, status) = SCARG(uap, status);
235: SCARG(&ua, options) = SCARG(uap, options);
236: SCARG(&ua, rusage) = SCARG(uap, rusage);
237:
238: return (sys_wait4(p, &ua, retval));
239: }
240:
241: /*
242: * Ultrix binaries pass in FD_MAX as the first arg to select().
243: * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select()
244: * can handle.
245: * Since we can't have more than the (native) FD_MAX descriptors open,
246: * limit nfds to at most FD_MAX.
247: */
248: int
249: ultrix_sys_select(p, v, retval)
250: struct proc *p;
251: void *v;
252: register_t *retval;
253: {
254: struct sys_select_args *uap = v;
255: struct timeval atv;
256: int error;
257:
258: /* Limit number of FDs selected on to the native maximum */
259:
260: if (SCARG(uap, nd) > FD_SETSIZE)
261: SCARG(uap, nd) = FD_SETSIZE;
262:
263: /* Check for negative timeval */
264: if (SCARG(uap, tv)) {
265: error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv,
266: sizeof(atv));
267: if (error)
268: goto done;
269: #ifdef DEBUG
270: /* Ultrix clients sometimes give negative timeouts? */
271: if (atv.tv_sec < 0 || atv.tv_usec < 0)
272: printf("ultrix select( %ld, %ld): negative timeout\n",
273: atv.tv_sec, atv.tv_usec);
274: /*tvp = (timeval *)STACKGAPBASE;*/
275: #endif
276:
277: }
278: error = sys_select(p, (void *) uap, retval);
279: if (error == EINVAL)
280: printf("ultrix select: bad args?\n");
281:
282: done:
283: return error;
284: }
285:
286: #if defined(NFSCLIENT)
287: int
288: async_daemon(p, v, retval)
289: struct proc *p;
290: void *v;
291: register_t *retval;
292: {
293: struct sys_nfssvc_args ouap;
294:
295: SCARG(&ouap, flag) = NFSSVC_BIOD;
296: SCARG(&ouap, argp) = NULL;
297:
298: return (sys_nfssvc(p, &ouap, retval));
299: }
300: #endif /* NFSCLIENT */
301:
302:
303: #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
304:
305: int
306: ultrix_sys_mmap(p, v, retval)
307: struct proc *p;
308: void *v;
309: register_t *retval;
310: {
311: struct ultrix_sys_mmap_args *uap = v;
312: struct sys_mmap_args ouap;
313:
314: /*
315: * Verify the arguments.
316: */
317: if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
318: return (EINVAL); /* XXX still needed? */
319:
320: if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
321: return (EINVAL);
322:
323: SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
324: SCARG(&ouap, addr) = SCARG(uap, addr);
325:
326: if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
327: SCARG(&ouap, addr) != 0 &&
328: SCARG(&ouap, addr) < (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ))
329: SCARG(&ouap, addr) = (void *)round_page((vaddr_t)p->p_vmspace->vm_daddr+MAXDSIZ);
330:
331: SCARG(&ouap, len) = SCARG(uap, len);
332: SCARG(&ouap, prot) = SCARG(uap, prot);
333: SCARG(&ouap, fd) = SCARG(uap, fd);
334: SCARG(&ouap, pos) = SCARG(uap, pos);
335:
336: return (sys_mmap(p, &ouap, retval));
337: }
338:
339: int
340: ultrix_sys_setsockopt(p, v, retval)
341: struct proc *p;
342: void *v;
343: register_t *retval;
344: {
345: register struct ultrix_sys_setsockopt_args *uap = v;
346: struct file *fp;
347: struct mbuf *m = NULL;
348: int error;
349:
350: if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
351: return (error);
352: #define SO_DONTLINGER (~SO_LINGER)
353: if (SCARG(uap, name) == SO_DONTLINGER) {
354: m = m_get(M_WAIT, MT_SOOPTS);
355: mtod(m, struct linger *)->l_onoff = 0;
356: m->m_len = sizeof(struct linger);
357: error = (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
358: SO_LINGER, m));
359: goto bad;
360: }
361: if (SCARG(uap, valsize) > MLEN) {
362: error = EINVAL;
363: goto bad;
364: }
365: if (SCARG(uap, val)) {
366: m = m_get(M_WAIT, MT_SOOPTS);
367: if ((error = copyin(SCARG(uap, val), mtod(m, caddr_t),
368: (u_int)SCARG(uap, valsize))) != 0) {
369: (void) m_free(m);
370: goto bad;
371: }
372: m->m_len = SCARG(uap, valsize);
373: }
374: error = (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
375: SCARG(uap, name), m));
376: bad:
377: FRELE(fp);
378: return (error);
379: }
380:
381: struct ultrix_utsname {
382: char sysname[9];
383: char nodename[9];
384: char nodeext[65-9];
385: char release[9];
386: char version[9];
387: char machine[9];
388: };
389:
390: int
391: ultrix_sys_uname(p, v, retval)
392: struct proc *p;
393: void *v;
394: register_t *retval;
395: {
396: struct ultrix_sys_uname_args *uap = v;
397: struct ultrix_utsname sut;
398: extern char machine[];
399:
400: bzero(&sut, sizeof(sut));
401:
402: bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
403: bcopy(hostname, sut.nodename, sizeof(sut.nodename));
404: sut.nodename[sizeof(sut.nodename)-1] = '\0';
405: bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
406: bcopy("1", sut.version, sizeof(sut.version) - 1);
407: bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
408:
409: return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
410: sizeof(struct ultrix_utsname));
411: }
412:
413: int
414: ultrix_sys_setpgrp(p, v, retval)
415: struct proc *p;
416: void *v;
417: register_t *retval;
418: {
419: struct ultrix_sys_setpgrp_args *uap = v;
420:
421: /*
422: * difference to our setpgid call is to include backwards
423: * compatibility to pre-setsid() binaries. Do setsid()
424: * instead of setpgid() in those cases where the process
425: * tries to create a new session the old way.
426: */
427: if (!SCARG(uap, pgid) &&
428: (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
429: return sys_setsid(p, uap, retval);
430: else
431: return sys_setpgid(p, uap, retval);
432: }
433:
434: #if defined (NFSSERVER)
435: int
436: ultrix_sys_nfssvc(p, v, retval)
437: struct proc *p;
438: void *v;
439: register_t *retval;
440: {
441:
442: #if 0 /* XXX */
443: struct ultrix_sys_nfssvc_args *uap = v;
444: struct emul *e = p->p_emul;
445: struct sys_nfssvc_args outuap;
446: struct sockaddr sa;
447: int error;
448:
449: bzero(&outuap, sizeof outuap);
450: SCARG(&outuap, fd) = SCARG(uap, fd);
451: SCARG(&outuap, mskval) = STACKGAPBASE;
452: SCARG(&outuap, msklen) = sizeof sa;
453: SCARG(&outuap, mtchval) = outuap.mskval + sizeof sa;
454: SCARG(&outuap, mtchlen) = sizeof sa;
455:
456: bzero(&sa, sizeof sa);
457: if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
458: return (error);
459: if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
460: return (error);
461:
462: return nfssvc(p, &outuap, retval);
463: #else
464: return (ENOSYS);
465: #endif
466: }
467: #endif /* NFSSERVER */
468:
469: struct ultrix_ustat {
470: int32_t f_tfree; /* total free */
471: ino_t f_tinode; /* total inodes free */
472: char f_fname[6]; /* filsys name */
473: char f_fpack[6]; /* filsys pack name */
474: };
475:
476: int
477: ultrix_sys_ustat(p, v, retval)
478: struct proc *p;
479: void *v;
480: register_t *retval;
481: {
482: struct ultrix_sys_ustat_args *uap = v;
483: struct ultrix_ustat us;
484: int error;
485:
486: bzero(&us, sizeof us);
487:
488: /*
489: * XXX: should set f_tfree and f_tinode at least
490: * How do we translate dev -> fstat? (and then to ultrix_ustat)
491: */
492:
493: if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
494: return (error);
495: return 0;
496: }
497:
498: int
499: ultrix_sys_quotactl(p, v, retval)
500: struct proc *p;
501: void *v;
502: register_t *retval;
503: {
504:
505: #ifdef notyet
506: struct ultrix_sys_quotactl_args *uap = v;
507: #endif
508:
509: return EINVAL;
510: }
511:
512: int
513: ultrix_sys_vhangup(p, v, retval)
514: struct proc *p;
515: void *v;
516: register_t *retval;
517: {
518:
519: return 0;
520: }
521:
522: int
523: ultrix_sys_exportfs(p, v, retval)
524: struct proc *p;
525: void *v;
526: register_t *retval;
527: {
528: #ifdef notyet
529: struct ultrix_sys_exportfs_args *uap = v;
530: #endif
531:
532: /*
533: * XXX: should perhaps translate into a mount(2)
534: * with MOUNT_EXPORT?
535: */
536: return 0;
537: }
538:
539: int
540: ultrix_sys_sigpending(p, v, retval)
541: struct proc *p;
542: void *v;
543: register_t *retval;
544: {
545: struct ultrix_sys_sigpending_args *uap = v;
546: int mask = p->p_siglist & p->p_sigmask;
547:
548: return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
549: }
550:
551: int
552: ultrix_sys_sigcleanup(p, v, retval)
553: struct proc *p;
554: void *v;
555: register_t *retval;
556: {
557: struct ultrix_sys_sigcleanup_args *uap = v;
558:
559: return sys_sigreturn(p, (struct sys_sigreturn_args *)uap, retval);
560: }
561:
562: int
563: ultrix_sys_sigreturn(p, v, retval)
564: struct proc *p;
565: void *v;
566: register_t *retval;
567: {
568: struct ultrix_sys_sigcleanup_args *uap = v;
569:
570: #ifdef DEBUG
571: printf("ultrix sigreturn\n");
572: #endif
573: return sys_sigreturn(p, (struct sys_sigreturn_args *)uap, retval);
574: }
575:
576: int
577: ultrix_sys_execve(p, v, retval)
578: struct proc *p;
579: void *v;
580: register_t *retval;
581: {
582: struct ultrix_sys_execve_args /* {
583: syscallarg(char *) path;
584: syscallarg(char **) argv;
585: syscallarg(char **) envp;
586: } */ *uap = v;
587: struct sys_execve_args ap;
588: caddr_t sg;
589:
590: sg = stackgap_init(p->p_emul);
591: ULTRIX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
592:
593: SCARG(&ap, path) = SCARG(uap, path);
594: SCARG(&ap, argp) = SCARG(uap, argp);
595: SCARG(&ap, envp) = SCARG(uap, envp);
596:
597: return (sys_execve(p, &ap, retval));
598: }
CVSweb