The branch stable/14 has been updated by kib:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=0c071c3ebdf12438fd880fa81a7fd5c93130c59d

commit 0c071c3ebdf12438fd880fa81a7fd5c93130c59d
Author:     Konstantin Belousov <k...@freebsd.org>
AuthorDate: 2025-06-04 05:41:47 +0000
Commit:     Konstantin Belousov <k...@freebsd.org>
CommitDate: 2025-06-12 04:28:26 +0000

    ktrace: trace and decode thr_new() thr_param
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    
    (cherry picked from commit 56a4d1a4cc151cf8356704aafd2d2ec0fd009701)
---
 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 0ab4cb5f7970..7c6d00692009 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>
@@ -185,6 +189,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 b615d82d2198..f86a9bb807d3 100644
--- a/sys/sys/ktrace.h
+++ b/sys/sys/ktrace.h
@@ -350,6 +350,8 @@ void        ktrcapfail(enum ktr_cap_violation, const void 
*);
        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 bde4eb7657e0..3240773f357b 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -62,6 +62,7 @@ static char sccsid[] = "@(#)kdump.c   8.1 (Berkeley) 6/6/93";
 #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>
@@ -120,6 +121,7 @@ void ktrsockaddr(struct sockaddr *);
 void ktrsplice(struct splice *);
 void ktrstat(struct stat *);
 void ktrstruct(char *, size_t);
+void ktrthrparam(struct thr_param *);
 void ktrcapfail(struct ktr_cap_fail *);
 void ktrfault(struct ktr_fault *);
 void ktrfaultend(struct ktr_faultend *);
@@ -1944,6 +1946,18 @@ ktrsplice(struct splice *sp)
            (intmax_t)sp->sp_idle.tv_usec);
 }
 
+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);
+}
+
 void
 ktrstat(struct stat *statp)
 {
@@ -2139,6 +2153,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)

Reply via email to