From: guenther Date: Thu, 29 Dec 2022 01:36:36 +0000 (+0000) Subject: Add ktrace struct tracepoints for siginfo_t to the kernel side of X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=79b24ea90edecf7f745b546b8a41493da0ed16dd;p=openbsd Add ktrace struct tracepoints for siginfo_t to the kernel side of waitid(2) and __thrsigdivert(2) and teach kdump(1) to handle them. Also report more from the siginfo_t inside PSIG tracepoints. ok mpi@ --- diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index afdba76e21d..7860c65eeda 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_exit.c,v 1.209 2022/12/19 00:22:12 guenther Exp $ */ +/* $OpenBSD: kern_exit.c,v 1.210 2022/12/29 01:36:36 guenther Exp $ */ /* $NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $ */ /* @@ -692,8 +692,13 @@ sys_waitid(struct proc *q, void *v, register_t *retval) error = dowait6(q, idtype, SCARG(uap, id), NULL, options, NULL, &info, retval); - if (error == 0) + if (error == 0) { error = copyout(&info, SCARG(uap, info), sizeof(info)); +#ifdef KTRACE + if (error == 0 && KTRPOINT(q, KTR_STRUCT)) + ktrsiginfo(q, &info); +#endif + } if (error == 0) *retval = 0; return (error); diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 1b943e139e7..f3e2761a78d 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sig.c,v 1.301 2022/10/16 16:27:02 deraadt Exp $ */ +/* $OpenBSD: kern_sig.c,v 1.302 2022/12/29 01:36:36 guenther Exp $ */ /* $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $ */ /* @@ -1875,8 +1875,13 @@ sys___thrsigdivert(struct proc *p, void *v, register_t *retval) if (error == 0) { *retval = si.si_signo; - if (SCARG(uap, info) != NULL) + if (SCARG(uap, info) != NULL) { error = copyout(&si, SCARG(uap, info), sizeof(si)); +#ifdef KTRACE + if (error == 0 && KTRPOINT(p, KTR_STRUCT)) + ktrsiginfo(p, &si); +#endif + } } else if (error == ERESTART && SCARG(uap, timeout) != NULL) { /* * Restarting is wrong if there's a timeout, as it'll be diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index d16ce8b8982..2c590b22078 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ktrace.h,v 1.42 2022/09/02 13:18:07 mbuhl Exp $ */ +/* $OpenBSD: ktrace.h,v 1.43 2022/12/29 01:36:36 guenther Exp $ */ /* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */ /* @@ -253,5 +253,7 @@ void ktrstruct(struct proc *, const char *, const void *, size_t); ktrstruct(p, "fds", fds, (count) * sizeof(int)) #define ktrflock(p, fl) \ ktrstruct(p, "flock", (fl), sizeof(struct flock)) +#define ktrsiginfo(p, si) \ + ktrstruct(p, "siginfo", (si), sizeof(siginfo_t)) #endif /* !_KERNEL */ diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 03b9368ac32..ed9d3449d11 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kdump.c,v 1.152 2022/12/20 21:44:19 guenther Exp $ */ +/* $OpenBSD: kdump.c,v 1.153 2022/12/29 01:36:36 guenther Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -1320,60 +1320,84 @@ ktrgenio(struct ktr_genio *ktr, size_t len) showbuf(dp, datalen); } -static void -ktrpsig(struct ktr_psig *psig) +void +siginfo(const siginfo_t *si, int show_signo) { - signame(psig->signo); - printf(" "); - if (psig->action == SIG_DFL) - (void)printf("SIG_DFL"); - else { - (void)printf("caught handler=0x%lx mask=", - (u_long)psig->action); - sigset(psig->mask); + if (show_signo) { + printf("signo="); + signame(si->si_signo); } - if (psig->code) { - printf(" code "); - if (fancy) { - switch (psig->signo) { + if (si->si_code) { + printf(" code="); + if (!fancy) + printf("<%d>", si->si_code); + else { + switch (si->si_signo) { case SIGILL: - sigill_name(psig->code); + sigill_name(si->si_code); break; case SIGTRAP: - sigtrap_name(psig->code); + sigtrap_name(si->si_code); break; case SIGEMT: - sigemt_name(psig->code); + sigemt_name(si->si_code); break; case SIGFPE: - sigfpe_name(psig->code); + sigfpe_name(si->si_code); break; case SIGBUS: - sigbus_name(psig->code); + sigbus_name(si->si_code); break; case SIGSEGV: - sigsegv_name(psig->code); + sigsegv_name(si->si_code); break; case SIGCHLD: - sigchld_name(psig->code); + sigchld_name(si->si_code); + break; + default: + printf("<%d>", si->si_code); break; } } - printf("<%d>", psig->code); } - switch (psig->signo) { + switch (si->si_signo) { case SIGSEGV: case SIGILL: case SIGBUS: case SIGFPE: - printf(" addr=%p trapno=%d", psig->si.si_addr, - psig->si.si_trapno); + printf(" addr=%p trapno=%d", si->si_addr, si->si_trapno); + break; + case SIGCHLD: + if (si->si_code == CLD_EXITED) { + printf(" status=%d", si->si_status); + if (si->si_status < 0 || si->si_status > 9) + (void)printf("/%#x", si->si_status); + } else { + printf(" status="); + signame(si->si_status); + } + printf(" pid=%d uid=", si->si_pid); + uidname(si->si_uid); break; default: break; } - printf("\n"); +} + +static void +ktrpsig(struct ktr_psig *psig) +{ + signame(psig->signo); + printf(" "); + if (psig->action == SIG_DFL) + printf("SIG_DFL"); + else { + printf("caught handler=0x%lx mask=", (u_long)psig->action); + sigset(psig->mask); + } + siginfo(&psig->si, 0); + putchar('\n'); } static void diff --git a/usr.bin/kdump/kdump.h b/usr.bin/kdump/kdump.h index 812a81364b1..2d17272f20b 100644 --- a/usr.bin/kdump/kdump.h +++ b/usr.bin/kdump/kdump.h @@ -20,6 +20,7 @@ const char *ioctlname(unsigned long); /* kdump.c */ void sigset(int); void showbufc(int _column, unsigned char *_dp, size_t _len, int _flags); +void siginfo(const siginfo_t *_si, int _show_signo); /* ktrstruct.c */ void ktrstruct(char *, size_t); diff --git a/usr.bin/kdump/ktrstruct.c b/usr.bin/kdump/ktrstruct.c index a036f331706..88fedd4663d 100644 --- a/usr.bin/kdump/ktrstruct.c +++ b/usr.bin/kdump/ktrstruct.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ktrstruct.c,v 1.30 2022/09/08 16:04:31 mbuhl Exp $ */ +/* $OpenBSD: ktrstruct.c,v 1.31 2022/12/29 01:36:36 guenther Exp $ */ /*- * Copyright (c) 1988, 1993 @@ -550,6 +550,14 @@ ktrflock(const struct flock *fl) printf(" }\n"); } +static void +ktrsiginfo(const siginfo_t *si) +{ + printf("siginfo_t { "); + siginfo(si, 1); + printf(" }\n"); +} + void ktrstruct(char *buf, size_t buflen) { @@ -710,6 +718,13 @@ ktrstruct(char *buf, size_t buflen) goto invalid; memcpy(&fl, data, datalen); ktrflock(&fl); + } else if (strcmp(name, "siginfo") == 0) { + siginfo_t si; + + if (datalen != sizeof(si)) + goto invalid; + memcpy(&si, data, datalen); + ktrsiginfo(&si); } else { printf("unknown structure %s\n", name); }