git: bb239328034e - main - ktrace: make ktr_tid a long not intptr_t (NFC)

From: Brooks Davis <brooks_at_FreeBSD.org>
Date: Sat, 17 Sep 2022 08:23:08 UTC
The branch main has been updated by brooks:

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

commit bb239328034eb4055fd2624cb9de6a105fc629ea
Author:     Brooks Davis <brooks@FreeBSD.org>
AuthorDate: 2022-09-17 08:21:32 +0000
Commit:     Brooks Davis <brooks@FreeBSD.org>
CommitDate: 2022-09-17 08:21:59 +0000

    ktrace: make ktr_tid a long not intptr_t (NFC)
    
    Long ago, ktr_tid was ktr_buffer which pointed to the buffer following
    the header and was used internally in the kernel.  Use was removed in
    efbbbf570d70b and it was repurposed as ktr_kid in c6854c347f4d8.  For
    ABI reasons, it stayed an intptr_t rather than becoming an lwpid_t at
    the time.  Since it doesn't hold a pointer any more (unless you have
    a ktrace.out from 2005), change the type to long which is alwasy the
    same size on all supported architectures.  Add a suggestion to change
    the type to lwpid_t (__int32_t) on a future ABI break.
    
    Remove most remaining references to ktr_buffer, retaing a comment in
    kdump.c explaining why negative values are treated as 0.  While here,
    accept that pid_t and lwpid_t are of type int and simplify casts in
    printf.
    
    This changed was motivated by CheriBSD where intptr_t is 16-bytes
    in the pure-capability ABI.
    
    Reviewed by:    kib, markj
    Sponsored by:   DARPA, AFRL
    Differential Revision:  https://reviews.freebsd.org/D36599
---
 lib/libc/sys/ktrace.2 |  2 +-
 sys/sys/ktrace.h      |  5 +++--
 usr.bin/kdump/kdump.c | 17 ++++++++---------
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/libc/sys/ktrace.2 b/lib/libc/sys/ktrace.2
index ffe967e35ed8..543f6f6ebba2 100644
--- a/lib/libc/sys/ktrace.2
+++ b/lib/libc/sys/ktrace.2
@@ -109,7 +109,7 @@ struct ktr_header {
 	pid_t		ktr_pid;		/* process id */
 	char		ktr_comm[MAXCOMLEN+1];	/* command name */
 	struct timeval	ktr_time;		/* timestamp */
-	intptr_t	ktr_tid;		/* was ktr_buffer */
+	long		ktr_tid;		/* thread id */
 };
 .Ed
 .Pp
diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h
index ed5c6c11eaf2..ae6d0ed5d361 100644
--- a/sys/sys/ktrace.h
+++ b/sys/sys/ktrace.h
@@ -58,7 +58,7 @@ struct ktr_header_v0 {
 	pid_t	ktr_pid;		/* process id */
 	char	ktr_comm[MAXCOMLEN + 1];/* command name */
 	struct	timeval ktr_time;	/* timestamp */
-	intptr_t	ktr_tid;	/* was ktr_buffer */
+	long	ktr_tid;		/* thread id */
 };
 
 struct ktr_header {
@@ -68,7 +68,8 @@ struct ktr_header {
 	pid_t	ktr_pid;		/* process id */
 	char	ktr_comm[MAXCOMLEN + 1];/* command name */
 	struct	timespec ktr_time;	/* timestamp */
-	intptr_t	ktr_tid;	/* thread id */
+	/* XXX: make ktr_tid an lwpid_t on next ABI break */
+	long	ktr_tid;		/* thread id */
 	int	ktr_cpu;		/* cpu id */
 };
 
diff --git a/usr.bin/kdump/kdump.c b/usr.bin/kdump/kdump.c
index 75fb5bd8c1d3..bff2920c6aa5 100644
--- a/usr.bin/kdump/kdump.c
+++ b/usr.bin/kdump/kdump.c
@@ -449,15 +449,15 @@ main(int argc, char *argv[])
 			ktr_header.ktr_type &= ~KTR_DROP;
 			if (!drop_logged && threads) {
 				printf(
-				    "%6jd %6jd %-8.*s Events dropped.\n",
-				    (intmax_t)ktr_header.ktr_pid,
+				    "%6d %6d %-8.*s Events dropped.\n",
+				    ktr_header.ktr_pid,
 				    ktr_header.ktr_tid > 0 ?
-				    (intmax_t)ktr_header.ktr_tid : 0,
+				    (lwpid_t)ktr_header.ktr_tid : 0,
 				    MAXCOMLEN, ktr_header.ktr_comm);
 				drop_logged = 1;
 			} else if (!drop_logged) {
-				printf("%6jd %-8.*s Events dropped.\n",
-				    (intmax_t)ktr_header.ktr_pid, MAXCOMLEN,
+				printf("%6d %-8.*s Events dropped.\n",
+				    ktr_header.ktr_pid, MAXCOMLEN,
 				    ktr_header.ktr_comm);
 				drop_logged = 1;
 			}
@@ -724,12 +724,11 @@ dumpheader(struct ktr_header *kth, u_int sv_flags)
 	 * negative tid's as 0.
 	 */
 	if (threads)
-		printf("%6jd %6jd %-8.*s ", (intmax_t)kth->ktr_pid,
-		    kth->ktr_tid > 0 ? (intmax_t)kth->ktr_tid : 0,
+		printf("%6d %6d %-8.*s ", kth->ktr_pid,
+		    kth->ktr_tid > 0 ? (lwpid_t)kth->ktr_tid : 0,
 		    MAXCOMLEN, kth->ktr_comm);
 	else
-		printf("%6jd %-8.*s ", (intmax_t)kth->ktr_pid, MAXCOMLEN,
-		    kth->ktr_comm);
+		printf("%6d %-8.*s ", kth->ktr_pid, MAXCOMLEN, kth->ktr_comm);
         if (timestamp) {
 		if (version == KTR_VERSION0)
 			dumptimeval((struct ktr_header_v0 *)kth);