sunos_misc.c revision 1.8 1 1.1 deraadt /*
2 1.1 deraadt * Copyright (c) 1992, 1993
3 1.1 deraadt * The Regents of the University of California. All rights reserved.
4 1.1 deraadt *
5 1.1 deraadt * This software was developed by the Computer Systems Engineering group
6 1.1 deraadt * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7 1.1 deraadt * contributed to Berkeley.
8 1.1 deraadt *
9 1.1 deraadt * All advertising materials mentioning features or use of this software
10 1.1 deraadt * must display the following acknowledgement:
11 1.1 deraadt * This product includes software developed by the University of
12 1.1 deraadt * California, Lawrence Berkeley Laboratory.
13 1.1 deraadt *
14 1.1 deraadt * Redistribution and use in source and binary forms, with or without
15 1.1 deraadt * modification, are permitted provided that the following conditions
16 1.1 deraadt * are met:
17 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
18 1.1 deraadt * notice, this list of conditions and the following disclaimer.
19 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
20 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
21 1.1 deraadt * documentation and/or other materials provided with the distribution.
22 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
23 1.1 deraadt * must display the following acknowledgement:
24 1.1 deraadt * This product includes software developed by the University of
25 1.1 deraadt * California, Berkeley and its contributors.
26 1.1 deraadt * 4. Neither the name of the University nor the names of its contributors
27 1.1 deraadt * may be used to endorse or promote products derived from this software
28 1.1 deraadt * without specific prior written permission.
29 1.1 deraadt *
30 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
31 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
34 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
36 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
37 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
38 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
39 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 1.1 deraadt * SUCH DAMAGE.
41 1.1 deraadt *
42 1.1 deraadt * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
43 1.1 deraadt *
44 1.1 deraadt * from: Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
45 1.8 deraadt * $Id: sunos_misc.c,v 1.8 1993/11/20 03:08:16 deraadt Exp $
46 1.1 deraadt */
47 1.1 deraadt
48 1.1 deraadt /*
49 1.1 deraadt * SunOS compatibility module.
50 1.1 deraadt *
51 1.1 deraadt * SunOS system calls that are implemented differently in BSD are
52 1.1 deraadt * handled here.
53 1.1 deraadt */
54 1.1 deraadt
55 1.1 deraadt #include <sys/param.h>
56 1.1 deraadt #include <sys/systm.h>
57 1.4 deraadt #include <ufs/dir.h>
58 1.1 deraadt #include <sys/proc.h>
59 1.1 deraadt #include <sys/file.h>
60 1.1 deraadt #include <sys/filedesc.h>
61 1.1 deraadt #include <sys/ioctl.h>
62 1.8 deraadt #include <sys/kernel.h>
63 1.1 deraadt #include <sys/malloc.h>
64 1.1 deraadt #include <sys/mbuf.h>
65 1.1 deraadt #include <sys/mman.h>
66 1.1 deraadt #include <sys/mount.h>
67 1.1 deraadt #include <sys/resource.h>
68 1.1 deraadt #include <sys/resourcevar.h>
69 1.1 deraadt #include <sys/signal.h>
70 1.1 deraadt #include <sys/signalvar.h>
71 1.1 deraadt #include <sys/socket.h>
72 1.1 deraadt #include <sys/vnode.h>
73 1.1 deraadt #include <sys/uio.h>
74 1.1 deraadt #include <sys/wait.h>
75 1.8 deraadt #include <sys/utsname.h>
76 1.1 deraadt
77 1.7 deraadt #include <miscfs/specfs/specdev.h>
78 1.1 deraadt
79 1.1 deraadt #include <vm/vm.h>
80 1.1 deraadt
81 1.1 deraadt struct sun_wait4_args {
82 1.1 deraadt int pid;
83 1.1 deraadt int *status;
84 1.1 deraadt int options;
85 1.1 deraadt struct rusage *rusage;
86 1.1 deraadt };
87 1.1 deraadt sun_wait4(p, uap, retval)
88 1.1 deraadt struct proc *p;
89 1.1 deraadt struct sun_wait4_args *uap;
90 1.1 deraadt int *retval;
91 1.1 deraadt {
92 1.1 deraadt
93 1.1 deraadt if (uap->pid == 0)
94 1.1 deraadt uap->pid = WAIT_ANY;
95 1.1 deraadt return (wait4(p, uap, retval));
96 1.1 deraadt }
97 1.1 deraadt
98 1.1 deraadt struct sun_creat_args {
99 1.1 deraadt char *fname;
100 1.1 deraadt int fmode;
101 1.1 deraadt };
102 1.1 deraadt sun_creat(p, uap, retval)
103 1.1 deraadt struct proc *p;
104 1.1 deraadt struct sun_creat_args *uap;
105 1.1 deraadt int *retval;
106 1.1 deraadt {
107 1.1 deraadt struct args {
108 1.1 deraadt char *fname;
109 1.1 deraadt int mode;
110 1.1 deraadt int crtmode;
111 1.1 deraadt } openuap;
112 1.1 deraadt
113 1.1 deraadt openuap.fname = uap->fname;
114 1.1 deraadt openuap.crtmode = uap->fmode;
115 1.1 deraadt openuap.mode = O_WRONLY | O_CREAT | O_TRUNC;
116 1.1 deraadt return (open(p, &openuap, retval));
117 1.1 deraadt }
118 1.1 deraadt
119 1.1 deraadt struct sun_execv_args {
120 1.1 deraadt char *fname;
121 1.1 deraadt char **argp;
122 1.1 deraadt char **envp; /* pseudo */
123 1.1 deraadt };
124 1.1 deraadt sun_execv(p, uap, retval)
125 1.1 deraadt struct proc *p;
126 1.1 deraadt struct sun_execv_args *uap;
127 1.1 deraadt int *retval;
128 1.1 deraadt {
129 1.1 deraadt
130 1.1 deraadt uap->envp = NULL;
131 1.1 deraadt return (execve(p, uap, retval));
132 1.1 deraadt }
133 1.1 deraadt
134 1.1 deraadt struct sun_omsync_args {
135 1.1 deraadt caddr_t addr;
136 1.1 deraadt int len;
137 1.1 deraadt int flags;
138 1.1 deraadt };
139 1.1 deraadt sun_omsync(p, uap, retval)
140 1.1 deraadt struct proc *p;
141 1.1 deraadt struct sun_omsync_args *uap;
142 1.1 deraadt int *retval;
143 1.1 deraadt {
144 1.1 deraadt
145 1.1 deraadt if (uap->flags)
146 1.1 deraadt return (EINVAL);
147 1.1 deraadt return (msync(p, uap, retval));
148 1.1 deraadt }
149 1.1 deraadt
150 1.1 deraadt struct sun_unmount_args {
151 1.1 deraadt char *name;
152 1.1 deraadt int flags; /* pseudo */
153 1.1 deraadt };
154 1.1 deraadt sun_unmount(p, uap, retval)
155 1.1 deraadt struct proc *p;
156 1.1 deraadt struct sun_unmount_args *uap;
157 1.1 deraadt int *retval;
158 1.1 deraadt {
159 1.1 deraadt
160 1.1 deraadt uap->flags = 0;
161 1.1 deraadt return (unmount(p, uap, retval));
162 1.1 deraadt }
163 1.1 deraadt
164 1.1 deraadt static int
165 1.1 deraadt gettype(tptr)
166 1.1 deraadt int *tptr;
167 1.1 deraadt {
168 1.1 deraadt int type, error;
169 1.1 deraadt char in[20];
170 1.1 deraadt
171 1.1 deraadt if (error = copyinstr((caddr_t)*tptr, in, sizeof in, (u_int *)0))
172 1.1 deraadt return (error);
173 1.1 deraadt if (strcmp(in, "4.2") == 0 || strcmp(in, "ufs") == 0)
174 1.1 deraadt type = MOUNT_UFS;
175 1.1 deraadt else if (strcmp(in, "nfs") == 0)
176 1.1 deraadt type = MOUNT_NFS;
177 1.1 deraadt else
178 1.1 deraadt return (EINVAL);
179 1.1 deraadt *tptr = type;
180 1.1 deraadt return (0);
181 1.1 deraadt }
182 1.1 deraadt
183 1.1 deraadt #define SUNM_RDONLY 0x01 /* mount fs read-only */
184 1.1 deraadt #define SUNM_NOSUID 0x02 /* mount fs with setuid disallowed */
185 1.1 deraadt #define SUNM_NEWTYPE 0x04 /* type is string (char *), not int */
186 1.1 deraadt #define SUNM_GRPID 0x08 /* (bsd semantics; ignored) */
187 1.1 deraadt #define SUNM_REMOUNT 0x10 /* update existing mount */
188 1.1 deraadt #define SUNM_NOSUB 0x20 /* prevent submounts (rejected) */
189 1.1 deraadt #define SUNM_MULTI 0x40 /* (ignored) */
190 1.1 deraadt #define SUNM_SYS5 0x80 /* Sys 5-specific semantics (rejected) */
191 1.1 deraadt
192 1.1 deraadt struct sun_mount_args {
193 1.1 deraadt int type;
194 1.1 deraadt char *dir;
195 1.1 deraadt int flags;
196 1.1 deraadt caddr_t data;
197 1.1 deraadt };
198 1.1 deraadt sun_mount(p, uap, retval)
199 1.1 deraadt struct proc *p;
200 1.1 deraadt struct sun_mount_args *uap;
201 1.1 deraadt int *retval;
202 1.1 deraadt {
203 1.1 deraadt int oflags = uap->flags, nflags, error;
204 1.1 deraadt
205 1.1 deraadt if (oflags & (SUNM_NOSUB | SUNM_SYS5))
206 1.1 deraadt return (EINVAL);
207 1.1 deraadt if (oflags & SUNM_NEWTYPE && (error = gettype(&uap->type)))
208 1.1 deraadt return (error);
209 1.1 deraadt nflags = 0;
210 1.1 deraadt if (oflags & SUNM_RDONLY)
211 1.1 deraadt nflags |= MNT_RDONLY;
212 1.1 deraadt if (oflags & SUNM_NOSUID)
213 1.1 deraadt nflags |= MNT_NOSUID;
214 1.1 deraadt if (oflags & SUNM_REMOUNT)
215 1.1 deraadt nflags |= MNT_UPDATE;
216 1.1 deraadt uap->flags = nflags;
217 1.1 deraadt return (mount(p, uap, retval));
218 1.1 deraadt }
219 1.1 deraadt
220 1.1 deraadt struct sun_sigpending_args {
221 1.1 deraadt int *mask;
222 1.1 deraadt };
223 1.1 deraadt sun_sigpending(p, uap, retval)
224 1.1 deraadt struct proc *p;
225 1.1 deraadt struct sun_sigpending_args *uap;
226 1.1 deraadt int *retval;
227 1.1 deraadt {
228 1.1 deraadt int mask = p->p_sig & p->p_sigmask;
229 1.1 deraadt
230 1.1 deraadt return (copyout((caddr_t)&mask, (caddr_t)uap->mask, sizeof(int)));
231 1.1 deraadt }
232 1.1 deraadt
233 1.8 deraadt /* XXX: Temporary until sys/dir.h, include/dirent.h and sys/dirent.h are fixed */
234 1.4 deraadt struct dirent {
235 1.4 deraadt u_long d_fileno; /* file number of entry */
236 1.4 deraadt u_short d_reclen; /* length of this record */
237 1.4 deraadt u_short d_namlen; /* length of string in d_name */
238 1.4 deraadt char d_name[255 + 1]; /* name must be no longer than this */
239 1.4 deraadt };
240 1.4 deraadt
241 1.1 deraadt /*
242 1.1 deraadt * Here is the sun layout. (Compare the BSD layout in <sys/dirent.h>.)
243 1.1 deraadt * We can assume big-endian, so the BSD d_type field is just the high
244 1.1 deraadt * byte of the SunOS d_namlen field, after adjusting for the extra "long".
245 1.1 deraadt */
246 1.1 deraadt struct sun_dirent {
247 1.1 deraadt long d_off;
248 1.1 deraadt u_long d_fileno;
249 1.1 deraadt u_short d_reclen;
250 1.1 deraadt u_short d_namlen;
251 1.1 deraadt char d_name[256];
252 1.1 deraadt };
253 1.1 deraadt
254 1.1 deraadt /*
255 1.1 deraadt * Read Sun-style directory entries. We suck them into kernel space so
256 1.1 deraadt * that they can be massaged before being copied out to user code. Like
257 1.1 deraadt * SunOS, we squish out `empty' entries.
258 1.1 deraadt *
259 1.1 deraadt * This is quite ugly, but what do you expect from compatibility code?
260 1.1 deraadt */
261 1.1 deraadt struct sun_getdents_args {
262 1.1 deraadt int fd;
263 1.1 deraadt char *buf;
264 1.1 deraadt int nbytes;
265 1.1 deraadt };
266 1.1 deraadt sun_getdents(p, uap, retval)
267 1.1 deraadt struct proc *p;
268 1.1 deraadt register struct sun_getdents_args *uap;
269 1.1 deraadt int *retval;
270 1.1 deraadt {
271 1.1 deraadt register struct vnode *vp;
272 1.1 deraadt register caddr_t inp, buf; /* BSD-format */
273 1.1 deraadt register int len, reclen; /* BSD-format */
274 1.1 deraadt register caddr_t outp; /* Sun-format */
275 1.1 deraadt register int resid; /* Sun-format */
276 1.1 deraadt struct file *fp;
277 1.1 deraadt struct uio auio;
278 1.1 deraadt struct iovec aiov;
279 1.1 deraadt off_t off; /* true file offset */
280 1.1 deraadt long soff; /* Sun file offset */
281 1.1 deraadt int buflen, error, eofflag;
282 1.1 deraadt #define BSD_DIRENT(cp) ((struct dirent *)(cp))
283 1.1 deraadt #define SUN_RECLEN(reclen) (reclen + sizeof(long))
284 1.1 deraadt
285 1.1 deraadt if ((error = getvnode(p->p_fd, uap->fd, &fp)) != 0)
286 1.1 deraadt return (error);
287 1.1 deraadt if ((fp->f_flag & FREAD) == 0)
288 1.1 deraadt return (EBADF);
289 1.1 deraadt vp = (struct vnode *)fp->f_data;
290 1.1 deraadt if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
291 1.1 deraadt return (EINVAL);
292 1.1 deraadt buflen = min(MAXBSIZE, uap->nbytes);
293 1.1 deraadt buf = malloc(buflen, M_TEMP, M_WAITOK);
294 1.1 deraadt VOP_LOCK(vp);
295 1.1 deraadt off = fp->f_offset;
296 1.1 deraadt again:
297 1.1 deraadt aiov.iov_base = buf;
298 1.1 deraadt aiov.iov_len = buflen;
299 1.1 deraadt auio.uio_iov = &aiov;
300 1.1 deraadt auio.uio_iovcnt = 1;
301 1.1 deraadt auio.uio_rw = UIO_READ;
302 1.1 deraadt auio.uio_segflg = UIO_SYSSPACE;
303 1.1 deraadt auio.uio_procp = p;
304 1.1 deraadt auio.uio_resid = buflen;
305 1.1 deraadt auio.uio_offset = off;
306 1.1 deraadt /*
307 1.1 deraadt * First we read into the malloc'ed buffer, then
308 1.1 deraadt * we massage it into user space, one record at a time.
309 1.1 deraadt */
310 1.4 deraadt if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, NULL, 0))
311 1.1 deraadt goto out;
312 1.1 deraadt inp = buf;
313 1.1 deraadt outp = uap->buf;
314 1.1 deraadt resid = uap->nbytes;
315 1.1 deraadt if ((len = buflen - auio.uio_resid) == 0)
316 1.1 deraadt goto eof;
317 1.1 deraadt for (; len > 0; len -= reclen) {
318 1.1 deraadt reclen = ((struct dirent *)inp)->d_reclen;
319 1.1 deraadt if (reclen & 3)
320 1.1 deraadt panic("sun_getdents");
321 1.1 deraadt off += reclen; /* each entry points to next */
322 1.1 deraadt if (BSD_DIRENT(inp)->d_fileno == 0) {
323 1.1 deraadt inp += reclen; /* it is a hole; squish it out */
324 1.1 deraadt continue;
325 1.1 deraadt }
326 1.1 deraadt if (reclen > len || resid < SUN_RECLEN(reclen)) {
327 1.1 deraadt /* entry too big for buffer, so just stop */
328 1.1 deraadt outp++;
329 1.1 deraadt break;
330 1.1 deraadt }
331 1.1 deraadt /*
332 1.1 deraadt * Massage in place to make a Sun-shaped dirent (otherwise
333 1.1 deraadt * we have to worry about touching user memory outside of
334 1.1 deraadt * the copyout() call).
335 1.1 deraadt */
336 1.1 deraadt BSD_DIRENT(inp)->d_reclen = SUN_RECLEN(reclen);
337 1.4 deraadt #if notdef
338 1.4 deraadt BSD_DIRENT(inp)->d_type = 0; /* 4.4 specific */
339 1.4 deraadt #endif
340 1.1 deraadt soff = off;
341 1.1 deraadt if ((error = copyout((caddr_t)&soff, outp, sizeof soff)) != 0 ||
342 1.1 deraadt (error = copyout(inp, outp + sizeof soff, reclen)) != 0)
343 1.1 deraadt goto out;
344 1.1 deraadt /* advance past this real entry */
345 1.1 deraadt inp += reclen;
346 1.1 deraadt /* advance output past Sun-shaped entry */
347 1.1 deraadt outp += SUN_RECLEN(reclen);
348 1.1 deraadt resid -= SUN_RECLEN(reclen);
349 1.1 deraadt }
350 1.1 deraadt /* if we squished out the whole block, try again */
351 1.1 deraadt if (outp == uap->buf)
352 1.1 deraadt goto again;
353 1.1 deraadt fp->f_offset = off; /* update the vnode offset */
354 1.1 deraadt eof:
355 1.1 deraadt *retval = uap->nbytes - resid;
356 1.1 deraadt out:
357 1.1 deraadt VOP_UNLOCK(vp);
358 1.1 deraadt free(buf, M_TEMP);
359 1.1 deraadt return (error);
360 1.1 deraadt }
361 1.1 deraadt
362 1.4 deraadt /*
363 1.4 deraadt * The Sun bit-style arguments are not in the same order as the
364 1.4 deraadt * NetBSD ones. We must remap them the bits.
365 1.4 deraadt */
366 1.1 deraadt
367 1.5 deraadt #if defined(sparc)
368 1.1 deraadt #define DEVZERO makedev(3, 12) /* major,minor of /dev/zero */
369 1.5 deraadt #endif
370 1.6 deraadt #if defined(sun3) || defined(amiga) || defined(mac) || defined(hp300)
371 1.6 deraadt #define DEVZERO makedev(2, 12) /* major,minor of /dev/zero */
372 1.5 deraadt #endif
373 1.1 deraadt
374 1.4 deraadt #define SUN_PROT_READ 1
375 1.4 deraadt #define SUN_PROT_WRITE 2
376 1.4 deraadt #define SUN_PROT_EXEC 4
377 1.4 deraadt #define SUN_PROT_UALL (SUN_PROT_READ | SUN_PROT_WRITE | SUN_PROT_EXEC)
378 1.4 deraadt
379 1.4 deraadt #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
380 1.4 deraadt
381 1.4 deraadt #define SUN_MAP_SHARED 1
382 1.4 deraadt #define SUN_MAP_PRIVATE 2
383 1.4 deraadt #define SUN_MAP_TYPE 0xf
384 1.4 deraadt #define SUN_MAP_FIXED 0x10
385 1.1 deraadt
386 1.1 deraadt struct sun_mmap_args {
387 1.1 deraadt caddr_t addr;
388 1.1 deraadt size_t len;
389 1.1 deraadt int prot;
390 1.1 deraadt int flags;
391 1.1 deraadt int fd;
392 1.4 deraadt off_t off;
393 1.1 deraadt };
394 1.1 deraadt sun_mmap(p, uap, retval)
395 1.1 deraadt register struct proc *p;
396 1.1 deraadt register struct sun_mmap_args *uap;
397 1.1 deraadt int *retval;
398 1.1 deraadt {
399 1.4 deraadt register int flags, prot, newflags, newprot;
400 1.1 deraadt register struct filedesc *fdp;
401 1.1 deraadt register struct file *fp;
402 1.1 deraadt register struct vnode *vp;
403 1.1 deraadt
404 1.1 deraadt /*
405 1.4 deraadt * Verify and re-map the arguments.
406 1.1 deraadt */
407 1.4 deraadt prot = uap->prot;
408 1.4 deraadt newprot = 0;
409 1.4 deraadt if (uap->prot & ~SUN_PROT_UALL)
410 1.4 deraadt return (EINVAL);
411 1.4 deraadt if (uap->prot & SUN_PROT_READ)
412 1.4 deraadt newprot |= PROT_READ;
413 1.4 deraadt if (uap->prot & SUN_PROT_WRITE)
414 1.4 deraadt newprot |= PROT_WRITE;
415 1.4 deraadt if (uap->prot & SUN_PROT_EXEC)
416 1.4 deraadt newprot |= PROT_EXEC;
417 1.4 deraadt
418 1.1 deraadt flags = uap->flags;
419 1.4 deraadt newflags = 0;
420 1.4 deraadt if ((flags & SUN__MAP_NEW) == 0)
421 1.1 deraadt return (EINVAL);
422 1.4 deraadt
423 1.4 deraadt switch (flags & SUN_MAP_TYPE) {
424 1.4 deraadt case SUN_MAP_SHARED:
425 1.4 deraadt newflags |= MAP_SHARED;
426 1.4 deraadt break;
427 1.4 deraadt case SUN_MAP_PRIVATE:
428 1.4 deraadt newflags |= MAP_PRIVATE;
429 1.4 deraadt break;
430 1.4 deraadt default:
431 1.1 deraadt return (EINVAL);
432 1.4 deraadt }
433 1.1 deraadt
434 1.4 deraadt if (flags & SUN_MAP_FIXED)
435 1.4 deraadt newflags |= MAP_FIXED;
436 1.4 deraadt
437 1.1 deraadt /*
438 1.1 deraadt * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
439 1.1 deraadt */
440 1.1 deraadt fdp = p->p_fd;
441 1.1 deraadt if ((unsigned)uap->fd < fdp->fd_nfiles && /*XXX*/
442 1.1 deraadt (fp = fdp->fd_ofiles[uap->fd]) != NULL && /*XXX*/
443 1.1 deraadt fp->f_type == DTYPE_VNODE && /*XXX*/
444 1.1 deraadt (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
445 1.1 deraadt vp->v_rdev == DEVZERO) { /*XXX*/
446 1.4 deraadt newflags |= MAP_ANON;
447 1.1 deraadt uap->fd = -1;
448 1.4 deraadt } else
449 1.4 deraadt newflags |= MAP_FILE;
450 1.4 deraadt
451 1.1 deraadt /* All done, fix up fields and go. */
452 1.4 deraadt uap->flags = newflags;
453 1.4 deraadt uap->prot = newprot;
454 1.2 deraadt return (smmap(p, uap, retval));
455 1.1 deraadt }
456 1.1 deraadt
457 1.1 deraadt #define MC_SYNC 1
458 1.1 deraadt #define MC_LOCK 2
459 1.1 deraadt #define MC_UNLOCK 3
460 1.1 deraadt #define MC_ADVISE 4
461 1.1 deraadt #define MC_LOCKAS 5
462 1.1 deraadt #define MC_UNLOCKAS 6
463 1.1 deraadt
464 1.1 deraadt struct sun_mctl_args {
465 1.1 deraadt caddr_t addr;
466 1.1 deraadt size_t len;
467 1.1 deraadt int func;
468 1.1 deraadt void *arg;
469 1.1 deraadt };
470 1.1 deraadt sun_mctl(p, uap, retval)
471 1.1 deraadt register struct proc *p;
472 1.1 deraadt register struct sun_mctl_args *uap;
473 1.1 deraadt int *retval;
474 1.1 deraadt {
475 1.1 deraadt
476 1.1 deraadt switch (uap->func) {
477 1.1 deraadt
478 1.1 deraadt case MC_ADVISE: /* ignore for now */
479 1.1 deraadt return (0);
480 1.1 deraadt
481 1.1 deraadt case MC_SYNC: /* translate to msync */
482 1.1 deraadt return (msync(p, uap, retval));
483 1.1 deraadt
484 1.1 deraadt default:
485 1.1 deraadt return (EINVAL);
486 1.1 deraadt }
487 1.1 deraadt }
488 1.1 deraadt
489 1.1 deraadt struct sun_setsockopt_args {
490 1.1 deraadt int s;
491 1.1 deraadt int level;
492 1.1 deraadt int name;
493 1.1 deraadt caddr_t val;
494 1.1 deraadt int valsize;
495 1.1 deraadt };
496 1.1 deraadt sun_setsockopt(p, uap, retval)
497 1.1 deraadt struct proc *p;
498 1.1 deraadt register struct sun_setsockopt_args *uap;
499 1.1 deraadt int *retval;
500 1.1 deraadt {
501 1.1 deraadt struct file *fp;
502 1.1 deraadt struct mbuf *m = NULL;
503 1.1 deraadt int error;
504 1.1 deraadt
505 1.1 deraadt if (error = getsock(p->p_fd, uap->s, &fp))
506 1.1 deraadt return (error);
507 1.1 deraadt #define SO_DONTLINGER (~SO_LINGER)
508 1.1 deraadt if (uap->name == SO_DONTLINGER) {
509 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
510 1.1 deraadt if (m == NULL)
511 1.1 deraadt return (ENOBUFS);
512 1.1 deraadt mtod(m, struct linger *)->l_onoff = 0;
513 1.1 deraadt m->m_len = sizeof(struct linger);
514 1.1 deraadt return (sosetopt((struct socket *)fp->f_data, uap->level,
515 1.1 deraadt SO_LINGER, m));
516 1.1 deraadt }
517 1.1 deraadt if (uap->valsize > MLEN)
518 1.1 deraadt return (EINVAL);
519 1.1 deraadt if (uap->val) {
520 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
521 1.1 deraadt if (m == NULL)
522 1.1 deraadt return (ENOBUFS);
523 1.1 deraadt if (error = copyin(uap->val, mtod(m, caddr_t),
524 1.1 deraadt (u_int)uap->valsize)) {
525 1.1 deraadt (void) m_free(m);
526 1.1 deraadt return (error);
527 1.1 deraadt }
528 1.1 deraadt m->m_len = uap->valsize;
529 1.1 deraadt }
530 1.1 deraadt return (sosetopt((struct socket *)fp->f_data, uap->level,
531 1.1 deraadt uap->name, m));
532 1.1 deraadt }
533 1.1 deraadt
534 1.1 deraadt struct sun_fchroot_args {
535 1.1 deraadt int fdes;
536 1.1 deraadt };
537 1.1 deraadt sun_fchroot(p, uap, retval)
538 1.1 deraadt register struct proc *p;
539 1.1 deraadt register struct sun_fchroot_args *uap;
540 1.1 deraadt int *retval;
541 1.1 deraadt {
542 1.1 deraadt register struct filedesc *fdp = p->p_fd;
543 1.1 deraadt register struct vnode *vp;
544 1.1 deraadt struct file *fp;
545 1.1 deraadt int error;
546 1.1 deraadt
547 1.1 deraadt if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
548 1.1 deraadt return (error);
549 1.1 deraadt if ((error = getvnode(fdp, uap->fdes, &fp)) != 0)
550 1.1 deraadt return (error);
551 1.1 deraadt vp = (struct vnode *)fp->f_data;
552 1.1 deraadt VOP_LOCK(vp);
553 1.1 deraadt if (vp->v_type != VDIR)
554 1.1 deraadt error = ENOTDIR;
555 1.1 deraadt else
556 1.1 deraadt error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
557 1.1 deraadt VOP_UNLOCK(vp);
558 1.1 deraadt if (error)
559 1.1 deraadt return (error);
560 1.1 deraadt VREF(vp);
561 1.1 deraadt if (fdp->fd_rdir != NULL)
562 1.1 deraadt vrele(fdp->fd_rdir);
563 1.1 deraadt fdp->fd_rdir = vp;
564 1.1 deraadt return (0);
565 1.3 deraadt }
566 1.3 deraadt
567 1.3 deraadt /*
568 1.3 deraadt * XXX: This needs cleaning up.
569 1.3 deraadt */
570 1.8 deraadt sun_auditsys(...)
571 1.3 deraadt {
572 1.3 deraadt return 0;
573 1.8 deraadt }
574 1.8 deraadt
575 1.8 deraadt struct sun_utsname {
576 1.8 deraadt char sysname[9];
577 1.8 deraadt char nodename[9];
578 1.8 deraadt char nodeext[65-9];
579 1.8 deraadt char release[9];
580 1.8 deraadt char version[9];
581 1.8 deraadt char machine[9];
582 1.8 deraadt };
583 1.8 deraadt
584 1.8 deraadt struct sun_uname_args {
585 1.8 deraadt struct sun_utsname *name;
586 1.8 deraadt };
587 1.8 deraadt sun_uname(p, uap, retval)
588 1.8 deraadt struct proc *p;
589 1.8 deraadt struct sun_uname_args *uap;
590 1.8 deraadt int *retval;
591 1.8 deraadt {
592 1.8 deraadt struct sun_utsname sut;
593 1.8 deraadt
594 1.8 deraadt /* first update utsname just as with NetBSD uname() */
595 1.8 deraadt bcopy(hostname, utsname.nodename, sizeof(utsname.nodename));
596 1.8 deraadt utsname.nodename[sizeof(utsname.nodename)-1] = '\0';
597 1.8 deraadt
598 1.8 deraadt /* then copy it over into SunOS struct utsname */
599 1.8 deraadt bzero(&sut, sizeof(sut));
600 1.8 deraadt bcopy(utsname.sysname, sut.sysname, sizeof(sut.sysname) - 1);
601 1.8 deraadt bcopy(utsname.nodename, sut.nodename, sizeof(sut.nodename) - 1);
602 1.8 deraadt bcopy(utsname.release, sut.release, sizeof(sut.release) - 1);
603 1.8 deraadt bcopy(utsname.version, sut.version, sizeof(sut.version) - 1);
604 1.8 deraadt bcopy(utsname.machine, sut.machine, sizeof(sut.machine) - 1);
605 1.8 deraadt
606 1.8 deraadt return copyout((caddr_t)&sut, (caddr_t)uap->name, sizeof(struct sun_utsname));
607 1.8 deraadt }
608 1.8 deraadt
609 1.8 deraadt struct sun_setpgid_args {
610 1.8 deraadt int pid; /* target process id */
611 1.8 deraadt int pgid; /* target pgrp id */
612 1.8 deraadt };
613 1.8 deraadt int
614 1.8 deraadt sun_setpgid(p, uap, retval)
615 1.8 deraadt struct proc *p;
616 1.8 deraadt struct sun_setpgid_args *uap;
617 1.8 deraadt int *retval;
618 1.8 deraadt {
619 1.8 deraadt /*
620 1.8 deraadt * difference to our setpgid call is to include backwards
621 1.8 deraadt * compatibility to pre-setsid() binaries. Do setsid()
622 1.8 deraadt * instead of setpgid() in those cases where the process
623 1.8 deraadt * tries to create a new session the old way.
624 1.8 deraadt */
625 1.8 deraadt if (!uap->pgid && (!uap->pid || uap->pid == p->p_pid))
626 1.8 deraadt return setsid(p, uap, retval);
627 1.8 deraadt else
628 1.8 deraadt return setpgid(p, uap, retval);
629 1.8 deraadt }
630 1.8 deraadt
631 1.8 deraadt struct sun_open_args {
632 1.8 deraadt char *fname;
633 1.8 deraadt int fmode;
634 1.8 deraadt int crtmode;
635 1.8 deraadt };
636 1.8 deraadt sun_open(p, uap, retval)
637 1.8 deraadt struct proc *p;
638 1.8 deraadt struct sun_open_args *uap;
639 1.8 deraadt int *retval;
640 1.8 deraadt {
641 1.8 deraadt int l, r;
642 1.8 deraadt int noctty = uap->fmode & 0x8000;
643 1.8 deraadt int ret;
644 1.8 deraadt
645 1.8 deraadt /* convert mode into NetBSD mode */
646 1.8 deraadt l = uap->fmode;
647 1.8 deraadt r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
648 1.8 deraadt r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
649 1.8 deraadt r |= ((l & 0x0080) ? O_SHLOCK : 0);
650 1.8 deraadt r |= ((l & 0x0100) ? O_EXLOCK : 0);
651 1.8 deraadt r |= ((l & 0x2000) ? O_FSYNC : 0);
652 1.8 deraadt
653 1.8 deraadt uap->fmode = r;
654 1.8 deraadt ret = open(p, uap, retval);
655 1.8 deraadt
656 1.8 deraadt if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & SCTTY)) {
657 1.8 deraadt struct filedesc *fdp = p->p_fd;
658 1.8 deraadt struct file *fp = fdp->fd_ofiles[*retval];
659 1.8 deraadt
660 1.8 deraadt /* ignore any error, just give it a try */
661 1.8 deraadt if (fp->f_type == DTYPE_VNODE)
662 1.8 deraadt (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
663 1.8 deraadt }
664 1.8 deraadt return ret;
665 1.1 deraadt }
666