iPXE
linux_uaccess.h
Go to the documentation of this file.
1 #ifndef _IPXE_LINUX_UACCESS_H
2 #define _IPXE_LINUX_UACCESS_H
3 
4 /** @file
5  *
6  * iPXE user access API for Linux
7  *
8  * We run with no distinction between internal and external addresses,
9  * so can use trivial_virt_to_user() et al.
10  *
11  * We have no concept of the underlying physical addresses, since
12  * these are not exposed to userspace. We provide a stub
13  * implementation of user_to_phys() since this is required by
14  * alloc_memblock(). We provide no implementation of phys_to_user();
15  * any code attempting to access physical addresses will therefore
16  * (correctly) fail to link.
17  */
18 
19 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
20 
21 #ifdef UACCESS_LINUX
22 #define UACCESS_PREFIX_linux
23 #else
24 #define UACCESS_PREFIX_linux __linux_
25 #endif
26 
27 /**
28  * Convert user buffer to physical address
29  *
30  * @v userptr User pointer
31  * @v offset Offset from user pointer
32  * @ret phys_addr Physical address
33  */
34 static inline __always_inline unsigned long
36 
37  /* We do not know the real underlying physical address. We
38  * provide this stub implementation only because it is
39  * required by alloc_memblock() (which allocates memory with
40  * specified physical address alignment). We assume that the
41  * low-order bits of virtual addresses match the low-order
42  * bits of physical addresses, and so simply returning the
43  * virtual address will suffice for the purpose of determining
44  * alignment.
45  */
46  return ( userptr + offset );
47 }
48 
49 static inline __always_inline userptr_t
50 UACCESS_INLINE ( linux, virt_to_user ) ( volatile const void *addr ) {
51  return trivial_virt_to_user ( addr );
52 }
53 
54 static inline __always_inline void *
55 UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) {
56  return trivial_user_to_virt ( userptr, offset );
57 }
58 
59 static inline __always_inline userptr_t
60 UACCESS_INLINE ( linux, userptr_add ) ( userptr_t userptr, off_t offset ) {
61  return trivial_userptr_add ( userptr, offset );
62 }
63 
64 static inline __always_inline off_t
65 UACCESS_INLINE ( linux, userptr_sub ) ( userptr_t userptr,
67  return trivial_userptr_sub ( userptr, subtrahend );
68 }
69 
70 static inline __always_inline void
73  size_t len ) {
75 }
76 
77 static inline __always_inline void
80  size_t len ) {
82 }
83 
84 static inline __always_inline int
87  size_t len ) {
89 }
90 
91 static inline __always_inline void
93  int c, size_t len ) {
95 }
96 
97 static inline __always_inline size_t
99  return trivial_strlen_user ( buffer, offset );
100 }
101 
102 static inline __always_inline off_t
104  int c, size_t len ) {
105  return trivial_memchr_user ( buffer, offset, c, len );
106 }
107 
108 #endif /* _IPXE_LINUX_UACCESS_H */
static __always_inline size_t trivial_strlen_user(userptr_t buffer, off_t offset)
Find length of NUL-terminated string in user buffer.
Definition: uaccess.h:167
static __always_inline void off_t userptr_t off_t src_off
Definition: linux_uaccess.h:71
static __always_inline void off_t dest_off
Definition: linux_uaccess.h:71
static __always_inline int trivial_memcmp_user(userptr_t first, off_t first_off, userptr_t second, off_t second_off, size_t len)
Compare data between user buffers.
Definition: uaccess.h:140
static __always_inline void * trivial_user_to_virt(userptr_t userptr, off_t offset)
Convert user pointer to virtual address.
Definition: uaccess.h:69
off_t memchr_user(userptr_t userptr, off_t offset, int c, size_t len)
Find character in user buffer.
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
static __always_inline int off_t first_off
Definition: linux_uaccess.h:85
static __always_inline userptr_t trivial_userptr_add(userptr_t userptr, off_t offset)
Add offset to user pointer.
Definition: uaccess.h:81
static __always_inline void trivial_memmove_user(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
Copy data between user buffers, allowing for overlap.
Definition: uaccess.h:123
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
static __always_inline off_t trivial_memchr_user(userptr_t buffer, off_t offset, int c, size_t len)
Find character in user buffer.
Definition: uaccess.h:181
static __always_inline void off_t userptr_t off_t size_t len
Definition: linux_uaccess.h:73
off_t userptr_sub(userptr_t userptr, userptr_t subtrahend)
Subtract user pointers.
void memset_user(userptr_t userptr, off_t offset, int c, size_t len)
Fill user buffer with a constant byte.
userptr_t userptr_add(userptr_t userptr, off_t offset)
Add offset to user pointer.
static __always_inline void off_t int c
Definition: linux_uaccess.h:92
static __always_inline unsigned long UACCESS_INLINE(linux, user_to_phys)(userptr_t userptr
Convert user buffer to physical address.
static void * dest
Definition: strings.h:176
#define __always_inline
Declare a function to be always inline.
Definition: compiler.h:611
u32 addr
Definition: sky2.h:8
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static __always_inline int off_t userptr_t off_t second_off
Definition: linux_uaccess.h:85
static __always_inline off_t trivial_userptr_sub(userptr_t userptr, userptr_t subtrahend)
Subtract user pointers.
Definition: uaccess.h:93
size_t strlen_user(userptr_t userptr, off_t offset)
Find length of NUL-terminated string in user buffer.
signed long off_t
Definition: stdint.h:8
static __always_inline off_t userptr_t subtrahend
Definition: linux_uaccess.h:66
int memcmp_user(userptr_t first, off_t first_off, userptr_t second, off_t second_off, size_t len)
Compare data between user buffers.
static __always_inline void trivial_memcpy_user(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
Copy data between user buffers.
Definition: uaccess.h:107
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
void * user_to_virt(userptr_t userptr, off_t offset)
Convert user pointer to virtual address.
void memmove_user(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
Copy data between user buffers, allowing for overlap.
static __always_inline userptr_t trivial_virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
Definition: uaccess.h:55
static __always_inline int off_t userptr_t second
Definition: linux_uaccess.h:85
uint32_t first
Length to skip in first segment.
Definition: pccrc.h:23
static __always_inline void off_t userptr_t src
Definition: linux_uaccess.h:71
void memcpy_user(userptr_t dest, off_t dest_off, userptr_t src, off_t src_off, size_t len)
Copy data between user buffers.
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33
static __always_inline unsigned long off_t offset
Definition: linux_uaccess.h:35
static __always_inline void trivial_memset_user(userptr_t buffer, off_t offset, int c, size_t len)
Fill user buffer with a constant byte.
Definition: uaccess.h:155