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
main
Brooks Davis 2 weeks ago
parent 714300faec
commit bb23932803
  1. 2
      lib/libc/sys/ktrace.2
  2. 5
      sys/sys/ktrace.h
  3. 17
      usr.bin/kdump/kdump.c

@ -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

@ -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 */
};

@ -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);

Loading…
Cancel
Save