patch-2.4.21 linux-2.4.21/arch/i386/lib/usercopy.c
Next file: linux-2.4.21/arch/i386/mm/init.c
Previous file: linux-2.4.21/arch/i386/lib/delay.c
Back to the patch index
Back to the overall index
- Lines: 109
- Date:
2003-06-13 07:51:29.000000000 -0700
- Orig file:
linux-2.4.20/arch/i386/lib/usercopy.c
- Orig date:
2001-11-09 13:58:02.000000000 -0800
diff -urN linux-2.4.20/arch/i386/lib/usercopy.c linux-2.4.21/arch/i386/lib/usercopy.c
@@ -95,6 +95,26 @@
: "memory"); \
} while (0)
+/**
+ * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
+ * @dst: Destination address, in kernel space. This buffer must be at
+ * least @count bytes long.
+ * @src: Source address, in user space.
+ * @count: Maximum number of bytes to copy, including the trailing NUL.
+ *
+ * Copies a NUL-terminated string from userspace to kernel space.
+ * Caller must check the specified block with access_ok() before calling
+ * this function.
+ *
+ * On success, returns the length of the string (not including the trailing
+ * NUL).
+ *
+ * If access to userspace fails, returns -EFAULT (some data may have been
+ * copied).
+ *
+ * If @count is smaller than the length of the string, copies @count bytes
+ * and returns @count.
+ */
long
__strncpy_from_user(char *dst, const char *src, long count)
{
@@ -103,6 +123,24 @@
return res;
}
+/**
+ * strncpy_from_user: - Copy a NUL terminated string from userspace.
+ * @dst: Destination address, in kernel space. This buffer must be at
+ * least @count bytes long.
+ * @src: Source address, in user space.
+ * @count: Maximum number of bytes to copy, including the trailing NUL.
+ *
+ * Copies a NUL-terminated string from userspace to kernel space.
+ *
+ * On success, returns the length of the string (not including the trailing
+ * NUL).
+ *
+ * If access to userspace fails, returns -EFAULT (some data may have been
+ * copied).
+ *
+ * If @count is smaller than the length of the string, copies @count bytes
+ * and returns @count.
+ */
long
strncpy_from_user(char *dst, const char *src, long count)
{
@@ -138,6 +176,16 @@
: "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0)); \
} while (0)
+/**
+ * clear_user: - Zero a block of memory in user space.
+ * @to: Destination address, in user space.
+ * @n: Number of bytes to zero.
+ *
+ * Zero a block of memory in user space.
+ *
+ * Returns number of bytes that could not be cleared.
+ * On success, this will be zero.
+ */
unsigned long
clear_user(void *to, unsigned long n)
{
@@ -146,6 +194,17 @@
return n;
}
+/**
+ * __clear_user: - Zero a block of memory in user space, with less checking.
+ * @to: Destination address, in user space.
+ * @n: Number of bytes to zero.
+ *
+ * Zero a block of memory in user space. Caller must check
+ * the specified block with access_ok() before calling this function.
+ *
+ * Returns number of bytes that could not be cleared.
+ * On success, this will be zero.
+ */
unsigned long
__clear_user(void *to, unsigned long n)
{
@@ -153,12 +212,17 @@
return n;
}
-/*
- * Return the size of a string (including the ending 0)
+/**
+ * strlen_user: - Get the size of a string in user space.
+ * @str: The string to measure.
+ * @n: The maximum valid length
*
- * Return 0 on exception, a value greater than N if too long
+ * Get the size of a NUL-terminated string in user space.
+ *
+ * Returns the size of the string INCLUDING the terminating NUL.
+ * On exception, returns 0.
+ * If the string is too long, returns a value greater than @n.
*/
-
long strnlen_user(const char *s, long n)
{
unsigned long mask = -__addr_ok(s);
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)