提交 1b79e551 编写于 作者: A Andrew Morton 提交者: Linus Torvalds

[PATCH] add probe_kernel_address()

Add a version of __get_user() which is safe to call inside mmap_sem.
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 aafe6c2a
......@@ -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__ */
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册