summaryrefslogtreecommitdiffstats
path: root/runtime/task_finder.c
diff options
context:
space:
mode:
authorFrank Ch. Eigler <fche@elastic.org>2008-08-21 13:26:56 -0400
committerFrank Ch. Eigler <fche@elastic.org>2008-08-21 13:26:56 -0400
commiteaf7e3121e673d7f5a7b383ab9563766f1e83ff0 (patch)
tree0c1e415b03cc4f11667f6b4d8cb1cf8104b82d5e /runtime/task_finder.c
parentc569c2e4973296701cd4caff35847e2fde32754a (diff)
parent46b3c6cd16e7aba1a5a26b310ee128bfdc7897fa (diff)
downloadsystemtap-steved-eaf7e3121e673d7f5a7b383ab9563766f1e83ff0.tar.gz
systemtap-steved-eaf7e3121e673d7f5a7b383ab9563766f1e83ff0.tar.xz
systemtap-steved-eaf7e3121e673d7f5a7b383ab9563766f1e83ff0.zip
Merge commit 'origin/master' into pr4225
* commit 'origin/master': Added task finder target parameter to vm_callback functions. Supports original and new utrace interfaces. Add ChangeLog entries stap client/server now pass 'make installcheck' Looks for both mmap and mmap2. PR 6841 fix. Add missing 'process' bindings.
Diffstat (limited to 'runtime/task_finder.c')
-rw-r--r--runtime/task_finder.c199
1 files changed, 149 insertions, 50 deletions
diff --git a/runtime/task_finder.c b/runtime/task_finder.c
index 59b83b76..146ce06f 100644
--- a/runtime/task_finder.c
+++ b/runtime/task_finder.c
@@ -11,6 +11,7 @@
#include <linux/mount.h>
#include "syscall.h"
+#include "utrace_compatibility.h"
#include "task_finder_vma.c"
static LIST_HEAD(__stp_task_finder_list);
@@ -36,19 +37,21 @@ atomic_t __stp_attach_count = ATOMIC_INIT (0);
#define debug_task_finder_report() /* empty */
#endif
-typedef int (*stap_task_finder_callback)(struct task_struct *tsk,
+typedef int (*stap_task_finder_callback)(struct stap_task_finder_target *tgt,
+ struct task_struct *tsk,
int register_p,
- int process_p,
- struct stap_task_finder_target *tgt);
+ int process_p);
-typedef int (*stap_task_finder_vm_callback)(struct task_struct *tsk,
+typedef int (*stap_task_finder_vm_callback)(struct stap_task_finder_target *tgt,
+ struct task_struct *tsk,
int map_p, char *vm_path,
unsigned long vm_start,
unsigned long vm_end,
unsigned long vm_pgoff);
#ifdef DEBUG_TASK_FINDER_VMA
-int __stp_tf_vm_cb(struct task_struct *tsk,
+int __stp_tf_vm_cb(struct stap_task_finder_target *tgt,
+ struct task_struct *tsk,
int map_p, char *vm_path,
unsigned long vm_start,
unsigned long vm_end,
@@ -86,23 +89,54 @@ struct stap_task_finder_target {
stap_task_finder_vm_callback vm_callback;
};
+#ifdef UTRACE_ORIG_VERSION
static u32
__stp_utrace_task_finder_target_death(struct utrace_attached_engine *engine,
struct task_struct *tsk);
+#else
+static u32
+__stp_utrace_task_finder_target_death(struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ bool group_dead, int signal);
+#endif
+#ifdef UTRACE_ORIG_VERSION
static u32
__stp_utrace_task_finder_target_quiesce(struct utrace_attached_engine *engine,
struct task_struct *tsk);
+#else
+static u32
+__stp_utrace_task_finder_target_quiesce(enum utrace_resume_action action,
+ struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ unsigned long event);
+#endif
+#ifdef UTRACE_ORIG_VERSION
static u32
__stp_utrace_task_finder_target_syscall_entry(struct utrace_attached_engine *engine,
struct task_struct *tsk,
struct pt_regs *regs);
+#else
+static u32
+__stp_utrace_task_finder_target_syscall_entry(enum utrace_resume_action action,
+ struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ struct pt_regs *regs);
+#endif
+#ifdef UTRACE_ORIG_VERSION
static u32
__stp_utrace_task_finder_target_syscall_exit(struct utrace_attached_engine *engine,
struct task_struct *tsk,
struct pt_regs *regs);
+#else
+static u32
+__stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action,
+ struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ struct pt_regs *regs);
+#endif
static int
stap_register_task_finder_target(struct stap_task_finder_target *new_tgt)
@@ -186,11 +220,11 @@ stap_utrace_detach(struct task_struct *tsk,
// we'd miss detaching from it if we were checking to see if
// it had an mm.
- engine = utrace_attach(tsk, UTRACE_ATTACH_MATCH_OPS, ops, 0);
+ engine = utrace_attach_task(tsk, UTRACE_ATTACH_MATCH_OPS, ops, 0);
if (IS_ERR(engine)) {
rc = -PTR_ERR(engine);
if (rc != ENOENT) {
- _stp_error("utrace_attach returned error %d on pid %d",
+ _stp_error("utrace_attach_task returned error %d on pid %d",
rc, tsk->pid);
}
else {
@@ -203,7 +237,7 @@ stap_utrace_detach(struct task_struct *tsk,
rc = EFAULT;
}
else {
- rc = utrace_detach(tsk, engine);
+ rc = utrace_control(tsk, engine, UTRACE_DETACH);
switch (rc) {
case 0: /* success */
debug_task_finder_detach();
@@ -327,8 +361,8 @@ __stp_get_mm_path(struct mm_struct *mm, char *buf, int buflen)
| UTRACE_EVENT(SYSCALL_ENTRY) \
| UTRACE_EVENT(SYSCALL_EXIT))
-#define __STP_ATTACHED_TASK_VM_EVENTS (__STP_ATTACHED_TASK_VM_BASE_EVENTS \
- | UTRACE_ACTION_QUIESCE \
+#define __STP_ATTACHED_TASK_VM_EVENTS (__STP_ATTACHED_TASK_BASE_EVENTS \
+ | UTRACE_STOP \
| UTRACE_EVENT(QUIESCE))
#define __STP_ATTACHED_TASK_EVENTS(tgt) \
@@ -354,7 +388,7 @@ stap_utrace_attach(struct task_struct *tsk,
return EPERM;
mmput(mm);
- engine = utrace_attach(tsk, UTRACE_ATTACH_CREATE, ops, data);
+ engine = utrace_attach_task(tsk, UTRACE_ATTACH_CREATE, ops, data);
if (IS_ERR(engine)) {
int error = -PTR_ERR(engine);
if (error != ENOENT) {
@@ -369,11 +403,11 @@ stap_utrace_attach(struct task_struct *tsk,
rc = EFAULT;
}
else {
- rc = utrace_set_flags(tsk, engine, event_flags);
+ rc = utrace_set_events(tsk, engine, event_flags);
if (rc == 0)
debug_task_finder_attach();
else
- _stp_error("utrace_set_flags returned error %d on pid %d",
+ _stp_error("utrace_set_events returned error %d on pid %d",
rc, (int)tsk->pid);
}
return rc;
@@ -421,8 +455,9 @@ __stp_utrace_attach_match_filename(struct task_struct *tsk,
continue;
if (cb_tgt->callback != NULL) {
- int rc = cb_tgt->callback(tsk, register_p,
- process_p, cb_tgt);
+ int rc = cb_tgt->callback(cb_tgt, tsk,
+ register_p,
+ process_p);
if (rc != 0) {
_stp_error("callback for %d failed: %d",
(int)tsk->pid, rc);
@@ -505,11 +540,20 @@ __stp_utrace_attach_match_tsk(struct task_struct *path_tsk,
return;
}
+#ifdef UTRACE_ORIG_VERSION
static u32
__stp_utrace_task_finder_report_clone(struct utrace_attached_engine *engine,
struct task_struct *parent,
unsigned long clone_flags,
struct task_struct *child)
+#else
+static u32
+__stp_utrace_task_finder_report_clone(enum utrace_resume_action action,
+ struct utrace_attached_engine *engine,
+ struct task_struct *parent,
+ unsigned long clone_flags,
+ struct task_struct *child)
+#endif
{
int rc;
struct mm_struct *mm;
@@ -517,24 +561,34 @@ __stp_utrace_task_finder_report_clone(struct utrace_attached_engine *engine,
char *mmpath;
if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING)
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
// On clone, attach to the child.
rc = stap_utrace_attach(child, engine->ops, 0,
__STP_TASK_FINDER_EVENTS);
if (rc != 0 && rc != EPERM)
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
__stp_utrace_attach_match_tsk(parent, child, 1,
(clone_flags & CLONE_THREAD) == 0);
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
}
+#ifdef UTRACE_ORIG_VERSION
static u32
__stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine,
struct task_struct *tsk,
const struct linux_binprm *bprm,
struct pt_regs *regs)
+#else
+static u32
+__stp_utrace_task_finder_report_exec(enum utrace_resume_action action,
+ struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ const struct linux_binfmt *fmt,
+ const struct linux_binprm *bprm,
+ struct pt_regs *regs)
+#endif
{
size_t filelen;
struct list_head *tgt_node;
@@ -542,7 +596,7 @@ __stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine,
int found_node = 0;
if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING)
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
// When exec'ing, we need to let callers detach from the
// parent thread (if necessary). For instance, assume
@@ -565,26 +619,40 @@ __stp_utrace_task_finder_report_exec(struct utrace_attached_engine *engine,
// relative.
__stp_utrace_attach_match_tsk(tsk, tsk, 1, 1);
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
}
+#ifdef UTRACE_ORIG_VERSION
static u32
stap_utrace_task_finder_report_death(struct utrace_attached_engine *engine,
struct task_struct *tsk)
+#else
+static u32
+stap_utrace_task_finder_report_death(struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ bool group_dead, int signal)
+#endif
{
debug_task_finder_detach();
- return UTRACE_ACTION_DETACH;
+ return UTRACE_DETACH;
}
+#ifdef UTRACE_ORIG_VERSION
static u32
__stp_utrace_task_finder_target_death(struct utrace_attached_engine *engine,
struct task_struct *tsk)
+#else
+static u32
+__stp_utrace_task_finder_target_death(struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ bool group_dead, int signal)
+#endif
{
struct stap_task_finder_target *tgt = engine->data;
if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) {
debug_task_finder_detach();
- return UTRACE_ACTION_DETACH;
+ return UTRACE_DETACH;
}
// The first implementation of this added a
@@ -600,30 +668,42 @@ __stp_utrace_task_finder_target_death(struct utrace_attached_engine *engine,
int rc;
// Call the callback
- rc = tgt->callback(tsk, 0,
- (tsk->signal == NULL) || (atomic_read(&tsk->signal->live) == 0),
- tgt);
+ rc = tgt->callback(tgt, tsk, 0,
+ ((tsk->signal == NULL)
+ || (atomic_read(&tsk->signal->live) == 0)));
if (rc != 0) {
_stp_error("death callback for %d failed: %d",
(int)tsk->pid, rc);
}
}
debug_task_finder_detach();
- return UTRACE_ACTION_DETACH;
+ return UTRACE_DETACH;
}
+#ifdef UTRACE_ORIG_VERSION
static u32
__stp_utrace_task_finder_target_quiesce(struct utrace_attached_engine *engine,
struct task_struct *tsk)
+#else
+static u32
+__stp_utrace_task_finder_target_quiesce(enum utrace_resume_action action,
+ struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ unsigned long event)
+#endif
{
struct stap_task_finder_target *tgt = engine->data;
+ int rc;
- // Turn off quiesce handling.
- utrace_set_flags(tsk, engine, __STP_ATTACHED_TASK_VM_BASE_EVENTS);
+ // Turn off quiesce handling (and turn on syscall handling).
+ rc = utrace_set_events(tsk, engine, __STP_ATTACHED_TASK_VM_BASE_EVENTS);
+ if (rc != 0)
+ _stp_error("utrace_set_events returned error %d on pid %d",
+ rc, (int)tsk->pid);
if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) {
debug_task_finder_detach();
- return UTRACE_ACTION_DETACH;
+ return UTRACE_DETACH;
}
if (tgt != NULL && tgt->vm_callback != NULL) {
@@ -661,7 +741,8 @@ __stp_utrace_task_finder_target_quiesce(struct utrace_attached_engine *engine,
#endif
if (mmpath) {
// Call the callback
- rc = tgt->vm_callback(tsk, 1, mmpath,
+ rc = tgt->vm_callback(tgt, tsk, 1,
+ mmpath,
vma->vm_start,
vma->vm_end,
(vma->vm_pgoff
@@ -685,7 +766,7 @@ __stp_utrace_task_finder_target_quiesce(struct utrace_attached_engine *engine,
}
utftq_out:
- return (UTRACE_ACTION_NEWSTATE | UTRACE_ACTION_RESUME);
+ return UTRACE_RESUME;
}
@@ -702,10 +783,18 @@ __stp_find_file_based_vma(struct mm_struct *mm, unsigned long addr)
return vma;
}
+#ifdef UTRACE_ORIG_VERSION
static u32
__stp_utrace_task_finder_target_syscall_entry(struct utrace_attached_engine *engine,
struct task_struct *tsk,
struct pt_regs *regs)
+#else
+static u32
+__stp_utrace_task_finder_target_syscall_entry(enum utrace_resume_action action,
+ struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ struct pt_regs *regs)
+#endif
{
struct stap_task_finder_target *tgt = engine->data;
unsigned long syscall_no;
@@ -716,20 +805,21 @@ __stp_utrace_task_finder_target_syscall_entry(struct utrace_attached_engine *eng
if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) {
debug_task_finder_detach();
- return UTRACE_ACTION_DETACH;
+ return UTRACE_DETACH;
}
if (tgt == NULL || tgt->vm_callback == NULL)
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
// See if syscall is one we're interested in.
//
// FIXME: do we need to handle mremap()?
syscall_no = __stp_user_syscall_nr(regs);
if (syscall_no != MMAP_SYSCALL_NO(tsk)
+ && syscall_no != MMAP2_SYSCALL_NO(tsk)
&& syscall_no != MPROTECT_SYSCALL_NO(tsk)
&& syscall_no != MUNMAP_SYSCALL_NO(tsk))
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
// We need the first syscall argument to see what address
@@ -755,7 +845,7 @@ __stp_utrace_task_finder_target_syscall_entry(struct utrace_attached_engine *eng
mmput(mm);
}
}
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
}
static void
@@ -787,7 +877,7 @@ __stp_target_call_vm_callback(struct stap_task_finder_target *tgt,
rc, (int)tsk->pid);
}
else {
- rc = tgt->vm_callback(tsk, 1, mmpath, vma->vm_start,
+ rc = tgt->vm_callback(tgt, tsk, 1, mmpath, vma->vm_start,
vma->vm_end,
(vma->vm_pgoff << PAGE_SHIFT));
if (rc != 0) {
@@ -798,10 +888,18 @@ __stp_target_call_vm_callback(struct stap_task_finder_target *tgt,
_stp_kfree(mmpath_buf);
}
+#ifdef UTRACE_ORIG_VERSION
static u32
__stp_utrace_task_finder_target_syscall_exit(struct utrace_attached_engine *engine,
struct task_struct *tsk,
struct pt_regs *regs)
+#else
+static u32
+__stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action,
+ struct utrace_attached_engine *engine,
+ struct task_struct *tsk,
+ struct pt_regs *regs)
+#endif
{
struct stap_task_finder_target *tgt = engine->data;
unsigned long syscall_no;
@@ -814,27 +912,28 @@ __stp_utrace_task_finder_target_syscall_exit(struct utrace_attached_engine *engi
if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) {
debug_task_finder_detach();
- return UTRACE_ACTION_DETACH;
+ return UTRACE_DETACH;
}
if (tgt == NULL || tgt->vm_callback == NULL)
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
// See if syscall is one we're interested in.
//
// FIXME: do we need to handle mremap()?
syscall_no = __stp_user_syscall_nr(regs);
if (syscall_no != MMAP_SYSCALL_NO(tsk)
+ && syscall_no != MMAP2_SYSCALL_NO(tsk)
&& syscall_no != MPROTECT_SYSCALL_NO(tsk)
&& syscall_no != MUNMAP_SYSCALL_NO(tsk))
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
// Get return value
rv_addr = __stp_user_syscall_return_value(tsk, regs);
if ((rc = __stp_get_user(rv, rv_addr)) != 0) {
_stp_error("couldn't read syscall return value for pid %d: %d",
tsk->pid, rc);
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
}
// We need the first syscall argument to see what address we
@@ -843,7 +942,7 @@ __stp_utrace_task_finder_target_syscall_exit(struct utrace_attached_engine *engi
if ((rc = __stp_get_user(arg0, arg0_addr)) != 0) {
_stp_error("couldn't read syscall arg 0 for pid %d: %d",
tsk->pid, rc);
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
}
#ifdef DEBUG_TASK_FINDER_VMA
@@ -851,9 +950,10 @@ __stp_utrace_task_finder_target_syscall_exit(struct utrace_attached_engine *engi
"tsk %d found %s(0x%lx), returned 0x%lx\n",
tsk->pid,
((syscall_no == MMAP_SYSCALL_NO(tsk)) ? "mmap"
- : ((syscall_no == MPROTECT_SYSCALL_NO(tsk)) ? "mprotect"
- : ((syscall_no == MUNMAP_SYSCALL_NO(tsk)) ? "munmap"
- : "UNKNOWN"))),
+ : ((syscall_no == MMAP2_SYSCALL_NO(tsk)) ? "mmap2"
+ : ((syscall_no == MPROTECT_SYSCALL_NO(tsk)) ? "mprotect"
+ : ((syscall_no == MUNMAP_SYSCALL_NO(tsk)) ? "munmap"
+ : "UNKNOWN")))),
arg0, rv);
#endif
@@ -896,7 +996,7 @@ __stp_utrace_task_finder_target_syscall_exit(struct utrace_attached_engine *engi
// FIXME: We'll need to figure out to
// retrieve the path of a deleted
// vma.
- rc = tgt->vm_callback(tsk, 0, NULL,
+ rc = tgt->vm_callback(tgt, tsk, 0, NULL,
entry->vm_start,
entry->vm_end,
(entry->vm_pgoff
@@ -930,7 +1030,7 @@ __stp_utrace_task_finder_target_syscall_exit(struct utrace_attached_engine *engi
// FIXME: We'll need to figure out to
// retrieve the path of a deleted
// vma.
- rc = tgt->vm_callback(tsk, 0, NULL,
+ rc = tgt->vm_callback(tgt, tsk, 0, NULL,
entry->vm_start,
entry->vm_end,
(entry->vm_pgoff
@@ -963,7 +1063,7 @@ __stp_utrace_task_finder_target_syscall_exit(struct utrace_attached_engine *engi
// Cleanup by deleting the saved vma info.
__stp_tf_remove_vma_entry(entry);
}
- return UTRACE_ACTION_RESUME;
+ return UTRACE_RESUME;
}
struct utrace_engine_ops __stp_utrace_task_finder_ops = {
@@ -1064,9 +1164,8 @@ stap_start_task_finder(void)
// the thread is a thread group
// leader, it is a process.
if (cb_tgt->callback != NULL) {
- rc = cb_tgt->callback(tsk, 1,
- (tsk->pid == tsk->tgid),
- cb_tgt);
+ rc = cb_tgt->callback(cb_tgt, tsk, 1,
+ (tsk->pid == tsk->tgid));
if (rc != 0) {
_stp_error("attach callback for %d failed: %d",
(int)tsk->pid, rc);