Add DTrace 'proc' provider probes using the Statically Defined Trace
(sdt) mechanism.
This commit is contained in:
parent
f72ab79315
commit
5d217f173c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=179276
@ -28,6 +28,7 @@
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_hwpmc_hooks.h"
|
||||
#include "opt_kdtrace.h"
|
||||
#include "opt_ktrace.h"
|
||||
#include "opt_mac.h"
|
||||
#include "opt_vm.h"
|
||||
@ -54,6 +55,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/pioctl.h>
|
||||
#include <sys/namei.h>
|
||||
#include <sys/resourcevar.h>
|
||||
#include <sys/sdt.h>
|
||||
#include <sys/sf_buf.h>
|
||||
#include <sys/syscallsubr.h>
|
||||
#include <sys/sysent.h>
|
||||
@ -83,6 +85,19 @@ __FBSDID("$FreeBSD$");
|
||||
#include <security/audit/audit.h>
|
||||
#include <security/mac/mac_framework.h>
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
#include <sys/dtrace_bsd.h>
|
||||
dtrace_execexit_func_t dtrace_fasttrap_exec;
|
||||
#endif
|
||||
|
||||
SDT_PROVIDER_DECLARE(proc);
|
||||
SDT_PROBE_DEFINE(proc, kernel, , exec);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , exec, 0, "char *");
|
||||
SDT_PROBE_DEFINE(proc, kernel, , exec_failure);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , exec_failure, 0, "int");
|
||||
SDT_PROBE_DEFINE(proc, kernel, , exec_success);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , exec_success, 0, "char *");
|
||||
|
||||
MALLOC_DEFINE(M_PARGS, "proc-args", "Process arguments");
|
||||
|
||||
static int sysctl_kern_ps_strings(SYSCTL_HANDLER_ARGS);
|
||||
@ -371,6 +386,8 @@ do_execve(td, args, mac_p)
|
||||
|
||||
imgp->image_header = NULL;
|
||||
|
||||
SDT_PROBE(proc, kernel, , exec, args->fname, 0, 0, 0, 0 );
|
||||
|
||||
/*
|
||||
* Translate the file name. namei() returns a vnode pointer
|
||||
* in ni_vp amoung other things.
|
||||
@ -702,6 +719,15 @@ do_execve(td, args, mac_p)
|
||||
textvp = p->p_textvp;
|
||||
p->p_textvp = binvp;
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
/*
|
||||
* Tell the DTrace fasttrap provider about the exec if it
|
||||
* has declared an interest.
|
||||
*/
|
||||
if (dtrace_fasttrap_exec)
|
||||
dtrace_fasttrap_exec(p);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Notify others that we exec'd, and clear the P_INEXEC flag
|
||||
* as we're now a bona fide freshly-execed process.
|
||||
@ -764,6 +790,7 @@ do_execve(td, args, mac_p)
|
||||
vfs_mark_atime(imgp->vp, td);
|
||||
|
||||
done1:
|
||||
|
||||
/*
|
||||
* Free any resources malloc'd earlier that we didn't use.
|
||||
*/
|
||||
@ -773,6 +800,9 @@ do_execve(td, args, mac_p)
|
||||
else
|
||||
crfree(newcred);
|
||||
VOP_UNLOCK(imgp->vp, 0);
|
||||
|
||||
SDT_PROBE(proc, kernel, , exec_success, args->fname, 0, 0, 0, 0);
|
||||
|
||||
/*
|
||||
* Handle deferred decrement of ref counts.
|
||||
*/
|
||||
@ -836,6 +866,8 @@ do_execve(td, args, mac_p)
|
||||
p->p_flag &= ~P_INEXEC;
|
||||
PROC_UNLOCK(p);
|
||||
|
||||
SDT_PROBE(proc, kernel, , exec_failure, error, 0, 0, 0, 0);
|
||||
|
||||
done2:
|
||||
#ifdef MAC
|
||||
mac_execve_exit(imgp);
|
||||
|
@ -38,6 +38,7 @@
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_compat.h"
|
||||
#include "opt_kdtrace.h"
|
||||
#include "opt_ktrace.h"
|
||||
#include "opt_mac.h"
|
||||
|
||||
@ -65,6 +66,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/acct.h> /* for acct_process() function prototype */
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/sdt.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/sem.h>
|
||||
#ifdef KTRACE
|
||||
@ -82,6 +84,15 @@ __FBSDID("$FreeBSD$");
|
||||
#include <vm/vm_page.h>
|
||||
#include <vm/uma.h>
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
#include <sys/dtrace_bsd.h>
|
||||
dtrace_execexit_func_t dtrace_fasttrap_exit;
|
||||
#endif
|
||||
|
||||
SDT_PROVIDER_DECLARE(proc);
|
||||
SDT_PROBE_DEFINE(proc, kernel, , exit);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , exit, 0, "int");
|
||||
|
||||
/* Required to be non-static for SysVR4 emulator */
|
||||
MALLOC_DEFINE(M_ZOMBIE, "zombie", "zombie proc status");
|
||||
|
||||
@ -443,11 +454,30 @@ exit1(struct thread *td, int rv)
|
||||
PROC_LOCK(p);
|
||||
p->p_xstat = rv;
|
||||
p->p_xthread = td;
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
/*
|
||||
* Tell the DTrace fasttrap provider about the exit if it
|
||||
* has declared an interest.
|
||||
*/
|
||||
if (dtrace_fasttrap_exit)
|
||||
dtrace_fasttrap_exit(p);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Notify interested parties of our demise.
|
||||
*/
|
||||
KNOTE_LOCKED(&p->p_klist, NOTE_EXIT);
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
int reason = CLD_EXITED;
|
||||
if (WCOREDUMP(rv))
|
||||
reason = CLD_DUMPED;
|
||||
else if (WIFSIGNALED(rv))
|
||||
reason = CLD_KILLED;
|
||||
SDT_PROBE(proc, kernel, , exit, reason, 0, 0, 0, 0);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Just delete all entries in the p_klist. At this point we won't
|
||||
* report any more events, and there are nasty race conditions that
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_kdtrace.h"
|
||||
#include "opt_ktrace.h"
|
||||
#include "opt_mac.h"
|
||||
|
||||
@ -63,6 +64,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/ktr.h>
|
||||
#include <sys/ktrace.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <sys/sdt.h>
|
||||
#include <sys/sx.h>
|
||||
#include <sys/signalvar.h>
|
||||
|
||||
@ -75,6 +77,16 @@ __FBSDID("$FreeBSD$");
|
||||
#include <vm/vm_extern.h>
|
||||
#include <vm/uma.h>
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
#include <sys/dtrace_bsd.h>
|
||||
dtrace_fork_func_t dtrace_fasttrap_fork;
|
||||
#endif
|
||||
|
||||
SDT_PROVIDER_DECLARE(proc);
|
||||
SDT_PROBE_DEFINE(proc, kernel, , create);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , create, 0, "struct proc *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , create, 1, "struct proc *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , create, 2, "int");
|
||||
|
||||
#ifndef _SYS_SYSPROTO_H_
|
||||
struct fork_args {
|
||||
@ -626,6 +638,15 @@ fork1(td, flags, pages, procp)
|
||||
p2->p_pfsflags = p1->p_pfsflags;
|
||||
}
|
||||
|
||||
#ifdef KDTRACE_HOOKS
|
||||
/*
|
||||
* Tell the DTrace fasttrap provider about the new process
|
||||
* if it has registered an interest.
|
||||
*/
|
||||
if (dtrace_fasttrap_fork)
|
||||
dtrace_fasttrap_fork(p1, p2);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This begins the section where we must prevent the parent
|
||||
* from being swapped.
|
||||
@ -715,6 +736,8 @@ fork1(td, flags, pages, procp)
|
||||
|
||||
PROC_UNLOCK(p1);
|
||||
|
||||
SDT_PROBE(proc, kernel, , create, p2, p1, flags, 0, 0);
|
||||
|
||||
/*
|
||||
* Preserve synchronization semantics of vfork. If waiting for
|
||||
* child to exec or exit, set P_PPWAIT on child, and sleep on our
|
||||
|
@ -33,6 +33,7 @@
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
#include "opt_kdtrace.h"
|
||||
#include "opt_ktrace.h"
|
||||
#include "opt_kstack_pages.h"
|
||||
#include "opt_stack.h"
|
||||
@ -55,6 +56,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/filedesc.h>
|
||||
#include <sys/tty.h>
|
||||
#include <sys/signalvar.h>
|
||||
#include <sys/sdt.h>
|
||||
#include <sys/sx.h>
|
||||
#include <sys/user.h>
|
||||
#include <sys/jail.h>
|
||||
@ -76,6 +78,35 @@ __FBSDID("$FreeBSD$");
|
||||
#include <vm/vm_object.h>
|
||||
#include <vm/uma.h>
|
||||
|
||||
SDT_PROVIDER_DEFINE(proc);
|
||||
SDT_PROBE_DEFINE(proc, kernel, ctor, entry);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, ctor, entry, 0, "struct proc *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, ctor, entry, 1, "int");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, ctor, entry, 2, "void *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, ctor, entry, 3, "int");
|
||||
SDT_PROBE_DEFINE(proc, kernel, ctor, return);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, ctor, return, 0, "struct proc *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, ctor, return, 1, "int");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, ctor, return, 2, "void *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, ctor, return, 3, "int");
|
||||
SDT_PROBE_DEFINE(proc, kernel, dtor, entry);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, dtor, entry, 0, "struct proc *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, dtor, entry, 1, "int");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, dtor, entry, 2, "void *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, dtor, entry, 3, "struct thread *");
|
||||
SDT_PROBE_DEFINE(proc, kernel, dtor, return);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, dtor, return, 0, "struct proc *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, dtor, return, 1, "int");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, dtor, return, 2, "void *");
|
||||
SDT_PROBE_DEFINE(proc, kernel, init, entry);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, init, entry, 0, "struct proc *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, init, entry, 1, "int");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, init, entry, 2, "int");
|
||||
SDT_PROBE_DEFINE(proc, kernel, init, return);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, init, return, 0, "struct proc *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, init, return, 1, "int");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, init, return, 2, "int");
|
||||
|
||||
MALLOC_DEFINE(M_PGRP, "pgrp", "process group header");
|
||||
MALLOC_DEFINE(M_SESSION, "session", "session header");
|
||||
static MALLOC_DEFINE(M_PROC, "proc", "Proc structures");
|
||||
@ -142,7 +173,9 @@ proc_ctor(void *mem, int size, void *arg, int flags)
|
||||
struct proc *p;
|
||||
|
||||
p = (struct proc *)mem;
|
||||
SDT_PROBE(proc, kernel, ctor , entry, p, size, arg, flags, 0);
|
||||
EVENTHANDLER_INVOKE(process_ctor, p);
|
||||
SDT_PROBE(proc, kernel, ctor , return, p, size, arg, flags, 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -158,6 +191,7 @@ proc_dtor(void *mem, int size, void *arg)
|
||||
/* INVARIANTS checks go here */
|
||||
p = (struct proc *)mem;
|
||||
td = FIRST_THREAD_IN_PROC(p);
|
||||
SDT_PROBE(proc, kernel, dtor, entry, p, size, arg, td, 0);
|
||||
if (td != NULL) {
|
||||
#ifdef INVARIANTS
|
||||
KASSERT((p->p_numthreads == 1),
|
||||
@ -175,6 +209,7 @@ proc_dtor(void *mem, int size, void *arg)
|
||||
EVENTHANDLER_INVOKE(process_dtor, p);
|
||||
if (p->p_ksi != NULL)
|
||||
KASSERT(! KSI_ONQ(p->p_ksi), ("SIGCHLD queue"));
|
||||
SDT_PROBE(proc, kernel, dtor, return, p, size, arg, 0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -186,6 +221,7 @@ proc_init(void *mem, int size, int flags)
|
||||
struct proc *p;
|
||||
|
||||
p = (struct proc *)mem;
|
||||
SDT_PROBE(proc, kernel, init, entry, p, size, flags, 0, 0);
|
||||
p->p_sched = (struct p_sched *)&p[1];
|
||||
bzero(&p->p_mtx, sizeof(struct mtx));
|
||||
mtx_init(&p->p_mtx, "process lock", NULL, MTX_DEF | MTX_DUPOK);
|
||||
@ -193,6 +229,7 @@ proc_init(void *mem, int size, int flags)
|
||||
TAILQ_INIT(&p->p_threads); /* all threads in proc */
|
||||
EVENTHANDLER_INVOKE(process_init, p);
|
||||
p->p_stats = pstats_alloc();
|
||||
SDT_PROBE(proc, kernel, init, return, p, size, flags, 0, 0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include "opt_compat.h"
|
||||
#include "opt_kdtrace.h"
|
||||
#include "opt_ktrace.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -59,6 +60,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/posix4.h>
|
||||
#include <sys/pioctl.h>
|
||||
#include <sys/resourcevar.h>
|
||||
#include <sys/sdt.h>
|
||||
#include <sys/sbuf.h>
|
||||
#include <sys/sleepqueue.h>
|
||||
#include <sys/smp.h>
|
||||
@ -82,6 +84,19 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#define ONSIG 32 /* NSIG for osig* syscalls. XXX. */
|
||||
|
||||
SDT_PROVIDER_DECLARE(proc);
|
||||
SDT_PROBE_DEFINE(proc, kernel, , signal_send);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , signal_send, 0, "struct thread *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , signal_send, 1, "struct proc *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , signal_send, 2, "int");
|
||||
SDT_PROBE_DEFINE(proc, kernel, , signal_clear);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , signal_clear, 0, "int");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , signal_clear, 1, "ksiginfo_t *");
|
||||
SDT_PROBE_DEFINE(proc, kernel, , signal_discard);
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , signal_discard, 0, "struct thread *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , signal_discard, 1, "struct proc *");
|
||||
SDT_PROBE_ARGTYPE(proc, kernel, , signal_discard, 2, "int");
|
||||
|
||||
static int coredump(struct thread *);
|
||||
static char *expand_name(const char *, uid_t, pid_t);
|
||||
static int killpg1(struct thread *td, int sig, int pgid, int all);
|
||||
@ -1236,6 +1251,9 @@ kern_sigtimedwait(struct thread *td, sigset_t waitset, ksiginfo_t *ksi,
|
||||
ksiginfo_init(ksi);
|
||||
sigqueue_get(&td->td_sigqueue, sig, ksi);
|
||||
ksi->ksi_signo = sig;
|
||||
|
||||
SDT_PROBE(proc, kernel, , signal_clear, sig, ksi, 0, 0, 0);
|
||||
|
||||
if (ksi->ksi_code == SI_TIMER)
|
||||
itimer_accept(p, ksi->ksi_timerid, ksi);
|
||||
error = 0;
|
||||
@ -1976,6 +1994,8 @@ tdsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi)
|
||||
sigqueue = &td->td_sigqueue;
|
||||
}
|
||||
|
||||
SDT_PROBE(proc, kernel, , signal_send, td, p, sig, 0, 0 );
|
||||
|
||||
/*
|
||||
* If the signal is being ignored,
|
||||
* then we forget about it immediately.
|
||||
@ -1985,6 +2005,8 @@ tdsignal(struct proc *p, struct thread *td, int sig, ksiginfo_t *ksi)
|
||||
*/
|
||||
mtx_lock(&ps->ps_mtx);
|
||||
if (SIGISMEMBER(ps->ps_sigignore, sig)) {
|
||||
SDT_PROBE(proc, kernel, , signal_discard, ps, td, sig, 0, 0 );
|
||||
|
||||
mtx_unlock(&ps->ps_mtx);
|
||||
if (ksi && (ksi->ksi_flags & KSI_INS))
|
||||
ksiginfo_tryfree(ksi);
|
||||
|
Loading…
Reference in New Issue
Block a user