Back to home page

LXR

 
 

    


0001 
0002 #include <linux/user-return-notifier.h>
0003 #include <linux/percpu.h>
0004 #include <linux/sched.h>
0005 #include <linux/export.h>
0006 
0007 static DEFINE_PER_CPU(struct hlist_head, return_notifier_list);
0008 
0009 /*
0010  * Request a notification when the current cpu returns to userspace.  Must be
0011  * called in atomic context.  The notifier will also be called in atomic
0012  * context.
0013  */
0014 void user_return_notifier_register(struct user_return_notifier *urn)
0015 {
0016     set_tsk_thread_flag(current, TIF_USER_RETURN_NOTIFY);
0017     hlist_add_head(&urn->link, this_cpu_ptr(&return_notifier_list));
0018 }
0019 EXPORT_SYMBOL_GPL(user_return_notifier_register);
0020 
0021 /*
0022  * Removes a registered user return notifier.  Must be called from atomic
0023  * context, and from the same cpu registration occurred in.
0024  */
0025 void user_return_notifier_unregister(struct user_return_notifier *urn)
0026 {
0027     hlist_del(&urn->link);
0028     if (hlist_empty(this_cpu_ptr(&return_notifier_list)))
0029         clear_tsk_thread_flag(current, TIF_USER_RETURN_NOTIFY);
0030 }
0031 EXPORT_SYMBOL_GPL(user_return_notifier_unregister);
0032 
0033 /* Calls registered user return notifiers */
0034 void fire_user_return_notifiers(void)
0035 {
0036     struct user_return_notifier *urn;
0037     struct hlist_node *tmp2;
0038     struct hlist_head *head;
0039 
0040     head = &get_cpu_var(return_notifier_list);
0041     hlist_for_each_entry_safe(urn, tmp2, head, link)
0042         urn->on_user_return(urn);
0043     put_cpu_var(return_notifier_list);
0044 }