memoryDefinitionWaterSprayFireAssociated.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #ifndef __ASM_AVR32_UACCESS_H
  9. #define __ASM_AVR32_UACCESS_H
  10. #include <linux/errno.h>
  11. #include <linux/sched.h>
  12. #define VERIFY_READ 0
  13. #define VERIFY_WRITE 1
  14. typedef struct {
  15. unsigned int is_user_space;
  16. } mm_segment_t;
  17. /*
  18. * The fs value determines whether argument validity checking should be
  19. * performed or not. If get_fs() == USER_DS, checking is performed, with
  20. * get_fs() == KERNEL_DS, checking is bypassed.
  21. *
  22. * For historical reasons (Data Segment Register?), these macros are misnamed.
  23. */
  24. #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
  25. #define segment_eq(a,b) ((a).is_user_space == (b).is_user_space)
  26. #define USER_ADDR_LIMIT 0x80000000
  27. #define KERNEL_DS MAKE_MM_SEG(0)
  28. #define USER_DS MAKE_MM_SEG(1)
  29. #define get_ds() (KERNEL_DS)
  30. static inline mm_segment_t get_fs(void)
  31. {
  32. return MAKE_MM_SEG(test_thread_flag(TIF_USERSPACE));
  33. }
  34. static inline void set_fs(mm_segment_t s)
  35. {
  36. if (s.is_user_space)
  37. set_thread_flag(TIF_USERSPACE);
  38. else
  39. clear_thread_flag(TIF_USERSPACE);
  40. }
  41. /*
  42. * Test whether a block of memory is a valid user space address.
  43. * Returns 0 if the range is valid, nonzero otherwise.
  44. *
  45. * We do the following checks:
  46. * 1. Is the access from kernel space?
  47. * 2. Does (addr + size) set the carry bit?
  48. * 3. Is (addr + size) a negative number (i.e. >= 0x80000000)?
  49. *
  50. * If yes on the first check, access is granted.
  51. * If no on any of the others, access is denied.
  52. */
  53. #define __range_ok(addr, size) \
  54. (test_thread_flag(TIF_USERSPACE) \
  55. && (((unsigned long)(addr) >= 0x80000000) \
  56. || ((unsigned long)(size) > 0x80000000) \
  57. || (((unsigned long)(addr) + (unsigned long)(size)) > 0x80000000)))
  58. #define access_ok(type, addr, size) (likely(__range_ok(addr, size) == 0))
  59. /* Generic arbitrary sized copy. Return the number of bytes NOT copied */
  60. extern __kernel_size_t __copy_user(void *to, const void *from,
  61. __kernel_size_t n);
  62. extern __kernel_size_t copy_to_user(void __user *to, const void *from,
  63. __kernel_size_t n);
  64. extern __kernel_size_t copy_from_user(void *to, const void __user *from,
  65. __kernel_size_t n);
  66. static inline __kernel_size_t __copy_to_user(void __user *to, const void *from,
  67. __kernel_size_t n)
  68. {
  69. return __copy_user((void __force *)to, from, n);
  70. }
  71. static inline __kernel_size_t __copy_from_user(void *to,
  72. const void __user *from,
  73. __kernel_size_t n)
  74. {
  75. return __copy_user(to, (const void __force *)from, n);
  76. }
  77. #define __copy_to_user_inatomic __copy_to_user
  78. #define __copy_from_user_inatomic __copy_from_user
  79. /*
  80. * put_user: - Write a simple value into user space.
  81. * @x: Value to copy to user space.
  82. * @ptr: Destination address, in user space.
  83. *
  84. * Context: User context only. This function may sleep.
  85. *
  86. * This macro copies a single simple value from kernel space to user
  87. * space. It supports simple types like char and int, but not larger
  88. * data types like structures or arrays.
  89. *
  90. * @ptr must have pointer-to-simple-variable type, and @x must be assignable
  91. * to the result of dereferencing @ptr.
  92. *
  93. * Returns zero on success, or -EFAULT on error.
  94. */
  95. #define put_user(x,ptr) \
  96. __put_user_check((x),(ptr),sizeof(*(ptr)))