Linux Audio

Check our new training course

Loading...
v4.10.11
 1/*
 2 * User address space access functions.
 3 *
 4 *  For licencing details see kernel-base/COPYING
 5 */
 6
 7#include <linux/highmem.h>
 8#include <linux/export.h>
 9
10#include <asm/word-at-a-time.h>
11#include <linux/sched.h>
12
13/*
14 * We rely on the nested NMI work to allow atomic faults from the NMI path; the
15 * nested NMI paths are careful to preserve CR2.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16 */
17unsigned long
18copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
19{
20	unsigned long ret;
21
22	if (__range_not_ok(from, n, TASK_SIZE))
23		return n;
24
 
 
 
25	/*
26	 * Even though this function is typically called from NMI/IRQ context
27	 * disable pagefaults so that its behaviour is consistent even when
28	 * called form other contexts.
29	 */
30	pagefault_disable();
31	ret = __copy_from_user_inatomic(to, from, n);
32	pagefault_enable();
33
34	return ret;
35}
36EXPORT_SYMBOL_GPL(copy_from_user_nmi);
37
38/**
39 * copy_to_user: - Copy a block of data into user space.
40 * @to:   Destination address, in user space.
41 * @from: Source address, in kernel space.
42 * @n:    Number of bytes to copy.
43 *
44 * Context: User context only. This function may sleep if pagefaults are
45 *          enabled.
46 *
47 * Copy data from kernel space to user space.
48 *
49 * Returns number of bytes that could not be copied.
50 * On success, this will be zero.
51 */
52unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
53{
54	if (access_ok(VERIFY_WRITE, to, n))
55		n = __copy_to_user(to, from, n);
56	return n;
57}
58EXPORT_SYMBOL(_copy_to_user);
59
60/**
61 * copy_from_user: - Copy a block of data from user space.
62 * @to:   Destination address, in kernel space.
63 * @from: Source address, in user space.
64 * @n:    Number of bytes to copy.
65 *
66 * Context: User context only. This function may sleep if pagefaults are
67 *          enabled.
68 *
69 * Copy data from user space to kernel space.
70 *
71 * Returns number of bytes that could not be copied.
72 * On success, this will be zero.
73 *
74 * If some data could not be copied, this function will pad the copied
75 * data to the requested size using zero bytes.
76 */
77unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
78{
79	if (access_ok(VERIFY_READ, from, n))
80		n = __copy_from_user(to, from, n);
81	else
82		memset(to, 0, n);
83	return n;
84}
85EXPORT_SYMBOL(_copy_from_user);
v5.14.15
 1/*
 2 * User address space access functions.
 3 *
 4 *  For licencing details see kernel-base/COPYING
 5 */
 6
 7#include <linux/uaccess.h>
 8#include <linux/export.h>
 9
10#include <asm/tlbflush.h>
 
11
12/**
13 * copy_from_user_nmi - NMI safe copy from user
14 * @to:		Pointer to the destination buffer
15 * @from:	Pointer to a user space address of the current task
16 * @n:		Number of bytes to copy
17 *
18 * Returns: The number of not copied bytes. 0 is success, i.e. all bytes copied
19 *
20 * Contrary to other copy_from_user() variants this function can be called
21 * from NMI context. Despite the name it is not restricted to be called
22 * from NMI context. It is safe to be called from any other context as
23 * well. It disables pagefaults across the copy which means a fault will
24 * abort the copy.
25 *
26 * For NMI context invocations this relies on the nested NMI work to allow
27 * atomic faults from the NMI path; the nested NMI paths are careful to
28 * preserve CR2.
29 */
30unsigned long
31copy_from_user_nmi(void *to, const void __user *from, unsigned long n)
32{
33	unsigned long ret;
34
35	if (__range_not_ok(from, n, TASK_SIZE))
36		return n;
37
38	if (!nmi_uaccess_okay())
39		return n;
40
41	/*
42	 * Even though this function is typically called from NMI/IRQ context
43	 * disable pagefaults so that its behaviour is consistent even when
44	 * called from other contexts.
45	 */
46	pagefault_disable();
47	ret = __copy_from_user_inatomic(to, from, n);
48	pagefault_enable();
49
50	return ret;
51}
52EXPORT_SYMBOL_GPL(copy_from_user_nmi);