diff options
author | markj <markj@FreeBSD.org> | 2014-07-31 17:10:03 +0000 |
---|---|---|
committer | markj <markj@FreeBSD.org> | 2014-07-31 17:10:03 +0000 |
commit | f850608aee29e7e8e964d6526a571a6cf7609200 (patch) | |
tree | d40f846c3c67bb670c723a3cc95cdf87f46cd741 /sys/cddl/dev | |
parent | d357493f146786ee3eea8ddf44ed669e6624e5e2 (diff) | |
download | FreeBSD-src-f850608aee29e7e8e964d6526a571a6cf7609200.zip FreeBSD-src-f850608aee29e7e8e964d6526a571a6cf7609200.tar.gz |
MFC r264434:
DTrace's pid provider works by inserting breakpoint instructions at probe
sites and installing a hook at the kernel's trap handler. The fasttrap code
will emulate the overwritten instruction in some common cases, but otherwise
copies it out into some scratch space in the traced process' address space
and ensures that it's executed after returning from the trap.
In Solaris and illumos, this (per-thread) scratch space comes from some
reserved space in TLS, accessible via the fs segment register. This
approach is somewhat unappealing on FreeBSD since it would require some
modifications to rtld and jemalloc (for static TLS) to ensure that TLS is
executable, and would thus introduce dependencies on their implementation
details. I think it would also be impossible to safely trace static binaries
compiled without these modifications.
This change implements the functionality in a different way, by having
fasttrap map pages into the target process' address space on demand. Each
page is divided into 64-byte chunks for use by individual threads, and
fasttrap's process descriptor struct has been extended to keep track of
any scratch space allocated for the corresponding process.
With this change it's possible to trace all libc functions in a program,
e.g. with
pid$target:libc.so.*::entry {@[probefunc] = count();}
Previously this would generally cause the victim process to crash, as
tracing memcpy on amd64 requires the functionality described above.
Diffstat (limited to 'sys/cddl/dev')
-rw-r--r-- | sys/cddl/dev/dtrace/dtrace_cddl.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/sys/cddl/dev/dtrace/dtrace_cddl.h b/sys/cddl/dev/dtrace/dtrace_cddl.h index 6caf3cf..eed32a8 100644 --- a/sys/cddl/dev/dtrace/dtrace_cddl.h +++ b/sys/cddl/dev/dtrace/dtrace_cddl.h @@ -84,6 +84,7 @@ typedef struct kdtrace_thread { #endif u_int64_t td_hrtime; /* Last time on cpu. */ int td_errno; /* Syscall return value. */ + void *td_dtrace_sscr; /* Saved scratch space location. */ } kdtrace_thread_t; /* @@ -108,10 +109,12 @@ typedef struct kdtrace_thread { #define t_dtrace_scrpc td_dtrace->td_dtrace_scrpc #define t_dtrace_astpc td_dtrace->td_dtrace_astpc #define t_dtrace_regv td_dtrace->td_dtrace_regv +#define t_dtrace_sscr td_dtrace->td_dtrace_sscr #define p_dtrace_helpers p_dtrace->p_dtrace_helpers #define p_dtrace_count p_dtrace->p_dtrace_count #define p_dtrace_probes p_dtrace->p_dtrace_probes #define p_model p_dtrace->p_dtrace_model + #define DATAMODEL_NATIVE 0 #ifdef __amd64__ #define DATAMODEL_LP64 0 |