1 /* MN10300 Userspace accessor functions
3 * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/uaccess.h>
15 * Copy a null terminated string from userspace.
17 #define __do_strncpy_from_user(dst, src, count, res) \
37 " .section .fixup,\"ax\"\n" \
42 " .section __ex_table,\"a\"\n" \
47 :"=&r"(res), "=r"(count), "=&r"(w) \
48 :"i"(-EFAULT), "1"(count), "a"(src), "a"(dst) \
53 strncpy_from_user(char *dst, const char *src, long count)
56 if (access_ok(VERIFY_READ, src, 1))
57 __do_strncpy_from_user(dst, src, count, res);
63 * Clear a userspace memory
65 #define __do_clear_user(addr, size) \
72 "0: movbu %1,(%3,%2)\n" \
79 ".section .fixup,\"ax\"\n" \
82 ".section __ex_table,\"a\"\n" \
86 : "+r"(size), "=&r"(w) \
92 __clear_user(void *to, unsigned long n)
94 __do_clear_user(to, n);
99 clear_user(void *to, unsigned long n)
101 if (access_ok(VERIFY_WRITE, to, n))
102 __do_clear_user(to, n);
107 * Return the size of a string (including the ending 0)
109 * Return 0 on exception, a value greater than N if too long
111 long strnlen_user(const char *s, long n)
113 unsigned long res, w;
118 if (n < 0 || n + (u_long) s > current_thread_info()->addr_limit.seg)
119 n = current_thread_info()->addr_limit.seg - (u_long)s;
124 "1: movbu (%0,%3),%1\n"
131 ".section .fixup,\"ax\"\n"
134 ".section __ex_table,\"a\"\n"
139 :"0"(0), "a"(s), "r"(n)