1 #ifndef __M68KNOMMU_UACCESS_H
2 #define __M68KNOMMU_UACCESS_H
5 * User space memory access functions
8 #include <linux/string.h>
10 #include <asm/segment.h>
12 #define access_ok(type,addr,size) _access_ok((unsigned long)(addr),(size))
15 * It is not enough to just have access_ok check for a real RAM address.
16 * This would disallow the case of code/ro-data running XIP in flash/rom.
17 * Ideally we would check the possible flash ranges too, but that is
18 * currently not so easy.
20 static inline int _access_ok(unsigned long addr, unsigned long size)
26 * These are the main single-value transfer routines. They automatically
27 * use the right size if we just have the right pointer type.
30 #define put_user(x, ptr) \
33 typeof(*(ptr)) __pu_val = (x); \
34 switch (sizeof (*(ptr))) { \
36 __put_user_asm(__pu_err, __pu_val, ptr, b); \
39 __put_user_asm(__pu_err, __pu_val, ptr, w); \
42 __put_user_asm(__pu_err, __pu_val, ptr, l); \
45 memcpy(ptr, &__pu_val, sizeof (*(ptr))); \
48 __pu_err = __put_user_bad(); \
53 #define __put_user(x, ptr) put_user(x, ptr)
55 extern int __put_user_bad(void);
58 * Tell gcc we read from memory instead of writing: this is because
59 * we do not write to any memory gcc knows about, so there are no
63 #define __ptr(x) ((unsigned long *)(x))
65 #define __put_user_asm(err,x,ptr,bwl) \
66 __asm__ ("move" #bwl " %0,%1" \
68 :"d" (x),"m" (*__ptr(ptr)) : "memory")
70 #define get_user(x, ptr) \
73 typeof(x) __gu_val = 0; \
74 switch (sizeof(*(ptr))) { \
76 __get_user_asm(__gu_err, __gu_val, ptr, b, "=d"); \
79 __get_user_asm(__gu_err, __gu_val, ptr, w, "=r"); \
82 __get_user_asm(__gu_err, __gu_val, ptr, l, "=r"); \
85 memcpy((void *) &__gu_val, ptr, sizeof (*(ptr))); \
89 __gu_err = __get_user_bad(); \
92 (x) = (typeof(*(ptr))) __gu_val; \
95 #define __get_user(x, ptr) get_user(x, ptr)
97 extern int __get_user_bad(void);
99 #define __get_user_asm(err,x,ptr,bwl,reg) \
100 __asm__ ("move" #bwl " %1,%0" \
104 static inline unsigned long
105 raw_copy_from_user(void *to, const void __user *from, unsigned long n)
107 memcpy(to, (__force const void *)from, n);
111 static inline unsigned long
112 raw_copy_to_user(void __user *to, const void *from, unsigned long n)
114 memcpy((__force void *)to, from, n);
117 #define INLINE_COPY_FROM_USER
118 #define INLINE_COPY_TO_USER
121 * Copy a null terminated string from userspace.
125 strncpy_from_user(char *dst, const char *src, long count)
128 strncpy(dst, src, count);
129 for (tmp = dst; *tmp && count > 0; tmp++, count--)
131 return(tmp - dst); /* DAVIDM should we count a NUL ? check getname */
135 * Return the size of a string (including the ending 0)
137 * Return 0 on exception, a value greater than N if too long
139 static inline long strnlen_user(const char *src, long n)
141 return(strlen(src) + 1); /* DAVIDM make safer */
144 #define strlen_user(str) strnlen_user(str, 32767)
150 static inline unsigned long
151 __clear_user(void *to, unsigned long n)
157 #define clear_user(to,n) __clear_user(to,n)
159 #endif /* _M68KNOMMU_UACCESS_H */