From d2f4d7286629da6e9f1b844beefb141a4d3ef2c3 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 10 Dec 2008 20:39:45 +0100 Subject: PR6866: First pass at translating addresses to symbol names through vma. --- runtime/ChangeLog | 11 +++++++++++ runtime/runtime.h | 18 ++++++++++++++++++ runtime/sym.c | 32 ++++++++++++++++++++++++++------ runtime/task_finder.c | 22 ++++++++++++++++------ runtime/task_finder_vma.c | 38 ++++++++++++++++++++++++++------------ 5 files changed, 97 insertions(+), 24 deletions(-) (limited to 'runtime') diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 3f88bae2..d83ac12c 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,14 @@ +2008-12-10 Mark Wielaard + + * runtime.h: Define __stp_tf_vma_entry here. + * sym.c (_stp_mod_sec_lookup): Try vma matching first if task given. + (_stp_kallsyms_lookup): Take an optional task. + (_stp_symbol_snprint): Likewise. + task_finder.c (__stp_tf_vm_cb): Use vm_path to match and attach + module to vma entry. + task_finder_vma.c (stap_add_vma_map_info): Take an optional module. + (__stp_tf_get_vma_entry_addr): New lookup function. + 2008-12-09 Frank Ch. Eigler * time.c (_stp_gettimeofday_ns): Protect some more against freq=0. diff --git a/runtime/runtime.h b/runtime/runtime.h index 3b3e117d..055d3f27 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -86,6 +86,24 @@ static struct #include "io.c" #include "arith.c" #include "copy.c" + +/* Lifted task_finder, internal details used in sym.c - XXX */ +struct __stp_tf_vma_entry { + struct hlist_node hlist; + + pid_t pid; + unsigned long addr; + unsigned long vm_start; + unsigned long vm_end; + unsigned long vm_pgoff; + // Is that enough? Should we store a dcookie for vm_file? + + // Module that this vma entry is mapped from, if any. + struct _stp_module *module; +}; +static struct __stp_tf_vma_entry * +__stp_tf_get_vma_entry_addr(struct task_struct *, unsigned long); + #include "sym.c" #ifdef STP_PERFMON #include "perf.c" diff --git a/runtime/sym.c b/runtime/sym.c index 06ac14a5..9b295f58 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -77,11 +77,28 @@ unsigned long _stp_module_relocate(const char *module, const char *section, unsi if found, return NULL otherwise. XXX: needs to be address-space-specific. */ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, + struct task_struct *task, struct _stp_section **sec) { struct _stp_module *m = NULL; unsigned midx = 0; unsigned long closest_section_offset = ~0; + + // Try vma matching first if task given. + struct __stp_tf_vma_entry *entry; + if (task) + { + entry = __stp_tf_get_vma_entry_addr(task, addr); + if (entry != NULL && entry->module != NULL) + { + m = entry->module; + *sec = & m->sections[0]; // XXX check actual section and relocate + if (strcmp(".dynamic", m->sections[0].name) == 0) + m->sections[0].addr = entry->vm_start; // cheat... + return m; + } + } + for (midx = 0; midx < _stp_num_modules; midx++) { unsigned secidx; @@ -109,7 +126,8 @@ static const char *_stp_kallsyms_lookup(unsigned long addr, unsigned long *symbo unsigned long *offset, const char **modname, /* char ** secname? */ - char *namebuf) + char *namebuf, + struct task_struct *task) { struct _stp_module *m = NULL; struct _stp_section *sec = NULL; @@ -117,7 +135,7 @@ static const char *_stp_kallsyms_lookup(unsigned long addr, unsigned long *symbo unsigned long flags; unsigned end, begin = 0; - m = _stp_mod_sec_lookup(addr, &sec); + m = _stp_mod_sec_lookup(addr, task, &sec); if (unlikely (m == NULL || sec == NULL)) return NULL; @@ -242,7 +260,7 @@ void _stp_symbol_print(unsigned long address) const char *name; unsigned long offset, size; - name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL); + name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, NULL); _stp_printf("%p", (int64_t) address); @@ -267,7 +285,7 @@ int _stp_func_print(unsigned long address, int verbose, int exact) else exstr = " (inexact)"; - name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL); + name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, NULL); if (name) { if (verbose) { @@ -283,13 +301,15 @@ int _stp_func_print(unsigned long address, int verbose, int exact) return 0; } -void _stp_symbol_snprint(char *str, size_t len, unsigned long address) +void _stp_symbol_snprint(char *str, size_t len, unsigned long address, + struct task_struct *task) { const char *modname; const char *name; unsigned long offset, size; - name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL); + name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, + task); if (name) strlcpy(str, name, len); else diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 25fad1a4..1e0a8474 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -55,7 +55,6 @@ typedef int (*stap_task_finder_vm_callback)(struct stap_task_finder_target *tgt, unsigned long vm_end, unsigned long vm_pgoff); -#ifdef DEBUG_TASK_FINDER_VMA int __stp_tf_vm_cb(struct stap_task_finder_target *tgt, struct task_struct *tsk, int map_p, char *vm_path, @@ -63,21 +62,32 @@ int __stp_tf_vm_cb(struct stap_task_finder_target *tgt, unsigned long vm_end, unsigned long vm_pgoff) { + int i; +#ifdef DEBUG_TASK_FINDER_VMA _stp_dbug(__FUNCTION__, __LINE__, "vm_cb: tsk %d:%d path %s, start 0x%08lx, end 0x%08lx, offset 0x%lx\n", tsk->pid, map_p, vm_path, vm_start, vm_end, vm_pgoff); +#endif if (map_p) { - // FIXME: What should we do with vm_path? We can't save - // the vm_path pointer itself, but we don't have any - // storage space allocated to save it in... - stap_add_vma_map_info(tsk, vm_start, vm_end, vm_pgoff); + struct _stp_module *module = NULL; + if (vm_path != NULL) + for (i = 0; i < _stp_num_modules; i++) + if (strcmp(vm_path, _stp_modules[i]->name) == 0) + { +#ifdef DEBUG_TASK_FINDER_VMA + _stp_dbug(__FUNCTION__, __LINE__, + "vm_cb: matched path %s to module\n", vm_path); +#endif + module = _stp_modules[i]; + break; + } + stap_add_vma_map_info(tsk, vm_start, vm_end, vm_pgoff, module); } else { stap_remove_vma_map_info(tsk, vm_start, vm_end, vm_pgoff); } return 0; } -#endif struct stap_task_finder_target { /* private: */ diff --git a/runtime/task_finder_vma.c b/runtime/task_finder_vma.c index 4dce4be8..b65d9ea4 100644 --- a/runtime/task_finder_vma.c +++ b/runtime/task_finder_vma.c @@ -16,17 +16,6 @@ static DEFINE_MUTEX(__stp_tf_vma_mutex); #define TASK_FINDER_VMA_ENTRY_ITEMS 100 #endif -struct __stp_tf_vma_entry { - struct hlist_node hlist; - - pid_t pid; - unsigned long addr; - unsigned long vm_start; - unsigned long vm_end; - unsigned long vm_pgoff; - // Is that enough? Should we store a dcookie for vm_file? -}; - static struct __stp_tf_vma_entry __stp_tf_vma_free_list_items[TASK_FINDER_VMA_ENTRY_ITEMS]; @@ -211,7 +200,8 @@ __stp_tf_get_vma_map_entry_internal(struct task_struct *tsk, // Add the vma info to the vma map hash table. static int stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, - unsigned long vm_end, unsigned long vm_pgoff) + unsigned long vm_end, unsigned long vm_pgoff, + struct _stp_module *module) { struct hlist_head *head; struct hlist_node *node; @@ -242,6 +232,7 @@ stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, entry->vm_start = vm_start; entry->vm_end = vm_end; entry->vm_pgoff = vm_pgoff; + entry->module = module; head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; hlist_add_head(&entry->hlist, head); @@ -305,3 +296,26 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, mutex_unlock(&__stp_tf_vma_mutex); return rc; } + +// Get vma_entry of the address (vm_start/vm_end) if the vma is +// present in the vma hash table containing. +// Returns NULL if not present. +static struct __stp_tf_vma_entry * +__stp_tf_get_vma_entry_addr(struct task_struct *tsk, unsigned long addr) +{ + struct hlist_head *head; + struct hlist_node *node; + struct __stp_tf_vma_entry *entry; + + mutex_lock(&__stp_tf_vma_mutex); + head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; + hlist_for_each_entry(entry, node, head, hlist) { + if (tsk->pid == entry->pid + && addr >= entry->vm_start && addr < entry->vm_end) { + mutex_unlock(&__stp_tf_vma_mutex); + return entry; + } + } + mutex_unlock(&__stp_tf_vma_mutex); + return NULL; +} -- cgit From 204038b16193de78eeb333fde0cce6081d9d1fcd Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 15 Dec 2008 17:51:49 +0100 Subject: Always include task_finder.c and enable emit_vm_callback_probe_decl. --- runtime/ChangeLog | 7 +++++++ runtime/runtime.h | 17 +---------------- runtime/sym.c | 4 +++- runtime/task_finder_vma.c | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 17 deletions(-) (limited to 'runtime') diff --git a/runtime/ChangeLog b/runtime/ChangeLog index d83ac12c..b9a2a058 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,10 @@ +2008-12-15 Mark Wielaard + + * runtime.h: Just include task_finder.c instead of defining parts + of it here. + * sym.c (_stp_mod_sec_lookup): Add dbug_sym statements. + * task_finder_vma.c: Define __stp_tf_vma_entry here. + 2008-12-10 Mark Wielaard * runtime.h: Define __stp_tf_vma_entry here. diff --git a/runtime/runtime.h b/runtime/runtime.h index 055d3f27..3ca43dc4 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -87,22 +87,7 @@ static struct #include "arith.c" #include "copy.c" -/* Lifted task_finder, internal details used in sym.c - XXX */ -struct __stp_tf_vma_entry { - struct hlist_node hlist; - - pid_t pid; - unsigned long addr; - unsigned long vm_start; - unsigned long vm_end; - unsigned long vm_pgoff; - // Is that enough? Should we store a dcookie for vm_file? - - // Module that this vma entry is mapped from, if any. - struct _stp_module *module; -}; -static struct __stp_tf_vma_entry * -__stp_tf_get_vma_entry_addr(struct task_struct *, unsigned long); +#include "task_finder.c" #include "sym.c" #ifdef STP_PERFMON diff --git a/runtime/sym.c b/runtime/sym.c index 9b295f58..82eef17d 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -92,7 +92,9 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, if (entry != NULL && entry->module != NULL) { m = entry->module; - *sec = & m->sections[0]; // XXX check actual section and relocate + *sec = &m->sections[0]; // XXX check actual section and relocate + dbug_sym(1, "found section %s in module %s at 0x%lx\n", + m->sections[0].name, m->name, entry->vm_start); if (strcmp(".dynamic", m->sections[0].name) == 0) m->sections[0].addr = entry->vm_start; // cheat... return m; diff --git a/runtime/task_finder_vma.c b/runtime/task_finder_vma.c index b65d9ea4..87a32fe5 100644 --- a/runtime/task_finder_vma.c +++ b/runtime/task_finder_vma.c @@ -16,6 +16,20 @@ static DEFINE_MUTEX(__stp_tf_vma_mutex); #define TASK_FINDER_VMA_ENTRY_ITEMS 100 #endif +struct __stp_tf_vma_entry { + struct hlist_node hlist; + + pid_t pid; + unsigned long addr; + unsigned long vm_start; + unsigned long vm_end; + unsigned long vm_pgoff; + // Is that enough? Should we store a dcookie for vm_file? + + // Module that this vma entry is mapped from, if any. + struct _stp_module *module; +}; + static struct __stp_tf_vma_entry __stp_tf_vma_free_list_items[TASK_FINDER_VMA_ENTRY_ITEMS]; -- cgit From cb1468beb7b34ad988280fea9fb7c4558b47341a Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 18 Mar 2009 12:27:13 +0100 Subject: Replace mutex in task_finder_vma with rwlock to be interrupt context safe. * runtime/task_finder_vma.c: Replace all mutex calls with appropriate read or write (un)lock calls. --- runtime/task_finder_vma.c | 82 +++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 31 deletions(-) (limited to 'runtime') diff --git a/runtime/task_finder_vma.c b/runtime/task_finder_vma.c index 83b206e5..a210d92e 100644 --- a/runtime/task_finder_vma.c +++ b/runtime/task_finder_vma.c @@ -1,13 +1,19 @@ #include #include -#include +#include // When handling memcpy() syscall tracing to notice memory map // changes, we need to cache memcpy() entry parameter values for // processing at memcpy() exit. -// __stp_tf_vma_mutex protects the hash table. -static DEFINE_MUTEX(__stp_tf_vma_mutex); +// __stp_tf_vma_lock protects the hash table. +// Documentation/spinlocks.txt suggest we can be a bit more clever +// if we guarantee that in interrupt context we only read, not write +// the datastructures. We should never change the hash table or the +// contents in interrupt context (which should only ever call +// __stp_tf_get_vma_entry_addr for symbol lookup). So we might want +// to look into that if this seems a bottleneck. +static DEFINE_RWLOCK(__stp_tf_vma_lock); #define __STP_TF_HASH_BITS 4 #define __STP_TF_TABLE_SIZE (1 << __STP_TF_HASH_BITS) @@ -40,23 +46,24 @@ static struct hlist_head __stp_tf_vma_table[__STP_TF_TABLE_SIZE]; static struct hlist_head __stp_tf_vma_map[__STP_TF_TABLE_SIZE]; // __stp_tf_vma_initialize(): Initialize the free list. Grabs the -// mutex. +// spinlock. static void __stp_tf_vma_initialize(void) { int i; struct hlist_head *head = &__stp_tf_vma_free_list[0]; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + write_lock_irqsave(&__stp_tf_vma_lock, flags); for (i = 0; i < TASK_FINDER_VMA_ENTRY_ITEMS; i++) { hlist_add_head(&__stp_tf_vma_free_list_items[i].hlist, head); } - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); } // __stp_tf_vma_get_free_entry(): Returns an entry from the free list -// or NULL. The __stp_tf_vma_mutex must be locked before calling this +// or NULL. The __stp_tf_vma_lock must be write locked before calling this // function. static struct __stp_tf_vma_entry * __stp_tf_vma_get_free_entry(void) @@ -77,7 +84,7 @@ __stp_tf_vma_get_free_entry(void) // __stp_tf_vma_put_free_entry(): Puts an entry back on the free -// list. The __stp_tf_vma_mutex must be locked before calling this +// list. The __stp_tf_vma_lock must be write locked before calling this // function. static void __stp_tf_vma_put_free_entry(struct __stp_tf_vma_entry *entry) @@ -101,7 +108,7 @@ __stp_tf_vma_hash(struct task_struct *tsk, unsigned long addr) // Get vma_entry if the vma is present in the vma hash table. -// Returns NULL if not present. +// Returns NULL if not present. Takes a read lock on __stp_tf_vma_lock. static struct __stp_tf_vma_entry * __stp_tf_get_vma_entry(struct task_struct *tsk, unsigned long addr) { @@ -109,20 +116,22 @@ __stp_tf_get_vma_entry(struct task_struct *tsk, unsigned long addr) struct hlist_node *node; struct __stp_tf_vma_entry *entry; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + read_lock_irqsave(&__stp_tf_vma_lock, flags); head = &__stp_tf_vma_table[__stp_tf_vma_hash(tsk, addr)]; hlist_for_each_entry(entry, node, head, hlist) { if (tsk->pid == entry->pid && addr == entry->addr) { - mutex_unlock(&__stp_tf_vma_mutex); + read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return entry; } } - mutex_unlock(&__stp_tf_vma_mutex); + read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return NULL; } // Add the vma info to the vma hash table. +// Takes a write lock on __stp_tf_vma_lock. static int __stp_tf_add_vma(struct task_struct *tsk, unsigned long addr, struct vm_area_struct *vma) @@ -131,7 +140,8 @@ __stp_tf_add_vma(struct task_struct *tsk, unsigned long addr, struct hlist_node *node; struct __stp_tf_vma_entry *entry; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + write_lock_irqsave(&__stp_tf_vma_lock, flags); head = &__stp_tf_vma_table[__stp_tf_vma_hash(tsk, addr)]; hlist_for_each_entry(entry, node, head, hlist) { if (tsk->pid == entry->pid @@ -141,7 +151,7 @@ __stp_tf_add_vma(struct task_struct *tsk, unsigned long addr, "vma (pid: %d, vm_start: 0x%lx) present?\n", tsk->pid, vma->vm_start); #endif - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return -EBUSY; /* Already there */ } } @@ -149,7 +159,7 @@ __stp_tf_add_vma(struct task_struct *tsk, unsigned long addr, // Get an element from the free list. entry = __stp_tf_vma_get_free_entry(); if (!entry) { - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return -ENOMEM; } entry->pid = tsk->pid; @@ -158,11 +168,12 @@ __stp_tf_add_vma(struct task_struct *tsk, unsigned long addr, entry->vm_end = vma->vm_end; entry->vm_pgoff = vma->vm_pgoff; hlist_add_head(&entry->hlist, head); - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return 0; } // Remove the vma entry from the vma hash table. +// Takes a write lock on __stp_tf_vma_lock. static int __stp_tf_remove_vma_entry(struct __stp_tf_vma_entry *entry) { @@ -171,10 +182,11 @@ __stp_tf_remove_vma_entry(struct __stp_tf_vma_entry *entry) int found = 0; if (entry != NULL) { - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + write_lock_irqsave(&__stp_tf_vma_lock, flags); hlist_del(&entry->hlist); __stp_tf_vma_put_free_entry(entry); - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); } return 0; } @@ -189,7 +201,7 @@ __stp_tf_vma_map_hash(struct task_struct *tsk) } // Get vma_entry if the vma is present in the vma map hash table. -// Returns NULL if not present. The __stp_tf_vma_mutex must be locked +// Returns NULL if not present. The __stp_tf_vma_lock must be read locked // before calling this function. static struct __stp_tf_vma_entry * __stp_tf_get_vma_map_entry_internal(struct task_struct *tsk, @@ -220,7 +232,10 @@ stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, struct hlist_node *node; struct __stp_tf_vma_entry *entry; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + // Take a write lock, since we are most likely going to write + // after reading. + write_lock_irqsave(&__stp_tf_vma_lock, flags); entry = __stp_tf_get_vma_map_entry_internal(tsk, vm_start); if (entry != NULL) { #if 0 @@ -228,14 +243,14 @@ stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, "vma (pid: %d, vm_start: 0x%lx) present?\n", tsk->pid, entry->vm_start); #endif - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return -EBUSY; /* Already there */ } // Get an element from the free list. entry = __stp_tf_vma_get_free_entry(); if (!entry) { - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return -ENOMEM; } @@ -249,7 +264,7 @@ stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; hlist_add_head(&entry->hlist, head); - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return 0; } @@ -263,18 +278,21 @@ stap_remove_vma_map_info(struct task_struct *tsk, unsigned long vm_start, struct hlist_node *node; struct __stp_tf_vma_entry *entry; - mutex_lock(&__stp_tf_vma_mutex); + // Take a write lock since we are most likely going to delete + // after reading. + unsigned long flags; + write_lock_irqsave(&__stp_tf_vma_lock, flags); entry = __stp_tf_get_vma_map_entry_internal(tsk, vm_start); if (entry != NULL) { hlist_del(&entry->hlist); __stp_tf_vma_put_free_entry(entry); } - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return 0; } // Finds vma info if the vma is present in the vma map hash table. -// Returns ESRCH if not present. The __stp_tf_vma_mutex must *not* be +// Returns ESRCH if not present. The __stp_tf_vma_lock must *not* be // locked before calling this function. static int stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, @@ -287,7 +305,8 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, struct __stp_tf_vma_entry *found_entry = NULL; int rc = ESRCH; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + read_lock_irqsave(&__stp_tf_vma_lock, flags); head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; hlist_for_each_entry(entry, node, head, hlist) { if (tsk->pid == entry->pid @@ -306,7 +325,7 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, *vm_pgoff = found_entry->vm_pgoff; rc = 0; } - mutex_unlock(&__stp_tf_vma_mutex); + read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return rc; } @@ -320,15 +339,16 @@ __stp_tf_get_vma_entry_addr(struct task_struct *tsk, unsigned long addr) struct hlist_node *node; struct __stp_tf_vma_entry *entry; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + read_lock_irqsave(&__stp_tf_vma_lock, flags); head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; hlist_for_each_entry(entry, node, head, hlist) { if (tsk->pid == entry->pid && addr >= entry->vm_start && addr < entry->vm_end) { - mutex_unlock(&__stp_tf_vma_mutex); + read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return entry; } } - mutex_unlock(&__stp_tf_vma_mutex); + read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return NULL; } -- cgit From 1882152af71f8339c91751ee17c97f1c4d18660a Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 19 Mar 2009 14:28:14 +0100 Subject: Get rid of __stp_tf_get_vma_entry_addr function. * runtime/task_finder_vma.c (__stp_tf_get_vma_entry_addr): Deleted. (struct __stp_tf_vma_entry): Replace module by user void* field. (stap_add_vma_map_info): Take a void *user arg. (stap_find_vma_map_info): Take a void **user arg. * runtime/sym.c (_stp_mod_sec_lookup): Use stap_find_vma_map_info. --- runtime/sym.c | 28 ++++++++++++++++------------ runtime/task_finder_vma.c | 40 +++++++++------------------------------- 2 files changed, 25 insertions(+), 43 deletions(-) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index 3788544e..1fe3f818 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -79,25 +79,29 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, struct task_struct *task, struct _stp_section **sec) { + void *user; struct _stp_module *m = NULL; unsigned midx = 0; unsigned long closest_section_offset = ~0; // Try vma matching first if task given. - struct __stp_tf_vma_entry *entry; + unsigned long vm_start; if (task) { - entry = __stp_tf_get_vma_entry_addr(task, addr); - if (entry != NULL && entry->module != NULL) - { - m = entry->module; - *sec = &m->sections[0]; // XXX check actual section and relocate - dbug_sym(1, "found section %s in module %s at 0x%lx\n", - m->sections[0].name, m->name, entry->vm_start); - if (strcmp(".dynamic", m->sections[0].name) == 0) - m->sections[0].addr = entry->vm_start; // cheat... - return m; - } + + if (stap_find_vma_map_info(task, addr, + &vm_start, NULL, + NULL, &user) == 0) + if (user != NULL) + { + m = (struct _stp_module *)user; + *sec = &m->sections[0]; // XXX check actual section and relocate + dbug_sym(1, "found section %s in module %s at 0x%lx\n", + m->sections[0].name, m->name, vm_start); + if (strcmp(".dynamic", m->sections[0].name) == 0) + m->sections[0].addr = vm_start; // cheat... + return m; + } } for (midx = 0; midx < _stp_num_modules; midx++) diff --git a/runtime/task_finder_vma.c b/runtime/task_finder_vma.c index a210d92e..ed9c6f4f 100644 --- a/runtime/task_finder_vma.c +++ b/runtime/task_finder_vma.c @@ -11,8 +11,8 @@ // if we guarantee that in interrupt context we only read, not write // the datastructures. We should never change the hash table or the // contents in interrupt context (which should only ever call -// __stp_tf_get_vma_entry_addr for symbol lookup). So we might want -// to look into that if this seems a bottleneck. +// stap_find_vma_map_info for getting stored vma info). So we might +// want to look into that if this seems a bottleneck. static DEFINE_RWLOCK(__stp_tf_vma_lock); #define __STP_TF_HASH_BITS 4 @@ -32,8 +32,8 @@ struct __stp_tf_vma_entry { unsigned long vm_pgoff; // Is that enough? Should we store a dcookie for vm_file? - // Module that this vma entry is mapped from, if any. - struct _stp_module *module; + // User data (possibly stp_module) + void *user; }; static struct __stp_tf_vma_entry @@ -226,7 +226,7 @@ __stp_tf_get_vma_map_entry_internal(struct task_struct *tsk, static int stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, unsigned long vm_end, unsigned long vm_pgoff, - struct _stp_module *module) + void *user) { struct hlist_head *head; struct hlist_node *node; @@ -260,7 +260,7 @@ stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, entry->vm_start = vm_start; entry->vm_end = vm_end; entry->vm_pgoff = vm_pgoff; - entry->module = module; + entry->user = user; head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; hlist_add_head(&entry->hlist, head); @@ -297,7 +297,7 @@ stap_remove_vma_map_info(struct task_struct *tsk, unsigned long vm_start, static int stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, unsigned long *vm_start, unsigned long *vm_end, - unsigned long *vm_pgoff) + unsigned long *vm_pgoff, void **user) { struct hlist_head *head; struct hlist_node *node; @@ -323,32 +323,10 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, *vm_end = found_entry->vm_end; if (vm_pgoff != NULL) *vm_pgoff = found_entry->vm_pgoff; + if (user != NULL) + *user = found_entry->user; rc = 0; } read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return rc; } - -// Get vma_entry of the address (vm_start/vm_end) if the vma is -// present in the vma hash table containing. -// Returns NULL if not present. -static struct __stp_tf_vma_entry * -__stp_tf_get_vma_entry_addr(struct task_struct *tsk, unsigned long addr) -{ - struct hlist_head *head; - struct hlist_node *node; - struct __stp_tf_vma_entry *entry; - - unsigned long flags; - read_lock_irqsave(&__stp_tf_vma_lock, flags); - head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; - hlist_for_each_entry(entry, node, head, hlist) { - if (tsk->pid == entry->pid - && addr >= entry->vm_start && addr < entry->vm_end) { - read_unlock_irqrestore(&__stp_tf_vma_lock, flags); - return entry; - } - } - read_unlock_irqrestore(&__stp_tf_vma_lock, flags); - return NULL; -} -- cgit From bfd5b4a50e6797da88a11eb6a52c185d2826a0d1 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 19 Mar 2009 14:51:33 +0100 Subject: Initialize user and vm_start before use. * runtime/sym.c (_stp_mod_sec_lookup): Initialize user and vm_start. --- runtime/sym.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index 1fe3f818..ed108f08 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -79,16 +79,15 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, struct task_struct *task, struct _stp_section **sec) { - void *user; + void *user = NULL; struct _stp_module *m = NULL; unsigned midx = 0; unsigned long closest_section_offset = ~0; // Try vma matching first if task given. - unsigned long vm_start; if (task) { - + unsigned long vm_start = 0; if (stap_find_vma_map_info(task, addr, &vm_start, NULL, NULL, &user) == 0) -- cgit From 5e94ef56760c087784e485c35521a6e438cfc3e5 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 19 Mar 2009 16:51:02 +0100 Subject: Remove __stp_tf_vm_cb from task_finder interface. * runtime/task_finder.c (__stp_tf_vm_cb): Removed. * tapsets.cxx (utrace_derived_probe_group::emit_module_decls): Output task finder vma callback and hook it. --- runtime/task_finder.c | 34 ---------------------------------- 1 file changed, 34 deletions(-) (limited to 'runtime') diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 38f9145d..1db2bc2a 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -55,40 +55,6 @@ typedef int (*stap_task_finder_vm_callback)(struct stap_task_finder_target *tgt, unsigned long vm_end, unsigned long vm_pgoff); -static 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, - unsigned long vm_pgoff) -{ - int i; -#ifdef DEBUG_TASK_FINDER_VMA - _stp_dbug(__FUNCTION__, __LINE__, - "vm_cb: tsk %d:%d path %s, start 0x%08lx, end 0x%08lx, offset 0x%lx\n", - tsk->pid, map_p, vm_path, vm_start, vm_end, vm_pgoff); -#endif - if (map_p) { - struct _stp_module *module = NULL; - if (vm_path != NULL) - for (i = 0; i < _stp_num_modules; i++) - if (strcmp(vm_path, _stp_modules[i]->path) == 0) - { -#ifdef DEBUG_TASK_FINDER_VMA - _stp_dbug(__FUNCTION__, __LINE__, - "vm_cb: matched path %s to module\n", vm_path); -#endif - module = _stp_modules[i]; - break; - } - stap_add_vma_map_info(tsk, vm_start, vm_end, vm_pgoff, module); - } - else { - stap_remove_vma_map_info(tsk, vm_start, vm_end, vm_pgoff); - } - return 0; -} - struct stap_task_finder_target { /* private: */ struct list_head list; /* __stp_task_finder_list linkage */ -- cgit From f735e6054d182b589750db65a906c1851faa9d75 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 20 Mar 2009 13:30:58 +0100 Subject: Move _stp_tf_vm_cb to sym.c. * tapsets.cxx (utrace_derived_probe_group::emit_module_decls): Remove output task finder vma callback _stp_tf_vm_cb. * runtime/sym.c (_stp_tf_vm_cb): And add it here. --- runtime/sym.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index ed108f08..d0c5d9fd 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -20,6 +20,40 @@ * @{ */ +/* Callback that needs to be registered (in tapsets.cxx for + emit_module_init) for every user task path or pid for which we + might need symbols or unwind info. */ +static 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, + unsigned long vm_pgoff) +{ + int i; +#ifdef DEBUG_TASK_FINDER_VMA + _stp_dbug(__FUNCTION__, __LINE__, "vm_cb: tsk %d:%d path %s, start 0x%08lx, end 0x%08lx, offset 0x%lx\n", tsk->pid, map_p, vm_path, vm_start, vm_end, vm_pgoff); +#endif + if (map_p) + { + struct _stp_module *module = NULL; + if (vm_path != NULL) + for (i = 0; i < _stp_num_modules; i++) + if (strcmp(vm_path, _stp_modules[i]->path) == 0) + { +#ifdef DEBUG_TASK_FINDER_VMA + _stp_dbug(__FUNCTION__, __LINE__, "vm_cb: matched path %s to module\n", vm_path); +#endif + module = _stp_modules[i]; + break; + } + stap_add_vma_map_info(tsk, vm_start, vm_end, vm_pgoff, module); + } + else + stap_remove_vma_map_info(tsk, vm_start, vm_end, vm_pgoff); + + return 0; +} + /* XXX: this needs to be address-space-specific. */ static unsigned long _stp_module_relocate(const char *module, const char *section, unsigned long offset) { -- cgit From 76eb4a5d7a17bd8c37a679590c55b94e200042d0 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 1 Apr 2009 11:30:50 -0400 Subject: PR4105: support up to 9 (up from 5) array index dimensions * runtime/map-gen.c, pmap-gen.c: Hand-expand arity 6..9 cases throughout. * testsuite/buildok/thirty.stp: New test. * testsuite/buildko/two.stp: New test. An Alan Smithee patch. --- runtime/map-gen.c | 291 +++++++++++++++++++++++++++++++++++++++++++++ runtime/pmap-gen.c | 343 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 634 insertions(+) (limited to 'runtime') diff --git a/runtime/map-gen.c b/runtime/map-gen.c index c4bdf2c7..fdb75089 100644 --- a/runtime/map-gen.c +++ b/runtime/map-gen.c @@ -26,6 +26,14 @@ #define JOIN5x(a,b,c,d,e,f) a##_##b##c##d##e##f #define JOIN6(a,b,c,d,e,f,g) JOIN6x(a,b,c,d,e,f,g) #define JOIN6x(a,b,c,d,e,f,g) a##_##b##c##d##e##f##g +#define JOIN7(a,b,c,d,e,f,g,h) JOIN7x(a,b,c,d,e,f,g,h) +#define JOIN7x(a,b,c,d,e,f,g,h) a##_##b##c##d##e##f##g##h +#define JOIN8(a,b,c,d,e,f,g,h,i) JOIN8x(a,b,c,d,e,f,g,h,i) +#define JOIN8x(a,b,c,d,e,f,g,h,i) a##_##b##c##d##e##f##g##h##i +#define JOIN9(a,b,c,d,e,f,g,h,i,j) JOIN9x(a,b,c,d,e,f,g,h,i,j) +#define JOIN9x(a,b,c,d,e,f,g,h,i,j) a##_##b##c##d##e##f##g##h##i##j +#define JOIN10(a,b,c,d,e,f,g,h,i,j,k) JOIN10x(a,b,c,d,e,f,g,h,i,j,k) +#define JOIN10x(a,b,c,d,e,f,g,h,i,j,k) a##_##b##c##d##e##f##g##h##i##j##k #include "map.h" @@ -162,6 +170,113 @@ #define KEY5_HASH JOIN(KEY5NAME,hash) #endif /* defined(KEY5_TYPE) */ +#if defined (KEY6_TYPE) +#undef KEY_ARITY +#define KEY_ARITY 6 +#if KEY6_TYPE == STRING +#define KEY6TYPE char* +#define KEY6NAME str +#define KEY6N s +#define KEY6STOR char key6[MAP_STRING_LENGTH] +#define KEY6CPY(m) str_copy(m->key6, key6) +#else +#define KEY6TYPE int64_t +#define KEY6NAME int64 +#define KEY6N i +#define KEY6STOR int64_t key6 +#define KEY6CPY(m) m->key6=key6 +#endif +#define KEY6_EQ_P JOIN(KEY6NAME,eq_p) +#define KEY6_HASH JOIN(KEY6NAME,hash) +#endif /* defined(KEY6_TYPE) */ + +#if defined (KEY7_TYPE) +#undef KEY_ARITY +#define KEY_ARITY 7 +#if KEY7_TYPE == STRING +#define KEY7TYPE char* +#define KEY7NAME str +#define KEY7N s +#define KEY7STOR char key7[MAP_STRING_LENGTH] +#define KEY7CPY(m) str_copy(m->key7, key7) +#else +#define KEY7TYPE int64_t +#define KEY7NAME int64 +#define KEY7N i +#define KEY7STOR int64_t key7 +#define KEY7CPY(m) m->key7=key7 +#endif +#define KEY7_EQ_P JOIN(KEY7NAME,eq_p) +#define KEY7_HASH JOIN(KEY7NAME,hash) +#endif /* defined(KEY7_TYPE) */ + +#if defined (KEY7_TYPE) +#undef KEY_ARITY +#define KEY_ARITY 7 +#if KEY7_TYPE == STRING +#define KEY7TYPE char* +#define KEY7NAME str +#define KEY7N s +#define KEY7STOR char key7[MAP_STRING_LENGTH] +#define KEY7CPY(m) str_copy(m->key7, key7) +#else +#define KEY7TYPE int64_t +#define KEY7NAME int64 +#define KEY7N i +#define KEY7STOR int64_t key7 +#define KEY7CPY(m) m->key7=key7 +#endif +#define KEY7_EQ_P JOIN(KEY7NAME,eq_p) +#define KEY7_HASH JOIN(KEY7NAME,hash) +#endif /* defined(KEY7_TYPE) */ + +#if defined (KEY8_TYPE) +#undef KEY_ARITY +#define KEY_ARITY 8 +#if KEY8_TYPE == STRING +#define KEY8TYPE char* +#define KEY8NAME str +#define KEY8N s +#define KEY8STOR char key8[MAP_STRING_LENGTH] +#define KEY8CPY(m) str_copy(m->key8, key8) +#else +#define KEY8TYPE int64_t +#define KEY8NAME int64 +#define KEY8N i +#define KEY8STOR int64_t key8 +#define KEY8CPY(m) m->key8=key8 +#endif +#define KEY8_EQ_P JOIN(KEY8NAME,eq_p) +#define KEY8_HASH JOIN(KEY8NAME,hash) +#endif /* defined(KEY8_TYPE) */ + +#if defined (KEY9_TYPE) +#undef KEY_ARITY +#define KEY_ARITY 9 +#if KEY9_TYPE == STRING +#define KEY9TYPE char* +#define KEY9NAME str +#define KEY9N s +#define KEY9STOR char key9[MAP_STRING_LENGTH] +#define KEY9CPY(m) str_copy(m->key9, key9) +#else +#define KEY9TYPE int64_t +#define KEY9NAME int64 +#define KEY9N i +#define KEY9STOR int64_t key9 +#define KEY9CPY(m) m->key9=key9 +#endif +#define KEY9_EQ_P JOIN(KEY9NAME,eq_p) +#define KEY9_HASH JOIN(KEY9NAME,hash) +#endif /* defined(KEY9_TYPE) */ + +/* Not so many, cowboy! */ +#if defined (KEY10_TYPE) +#error "excessive key arity == too many array indexes" +#endif + + + #if KEY_ARITY == 1 #define KEYSYM(x) JOIN2(x,KEY1N,VALN) #define ALLKEYS(x) x##1 @@ -187,6 +302,26 @@ #define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5 #define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5 #define KEYCPY(m) {KEY1CPY(m);KEY2CPY(m);KEY3CPY(m);KEY4CPY(m);KEY5CPY(m);} +#elif KEY_ARITY == 6 +#define KEYSYM(x) JOIN7(x,KEY1N,KEY2N,KEY3N,KEY4N,KEY5N,KEY6N,VALN) +#define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5, x##6 +#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5, KEY6TYPE x##6 +#define KEYCPY(m) {KEY1CPY(m);KEY2CPY(m);KEY3CPY(m);KEY4CPY(m);KEY5CPY(m);KEY6CPY(m);} +#elif KEY_ARITY == 7 +#define KEYSYM(x) JOIN8(x,KEY1N,KEY2N,KEY3N,KEY4N,KEY5N,KEY6N,KEY7N,VALN) +#define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5, x##6, x##7 +#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5, KEY6TYPE x##6, KEY7TYPE x##7 +#define KEYCPY(m) {KEY1CPY(m);KEY2CPY(m);KEY3CPY(m);KEY4CPY(m);KEY5CPY(m);KEY6CPY(m);KEY7CPY(m);} +#elif KEY_ARITY == 8 +#define KEYSYM(x) JOIN9(x,KEY1N,KEY2N,KEY3N,KEY4N,KEY5N,KEY6N,KEY7N,KEY8N,VALN) +#define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5, x##6, x##7, x##8 +#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5, KEY6TYPE x##6, KEY7TYPE x##7, KEY8TYPE x##8 +#define KEYCPY(m) {KEY1CPY(m);KEY2CPY(m);KEY3CPY(m);KEY4CPY(m);KEY5CPY(m);KEY6CPY(m);KEY7CPY(m);KEY8CPY(m);} +#elif KEY_ARITY == 9 +#define KEYSYM(x) JOIN10(x,KEY1N,KEY2N,KEY3N,KEY4N,KEY5N,KEY6N,KEY7N,KEY8N,KEY9N,VALN) +#define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5, x##6, x##7, x##8, x##9 +#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5, KEY6TYPE x##6, KEY7TYPE x##7, KEY8TYPE x##8, KEY9TYPE x##9 +#define KEYCPY(m) {KEY1CPY(m);KEY2CPY(m);KEY3CPY(m);KEY4CPY(m);KEY5CPY(m);KEY6CPY(m);KEY7CPY(m);KEY8CPY(m);KEY9CPY(m);} #endif /* */ @@ -208,6 +343,18 @@ struct KEYSYM(map_node) { KEY4STOR; #if KEY_ARITY > 4 KEY5STOR; +#if KEY_ARITY > 5 + KEY6STOR; +#if KEY_ARITY > 6 + KEY7STOR; +#if KEY_ARITY > 7 + KEY8STOR; +#if KEY_ARITY > 8 + KEY9STOR; +#endif +#endif +#endif +#endif #endif #endif #endif @@ -266,6 +413,34 @@ static key_data KEYSYM(map_get_key) (struct map_node *mn, int n, int *type) if (type) *type = type_to_enum(KEY5TYPE); break; +#if KEY_ARITY > 5 + case 6: + ptr = (key_data)m->key6; + if (type) + *type = type_to_enum(KEY6TYPE); + break; +#if KEY_ARITY > 6 + case 7: + ptr = (key_data)m->key7; + if (type) + *type = type_to_enum(KEY7TYPE); + break; +#if KEY_ARITY > 7 + case 8: + ptr = (key_data)m->key8; + if (type) + *type = type_to_enum(KEY8TYPE); + break; +#if KEY_ARITY > 8 + case 9: + ptr = (key_data)m->key9; + if (type) + *type = type_to_enum(KEY9TYPE); + break; +#endif +#endif +#endif +#endif #endif #endif #endif @@ -309,6 +484,34 @@ static unsigned int KEYSYM(keycheck) (ALLKEYSD(key)) if (key5 == NULL) return 0; #endif + +#if KEY_ARITY > 5 +#if KEY6_TYPE == STRING + if (key6 == NULL) + return 0; +#endif + +#if KEY_ARITY > 6 +#if KEY7_TYPE == STRING + if (key7 == NULL) + return 0; +#endif + +#if KEY_ARITY > 7 +#if KEY8_TYPE == STRING + if (key8 == NULL) + return 0; +#endif + +#if KEY_ARITY > 8 +#if KEY9_TYPE == STRING + if (key9 == NULL) + return 0; +#endif +#endif +#endif +#endif +#endif #endif #endif #endif @@ -327,6 +530,18 @@ static unsigned int KEYSYM(hash) (ALLKEYSD(key)) hash ^= KEY4_HASH(key4); #if KEY_ARITY > 4 hash ^= KEY5_HASH(key5); +#if KEY_ARITY > 5 + hash ^= KEY6_HASH(key6); +#if KEY_ARITY > 6 + hash ^= KEY7_HASH(key7); +#if KEY_ARITY > 7 + hash ^= KEY8_HASH(key8); +#if KEY_ARITY > 8 + hash ^= KEY9_HASH(key9); +#endif +#endif +#endif +#endif #endif #endif #endif @@ -411,6 +626,18 @@ static int KEYSYM(__stp_map_set) (MAP map, ALLKEYSD(key), VSTYPE val, int add) && KEY4_EQ_P(n->key4, key4) #if KEY_ARITY > 4 && KEY5_EQ_P(n->key5, key5) +#if KEY_ARITY > 5 + && KEY6_EQ_P(n->key6, key6) +#if KEY_ARITY > 6 + && KEY7_EQ_P(n->key7, key7) +#if KEY_ARITY > 7 + && KEY8_EQ_P(n->key8, key8) +#if KEY_ARITY > 8 + && KEY9_EQ_P(n->key9, key9) +#endif +#endif +#endif +#endif #endif #endif #endif @@ -462,6 +689,18 @@ static VALTYPE KEYSYM(_stp_map_get) (MAP map, ALLKEYSD(key)) && KEY4_EQ_P(n->key4, key4) #if KEY_ARITY > 4 && KEY5_EQ_P(n->key5, key5) +#if KEY_ARITY > 5 + && KEY6_EQ_P(n->key6, key6) +#if KEY_ARITY > 6 + && KEY7_EQ_P(n->key7, key7) +#if KEY_ARITY > 7 + && KEY8_EQ_P(n->key8, key8) +#if KEY_ARITY > 8 + && KEY9_EQ_P(n->key9, key9) +#endif +#endif +#endif +#endif #endif #endif #endif @@ -498,6 +737,18 @@ static int KEYSYM(_stp_map_del) (MAP map, ALLKEYSD(key)) && KEY4_EQ_P(n->key4, key4) #if KEY_ARITY > 4 && KEY5_EQ_P(n->key5, key5) +#if KEY_ARITY > 5 + && KEY6_EQ_P(n->key6, key6) +#if KEY_ARITY > 6 + && KEY7_EQ_P(n->key7, key7) +#if KEY_ARITY > 7 + && KEY8_EQ_P(n->key8, key8) +#if KEY_ARITY > 8 + && KEY9_EQ_P(n->key9, key9) +#endif +#endif +#endif +#endif #endif #endif #endif @@ -535,6 +786,18 @@ static int KEYSYM(_stp_map_exists) (MAP map, ALLKEYSD(key)) && KEY4_EQ_P(n->key4, key4) #if KEY_ARITY > 4 && KEY5_EQ_P(n->key5, key5) +#if KEY_ARITY > 5 + && KEY6_EQ_P(n->key6, key6) +#if KEY_ARITY > 6 + && KEY7_EQ_P(n->key7, key7) +#if KEY_ARITY > 7 + && KEY8_EQ_P(n->key8, key8) +#if KEY_ARITY > 8 + && KEY9_EQ_P(n->key9, key9) +#endif +#endif +#endif +#endif #endif #endif #endif @@ -582,6 +845,34 @@ static int KEYSYM(_stp_map_exists) (MAP map, ALLKEYSD(key)) #undef KEY5STOR #undef KEY5CPY +#undef KEY6NAME +#undef KEY6N +#undef KEY6TYPE +#undef KEY6_TYPE +#undef KEY6STOR +#undef KEY6CPY + +#undef KEY7NAME +#undef KEY7N +#undef KEY7TYPE +#undef KEY7_TYPE +#undef KEY7STOR +#undef KEY7CPY + +#undef KEY8NAME +#undef KEY8N +#undef KEY8TYPE +#undef KEY8_TYPE +#undef KEY8STOR +#undef KEY8CPY + +#undef KEY9NAME +#undef KEY9N +#undef KEY9TYPE +#undef KEY9_TYPE +#undef KEY9STOR +#undef KEY9CPY + #undef KEY_ARITY #undef ALLKEYS #undef ALLKEYSD diff --git a/runtime/pmap-gen.c b/runtime/pmap-gen.c index 86c3dc42..c95adc6b 100644 --- a/runtime/pmap-gen.c +++ b/runtime/pmap-gen.c @@ -26,6 +26,14 @@ #define JOIN5x(a,b,c,d,e,f) a##_##b##c##d##e##f #define JOIN6(a,b,c,d,e,f,g) JOIN6x(a,b,c,d,e,f,g) #define JOIN6x(a,b,c,d,e,f,g) a##_##b##c##d##e##f##g +#define JOIN7(a,b,c,d,e,f,g,h) JOIN7x(a,b,c,d,e,f,g,h) +#define JOIN7x(a,b,c,d,e,f,g,h) a##_##b##c##d##e##f##g##h +#define JOIN8(a,b,c,d,e,f,g,h,i) JOIN8x(a,b,c,d,e,f,g,h,i) +#define JOIN8x(a,b,c,d,e,f,g,h,i) a##_##b##c##d##e##f##g##h##i +#define JOIN9(a,b,c,d,e,f,g,h,i,j) JOIN9x(a,b,c,d,e,f,g,h,i,j) +#define JOIN9x(a,b,c,d,e,f,g,h,i,j) a##_##b##c##d##e##f##g##h##i##j +#define JOIN10(a,b,c,d,e,f,g,h,i,j,k) JOIN10x(a,b,c,d,e,f,g,h,i,j,k) +#define JOIN10x(a,b,c,d,e,f,g,h,i,j,k) a##_##b##c##d##e##f##g##h##i##j##k #include "map.h" @@ -162,6 +170,113 @@ #define KEY5_HASH JOIN(KEY5NAME,hash) #endif /* defined(KEY5_TYPE) */ +#if defined (KEY6_TYPE) +#undef KEY_ARITY +#define KEY_ARITY 6 +#if KEY6_TYPE == STRING +#define KEY6TYPE char* +#define KEY6NAME str +#define KEY6N s +#define KEY6STOR char key6[MAP_STRING_LENGTH] +#define KEY6CPY(m) str_copy(m->key6, key6) +#else +#define KEY6TYPE int64_t +#define KEY6NAME int64 +#define KEY6N i +#define KEY6STOR int64_t key6 +#define KEY6CPY(m) m->key6=key6 +#endif +#define KEY6_EQ_P JOIN(KEY6NAME,eq_p) +#define KEY6_HASH JOIN(KEY6NAME,hash) +#endif /* defined(KEY6_TYPE) */ + +#if defined (KEY7_TYPE) +#undef KEY_ARITY +#define KEY_ARITY 7 +#if KEY7_TYPE == STRING +#define KEY7TYPE char* +#define KEY7NAME str +#define KEY7N s +#define KEY7STOR char key7[MAP_STRING_LENGTH] +#define KEY7CPY(m) str_copy(m->key7, key7) +#else +#define KEY7TYPE int64_t +#define KEY7NAME int64 +#define KEY7N i +#define KEY7STOR int64_t key7 +#define KEY7CPY(m) m->key7=key7 +#endif +#define KEY7_EQ_P JOIN(KEY7NAME,eq_p) +#define KEY7_HASH JOIN(KEY7NAME,hash) +#endif /* defined(KEY7_TYPE) */ + +#if defined (KEY7_TYPE) +#undef KEY_ARITY +#define KEY_ARITY 7 +#if KEY7_TYPE == STRING +#define KEY7TYPE char* +#define KEY7NAME str +#define KEY7N s +#define KEY7STOR char key7[MAP_STRING_LENGTH] +#define KEY7CPY(m) str_copy(m->key7, key7) +#else +#define KEY7TYPE int64_t +#define KEY7NAME int64 +#define KEY7N i +#define KEY7STOR int64_t key7 +#define KEY7CPY(m) m->key7=key7 +#endif +#define KEY7_EQ_P JOIN(KEY7NAME,eq_p) +#define KEY7_HASH JOIN(KEY7NAME,hash) +#endif /* defined(KEY7_TYPE) */ + +#if defined (KEY8_TYPE) +#undef KEY_ARITY +#define KEY_ARITY 8 +#if KEY8_TYPE == STRING +#define KEY8TYPE char* +#define KEY8NAME str +#define KEY8N s +#define KEY8STOR char key8[MAP_STRING_LENGTH] +#define KEY8CPY(m) str_copy(m->key8, key8) +#else +#define KEY8TYPE int64_t +#define KEY8NAME int64 +#define KEY8N i +#define KEY8STOR int64_t key8 +#define KEY8CPY(m) m->key8=key8 +#endif +#define KEY8_EQ_P JOIN(KEY8NAME,eq_p) +#define KEY8_HASH JOIN(KEY8NAME,hash) +#endif /* defined(KEY8_TYPE) */ + +#if defined (KEY9_TYPE) +#undef KEY_ARITY +#define KEY_ARITY 9 +#if KEY9_TYPE == STRING +#define KEY9TYPE char* +#define KEY9NAME str +#define KEY9N s +#define KEY9STOR char key9[MAP_STRING_LENGTH] +#define KEY9CPY(m) str_copy(m->key9, key9) +#else +#define KEY9TYPE int64_t +#define KEY9NAME int64 +#define KEY9N i +#define KEY9STOR int64_t key9 +#define KEY9CPY(m) m->key9=key9 +#endif +#define KEY9_EQ_P JOIN(KEY9NAME,eq_p) +#define KEY9_HASH JOIN(KEY9NAME,hash) +#endif /* defined(KEY9_TYPE) */ + +/* Not so many, cowboy! */ +#if defined (KEY10_TYPE) +#error "excessive key arity == too many array indexes" +#endif + + + #if KEY_ARITY == 1 #define KEYSYM(x) JOIN2(x,KEY1N,VALN) #define ALLKEYS(x) x##1 @@ -187,6 +302,26 @@ #define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5 #define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5 #define KEYCPY(m) {KEY1CPY(m);KEY2CPY(m);KEY3CPY(m);KEY4CPY(m);KEY5CPY(m);} +#elif KEY_ARITY == 6 +#define KEYSYM(x) JOIN7(x,KEY1N,KEY2N,KEY3N,KEY4N,KEY5N,KEY6N,VALN) +#define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5, x##6 +#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5, KEY6TYPE x##6 +#define KEYCPY(m) {KEY1CPY(m);KEY2CPY(m);KEY3CPY(m);KEY4CPY(m);KEY5CPY(m);KEY6CPY(m);} +#elif KEY_ARITY == 7 +#define KEYSYM(x) JOIN8(x,KEY1N,KEY2N,KEY3N,KEY4N,KEY5N,KEY6N,KEY7N,VALN) +#define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5, x##6, x##7 +#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5, KEY6TYPE x##6, KEY7TYPE x##7 +#define KEYCPY(m) {KEY1CPY(m);KEY2CPY(m);KEY3CPY(m);KEY4CPY(m);KEY5CPY(m);KEY6CPY(m);KEY7CPY(m);} +#elif KEY_ARITY == 8 +#define KEYSYM(x) JOIN9(x,KEY1N,KEY2N,KEY3N,KEY4N,KEY5N,KEY6N,KEY7N,KEY8N,VALN) +#define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5, x##6, x##7, x##8 +#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5, KEY6TYPE x##6, KEY7TYPE x##7, KEY8TYPE x##8 +#define KEYCPY(m) {KEY1CPY(m);KEY2CPY(m);KEY3CPY(m);KEY4CPY(m);KEY5CPY(m);KEY6CPY(m);KEY7CPY(m);KEY8CPY(m);} +#elif KEY_ARITY == 9 +#define KEYSYM(x) JOIN10(x,KEY1N,KEY2N,KEY3N,KEY4N,KEY5N,KEY6N,KEY7N,KEY8N,KEY9N,VALN) +#define ALLKEYS(x) x##1, x##2, x##3, x##4, x##5, x##6, x##7, x##8, x##9 +#define ALLKEYSD(x) KEY1TYPE x##1, KEY2TYPE x##2, KEY3TYPE x##3, KEY4TYPE x##4, KEY5TYPE x##5, KEY6TYPE x##6, KEY7TYPE x##7, KEY8TYPE x##8, KEY9TYPE x##9 +#define KEYCPY(m) {KEY1CPY(m);KEY2CPY(m);KEY3CPY(m);KEY4CPY(m);KEY5CPY(m);KEY6CPY(m);KEY7CPY(m);KEY8CPY(m);KEY9CPY(m);} #endif /* */ @@ -208,6 +343,18 @@ struct KEYSYM(pmap_node) { KEY4STOR; #if KEY_ARITY > 4 KEY5STOR; +#if KEY_ARITY > 5 + KEY6STOR; +#if KEY_ARITY > 6 + KEY7STOR; +#if KEY_ARITY > 7 + KEY8STOR; +#if KEY_ARITY > 8 + KEY9STOR; +#endif +#endif +#endif +#endif #endif #endif #endif @@ -238,6 +385,18 @@ static int KEYSYM(pmap_key_cmp) (struct map_node *m1, struct map_node *m2) && KEY4_EQ_P(n1->key4, n2->key4) #if KEY_ARITY > 4 && KEY5_EQ_P(n1->key5, n2->key5) +#if KEY_ARITY > 5 + && KEY6_EQ_P(n1->key6, n2->key6) +#if KEY_ARITY > 6 + && KEY7_EQ_P(n1->key7, n2->key7) +#if KEY_ARITY > 7 + && KEY8_EQ_P(n1->key8, n2->key8) +#if KEY_ARITY > 8 + && KEY9_EQ_P(n1->key9, n2->key9) +#endif +#endif +#endif +#endif #endif #endif #endif @@ -282,6 +441,34 @@ static void KEYSYM(pmap_copy_keys) (struct map_node *m1, struct map_node *m2) #else dst->key5 = src->key5; #endif +#if KEY_ARITY > 5 +#if KEY6_TYPE == STRING + str_copy (dst->key6, src->key6); +#else + dst->key6 = src->key6; +#endif +#if KEY_ARITY > 6 +#if KEY7_TYPE == STRING + str_copy (dst->key7, src->key7); +#else + dst->key7 = src->key7; +#endif +#if KEY_ARITY > 7 +#if KEY8_TYPE == STRING + str_copy (dst->key8, src->key8); +#else + dst->key8 = src->key8; +#endif +#if KEY_ARITY > 8 +#if KEY9_TYPE == STRING + str_copy (dst->key9, src->key9); +#else + dst->key9 = src->key9; +#endif +#endif +#endif +#endif +#endif #endif #endif #endif @@ -330,6 +517,34 @@ static key_data KEYSYM(pmap_get_key) (struct map_node *mn, int n, int *type) if (type) *type = type_to_enum(KEY5TYPE); break; +#if KEY_ARITY > 5 + case 6: + ptr = (key_data)m->key6; + if (type) + *type = type_to_enum(KEY6TYPE); + break; +#if KEY_ARITY > 6 + case 7: + ptr = (key_data)m->key7; + if (type) + *type = type_to_enum(KEY7TYPE); + break; +#if KEY_ARITY > 7 + case 8: + ptr = (key_data)m->key8; + if (type) + *type = type_to_enum(KEY8TYPE); + break; +#if KEY_ARITY > 8 + case 9: + ptr = (key_data)m->key9; + if (type) + *type = type_to_enum(KEY9TYPE); + break; +#endif +#endif +#endif +#endif #endif #endif #endif @@ -373,6 +588,34 @@ static unsigned int KEYSYM(pkeycheck) (ALLKEYSD(key)) if (key5 == NULL) return 0; #endif + +#if KEY_ARITY > 5 +#if KEY6_TYPE == STRING + if (key6 == NULL) + return 0; +#endif + +#if KEY_ARITY > 6 +#if KEY7_TYPE == STRING + if (key7 == NULL) + return 0; +#endif + +#if KEY_ARITY > 7 +#if KEY8_TYPE == STRING + if (key8 == NULL) + return 0; +#endif + +#if KEY_ARITY > 8 +#if KEY9_TYPE == STRING + if (key9 == NULL) + return 0; +#endif +#endif +#endif +#endif +#endif #endif #endif #endif @@ -391,6 +634,18 @@ static unsigned int KEYSYM(phash) (ALLKEYSD(key)) hash ^= KEY4_HASH(key4); #if KEY_ARITY > 4 hash ^= KEY5_HASH(key5); +#if KEY_ARITY > 5 + hash ^= KEY6_HASH(key6); +#if KEY_ARITY > 6 + hash ^= KEY7_HASH(key7); +#if KEY_ARITY > 7 + hash ^= KEY8_HASH(key8); +#if KEY_ARITY > 8 + hash ^= KEY9_HASH(key9); +#endif +#endif +#endif +#endif #endif #endif #endif @@ -504,6 +759,18 @@ static int KEYSYM(__stp_pmap_set) (MAP map, ALLKEYSD(key), VSTYPE val, int add) && KEY4_EQ_P(n->key4, key4) #if KEY_ARITY > 4 && KEY5_EQ_P(n->key5, key5) +#if KEY_ARITY > 5 + && KEY6_EQ_P(n->key6, key6) +#if KEY_ARITY > 6 + && KEY7_EQ_P(n->key7, key7) +#if KEY_ARITY > 7 + && KEY8_EQ_P(n->key8, key8) +#if KEY_ARITY > 8 + && KEY9_EQ_P(n->key9, key9) +#endif +#endif +#endif +#endif #endif #endif #endif @@ -587,6 +854,18 @@ static VALTYPE KEYSYM(_stp_pmap_get_cpu) (PMAP pmap, ALLKEYSD(key)) && KEY4_EQ_P(n->key4, key4) #if KEY_ARITY > 4 && KEY5_EQ_P(n->key5, key5) +#if KEY_ARITY > 5 + && KEY6_EQ_P(n->key6, key6) +#if KEY_ARITY > 6 + && KEY7_EQ_P(n->key7, key7) +#if KEY_ARITY > 7 + && KEY8_EQ_P(n->key8, key8) +#if KEY_ARITY > 8 + && KEY9_EQ_P(n->key9, key9) +#endif +#endif +#endif +#endif #endif #endif #endif @@ -637,6 +916,18 @@ static VALTYPE KEYSYM(_stp_pmap_get) (PMAP pmap, ALLKEYSD(key)) && KEY4_EQ_P(n->key4, key4) #if KEY_ARITY > 4 && KEY5_EQ_P(n->key5, key5) +#if KEY_ARITY > 5 + && KEY6_EQ_P(n->key6, key6) +#if KEY_ARITY > 6 + && KEY7_EQ_P(n->key7, key7) +#if KEY_ARITY > 7 + && KEY8_EQ_P(n->key8, key8) +#if KEY_ARITY > 8 + && KEY9_EQ_P(n->key9, key9) +#endif +#endif +#endif +#endif #endif #endif #endif @@ -669,6 +960,18 @@ static VALTYPE KEYSYM(_stp_pmap_get) (PMAP pmap, ALLKEYSD(key)) && KEY4_EQ_P(n->key4, key4) #if KEY_ARITY > 4 && KEY5_EQ_P(n->key5, key5) +#if KEY_ARITY > 5 + && KEY6_EQ_P(n->key6, key6) +#if KEY_ARITY > 6 + && KEY7_EQ_P(n->key7, key7) +#if KEY_ARITY > 7 + && KEY8_EQ_P(n->key8, key8) +#if KEY_ARITY > 8 + && KEY9_EQ_P(n->key9, key9) +#endif +#endif +#endif +#endif #endif #endif #endif @@ -723,6 +1026,18 @@ static int KEYSYM(__stp_pmap_del) (MAP map, ALLKEYSD(key)) && KEY4_EQ_P(n->key4, key4) #if KEY_ARITY > 4 && KEY5_EQ_P(n->key5, key5) +#if KEY_ARITY > 5 + && KEY6_EQ_P(n->key6, key6) +#if KEY_ARITY > 6 + && KEY7_EQ_P(n->key7, key7) +#if KEY_ARITY > 7 + && KEY8_EQ_P(n->key8, key8) +#if KEY_ARITY > 8 + && KEY9_EQ_P(n->key9, key9) +#endif +#endif +#endif +#endif #endif #endif #endif @@ -788,6 +1103,34 @@ static int KEYSYM(_stp_pmap_del) (PMAP pmap, ALLKEYSD(key)) #undef KEY5STOR #undef KEY5CPY +#undef KEY6NAME +#undef KEY6N +#undef KEY6TYPE +#undef KEY6_TYPE +#undef KEY6STOR +#undef KEY6CPY + +#undef KEY7NAME +#undef KEY7N +#undef KEY7TYPE +#undef KEY7_TYPE +#undef KEY7STOR +#undef KEY7CPY + +#undef KEY8NAME +#undef KEY8N +#undef KEY8TYPE +#undef KEY8_TYPE +#undef KEY8STOR +#undef KEY8CPY + +#undef KEY9NAME +#undef KEY9N +#undef KEY9TYPE +#undef KEY9_TYPE +#undef KEY9STOR +#undef KEY9CPY + #undef KEY_ARITY #undef ALLKEYS #undef ALLKEYSD -- cgit From 489afa702639fd10e9756795bd516d939766247d Mon Sep 17 00:00:00 2001 From: Maynard Johnson Date: Wed, 1 Apr 2009 09:51:57 -0500 Subject: Fix runtime/itrace.c to call arch_has_*_step() prior to calling utrace_control As Roland pointed out in his Mar 31 reply to a posting of mine (subject: Re: Testing insn.block probe point uncovers possible utrace bug), utrace_control() documents that the caller must ensure that arch_has_single_step and arch_has_block_step are defined before trying to use those step modes. The attached patch addresses that issue. I've tested this patch on x86_64 arch, and a block step test runs successfully, since block step is supported on that arch. Testing on ppc64 arch, the test fails as expected (since block step is not supported on ppc64 yet) with: "ERROR: callback for failed: 1" which is sent to stdderr and "usr_itrace_init: arch does not support block step mode" which is sent to the system log. This isn't the most user-friendly way of surfacing an error. Perhaps the stap runtime could have a set of defined return codes that would be mapped to strings so the user can get an idea of what the error is without looking in the system log. But that's a side issue, of course. Regards, -Maynard --- runtime/itrace.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'runtime') diff --git a/runtime/itrace.c b/runtime/itrace.c index 97ba427e..69f3bf74 100644 --- a/runtime/itrace.c +++ b/runtime/itrace.c @@ -318,6 +318,19 @@ static int usr_itrace_init(int single_step, pid_t tid, struct stap_itrace_probe struct task_struct *tsk; spin_lock_init(&itrace_lock); + + /* 'arch_has_single_step' needs to be defined for either single step mode + * or branch mode. + */ + if (!arch_has_single_step()) { + printk(KERN_ERR "usr_itrace_init: arch does not support step mode\n"); + return 1; + } + if (!single_step && !arch_has_block_step()) { + printk(KERN_ERR "usr_itrace_init: arch does not support block step mode\n"); + return 1; + } + rcu_read_lock(); #ifdef STAPCONF_FIND_TASK_PID tsk = find_task_by_pid(tid); -- cgit From f3921e808cc95592308727d011d7718f053008e2 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 1 Apr 2009 16:39:12 -0700 Subject: Revert "Fix runtime/itrace.c to call arch_has_*_step() prior to calling utrace_control" This reverts commit 489afa702639fd10e9756795bd516d939766247d. --- runtime/itrace.c | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'runtime') diff --git a/runtime/itrace.c b/runtime/itrace.c index 69f3bf74..97ba427e 100644 --- a/runtime/itrace.c +++ b/runtime/itrace.c @@ -318,19 +318,6 @@ static int usr_itrace_init(int single_step, pid_t tid, struct stap_itrace_probe struct task_struct *tsk; spin_lock_init(&itrace_lock); - - /* 'arch_has_single_step' needs to be defined for either single step mode - * or branch mode. - */ - if (!arch_has_single_step()) { - printk(KERN_ERR "usr_itrace_init: arch does not support step mode\n"); - return 1; - } - if (!single_step && !arch_has_block_step()) { - printk(KERN_ERR "usr_itrace_init: arch does not support block step mode\n"); - return 1; - } - rcu_read_lock(); #ifdef STAPCONF_FIND_TASK_PID tsk = find_task_by_pid(tid); -- cgit From dcfd7fed7088871f46d9da7183e485877fb2d81f Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 1 Apr 2009 22:50:47 -0400 Subject: PR10019: --skip-badvars to suppress run-time memory errors too * NEWS: Note this change. * hash.cxx (find_script_hash): Add s.skip_badvars into hash. * translate.cxx (translate_pass): Emit STP_SKIP_BADVARS. * runtime/loc2c-runtime.h (DEREF_FAULT, STORE_DEREF_FAULT): Provide dummy implementation if STP_SKIP_BADVARS. --- runtime/loc2c-runtime.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/loc2c-runtime.h b/runtime/loc2c-runtime.h index 16ddb950..eaf47cad 100644 --- a/runtime/loc2c-runtime.h +++ b/runtime/loc2c-runtime.h @@ -62,6 +62,10 @@ must work right for kernel addresses, and can use whatever existing machine-specific kernel macros are convenient. */ +#if STP_SKIP_BADVARS +#define DEREF_FAULT(addr) ({0; }) +#define STORE_DEREF_FAULT(addr) ({0; }) +#else #define DEREF_FAULT(addr) ({ \ snprintf(c->error_buffer, sizeof(c->error_buffer), \ "kernel read fault at 0x%p (%s)", (void *)(intptr_t)(addr), #addr); \ @@ -75,7 +79,7 @@ c->last_error = c->error_buffer; \ goto deref_fault; \ }) - +#endif #if defined (STAPCONF_X86_UNIREGS) && defined (__i386__) -- cgit From 5ff8be611e2460ad5e0a15e1cd0936c38e518c7f Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 2 Apr 2009 13:49:12 +0200 Subject: Make task_finder.c compiler if ! defined (CONFIG_UTRACE). * runtime/task-finder.c: If ! defined (CONFIG_UTRACE) define dummy noop API for sym.c consisting of struct stap_task_finder_target, stap_add_vma_map_info, stap_remove_vma_map_info and stap_find_vma_map_info. --- runtime/task_finder.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 44dca296..3507c669 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -2,8 +2,32 @@ #define TASK_FINDER_C #if ! defined(CONFIG_UTRACE) -#error "Need CONFIG_UTRACE!" -#endif +/* Dummy definitions for use in sym.c */ +struct stap_task_finder_target { }; + +static int +stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, + unsigned long vm_end, unsigned long vm_pgoff, + void *user) +{ + return 0; +} + +static int +stap_remove_vma_map_info(struct task_struct *tsk, unsigned long vm_start, + unsigned long vm_end, unsigned long vm_pgoff) +{ + return 0; +} + +static int +stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, + unsigned long *vm_start, unsigned long *vm_end, + unsigned long *vm_pgoff, void **user) +{ + return ESRCH; +} +#else #include @@ -1358,4 +1382,6 @@ stap_stop_task_finder(void) } +#endif /* defined(CONFIG_UTRACE) */ + #endif /* TASK_FINDER_C */ -- cgit From b2b336288ce9e92a21efe7dcd314f604bc97be29 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 2 Apr 2009 18:42:38 +0200 Subject: PR6580: Implement symname, symdata and modname context functions. This adds a couple of the suggested context/stack revamp functions from PR6580. In particular it replaces the symbolname() function that sneaked in with the pr6866 branch merge with the suggested symname(). * runtime/sym.c (_stp_mod_sec_lookup): Make section optional. (_stp_symbol_snprint): Provide a way to get optional module info. * tapset/context-symbols.stp: Replace symbolname() with symname(), add modname() and symdata(). (probemod): Implement pc based fallback. * tapset/context-unwind.stp (caller): Adjust for _stp_symbol_snprint change. * testsuite/systemtap.context/usymbols.exp: Use new symname. * testsuite/buildok/modname.stp: New test. * testsuite/buildok/symdata.stp: Likewise. * testsuite/buildok/symname.stp: Likewise. --- runtime/sym.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index d0c5d9fd..ecd64fee 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -106,8 +106,8 @@ static unsigned long _stp_module_relocate(const char *module, const char *sectio } -/* Return module owner and fills in closest section of the address - if found, return NULL otherwise. +/* Return module owner and, if sec != NULL, fills in closest section + of the address if found, return NULL otherwise. XXX: needs to be address-space-specific. */ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, struct task_struct *task, @@ -151,7 +151,8 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, { closest_section_offset = this_section_offset; m = _stp_modules[midx]; - *sec = & m->sections[secidx]; + if (sec) + *sec = & m->sections[secidx]; } } } @@ -338,8 +339,15 @@ static int _stp_func_print(unsigned long address, int verbose, int exact) return 0; } +/** Puts symbolic information of an address in a string. + * @param src The string to fill in. + * @param len The length of the given src string. + * @param address The address to lookup. + * @param add_mod Whether to include module name information if found. + */ + static void _stp_symbol_snprint(char *str, size_t len, unsigned long address, - struct task_struct *task) + struct task_struct *task, int add_mod) { const char *modname; const char *name; @@ -347,9 +355,13 @@ static void _stp_symbol_snprint(char *str, size_t len, unsigned long address, name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, task); - if (name) - strlcpy(str, name, len); - else + if (name) { + if (add_mod && modname && *modname) + _stp_printf("%s %s+%#lx/%#lx\n", + name, modname, offset, size); + else + strlcpy(str, name, len); + } else _stp_snprintf(str, len, "%p", (int64_t) address); } -- cgit From 49be62cc7130e60947bbae90b6bf177e173c8b29 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 2 Apr 2009 23:19:27 +0200 Subject: runtime/syscall.h: Forward declare __ia64_fetch_register. --- runtime/syscall.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'runtime') diff --git a/runtime/syscall.h b/runtime/syscall.h index ae451070..bd480a0c 100644 --- a/runtime/syscall.h +++ b/runtime/syscall.h @@ -261,6 +261,9 @@ __stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, #endif #if defined(__ia64__) +/* Defined in regs-ia64.c. Forward declaration for ____stp_user_syscall_arg. */ +static long * __ia64_fetch_register(int, struct pt_regs *, unsigned long **); + #define __stp_user_syscall_arg(task, regs, n) \ ____stp_user_syscall_arg(task, regs, n, &c->unwaddr) -- cgit From 35ca8082a77e00173c94fe5fdcbd013b111033f2 Mon Sep 17 00:00:00 2001 From: William Cohen Date: Thu, 2 Apr 2009 17:40:58 -0400 Subject: Revert "runtime/syscall.h: Forward declare __ia64_fetch_register." This reverts commit 49be62cc7130e60947bbae90b6bf177e173c8b29. --- runtime/syscall.h | 3 --- 1 file changed, 3 deletions(-) (limited to 'runtime') diff --git a/runtime/syscall.h b/runtime/syscall.h index bd480a0c..ae451070 100644 --- a/runtime/syscall.h +++ b/runtime/syscall.h @@ -261,9 +261,6 @@ __stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, #endif #if defined(__ia64__) -/* Defined in regs-ia64.c. Forward declaration for ____stp_user_syscall_arg. */ -static long * __ia64_fetch_register(int, struct pt_regs *, unsigned long **); - #define __stp_user_syscall_arg(task, regs, n) \ ____stp_user_syscall_arg(task, regs, n, &c->unwaddr) -- cgit From 093421c6ba933754aa52cf6399aae5b8f86d86d9 Mon Sep 17 00:00:00 2001 From: William Cohen Date: Thu, 2 Apr 2009 17:41:20 -0400 Subject: Reorder includes so regs.c and regs-ia64.c included before task_finder.c. --- runtime/runtime.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'runtime') diff --git a/runtime/runtime.h b/runtime/runtime.h index 822562a2..0a656b78 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -86,6 +86,8 @@ static struct #include "io.c" #include "arith.c" #include "copy.c" +#include "regs.c" +#include "regs-ia64.c" #include "task_finder.c" -- cgit From 5aa1f218c5ff8a459c324ac64ee7a9b8046e683d Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Thu, 2 Apr 2009 18:44:34 -0400 Subject: Fix a bug in file size limitation code. This fixes a bug in stapio, which checks written data size and switches new file when it exceeds a limit. The problem is that written-data-size counter ignores the first written-data size when switching files. So, actual file size always exceeds the limit. This changes stapio to initialize written-data-size counter with the size of the data which will be written in new file. --- runtime/staprun/relay.c | 2 +- runtime/staprun/relay_old.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'runtime') diff --git a/runtime/staprun/relay.c b/runtime/staprun/relay.c index 50f295b5..694cb27e 100644 --- a/runtime/staprun/relay.c +++ b/runtime/staprun/relay.c @@ -200,7 +200,7 @@ static void *reader_thread(void *data) perr("Couldn't open file for cpu %d, exiting.", cpu); return(NULL); } - wsize = 0; + wsize = rc; } if (write(out_fd[cpu], buf, rc) != rc) { perr("Couldn't write to output %d for cpu %d, exiting.", out_fd[cpu], cpu); diff --git a/runtime/staprun/relay_old.c b/runtime/staprun/relay_old.c index ef8fd0da..469a5831 100644 --- a/runtime/staprun/relay_old.c +++ b/runtime/staprun/relay_old.c @@ -241,7 +241,7 @@ static int process_subbufs(struct _stp_buf_info *info, perr("Couldn't open file for cpu %d, exiting.", cpu); exit(1); } - scb->wsize = 0; + scb->wsize = len; } if (len) { if (fwrite_unlocked (subbuf_ptr, len, 1, percpu_tmpfile[cpu]) != 1) { @@ -320,7 +320,7 @@ int write_realtime_data(void *data, ssize_t nb) perr("Couldn't open file, exiting."); return -1; } - global_scb.wsize = 0; + global_scb.wsize = nb; } bw = write(out_fd[0], data, nb); if (bw >= 0 && bw != nb) { -- cgit From b9e80fe13706ae1c820e565e9b26f00b5f5a8dca Mon Sep 17 00:00:00 2001 From: Masami Hiramatsu Date: Thu, 2 Apr 2009 18:44:34 -0400 Subject: Fix strftime format bug This fixes bugs in strftime-subset function. This modifies %C, %l and %j to fit the output of date command. --- runtime/staprun/common.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'runtime') diff --git a/runtime/staprun/common.c b/runtime/staprun/common.c index 8200ec9d..26b166c2 100644 --- a/runtime/staprun/common.c +++ b/runtime/staprun/common.c @@ -82,7 +82,7 @@ int stap_strfloctime(char *buf, size_t max, const char *fmt, time_t t) num = tm.tm_year % 100; goto numbering02; case 'C': - num = ((tm.tm_year + 1900 - 1) / 100) + 1; + num = ((tm.tm_year + 1900) / 100); goto numbering; case 'm': num = tm.tm_mon + 1; @@ -107,7 +107,7 @@ int stap_strfloctime(char *buf, size_t max, const char *fmt, time_t t) if (num == 0) num = 12; goto numbering02; case 'j': - ret = snprintf(c, end - c, "%03d", tm.tm_yday); + ret = snprintf(c, end - c, "%03d", tm.tm_yday + 1); if (ret < 0) return ret; c += ret; break; @@ -117,7 +117,10 @@ int stap_strfloctime(char *buf, size_t max, const char *fmt, time_t t) case 'l': num = tm.tm_hour % 12; if (num == 0) num = 12; - goto numbering; + ret = snprintf(c, end - c, "%2d", num); + if (ret < 0) return ret; + c += ret; + break; case 'M': num = tm.tm_min; goto numbering02; -- cgit From b516e13ac098181536ae7281a8263e8f5b3553eb Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 2 Apr 2009 18:59:03 -0700 Subject: Really fix run-stap this time, I promise! --- runtime/staprun/staprun_funcs.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/staprun/staprun_funcs.c b/runtime/staprun/staprun_funcs.c index e94e5d13..49b37988 100644 --- a/runtime/staprun/staprun_funcs.c +++ b/runtime/staprun/staprun_funcs.c @@ -316,8 +316,21 @@ int check_permissions(void) int path_check = 0; /* If we're root, we can do anything. */ - if (getuid() == 0) + if (getuid() == 0) { + /* ... like overriding the real UID */ + const char *env_id = getenv("SYSTEMTAP_REAL_UID"); + if (env_id && setreuid(atoi(env_id), -1)) + err("WARNING: couldn't set staprun UID to '%s': %s", + env_id, strerror(errno)); + + /* ... or overriding the real GID */ + env_id = getenv("SYSTEMTAP_REAL_GID"); + if (env_id && setregid(atoi(env_id), -1)) + err("WARNING: couldn't set staprun GID to '%s': %s", + env_id, strerror(errno)); + return 1; + } /* Lookup the gid for group "stapdev" */ errno = 0; -- cgit From 85cd50d2a532d78ae1b0281c4baea3c4af396e2b Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 2 Apr 2009 22:41:18 -0700 Subject: Add a .gitignore for uprobes --- runtime/uprobes/.gitignore | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 runtime/uprobes/.gitignore (limited to 'runtime') diff --git a/runtime/uprobes/.gitignore b/runtime/uprobes/.gitignore new file mode 100644 index 00000000..c8172c41 --- /dev/null +++ b/runtime/uprobes/.gitignore @@ -0,0 +1,7 @@ +/*.o +/*.cmd +/.tmp_versions +/Module.* +/modules.order +/uprobes.ko +/uprobes.mod.c -- cgit From 1bcb8a30c3c138373c2b21a5d3820d132dacf162 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 3 Apr 2009 13:32:22 -0700 Subject: PR10032: Trigger cleanup after relay thread errors When the relay threads encounter an error, they now send SIGTERM to the rest of the process before the thread exit, so we get a clean shutdown. For EPIPE in particular, error messages are also suppressed. --- runtime/staprun/relay.c | 17 ++++++++++++----- runtime/staprun/relay_old.c | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) (limited to 'runtime') diff --git a/runtime/staprun/relay.c b/runtime/staprun/relay.c index 694cb27e..b9796241 100644 --- a/runtime/staprun/relay.c +++ b/runtime/staprun/relay.c @@ -185,7 +185,7 @@ static void *reader_thread(void *data) dbug(3, "cpu=%d poll=%d errno=%d\n", cpu, rc, errno); if (errno != EINTR) { _perr("poll error"); - return(NULL); + goto error_out; } } while ((rc = read(relay_fd[cpu], buf, sizeof(buf))) > 0) { @@ -198,17 +198,24 @@ static void *reader_thread(void *data) remove_file = 1; if (open_outfile(fnum, cpu, remove_file) < 0) { perr("Couldn't open file for cpu %d, exiting.", cpu); - return(NULL); + goto error_out; } wsize = rc; } if (write(out_fd[cpu], buf, rc) != rc) { - perr("Couldn't write to output %d for cpu %d, exiting.", out_fd[cpu], cpu); - return(NULL); + if (errno != EPIPE) + perr("Couldn't write to output %d for cpu %d, exiting.", out_fd[cpu], cpu); + goto error_out; } } } while (!stop_threads); - dbug(3, "exiting thread %d\n", cpu); + dbug(3, "exiting thread for cpu %d\n", cpu); + return(NULL); + +error_out: + /* Signal the main thread that we need to quit */ + kill(getpid(), SIGTERM); + dbug(2, "exiting thread for cpu %d after error\n", cpu); return(NULL); } diff --git a/runtime/staprun/relay_old.c b/runtime/staprun/relay_old.c index 469a5831..33d2daf3 100644 --- a/runtime/staprun/relay_old.c +++ b/runtime/staprun/relay_old.c @@ -239,14 +239,15 @@ static int process_subbufs(struct _stp_buf_info *info, scb->rmfile = 1; if (open_oldoutfile(scb->fnum, cpu, scb->rmfile) < 0) { perr("Couldn't open file for cpu %d, exiting.", cpu); - exit(1); + return -1; } scb->wsize = len; } if (len) { if (fwrite_unlocked (subbuf_ptr, len, 1, percpu_tmpfile[cpu]) != 1) { - _perr("Couldn't write to output file for cpu %d, exiting:", cpu); - exit(1); + if (errno != EPIPE) + _perr("Couldn't write to output file for cpu %d, exiting:", cpu); + return -1; } } subbufs_consumed++; @@ -281,14 +282,17 @@ static void *reader_thread(void *data) if (rc < 0) { if (errno != EINTR) { _perr("poll error"); - exit(1); + break; } err("WARNING: poll warning: %s\n", strerror(errno)); rc = 0; } rc = read(proc_fd[cpu], &status[cpu].info, sizeof(struct _stp_buf_info)); - subbufs_consumed = process_subbufs(&status[cpu].info, &scb); + rc = process_subbufs(&status[cpu].info, &scb); + if (rc < 0) + break; + subbufs_consumed = rc; if (subbufs_consumed) { if (subbufs_consumed > status[cpu].max_backlog) status[cpu].max_backlog = subbufs_consumed; @@ -301,6 +305,10 @@ static void *reader_thread(void *data) if (status[cpu].info.flushing) pthread_exit(NULL); } while (1); + + /* Signal the main thread that we need to quit */ + kill(getpid(), SIGTERM); + pthread_exit(NULL); } /** -- cgit From 782040b3f07a908790c074d94c6253c9966c18b2 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 7 Apr 2009 08:23:14 -0500 Subject: PR 9940. Rearchitected task_finder.c a bit. 2009-04-07 David Smith PR 9940. * tapsets.cxx (emit_vma_callback_probe_decl): Initialized new callbacks. (utrace_derived_probe_group::emit_probe_decl): Ditto. (uprobe_derived_probe_group::emit_module_decls): Uses new callback. Makes sure mapping is executable before trying to set a probe in it. (itrace_derived_probe_group::emit_module_init): Calls _stp_sym_init(). (utrace_derived_probe_group::emit_module_init): Ditto. (uprobe_derived_probe_group::emit_module_init): Ditto. * runtime/sym.c: Moved task_finder_vma.c inclusion here from task_finder.c. (_stp_sym_init): New function. (_stp_tf_mmap_cb): New function that replaces _stp_tf_vm_cb. (_stp_tf_munmap_cb): Ditto. * runtime/task_finder.c: Removed task_finder_vma.c inclusion. Split vm_callback into 3 callbacks: mmap_callback, munmap_callback, and mprotect_callback. (stap_register_task_finder_target): Initializes new events variables for the new callbacks. (__STP_TASK_VM_BASE_EVENTS): No longer specifies syscall entry events. (__stp_call_mmap_callbacks): New function. (__stp_call_mmap_callbacks_with_vma): Ditto. (__stp_call_munmap_callbacks): Ditto. (__stp_call_mprotect_callbacks): Ditto. (__stp_call_vm_callbacks): Removed. (__stp_utrace_task_finder_target_quiesce): Calls __stp_call_mmap_callbacks() instead of __stp_call_vm_callbacks(). (__stp_utrace_task_finder_target_syscall_entry): Removed function. (__stp_utrace_task_finder_target_syscall_exit): Reports raw mmap()/mprotect()/munmap() events. --- runtime/sym.c | 68 ++++--- runtime/task_finder.c | 491 ++++++++++++++++++++++---------------------------- 2 files changed, 261 insertions(+), 298 deletions(-) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index ecd64fee..69c3fe26 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -13,6 +13,7 @@ #define _STP_SYM_C_ #include "string.c" +#include "task_finder_vma.c" /** @file sym.c * @addtogroup sym Symbolic Functions @@ -20,38 +21,59 @@ * @{ */ +static void _stp_sym_init(void) +{ + static int initialized = 0; + if (! initialized) { + __stp_tf_vma_initialize(); + initialized = 1; + } +} + /* Callback that needs to be registered (in tapsets.cxx for emit_module_init) for every user task path or pid for which we might need symbols or unwind info. */ -static 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, - unsigned long vm_pgoff) +static int _stp_tf_mmap_cb(struct stap_task_finder_target *tgt, + struct task_struct *tsk, + char *path, + unsigned long addr, + unsigned long length, + unsigned long offset, + unsigned long vm_flags) { - int i; + int i; + struct _stp_module *module = NULL; + #ifdef DEBUG_TASK_FINDER_VMA - _stp_dbug(__FUNCTION__, __LINE__, "vm_cb: tsk %d:%d path %s, start 0x%08lx, end 0x%08lx, offset 0x%lx\n", tsk->pid, map_p, vm_path, vm_start, vm_end, vm_pgoff); + _stp_dbug(__FUNCTION__, __LINE__, + "mmap_cb: tsk %d path %s, addr 0x%08lx, length 0x%08lx, offset 0x%lx, flags 0x%lx\n", + tsk->pid, path, addr, length, offset, flags); #endif - if (map_p) - { - struct _stp_module *module = NULL; - if (vm_path != NULL) - for (i = 0; i < _stp_num_modules; i++) - if (strcmp(vm_path, _stp_modules[i]->path) == 0) - { + if (path != NULL) { + for (i = 0; i < _stp_num_modules; i++) { + if (strcmp(path, _stp_modules[i]->path) == 0) + { #ifdef DEBUG_TASK_FINDER_VMA - _stp_dbug(__FUNCTION__, __LINE__, "vm_cb: matched path %s to module\n", vm_path); + _stp_dbug(__FUNCTION__, __LINE__, + "vm_cb: matched path %s to module\n", + path); #endif - module = _stp_modules[i]; - break; - } - stap_add_vma_map_info(tsk, vm_start, vm_end, vm_pgoff, module); - } - else - stap_remove_vma_map_info(tsk, vm_start, vm_end, vm_pgoff); + module = _stp_modules[i]; + break; + } + } + } + stap_add_vma_map_info(tsk, addr, addr + length, offset, module); + return 0; +} - return 0; +static int _stp_tf_munmap_cb(struct stap_task_finder_target *tgt, + struct task_struct *tsk, + unsigned long addr, + unsigned long length) +{ + stap_remove_vma_map_info(tsk, addr, addr + length, 0); + return 0; } /* XXX: this needs to be address-space-specific. */ diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 3507c669..69b6246b 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -2,32 +2,8 @@ #define TASK_FINDER_C #if ! defined(CONFIG_UTRACE) -/* Dummy definitions for use in sym.c */ -struct stap_task_finder_target { }; - -static int -stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, - unsigned long vm_end, unsigned long vm_pgoff, - void *user) -{ - return 0; -} - -static int -stap_remove_vma_map_info(struct task_struct *tsk, unsigned long vm_start, - unsigned long vm_end, unsigned long vm_pgoff) -{ - return 0; -} - -static int -stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, - unsigned long *vm_start, unsigned long *vm_end, - unsigned long *vm_pgoff, void **user) -{ - return ESRCH; -} -#else +#error "Need CONFIG_UTRACE!" +#endif #include @@ -42,7 +18,6 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, #include "syscall.h" #include "utrace_compatibility.h" -#include "task_finder_vma.c" static LIST_HEAD(__stp_task_finder_list); @@ -86,12 +61,26 @@ typedef int (*stap_task_finder_callback)(struct stap_task_finder_target *tgt, int register_p, int process_p); -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); +typedef int +(*stap_task_finder_mmap_callback)(struct stap_task_finder_target *tgt, + struct task_struct *tsk, + char *path, + unsigned long addr, + unsigned long length, + unsigned long offset, + unsigned long vm_flags); +typedef int +(*stap_task_finder_munmap_callback)(struct stap_task_finder_target *tgt, + struct task_struct *tsk, + unsigned long addr, + unsigned long length); + +typedef int +(*stap_task_finder_mprotect_callback)(struct stap_task_finder_target *tgt, + struct task_struct *tsk, + unsigned long addr, + unsigned long length, + int prot); struct stap_task_finder_target { /* private: */ @@ -100,14 +89,18 @@ struct stap_task_finder_target { struct list_head callback_list; struct utrace_engine_ops ops; unsigned engine_attached:1; - unsigned vm_events:1; + unsigned mmap_events:1; + unsigned munmap_events:1; + unsigned mprotect_events:1; size_t pathlen; /* public: */ const char *pathname; pid_t pid; stap_task_finder_callback callback; - stap_task_finder_vm_callback vm_callback; + stap_task_finder_mmap_callback mmap_callback; + stap_task_finder_munmap_callback munmap_callback; + stap_task_finder_mprotect_callback mprotect_callback; }; #ifdef UTRACE_ORIG_VERSION @@ -133,19 +126,6 @@ __stp_utrace_task_finder_target_quiesce(enum utrace_resume_action action, 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, @@ -179,12 +159,12 @@ stap_register_task_finder_target(struct stap_task_finder_target *new_tgt) // Make sure everything is initialized properly. new_tgt->engine_attached = 0; - new_tgt->vm_events = 0; + new_tgt->mmap_events = 0; + new_tgt->munmap_events = 0; + new_tgt->mprotect_events = 0; memset(&new_tgt->ops, 0, sizeof(new_tgt->ops)); new_tgt->ops.report_death = &__stp_utrace_task_finder_target_death; new_tgt->ops.report_quiesce = &__stp_utrace_task_finder_target_quiesce; - new_tgt->ops.report_syscall_entry = \ - &__stp_utrace_task_finder_target_syscall_entry; new_tgt->ops.report_syscall_exit = \ &__stp_utrace_task_finder_target_syscall_exit; @@ -216,9 +196,13 @@ stap_register_task_finder_target(struct stap_task_finder_target *new_tgt) // Add this target to the callback list for this task. list_add_tail(&new_tgt->callback_list, &tgt->callback_list_head); - // If the new target has a vm_callback, remember this. - if (new_tgt->vm_callback != NULL) - tgt->vm_events = 1; + // If the new target has any m* callbacks, remember this. + if (new_tgt->mmap_callback != NULL) + tgt->mmap_events = 1; + if (new_tgt->munmap_callback != NULL) + tgt->munmap_events = 1; + if (new_tgt->mprotect_callback != NULL) + tgt->mprotect_events = 1; return 0; } @@ -401,15 +385,14 @@ __stp_get_mm_path(struct mm_struct *mm, char *buf, int buflen) /* * __STP_TASK_BASE_EVENTS: base events for stap_task_finder_target's - * without vm_callback's + * without map callback's * * __STP_TASK_VM_BASE_EVENTS: base events for - * stap_task_finder_target's with vm_callback's + * stap_task_finder_target's with map callback's */ #define __STP_TASK_BASE_EVENTS (UTRACE_EVENT(DEATH)) #define __STP_TASK_VM_BASE_EVENTS (__STP_TASK_BASE_EVENTS \ - | UTRACE_EVENT(SYSCALL_ENTRY)\ | UTRACE_EVENT(SYSCALL_EXIT)) /* @@ -421,8 +404,10 @@ __stp_get_mm_path(struct mm_struct *mm, char *buf, int buflen) #define __STP_ATTACHED_TASK_EVENTS (__STP_TASK_BASE_EVENTS \ | UTRACE_EVENT(QUIESCE)) -#define __STP_ATTACHED_TASK_BASE_EVENTS(tgt) \ - ((tgt)->vm_events ? __STP_TASK_VM_BASE_EVENTS : __STP_TASK_BASE_EVENTS) +#define __STP_ATTACHED_TASK_BASE_EVENTS(tgt) \ + (((tgt)->mmap_events || (tgt)->munmap_events \ + || (tgt)->mprotect_events) \ + ? __STP_TASK_VM_BASE_EVENTS : __STP_TASK_BASE_EVENTS) static int __stp_utrace_attach(struct task_struct *tsk, @@ -538,11 +523,113 @@ __stp_call_callbacks(struct stap_task_finder_target *tgt, } } +static void +__stp_call_mmap_callbacks(struct stap_task_finder_target *tgt, + struct task_struct *tsk, char *path, + unsigned long addr, unsigned long length, + unsigned long offset, unsigned long vm_flags) +{ + struct list_head *cb_node; + int rc; + + if (tgt == NULL || tsk == NULL) + return; + +#ifdef DEBUG_TASK_FINDER_VMA + _stp_dbug(__FUNCTION__, __LINE__, + "pid %d, a/l/o/p/path 0x%lx 0x%lx 0x%lx %c%c%c%c %s\n", + tsk->pid, addr, length, offset, + vm_flags & VM_READ ? 'r' : '-', + vm_flags & VM_WRITE ? 'w' : '-', + vm_flags & VM_EXEC ? 'x' : '-', + vm_flags & VM_MAYSHARE ? 's' : 'p', + path); +#endif + list_for_each(cb_node, &tgt->callback_list_head) { + struct stap_task_finder_target *cb_tgt; + + cb_tgt = list_entry(cb_node, struct stap_task_finder_target, + callback_list); + if (cb_tgt == NULL || cb_tgt->mmap_callback == NULL) + continue; + + rc = cb_tgt->mmap_callback(cb_tgt, tsk, path, addr, length, + offset, vm_flags); + if (rc != 0) { + _stp_error("mmap callback for %d failed: %d", + (int)tsk->pid, rc); + } + } +} + +static void +__stp_call_mmap_callbacks_with_vma(struct stap_task_finder_target *tgt, + struct task_struct *tsk, + struct vm_area_struct *vma) +{ + char *mmpath_buf; + char *mmpath; + int rc; + + // Allocate space for a path + mmpath_buf = _stp_kmalloc(PATH_MAX); + if (mmpath_buf == NULL) { + _stp_error("Unable to allocate space for path"); + return; + } + + // Grab the path associated with this vma. +#ifdef STAPCONF_DPATH_PATH + mmpath = d_path(&(vma->vm_file->f_path), mmpath_buf, PATH_MAX); +#else + mmpath = d_path(vma->vm_file->f_dentry, vma->vm_file->f_vfsmnt, + mmpath_buf, PATH_MAX); +#endif + if (mmpath == NULL || IS_ERR(mmpath)) { + rc = -PTR_ERR(mmpath); + _stp_error("Unable to get path (error %d) for pid %d", + rc, (int)tsk->pid); + } + else { + __stp_call_mmap_callbacks(tgt, tsk, mmpath, vma->vm_start, + vma->vm_end - vma->vm_start, + (vma->vm_pgoff << PAGE_SHIFT), + vma->vm_flags); + } + _stp_kfree(mmpath_buf); +} + +static inline void +__stp_call_munmap_callbacks(struct stap_task_finder_target *tgt, + struct task_struct *tsk, unsigned long addr, + unsigned long length) +{ + struct list_head *cb_node; + int rc; + + if (tgt == NULL || tsk == NULL) + return; + + list_for_each(cb_node, &tgt->callback_list_head) { + struct stap_task_finder_target *cb_tgt; + + cb_tgt = list_entry(cb_node, struct stap_task_finder_target, + callback_list); + if (cb_tgt == NULL || cb_tgt->munmap_callback == NULL) + continue; + + rc = cb_tgt->munmap_callback(cb_tgt, tsk, addr, length); + if (rc != 0) { + _stp_error("munmap callback for %d failed: %d", + (int)tsk->pid, rc); + } + } +} + static inline void -__stp_call_vm_callbacks(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) +__stp_call_mprotect_callbacks(struct stap_task_finder_target *tgt, + struct task_struct *tsk, unsigned long addr, + unsigned long length, int prot) { struct list_head *cb_node; int rc; @@ -555,13 +642,13 @@ __stp_call_vm_callbacks(struct stap_task_finder_target *tgt, cb_tgt = list_entry(cb_node, struct stap_task_finder_target, callback_list); - if (cb_tgt == NULL || cb_tgt->vm_callback == NULL) + if (cb_tgt == NULL || cb_tgt->mprotect_callback == NULL) continue; - rc = cb_tgt->vm_callback(cb_tgt, tsk, map_p, vm_path, - vm_start, vm_end, vm_pgoff); + rc = cb_tgt->mprotect_callback(cb_tgt, tsk, addr, length, + prot); if (rc != 0) { - _stp_error("vm callback for %d failed: %d", + _stp_error("mprotect callback for %d failed: %d", (int)tsk->pid, rc); } } @@ -888,16 +975,16 @@ __stp_utrace_task_finder_target_quiesce(enum utrace_resume_action action, __stp_call_callbacks(tgt, tsk, 1, (tsk->pid == tsk->tgid)); /* If this is just a thread other than the thread group leader, - don't bother inform vm_callback clients about its memory map, + don't bother inform map callback clients about its memory map, since they will simply duplicate each other. */ - if (tgt->vm_events == 1 && tsk->tgid == tsk->pid) { + if (tgt->mmap_events == 1 && tsk->tgid == tsk->pid) { struct mm_struct *mm; char *mmpath_buf; char *mmpath; struct vm_area_struct *vma; int rc; - /* Call the vm_callback for every vma associated with + /* Call the mmap_callback for every vma associated with * a file. */ mm = get_task_mm(tsk); if (! mm) @@ -924,12 +1011,13 @@ __stp_utrace_task_finder_target_quiesce(enum utrace_resume_action action, mmpath_buf, PATH_MAX); #endif if (mmpath) { - __stp_call_vm_callbacks(tgt, tsk, 1, - mmpath, - vma->vm_start, - vma->vm_end, - (vma->vm_pgoff - << PAGE_SHIFT)); + __stp_call_mmap_callbacks(tgt, tsk, + mmpath, + vma->vm_start, + vma->vm_end - vma->vm_start, + (vma->vm_pgoff + << PAGE_SHIFT), + vma->vm_flags); } else { _stp_dbug(__FUNCTION__, __LINE__, @@ -962,112 +1050,6 @@ __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; - struct mm_struct *mm; - struct vm_area_struct *vma; - unsigned long *arg0_addr, arg0; - int rc; -#if defined(__ia64__) - struct { unsigned long *unwaddr; } _c = {.unwaddr = NULL}, *c = &_c; -#endif - - if (atomic_read(&__stp_task_finder_state) != __STP_TF_RUNNING) { - debug_task_finder_detach(); - return UTRACE_DETACH; - } - - if (tgt == NULL || tgt->vm_events == 0) - 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_RESUME; - - __stp_tf_handler_start(); - - // We need the first syscall argument to see what address - // we're operating on. - arg0_addr = __stp_user_syscall_arg(tsk, regs, 0); - if ((rc = __stp_get_user(arg0, arg0_addr)) != 0) { - _stp_error("couldn't read syscall arg 0 for pid %d: %d", - tsk->pid, rc); - } - else if (arg0 != (unsigned long)NULL) { - mm = get_task_mm(tsk); - if (mm) { - down_read(&mm->mmap_sem); - - // If we can find a matching vma associated - // with a file, save off its details. - vma = __stp_find_file_based_vma(mm, arg0); - if (vma != NULL) { - __stp_tf_add_vma(tsk, arg0, vma); - } - - up_read(&mm->mmap_sem); - mmput(mm); - } - } - __stp_tf_handler_end(); - return UTRACE_RESUME; -} - -static void -__stp_call_vm_callbacks_with_vma(struct stap_task_finder_target *tgt, - struct task_struct *tsk, - struct vm_area_struct *vma) -{ - char *mmpath_buf; - char *mmpath; - int rc; - - // Allocate space for a path - mmpath_buf = _stp_kmalloc(PATH_MAX); - if (mmpath_buf == NULL) { - _stp_error("Unable to allocate space for path"); - return; - } - - // Grab the path associated with this vma. -#ifdef STAPCONF_DPATH_PATH - mmpath = d_path(&(vma->vm_file->f_path), mmpath_buf, PATH_MAX); -#else - mmpath = d_path(vma->vm_file->f_dentry, vma->vm_file->f_vfsmnt, - mmpath_buf, PATH_MAX); -#endif - if (mmpath == NULL || IS_ERR(mmpath)) { - rc = -PTR_ERR(mmpath); - _stp_error("Unable to get path (error %d) for pid %d", - rc, (int)tsk->pid); - } - else { - __stp_call_vm_callbacks(tgt, tsk, 1, mmpath, - vma->vm_start, vma->vm_end, - (vma->vm_pgoff << PAGE_SHIFT)); - } - _stp_kfree(mmpath_buf); -} - #ifdef UTRACE_ORIG_VERSION static u32 __stp_utrace_task_finder_target_syscall_exit(struct utrace_attached_engine *engine, @@ -1084,11 +1066,12 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, struct stap_task_finder_target *tgt = engine->data; unsigned long syscall_no; unsigned long *rv_addr, rv; - unsigned long *arg0_addr, arg0; + unsigned long *arg_addr, arg0; + unsigned long arg1 = 0; + unsigned long arg2 = 0; int rc; struct mm_struct *mm; struct vm_area_struct *vma; - struct __stp_tf_vma_entry *entry = NULL; #if defined(__ia64__) struct { unsigned long *unwaddr; } _c = {.unwaddr = NULL}, *c = &_c; #endif @@ -1098,7 +1081,7 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, return UTRACE_DETACH; } - if (tgt == NULL || tgt->vm_events == 0) + if (tgt == NULL) return UTRACE_RESUME; // See if syscall is one we're interested in. @@ -1111,6 +1094,16 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, && syscall_no != MUNMAP_SYSCALL_NO(tsk)) return UTRACE_RESUME; + // The syscall is one we're interested in, but do we have a + // handler for it? + if (((syscall_no == MMAP_SYSCALL_NO(tsk) + || syscall_no == MMAP2_SYSCALL_NO(tsk)) && tgt->mmap_events == 0) + || (syscall_no == MPROTECT_SYSCALL_NO(tsk) + && tgt->mprotect_events == 0) + || (syscall_no == MUNMAP_SYSCALL_NO(tsk) + && tgt->munmap_events == 0)) + return UTRACE_RESUME; + // Get return value rv_addr = __stp_user_syscall_return_value(tsk, regs); if ((rc = __stp_get_user(rv, rv_addr)) != 0) { @@ -1121,8 +1114,8 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, // We need the first syscall argument to see what address we // were operating on. - arg0_addr = __stp_user_syscall_arg(tsk, regs, 0); - if ((rc = __stp_get_user(arg0, arg0_addr)) != 0) { + arg_addr = __stp_user_syscall_arg(tsk, regs, 0); + if ((rc = __stp_get_user(arg0, arg_addr)) != 0) { _stp_error("couldn't read syscall arg 0 for pid %d: %d", tsk->pid, rc); return UTRACE_RESUME; @@ -1141,105 +1134,57 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, #endif __stp_tf_handler_start(); - // Try to find the vma info we might have saved. - if (arg0 != (unsigned long)NULL) - entry = __stp_tf_get_vma_entry(tsk, arg0); + if (syscall_no == MUNMAP_SYSCALL_NO(tsk)) { + // We need the 2nd syscall argument for the length. + arg_addr = __stp_user_syscall_arg(tsk, regs, 1); + if ((rc = __stp_get_user(arg1, arg_addr)) != 0) { + _stp_error("couldn't read syscall arg 1 for pid %d: %d", + tsk->pid, rc); + goto syscall_exit_done; + } + // Call the callbacks + __stp_call_munmap_callbacks(tgt, tsk, arg0, arg1); + } + else if (syscall_no == MMAP_SYSCALL_NO(tsk) + || syscall_no == MMAP2_SYSCALL_NO(tsk)) { - // If entry is NULL, this means we didn't find a file based - // vma to store in the syscall_entry routine. This could mean - // we just created a new vma. - if (entry == NULL) { mm = get_task_mm(tsk); if (mm) { down_read(&mm->mmap_sem); vma = __stp_find_file_based_vma(mm, rv); - if (vma != NULL) { - __stp_call_vm_callbacks_with_vma(tgt, tsk, vma); + + // Call the callbacks + if (vma) { + __stp_call_mmap_callbacks_with_vma(tgt, tsk, + vma); } + up_read(&mm->mmap_sem); mmput(mm); } } - // If we found saved vma information, try to match it up with - // what currently exists. else { -#ifdef DEBUG_TASK_FINDER_VMA - _stp_dbug(__FUNCTION__, __LINE__, - "** found stored vma 0x%lx/0x%lx/0x%lx!\n", - entry->vm_start, entry->vm_end, entry->vm_pgoff); -#endif - mm = get_task_mm(tsk); - if (mm) { - down_read(&mm->mmap_sem); - vma = __stp_find_file_based_vma(mm, entry->vm_start); - - // We couldn't find the vma at all. The - // original vma was deleted. - if (vma == NULL) { - // FIXME: We'll need to figure out to - // retrieve the path of a deleted - // vma. - - __stp_call_vm_callbacks(tgt, tsk, 0, NULL, - entry->vm_start, - entry->vm_end, - (entry->vm_pgoff - << PAGE_SHIFT)); - } - - // If nothing has changed, there is no - // need to call the callback. - else if (vma->vm_start == entry->vm_start - && vma->vm_end == entry->vm_end - && vma->vm_pgoff == entry->vm_pgoff) { - // do nothing - } + // We need the 2nd syscall argument for the length. + arg_addr = __stp_user_syscall_arg(tsk, regs, 1); + if ((rc = __stp_get_user(arg1, arg_addr)) != 0) { + _stp_error("couldn't read syscall arg 1 for pid %d: %d", + tsk->pid, rc); + goto syscall_exit_done; + } - // The original vma has been changed. It is - // possible that calling mprotect (e.g.) split - // up an existing vma into 2 or 3 new vma's - // (assuming it protected a portion of the - // original vma at the beginning, middle, or - // end). Try to determine what happened. - else { - unsigned long tmp; - - // First report that the original vma - // is gone. - // - // FIXME: We'll need to figure out to - // retrieve the path of a deleted - // vma. - __stp_call_vm_callbacks(tgt, tsk, 0, NULL, - entry->vm_start, - entry->vm_end, - (entry->vm_pgoff - << PAGE_SHIFT)); - - // Now find all the new vma's that - // made up the original vma's address - // space and call the callback on each - // new vma. - tmp = entry->vm_start; - while (((vma = __stp_find_file_based_vma(mm, - tmp)) - != NULL) - && vma->vm_end <= entry->vm_end) { - __stp_call_vm_callbacks_with_vma(tgt, - tsk, - vma); - if (vma->vm_end >= entry->vm_end) - break; - tmp = vma->vm_end; - } - } - up_read(&mm->mmap_sem); - mmput(mm); + // We need the 3nd syscall argument for the protection. + arg_addr = __stp_user_syscall_arg(tsk, regs, 2); + if ((rc = __stp_get_user(arg2, arg_addr)) != 0) { + _stp_error("couldn't read syscall arg 2 for pid %d: %d", + tsk->pid, rc); + goto syscall_exit_done; } - // Cleanup by deleting the saved vma info. - __stp_tf_remove_vma_entry(entry); + // Call the callbacks + __stp_call_mprotect_callbacks(tgt, tsk, arg0, arg1, arg2); } + +syscall_exit_done: __stp_tf_handler_end(); return UTRACE_RESUME; } @@ -1264,8 +1209,6 @@ stap_start_task_finder(void) return ENOMEM; } - __stp_tf_vma_initialize(); - atomic_set(&__stp_task_finder_state, __STP_TF_RUNNING); rcu_read_lock(); @@ -1382,6 +1325,4 @@ stap_stop_task_finder(void) } -#endif /* defined(CONFIG_UTRACE) */ - #endif /* TASK_FINDER_C */ -- cgit From 92f6f03ee1823624f518fd6f9942f91ea88f1fe8 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 7 Apr 2009 14:17:09 +0200 Subject: Track VMA per pid (group_leader/tgid). * runtime/sym.c (_stp_tf_vm_cb): Add and remove tsk->group_leader. (_stp_mod_sec_lookup): find vma for task->group_leader. --- runtime/sym.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index 69c3fe26..0268f1ab 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -46,8 +46,8 @@ static int _stp_tf_mmap_cb(struct stap_task_finder_target *tgt, #ifdef DEBUG_TASK_FINDER_VMA _stp_dbug(__FUNCTION__, __LINE__, - "mmap_cb: tsk %d path %s, addr 0x%08lx, length 0x%08lx, offset 0x%lx, flags 0x%lx\n", - tsk->pid, path, addr, length, offset, flags); + "mmap_cb: tsk %d:%d path %s, addr 0x%08lx, length 0x%08lx, offset 0x%lx, flags 0x%lx\n", + tsk->pid, tsk->tgid, path, addr, length, offset, flags); #endif if (path != NULL) { for (i = 0; i < _stp_num_modules; i++) { @@ -63,7 +63,8 @@ static int _stp_tf_mmap_cb(struct stap_task_finder_target *tgt, } } } - stap_add_vma_map_info(tsk, addr, addr + length, offset, module); + stap_add_vma_map_info(tsk->group_leader, addr, addr + length, offset, + module); return 0; } @@ -72,7 +73,7 @@ static int _stp_tf_munmap_cb(struct stap_task_finder_target *tgt, unsigned long addr, unsigned long length) { - stap_remove_vma_map_info(tsk, addr, addr + length, 0); + stap_remove_vma_map_info(tsk->group_leader, addr, addr + length, 0); return 0; } @@ -144,7 +145,7 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, if (task) { unsigned long vm_start = 0; - if (stap_find_vma_map_info(task, addr, + if (stap_find_vma_map_info(task->group_leader, addr, &vm_start, NULL, NULL, &user) == 0) if (user != NULL) -- cgit From 07cee54d6fb720d4300972aaff9300ac8028c88d Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 8 Apr 2009 11:11:34 +0200 Subject: Use _stp_snprintf in _stp_symbol_snprint. * runtime/sym.c (_stp_symbol_snprint): Use _stp_snprintf, no _stp_printf. --- runtime/sym.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index 0268f1ab..835e1b46 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -380,8 +380,8 @@ static void _stp_symbol_snprint(char *str, size_t len, unsigned long address, task); if (name) { if (add_mod && modname && *modname) - _stp_printf("%s %s+%#lx/%#lx\n", - name, modname, offset, size); + _stp_snprintf(str, len, "%s %s+%#lx/%#lx", + name, modname, offset, size); else strlcpy(str, name, len); } else -- cgit From 55c0f2bfefb04915622dd3688bba59da1addaec8 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 8 Apr 2009 12:41:55 -0500 Subject: Only includes task_finder.c when needed. 2009-04-08 David Smith * tapsets.cxx (itrace_derived_probe_group::emit_module_decls): Added inclusion of task_finder.c back. Unconditionally including it when not needed causes all systemtap scripts to fail on kernels with no utrace support. (utrace_derived_probe_group::emit_module_decls): Ditto. (uprobe_derived_probe_group::emit_module_decls): Ditto. * runtime/runtime.h: Removed unconditional inclusion of task_finder.c. --- runtime/runtime.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'runtime') diff --git a/runtime/runtime.h b/runtime/runtime.h index 0a656b78..70fe4dce 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -89,8 +89,6 @@ static struct #include "regs.c" #include "regs-ia64.c" -#include "task_finder.c" - #include "sym.c" #ifdef STP_PERFMON #include "perf.c" -- cgit From 117bcbe45ff448c0913007d31cfa2be78caeb4ba Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 8 Apr 2009 13:14:24 -0500 Subject: Added '#ifdef STP_NEED_VMA_TRACKER' around code that needs it. 2009-04-08 David Smith * runtime/sym.c: Added '#ifdef STP_NEED_VMA_TRACKER' around code that needs it. --- runtime/sym.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index 835e1b46..7b918428 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -30,6 +30,7 @@ static void _stp_sym_init(void) } } +#ifdef STP_NEED_VMA_TRACKER /* Callback that needs to be registered (in tapsets.cxx for emit_module_init) for every user task path or pid for which we might need symbols or unwind info. */ @@ -76,6 +77,7 @@ static int _stp_tf_munmap_cb(struct stap_task_finder_target *tgt, stap_remove_vma_map_info(tsk->group_leader, addr, addr + length, 0); return 0; } +#endif /* XXX: this needs to be address-space-specific. */ static unsigned long _stp_module_relocate(const char *module, const char *section, unsigned long offset) @@ -128,7 +130,6 @@ static unsigned long _stp_module_relocate(const char *module, const char *sectio return 0; } - /* Return module owner and, if sec != NULL, fills in closest section of the address if found, return NULL otherwise. XXX: needs to be address-space-specific. */ -- cgit From 9b11ea1ccc742f6a594be6a9777e618bdcbfebed Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 8 Apr 2009 19:27:42 +0200 Subject: Fix DEBUG_TASK_FINDER_VMA compilation. * runtime/sym.c (_stp_tf_mmap_cb): We get passed vm_flags, not flags. --- runtime/sym.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index 7b918428..8de01bc8 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -48,7 +48,7 @@ static int _stp_tf_mmap_cb(struct stap_task_finder_target *tgt, #ifdef DEBUG_TASK_FINDER_VMA _stp_dbug(__FUNCTION__, __LINE__, "mmap_cb: tsk %d:%d path %s, addr 0x%08lx, length 0x%08lx, offset 0x%lx, flags 0x%lx\n", - tsk->pid, tsk->tgid, path, addr, length, offset, flags); + tsk->pid, tsk->tgid, path, addr, length, offset, vm_flags); #endif if (path != NULL) { for (i = 0; i < _stp_num_modules; i++) { -- cgit From 8c39e6ee099a479b3f8e25bad1272085369970a9 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 8 Apr 2009 23:35:21 +0200 Subject: Make sure code using the vma tracker compiles again. * runtime/runtime.h: Include task_finder.c. * runtime/sym.c: Always define task_finder callbacks for usage in tapsets. * runtime/task_finder.c: Define dummy stap_task_finder_target when ! defined(CONFIG_UTRACE). * tapsets.cxx: Never include task_finder.c directly. --- runtime/runtime.h | 2 ++ runtime/sym.c | 2 -- runtime/task_finder.c | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) (limited to 'runtime') diff --git a/runtime/runtime.h b/runtime/runtime.h index 70fe4dce..0a656b78 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -89,6 +89,8 @@ static struct #include "regs.c" #include "regs-ia64.c" +#include "task_finder.c" + #include "sym.c" #ifdef STP_PERFMON #include "perf.c" diff --git a/runtime/sym.c b/runtime/sym.c index 8de01bc8..a2cdd0ff 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -30,7 +30,6 @@ static void _stp_sym_init(void) } } -#ifdef STP_NEED_VMA_TRACKER /* Callback that needs to be registered (in tapsets.cxx for emit_module_init) for every user task path or pid for which we might need symbols or unwind info. */ @@ -77,7 +76,6 @@ static int _stp_tf_munmap_cb(struct stap_task_finder_target *tgt, stap_remove_vma_map_info(tsk->group_leader, addr, addr + length, 0); return 0; } -#endif /* XXX: this needs to be address-space-specific. */ static unsigned long _stp_module_relocate(const char *module, const char *section, unsigned long offset) diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 69b6246b..55a896ee 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -2,8 +2,9 @@ #define TASK_FINDER_C #if ! defined(CONFIG_UTRACE) -#error "Need CONFIG_UTRACE!" -#endif +/* Dummy definitions for use in sym.c */ +struct stap_task_finder_target { }; +#else #include @@ -1324,5 +1325,5 @@ stap_stop_task_finder(void) debug_task_finder_report(); } - +#endif /* defined(CONFIG_UTRACE) */ #endif /* TASK_FINDER_C */ -- cgit From 86872ea4cdc4ce7b4546975125fc7be7c7a6e0ec Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 9 Apr 2009 14:22:03 +0200 Subject: Make new stap_task_finder_targets chain on correct list. * runtime/task_finder.c (stap_register_task_finder_target): Also check both pathlen are zero. --- runtime/task_finder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 55a896ee..433a042a 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -179,7 +179,7 @@ stap_register_task_finder_target(struct stap_task_finder_target *new_tgt) && strcmp(tgt->pathname, new_tgt->pathname) == 0) /* pid-based target (a specific pid or all * pids) */ - || (new_tgt->pathlen == 0 + || (new_tgt->pathlen == 0 && tgt->pathlen == 0 && tgt->pid == new_tgt->pid))) { found_node = 1; break; -- cgit From 52356a26e1825acbd9146337ffdbed9b0e173f2b Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 9 Apr 2009 18:20:32 +0200 Subject: Make simple probes work even without KPROBES in the kernel. Without KPROBES very little works atm. But stack.c file is unconditionally imported, while these two functions are only used through context-unwind.stp. This at least lets us do simple sanity checks on "plain" kernels. * runtime/stack.c (_stp_stack_print, _stp_stack_snprint): Wrap in #if defined (CONFIG_KPROBES). --- runtime/stack.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'runtime') diff --git a/runtime/stack.c b/runtime/stack.c index f6b1cd08..68fb9b1f 100644 --- a/runtime/stack.c +++ b/runtime/stack.c @@ -97,6 +97,12 @@ static void _stp_stack_print_fallback(unsigned long stack, int verbose, int leve &print_data); } #endif + +// Without KPROBES very little works atm. +// But this file is unconditionally imported, while these two functions are only +// used through context-unwind.stp. +#if defined (CONFIG_KPROBES) + /** Prints the stack backtrace * @param regs A pointer to the struct pt_regs. */ @@ -141,6 +147,8 @@ static void _stp_stack_snprint(char *str, int size, struct pt_regs *regs, int ve pb->len = 0; } +#endif /* CONFIG_KPROBES */ + /** Prints the user stack backtrace * @param str string * @returns Same string as was input with trace info appended, -- cgit From d5cd287f7860df8752f93de93fcd1cc68884d56b Mon Sep 17 00:00:00 2001 From: David Smith Date: Thu, 9 Apr 2009 12:06:05 -0500 Subject: Uses when available. 2009-04-09 David Smith * buildrun.cxx (compile_pass): Compile autoconf test for . * runtime/autoconf-asm-syscall.c: New "autoconf" test the presence of . * runtime/syscall.h: If exists, use it. Otherwise, use our private copy of the functions for each architecture. (syscall_get_nr): Renamed from __stp_user_syscall_nr(). (syscall_get_return_value): Renamed from __stp_user_syscall_return_value(). (syscall_get_arguments): Renamed from __stp_user_syscall_arg(). * runtime/task_finder.c (__stp_utrace_task_finder_target_syscall_exit): Uses new syscall.h functions. * tapset/utrace.stp: Ditto. --- runtime/autoconf-asm-syscall.c | 2 + runtime/syscall.h | 298 ++++++++++++++++++++++++++--------------- runtime/task_finder.c | 56 ++------ 3 files changed, 207 insertions(+), 149 deletions(-) create mode 100644 runtime/autoconf-asm-syscall.c (limited to 'runtime') diff --git a/runtime/autoconf-asm-syscall.c b/runtime/autoconf-asm-syscall.c new file mode 100644 index 00000000..bf7a273f --- /dev/null +++ b/runtime/autoconf-asm-syscall.c @@ -0,0 +1,2 @@ +#include + diff --git a/runtime/syscall.h b/runtime/syscall.h index ae451070..6d22ba83 100644 --- a/runtime/syscall.h +++ b/runtime/syscall.h @@ -1,5 +1,6 @@ -/* syscall defines and inlines - * Copyright (C) 2008 Red Hat Inc. +/* + * syscall defines and inlines + * Copyright (C) 2008-2009 Red Hat Inc. * * This file is part of systemtap, and is free software. You can * redistribute it and/or modify it under the terms of the GNU General @@ -89,9 +90,17 @@ #error "Unimplemented architecture" #endif +#ifdef STAPCONF_ASM_SYSCALL_H + +/* If the system has asm/syscall.h, use defines from it. */ +#include + +#else /* !STAPCONF_ASM_SYSCALL_H */ + +/* If the system doesn't have asm/syscall.h, use our defines. */ #if defined(__i386__) || defined(__x86_64__) -static inline unsigned long -__stp_user_syscall_nr(struct pt_regs *regs) +static inline long +syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { #if defined(STAPCONF_X86_UNIREGS) return regs->orig_ax; @@ -104,37 +113,37 @@ __stp_user_syscall_nr(struct pt_regs *regs) #endif #if defined(__powerpc__) -static inline unsigned long -__stp_user_syscall_nr(struct pt_regs *regs) +static inline long +syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { return regs->gpr[0]; } #endif #if defined(__ia64__) -static inline unsigned long -__stp_user_syscall_nr(struct pt_regs *regs) +static inline long +syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { return regs->r15; } #endif #if defined(__s390__) || defined(__s390x__) -static inline unsigned long -__stp_user_syscall_nr(struct pt_regs *regs) +static inline long +syscall_get_nr(struct task_struct *task, struct pt_regs *regs) { - // might need to be 'orig_gpr2' + // might need to be 'orig_gpr2' return regs->gprs[2]; } #endif #if defined(__i386__) || defined(__x86_64__) -static inline long * -__stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) +static inline long +syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { #ifdef CONFIG_IA32_EMULATION // This code works, but isn't what we need. Since -// __stp_user_syscall_arg() doesn't sign-extend, a value passed in as +// syscall_get_syscall_arg() doesn't sign-extend, a value passed in as // an argument and then returned won't compare correctly anymore. So, // for now, disable this code. # if 0 @@ -145,158 +154,233 @@ __stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) # endif #endif #if defined(STAPCONF_X86_UNIREGS) - return ®s->ax; + return regs->ax; #elif defined(__x86_64__) - return ®s->rax; + return regs->rax; #elif defined (__i386__) - return ®s->eax; + return regs->eax; #endif } #endif #if defined(__powerpc__) -static inline long * -__stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) +static inline long +syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { - return ®s->gpr[3]; + return regs->gpr[3]; } #endif #if defined(__ia64__) -static inline long * -__stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) +static inline long +syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { - return ®s->r8; + return regs->r8; } #endif #if defined(__s390__) || defined(__s390x__) -static inline long * -__stp_user_syscall_return_value(struct task_struct *task, struct pt_regs *regs) +static inline long +syscall_get_return_value(struct task_struct *task, struct pt_regs *regs) { - return ®s->gprs[2]; + return regs->gprs[2]; } #endif #if defined(__i386__) || defined(__x86_64__) -static inline long * -__stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, - unsigned int n) +static inline void +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned int i, unsigned int n, unsigned long *args) { -#if defined(__i386__) - if (n > 5) { - _stp_error("syscall arg > 5"); - return NULL; + if (i + n > 6) { + _stp_error("invalid syscall arg request"); + return; } +#if defined(__i386__) #if defined(STAPCONF_X86_UNIREGS) - return ®s->bx + n; + memcpy(args, ®s->bx + i, n * sizeof(args[0])); #else - return ®s->ebx + n; + memcpy(args, ®s->ebx + i, n * sizeof(args[0])); #endif #elif defined(__x86_64__) #ifdef CONFIG_IA32_EMULATION - if (test_tsk_thread_flag(task, TIF_IA32)) - switch (n) { + if (test_tsk_thread_flag(task, TIF_IA32)) { + switch (i) { #if defined(STAPCONF_X86_UNIREGS) - case 0: return ®s->bx; - case 1: return ®s->cx; - case 2: return ®s->dx; - case 3: return ®s->si; - case 4: return ®s->di; - case 5: return ®s->bp; + case 0: + if (!n--) break; + *args++ = regs->bx; + case 1: + if (!n--) break; + *args++ = regs->cx; + case 2: + if (!n--) break; + *args++ = regs->dx; + case 3: + if (!n--) break; + *args++ = regs->si; + case 4: + if (!n--) break; + *args++ = regs->di; + case 5: + if (!n--) break; + *args++ = regs->bp; #else - case 0: return ®s->rbx; - case 1: return ®s->rcx; - case 2: return ®s->rdx; - case 3: return ®s->rsi; - case 4: return ®s->rdi; - case 5: return ®s->rbp; + case 0: + if (!n--) break; + *args++ = regs->rbx; + case 1: + if (!n--) break; + *args++ = regs->rcx; + case 2: + if (!n--) break; + *args++ = regs->rdx; + case 3: + if (!n--) break; + *args++ = regs->rsi; + case 4: + if (!n--) break; + *args++ = regs->rdi; + case 5: + if (!n--) break; + *args++ = regs->rbp; #endif - default: - _stp_error("syscall arg > 5"); - return NULL; } + return; + } #endif /* CONFIG_IA32_EMULATION */ - switch (n) { + switch (i) { #if defined(STAPCONF_X86_UNIREGS) - case 0: return ®s->di; - case 1: return ®s->si; - case 2: return ®s->dx; - case 3: return ®s->r10; - case 4: return ®s->r8; - case 5: return ®s->r9; + case 0: + if (!n--) break; + *args++ = regs->di; + case 1: + if (!n--) break; + *args++ = regs->si; + case 2: + if (!n--) break; + *args++ = regs->dx; + case 3: + if (!n--) break; + *args++ = regs->r10; + case 4: + if (!n--) break; + *args++ = regs->r8; + case 5: + if (!n--) break; + *args++ = regs->r9; #else - case 0: return ®s->rdi; - case 1: return ®s->rsi; - case 2: return ®s->rdx; - case 3: return ®s->r10; - case 4: return ®s->r8; - case 5: return ®s->r9; + case 0: + if (!n--) break; + *args++ = regs->rdi; + case 1: + if (!n--) break; + *args++ = regs->rsi; + case 2: + if (!n--) break; + *args++ = regs->rdx; + case 3: + if (!n--) break; + *args++ = regs->r10; + case 4: + if (!n--) break; + *args++ = regs->r8; + case 5: + if (!n--) break; + *args++ = regs->r9; #endif - default: - _stp_error("syscall arg > 5"); - return NULL; } #endif /* CONFIG_X86_32 */ + return; } #endif #if defined(__powerpc__) -static inline long * -__stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, - unsigned int n) +static inline void +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned int i, unsigned int n, unsigned long *args) { - switch (n) { - case 0: return ®s->gpr[3]; - case 1: return ®s->gpr[4]; - case 2: return ®s->gpr[5]; - case 3: return ®s->gpr[6]; - case 4: return ®s->gpr[7]; - case 5: return ®s->gpr[8]; - default: - _stp_error("syscall arg > 5"); - return NULL; + if (i + n > 6) { + _stp_error("invalid syscall arg request"); + return; } + memcpy(args, ®s->gpr[3 + i], n * sizeof(args[0])); } #endif #if defined(__ia64__) -#define __stp_user_syscall_arg(task, regs, n) \ - ____stp_user_syscall_arg(task, regs, n, &c->unwaddr) +#define syscall_get_arguments(task, regs, i, n, args) \ + __ia64_syscall_get_arguments(task, regs, i, n, args, &c->unwaddr) -static inline long * -____stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, - unsigned int n, unsigned long **cache) +static inline void +__ia64_syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned int i, unsigned int n, + unsigned long *args, unsigned long **cache) { - if (n > 5) { - _stp_error("syscall arg > 5"); - return NULL; + if (i + n > 6) { + _stp_error("invalid syscall arg request"); + return; + } + switch (i) { + case 0: + if (!n--) break; + *args++ = *__ia64_fetch_register(i + 32, regs, cache); + case 1: + if (!n--) break; + *args++ = *__ia64_fetch_register(i + 33, regs, cache); + case 2: + if (!n--) break; + *args++ = *__ia64_fetch_register(i + 34, regs, cache); + case 3: + if (!n--) break; + *args++ = *__ia64_fetch_register(i + 35, regs, cache); + case 4: + if (!n--) break; + *args++ = *__ia64_fetch_register(i + 36, regs, cache); + case 5: + if (!n--) break; + *args++ = *__ia64_fetch_register(i + 37, regs, cache); } - return __ia64_fetch_register(n + 32, regs, cache); } #endif #if defined(__s390__) || defined(__s390x__) -static inline long * -__stp_user_syscall_arg(struct task_struct *task, struct pt_regs *regs, - unsigned int n) +static inline void +syscall_get_arguments(struct task_struct *task, struct pt_regs *regs, + unsigned int i, unsigned int n, unsigned long *args) { - /* If we were returning a value, we could check for TIF_31BIT - * here and cast the value with '(u32)' to make sure it got - * down to 32bits. But, since we're returning an address, - * there isn't much we can do. */ - switch (n) { - case 0: return ®s->orig_gpr2; - case 1: return ®s->gprs[3]; - case 2: return ®s->gprs[4]; - case 3: return ®s->gprs[5]; - case 4: return ®s->gprs[6]; - case 5: return ®s->args[0]; - default: - _stp_error("syscall arg > 5"); - return NULL; + unsigned long mask = -1UL; + + if (i + n > 6) { + _stp_error("invalid syscall arg request"); + return; + } +#ifdef CONFIG_COMPAT + if (test_tsk_thread_flag(task, TIF_31BIT)) + mask = 0xffffffff; +#endif + switch (i) { + case 0: + if (!n--) break; + *args++ = regs->orig_gpr2 & mask; + case 1: + if (!n--) break; + *args++ = regs->gprs[3] & mask; + case 2: + if (!n--) break; + *args++ = regs->gprs[4] & mask; + case 3: + if (!n--) break; + *args++ = regs->gprs[5] & mask; + case 4: + if (!n--) break; + *args++ = regs->gprs[6] & mask; + case 5: + if (!n--) break; + *args++ = regs->args[0] & mask; } } #endif +#endif /* !STAPCONF_ASM_SYSCALL_H */ #endif /* _SYSCALL_H_ */ diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 433a042a..fa6c296e 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -1065,11 +1065,9 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, #endif { struct stap_task_finder_target *tgt = engine->data; - unsigned long syscall_no; - unsigned long *rv_addr, rv; - unsigned long *arg_addr, arg0; - unsigned long arg1 = 0; - unsigned long arg2 = 0; + long syscall_no; + unsigned long rv; + unsigned long args[3]; int rc; struct mm_struct *mm; struct vm_area_struct *vma; @@ -1088,7 +1086,7 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, // See if syscall is one we're interested in. // // FIXME: do we need to handle mremap()? - syscall_no = __stp_user_syscall_nr(regs); + syscall_no = syscall_get_nr(tsk, regs); if (syscall_no != MMAP_SYSCALL_NO(tsk) && syscall_no != MMAP2_SYSCALL_NO(tsk) && syscall_no != MPROTECT_SYSCALL_NO(tsk) @@ -1106,21 +1104,11 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, 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_RESUME; - } + rv = syscall_get_return_value(tsk, regs); // We need the first syscall argument to see what address we // were operating on. - arg_addr = __stp_user_syscall_arg(tsk, regs, 0); - if ((rc = __stp_get_user(arg0, arg_addr)) != 0) { - _stp_error("couldn't read syscall arg 0 for pid %d: %d", - tsk->pid, rc); - return UTRACE_RESUME; - } + syscall_get_arguments(tsk, regs, 0, 1, args); #ifdef DEBUG_TASK_FINDER_VMA _stp_dbug(__FUNCTION__, __LINE__, @@ -1131,20 +1119,15 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, : ((syscall_no == MPROTECT_SYSCALL_NO(tsk)) ? "mprotect" : ((syscall_no == MUNMAP_SYSCALL_NO(tsk)) ? "munmap" : "UNKNOWN")))), - arg0, rv); + args[0], rv); #endif __stp_tf_handler_start(); if (syscall_no == MUNMAP_SYSCALL_NO(tsk)) { // We need the 2nd syscall argument for the length. - arg_addr = __stp_user_syscall_arg(tsk, regs, 1); - if ((rc = __stp_get_user(arg1, arg_addr)) != 0) { - _stp_error("couldn't read syscall arg 1 for pid %d: %d", - tsk->pid, rc); - goto syscall_exit_done; - } + syscall_get_arguments(tsk, regs, 1, 1, &args[1]); // Call the callbacks - __stp_call_munmap_callbacks(tgt, tsk, arg0, arg1); + __stp_call_munmap_callbacks(tgt, tsk, args[0], args[1]); } else if (syscall_no == MMAP_SYSCALL_NO(tsk) || syscall_no == MMAP2_SYSCALL_NO(tsk)) { @@ -1165,24 +1148,13 @@ __stp_utrace_task_finder_target_syscall_exit(enum utrace_resume_action action, } } else { - // We need the 2nd syscall argument for the length. - arg_addr = __stp_user_syscall_arg(tsk, regs, 1); - if ((rc = __stp_get_user(arg1, arg_addr)) != 0) { - _stp_error("couldn't read syscall arg 1 for pid %d: %d", - tsk->pid, rc); - goto syscall_exit_done; - } - - // We need the 3nd syscall argument for the protection. - arg_addr = __stp_user_syscall_arg(tsk, regs, 2); - if ((rc = __stp_get_user(arg2, arg_addr)) != 0) { - _stp_error("couldn't read syscall arg 2 for pid %d: %d", - tsk->pid, rc); - goto syscall_exit_done; - } + // We need the 2nd syscall argument for the length and + // the 3rd argument for the protection. + syscall_get_arguments(tsk, regs, 1, 2, &args[1]); // Call the callbacks - __stp_call_mprotect_callbacks(tgt, tsk, arg0, arg1, arg2); + __stp_call_mprotect_callbacks(tgt, tsk, args[0], args[1], + args[2]); } syscall_exit_done: -- cgit From 6d6dbe278ad5fab5d33273b38c1ad137380a3e1e Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 10 Apr 2009 22:55:26 +0200 Subject: Fix unwind _stp_mod_sec_lookup. * runtime/unwind.c (unwind): Pass current to _stp_mod_sec_lookup(). --- runtime/unwind.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/unwind.c b/runtime/unwind.c index 9c704e28..f7b19def 100644 --- a/runtime/unwind.c +++ b/runtime/unwind.c @@ -581,7 +581,7 @@ static int unwind(struct unwind_frame_info *frame) if (UNW_PC(frame) == 0) return -EINVAL; - m = _stp_mod_sec_lookup (pc, &s); + m = _stp_mod_sec_lookup (pc, current, &s); if (unlikely(m == NULL)) { dbug_unwind(1, "No module found for pc=%lx", pc); return -EINVAL; -- cgit From a6f6008cf0034b8580f67851f742dd0ada0d683c Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 11 Apr 2009 13:08:06 +0200 Subject: Prefer dwarf unwinder on i386 and x86_64. * runtime/runtime.h: Move up and enable check for STP_USE_DWARF_UNWINDER. --- runtime/runtime.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'runtime') diff --git a/runtime/runtime.h b/runtime/runtime.h index 0a656b78..f333756e 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -66,6 +66,11 @@ static struct #define MAXTRACE 20 #endif +/* dwarf unwinder only tested so far on i386 and x86_64. */ +#if (defined(__i386__) || defined(__x86_64__)) +#define STP_USE_DWARF_UNWINDER +#endif + #ifdef CONFIG_FRAME_POINTER /* Just because frame pointers are available does not mean we can trust them. */ #ifndef STP_USE_DWARF_UNWINDER @@ -73,13 +78,6 @@ static struct #endif #endif -/* dwarf unwinder only tested so far on i386 and x86_64, - but globally disabled for now */ -#if 0 -// !defined(STP_USE_FRAME_BUFFER) && (defined(__i386__) || defined(__x86_64__)) -#define STP_USE_DWARF_UNWINDER -#endif - #include "alloc.c" #include "print.c" #include "string.c" -- cgit From f38b2e7385b3395dc589af5bde137971adf84f27 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sun, 12 Apr 2009 23:46:48 +0200 Subject: Don't redefine STP_USE_DWARF_UNWINDER. * runtime/runtime.h: STP_USE_DWARF_UNWINDER don't redefine. --- runtime/runtime.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'runtime') diff --git a/runtime/runtime.h b/runtime/runtime.h index f333756e..c2e927cc 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -68,8 +68,10 @@ static struct /* dwarf unwinder only tested so far on i386 and x86_64. */ #if (defined(__i386__) || defined(__x86_64__)) +#ifndef STP_USE_DWARF_UNWINDER #define STP_USE_DWARF_UNWINDER #endif +#endif #ifdef CONFIG_FRAME_POINTER /* Just because frame pointers are available does not mean we can trust them. */ -- cgit From b9c2e81cc7a62336ec1daf374cb3411add772ab4 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Mon, 13 Apr 2009 19:50:23 -0700 Subject: PR10067: fix bitfield access * tapsets.cxx (dwflpp::translate_components): Eliminate the extra die-dereference at the end of the loop (a regression from @casts). * runtime/loc2c-runtime.h (store_bitfield): Use the target as the representative type, since the base is always int64_t. Also be a bit more aggressive with masking and parentheses. * testsuite/systemtap.base/bitfield.*: New test for R/W bitfields. --- runtime/loc2c-runtime.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'runtime') diff --git a/runtime/loc2c-runtime.h b/runtime/loc2c-runtime.h index eaf47cad..620e1615 100644 --- a/runtime/loc2c-runtime.h +++ b/runtime/loc2c-runtime.h @@ -29,11 +29,12 @@ & (((__typeof (base)) 1 << (nbits)) - 1)) #define store_bitfield(target, base, higherbits, nbits) \ - target = (target \ - &~ ((((__typeof (base)) 1 << (nbits)) - 1) \ - << (sizeof (base) * 8 - (higherbits) - (nbits))) \ - | ((__typeof (base)) (base) \ - << (sizeof (base) * 8 - (higherbits) - (nbits)))) + target = ((target \ + &~ ((((__typeof (target)) 1 << (nbits)) - 1) \ + << (sizeof (target) * 8 - (higherbits) - (nbits)))) \ + | ((((__typeof (target)) (base)) \ + & (((__typeof (target)) 1 << (nbits)) - 1)) \ + << (sizeof (target) * 8 - (higherbits) - (nbits)))) /* Given a DWARF register number, fetch its intptr_t (long) value from the -- cgit From 60ad8ebae62f472a9f089f51053a2d0d66c67a95 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 14 Apr 2009 19:30:56 +0200 Subject: Keep track of relocation section sizes. * runtime/sym.h (_stp_section): Add size field. * translate.cxx (dump_unwindsyms): Get start of module address space, turn seclist into vector of secname, size pairs, track relocation section size, or add module address range if no sections, output size in _stp_section list. --- runtime/sym.h | 1 + 1 file changed, 1 insertion(+) (limited to 'runtime') diff --git a/runtime/sym.h b/runtime/sym.h index 586b10ca..80c334fb 100644 --- a/runtime/sym.h +++ b/runtime/sym.h @@ -18,6 +18,7 @@ struct _stp_symbol { struct _stp_section { const char *name; unsigned long addr; /* XXX: belongs in per-address-space tables */ + unsigned long size; /* length of the address space module covers. */ struct _stp_symbol *symbols; /* ordered by address */ unsigned num_symbols; }; -- cgit From 4787e8398f4d0376f31cffc0771b71f5bbdd9d52 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 14 Apr 2009 19:54:38 +0200 Subject: Only set sec in _stp_mod_sec_lookup when not NULL. * runtime/sym.c (_stp_mod_sec_lookup): Only set sec when not NULL. --- runtime/sym.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index a2cdd0ff..fc9b2e80 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -150,7 +150,8 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, if (user != NULL) { m = (struct _stp_module *)user; - *sec = &m->sections[0]; // XXX check actual section and relocate + if (sec) + *sec = &m->sections[0]; // XXX check actual section and relocate dbug_sym(1, "found section %s in module %s at 0x%lx\n", m->sections[0].name, m->name, vm_start); if (strcmp(".dynamic", m->sections[0].name) == 0) -- cgit From c1af604e1c626b90834113ba7d71c4a2ea1bda68 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 14 Apr 2009 20:58:26 +0200 Subject: Make sure addr falls inside section in _stp_mod_sec_lookup. * runtime/sym.c (_stp_mod_sec_lookup): Use section size to match addr. Only return exact matches, not just closes offset. --- runtime/sym.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'runtime') diff --git a/runtime/sym.c b/runtime/sym.c index fc9b2e80..f6f97ac2 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -136,9 +136,7 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, struct _stp_section **sec) { void *user = NULL; - struct _stp_module *m = NULL; unsigned midx = 0; - unsigned long closest_section_offset = ~0; // Try vma matching first if task given. if (task) @@ -149,7 +147,7 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, NULL, &user) == 0) if (user != NULL) { - m = (struct _stp_module *)user; + struct _stp_module *m = (struct _stp_module *)user; if (sec) *sec = &m->sections[0]; // XXX check actual section and relocate dbug_sym(1, "found section %s in module %s at 0x%lx\n", @@ -165,21 +163,19 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, unsigned secidx; for (secidx = 0; secidx < _stp_modules[midx]->num_sections; secidx++) { - unsigned long this_section_addr; - unsigned long this_section_offset; - this_section_addr = _stp_modules[midx]->sections[secidx].addr; - if (addr < this_section_addr) continue; - this_section_offset = addr - this_section_addr; - if (this_section_offset < closest_section_offset) - { - closest_section_offset = this_section_offset; - m = _stp_modules[midx]; + unsigned long sec_addr; + unsigned long sec_size; + sec_addr = _stp_modules[midx]->sections[secidx].addr; + sec_size = _stp_modules[midx]->sections[secidx].size; + if (addr >= sec_addr && addr < sec_addr + sec_size) + { if (sec) - *sec = & m->sections[secidx]; + *sec = & _stp_modules[midx]->sections[secidx]; + return _stp_modules[midx]; } } } - return m; + return NULL; } -- cgit