- someone must have been confused about how to use the stackgap.

- remove extra caddr_t
- cleanup unneeded syscalls.
- add locking.
This commit is contained in:
christos 2005-03-05 17:47:06 +00:00
parent a6d3ad34e1
commit 44f6417295
1 changed files with 68 additions and 83 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ibcs2_misc.c,v 1.72 2005/02/26 23:10:18 perry Exp $ */ /* $NetBSD: ibcs2_misc.c,v 1.73 2005/03/05 17:47:06 christos Exp $ */
/* /*
* Copyright (c) 1992, 1993 * Copyright (c) 1992, 1993
@ -95,7 +95,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ibcs2_misc.c,v 1.72 2005/02/26 23:10:18 perry Exp $"); __KERNEL_RCSID(0, "$NetBSD: ibcs2_misc.c,v 1.73 2005/03/05 17:47:06 christos Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -244,8 +244,7 @@ ibcs2_sys_waitsys(l, v, retval)
if ((error = sys_wait4(l, &w4, retval)) != 0) if ((error = sys_wait4(l, &w4, retval)) != 0)
return error; return error;
return copyin((caddr_t)SCARG(&w4, status), (caddr_t)&retval[1], return copyin(SCARG(&w4, status), &retval[1], sizeof(int));
sizeof(int));
} }
int int
@ -332,9 +331,9 @@ ibcs2_sys_mount(l, v, retval)
char fsname[MFSNAMELEN]; char fsname[MFSNAMELEN];
if (oflags & (IBCS2_MS_NOSUB | IBCS2_MS_SYS5)) if (oflags & (IBCS2_MS_NOSUB | IBCS2_MS_SYS5))
return (EINVAL); return EINVAL;
if ((oflags & IBCS2_MS_NEWTYPE) == 0) if ((oflags & IBCS2_MS_NEWTYPE) == 0)
return (EINVAL); return EINVAL;
nflags = 0; nflags = 0;
if (oflags & IBCS2_MS_RDONLY) if (oflags & IBCS2_MS_RDONLY)
nflags |= MNT_RDONLY; nflags |= MNT_RDONLY;
@ -344,14 +343,13 @@ ibcs2_sys_mount(l, v, retval)
nflags |= MNT_UPDATE; nflags |= MNT_UPDATE;
SCARG(uap, flags) = nflags; SCARG(uap, flags) = nflags;
if (error = copyinstr((caddr_t)SCARG(uap, type), fsname, sizeof fsname, if (error = copyinstr(SCARG(uap, type), fsname, sizeof fsname, NULL))
(u_int *)0)) return error;
return (error);
if (strncmp(fsname, "4.2", sizeof fsname) == 0) { if (strncmp(fsname, "4.2", sizeof fsname) == 0) {
SCARG(uap, type) = (caddr_t)STACK_ALLOC(); SCARG(uap, type) = (caddr_t)STACK_ALLOC();
if (error = copyout("ffs", SCARG(uap, type), sizeof("ffs"))) if (error = copyout("ffs", SCARG(uap, type), sizeof("ffs")))
return (error); return error;
} else if (strncmp(fsname, "nfs", sizeof fsname) == 0) { } else if (strncmp(fsname, "nfs", sizeof fsname) == 0) {
struct ibcs2_nfs_args sna; struct ibcs2_nfs_args sna;
struct sockaddr_in sain; struct sockaddr_in sain;
@ -359,13 +357,13 @@ ibcs2_sys_mount(l, v, retval)
struct sockaddr sa; struct sockaddr sa;
if (error = copyin(SCARG(uap, data), &sna, sizeof sna)) if (error = copyin(SCARG(uap, data), &sna, sizeof sna))
return (error); return error;
if (error = copyin(sna.addr, &sain, sizeof sain)) if (error = copyin(sna.addr, &sain, sizeof sain))
return (error); return error;
memcpy(&sa, &sain, sizeof sa); memcpy(&sa, &sain, sizeof sa);
sa.sa_len = sizeof(sain); sa.sa_len = sizeof(sain);
SCARG(uap, data) = (caddr_t)STACK_ALLOC(); SCARG(uap, data) = STACK_ALLOC();
na.addr = (struct sockaddr *)((int)SCARG(uap, data) + sizeof na); na.addr = (void *)((unsigned long)SCARG(uap, data) + sizeof na);
na.sotype = SOCK_DGRAM; na.sotype = SOCK_DGRAM;
na.proto = IPPROTO_UDP; na.proto = IPPROTO_UDP;
na.fh = (nfsv2fh_t *)sna.fh; na.fh = (nfsv2fh_t *)sna.fh;
@ -377,11 +375,11 @@ ibcs2_sys_mount(l, v, retval)
na.hostname = sna.hostname; na.hostname = sna.hostname;
if (error = copyout(&sa, na.addr, sizeof sa)) if (error = copyout(&sa, na.addr, sizeof sa))
return (error); return error;
if (error = copyout(&na, SCARG(uap, data), sizeof na)) if (error = copyout(&na, SCARG(uap, data), sizeof na))
return (error); return error;
} }
return (sys_mount(p, uap, retval)); return sys_mount(p, uap, retval);
#else #else
return EINVAL; return EINVAL;
#endif #endif
@ -515,7 +513,7 @@ out:
if (cookiebuf) if (cookiebuf)
free(cookiebuf, M_TEMP); free(cookiebuf, M_TEMP);
free(buf, M_TEMP); free(buf, M_TEMP);
out1: out1:
FILE_UNUSE(fp, p); FILE_UNUSE(fp, p);
return (error); return (error);
} }
@ -563,7 +561,7 @@ ibcs2_sys_read(l, v, retval)
error = EBADF; error = EBADF;
goto out1; goto out1;
} }
vp = (struct vnode *)fp->f_data; vp = fp->f_data;
if (vp->v_type != VDIR) { if (vp->v_type != VDIR) {
FILE_UNUSE(fp, p); FILE_UNUSE(fp, p);
return sys_read(l, uap, retval); return sys_read(l, uap, retval);
@ -714,14 +712,13 @@ ibcs2_sys_getgroups(l, v, retval)
gidsetsize = retval[0]; gidsetsize = retval[0];
if (gidsetsize < 0) if (gidsetsize < 0)
gidsetsize = 0; gidsetsize = 0;
error = copyin((caddr_t)SCARG(&sa, gidset), (caddr_t)nset, error = copyin(SCARG(&sa, gidset), nset,
sizeof(gid_t) * gidsetsize); sizeof(gid_t) * gidsetsize);
if (error) if (error)
return error; return error;
for (i = 0; i < gidsetsize; i++) for (i = 0; i < gidsetsize; i++)
iset[i] = (ibcs2_gid_t)nset[i]; iset[i] = (ibcs2_gid_t)nset[i];
error = copyout((caddr_t)iset, error = copyout(iset, SCARG(uap, gidset),
(caddr_t)SCARG(uap, gidset),
sizeof(ibcs2_gid_t) * retval[0]); sizeof(ibcs2_gid_t) * retval[0]);
} }
return error; return error;
@ -750,7 +747,7 @@ ibcs2_sys_setgroups(l, v, retval)
SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize); SCARG(&sa, gidsetsize) = SCARG(uap, gidsetsize);
if (SCARG(&sa, gidsetsize)) { if (SCARG(&sa, gidsetsize)) {
error = copyin((caddr_t)SCARG(uap, gidset), (caddr_t)iset, error = copyin(SCARG(uap, gidset), iset,
sizeof(ibcs2_gid_t) * SCARG(uap, gidsetsize)); sizeof(ibcs2_gid_t) * SCARG(uap, gidsetsize));
if (error) if (error)
return error; return error;
@ -813,7 +810,7 @@ xenix_sys_ftime(l, v, retval)
/* NetBSD has no kernel notion of timezone -- fake it. */ /* NetBSD has no kernel notion of timezone -- fake it. */
itb.timezone = 0; itb.timezone = 0;
itb.dstflag = 0; itb.dstflag = 0;
return copyout((caddr_t)&itb, (caddr_t)SCARG(uap, tp), xenix_timeb_len); return copyout(&itb, SCARG(uap, tp), xenix_timeb_len);
} }
int int
@ -831,8 +828,8 @@ ibcs2_sys_time(l, v, retval)
microtime(&tv); microtime(&tv);
*retval = tv.tv_sec; *retval = tv.tv_sec;
if (p->p_emuldata == IBCS2_EXEC_XENIX && SCARG(uap, tp)) if (p->p_emuldata == IBCS2_EXEC_XENIX && SCARG(uap, tp))
return copyout((caddr_t)&tv.tv_sec, (caddr_t)SCARG(uap, tp), return copyout(&tv.tv_sec, SCARG(uap, tp),
sizeof(ibcs2_time_t)); sizeof(ibcs2_time_t));
else else
return 0; return 0;
} }
@ -877,7 +874,6 @@ ibcs2_sys_sysconf(l, v, retval)
struct proc *p = l->l_proc; struct proc *p = l->l_proc;
int mib[2], value, error; int mib[2], value, error;
size_t len; size_t len;
struct sys_getrlimit_args ga;
switch(SCARG(uap, name)) { switch(SCARG(uap, name)) {
case IBCS2_SC_ARG_MAX: case IBCS2_SC_ARG_MAX:
@ -885,16 +881,8 @@ ibcs2_sys_sysconf(l, v, retval)
break; break;
case IBCS2_SC_CHILD_MAX: case IBCS2_SC_CHILD_MAX:
{ *retval = p->p_rlimit[RLIMIT_NPROC].rlim_cur;
caddr_t sg = stackgap_init(p, 0);
SCARG(&ga, which) = RLIMIT_NPROC;
SCARG(&ga, rlp) = stackgap_alloc(p, &sg, sizeof(struct rlimit *));
if ((error = sys_getrlimit(l, &ga, retval)) != 0)
return error;
*retval = SCARG(&ga, rlp)->rlim_cur;
return 0; return 0;
}
case IBCS2_SC_CLK_TCK: case IBCS2_SC_CLK_TCK:
*retval = hz; *retval = hz;
@ -905,16 +893,8 @@ ibcs2_sys_sysconf(l, v, retval)
break; break;
case IBCS2_SC_OPEN_MAX: case IBCS2_SC_OPEN_MAX:
{ *retval = p->p_rlimit[RLIMIT_NPROC].rlim_cur;
caddr_t sg = stackgap_init(p, 0);
SCARG(&ga, which) = RLIMIT_NOFILE;
SCARG(&ga, rlp) = stackgap_alloc(p, &sg, sizeof(struct rlimit *));
if ((error = sys_getrlimit(l, &ga, retval)) != 0)
return error;
*retval = SCARG(&ga, rlp)->rlim_cur;
return 0; return 0;
}
case IBCS2_SC_JOB_CONTROL: case IBCS2_SC_JOB_CONTROL:
mib[1] = KERN_JOB_CONTROL; mib[1] = KERN_JOB_CONTROL;
@ -964,15 +944,19 @@ ibcs2_sys_alarm(l, v, retval)
} */ *uap = v; } */ *uap = v;
struct proc *p = l->l_proc; struct proc *p = l->l_proc;
int error; int error;
struct itimerval *itp, *oitp; struct itimerval it, *itp, *oitp;
struct sys_setitimer_args sa; struct sys_setitimer_args sa;
caddr_t sg = stackgap_init(p, 0); caddr_t sg = stackgap_init(p, 0);
itp = stackgap_alloc(p, &sg, sizeof(*itp)); itp = stackgap_alloc(p, &sg, sizeof(*itp));
oitp = stackgap_alloc(p, &sg, sizeof(*oitp)); oitp = stackgap_alloc(p, &sg, sizeof(*oitp));
timerclear(&itp->it_interval);
itp->it_value.tv_sec = SCARG(uap, sec); timerclear(&it.it_interval);
itp->it_value.tv_usec = 0; it.it_value.tv_sec = SCARG(uap, sec);
it.it_value.tv_usec = 0;
if ((error = copyout(&it, itp, sizeof(*itp))) != 0)
return error;
SCARG(&sa, which) = ITIMER_REAL; SCARG(&sa, which) = ITIMER_REAL;
SCARG(&sa, itv) = itp; SCARG(&sa, itv) = itp;
@ -980,9 +964,11 @@ ibcs2_sys_alarm(l, v, retval)
error = sys_setitimer(l, &sa, retval); error = sys_setitimer(l, &sa, retval);
if (error) if (error)
return error; return error;
if (oitp->it_value.tv_usec) if ((error = copyin(oitp, &it, sizeof(it))) != 0)
oitp->it_value.tv_sec++; return error;
*retval = oitp->it_value.tv_sec; if (it.it_value.tv_usec)
it.it_value.tv_sec++;
*retval = it.it_value.tv_sec;
return 0; return 0;
} }
@ -1058,8 +1044,7 @@ ibcs2_sys_times(l, v, retval)
microtime(&t); microtime(&t);
*retval = CONVTCK(t); *retval = CONVTCK(t);
return copyout((caddr_t)&tms, (caddr_t)SCARG(uap, tp), return copyout(&tms, SCARG(uap, tp), sizeof(tms));
sizeof(struct tms));
} }
int int
@ -1669,26 +1654,22 @@ ibcs2_sys_scoinfo(l, v, retval)
syscallarg(struct scoutsname *) bp; syscallarg(struct scoutsname *) bp;
syscallarg(int) len; syscallarg(int) len;
} */ *uap = v; } */ *uap = v;
struct proc *p = l->l_proc; struct scoutsname uts;
caddr_t sg = stackgap_init(p, 0);
struct scoutsname *utsp = stackgap_alloc(p, &sg,
sizeof(struct scoutsname));
memset(utsp, 0, sizeof(struct scoutsname)); (void)memset(&uts, 0, sizeof(uts));
strncpy(utsp->sysname, ostype, 8); (void)strncpy(uts.sysname, ostype, 8);
strncpy(utsp->nodename, hostname, 8); (void)strncpy(uts.nodename, hostname, 8);
strncpy(utsp->release, osrelease, 15); (void)strncpy(uts.release, osrelease, 15);
strncpy(utsp->kid, "kernel id 1", 19); (void)strncpy(uts.kid, "kernel id 1", 19);
strncpy(utsp->machine, machine, 8); (void)strncpy(uts.machine, machine, 8);
strncpy(utsp->bustype, "pci", 8); (void)strncpy(uts.bustype, "pci", 8);
strncpy(utsp->serial, "1234", 9); (void)strncpy(uts.serial, "1234", 9);
utsp->origin = 0; uts.origin = 0;
utsp->oem = 0; uts.oem = 0;
strncpy(utsp->nusers, "unlim", 8); (void)strncpy(uts.nusers, "unlim", 8);
utsp->ncpu = 1; uts.ncpu = 1;
return copyout((caddr_t)utsp, (caddr_t)SCARG(uap, bp), return copyout(&uts, SCARG(uap, bp), sizeof(uts));
sizeof(struct scoutsname));
} }
#define X_LK_UNLCK 0 #define X_LK_UNLCK 0
@ -1714,10 +1695,10 @@ xenix_sys_locking(l, v, retval)
} */ *uap = v; } */ *uap = v;
struct proc *p = l->l_proc; struct proc *p = l->l_proc;
struct sys_fcntl_args fa; struct sys_fcntl_args fa;
struct flock *flp; struct flock *flp, fl;
struct filedesc *fdp = p->p_fd; struct filedesc *fdp = p->p_fd;
struct file *fp; struct file *fp;
int cmd; int cmd, error;
off_t off; off_t off;
caddr_t sg = stackgap_init(p, 0); caddr_t sg = stackgap_init(p, 0);
@ -1730,36 +1711,40 @@ xenix_sys_locking(l, v, retval)
if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL) if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
return (EBADF); return (EBADF);
FILE_USE(fp);
off = fp->f_offset; off = fp->f_offset;
FILE_UNUSE(fp, p);
flp = stackgap_alloc(p, &sg, sizeof(*flp)); fl.l_start = off;
flp->l_start = off;
switch SCARG(uap, blk) { switch SCARG(uap, blk) {
case X_LK_UNLCK: case X_LK_UNLCK:
cmd = F_SETLK; cmd = F_SETLK;
flp->l_type = F_UNLCK; fl.l_type = F_UNLCK;
break; break;
case X_LK_LOCK: case X_LK_LOCK:
cmd = F_SETLKW; cmd = F_SETLKW;
flp->l_type = F_WRLCK; fl.l_type = F_WRLCK;
break; break;
case X_LK_NBRLCK: case X_LK_NBRLCK:
cmd = F_SETLK; cmd = F_SETLK;
flp->l_type = F_RDLCK; fl.l_type = F_RDLCK;
break; break;
case X_LK_NBLCK: case X_LK_NBLCK:
cmd = F_SETLK; cmd = F_SETLK;
flp->l_type = F_WRLCK; fl.l_type = F_WRLCK;
break; break;
default: default:
return EINVAL; return EINVAL;
} }
flp->l_len = SCARG(uap, size); fl.l_len = SCARG(uap, size);
flp->l_whence = SEEK_SET; fl.l_whence = SEEK_SET;
flp = stackgap_alloc(p, &sg, sizeof(*flp));
if ((error = copyout(&fl, flp, sizeof(*flp))) != 0)
return error;
SCARG(&fa, fd) = SCARG(uap, fd); SCARG(&fa, fd) = SCARG(uap, fd);
SCARG(&fa, cmd) = cmd; SCARG(&fa, cmd) = cmd;
SCARG(&fa, arg) = (void *)flp; SCARG(&fa, arg) = flp;
return sys_fcntl(l, &fa, retval); return sys_fcntl(l, &fa, retval);
} }