linux/arch/m68k/include/asm/uaccess_no.h
<<
>>
Prefs
   1#ifndef __M68KNOMMU_UACCESS_H
   2#define __M68KNOMMU_UACCESS_H
   3
   4/*
   5 * User space memory access functions
   6 */
   7#include <linux/mm.h>
   8#include <linux/string.h>
   9
  10#include <asm/segment.h>
  11
  12#define access_ok(type,addr,size)       _access_ok((unsigned long)(addr),(size))
  13
  14/*
  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.
  19 */
  20static inline int _access_ok(unsigned long addr, unsigned long size)
  21{
  22        return 1;
  23}
  24
  25/*
  26 * These are the main single-value transfer routines.  They automatically
  27 * use the right size if we just have the right pointer type.
  28 */
  29
  30#define put_user(x, ptr)                                \
  31({                                                      \
  32    int __pu_err = 0;                                   \
  33    typeof(*(ptr)) __pu_val = (x);                      \
  34    switch (sizeof (*(ptr))) {                          \
  35    case 1:                                             \
  36        __put_user_asm(__pu_err, __pu_val, ptr, b);     \
  37        break;                                          \
  38    case 2:                                             \
  39        __put_user_asm(__pu_err, __pu_val, ptr, w);     \
  40        break;                                          \
  41    case 4:                                             \
  42        __put_user_asm(__pu_err, __pu_val, ptr, l);     \
  43        break;                                          \
  44    case 8:                                             \
  45        memcpy(ptr, &__pu_val, sizeof (*(ptr))); \
  46        break;                                          \
  47    default:                                            \
  48        __pu_err = __put_user_bad();                    \
  49        break;                                          \
  50    }                                                   \
  51    __pu_err;                                           \
  52})
  53#define __put_user(x, ptr) put_user(x, ptr)
  54
  55extern int __put_user_bad(void);
  56
  57/*
  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
  60 * aliasing issues.
  61 */
  62
  63#define __ptr(x) ((unsigned long *)(x))
  64
  65#define __put_user_asm(err,x,ptr,bwl)                           \
  66        __asm__ ("move" #bwl " %0,%1"                           \
  67                : /* no outputs */                                              \
  68                :"d" (x),"m" (*__ptr(ptr)) : "memory")
  69
  70#define get_user(x, ptr)                                        \
  71({                                                              \
  72    int __gu_err = 0;                                           \
  73    typeof(x) __gu_val = 0;                                     \
  74    switch (sizeof(*(ptr))) {                                   \
  75    case 1:                                                     \
  76        __get_user_asm(__gu_err, __gu_val, ptr, b, "=d");       \
  77        break;                                                  \
  78    case 2:                                                     \
  79        __get_user_asm(__gu_err, __gu_val, ptr, w, "=r");       \
  80        break;                                                  \
  81    case 4:                                                     \
  82        __get_user_asm(__gu_err, __gu_val, ptr, l, "=r");       \
  83        break;                                                  \
  84    case 8:                                                     \
  85        memcpy((void *) &__gu_val, ptr, sizeof (*(ptr)));       \
  86        break;                                                  \
  87    default:                                                    \
  88        __gu_val = 0;                                           \
  89        __gu_err = __get_user_bad();                            \
  90        break;                                                  \
  91    }                                                           \
  92    (x) = (typeof(*(ptr))) __gu_val;                            \
  93    __gu_err;                                                   \
  94})
  95#define __get_user(x, ptr) get_user(x, ptr)
  96
  97extern int __get_user_bad(void);
  98
  99#define __get_user_asm(err,x,ptr,bwl,reg)                       \
 100        __asm__ ("move" #bwl " %1,%0"                           \
 101                 : "=d" (x)                                     \
 102                 : "m" (*__ptr(ptr)))
 103
 104static inline unsigned long
 105raw_copy_from_user(void *to, const void __user *from, unsigned long n)
 106{
 107        memcpy(to, (__force const void *)from, n);
 108        return 0;
 109}
 110
 111static inline unsigned long
 112raw_copy_to_user(void __user *to, const void *from, unsigned long n)
 113{
 114        memcpy((__force void *)to, from, n);
 115        return 0;
 116}
 117#define INLINE_COPY_FROM_USER
 118#define INLINE_COPY_TO_USER
 119
 120/*
 121 * Copy a null terminated string from userspace.
 122 */
 123
 124static inline long
 125strncpy_from_user(char *dst, const char *src, long count)
 126{
 127        char *tmp;
 128        strncpy(dst, src, count);
 129        for (tmp = dst; *tmp && count > 0; tmp++, count--)
 130                ;
 131        return(tmp - dst); /* DAVIDM should we count a NUL ?  check getname */
 132}
 133
 134/*
 135 * Return the size of a string (including the ending 0)
 136 *
 137 * Return 0 on exception, a value greater than N if too long
 138 */
 139static inline long strnlen_user(const char *src, long n)
 140{
 141        return(strlen(src) + 1); /* DAVIDM make safer */
 142}
 143
 144/*
 145 * Zero Userspace
 146 */
 147
 148static inline unsigned long
 149__clear_user(void *to, unsigned long n)
 150{
 151        memset(to, 0, n);
 152        return 0;
 153}
 154
 155#define clear_user(to,n)        __clear_user(to,n)
 156
 157#endif /* _M68KNOMMU_UACCESS_H */
 158