ultrix_misc.c revision 1.50.2.1 1 1.50.2.1 he /* $NetBSD: ultrix_misc.c,v 1.50.2.1 2000/01/31 20:41:37 he Exp $ */
2 1.5 cgd
3 1.1 glass /*
4 1.30 jonathan * Copyright (c) 1995, 1997 Jonathan Stone (hereinafter referred to as the author)
5 1.30 jonathan * All rights reserved.
6 1.23 jonathan *
7 1.23 jonathan * Redistribution and use in source and binary forms, with or without
8 1.23 jonathan * modification, are permitted provided that the following conditions
9 1.23 jonathan * are met:
10 1.23 jonathan * 1. Redistributions of source code must retain the above copyright
11 1.23 jonathan * notice, this list of conditions and the following disclaimer.
12 1.23 jonathan * 2. Redistributions in binary form must reproduce the above copyright
13 1.23 jonathan * notice, this list of conditions and the following disclaimer in the
14 1.23 jonathan * documentation and/or other materials provided with the distribution.
15 1.28 jonathan * 3. All advertising materials mentioning features or use of this software
16 1.28 jonathan * must display the following acknowledgement:
17 1.37 jonathan * This product includes software developed by Jonathan Stone for
18 1.28 jonathan * the NetBSD Project.
19 1.28 jonathan * 4. The name of the author may not be used to endorse or promote products
20 1.23 jonathan * derived from this software without specific prior written permission.
21 1.23 jonathan *
22 1.23 jonathan * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
23 1.23 jonathan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.23 jonathan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.23 jonathan * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
26 1.23 jonathan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.23 jonathan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.23 jonathan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.23 jonathan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.23 jonathan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.23 jonathan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.23 jonathan * SUCH DAMAGE.
33 1.23 jonathan */
34 1.23 jonathan
35 1.23 jonathan /*
36 1.1 glass * Copyright (c) 1992, 1993
37 1.1 glass * The Regents of the University of California. All rights reserved.
38 1.1 glass *
39 1.1 glass * This software was developed by the Computer Systems Engineering group
40 1.1 glass * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
41 1.1 glass * contributed to Berkeley.
42 1.1 glass *
43 1.1 glass * All advertising materials mentioning features or use of this software
44 1.1 glass * must display the following acknowledgement:
45 1.1 glass * This product includes software developed by the University of
46 1.1 glass * California, Lawrence Berkeley Laboratory.
47 1.1 glass *
48 1.1 glass * Redistribution and use in source and binary forms, with or without
49 1.1 glass * modification, are permitted provided that the following conditions
50 1.1 glass * are met:
51 1.1 glass * 1. Redistributions of source code must retain the above copyright
52 1.1 glass * notice, this list of conditions and the following disclaimer.
53 1.1 glass * 2. Redistributions in binary form must reproduce the above copyright
54 1.1 glass * notice, this list of conditions and the following disclaimer in the
55 1.1 glass * documentation and/or other materials provided with the distribution.
56 1.1 glass * 3. All advertising materials mentioning features or use of this software
57 1.1 glass * must display the following acknowledgement:
58 1.1 glass * This product includes software developed by the University of
59 1.1 glass * California, Berkeley and its contributors.
60 1.1 glass * 4. Neither the name of the University nor the names of its contributors
61 1.1 glass * may be used to endorse or promote products derived from this software
62 1.1 glass * without specific prior written permission.
63 1.1 glass *
64 1.1 glass * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 1.1 glass * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 1.1 glass * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 1.1 glass * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 1.1 glass * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 1.1 glass * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 1.1 glass * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 1.1 glass * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 1.1 glass * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 1.1 glass * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 1.1 glass * SUCH DAMAGE.
75 1.1 glass *
76 1.5 cgd *
77 1.1 glass * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
78 1.1 glass *
79 1.1 glass * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
80 1.1 glass */
81 1.1 glass
82 1.40 mhitch #include "opt_nfsserver.h"
83 1.47 tron #include "opt_sysv.h"
84 1.40 mhitch
85 1.38 jonathan #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
86 1.38 jonathan
87 1.1 glass /*
88 1.49 sommerfe * Ultrix compatibility module.
89 1.1 glass *
90 1.49 sommerfe * Ultrix system calls that are implemented differently in BSD are
91 1.1 glass * handled here.
92 1.1 glass */
93 1.39 thorpej
94 1.39 thorpej #include "fs_nfs.h"
95 1.1 glass
96 1.1 glass #include <sys/param.h>
97 1.1 glass #include <sys/systm.h>
98 1.1 glass #include <sys/namei.h>
99 1.25 mycroft #include <sys/dirent.h>
100 1.1 glass #include <sys/proc.h>
101 1.1 glass #include <sys/file.h>
102 1.1 glass #include <sys/filedesc.h>
103 1.20 jonathan /*#include <sys/stat.h>*/
104 1.20 jonathan /*#include <sys/ioctl.h>*/
105 1.1 glass #include <sys/kernel.h>
106 1.1 glass #include <sys/exec.h>
107 1.1 glass #include <sys/malloc.h>
108 1.1 glass #include <sys/mbuf.h>
109 1.1 glass #include <sys/mman.h>
110 1.1 glass #include <sys/mount.h>
111 1.1 glass #include <sys/resource.h>
112 1.1 glass #include <sys/resourcevar.h>
113 1.1 glass #include <sys/signal.h>
114 1.1 glass #include <sys/signalvar.h>
115 1.1 glass #include <sys/socket.h>
116 1.1 glass #include <sys/vnode.h>
117 1.1 glass #include <sys/uio.h>
118 1.1 glass #include <sys/wait.h>
119 1.1 glass #include <sys/utsname.h>
120 1.1 glass #include <sys/unistd.h>
121 1.30 jonathan #include <sys/ipc.h>
122 1.20 jonathan
123 1.16 mycroft #include <sys/syscallargs.h>
124 1.16 mycroft
125 1.16 mycroft #include <compat/ultrix/ultrix_syscall.h>
126 1.16 mycroft #include <compat/ultrix/ultrix_syscallargs.h>
127 1.30 jonathan #include <compat/common/compat_util.h>
128 1.1 glass
129 1.1 glass #include <netinet/in.h>
130 1.1 glass
131 1.1 glass #include <miscfs/specfs/specdev.h>
132 1.1 glass
133 1.3 glass #include <nfs/rpcv2.h>
134 1.21 pk #include <nfs/nfsproto.h>
135 1.3 glass #include <nfs/nfs.h>
136 1.3 glass
137 1.35 jonathan #include <vm/vm.h> /* pmap declarations */
138 1.11 christos
139 1.23 jonathan #include <sys/conf.h> /* iszerodev() */
140 1.23 jonathan #include <sys/socketvar.h> /* sosetopt() */
141 1.23 jonathan
142 1.50.2.1 he #include <compat/ultrix/ultrix_flock.h>
143 1.50.2.1 he
144 1.50.2.1 he static int ultrix_to_bsd_flock __P((struct ultrix_flock *, struct flock *));
145 1.50.2.1 he static void bsd_to_ultrix_flock __P((struct flock *, struct ultrix_flock *));
146 1.35 jonathan
147 1.11 christos extern struct sysent ultrix_sysent[];
148 1.11 christos extern char *ultrix_syscallnames[];
149 1.22 jonathan
150 1.35 jonathan
151 1.22 jonathan /*
152 1.22 jonathan * Select the appropriate setregs callback for the target architecture.
153 1.22 jonathan */
154 1.48 matt #ifdef __mips__
155 1.33 jonathan #include <machine/ecoff_machdep.h>
156 1.22 jonathan #define ULTRIX_EXEC_SETREGS cpu_exec_ecoff_setregs
157 1.22 jonathan #endif /* mips */
158 1.22 jonathan
159 1.48 matt #ifdef __vax__
160 1.22 jonathan #define ULTRIX_EXEC_SETREGS setregs
161 1.48 matt #endif /* vax */
162 1.22 jonathan
163 1.22 jonathan
164 1.22 jonathan extern void ULTRIX_EXEC_SETREGS __P((struct proc *, struct exec_package *,
165 1.36 mhitch u_long));
166 1.45 drochner extern char ultrix_sigcode[], ultrix_esigcode[];
167 1.19 jonathan
168 1.11 christos struct emul emul_ultrix = {
169 1.11 christos "ultrix",
170 1.11 christos NULL,
171 1.11 christos sendsig,
172 1.11 christos ULTRIX_SYS_syscall,
173 1.11 christos ULTRIX_SYS_MAXSYSCALL,
174 1.11 christos ultrix_sysent,
175 1.11 christos ultrix_syscallnames,
176 1.11 christos 0,
177 1.11 christos copyargs,
178 1.22 jonathan ULTRIX_EXEC_SETREGS,
179 1.45 drochner ultrix_sigcode,
180 1.45 drochner ultrix_esigcode,
181 1.11 christos };
182 1.1 glass
183 1.6 glass #define GSI_PROG_ENV 1
184 1.6 glass
185 1.23 jonathan int
186 1.16 mycroft ultrix_sys_getsysinfo(p, v, retval)
187 1.6 glass struct proc *p;
188 1.15 thorpej void *v;
189 1.16 mycroft register_t *retval;
190 1.6 glass {
191 1.16 mycroft struct ultrix_sys_getsysinfo_args *uap = v;
192 1.6 glass static short progenv = 0;
193 1.6 glass
194 1.16 mycroft switch (SCARG(uap, op)) {
195 1.6 glass /* operations implemented: */
196 1.6 glass case GSI_PROG_ENV:
197 1.16 mycroft if (SCARG(uap, nbytes) < sizeof(short))
198 1.6 glass return EINVAL;
199 1.6 glass *retval = 1;
200 1.16 mycroft return (copyout(&progenv, SCARG(uap, buffer), sizeof(short)));
201 1.6 glass default:
202 1.6 glass *retval = 0; /* info unavail */
203 1.6 glass return 0;
204 1.6 glass }
205 1.6 glass }
206 1.6 glass
207 1.23 jonathan int
208 1.16 mycroft ultrix_sys_setsysinfo(p, v, retval)
209 1.6 glass struct proc *p;
210 1.15 thorpej void *v;
211 1.16 mycroft register_t *retval;
212 1.6 glass {
213 1.23 jonathan
214 1.23 jonathan #ifdef notyet
215 1.16 mycroft struct ultrix_sys_setsysinfo_args *uap = v;
216 1.23 jonathan #endif
217 1.23 jonathan
218 1.6 glass *retval = 0;
219 1.6 glass return 0;
220 1.6 glass }
221 1.6 glass
222 1.23 jonathan int
223 1.16 mycroft ultrix_sys_waitpid(p, v, retval)
224 1.1 glass struct proc *p;
225 1.15 thorpej void *v;
226 1.7 cgd register_t *retval;
227 1.1 glass {
228 1.16 mycroft struct ultrix_sys_waitpid_args *uap = v;
229 1.16 mycroft struct sys_wait4_args ua;
230 1.1 glass
231 1.16 mycroft SCARG(&ua, pid) = SCARG(uap, pid);
232 1.16 mycroft SCARG(&ua, status) = SCARG(uap, status);
233 1.16 mycroft SCARG(&ua, options) = SCARG(uap, options);
234 1.16 mycroft SCARG(&ua, rusage) = 0;
235 1.1 glass
236 1.16 mycroft return (sys_wait4(p, &ua, retval));
237 1.2 glass }
238 1.2 glass
239 1.23 jonathan int
240 1.16 mycroft ultrix_sys_wait3(p, v, retval)
241 1.2 glass struct proc *p;
242 1.15 thorpej void *v;
243 1.7 cgd register_t *retval;
244 1.2 glass {
245 1.16 mycroft struct ultrix_sys_wait3_args *uap = v;
246 1.16 mycroft struct sys_wait4_args ua;
247 1.2 glass
248 1.16 mycroft SCARG(&ua, pid) = -1;
249 1.16 mycroft SCARG(&ua, status) = SCARG(uap, status);
250 1.16 mycroft SCARG(&ua, options) = SCARG(uap, options);
251 1.16 mycroft SCARG(&ua, rusage) = SCARG(uap, rusage);
252 1.1 glass
253 1.16 mycroft return (sys_wait4(p, &ua, retval));
254 1.1 glass }
255 1.1 glass
256 1.20 jonathan /*
257 1.20 jonathan * Ultrix binaries pass in FD_MAX as the first arg to select().
258 1.23 jonathan * On Ultrix, FD_MAX is 4096, which is more than the NetBSD sys_select()
259 1.20 jonathan * can handle.
260 1.23 jonathan * Since we can't have more than the (native) FD_MAX descriptors open,
261 1.23 jonathan * limit nfds to at most FD_MAX.
262 1.20 jonathan */
263 1.23 jonathan int
264 1.18 jonathan ultrix_sys_select(p, v, retval)
265 1.18 jonathan struct proc *p;
266 1.18 jonathan void *v;
267 1.18 jonathan register_t *retval;
268 1.18 jonathan {
269 1.18 jonathan struct sys_select_args *uap = v;
270 1.23 jonathan struct timeval atv;
271 1.18 jonathan int error;
272 1.18 jonathan
273 1.18 jonathan /* Limit number of FDs selected on to the native maximum */
274 1.18 jonathan
275 1.18 jonathan if (SCARG(uap, nd) > FD_SETSIZE)
276 1.18 jonathan SCARG(uap, nd) = FD_SETSIZE;
277 1.18 jonathan
278 1.18 jonathan /* Check for negative timeval */
279 1.18 jonathan if (SCARG(uap, tv)) {
280 1.18 jonathan error = copyin((caddr_t)SCARG(uap, tv), (caddr_t)&atv,
281 1.18 jonathan sizeof(atv));
282 1.18 jonathan if (error)
283 1.18 jonathan goto done;
284 1.18 jonathan #ifdef DEBUG
285 1.18 jonathan /* Ultrix clients sometimes give negative timeouts? */
286 1.18 jonathan if (atv.tv_sec < 0 || atv.tv_usec < 0)
287 1.27 christos printf("ultrix select( %ld, %ld): negative timeout\n",
288 1.26 christos atv.tv_sec, atv.tv_usec);
289 1.18 jonathan /*tvp = (timeval *)STACKGAPBASE;*/
290 1.18 jonathan #endif
291 1.18 jonathan
292 1.18 jonathan }
293 1.18 jonathan error = sys_select(p, (void*) uap, retval);
294 1.18 jonathan if (error == EINVAL)
295 1.27 christos printf("ultrix select: bad args?\n");
296 1.18 jonathan
297 1.18 jonathan done:
298 1.18 jonathan return error;
299 1.1 glass }
300 1.1 glass
301 1.29 thorpej #if defined(NFS)
302 1.23 jonathan int
303 1.16 mycroft async_daemon(p, v, retval)
304 1.1 glass struct proc *p;
305 1.15 thorpej void *v;
306 1.7 cgd register_t *retval;
307 1.1 glass {
308 1.16 mycroft struct sys_nfssvc_args ouap;
309 1.1 glass
310 1.16 mycroft SCARG(&ouap, flag) = NFSSVC_BIOD;
311 1.16 mycroft SCARG(&ouap, argp) = NULL;
312 1.3 glass
313 1.16 mycroft return (sys_nfssvc(p, &ouap, retval));
314 1.3 glass }
315 1.29 thorpej #endif /* NFS */
316 1.3 glass
317 1.1 glass
318 1.1 glass #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
319 1.1 glass
320 1.20 jonathan int
321 1.16 mycroft ultrix_sys_mmap(p, v, retval)
322 1.1 glass register struct proc *p;
323 1.15 thorpej void *v;
324 1.7 cgd register_t *retval;
325 1.1 glass {
326 1.16 mycroft register struct ultrix_sys_mmap_args *uap = v;
327 1.16 mycroft struct sys_mmap_args ouap;
328 1.1 glass register struct filedesc *fdp;
329 1.1 glass register struct file *fp;
330 1.1 glass register struct vnode *vp;
331 1.1 glass
332 1.1 glass /*
333 1.1 glass * Verify the arguments.
334 1.1 glass */
335 1.16 mycroft if (SCARG(uap, prot) & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
336 1.1 glass return (EINVAL); /* XXX still needed? */
337 1.1 glass
338 1.16 mycroft if ((SCARG(uap, flags) & SUN__MAP_NEW) == 0)
339 1.1 glass return (EINVAL);
340 1.1 glass
341 1.16 mycroft SCARG(&ouap, flags) = SCARG(uap, flags) & ~SUN__MAP_NEW;
342 1.16 mycroft SCARG(&ouap, addr) = SCARG(uap, addr);
343 1.16 mycroft
344 1.16 mycroft if ((SCARG(&ouap, flags) & MAP_FIXED) == 0 &&
345 1.16 mycroft SCARG(&ouap, addr) != 0 &&
346 1.38 jonathan SCARG(&ouap, addr) < (void *)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
347 1.38 jonathan SCARG(&ouap, addr) = (void *)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
348 1.16 mycroft
349 1.16 mycroft SCARG(&ouap, len) = SCARG(uap, len);
350 1.16 mycroft SCARG(&ouap, prot) = SCARG(uap, prot);
351 1.16 mycroft SCARG(&ouap, fd) = SCARG(uap, fd);
352 1.16 mycroft SCARG(&ouap, pos) = SCARG(uap, pos);
353 1.1 glass
354 1.1 glass /*
355 1.1 glass * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
356 1.1 glass */
357 1.1 glass fdp = p->p_fd;
358 1.16 mycroft if ((unsigned)SCARG(&ouap, fd) < fdp->fd_nfiles && /*XXX*/
359 1.16 mycroft (fp = fdp->fd_ofiles[SCARG(&ouap, fd)]) != NULL && /*XXX*/
360 1.1 glass fp->f_type == DTYPE_VNODE && /*XXX*/
361 1.1 glass (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
362 1.1 glass iszerodev(vp->v_rdev)) { /*XXX*/
363 1.16 mycroft SCARG(&ouap, flags) |= MAP_ANON;
364 1.16 mycroft SCARG(&ouap, fd) = -1;
365 1.1 glass }
366 1.1 glass
367 1.16 mycroft return (sys_mmap(p, &ouap, retval));
368 1.1 glass }
369 1.1 glass
370 1.23 jonathan int
371 1.16 mycroft ultrix_sys_setsockopt(p, v, retval)
372 1.1 glass struct proc *p;
373 1.15 thorpej void *v;
374 1.7 cgd register_t *retval;
375 1.1 glass {
376 1.16 mycroft register struct ultrix_sys_setsockopt_args *uap = v;
377 1.1 glass struct file *fp;
378 1.1 glass struct mbuf *m = NULL;
379 1.1 glass int error;
380 1.1 glass
381 1.23 jonathan if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
382 1.1 glass return (error);
383 1.1 glass #define SO_DONTLINGER (~SO_LINGER)
384 1.16 mycroft if (SCARG(uap, name) == SO_DONTLINGER) {
385 1.1 glass m = m_get(M_WAIT, MT_SOOPTS);
386 1.1 glass mtod(m, struct linger *)->l_onoff = 0;
387 1.1 glass m->m_len = sizeof(struct linger);
388 1.16 mycroft return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
389 1.1 glass SO_LINGER, m));
390 1.1 glass }
391 1.30 jonathan if (SCARG(uap, level) == IPPROTO_IP) {
392 1.30 jonathan #define EMUL_IP_MULTICAST_IF 2
393 1.30 jonathan #define EMUL_IP_MULTICAST_TTL 3
394 1.30 jonathan #define EMUL_IP_MULTICAST_LOOP 4
395 1.30 jonathan #define EMUL_IP_ADD_MEMBERSHIP 5
396 1.30 jonathan #define EMUL_IP_DROP_MEMBERSHIP 6
397 1.30 jonathan static int ipoptxlat[] = {
398 1.30 jonathan IP_MULTICAST_IF,
399 1.30 jonathan IP_MULTICAST_TTL,
400 1.30 jonathan IP_MULTICAST_LOOP,
401 1.30 jonathan IP_ADD_MEMBERSHIP,
402 1.30 jonathan IP_DROP_MEMBERSHIP
403 1.30 jonathan };
404 1.30 jonathan if (SCARG(uap, name) >= EMUL_IP_MULTICAST_IF &&
405 1.30 jonathan SCARG(uap, name) <= EMUL_IP_DROP_MEMBERSHIP) {
406 1.30 jonathan SCARG(uap, name) =
407 1.30 jonathan ipoptxlat[SCARG(uap, name) - EMUL_IP_MULTICAST_IF];
408 1.30 jonathan }
409 1.30 jonathan }
410 1.16 mycroft if (SCARG(uap, valsize) > MLEN)
411 1.1 glass return (EINVAL);
412 1.16 mycroft if (SCARG(uap, val)) {
413 1.1 glass m = m_get(M_WAIT, MT_SOOPTS);
414 1.30 jonathan error = copyin(SCARG(uap, val), mtod(m, caddr_t),
415 1.30 jonathan (u_int)SCARG(uap, valsize));
416 1.30 jonathan if (error) {
417 1.1 glass (void) m_free(m);
418 1.1 glass return (error);
419 1.1 glass }
420 1.16 mycroft m->m_len = SCARG(uap, valsize);
421 1.1 glass }
422 1.16 mycroft return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level),
423 1.16 mycroft SCARG(uap, name), m));
424 1.1 glass }
425 1.1 glass
426 1.16 mycroft struct ultrix_utsname {
427 1.1 glass char sysname[9];
428 1.1 glass char nodename[9];
429 1.1 glass char nodeext[65-9];
430 1.1 glass char release[9];
431 1.1 glass char version[9];
432 1.1 glass char machine[9];
433 1.1 glass };
434 1.1 glass
435 1.20 jonathan int
436 1.16 mycroft ultrix_sys_uname(p, v, retval)
437 1.1 glass struct proc *p;
438 1.15 thorpej void *v;
439 1.7 cgd register_t *retval;
440 1.1 glass {
441 1.16 mycroft struct ultrix_sys_uname_args *uap = v;
442 1.16 mycroft struct ultrix_utsname sut;
443 1.1 glass extern char ostype[], machine[], osrelease[];
444 1.1 glass
445 1.41 perry memset(&sut, 0, sizeof(sut));
446 1.1 glass
447 1.41 perry memcpy(sut.sysname, ostype, sizeof(sut.sysname) - 1);
448 1.41 perry memcpy(sut.nodename, hostname, sizeof(sut.nodename));
449 1.1 glass sut.nodename[sizeof(sut.nodename)-1] = '\0';
450 1.41 perry memcpy(sut.release, osrelease, sizeof(sut.release) - 1);
451 1.41 perry memcpy(sut.version, "1", sizeof(sut.version) - 1);
452 1.41 perry memcpy(sut.machine, machine, sizeof(sut.machine) - 1);
453 1.1 glass
454 1.16 mycroft return copyout((caddr_t)&sut, (caddr_t)SCARG(uap, name),
455 1.16 mycroft sizeof(struct ultrix_utsname));
456 1.1 glass }
457 1.1 glass
458 1.1 glass int
459 1.16 mycroft ultrix_sys_setpgrp(p, v, retval)
460 1.1 glass struct proc *p;
461 1.15 thorpej void *v;
462 1.7 cgd register_t *retval;
463 1.1 glass {
464 1.16 mycroft struct ultrix_sys_setpgrp_args *uap = v;
465 1.15 thorpej
466 1.1 glass /*
467 1.1 glass * difference to our setpgid call is to include backwards
468 1.1 glass * compatibility to pre-setsid() binaries. Do setsid()
469 1.1 glass * instead of setpgid() in those cases where the process
470 1.1 glass * tries to create a new session the old way.
471 1.1 glass */
472 1.16 mycroft if (!SCARG(uap, pgid) &&
473 1.16 mycroft (!SCARG(uap, pid) || SCARG(uap, pid) == p->p_pid))
474 1.16 mycroft return sys_setsid(p, uap, retval);
475 1.1 glass else
476 1.16 mycroft return sys_setpgid(p, uap, retval);
477 1.1 glass }
478 1.1 glass
479 1.1 glass #if defined (NFSSERVER)
480 1.20 jonathan int
481 1.16 mycroft ultrix_sys_nfssvc(p, v, retval)
482 1.1 glass struct proc *p;
483 1.15 thorpej void *v;
484 1.7 cgd register_t *retval;
485 1.1 glass {
486 1.23 jonathan
487 1.23 jonathan #if 0 /* XXX */
488 1.16 mycroft struct ultrix_sys_nfssvc_args *uap = v;
489 1.16 mycroft struct emul *e = p->p_emul;
490 1.16 mycroft struct sys_nfssvc_args outuap;
491 1.1 glass struct sockaddr sa;
492 1.1 glass int error;
493 1.1 glass
494 1.41 perry memset(&outuap, 0, sizeof outuap);
495 1.16 mycroft SCARG(&outuap, fd) = SCARG(uap, fd);
496 1.16 mycroft SCARG(&outuap, mskval) = STACKGAPBASE;
497 1.16 mycroft SCARG(&outuap, msklen) = sizeof sa;
498 1.16 mycroft SCARG(&outuap, mtchval) = outuap.mskval + sizeof sa;
499 1.16 mycroft SCARG(&outuap, mtchlen) = sizeof sa;
500 1.1 glass
501 1.41 perry memset(&sa, 0, sizeof sa);
502 1.16 mycroft if (error = copyout(&sa, SCARG(&outuap, mskval), SCARG(&outuap, msklen)))
503 1.1 glass return (error);
504 1.16 mycroft if (error = copyout(&sa, SCARG(&outuap, mtchval), SCARG(&outuap, mtchlen)))
505 1.1 glass return (error);
506 1.1 glass
507 1.1 glass return nfssvc(p, &outuap, retval);
508 1.16 mycroft #else
509 1.16 mycroft return (ENOSYS);
510 1.16 mycroft #endif
511 1.1 glass }
512 1.1 glass #endif /* NFSSERVER */
513 1.1 glass
514 1.16 mycroft struct ultrix_ustat {
515 1.1 glass daddr_t f_tfree; /* total free */
516 1.1 glass ino_t f_tinode; /* total inodes free */
517 1.1 glass char f_fname[6]; /* filsys name */
518 1.1 glass char f_fpack[6]; /* filsys pack name */
519 1.1 glass };
520 1.16 mycroft
521 1.20 jonathan int
522 1.16 mycroft ultrix_sys_ustat(p, v, retval)
523 1.1 glass struct proc *p;
524 1.15 thorpej void *v;
525 1.7 cgd register_t *retval;
526 1.1 glass {
527 1.16 mycroft struct ultrix_sys_ustat_args *uap = v;
528 1.16 mycroft struct ultrix_ustat us;
529 1.1 glass int error;
530 1.1 glass
531 1.41 perry memset(&us, 0, sizeof us);
532 1.1 glass
533 1.1 glass /*
534 1.1 glass * XXX: should set f_tfree and f_tinode at least
535 1.16 mycroft * How do we translate dev -> fstat? (and then to ultrix_ustat)
536 1.1 glass */
537 1.1 glass
538 1.23 jonathan if ((error = copyout(&us, SCARG(uap, buf), sizeof us)) != 0)
539 1.1 glass return (error);
540 1.1 glass return 0;
541 1.1 glass }
542 1.1 glass
543 1.20 jonathan int
544 1.16 mycroft ultrix_sys_quotactl(p, v, retval)
545 1.1 glass struct proc *p;
546 1.15 thorpej void *v;
547 1.7 cgd register_t *retval;
548 1.1 glass {
549 1.23 jonathan
550 1.23 jonathan #ifdef notyet
551 1.16 mycroft struct ultrix_sys_quotactl_args *uap = v;
552 1.23 jonathan #endif
553 1.15 thorpej
554 1.1 glass return EINVAL;
555 1.1 glass }
556 1.1 glass
557 1.20 jonathan int
558 1.16 mycroft ultrix_sys_vhangup(p, v, retval)
559 1.1 glass struct proc *p;
560 1.16 mycroft void *v;
561 1.7 cgd register_t *retval;
562 1.1 glass {
563 1.16 mycroft
564 1.1 glass return 0;
565 1.1 glass }
566 1.35 jonathan
567 1.35 jonathan
568 1.35 jonathan /*
569 1.35 jonathan * RISC Ultrix cache control syscalls
570 1.35 jonathan */
571 1.35 jonathan #ifdef __mips
572 1.35 jonathan int
573 1.35 jonathan ultrix_sys_cacheflush(p, v, retval)
574 1.35 jonathan register struct proc *p;
575 1.35 jonathan void *v;
576 1.35 jonathan register_t *retval;
577 1.35 jonathan {
578 1.35 jonathan register struct ultrix_sys_cacheflush_args /* {
579 1.35 jonathan syscallarg(void *) addr;
580 1.35 jonathan syscallarg(int) nbytes;
581 1.35 jonathan syscallarg(int) flag;
582 1.35 jonathan } */ *uap = v;
583 1.42 eeh register vaddr_t va = (vaddr_t)SCARG(uap, addr);
584 1.35 jonathan register int nbytes = SCARG(uap, nbytes);
585 1.35 jonathan register int whichcache = SCARG(uap, whichcache);
586 1.35 jonathan
587 1.35 jonathan return (mips_user_cacheflush(p, va, nbytes, whichcache));
588 1.35 jonathan }
589 1.35 jonathan
590 1.35 jonathan
591 1.35 jonathan int
592 1.35 jonathan ultrix_sys_cachectl(p, v, retval)
593 1.35 jonathan register struct proc *p;
594 1.35 jonathan void *v;
595 1.35 jonathan register_t *retval;
596 1.35 jonathan {
597 1.35 jonathan register struct ultrix_sys_cachectl_args /* {
598 1.35 jonathan syscallarg(void *) addr;
599 1.35 jonathan syscallarg(int) nbytes;
600 1.35 jonathan syscallarg(int) cacheop;
601 1.35 jonathan } */ *uap = v;
602 1.42 eeh register vaddr_t va = (vaddr_t)SCARG(uap, addr);
603 1.35 jonathan register int nbytes = SCARG(uap, nbytes);
604 1.35 jonathan register int cacheop = SCARG(uap, cacheop);
605 1.35 jonathan
606 1.35 jonathan return mips_user_cachectl(p, va, nbytes, cacheop);
607 1.35 jonathan }
608 1.35 jonathan
609 1.35 jonathan #endif /* __mips */
610 1.35 jonathan
611 1.1 glass
612 1.20 jonathan int
613 1.16 mycroft ultrix_sys_exportfs(p, v, retval)
614 1.1 glass struct proc *p;
615 1.15 thorpej void *v;
616 1.7 cgd register_t *retval;
617 1.1 glass {
618 1.23 jonathan #ifdef notyet
619 1.16 mycroft struct ultrix_sys_exportfs_args *uap = v;
620 1.23 jonathan #endif
621 1.15 thorpej
622 1.1 glass /*
623 1.1 glass * XXX: should perhaps translate into a mount(2)
624 1.1 glass * with MOUNT_EXPORT?
625 1.1 glass */
626 1.1 glass return 0;
627 1.1 glass }
628 1.1 glass
629 1.16 mycroft int
630 1.19 jonathan ultrix_sys_sigpending(p, v, retval)
631 1.19 jonathan struct proc *p;
632 1.19 jonathan void *v;
633 1.19 jonathan register_t *retval;
634 1.19 jonathan {
635 1.19 jonathan struct ultrix_sys_sigpending_args *uap = v;
636 1.43 drochner sigset_t ss;
637 1.43 drochner int mask;
638 1.43 drochner
639 1.43 drochner sigpending1(p, &ss);
640 1.43 drochner mask = ss.__bits[0];
641 1.19 jonathan
642 1.19 jonathan return (copyout((caddr_t)&mask, (caddr_t)SCARG(uap, mask), sizeof(int)));
643 1.19 jonathan }
644 1.19 jonathan
645 1.19 jonathan int
646 1.44 drochner ultrix_sys_sigreturn(p, v, retval)
647 1.44 drochner struct proc *p;
648 1.44 drochner void *v;
649 1.44 drochner register_t *retval;
650 1.44 drochner {
651 1.44 drochner struct ultrix_sys_sigreturn_args *uap = v;
652 1.44 drochner
653 1.45 drochner /* struct sigcontext13 is close enough to Ultrix */
654 1.45 drochner
655 1.45 drochner return (compat_13_sys_sigreturn(p, uap, retval));
656 1.44 drochner }
657 1.44 drochner
658 1.44 drochner int
659 1.16 mycroft ultrix_sys_sigcleanup(p, v, retval)
660 1.13 mellon struct proc *p;
661 1.15 thorpej void *v;
662 1.13 mellon register_t *retval;
663 1.13 mellon {
664 1.16 mycroft struct ultrix_sys_sigcleanup_args *uap = v;
665 1.15 thorpej
666 1.45 drochner /* struct sigcontext13 is close enough to Ultrix */
667 1.45 drochner
668 1.45 drochner return (compat_13_sys_sigreturn(p, uap, retval));
669 1.44 drochner }
670 1.44 drochner
671 1.44 drochner int
672 1.44 drochner ultrix_sys_sigsuspend(p, v, retval)
673 1.44 drochner struct proc *p;
674 1.44 drochner void *v;
675 1.44 drochner register_t *retval;
676 1.44 drochner {
677 1.44 drochner struct ultrix_sys_sigsuspend_args *uap = v;
678 1.44 drochner int mask = SCARG(uap, mask);
679 1.44 drochner sigset_t ss;
680 1.44 drochner
681 1.44 drochner ss.__bits[0] = mask;
682 1.44 drochner ss.__bits[1] = 0;
683 1.44 drochner ss.__bits[2] = 0;
684 1.44 drochner ss.__bits[3] = 0;
685 1.44 drochner
686 1.44 drochner return (sigsuspend1(p, &ss));
687 1.19 jonathan }
688 1.19 jonathan
689 1.46 drochner #define ULTRIX_SV_ONSTACK 0x0001 /* take signal on signal stack */
690 1.46 drochner #define ULTRIX_SV_INTERRUPT 0x0002 /* do not restart system on signal return */
691 1.46 drochner #define ULTRIX_SV_OLDSIG 0x1000 /* Emulate old signal() for POSIX */
692 1.46 drochner
693 1.46 drochner int
694 1.46 drochner ultrix_sys_sigvec(p, v, retval)
695 1.46 drochner struct proc *p;
696 1.46 drochner void *v;
697 1.46 drochner register_t *retval;
698 1.46 drochner {
699 1.46 drochner struct ultrix_sys_sigvec_args *uap = v;
700 1.46 drochner struct sigvec nsv, osv;
701 1.46 drochner struct sigaction nsa, osa;
702 1.46 drochner int error;
703 1.46 drochner
704 1.46 drochner if (SCARG(uap, nsv)) {
705 1.46 drochner error = copyin(SCARG(uap, nsv), &nsv, sizeof(nsv));
706 1.46 drochner if (error)
707 1.46 drochner return (error);
708 1.46 drochner nsa.sa_handler = nsv.sv_handler;
709 1.46 drochner #if 0 /* documentation */
710 1.46 drochner /* ONSTACK is identical */
711 1.46 drochner nsa.sa_flags = nsv.sv_flags & ULTRIX_SV_ONSTACK;
712 1.46 drochner if ((nsv.sv_flags & ULTRIX_SV_OLDSIG)
713 1.46 drochner /* old signal() - always restart */
714 1.46 drochner || (!(nsv.sv_flags & ULTRIX_SV_INTERRUPT))
715 1.46 drochner /* inverted meaning (same bit) */
716 1.46 drochner )
717 1.46 drochner nsa.sa_flags |= SA_RESTART;
718 1.46 drochner #else /* optimized - assuming ULTRIX_SV_OLDSIG=>!ULTRIX_SV_INTERRUPT */
719 1.46 drochner nsa.sa_flags = nsv.sv_flags & ~ULTRIX_SV_OLDSIG;
720 1.46 drochner nsa.sa_flags ^= SA_RESTART;
721 1.46 drochner #endif
722 1.46 drochner native_sigset13_to_sigset(&nsv.sv_mask, &nsa.sa_mask);
723 1.46 drochner }
724 1.46 drochner error = sigaction1(p, SCARG(uap, signum),
725 1.46 drochner SCARG(uap, nsv) ? &nsa : 0, SCARG(uap, osv) ? &osa : 0);
726 1.46 drochner if (error)
727 1.46 drochner return (error);
728 1.46 drochner if (SCARG(uap, osv)) {
729 1.46 drochner osv.sv_handler = osa.sa_handler;
730 1.46 drochner osv.sv_flags = osa.sa_flags ^ SA_RESTART;
731 1.46 drochner osv.sv_flags &= (ULTRIX_SV_ONSTACK | ULTRIX_SV_INTERRUPT);
732 1.46 drochner native_sigset_to_sigset13(&osa.sa_mask, &osv.sv_mask);
733 1.46 drochner error = copyout(&osv, SCARG(uap, osv), sizeof(osv));
734 1.46 drochner if (error)
735 1.46 drochner return (error);
736 1.46 drochner }
737 1.46 drochner return (0);
738 1.46 drochner }
739 1.30 jonathan
740 1.32 jonathan int
741 1.30 jonathan ultrix_sys_shmsys(p, v, retval)
742 1.30 jonathan struct proc *p;
743 1.30 jonathan void *v;
744 1.30 jonathan register_t *retval;
745 1.30 jonathan {
746 1.30 jonathan
747 1.30 jonathan #ifdef SYSVSHM
748 1.30 jonathan
749 1.30 jonathan /* Ultrix SVSHM weirndess: */
750 1.30 jonathan struct ultrix_sys_shmsys_args *uap = v;
751 1.30 jonathan struct sys_shmat_args shmat_args;
752 1.30 jonathan struct sys_shmctl_args shmctl_args;
753 1.30 jonathan struct sys_shmdt_args shmdt_args;
754 1.30 jonathan struct sys_shmget_args shmget_args;
755 1.30 jonathan
756 1.30 jonathan
757 1.30 jonathan switch (SCARG(uap, shmop)) {
758 1.30 jonathan case 0: /* Ultrix shmat() */
759 1.30 jonathan SCARG(&shmat_args, shmid) = SCARG(uap, a2);
760 1.30 jonathan SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a3);
761 1.30 jonathan SCARG(&shmat_args, shmflg) = SCARG(uap, a4);
762 1.30 jonathan return (sys_shmat(p, &shmat_args, retval));
763 1.30 jonathan
764 1.30 jonathan case 1: /* Ultrix shmctl() */
765 1.30 jonathan SCARG(&shmctl_args, shmid) = SCARG(uap, a2);
766 1.30 jonathan SCARG(&shmctl_args, cmd) = SCARG(uap, a3);
767 1.30 jonathan SCARG(&shmctl_args, buf) = (struct shmid_ds *)SCARG(uap, a4);
768 1.30 jonathan return (sys_shmctl(p, &shmctl_args, retval));
769 1.30 jonathan
770 1.30 jonathan case 2: /* Ultrix shmdt() */
771 1.30 jonathan SCARG(&shmat_args, shmaddr) = (void *)SCARG(uap, a2);
772 1.30 jonathan return (sys_shmdt(p, &shmdt_args, retval));
773 1.30 jonathan
774 1.30 jonathan case 3: /* Ultrix shmget() */
775 1.30 jonathan SCARG(&shmget_args, key) = SCARG(uap, a2);
776 1.30 jonathan SCARG(&shmget_args, size) = SCARG(uap, a3);
777 1.30 jonathan SCARG(&shmget_args, shmflg) = SCARG(uap, a4)
778 1.30 jonathan & (IPC_CREAT|IPC_EXCL|IPC_NOWAIT);
779 1.30 jonathan return (sys_shmget(p, &shmget_args, retval));
780 1.30 jonathan
781 1.30 jonathan default:
782 1.30 jonathan return (EINVAL);
783 1.30 jonathan }
784 1.31 jonathan #else
785 1.31 jonathan return (EOPNOTSUPP);
786 1.30 jonathan #endif /* SYSVSHM */
787 1.50.2.1 he }
788 1.50.2.1 he
789 1.50.2.1 he static int
790 1.50.2.1 he ultrix_to_bsd_flock(ufl, fl)
791 1.50.2.1 he struct ultrix_flock *ufl;
792 1.50.2.1 he struct flock *fl;
793 1.50.2.1 he {
794 1.50.2.1 he
795 1.50.2.1 he fl->l_start = ufl->l_start;
796 1.50.2.1 he fl->l_len = ufl->l_len;
797 1.50.2.1 he fl->l_pid = ufl->l_pid;
798 1.50.2.1 he fl->l_whence = ufl->l_whence;
799 1.50.2.1 he
800 1.50.2.1 he switch (ufl->l_type) {
801 1.50.2.1 he case ULTRIX_F_RDLCK:
802 1.50.2.1 he fl->l_type = F_RDLCK;
803 1.50.2.1 he break;
804 1.50.2.1 he case ULTRIX_F_WRLCK:
805 1.50.2.1 he fl->l_type = F_WRLCK;
806 1.50.2.1 he break;
807 1.50.2.1 he case ULTRIX_F_UNLCK:
808 1.50.2.1 he fl->l_type = F_UNLCK;
809 1.50.2.1 he break;
810 1.50.2.1 he default:
811 1.50.2.1 he return (EINVAL);
812 1.50.2.1 he }
813 1.50.2.1 he
814 1.50.2.1 he return (0);
815 1.50.2.1 he }
816 1.50.2.1 he
817 1.50.2.1 he static void
818 1.50.2.1 he bsd_to_ultrix_flock(fl, ufl)
819 1.50.2.1 he struct flock *fl;
820 1.50.2.1 he struct ultrix_flock *ufl;
821 1.50.2.1 he {
822 1.50.2.1 he
823 1.50.2.1 he ufl->l_start = fl->l_start;
824 1.50.2.1 he ufl->l_len = fl->l_len;
825 1.50.2.1 he ufl->l_pid = fl->l_pid;
826 1.50.2.1 he ufl->l_whence = fl->l_whence;
827 1.50.2.1 he
828 1.50.2.1 he switch (fl->l_type) {
829 1.50.2.1 he case F_RDLCK:
830 1.50.2.1 he ufl->l_type = ULTRIX_F_RDLCK;
831 1.50.2.1 he break;
832 1.50.2.1 he case F_WRLCK:
833 1.50.2.1 he ufl->l_type = ULTRIX_F_WRLCK;
834 1.50.2.1 he break;
835 1.50.2.1 he case F_UNLCK:
836 1.50.2.1 he ufl->l_type = ULTRIX_F_UNLCK;
837 1.50.2.1 he break;
838 1.50.2.1 he }
839 1.50.2.1 he }
840 1.50.2.1 he
841 1.50.2.1 he int
842 1.50.2.1 he ultrix_sys_fcntl(p, v, retval)
843 1.50.2.1 he struct proc *p;
844 1.50.2.1 he void *v;
845 1.50.2.1 he register_t *retval;
846 1.50.2.1 he {
847 1.50.2.1 he struct ultrix_sys_fcntl_args *uap = v;
848 1.50.2.1 he int error;
849 1.50.2.1 he struct ultrix_flock ufl;
850 1.50.2.1 he struct flock fl, *flp;
851 1.50.2.1 he caddr_t sg;
852 1.50.2.1 he struct sys_fcntl_args *args, fca;
853 1.50.2.1 he
854 1.50.2.1 he switch (SCARG(uap, cmd)) {
855 1.50.2.1 he case F_GETLK:
856 1.50.2.1 he case F_SETLK:
857 1.50.2.1 he case F_SETLKW:
858 1.50.2.1 he error = copyin(SCARG(uap, arg), &ufl, sizeof(ufl));
859 1.50.2.1 he if (error)
860 1.50.2.1 he return (error);
861 1.50.2.1 he error = ultrix_to_bsd_flock(&ufl, &fl);
862 1.50.2.1 he if (error)
863 1.50.2.1 he return (error);
864 1.50.2.1 he sg = stackgap_init(p->p_emul);
865 1.50.2.1 he flp = (struct flock *)stackgap_alloc(&sg, sizeof(*flp));
866 1.50.2.1 he error = copyout(&fl, flp, sizeof(*flp));
867 1.50.2.1 he if (error)
868 1.50.2.1 he return (error);
869 1.50.2.1 he
870 1.50.2.1 he SCARG(&fca, fd) = SCARG(uap, fd);
871 1.50.2.1 he SCARG(&fca, cmd) = SCARG(uap, cmd);
872 1.50.2.1 he SCARG(&fca, arg) = flp;
873 1.50.2.1 he args = &fca;
874 1.50.2.1 he break;
875 1.50.2.1 he default:
876 1.50.2.1 he args = v;
877 1.50.2.1 he break;
878 1.50.2.1 he }
879 1.50.2.1 he
880 1.50.2.1 he error = sys_fcntl(p, args, retval);
881 1.50.2.1 he if (error)
882 1.50.2.1 he return (error);
883 1.50.2.1 he
884 1.50.2.1 he switch (SCARG(uap, cmd)) {
885 1.50.2.1 he case F_GETLK:
886 1.50.2.1 he error = copyin(flp, &fl, sizeof(fl));
887 1.50.2.1 he if (error)
888 1.50.2.1 he return (error);
889 1.50.2.1 he bsd_to_ultrix_flock(&fl, &ufl);
890 1.50.2.1 he error = copyout(&ufl, SCARG(uap, arg), sizeof(ufl));
891 1.50.2.1 he break;
892 1.50.2.1 he }
893 1.50.2.1 he
894 1.50.2.1 he return (error);
895 1.1 glass }
896