The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=56a4d1a4cc151cf8356704aafd2d2ec0fd009701
commit 56a4d1a4cc151cf8356704aafd2d2ec0fd009701 Author: Konstantin Belousov <k...@freebsd.org> AuthorDate: 2025-06-04 05:41:47 +0000 Commit: Konstantin Belousov <k...@freebsd.org> CommitDate: 2025-06-04 11:24:20 +0000 ktrace: trace and decode thr_new() thr_param Sponsored by: The FreeBSD Foundation MFC after: 1 week --- sys/kern/kern_thr.c | 8 ++++++++ sys/sys/ktrace.h | 2 ++ usr.bin/kdump/kdump.c | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/sys/kern/kern_thr.c b/sys/kern/kern_thr.c index 7863e40e73af..8ad885b42ebe 100644 --- a/sys/kern/kern_thr.c +++ b/sys/kern/kern_thr.c @@ -26,11 +26,15 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "opt_ktrace.h" #include "opt_posix.h" #include "opt_hwpmc_hooks.h" #include <sys/systm.h> #include <sys/kernel.h> +#ifdef KTRACE +#include <sys/ktrace.h> +#endif #include <sys/limits.h> #include <sys/lock.h> #include <sys/mutex.h> @@ -188,6 +192,10 @@ kern_thr_new(struct thread *td, struct thr_param *param) return (error); rtpp = &rtp; } +#ifdef KTRACE + if (KTRPOINT(td, KTR_STRUCT)) + ktrthrparam(param); +#endif return (thread_create(td, rtpp, thr_new_initthr, param)); } diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h index dba650c72494..822822a6ffe7 100644 --- a/sys/sys/ktrace.h +++ b/sys/sys/ktrace.h @@ -371,6 +371,8 @@ void ktrdata(int, const void *, size_t); ktrstruct("cpuset_t", (s), l) #define ktrsplice(s) \ ktrstruct("splice", (s), sizeof(struct splice)) +#define ktrthrparam(s) \ + ktrstruct("thrparam", (s), sizeof(struct thr_param)) extern u_int ktr_geniosize; #ifdef KTRACE extern int ktr_filesize_limit_signal; diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c index 86df45acdf05..9cc22d382de5 100644 --- a/usr.bin/kdump/kdump.c +++ b/usr.bin/kdump/kdump.c @@ -50,6 +50,7 @@ #include <sys/socket.h> #include <sys/stat.h> #include <sys/sysent.h> +#include <sys/thr.h> #include <sys/umtx.h> #include <sys/un.h> #include <sys/queue.h> @@ -109,6 +110,7 @@ static void ktrsockaddr(struct sockaddr *); static void ktrsplice(struct splice *); static void ktrstat(struct stat *); static void ktrstruct(char *, size_t); +static void ktrthrparam(struct thr_param *); static void ktrcapfail(struct ktr_cap_fail *); static void ktrfault(struct ktr_fault *); static void ktrfaultend(struct ktr_faultend *); @@ -1952,6 +1954,18 @@ ktrsplice(struct splice *sp) (intmax_t)sp->sp_idle.tv_usec); } +static void +ktrthrparam(struct thr_param *tp) +{ + printf("thr param { start=%p arg=%p stack_base=%p " + "stack_size=%#zx tls_base=%p tls_size=%#zx child_tidp=%p " + "parent_tidp=%p flags=", + tp->start_func, tp->arg, tp->stack_base, tp->stack_size, + tp->tls_base, tp->tls_size, tp->child_tid, tp->parent_tid); + print_mask_arg(sysdecode_thr_create_flags, tp->flags); + printf(" rtp=%p }\n", tp->rtp); +} + static void ktrstat(struct stat *statp) { @@ -2147,6 +2161,13 @@ ktrstruct(char *buf, size_t buflen) goto invalid; memcpy(&sp, data, datalen); ktrsplice(&sp); + } else if (strcmp(name, "thrparam") == 0) { + struct thr_param tp; + + if (datalen != sizeof(tp)) + goto invalid; + memcpy(&tp, data, datalen); + ktrthrparam(&tp); } else { #ifdef SYSDECODE_HAVE_LINUX if (ktrstruct_linux(name, data, datalen) == false)