From 4ffba11c271ae9177ac69cc0fd0650c24a37cb1e Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Thu, 28 Mar 2013 20:46:09 +0000 Subject: [PATCH] stack() / jstack(): Send PID to userspace. The stack() and jstack() actions expect the buffer to begin with the PID under investigation, rather than just being a stream of addresses, as now. Adjust the buffer size and contents accordingly. Signed-off-by: Nick Alcock --- dtrace/dtrace_ecb.c | 3 ++- dtrace/dtrace_probe.c | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dtrace/dtrace_ecb.c b/dtrace/dtrace_ecb.c index 596477c7e0af..c2c929324a64 100644 --- a/dtrace/dtrace_ecb.c +++ b/dtrace/dtrace_ecb.c @@ -278,7 +278,8 @@ static int dtrace_ecb_action_add(dtrace_ecb_t *ecb, dtrace_actdesc_t *desc) arg = DTRACE_USTACK_ARG(nframes, strsize); } - size = (nframes + 1) * sizeof(uint64_t); + size = (nframes + 2) * sizeof(uint64_t); /* +1 for limit, + +1 for PID */ size += DTRACE_USTACK_STRSIZE(arg); size = P2ROUNDUP(size, (uint32_t)(sizeof(uintptr_t))); diff --git a/dtrace/dtrace_probe.c b/dtrace/dtrace_probe.c index 0a6cb394a61b..a161c9301d93 100644 --- a/dtrace/dtrace_probe.c +++ b/dtrace/dtrace_probe.c @@ -855,7 +855,9 @@ void dtrace_probe(dtrace_id_t id, uintptr_t arg0, uintptr_t arg1, continue; case DTRACEACT_JSTACK: - case DTRACEACT_USTACK: + case DTRACEACT_USTACK: { + pid_t pid = current->pid; + if (!dtrace_priv_proc(state)) continue; @@ -875,29 +877,35 @@ void dtrace_probe(dtrace_id_t id, uintptr_t arg0, uintptr_t arg1, continue; } + DTRACE_STORE(uint64_t, tomax, valoffs, + (uint64_t)pid); + if (DTRACE_USTACK_STRSIZE(rec->dtrd_arg) != 0 && current->dtrace_helpers != NULL) { /* * This is the slow path -- we have * allocated string space, and we're * getting the stack of a process that - * has helpers. Call into a separate + * has helpers. Call into a separate * routine to perform this processing. */ dtrace_action_ustack( &mstate, state, - (uint64_t *)(tomax + valoffs), + (uint64_t *)(tomax + valoffs + + sizeof(uint64_t)), rec->dtrd_arg); continue; } DTRACE_CPUFLAG_SET(CPU_DTRACE_NOFAULT); dtrace_getupcstack( - (uint64_t *)(tomax + valoffs), + (uint64_t *)(tomax + valoffs + + sizeof(uint64_t)), DTRACE_USTACK_NFRAMES(rec->dtrd_arg) + 1); DTRACE_CPUFLAG_CLEAR(CPU_DTRACE_NOFAULT); continue; + } default: break; -- 2.50.1