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