Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef _IPXE_LINUX_UACCESS_H
  2. #define _IPXE_LINUX_UACCESS_H
  3. /** @file
  4. *
  5. * iPXE user access API for Linux
  6. *
  7. * We run with no distinction between internal and external addresses,
  8. * so can use trivial_virt_to_user() et al.
  9. *
  10. * We have no concept of the underlying physical addresses, since
  11. * these are not exposed to userspace. We provide a stub
  12. * implementation of user_to_phys() since this is required by
  13. * alloc_memblock(). We provide no implementation of phys_to_user();
  14. * any code attempting to access physical addresses will therefore
  15. * (correctly) fail to link.
  16. */
  17. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  18. #ifdef UACCESS_LINUX
  19. #define UACCESS_PREFIX_linux
  20. #else
  21. #define UACCESS_PREFIX_linux __linux_
  22. #endif
  23. /**
  24. * Convert user buffer to physical address
  25. *
  26. * @v userptr User pointer
  27. * @v offset Offset from user pointer
  28. * @ret phys_addr Physical address
  29. */
  30. static inline __always_inline unsigned long
  31. UACCESS_INLINE ( linux, user_to_phys ) ( userptr_t userptr, off_t offset ) {
  32. /* We do not know the real underlying physical address. We
  33. * provide this stub implementation only because it is
  34. * required by alloc_memblock() (which allocates memory with
  35. * specified physical address alignment). We assume that the
  36. * low-order bits of virtual addresses match the low-order
  37. * bits of physical addresses, and so simply returning the
  38. * virtual address will suffice for the purpose of determining
  39. * alignment.
  40. */
  41. return ( userptr + offset );
  42. }
  43. static inline __always_inline userptr_t
  44. UACCESS_INLINE ( linux, virt_to_user ) ( volatile const void *addr ) {
  45. return trivial_virt_to_user ( addr );
  46. }
  47. static inline __always_inline void *
  48. UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) {
  49. return trivial_user_to_virt ( userptr, offset );
  50. }
  51. static inline __always_inline userptr_t
  52. UACCESS_INLINE ( linux, userptr_add ) ( userptr_t userptr, off_t offset ) {
  53. return trivial_userptr_add ( userptr, offset );
  54. }
  55. static inline __always_inline off_t
  56. UACCESS_INLINE ( linux, userptr_sub ) ( userptr_t userptr,
  57. userptr_t subtrahend ) {
  58. return trivial_userptr_sub ( userptr, subtrahend );
  59. }
  60. static inline __always_inline void
  61. UACCESS_INLINE ( linux, memcpy_user ) ( userptr_t dest, off_t dest_off,
  62. userptr_t src, off_t src_off,
  63. size_t len ) {
  64. trivial_memcpy_user ( dest, dest_off, src, src_off, len );
  65. }
  66. static inline __always_inline void
  67. UACCESS_INLINE ( linux, memmove_user ) ( userptr_t dest, off_t dest_off,
  68. userptr_t src, off_t src_off,
  69. size_t len ) {
  70. trivial_memmove_user ( dest, dest_off, src, src_off, len );
  71. }
  72. static inline __always_inline int
  73. UACCESS_INLINE ( linux, memcmp_user ) ( userptr_t first, off_t first_off,
  74. userptr_t second, off_t second_off,
  75. size_t len ) {
  76. return trivial_memcmp_user ( first, first_off, second, second_off, len);
  77. }
  78. static inline __always_inline void
  79. UACCESS_INLINE ( linux, memset_user ) ( userptr_t buffer, off_t offset,
  80. int c, size_t len ) {
  81. trivial_memset_user ( buffer, offset, c, len );
  82. }
  83. static inline __always_inline size_t
  84. UACCESS_INLINE ( linux, strlen_user ) ( userptr_t buffer, off_t offset ) {
  85. return trivial_strlen_user ( buffer, offset );
  86. }
  87. static inline __always_inline off_t
  88. UACCESS_INLINE ( linux, memchr_user ) ( userptr_t buffer, off_t offset,
  89. int c, size_t len ) {
  90. return trivial_memchr_user ( buffer, offset, c, len );
  91. }
  92. #endif /* _IPXE_LINUX_UACCESS_H */