git: 22f93edf2014 - main - kern_time.c: add kern_ and user_ implementations
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 10 Nov 2026 15:54:42 UTC
The branch main has been updated by brooks:
URL: https://cgit.FreeBSD.org/src/commit/?id=22f93edf2014e39cc96822d1bf2e4804350f266f
commit 22f93edf2014e39cc96822d1bf2e4804350f266f
Author: Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2025-11-24 15:58:25 +0000
Commit: Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2026-11-10 15:54:20 +0000
kern_time.c: add kern_ and user_ implementations
Expose user_clock_nanosleep globally.
Effort: CHERI upstreaming
Sponsored by: Innovate UK
Pull Request: https://github.com/freebsd/freebsd-src/pull/2284
---
sys/kern/kern_time.c | 35 ++++++++++++++++++++++-------------
sys/sys/syscallsubr.h | 7 +++++++
2 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c
index b9daad17c639..0e637299ae53 100644
--- a/sys/kern/kern_time.c
+++ b/sys/kern/kern_time.c
@@ -86,9 +86,6 @@ static uma_zone_t itimer_zone = NULL;
static int settime(struct thread *, struct timeval *);
static void timevalfix(struct timeval *);
-static int user_clock_nanosleep(struct thread *td, clockid_t clock_id,
- int flags, const struct timespec *ua_rqtp,
- struct timespec *ua_rmtp);
static void itimer_start(void *);
static int itimer_init(void *, int, int);
@@ -631,7 +628,6 @@ struct nanosleep_args {
int
sys_nanosleep(struct thread *td, struct nanosleep_args *uap)
{
-
return (user_clock_nanosleep(td, CLOCK_REALTIME, TIMER_RELTIME,
uap->rqtp, uap->rmtp));
}
@@ -655,7 +651,7 @@ sys_clock_nanosleep(struct thread *td, struct clock_nanosleep_args *uap)
return (kern_posix_error(td, error));
}
-static int
+int
user_clock_nanosleep(struct thread *td, clockid_t clock_id, int flags,
const struct timespec *ua_rqtp, struct timespec *ua_rmtp)
{
@@ -683,19 +679,25 @@ struct gettimeofday_args {
/* ARGSUSED */
int
sys_gettimeofday(struct thread *td, struct gettimeofday_args *uap)
+{
+ return (kern_gettimeofday(td, uap->tp, uap->tzp));
+}
+
+int
+kern_gettimeofday(struct thread *td, struct timeval *tp, struct timezone *tzp)
{
struct timeval atv;
struct timezone rtz;
int error = 0;
- if (uap->tp) {
+ if (tp) {
microtime(&atv);
- error = copyout(&atv, uap->tp, sizeof (atv));
+ error = copyout(&atv, tp, sizeof(atv));
}
- if (error == 0 && uap->tzp != NULL) {
+ if (error == 0 && tzp != NULL) {
rtz.tz_minuteswest = 0;
rtz.tz_dsttime = 0;
- error = copyout(&rtz, uap->tzp, sizeof (rtz));
+ error = copyout(&rtz, tzp, sizeof(rtz));
}
return (error);
}
@@ -709,20 +711,27 @@ struct settimeofday_args {
/* ARGSUSED */
int
sys_settimeofday(struct thread *td, struct settimeofday_args *uap)
+{
+ return (user_settimeofday(td, uap->tv, uap->tzp));
+}
+
+int
+user_settimeofday(struct thread *td, const struct timeval *tv,
+ const struct timezone *tz)
{
struct timeval atv, *tvp;
struct timezone atz, *tzp;
int error;
- if (uap->tv) {
- error = copyin(uap->tv, &atv, sizeof(atv));
+ if (tv) {
+ error = copyin(tv, &atv, sizeof(atv));
if (error)
return (error);
tvp = &atv;
} else
tvp = NULL;
- if (uap->tzp) {
- error = copyin(uap->tzp, &atz, sizeof(atz));
+ if (tz) {
+ error = copyin(tz, &atz, sizeof(atz));
if (error)
return (error);
tzp = &atz;
diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h
index 3b4a0b1fa190..200ed205557c 100644
--- a/sys/sys/syscallsubr.h
+++ b/sys/sys/syscallsubr.h
@@ -271,6 +271,8 @@ int kern_getsid(struct thread *td, pid_t pid);
int kern_getsockname(struct thread *td, int fd, struct sockaddr *sa);
int kern_getsockopt(struct thread *td, int s, int level, int name,
void *optval, enum uio_seg valseg, socklen_t *valsize);
+int kern_gettimeofday(struct thread *td, struct timeval *tp,
+ struct timezone *tzp);
int kern_ioctl(struct thread *td, int fd, u_long com, caddr_t data);
int kern_jail(struct thread *td, struct jail *j);
int kern_jail_get(struct thread *td, struct uio *options, int flags);
@@ -528,6 +530,9 @@ int kern_socketpair(struct thread *td, int domain, int type, int protocol,
int *rsv);
int kern_unmount(struct thread *td, const char *path, uint64_t flags);
+int user_clock_nanosleep(struct thread *td, clockid_t clock_id,
+ int flags, const struct timespec *ua_rqtp,
+ struct timespec *ua_rmtp);
int user_cpuset_getaffinity(struct thread *td, cpulevel_t level,
cpuwhich_t which, id_t id, size_t cpusetsize, cpuset_t *maskp,
const struct cpuset_copy_cb *cb);
@@ -544,6 +549,8 @@ int user_jail_set(struct thread *td, struct iovec *iovp,
unsigned int iovcnt, int flags, copyinuio_t *copyinuio_f);
int user_kldload(struct thread *td, const char *file);
int user_setgroups(struct thread *td, int gidsetsize, const gid_t *gidset);
+int user_settimeofday(struct thread *td, const struct timeval *tv,
+ const struct timezone *tz);
int user_sigprocmask(struct thread *td, int how, const sigset_t *uset,
sigset_t *uoset);
int user_sigsuspend(struct thread *td, const sigset_t *sigmask);