summaryrefslogtreecommitdiff
path: root/sys/compat/linux
diff options
context:
space:
mode:
authordsl <dsl@NetBSD.org>2007-05-13 11:04:11 +0000
committerdsl <dsl@NetBSD.org>2007-05-13 11:04:11 +0000
commit2cc0d0a9c41cc04698d779a33b6076846c734059 (patch)
treec9ea701663b72135a72fbc1dce31c19e445f0028 /sys/compat/linux
parent9a585a457d8db167e6996348a7e7af55cc5ac178 (diff)
Stop using the stackgap for time functions.
Diffstat (limited to 'sys/compat/linux')
-rw-r--r--sys/compat/linux/common/linux_time.c139
1 files changed, 38 insertions, 101 deletions
diff --git a/sys/compat/linux/common/linux_time.c b/sys/compat/linux/common/linux_time.c
index ad656b18957..c3e6d470da5 100644
--- a/sys/compat/linux/common/linux_time.c
+++ b/sys/compat/linux/common/linux_time.c
@@ -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)
- 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)
+ error = nanosleep1(l, &rqts, SCARG(uap, rmtp) ? &rmts : 0);
+ if (SCARG(uap, rmtp) == NULL || (error != 0 && error != EINTR))
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;
}