1 /* MN10300 Userspace accessor functions
3 * Copyright (C) 2007 Matsushita Electric Industrial Co., Ltd.
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
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 <asm/uaccess.h>
15 __generic_copy_to_user(void *to
, const void *from
, unsigned long n
)
17 if (access_ok(VERIFY_WRITE
, to
, n
))
18 __copy_user(to
, from
, n
);
23 __generic_copy_from_user(void *to
, const void *from
, unsigned long n
)
25 if (access_ok(VERIFY_READ
, from
, n
))
26 __copy_user_zeroing(to
, from
, n
);
31 * Copy a null terminated string from userspace.
33 #define __do_strncpy_from_user(dst, src, count, res) \
53 " .section .fixup,\"ax\"\n" \
58 " .section __ex_table,\"a\"\n" \
63 :"=&r"(res), "=r"(count), "=&r"(w) \
64 :"i"(-EFAULT), "1"(count), "a"(src), "a"(dst) \
69 __strncpy_from_user(char *dst
, const char *src
, long count
)
72 __do_strncpy_from_user(dst
, src
, count
, res
);
77 strncpy_from_user(char *dst
, const char *src
, long count
)
80 if (access_ok(VERIFY_READ
, src
, 1))
81 __do_strncpy_from_user(dst
, src
, count
, res
);
87 * Clear a userspace memory
89 #define __do_clear_user(addr, size) \
96 "0: movbu %1,(%3,%2)\n" \
103 ".section .fixup,\"ax\"\n" \
106 ".section __ex_table,\"a\"\n" \
110 : "+r"(size), "=&r"(w) \
111 : "a"(addr), "d"(0) \
116 __clear_user(void *to
, unsigned long n
)
118 __do_clear_user(to
, n
);
123 clear_user(void *to
, unsigned long n
)
125 if (access_ok(VERIFY_WRITE
, to
, n
))
126 __do_clear_user(to
, n
);
131 * Return the size of a string (including the ending 0)
133 * Return 0 on exception, a value greater than N if too long
135 long strnlen_user(const char *s
, long n
)
137 unsigned long res
, w
;
142 if (n
< 0 || n
+ (u_long
) s
> current_thread_info()->addr_limit
.seg
)
143 n
= current_thread_info()->addr_limit
.seg
- (u_long
)s
;
148 "1: movbu (%0,%3),%1\n"
155 ".section .fixup,\"ax\"\n"
158 ".section __ex_table,\"a\"\n"
163 :"0"(0), "a"(s
), "r"(n
)