1 /* uaccess.c: userspace access functions
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
13 #include <linux/module.h>
14 #include <asm/uaccess.h>
16 /*****************************************************************************/
18 * copy a null terminated string from userspace
20 long strncpy_from_user(char *dst, const char __user *src, long count)
32 if ((unsigned long) src < memory_start)
36 if ((unsigned long) src >= get_addr_limit())
39 max = get_addr_limit() - (unsigned long) src;
40 if ((unsigned long) count > max) {
41 memset(dst + max, 0, count - max);
46 for (; count > 0; count--, p++, src++) {
47 __get_user_asm(err, ch, src, "ub", "=r");
55 err = p - dst; /* return length excluding NUL */
59 memset(p, 0, count); /* clear remainder of buffer [security] */
63 } /* end strncpy_from_user() */
65 EXPORT_SYMBOL(strncpy_from_user);
67 /*****************************************************************************/
69 * Return the size of a string (including the ending 0)
71 * Return 0 on exception, a value greater than N if too long
73 long strnlen_user(const char __user *src, long count)
83 if ((unsigned long) src < memory_start)
87 if ((unsigned long) src >= get_addr_limit())
90 for (p = src; count > 0; count--, p++) {
91 __get_user_asm(err, ch, p, "ub", "=r");
98 return p - src + 1; /* return length including NUL */
100 } /* end strnlen_user() */
102 EXPORT_SYMBOL(strnlen_user);