]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/commit
MFC r264434:
authormarkj <markj@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Thu, 31 Jul 2014 17:10:03 +0000 (17:10 +0000)
committermarkj <markj@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Thu, 31 Jul 2014 17:10:03 +0000 (17:10 +0000)
commit102bfb584f041ce7ebb7f435cb25311746483edb
treed40f846c3c67bb670c723a3cc95cdf87f46cd741
parentae998900e63912dfa0893250592c1fec59797358
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.

git-svn-id: svn://svn.freebsd.org/base/stable/10@269342 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c
sys/cddl/contrib/opensolaris/uts/common/sys/fasttrap_impl.h
sys/cddl/contrib/opensolaris/uts/intel/dtrace/fasttrap_isa.c
sys/cddl/dev/dtrace/dtrace_cddl.h