Page MenuHomeFreeBSD

Use PT_GET_SC_ARGS and PT_GET_SC_RET in truss.
ClosedPublic

Authored by jhb on Jul 15 2019, 10:17 PM.
Tags
None
Referenced Files
Unknown Object (File)
Jan 20 2024, 9:17 PM
Unknown Object (File)
Jan 10 2024, 2:28 AM
Unknown Object (File)
Dec 20 2023, 6:13 AM
Unknown Object (File)
Nov 28 2023, 1:04 PM
Unknown Object (File)
Nov 5 2023, 7:10 PM
Unknown Object (File)
Nov 4 2023, 4:07 AM
Unknown Object (File)
Oct 4 2023, 6:05 PM
Unknown Object (File)
Oct 3 2023, 3:58 AM
Subscribers

Details

Summary

This removes all of the architecture-specific functions from truss.

A per-ABI structure is still needed to map syscall numbers to names
and FreeBSD errno values to ABI error values as well as hold syscall
counters. However, the linker set of ABI structures is now replaced
with a simple table mapping ABI names to structures. This approach
permits sharing the same ABI structure among separate names such as
i386 a.out and ELF binaries as well as ELF v1 vs ELF v2 for powerpc64.

A few differences are visible due to using PT_GET_SC_RET to fetch the
error value of a system call. Note that ktrace/kdump have had the
"new" behaviors for a long time already:

  • System calls that return with EJUSTRETURN or ERESTART will now be noticed and logged as such. Previously sigreturn (which uses EJUSTRETURN) would report whatever random value was in the register holding errno from the previous system call for example. Now it reports JUSTRETURN.
  • System calls that return errno as their error value such as posix_fallocate() and posix_fadvise() now report non-zero return values as errors instead of success with a non-zero return value.

Sponsored by: DARPA

Test Plan
  • tested on amd64 for amd64 and i386 binaries
  • tested on i386 for ELF binaries

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

usr.bin/truss/setup.c
455 ↗(On Diff #59788)

Now, that you rely on kernel to fetch syscall args, would it make sense to do PT_GET_SC_ARGS even in narg == 0 case ? Or just avoid narg use at all.

usr.bin/truss/setup.c
455 ↗(On Diff #59788)

It is a small optimization I guess to skip ptrace() if there aren't any arguments to fetch. I'm not quite sure what you mean by avoiding use of narg. We still need to know how many elements of cs.args[] are valid.

kib added inline comments.
usr.bin/truss/setup.c
455 ↗(On Diff #59788)

But you pass sizeof(cs.args) to ptrace and not nargs. Anyway, it is very minor.

This revision is now accepted and ready to land.Jul 16 2019, 5:24 PM
usr.bin/truss/setup.c
455 ↗(On Diff #59788)

Yes, it just means a constant at runtime. PT_GET_SC_ARG is careful to only copy out the number of actual args, so this seemed simpler than using 'narg * sizeof(t->cs.args[0])' as the length.

This revision was automatically updated to reflect the committed changes.