Stop using the stackgap for time functions.

This commit is contained in:
dsl 2007-05-13 11:04:11 +00:00
parent 9a585a457d
commit 2cc0d0a9c4
1 changed files with 38 additions and 101 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: linux_time.c,v 1.17 2007/05/12 20:23:36 dsl Exp $ */
/* $NetBSD: linux_time.c,v 1.18 2007/05/13 11:04:11 dsl Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -37,14 +37,16 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.17 2007/05/12 20:23:36 dsl Exp $");
__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.18 2007/05/13 11:04:11 dsl Exp $");
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/kauth.h>
#include <sys/mount.h>
#include <sys/signal.h>
#include <sys/stdint.h>
#include <sys/time.h>
#include <sys/timetc.h>
#include <sys/systm.h>
#include <sys/syscallargs.h>
#include <sys/lwp.h>
@ -183,33 +185,21 @@ linux_sys_clock_gettime(l, v, retval)
syscallarg(clockid_t) which;
syscallarg(struct linux_timespec *)tp;
} */ *uap = v;
void *sg;
struct proc *p = l->l_proc;
struct timespec *tp, ts;
struct timespec ts;
struct linux_timespec lts;
int error;
clockid_t nwhich = 0; /* XXX: GCC */
struct sys_clock_gettime_args sga;
error = linux_to_native_clockid(&nwhich, SCARG(uap, which));
if (error != 0)
return error;
sg = stackgap_init(p, 0);
tp = stackgap_alloc(p, &sg, sizeof *tp);
SCARG(&sga, clock_id) = nwhich;
SCARG(&sga, tp) = tp;
error = sys_clock_gettime(l, &sga, retval);
if (error != 0)
return error;
error = copyin(tp, &ts, sizeof ts);
if (error != 0)
return error;
switch (SCARG(uap, which)) {
case LINUX_CLOCK_REALTIME:
nanotime(&ts);
break;
case LINUX_CLOCK_MONOTONIC:
nanouptime(&ts);
break;
default:
return EINVAL;
}
native_to_linux_timespec(&lts, &ts);
return copyout(&lts, SCARG(uap, tp), sizeof lts);
}
@ -223,17 +213,16 @@ linux_sys_clock_settime(l, v, retval)
syscallarg(clockid_t) which;
syscallarg(struct linux_timespec *)tp;
} */ *uap = v;
void *sg;
struct proc *p = l->l_proc;
struct timespec *tp, ts;
struct timespec ts;
struct linux_timespec lts;
int error;
clockid_t nwhich = 0; /* XXX: GCC */
struct sys_clock_settime_args sta;
error = linux_to_native_clockid(&nwhich, SCARG(uap, which));
if (error != 0)
return error;
switch (SCARG(uap, which)) {
case LINUX_CLOCK_REALTIME:
break;
default:
return EINVAL;
}
error = copyin(SCARG(uap, tp), &lts, sizeof lts);
if (error != 0)
@ -241,16 +230,12 @@ linux_sys_clock_settime(l, v, retval)
linux_to_native_timespec(&ts, &lts);
sg = stackgap_init(p, 0);
tp = stackgap_alloc(p, &sg, sizeof *tp);
error = copyout(&ts, tp, sizeof ts);
error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_TIME,
KAUTH_REQ_SYSTEM_TIME_SYSTEM, NULL, NULL, NULL);
if (error != 0)
return error;
return (error);
SCARG(&sta, clock_id) = nwhich;
SCARG(&sta, tp) = tp;
return sys_clock_settime(l, &sta, retval);
return settime(l->l_proc, &ts);
}
int
@ -263,41 +248,19 @@ linux_sys_clock_getres(l, v, retval)
syscallarg(clockid_t) which;
syscallarg(struct linux_timespec *)tp;
} */ *uap = v;
void *sg;
struct proc *p = l->l_proc;
struct timespec *tp, ts;
struct timespec ts;
struct linux_timespec lts;
int error;
clockid_t nwhich = 0; /* XXX: GCC */
struct sys_clock_gettime_args sga;
error = linux_to_native_clockid(&nwhich, SCARG(uap, which));
if (error != 0)
if (error != 0 || SCARG(uap, tp) == NULL)
return error;
if (SCARG(uap, tp) != NULL) {
sg = stackgap_init(p, 0);
tp = stackgap_alloc(p, &sg, sizeof *tp);
} else
tp = NULL;
SCARG(&sga, clock_id) = nwhich;
SCARG(&sga, tp) = tp;
error = sys_clock_getres(l, &sga, retval);
if (error != 0)
return error;
if (tp != NULL) {
error = copyin(tp, &ts, sizeof ts);
if (error != 0)
return error;
native_to_linux_timespec(&lts, &ts);
return copyout(&lts, SCARG(uap, tp), sizeof lts);
}
return 0;
ts.tv_sec = 0;
ts.tv_nsec = 1000000000 / tc_getfrequency();
native_to_linux_timespec(&lts, &ts);
return copyout(&lts, SCARG(uap, tp), sizeof lts);
}
int
@ -312,13 +275,9 @@ linux_sys_clock_nanosleep(l, v, retval)
syscallarg(struct linux_timespec) *rqtp;
syscallarg(struct linux_timespec) *rmtp;
} */ *uap = v;
void *sg;
struct proc *p = l->l_proc;
struct timespec *rqtp, *rmtp;
struct linux_timespec lrqts, lrmts;
struct timespec rqts, rmts;
int error;
struct sys_nanosleep_args sna;
int error, error1;
if (SCARG(uap, flags) != 0)
return EINVAL; /* XXX deal with TIMER_ABSTIME */
@ -332,33 +291,11 @@ linux_sys_clock_nanosleep(l, v, retval)
linux_to_native_timespec(&rqts, &lrqts);
sg = stackgap_init(p, 0);
rqtp = stackgap_alloc(p, &sg, sizeof *rqtp);
error = copyout(&rqts, rqtp, sizeof rqts);
if (error != 0)
error = nanosleep1(l, &rqts, SCARG(uap, rmtp) ? &rmts : 0);
if (SCARG(uap, rmtp) == NULL || (error != 0 && error != EINTR))
return error;
if (SCARG(uap, rmtp) != NULL)
rmtp = stackgap_alloc(p, &sg, sizeof *rmtp);
else
rmtp = NULL;
SCARG(&sna, rqtp) = rqtp;
SCARG(&sna, rmtp) = rmtp;
error = sys_nanosleep(l, &sna, retval);
if (error != 0)
return error;
if (rmtp != NULL) {
error = copyin(rmtp, &rmts, sizeof rmts);
if (error != 0)
return error;
native_to_linux_timespec(&lrmts, &rmts);
error = copyout(&lrmts, SCARG(uap, rmtp), sizeof lrmts);
if (error != 0)
return error;
}
return 0;
native_to_linux_timespec(&lrmts, &rmts);
error1 = copyout(&lrmts, SCARG(uap, rmtp), sizeof lrmts);
return error1 ? error1 : error;
}