History log of /freebsd-10-stable/sys/cddl/contrib/opensolaris/uts/common/dtrace/fasttrap.c
Revision Date Author Comments
# 299003 03-May-2016 markj

MFC r296479:
Fix fasttrap tracepoint locking.


# 297077 20-Mar-2016 mav

MFC r277300 (by smh): Mechanically convert cddl sun #ifdef's to illumos

Since the upstream for cddl code is now illumos not sun, mechanically
convert all sun #ifdef's to illumos #ifdef's which have been used in all
newer code for some time.

Also do a manual pass to correct the use if #ifdef comments as per style(9)
as well as few uses of #if defined(__FreeBSD__) vs #ifndef illumos.


# 293413 08-Jan-2016 stas

MFC r291545: make the number of fasttrap probes and the size of the trace points hash table
tunable via sysctl or kernel tunables.


# 283677 29-May-2015 markj

MFC r277915:
Don't attempt to disable enabled fasttrap probes in an exiting process.

MFC r277914:
fasttrap_sigtrap(): use tdsendsignal() to send SIGTRAP.


# 277547 22-Jan-2015 delphij

MFC r275562: MFV r275535:

Unexpand ISP2() and MSEC2NSEC().

Illumos issue:
5255 uts shouldn't open-code ISP2


# 271001 03-Sep-2014 delphij

MFC r270247: MFV r270195:

Illumos issue:
5045 use atomic_{inc,dec}_* instead of atomic_add_*


# 269342 31-Jul-2014 markj

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.


# 268734 16-Jul-2014 pfg

MFC r268097:

MFV r260708
4427 pid provider rejects probes with valid UTF-8 names

This make use of Solaris' u8_validate() which we happen to
use since r185029 for ZFS.
Use of u8_textprep.c required -Wno-cast-qual for powerpc.

Illumos Revision: 1444d846b126463eb1059a572ff114d51f7562e5

Reference:
https://www.illumos.org/issues/4427

Obtained from: Illumos


# 268572 12-Jul-2014 pfg

MFC r268130, r268224, r268230, r268231:

Various DTrace Merges from OpenSolaris/Illumos:

15-Sep-2008:
6735480 race between probe enabling and provider registration

20-Apr-2008:
6822482 DOF validation needs to handle loadable sections flagged as unloadable

22-Apr-2009:
6823388 DTrace ioctl handlers must validate all structure members

30-Jun-2009:
6851093 system drops to kmdb with anonymous dtrace probes + kmdb

Obtained from: OpenSolaris


# 262048 17-Feb-2014 avg

MFC r258291: change the ioctl definition so that the fasttrap ioctl
handler is responsible for copying in userland data


# 259483 16-Dec-2013 asomers

MFC r258311

opensolaris/uts/common/dtrace/fasttrap.c
Fix several problems that can cause panics on kldload and kldunload.

* kproc_create(fasttrap_pid_cleanup_cb, ...) gets called before
fasttrap_provs.fth_table gets allocated. This can lead to a panic
on module load, because fasttrap_pid_cleanup_cb references
fasttrap_provs.fth_table. Move kproc_create down after the point
that fasttrap_provs.fth_table gets allocated, and modify the error
handling accordingly.

* dtrace_fasttrap_{fork,exec,exit} weren't getting NULLed until
after fasttrap_provs.fth_table got freed. That caused panics on
module unload because fasttrap_exec_exit calls
fasttrap_provider_retire, which references
fasttrap_provs.fth_table. NULL those function pointers earlier.

* There wasn't any code to destroy the
fasttrap_{tpoints,provs,procs}.fth_table mutexes on module unload,
leading to a resource leak when WITNESS is enabled. Destroy those
mutexes during fasttrap_unload().

Sponsored by: Spectra Logic Corporation


# 283677 29-May-2015 markj

MFC r277915:
Don't attempt to disable enabled fasttrap probes in an exiting process.

MFC r277914:
fasttrap_sigtrap(): use tdsendsignal() to send SIGTRAP.


# 277547 22-Jan-2015 delphij

MFC r275562: MFV r275535:

Unexpand ISP2() and MSEC2NSEC().

Illumos issue:
5255 uts shouldn't open-code ISP2


# 271001 03-Sep-2014 delphij

MFC r270247: MFV r270195:

Illumos issue:
5045 use atomic_{inc,dec}_* instead of atomic_add_*


# 269342 31-Jul-2014 markj

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.


# 268734 16-Jul-2014 pfg

MFC r268097:

MFV r260708
4427 pid provider rejects probes with valid UTF-8 names

This make use of Solaris' u8_validate() which we happen to
use since r185029 for ZFS.
Use of u8_textprep.c required -Wno-cast-qual for powerpc.

Illumos Revision: 1444d846b126463eb1059a572ff114d51f7562e5

Reference:
https://www.illumos.org/issues/4427

Obtained from: Illumos


# 268572 12-Jul-2014 pfg

MFC r268130, r268224, r268230, r268231:

Various DTrace Merges from OpenSolaris/Illumos:

15-Sep-2008:
6735480 race between probe enabling and provider registration

20-Apr-2008:
6822482 DOF validation needs to handle loadable sections flagged as unloadable

22-Apr-2009:
6823388 DTrace ioctl handlers must validate all structure members

30-Jun-2009:
6851093 system drops to kmdb with anonymous dtrace probes + kmdb

Obtained from: OpenSolaris


# 262048 17-Feb-2014 avg

MFC r258291: change the ioctl definition so that the fasttrap ioctl
handler is responsible for copying in userland data


# 259483 16-Dec-2013 asomers

MFC r258311

opensolaris/uts/common/dtrace/fasttrap.c
Fix several problems that can cause panics on kldload and kldunload.

* kproc_create(fasttrap_pid_cleanup_cb, ...) gets called before
fasttrap_provs.fth_table gets allocated. This can lead to a panic
on module load, because fasttrap_pid_cleanup_cb references
fasttrap_provs.fth_table. Move kproc_create down after the point
that fasttrap_provs.fth_table gets allocated, and modify the error
handling accordingly.

* dtrace_fasttrap_{fork,exec,exit} weren't getting NULLed until
after fasttrap_provs.fth_table got freed. That caused panics on
module unload because fasttrap_exec_exit calls
fasttrap_provider_retire, which references
fasttrap_provs.fth_table. NULL those function pointers earlier.

* There wasn't any code to destroy the
fasttrap_{tpoints,provs,procs}.fth_table mutexes on module unload,
leading to a resource leak when WITNESS is enabled. Destroy those
mutexes during fasttrap_unload().

Sponsored by: Spectra Logic Corporation