Remove some more uses of the 'stackgap' - the code is a lot simpler if

we just access stuff like l->l_proc->p_stats->p_ru instead of copying it
to and from userspace.
This commit is contained in:
dsl 2007-05-12 14:09:34 +00:00
parent 920d7a6afe
commit 76bef02b3a
3 changed files with 82 additions and 230 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: osf1_resource.c,v 1.7 2007/03/04 06:01:28 christos Exp $ */
/* $NetBSD: osf1_resource.c,v 1.8 2007/05/12 14:09:34 dsl Exp $ */
/*
* Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: osf1_resource.c,v 1.7 2007/03/04 06:01:28 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: osf1_resource.c,v 1.8 2007/05/12 14:09:34 dsl Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -94,20 +94,16 @@ osf1_sys_getrusage(l, v, retval)
register_t *retval;
{
struct osf1_sys_getrusage_args *uap = v;
struct proc *p = l->l_proc;
struct sys_getrusage_args a;
struct osf1_rusage osf1_rusage;
struct rusage netbsd_rusage;
void *sg;
int error;
struct rusage *netbsd_rusage;
switch (SCARG(uap, who)) {
case OSF1_RUSAGE_SELF:
SCARG(&a, who) = RUSAGE_SELF;
netbsd_rusage = &l->l_proc->p_stats->p_ru;
break;
case OSF1_RUSAGE_CHILDREN:
SCARG(&a, who) = RUSAGE_CHILDREN;
netbsd_rusage = &l->l_proc->p_stats->p_cru;
break;
case OSF1_RUSAGE_THREAD: /* XXX not supported */
@ -115,20 +111,8 @@ osf1_sys_getrusage(l, v, retval)
return (EINVAL);
}
sg = stackgap_init(p, 0);
SCARG(&a, rusage) = stackgap_alloc(p, &sg, sizeof netbsd_rusage);
error = sys_getrusage(l, &a, retval);
if (error == 0)
error = copyin((void *)SCARG(&a, rusage),
(void *)&netbsd_rusage, sizeof netbsd_rusage);
if (error == 0) {
osf1_cvt_rusage_from_native(&netbsd_rusage, &osf1_rusage);
error = copyout((void *)&osf1_rusage,
(void *)SCARG(uap, rusage), sizeof osf1_rusage);
}
return (error);
osf1_cvt_rusage_from_native(netbsd_rusage, &osf1_rusage);
return copyout(&osf1_rusage, SCARG(uap, rusage), sizeof osf1_rusage);
}
int

View File

@ -1,4 +1,4 @@
/* $NetBSD: svr4_misc.c,v 1.129 2007/05/07 16:53:19 dsl Exp $ */
/* $NetBSD: svr4_misc.c,v 1.130 2007/05/12 14:09:34 dsl Exp $ */
/*-
* Copyright (c) 1994 The NetBSD Foundation, Inc.
@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: svr4_misc.c,v 1.129 2007/05/07 16:53:19 dsl Exp $");
__KERNEL_RCSID(0, "$NetBSD: svr4_misc.c,v 1.130 2007/05/12 14:09:34 dsl Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -796,40 +796,17 @@ svr4_sys_times(l, v, retval)
register_t *retval;
{
struct svr4_sys_times_args *uap = v;
struct proc *p = l->l_proc;
int error;
struct tms tms;
struct timeval t;
struct rusage *ru;
struct rusage r;
struct sys_getrusage_args ga;
void *sg = stackgap_init(p, 0);
ru = stackgap_alloc(p, &sg, sizeof(struct rusage));
ru = &l->l_proc->p_stats->p_ru;
tms.tms_utime = timeval_to_clock_t(&ru->ru_utime);
tms.tms_stime = timeval_to_clock_t(&ru->ru_stime);
SCARG(&ga, who) = RUSAGE_SELF;
SCARG(&ga, rusage) = ru;
error = sys_getrusage(l, &ga, retval);
if (error)
return error;
if ((error = copyin(ru, &r, sizeof r)) != 0)
return error;
tms.tms_utime = timeval_to_clock_t(&r.ru_utime);
tms.tms_stime = timeval_to_clock_t(&r.ru_stime);
SCARG(&ga, who) = RUSAGE_CHILDREN;
error = sys_getrusage(l, &ga, retval);
if (error)
return error;
if ((error = copyin(ru, &r, sizeof r)) != 0)
return error;
tms.tms_cutime = timeval_to_clock_t(&r.ru_utime);
tms.tms_cstime = timeval_to_clock_t(&r.ru_stime);
ru = &l->l_proc->p_stats->p_cru;
tms.tms_cutime = timeval_to_clock_t(&ru->ru_utime);
tms.tms_cstime = timeval_to_clock_t(&ru->ru_stime);
microtime(&t);
*retval = timeval_to_clock_t(&t);
@ -846,66 +823,43 @@ svr4_sys_ulimit(l, v, retval)
{
struct svr4_sys_ulimit_args *uap = v;
struct proc *p = l->l_proc;
int error;
struct rlimit krl;
register_t r;
switch (SCARG(uap, cmd)) {
case SVR4_GFILLIM:
*retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur / 512;
if (*retval == -1)
*retval = 0x7fffffff;
return 0;
r = p->p_rlimit[RLIMIT_FSIZE].rlim_cur / 512;
break;
case SVR4_SFILLIM:
{
int error;
struct sys_setrlimit_args srl;
struct rlimit krl;
void *sg = stackgap_init(p, 0);
struct rlimit *url = (struct rlimit *)
stackgap_alloc(p, &sg, sizeof *url);
krl.rlim_cur = SCARG(uap, newlimit) * 512;
krl.rlim_max = p->p_rlimit[RLIMIT_FSIZE].rlim_max;
error = copyout(&krl, url, sizeof(*url));
error = dosetrlimit(l, l->l_proc, RLIMIT_FSIZE, &krl);
if (error)
return error;
SCARG(&srl, which) = RLIMIT_FSIZE;
SCARG(&srl, rlp) = url;
error = sys_setrlimit(l, &srl, retval);
if (error)
return error;
*retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
if (*retval == -1)
*retval = 0x7fffffff;
return 0;
}
r = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
break;
case SVR4_GMEMLIM:
{
struct vmspace *vm = p->p_vmspace;
register_t r = p->p_rlimit[RLIMIT_DATA].rlim_cur;
if (r == -1)
r = 0x7fffffff;
r += (long) vm->vm_daddr;
r = p->p_rlimit[RLIMIT_DATA].rlim_cur;
if (r > 0x7fffffff)
r = 0x7fffffff;
*retval = r;
return 0;
}
r += (long)p->p_vmspace->vm_daddr;
break;
case SVR4_GDESLIM:
*retval = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
if (*retval == -1)
*retval = 0x7fffffff;
return 0;
r = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
break;
default:
return EINVAL;
}
*retval = r > 0x7fffffff ? 0x7fffffff : r;
return 0;
}
@ -1303,38 +1257,18 @@ svr4_sys_alarm(l, v, retval)
register_t *retval;
{
struct svr4_sys_alarm_args *uap = v;
struct proc *p = l->l_proc;
int error;
struct itimerval *ntp, *otp, tp;
struct sys_setitimer_args sa;
void *sg = stackgap_init(p, 0);
struct itimerval tp;
ntp = stackgap_alloc(p, &sg, sizeof(struct itimerval));
otp = stackgap_alloc(p, &sg, sizeof(struct itimerval));
dogetitimer(l->l_proc, ITIMER_REAL, &tp);
if (tp.it_value.tv_usec)
tp.it_value.tv_sec++;
*retval = (register_t)tp.it_value.tv_sec;
timerclear(&tp.it_interval);
tp.it_value.tv_sec = SCARG(uap, sec);
tp.it_value.tv_usec = 0;
if ((error = copyout(&tp, ntp, sizeof(tp))) != 0)
return error;
SCARG(&sa, which) = ITIMER_REAL;
SCARG(&sa, itv) = ntp;
SCARG(&sa, oitv) = otp;
if ((error = sys_setitimer(l, &sa, retval)) != 0)
return error;
if ((error = copyin(otp, &tp, sizeof(tp))) != 0)
return error;
if (tp.it_value.tv_usec)
tp.it_value.tv_sec++;
*retval = (register_t) tp.it_value.tv_sec;
return 0;
return dosetitimer(l->l_proc, ITIMER_REAL, &tp);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: svr4_32_misc.c,v 1.48 2007/05/07 16:53:19 dsl Exp $ */
/* $NetBSD: svr4_32_misc.c,v 1.49 2007/05/12 14:09:35 dsl Exp $ */
/*-
* Copyright (c) 1994 The NetBSD Foundation, Inc.
@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.48 2007/05/07 16:53:19 dsl Exp $");
__KERNEL_RCSID(0, "$NetBSD: svr4_32_misc.c,v 1.49 2007/05/12 14:09:35 dsl Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -820,7 +820,6 @@ timeval_to_clock_t(tv)
return tv->tv_sec * hz + tv->tv_usec / (1000000 / hz);
}
int
svr4_32_sys_times(l, v, retval)
struct lwp *l;
@ -828,40 +827,17 @@ svr4_32_sys_times(l, v, retval)
register_t *retval;
{
struct svr4_32_sys_times_args *uap = v;
struct proc *p = l->l_proc;
int error;
struct tms tms;
struct timeval t;
struct rusage *ru;
struct rusage r;
struct sys_getrusage_args ga;
void *sg = stackgap_init(p, 0);
ru = stackgap_alloc(p, &sg, sizeof(struct rusage));
ru = &l->l_proc->p_stats->p_ru;
tms.tms_utime = timeval_to_clock_t(&ru->ru_utime);
tms.tms_stime = timeval_to_clock_t(&ru->ru_stime);
SCARG(&ga, who) = RUSAGE_SELF;
SCARG(&ga, rusage) = ru;
error = sys_getrusage(l, &ga, retval);
if (error)
return error;
if ((error = copyin(ru, &r, sizeof r)) != 0)
return error;
tms.tms_utime = timeval_to_clock_t(&r.ru_utime);
tms.tms_stime = timeval_to_clock_t(&r.ru_stime);
SCARG(&ga, who) = RUSAGE_CHILDREN;
error = sys_getrusage(l, &ga, retval);
if (error)
return error;
if ((error = copyin(ru, &r, sizeof r)) != 0)
return error;
tms.tms_cutime = timeval_to_clock_t(&r.ru_utime);
tms.tms_cstime = timeval_to_clock_t(&r.ru_stime);
ru = &l->l_proc->p_stats->p_cru;
tms.tms_cutime = timeval_to_clock_t(&ru->ru_utime);
tms.tms_cstime = timeval_to_clock_t(&ru->ru_stime);
microtime(&t);
*retval = timeval_to_clock_t(&t);
@ -878,66 +854,43 @@ svr4_32_sys_ulimit(l, v, retval)
{
struct svr4_32_sys_ulimit_args *uap = v;
struct proc *p = l->l_proc;
int error;
struct rlimit krl;
register_t r;
switch (SCARG(uap, cmd)) {
case SVR4_GFILLIM:
*retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur / 512;
if (*retval == -1)
*retval = 0x7fffffff;
return 0;
r = p->p_rlimit[RLIMIT_FSIZE].rlim_cur / 512;
break;
case SVR4_SFILLIM:
{
int error;
struct sys_setrlimit_args srl;
struct rlimit krl;
void *sg = stackgap_init(p, 0);
struct rlimit *url = (struct rlimit *)
stackgap_alloc(p, &sg, sizeof *url);
krl.rlim_cur = SCARG(uap, newlimit) * 512;
krl.rlim_max = p->p_rlimit[RLIMIT_FSIZE].rlim_max;
error = copyout(&krl, url, sizeof(*url));
error = dosetrlimit(l, l->l_proc, RLIMIT_FSIZE, &krl);
if (error)
return error;
SCARG(&srl, which) = RLIMIT_FSIZE;
SCARG(&srl, rlp) = url;
error = sys_setrlimit(l, &srl, retval);
if (error)
return error;
*retval = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
if (*retval == -1)
*retval = 0x7fffffff;
return 0;
}
r = p->p_rlimit[RLIMIT_FSIZE].rlim_cur;
break;
case SVR4_GMEMLIM:
{
struct vmspace *vm = p->p_vmspace;
register_t r = p->p_rlimit[RLIMIT_DATA].rlim_cur;
if (r == -1)
r = 0x7fffffff;
r += (long) vm->vm_daddr;
r = p->p_rlimit[RLIMIT_DATA].rlim_cur;
if (r > 0x7fffffff)
r = 0x7fffffff;
*retval = r;
return 0;
}
r += (long)p->p_vmspace->vm_daddr;
break;
case SVR4_GDESLIM:
*retval = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
if (*retval == -1)
*retval = 0x7fffffff;
return 0;
r = p->p_rlimit[RLIMIT_NOFILE].rlim_cur;
break;
default:
return EINVAL;
}
*retval = r > 0x7fffffff ? 0x7fffffff : r;
return 0;
}
@ -1330,6 +1283,7 @@ svr4_32_sys_fstatvfs64(l, v, retval)
}
int
svr4_32_sys_alarm(l, v, retval)
struct lwp *l;
@ -1337,38 +1291,18 @@ svr4_32_sys_alarm(l, v, retval)
register_t *retval;
{
struct svr4_32_sys_alarm_args *uap = v;
struct proc *p = l->l_proc;
int error;
struct itimerval *ntp, *otp, tp;
struct sys_setitimer_args sa;
void *sg = stackgap_init(p, 0);
struct itimerval tp;
ntp = stackgap_alloc(p, &sg, sizeof(struct itimerval));
otp = stackgap_alloc(p, &sg, sizeof(struct itimerval));
dogetitimer(l->l_proc, ITIMER_REAL, &tp);
if (tp.it_value.tv_usec)
tp.it_value.tv_sec++;
*retval = (register_t)tp.it_value.tv_sec;
timerclear(&tp.it_interval);
tp.it_value.tv_sec = SCARG(uap, sec);
tp.it_value.tv_usec = 0;
if ((error = copyout(&tp, ntp, sizeof(tp))) != 0)
return error;
SCARG(&sa, which) = ITIMER_REAL;
SCARG(&sa, itv) = ntp;
SCARG(&sa, oitv) = otp;
if ((error = sys_setitimer(l, &sa, retval)) != 0)
return error;
if ((error = copyin(otp, &tp, sizeof(tp))) != 0)
return error;
if (tp.it_value.tv_usec)
tp.it_value.tv_sec++;
*retval = (register_t) tp.it_value.tv_sec;
return 0;
return dosetitimer(l->l_proc, ITIMER_REAL, &tp);
}