Re: [PATCH v4 3.0-rc2-tip 7/22] 7: uprobes: mmap and fork hooks.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2011-06-16 at 20:23 +0200, Peter Zijlstra wrote:
> int __register_uprobe(...)
> {
>   uprobe = alloc_uprobe(...); // find or insert in tree
> 
>   vma_prio_tree_foreach(..) {
>     // get mm ref, add to list blah blah
>   }
> 
>   list_for_each_entry_safe() {
>     // del from list etc..
>     down_read(mm->mmap_sem);
>     ret = install_breakpoint();
>     if (ret && (ret != -ESRCH || ret != -EEXIST)) {
>       up_read(..);
>       goto fail;
>   }
> 
>   return 0;
> 
> fail:
>   list_for_each_entry_safe() {
>     // del from list, put mm
>   }
> 
>   return ret;
> }
> 
> void __unregister_uprobe(...)
> {
>   uprobe = find_uprobe(); // ref++
>   if (delete_consumer(...)); // includes tree removal on last consumer
>                              // implies we own the last ref
>      return; // consumers
> 
>   vma_prio_tree_foreach() {
>      // create list
>   }
> 
>   list_for_each_entry_safe() {
>     // remove from list
>     remove_breakpoint(); // unconditional, if it wasn't there
>                          // its a nop anyway, can't get any new
>                          // new probes on account of holding
>                          // uprobes_mutex and mmap() doesn't see
>                          // it due to tree removal.
>   }

   put_uprobe(); // last ref, *poof*
> }
> 
> int register_uprobe(...)
> {
>   int ret;
> 
>   mutex_lock(&uprobes_mutex);
>   ret = __register_uprobe(...);
>   if (!ret)
>     __unregister_uprobe(...);
>   mutex_unlock(&uprobes_mutex);
> 
>   ret;
> }
> 
> int mmap_uprobe(...)
> {
>   spin_lock(&uprobes_treelock);
>   for_each_probe_in_inode() {
>     // create list;
>   }
>   spin_unlock(..);
> 
>   list_for_each_entry_safe() {
>     // remove from list
>     ret = install_breakpoint();
>     if (ret)
>       goto fail;
>     if (!uprobe_still_there()) // takes treelock
>       remove_breakpoint();
>   }
> 
>   return 0;
> 
> fail:
>   list_for_each_entry_safe() {
>     // destroy list
>   }
>   return ret;
> } 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@xxxxxxxxxx  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]