freebsd-skq/sys/cddl/dev/dtrace
markj 801a01a441 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.

Tested by:	Prashanth Kumar <pra_udupi@yahoo.co.in> (earlier version)
MFC after:	6 weeks
2014-04-14 00:22:42 +00:00
..
amd64 Move some files that are identical on i386 and amd64 to an x86 subdirectory 2014-02-27 01:04:35 +00:00
i386 Move some files that are identical on i386 and amd64 to an x86 subdirectory 2014-02-27 01:04:35 +00:00
mips - For o32 ABI get arguments from the stack 2012-03-26 21:47:06 +00:00
powerpc ELF PowerPC64 ABI puts the LR save word at 16 byte offset, not 8. 2013-10-25 00:17:12 +00:00
x86 Fix the struct reg mappings for i386 and amd64, which differ between illumos 2014-02-27 01:24:47 +00:00
dtrace_anon.c
dtrace_cddl.h DTrace's pid provider works by inserting breakpoint instructions at probe 2014-04-14 00:22:42 +00:00
dtrace_clone.c - Use make_dev_credf(MAKEDEV_REF) instead of the race-prone make_dev()+ 2013-09-07 13:45:44 +00:00
dtrace_debug.c Correct a series of errors in the hand-rolled locking for drace_debug.c: 2012-12-23 15:50:37 +00:00
dtrace_hacks.c
dtrace_ioctl.c Expose a few DTrace parameters as sysctls under kern.dtrace and add 2014-03-01 19:06:43 +00:00
dtrace_load.c Allocate the probe ID unrhdr before the DTrace kld_* event handlers are 2013-12-31 15:41:16 +00:00
dtrace_modevent.c
dtrace_sysctl.c Expose a few DTrace parameters as sysctls under kern.dtrace and add 2014-03-01 19:06:43 +00:00
dtrace_test.c dtrace sdt: remove the ugly sname parameter of SDT_PROBE_DEFINE 2013-11-26 08:46:27 +00:00
dtrace_unload.c Revert r260091. The vmem calls seem to be slower than the *_unr() calls that 2013-12-31 15:37:51 +00:00
dtrace_vtime.c