* Re: PATCH: document useraccess lib functions too
2003-03-21 20:28 PATCH: document useraccess lib functions too Alan Cox
@ 2003-03-21 19:42 ` Jeff Garzik
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Garzik @ 2003-03-21 19:42 UTC (permalink / raw)
To: Alan Cox; +Cc: linux-kernel, torvalds
On Fri, Mar 21, 2003 at 08:28:09PM +0000, Alan Cox wrote:
> diff -u --new-file --recursive --exclude-from /usr/src/exclude linux-2.5.65/arch/i386/lib/usercopy.c linux-2.5.65-ac2/arch/i386/lib/usercopy.c
> --- linux-2.5.65/arch/i386/lib/usercopy.c 2003-02-10 18:37:55.000000000 +0000
> +++ linux-2.5.65-ac2/arch/i386/lib/usercopy.c 2003-03-06 23:12:31.000000000 +0000
akpm pushed this one...
^ permalink raw reply [flat|nested] 2+ messages in thread
* PATCH: document useraccess lib functions too
@ 2003-03-21 20:28 Alan Cox
2003-03-21 19:42 ` Jeff Garzik
0 siblings, 1 reply; 2+ messages in thread
From: Alan Cox @ 2003-03-21 20:28 UTC (permalink / raw)
To: linux-kernel, torvalds
diff -u --new-file --recursive --exclude-from /usr/src/exclude linux-2.5.65/arch/i386/lib/usercopy.c linux-2.5.65-ac2/arch/i386/lib/usercopy.c
--- linux-2.5.65/arch/i386/lib/usercopy.c 2003-02-10 18:37:55.000000000 +0000
+++ linux-2.5.65-ac2/arch/i386/lib/usercopy.c 2003-03-06 23:12:31.000000000 +0000
@@ -50,6 +50,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)
{
@@ -58,6 +78,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)
{
@@ -93,6 +131,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)
{
@@ -101,6 +149,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)
{
@@ -108,12 +167,17 @@
return n;
}
-/*
- * Return the size of a string (including the ending 0)
+/**
+ * strlen_user: - Get the size of a string in user space.
+ * @s: 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);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-03-21 20:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-21 20:28 PATCH: document useraccess lib functions too Alan Cox
2003-03-21 19:42 ` Jeff Garzik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®