Commit 9ee8b24c authored by David S. Miller's avatar David S. Miller

[SPARC]: Cleanup uaccess headers and add __user attributes.

parent b1d7a6ca
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#define _ASM_UACCESS_H #define _ASM_UACCESS_H
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/compiler.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/errno.h> #include <linux/errno.h>
...@@ -45,7 +46,7 @@ ...@@ -45,7 +46,7 @@
#define __access_ok(addr,size) (__user_ok((addr) & get_fs().seg,(size))) #define __access_ok(addr,size) (__user_ok((addr) & get_fs().seg,(size)))
#define access_ok(type,addr,size) __access_ok((unsigned long)(addr),(size)) #define access_ok(type,addr,size) __access_ok((unsigned long)(addr),(size))
extern inline int verify_area(int type, const void * addr, unsigned long size) static inline int verify_area(int type, const void __user * addr, unsigned long size)
{ {
return access_ok(type,addr,size)?0:-EFAULT; return access_ok(type,addr,size)?0:-EFAULT;
} }
...@@ -291,87 +292,87 @@ __asm__ __volatile__( \ ...@@ -291,87 +292,87 @@ __asm__ __volatile__( \
extern int __get_user_bad(void); extern int __get_user_bad(void);
extern __kernel_size_t __copy_user(void *to, void *from, __kernel_size_t size); extern unsigned long __copy_user(void *to, void *from, unsigned long size);
#define copy_to_user(to,from,n) ({ \ static inline unsigned long copy_to_user(void __user *to, void *from, unsigned long n)
void *__copy_to = (void *) (to); \
__kernel_size_t __copy_size = (__kernel_size_t) (n); \
__kernel_size_t __copy_res; \
if(__copy_size && __access_ok((unsigned long)__copy_to, __copy_size)) { \
__copy_res = __copy_user(__copy_to, (void *) (from), __copy_size); \
} else __copy_res = __copy_size; \
__copy_res; })
#define __copy_to_user(to,from,n) \
__copy_user((void *)(to), \
(void *)(from), n)
#define copy_from_user(to,from,n) ({ \
void *__copy_to = (void *) (to); \
void *__copy_from = (void *) (from); \
__kernel_size_t __copy_size = (__kernel_size_t) (n); \
__kernel_size_t __copy_res; \
if(__copy_size && __access_ok((unsigned long)__copy_from, __copy_size)) { \
__copy_res = __copy_user(__copy_to, __copy_from, __copy_size); \
} else __copy_res = __copy_size; \
__copy_res; })
#define __copy_from_user(to,from,n) \
__copy_user((void *)(to), \
(void *)(from), n)
extern __inline__ __kernel_size_t __clear_user(void *addr, __kernel_size_t size)
{ {
__kernel_size_t ret; if (n && __access_ok((unsigned long) to, n))
__asm__ __volatile__ ( return __copy_user((void *) to, from, n);
".section __ex_table,#alloc\n\t" else
".align 4\n\t" return n;
".word 1f,3\n\t"
".previous\n\t"
"mov %2, %%o1\n"
"1:\n\t"
"call __bzero\n\t"
" mov %1, %%o0\n\t"
"mov %%o0, %0\n"
: "=r" (ret) : "r" (addr), "r" (size) :
"o0", "o1", "o2", "o3", "o4", "o5", "o7",
"g1", "g2", "g3", "g4", "g5", "g7", "cc");
return ret;
} }
#define clear_user(addr,n) ({ \ static inline unsigned long __copy_to_user(void __user *to, void *from, unsigned long n)
void *__clear_addr = (void *) (addr); \ {
__kernel_size_t __clear_size = (__kernel_size_t) (n); \ return __copy_user((void *)to, from, n);
__kernel_size_t __clear_res; \ }
if(__clear_size && __access_ok((unsigned long)__clear_addr, __clear_size)) { \
__clear_res = __clear_user(__clear_addr, __clear_size); \ static inline unsigned long copy_from_user(void *to, void __user *from, unsigned long n)
} else __clear_res = __clear_size; \ {
__clear_res; }) if (n && __access_ok((unsigned long) from, n))
return __copy_user(to, (void *) from, n);
extern int __strncpy_from_user(unsigned long dest, unsigned long src, int count); else
return n;
#define strncpy_from_user(dest,src,count) ({ \ }
unsigned long __sfu_src = (unsigned long) (src); \
int __sfu_count = (int) (count); \ static inline unsigned long __copy_from_user(void *to, void __user *from, unsigned long n)
long __sfu_res = -EFAULT; \ {
if(__access_ok(__sfu_src, __sfu_count)) { \ return __copy_user(to, (void *)from, n);
__sfu_res = __strncpy_from_user((unsigned long) (dest), __sfu_src, __sfu_count); \ }
} __sfu_res; })
static inline unsigned long __clear_user(void __user *addr, unsigned long size)
extern int __strlen_user(const char *); {
extern int __strnlen_user(const char *, long len); unsigned long ret;
extern __inline__ int strlen_user(const char *str) __asm__ __volatile__ (
".section __ex_table,#alloc\n\t"
".align 4\n\t"
".word 1f,3\n\t"
".previous\n\t"
"mov %2, %%o1\n"
"1:\n\t"
"call __bzero\n\t"
" mov %1, %%o0\n\t"
"mov %%o0, %0\n"
: "=r" (ret) : "r" (addr), "r" (size) :
"o0", "o1", "o2", "o3", "o4", "o5", "o7",
"g1", "g2", "g3", "g4", "g5", "g7", "cc");
return ret;
}
static inline unsigned long clear_user(void __user *addr, unsigned long n)
{
if (n && __access_ok((unsigned long) addr, n)) {
return __clear_user(addr, n);
else
return n;
}
extern long __strncpy_from_user(char *dest, const char __user *src, long count);
static inline long strncpy_from_user(char *dest, const char __user *src, long count)
{
if (__access_ok((unsigned long) src, count))
return __strncpy_from_user(dest, src, count);
else
return -EFAULT;
}
extern long __strlen_user(const char __user *);
extern long __strnlen_user(const char __user *, long len);
static inline long strlen_user(const char __user *str)
{ {
if(!access_ok(VERIFY_READ, str, 0)) if (!access_ok(VERIFY_READ, str, 0))
return 0; return 0;
else else
return __strlen_user(str); return __strlen_user(str);
} }
extern __inline__ int strnlen_user(const char *str, long len) static inline long strnlen_user(const char __user *str, long len)
{ {
if(!access_ok(VERIFY_READ, str, 0)) if (!access_ok(VERIFY_READ, str, 0))
return 0; return 0;
else else
return __strnlen_user(str, len); return __strnlen_user(str, len);
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/compiler.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/string.h> #include <linux/string.h>
#include <asm/a.out.h> #include <asm/a.out.h>
...@@ -52,7 +53,7 @@ do { \ ...@@ -52,7 +53,7 @@ do { \
#define __access_ok(addr,size) 1 #define __access_ok(addr,size) 1
#define access_ok(type,addr,size) 1 #define access_ok(type,addr,size) 1
static inline int verify_area(int type, const void * addr, unsigned long size) static inline int verify_area(int type, const void __user * addr, unsigned long size)
{ {
return 0; return 0;
} }
...@@ -249,44 +250,34 @@ __asm__ __volatile__( \ ...@@ -249,44 +250,34 @@ __asm__ __volatile__( \
extern int __get_user_bad(void); extern int __get_user_bad(void);
extern __kernel_size_t __copy_from_user(void *to, const void *from, extern unsigned long __copy_from_user(void *to, const void __user *from,
__kernel_size_t size); unsigned long size);
extern __kernel_size_t __copy_to_user(void *to, const void *from, extern unsigned long __copy_to_user(void __user *to, const void *from,
__kernel_size_t size); unsigned long size);
extern __kernel_size_t __copy_in_user(void *to, const void *from, extern unsigned long __copy_in_user(void __user *to, const void __user *from,
__kernel_size_t size); unsigned long size);
#define copy_from_user(to,from,n) \ #define copy_from_user __copy_from_user
__copy_from_user((void *)(to), \ #define copy_to_user __copy_to_user
(void *)(from), (__kernel_size_t)(n)) #define copy_in_user __copy_in_user
#define copy_to_user(to,from,n) \ static inline unsigned long __clear_user(void __user *addr, unsigned long size)
__copy_to_user((void *)(to), \
(void *) (from), (__kernel_size_t)(n))
#define copy_in_user(to,from,n) \
__copy_in_user((void *)(to), \
(void *) (from), (__kernel_size_t)(n))
static __inline__ __kernel_size_t __clear_user(void *addr, __kernel_size_t size)
{ {
extern __kernel_size_t __bzero_noasi(void *addr, __kernel_size_t size); extern unsigned long __bzero_noasi(void *addr, unsigned long size);
return __bzero_noasi(addr, size); return __bzero_noasi((void *) addr, size);
} }
#define clear_user(addr,n) \ #define clear_user __clear_user
__clear_user((void *)(addr), (__kernel_size_t)(n))
extern int __strncpy_from_user(unsigned long dest, unsigned long src, int count); extern long __strncpy_from_user(char *dest, const char __user *src, long count);
#define strncpy_from_user(dest,src,count) \ #define strncpy_from_user __strncpy_from_user
__strncpy_from_user((unsigned long)(dest), (unsigned long)(src), (int)(count))
extern int __strlen_user(const char *); extern long __strlen_user(const char __user *);
extern int __strnlen_user(const char *, long len); extern long __strnlen_user(const char __user *, long len);
#define strlen_user __strlen_user #define strlen_user __strlen_user
#define strnlen_user __strnlen_user #define strnlen_user __strnlen_user
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment