From 82f12b623790126df303a34e4411b60d2dbef6bb Mon Sep 17 00:00:00 2001 From: kib Date: Sat, 20 Jul 2013 13:39:41 +0000 Subject: [PATCH] id_t is 64bit, provide the compat32 wrapper for clock_getcpuclockid2(2). Reported and tested by: Petr Salinger PR: threads/180652 Sponsored by: The FreeBSD Foundation --- sys/compat/freebsd32/freebsd32_misc.c | 14 +++++++++++ sys/compat/freebsd32/syscalls.master | 5 ++-- sys/kern/kern_time.c | 36 ++++++++++++++++----------- sys/sys/syscallsubr.h | 2 ++ 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/sys/compat/freebsd32/freebsd32_misc.c b/sys/compat/freebsd32/freebsd32_misc.c index dd8d4f742ca..cfcd83b7c5e 100644 --- a/sys/compat/freebsd32/freebsd32_misc.c +++ b/sys/compat/freebsd32/freebsd32_misc.c @@ -2331,6 +2331,20 @@ freebsd32_clock_getres(struct thread *td, return (error); } +int +freebsd32_clock_getcpuclockid2(struct thread *td, + struct freebsd32_clock_getcpuclockid2_args *uap) +{ + clockid_t clk_id; + int error; + + error = kern_clock_getcpuclockid2(td, PAIR32TO64(id_t, uap->id), + uap->which, &clk_id); + if (error == 0) + error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t)); + return (error); +} + int freebsd32_thr_new(struct thread *td, struct freebsd32_thr_new_args *uap) diff --git a/sys/compat/freebsd32/syscalls.master b/sys/compat/freebsd32/syscalls.master index bcca754b28b..6cb649f68e1 100644 --- a/sys/compat/freebsd32/syscalls.master +++ b/sys/compat/freebsd32/syscalls.master @@ -457,8 +457,9 @@ 244 AUE_NULL UNIMPL nosys 245 AUE_NULL UNIMPL nosys 246 AUE_NULL UNIMPL nosys -247 AUE_NULL NOPROTO { int clock_getcpuclockid2(id_t id,\ - int which, clockid_t *clock_id); } +247 AUE_NULL STD { int freebsd32_clock_getcpuclockid2(\ + uint32_t id1, uint32_t id2,\ + int which, clockid_t *clock_id); } 248 AUE_NULL UNIMPL ntp_gettime 249 AUE_NULL UNIMPL nosys ; syscall numbers initially used in OpenBSD diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 9e0cc068778..6b908a095d4 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -183,38 +183,46 @@ int sys_clock_getcpuclockid2(struct thread *td, struct clock_getcpuclockid2_args *uap) { clockid_t clk_id; + int error; + + error = kern_clock_getcpuclockid2(td, uap->id, uap->which, &clk_id); + if (error == 0) + error = copyout(&clk_id, uap->clock_id, sizeof(clockid_t)); + return (error); +} + +int +kern_clock_getcpuclockid2(struct thread *td, id_t id, int which, + clockid_t *clk_id) +{ struct proc *p; pid_t pid; lwpid_t tid; int error; - switch(uap->which) { + switch (which) { case CPUCLOCK_WHICH_PID: - if (uap->id != 0) { - p = pfind(uap->id); + if (id != 0) { + p = pfind(id); if (p == NULL) return (ESRCH); error = p_cansee(td, p); PROC_UNLOCK(p); - if (error) + if (error != 0) return (error); - pid = uap->id; + pid = id; } else { pid = td->td_proc->p_pid; } - clk_id = MAKE_PROCESS_CPUCLOCK(pid); - break; + *clk_id = MAKE_PROCESS_CPUCLOCK(pid); + return (0); case CPUCLOCK_WHICH_TID: - if (uap->id == 0) - tid = td->td_tid; - else - tid = uap->id; - clk_id = MAKE_THREAD_CPUCLOCK(tid); - break; + tid = id == 0 ? td->td_tid : id; + *clk_id = MAKE_THREAD_CPUCLOCK(tid); + return (0); default: return (EINVAL); } - return (copyout(&clk_id, uap->clock_id, sizeof(clockid_t))); } #ifndef _SYS_SYSPROTO_H_ diff --git a/sys/sys/syscallsubr.h b/sys/sys/syscallsubr.h index 49e8be1b7fe..75278c346e8 100644 --- a/sys/sys/syscallsubr.h +++ b/sys/sys/syscallsubr.h @@ -76,6 +76,8 @@ int kern_chmod(struct thread *td, char *path, enum uio_seg pathseg, int mode); int kern_chown(struct thread *td, char *path, enum uio_seg pathseg, int uid, int gid); +int kern_clock_getcpuclockid2(struct thread *td, id_t id, int which, + clockid_t *clk_id); int kern_clock_getres(struct thread *td, clockid_t clock_id, struct timespec *ts); int kern_clock_gettime(struct thread *td, clockid_t clock_id, -- 2.45.0