From a984a0c3bbe9bd26145da0f9cdbbc52b679f5629 Mon Sep 17 00:00:00 2001 From: guenther Date: Fri, 26 Jul 2024 19:16:31 +0000 Subject: [PATCH] Trace struct itimerval ok deraadt@ claudio@ --- sys/kern/kern_time.c | 25 ++++++++++++++++++++----- sys/sys/ktrace.h | 4 +++- usr.bin/kdump/ktrstruct.c | 21 ++++++++++++++++++++- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index a34fb245cca..5997861d0c5 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_time.c,v 1.168 2024/07/08 13:17:12 claudio Exp $ */ +/* $OpenBSD: kern_time.c,v 1.169 2024/07/26 19:16:31 guenther Exp $ */ /* $NetBSD: kern_time.c,v 1.20 1996/02/18 11:57:06 fvdl Exp $ */ /* @@ -602,7 +602,7 @@ sys_getitimer(struct proc *p, void *v, register_t *retval) syscallarg(struct itimerval *) itv; } */ *uap = v; struct itimerval aitv; - int which; + int which, error; which = SCARG(uap, which); if (which < ITIMER_REAL || which > ITIMER_PROF) @@ -612,7 +612,12 @@ sys_getitimer(struct proc *p, void *v, register_t *retval) setitimer(which, NULL, &aitv); - return copyout(&aitv, SCARG(uap, itv), sizeof(aitv)); + error = copyout(&aitv, SCARG(uap, itv), sizeof(aitv)); +#ifdef KTRACE + if (error == 0 && KTRPOINT(p, KTR_STRUCT)) + ktritimerval(p, &aitv); +#endif + return (error); } int @@ -636,6 +641,10 @@ sys_setitimer(struct proc *p, void *v, register_t *retval) error = copyin(SCARG(uap, itv), &aitv, sizeof(aitv)); if (error) return error; +#ifdef KTRACE + if (KTRPOINT(p, KTR_STRUCT)) + ktritimerval(p, &aitv); +#endif error = itimerfix(&aitv); if (error) return error; @@ -650,8 +659,14 @@ sys_setitimer(struct proc *p, void *v, register_t *retval) setitimer(which, newitvp, olditvp); - if (SCARG(uap, oitv) != NULL) - return copyout(&olditv, SCARG(uap, oitv), sizeof(olditv)); + if (SCARG(uap, oitv) != NULL) { + error = copyout(&olditv, SCARG(uap, oitv), sizeof(olditv)); +#ifdef KTRACE + if (error == 0 && KTRPOINT(p, KTR_STRUCT)) + ktritimerval(p, &aitv); +#endif + return error; + } return 0; } diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index be284143108..99cfafa0944 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ktrace.h,v 1.48 2023/12/15 15:12:08 deraadt Exp $ */ +/* $OpenBSD: ktrace.h,v 1.49 2024/07/26 19:16:31 guenther Exp $ */ /* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */ /* @@ -241,6 +241,8 @@ void ktrstruct(struct proc *, const char *, const void *, size_t); ktrstruct((p), "abstimeval", (s), sizeof(struct timeval)) #define ktrreltimeval(p, s) \ ktrstruct((p), "reltimeval", (s), sizeof(struct timeval)) +#define ktritimerval(p, s) \ + ktrstruct((p), "itimerval", (s), sizeof(struct itimerval)) #define ktrsigaction(p, s) \ ktrstruct((p), "sigaction", (s), sizeof(struct sigaction)) #define ktrrlimit(p, s) \ diff --git a/usr.bin/kdump/ktrstruct.c b/usr.bin/kdump/ktrstruct.c index 88fedd4663d..489a441df05 100644 --- a/usr.bin/kdump/ktrstruct.c +++ b/usr.bin/kdump/ktrstruct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ktrstruct.c,v 1.31 2022/12/29 01:36:36 guenther Exp $ */ +/* $OpenBSD: ktrstruct.c,v 1.32 2024/07/26 19:16:31 guenther Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -265,6 +265,18 @@ ktrtimeval(const struct timeval *tvp, int relative) printf(" }\n"); } +static void +ktritimerval(const struct itimerval *itvp) +{ + printf("struct itimerval { value="); + print_timeval(&itvp->it_value, 0); + if (timerisset(&itvp->it_interval)) { + printf(", interval="); + print_timeval(&itvp->it_interval, 1); + } + printf(" }\n"); +} + static void ktrsigaction(const struct sigaction *sa) { @@ -615,6 +627,13 @@ ktrstruct(char *buf, size_t buflen) goto invalid; memcpy(&tv, data, datalen); ktrtimeval(&tv, name[0] == 'r'); + } else if (strcmp(name, "itimerval") == 0) { + struct itimerval itv; + + if (datalen != sizeof(itv)) + goto invalid; + memcpy(&itv, data, datalen); + ktritimerval(&itv); } else if (strcmp(name, "sigaction") == 0) { struct sigaction sa; -- 2.20.1