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 pointer 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 /**
50  * Convert physical address to user pointer
51  *
52  * @v phys_addr Physical address
53  * @ret userptr User pointer
54  */
55 static inline __always_inline userptr_t
56 UACCESS_INLINE ( linux, phys_to_user ) ( physaddr_t phys_addr ) {
57 
58  /* For symmetry with the stub user_to_phys() */
59  return phys_addr;
60 }
61 
62 static inline __always_inline userptr_t
63 UACCESS_INLINE ( linux, virt_to_user ) ( volatile const void *addr ) {
64  return trivial_virt_to_user ( addr );
65 }
66 
67 static inline __always_inline void *
68 UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) {
69  return trivial_user_to_virt ( userptr, offset );
70 }
71 
72 static inline __always_inline userptr_t
73 UACCESS_INLINE ( linux, userptr_add ) ( userptr_t userptr, off_t offset ) {
74  return trivial_userptr_add ( userptr, offset );
75 }
76 
77 static inline __always_inline off_t
78 UACCESS_INLINE ( linux, userptr_sub ) ( userptr_t userptr,
80  return trivial_userptr_sub ( userptr, subtrahend );
81 }
82 
83 static inline __always_inline void
86  size_t len ) {
88 }
89 
90 static inline __always_inline void
93  size_t len ) {
95 }
96 
97 static inline __always_inline int
100  size_t len ) {
102 }
103 
104 static inline __always_inline void
106  int c, size_t len ) {
108 }
109 
110 static inline __always_inline size_t
112  return trivial_strlen_user ( buffer, offset );
113 }
114 
115 static inline __always_inline off_t
117  int c, size_t len ) {
118  return trivial_memchr_user ( buffer, offset, c, len );
119 }
120 
121 #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:84
static __always_inline void off_t dest_off
Definition: linux_uaccess.h:84
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
uint32_t first
First block in range.
Definition: pccrr.h:14
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:98
static __always_inline userptr_t trivial_userptr_add(userptr_t userptr, off_t offset)
Add offset to user pointer.
Definition: uaccess.h:81
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
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:86
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.
uint32_t userptr_t
A pointer to a user buffer.
Definition: libkir.h:159
static __always_inline void off_t int c
static __always_inline unsigned long UACCESS_INLINE(linux, user_to_phys)(userptr_t userptr
Convert user pointer to physical address.
#define __always_inline
Declare a function to be always inline.
Definition: compiler.h:611
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static __always_inline int off_t userptr_t off_t second_off
Definition: linux_uaccess.h:98
unsigned long physaddr_t
Definition: stdint.h:20
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:79
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.
u32 addr
Definition: sky2.h:8
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.
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" return dest
Definition: string.h:150
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:98
static __always_inline void off_t userptr_t src
Definition: linux_uaccess.h:84
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.
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