Alex Richardson 7daca4e204 truss: improved support for decoding compat32 arguments
Currently running `truss -a -e` does not decode any
argument values for freebsd32_* syscalls (open/readlink/etc.)

This change checks whether a syscall starts with freebsd{32,64}_ and if
so strips that prefix when looking up the syscall information. To ensure
that the truss logs include the real syscall name we create a copy of
the syscall information struct with the updated.

The other problem is that when reading string array values, truss
naively iterates over an array of char* and fetches the pointer value.
This will result in arguments not being loaded if the pointer is not
aligned to sizeof(void*), which can happens in the compat32 case. If it
happens to be aligned, we would end up printing every other value.
To fix this problem, this changes adds a pointer_size member to the
procabi struct and uses that to correctly read indirect arguments
as 64/32 bit addresses in the the compat32 case (and also compat64 on
CheriBSD).

The motivating use-case for this change is using truss for 64-bit
programs on a CHERI system, but most of the diff also applies to 32-bit
compat on a 64-bit system, so I'm upstreaming this instead of keeping it
as a local CheriBSD patch.

Output of `truss -aef ldd32 /usr/bin/ldd32` before:
39113: freebsd32_mmap(0x0,0x1000,0x3,0x1002,0xffffffff,0x0,0x0) = 543440896 (0x20644000)
39113: freebsd32_ioctl(0x1,0x402c7413,0xffffd2a0) = 0 (0x0)
/usr/bin/ldd32:
39113: write(1,"/usr/bin/ldd32:\n",16)		 = 16 (0x10)
39113: fork()					 = 39114 (0x98ca)
39114: <new process>
39114: freebsd32_execve(0xffffd97e,0xffffd680,0x20634000) EJUSTRETURN
39114: freebsd32_mmap(0x0,0x20000,0x3,0x1002,0xffffffff,0x0,0x0) = 541237248 (0x2042a000)
39114: freebsd32_mprotect(0x20427000,0x1000,0x1) = 0 (0x0)
39114: issetugid()				 = 0 (0x0)
39114: openat(AT_FDCWD,"/etc/libmap32.conf",O_RDONLY|O_CLOEXEC,00) ERR#2 'No such file or directory'
39114: openat(AT_FDCWD,"/var/run/ld-elf32.so.hints",O_RDONLY|O_CLOEXEC,00) = 3 (0x3)
39114: read(3,"Ehnt\^A\0\0\0\M^@\0\0\0#\0\0\0\0"...,128) = 128 (0x80)
39114: freebsd32_fstat(0x3,0xffffbd98)		 = 0 (0x0)
39114: freebsd32_pread(0x3,0x2042f000,0x23,0x80,0x0) = 35 (0x23)
39114: close(3)					 = 0 (0x0)
39114: openat(AT_FDCWD,"/usr/lib32/libc.so.7",O_RDONLY|O_CLOEXEC|O_VERIFY,00) = 3 (0x3)
39114: freebsd32_fstat(0x3,0xffffc7d0)		 = 0 (0x0)
39114: freebsd32_mmap(0x0,0x1000,0x1,0x40002,0x3,0x0,0x0) = 541368320 (0x2044a000)

After:
  783: freebsd32_mmap(0x0,4096,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON|MAP_ALIGNED(12),-1,0x0) = 543543296 (0x2065d000)
  783: freebsd32_ioctl(1,TIOCGETA,0xffffd7b0)    = 0 (0x0)
/usr/bin/ldd32:
  783: write(1,"/usr/bin/ldd32:\n",16)           = 16 (0x10)
  784: <new process>
  783: fork()                                    = 784 (0x310)
  784: freebsd32_execve("/usr/bin/ldd32",[ "(null)" ],[ "LD_32_TRACE_LOADED_OBJECTS_PROGNAME=/usr/bin/ldd32", "LD_TRACE_LOADED_OBJECTS_PROGNAME=/usr/bin/ldd32", "LD_32_TRACE_LOADED_OBJECTS=yes", "LD_TRACE_LOADED_OBJECTS=yes", "USER=root", "LOGNAME=root", "HOME=/root", "SHELL=/bin/csh", "BLOCKSIZE=K", "MAIL=/var/mail/root", "MM_CHARSET=UTF-8", "LANG=C.UTF-8", "PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin", "TERM=vt100", "HOSTTYPE=FreeBSD", "VENDOR=amd", "OSTYPE=FreeBSD", "MACHTYPE=x86_64", "SHLVL=1", "PWD=/root", "GROUP=wheel", "HOST=freebsd-amd64", "EDITOR=vi", "PAGER=less" ]) EJUSTRETURN
  784: freebsd32_mmap(0x0,135168,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANON,-1,0x0) = 541212672 (0x20424000)
  784: freebsd32_mprotect(0x20421000,4096,PROT_READ) = 0 (0x0)
  784: issetugid()                               = 0 (0x0)
  784: sigfastblock(0x1,0x204234fc)              = 0 (0x0)
  784: open("/etc/libmap32.conf",O_RDONLY|O_CLOEXEC,00) ERR#2 'No such file or directory'
  784: open("/var/run/ld-elf32.so.hints",O_RDONLY|O_CLOEXEC,00) = 3 (0x3)
  784: read(3,"Ehnt\^A\0\0\0\M^@\0\0\0\v\0\0\0"...,128) = 128 (0x80)
  784: freebsd32_fstat(3,{ mode=-r--r--r-- ,inode=18680,size=32768,blksize=0 }) = 0 (0x0)
  784: freebsd32_pread(3,"/usr/lib32\0",11,0x80) = 11 (0xb)

Reviewed By:	jhb
Differential Revision: https://reviews.freebsd.org/D27625
2021-03-25 11:14:13 +00:00
..
2021-03-13 18:26:15 +01:00
2017-10-31 00:07:04 +00:00
2020-06-13 09:16:07 +00:00
2019-01-12 12:35:02 +00:00
2019-12-11 17:37:53 +00:00
2020-11-16 18:41:49 +00:00
2020-10-09 14:03:45 +00:00
2019-12-11 17:37:53 +00:00
2020-10-21 16:30:34 +00:00
2020-06-23 10:27:41 +00:00
2020-07-27 16:51:23 +00:00
2020-10-10 13:01:04 +00:00
2020-10-09 19:12:44 +00:00
2021-01-07 09:31:03 +00:00
2017-10-31 00:07:04 +00:00
2021-01-23 17:24:32 +02:00
2021-03-03 14:21:56 -06:00
2018-04-25 18:56:27 +00:00
2020-10-30 09:48:41 +00:00
2017-10-31 00:07:04 +00:00
2021-03-13 18:26:15 +01:00
2020-10-29 18:39:04 +00:00
2021-02-26 08:06:07 -07:00
2020-11-19 19:05:16 +00:00
2017-10-31 00:07:04 +00:00
2020-10-24 16:40:34 +00:00
2020-12-26 11:47:47 -05:00
2019-12-11 17:37:53 +00:00
2020-06-29 15:15:14 +00:00
2017-10-31 00:07:04 +00:00
2020-11-29 18:22:14 +00:00
2020-12-10 18:34:15 +00:00
2020-12-19 12:54:00 +00:00
2020-10-09 19:12:44 +00:00
2018-03-02 23:31:55 +00:00
2020-06-20 11:27:59 +00:00
2021-01-07 09:31:03 +00:00
2021-01-09 18:37:25 +01:00
2021-01-29 10:53:50 -08:00
2019-11-12 22:31:59 +00:00
2019-06-29 18:41:40 +00:00
2020-06-18 18:09:16 +00:00
2020-06-25 16:46:27 +00:00
2020-12-11 08:04:54 +00:00
2020-12-11 19:27:21 +00:00
2020-12-29 21:48:12 +01:00
2020-12-29 21:35:24 +01:00
2020-09-11 13:28:37 +00:00
2021-01-09 18:22:08 +01:00
2018-01-06 15:52:28 +00:00
2020-10-24 05:52:29 +00:00
2020-06-18 08:26:26 +00:00
2019-12-11 17:37:53 +00:00
2021-01-29 23:52:13 -06:00
2018-11-20 00:06:53 +00:00
2020-07-01 16:33:32 +00:00
2020-06-27 11:19:18 +00:00
2018-07-03 19:09:46 +00:00
2018-06-25 11:44:56 +00:00
2021-01-05 16:32:27 +01:00
2020-06-20 11:24:29 +00:00
2019-12-11 17:37:53 +00:00
2020-12-30 13:45:53 -05:00
2020-06-18 15:14:10 +00:00
2019-05-01 19:35:45 +00:00
2019-12-11 17:37:53 +00:00
2020-03-26 17:58:52 +00:00
2021-02-15 20:23:32 +01:00
2017-12-28 05:33:39 +00:00
2020-06-23 10:22:58 +00:00
2019-12-11 17:37:53 +00:00
2020-10-09 14:03:45 +00:00
2020-07-07 16:07:39 +00:00
2020-07-07 17:02:23 +00:00
2020-07-14 22:43:40 +00:00
2020-08-30 17:37:56 +00:00
2019-11-20 19:43:34 +00:00
2017-10-31 00:07:04 +00:00
2021-01-02 10:50:08 +09:00
2020-09-11 13:28:37 +00:00
2018-11-12 07:14:34 +00:00
2020-10-01 04:46:23 +00:00
2017-10-31 00:07:04 +00:00
2020-08-24 17:57:08 +00:00
2020-08-30 17:40:59 +00:00
2020-12-12 15:38:32 +00:00
2020-01-25 21:16:45 +00:00
2017-06-16 06:29:21 +00:00
2017-06-16 06:29:21 +00:00
2017-10-31 00:07:04 +00:00
2017-10-31 00:07:04 +00:00
2020-07-14 01:54:24 +00:00
2020-09-11 13:28:37 +00:00