From 50b8e899e87a7a182dd84a485f21c2d785b1a12d Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Wed, 27 Sep 2006 01:51:14 -0700 Subject: [PATCH] --- yaml --- r: 36215 b: refs/heads/master c: 1b79e5513d52e8533a08af35a3595dad80c74d1f h: refs/heads/master i: 36213: 6dc8faf53b35dcf5c280f57f13de7db7a03e515a 36211: 82344836fb2efc4fa7f6a79144a79d4bbaa4b41d 36207: 4bd090869a69c86ba320a9b4dc767a211c06cfcd v: v3 --- [refs] | 2 +- trunk/include/linux/uaccess.h | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/[refs] b/[refs] index 0a5fa5012cad..dd329b0537ec 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: aafe6c2a2b6bce5a3a4913ce5c07e85ea143144d +refs/heads/master: 1b79e5513d52e8533a08af35a3595dad80c74d1f diff --git a/trunk/include/linux/uaccess.h b/trunk/include/linux/uaccess.h index 391e7ed1eb3f..a48d7f11c7be 100644 --- a/trunk/include/linux/uaccess.h +++ b/trunk/include/linux/uaccess.h @@ -19,4 +19,26 @@ static inline unsigned long __copy_from_user_nocache(void *to, #endif /* ARCH_HAS_NOCACHE_UACCESS */ +/** + * probe_kernel_address(): safely attempt to read from a location + * @addr: address to read from - its type is type typeof(retval)* + * @retval: read into this variable + * + * Safely read from address @addr into variable @revtal. If a kernel fault + * happens, handle that and return -EFAULT. + * We ensure that the __get_user() is executed in atomic context so that + * do_page_fault() doesn't attempt to take mmap_sem. This makes + * probe_kernel_address() suitable for use within regions where the caller + * already holds mmap_sem, or other locks which nest inside mmap_sem. + */ +#define probe_kernel_address(addr, retval) \ + ({ \ + long ret; \ + \ + inc_preempt_count(); \ + ret = __get_user(retval, addr); \ + dec_preempt_count(); \ + ret; \ + }) + #endif /* __LINUX_UACCESS_H__ */