linux/arch/m68k/include/asm/uaccess_no.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2#ifndef __M68KNOMMU_UACCESS_H
   3#define __M68KNOMMU_UACCESS_H
   4
   5/*
   6 * User space memory access functions
   7 */
   8#include <linux/string.h>
   9
  10#include <asm/segment.h>
  11
  12#define access_ok(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((void __force *)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 __user *)(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    switch (sizeof(*(ptr))) {                                   \
  74    case 1:                                                     \
  75        __get_user_asm(__gu_err, x, ptr, b, "=d");              \
  76        break;                                                  \
  77    case 2:                                                     \
  78        __get_user_asm(__gu_err, x, ptr, w, "=r");              \
  79        break;                                                  \
  80    case 4:                                                     \
  81        __get_user_asm(__gu_err, x, ptr, l, "=r");              \
  82        break;                                                  \
  83    case 8: {                                                   \
  84        union {                                                 \
  85            u64 l;                                              \
  86            __typeof__(*(ptr)) t;                               \
  87        } __gu_val;                                             \
  88        memcpy(&__gu_val.l, (const void __force *)ptr, sizeof(__gu_val.l)); \
  89        (x) = __gu_val.t;                                       \
  90        break;                                                  \
  91    }                                                           \
  92    default:                                                    \
  93        __gu_err = __get_user_bad();                            \
  94        break;                                                  \
  95    }                                                           \
  96    __gu_err;                                                   \
  97})
  98#define __get_user(x, ptr) get_user(x, ptr)
  99
 100extern int __get_user_bad(void);
 101
 102#define __get_user_asm(err,x,ptr,bwl,reg)                       \
 103        __asm__ ("move" #bwl " %1,%0"                           \
 104                 : "=d" (x)                                     \
 105                 : "m" (*__ptr(ptr)))
 106
 107static inline unsigned long
 108raw_copy_from_user(void *to, const void __user *from, unsigned long n)
 109{
 110        memcpy(to, (__force const void *)from, n);
 111        return 0;
 112}
 113
 114static inline unsigned long
 115raw_copy_to_user(void __user *to, const void *from, unsigned long n)
 116{
 117        memcpy((__force void *)to, from, n);
 118        return 0;
 119}
 120#define INLINE_COPY_FROM_USER
 121#define INLINE_COPY_TO_USER
 122
 123/*
 124 * Copy a null terminated string from userspace.
 125 */
 126
 127static inline long
 128strncpy_from_user(char *dst, const char *src, long count)
 129{
 130        char *tmp;
 131        strncpy(dst, src, count);
 132        for (tmp = dst; *tmp && count > 0; tmp++, count--)
 133                ;
 134        return(tmp - dst); /* DAVIDM should we count a NUL ?  check getname */
 135}
 136
 137/*
 138 * Return the size of a string (including the ending 0)
 139 *
 140 * Return 0 on exception, a value greater than N if too long
 141 */
 142static inline long strnlen_user(const char *src, long n)
 143{
 144        return(strlen(src) + 1); /* DAVIDM make safer */
 145}
 146
 147/*
 148 * Zero Userspace
 149 */
 150
 151static inline unsigned long
 152__clear_user(void *to, unsigned long n)
 153{
 154        memset(to, 0, n);
 155        return 0;
 156}
 157
 158#define clear_user(to,n)        __clear_user(to,n)
 159
 160#endif /* _M68KNOMMU_UACCESS_H */
 161