diff options
author | Frank Ch. Eigler <fche@elastic.org> | 2008-08-11 17:34:47 -0400 |
---|---|---|
committer | Frank Ch. Eigler <fche@elastic.org> | 2008-08-11 17:34:47 -0400 |
commit | 42e740602dbb7960e11b0bbf9053e95e8a1cb1e5 (patch) | |
tree | aa32f56c7c5b1838e9d80bec2c15325c71742660 /runtime/task_finder_vma.c | |
parent | 3213d0891c826f16ba727a3e863075e2922666a0 (diff) | |
parent | 79640c29c5bcf8de20f013dcc80e1a9c7a93811f (diff) | |
download | systemtap-steved-42e740602dbb7960e11b0bbf9053e95e8a1cb1e5.tar.gz systemtap-steved-42e740602dbb7960e11b0bbf9053e95e8a1cb1e5.tar.xz systemtap-steved-42e740602dbb7960e11b0bbf9053e95e8a1cb1e5.zip |
Merge commit 'origin/master' into pr4225
* commit 'origin/master': (34 commits)
PR5049: fix overbroad effects of naive "*" prefixing; instead use optional "*/" only.
stap-serverd was incorectly determining that the server could
stapprobes man page: clarify statement(NUM).absolute and process("path") searching
PR5049: prefix with "*" any filenames given in "fn@filename:line" probes
Indentation fix.
Redirect stderr gets redircted so warnings don't let example script run fail.
PR6835. io/io_submit.stp: Fix #! start. Convert to normal line-ending.
PR2895. Add proper #! /usr/bin/env stap line. Make example scripts executable.
Use INSTALL_PROGRAM, not INSTALL_DATA for executable .stp scripts.
example index: only warn if old, do not regenerate
Start/stop the systemtap server from systemtap.exp and not in the top level Makefile.
Lower statement wildcard test matching threshold.
Moved details of utrace detach to stap_utrace_detach().
Saves thread vma information.
Always generate examples indexes and install examples from srcdir.
Refer to srcdir spec file Makefile so make rpm works when builddir != srcdir.
Add index of subsystem and keywords at top of HTML indexes.
Don't output output, exits, status line in indexes (mentioned in descriptions).
Disable chmodding of samples/kmalloc-top in spec file since it isn't installed.
Make sure examples indexes are always generated in builddir.
...
Diffstat (limited to 'runtime/task_finder_vma.c')
-rw-r--r-- | runtime/task_finder_vma.c | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/runtime/task_finder_vma.c b/runtime/task_finder_vma.c index c0a018ab..9d43e36c 100644 --- a/runtime/task_finder_vma.c +++ b/runtime/task_finder_vma.c @@ -34,6 +34,8 @@ static struct hlist_head __stp_tf_vma_free_list[1]; 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. static void @@ -171,3 +173,133 @@ __stp_tf_remove_vma_entry(struct __stp_tf_vma_entry *entry) } return 0; } + + + +// __stp_tf_vma_map_hash(): Compute the vma map hash. +static inline u32 +__stp_tf_vma_map_hash(struct task_struct *tsk) +{ + return (jhash_1word(tsk->pid, 0) & (__STP_TF_TABLE_SIZE - 1)); +} + +// 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 +// before calling this function. +static struct __stp_tf_vma_entry * +__stp_tf_get_vma_map_entry_internal(struct task_struct *tsk, + unsigned long vm_start) +{ + struct hlist_head *head; + struct hlist_node *node; + struct __stp_tf_vma_entry *entry; + + head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; + hlist_for_each_entry(entry, node, head, hlist) { + if (tsk->pid == entry->pid + && vm_start == entry->addr) { + mutex_unlock(&__stp_tf_vma_mutex); + return entry; + } + } + return NULL; +} + + +// 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) +{ + struct hlist_head *head; + struct hlist_node *node; + struct __stp_tf_vma_entry *entry; + + mutex_lock(&__stp_tf_vma_mutex); + entry = __stp_tf_get_vma_map_entry_internal(tsk, vm_start); + if (entry != NULL) { +#if 0 + printk(KERN_NOTICE + "vma (pid: %d, vm_start: 0x%lx) present?\n", + tsk->pid, entry->vm_start); +#endif + mutex_unlock(&__stp_tf_vma_mutex); + 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); + return -ENOMEM; + } + + // Fill in the info + entry->pid = tsk->pid; + //entry->addr = addr; ??? + entry->vm_start = vm_start; + entry->vm_end = vm_end; + entry->vm_pgoff = vm_pgoff; + + head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; + hlist_add_head(&entry->hlist, head); + mutex_unlock(&__stp_tf_vma_mutex); + return 0; +} + + +// Remove the vma entry from the vma hash table. +static int +stap_remove_vma_map_info(struct task_struct *tsk, unsigned long vm_start, + unsigned long vm_end, unsigned long vm_pgoff) +{ + struct hlist_head *head; + struct hlist_node *node; + struct __stp_tf_vma_entry *entry; + + mutex_lock(&__stp_tf_vma_mutex); + 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); + 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 +// locked before calling this function. +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) +{ + struct hlist_head *head; + struct hlist_node *node; + struct __stp_tf_vma_entry *entry; + struct __stp_tf_vma_entry *found_entry = NULL; + int rc = ESRCH; + + 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 + && vm_addr >= entry->vm_start + && vm_addr < entry->vm_end) { + found_entry = entry; + break; + } + } + if (found_entry != NULL) { + if (vm_start != NULL) + *vm_start = found_entry->vm_start; + if (vm_end != NULL) + *vm_end = found_entry->vm_end; + if (vm_pgoff != NULL) + *vm_pgoff = found_entry->vm_pgoff; + rc = 0; + } + mutex_unlock(&__stp_tf_vma_mutex); + return rc; +} |