iPXE
linux_uaccess.h
Go to the documentation of this file.
00001 #ifndef _IPXE_LINUX_UACCESS_H
00002 #define _IPXE_LINUX_UACCESS_H
00003 
00004 /** @file
00005  *
00006  * iPXE user access API for Linux
00007  *
00008  * We run with no distinction between internal and external addresses,
00009  * so can use trivial_virt_to_user() et al.
00010  *
00011  * We have no concept of the underlying physical addresses, since
00012  * these are not exposed to userspace.  We provide a stub
00013  * implementation of user_to_phys() since this is required by
00014  * alloc_memblock().  We provide no implementation of phys_to_user();
00015  * any code attempting to access physical addresses will therefore
00016  * (correctly) fail to link.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00020 
00021 #ifdef UACCESS_LINUX
00022 #define UACCESS_PREFIX_linux
00023 #else
00024 #define UACCESS_PREFIX_linux __linux_
00025 #endif
00026 
00027 /**
00028  * Convert user buffer to physical address
00029  *
00030  * @v userptr           User pointer
00031  * @v offset            Offset from user pointer
00032  * @ret phys_addr       Physical address
00033  */
00034 static inline __always_inline unsigned long
00035 UACCESS_INLINE ( linux, user_to_phys ) ( userptr_t userptr, off_t offset ) {
00036 
00037         /* We do not know the real underlying physical address.  We
00038          * provide this stub implementation only because it is
00039          * required by alloc_memblock() (which allocates memory with
00040          * specified physical address alignment).  We assume that the
00041          * low-order bits of virtual addresses match the low-order
00042          * bits of physical addresses, and so simply returning the
00043          * virtual address will suffice for the purpose of determining
00044          * alignment.
00045          */
00046         return ( userptr + offset );
00047 }
00048 
00049 static inline __always_inline userptr_t
00050 UACCESS_INLINE ( linux, virt_to_user ) ( volatile const void *addr ) {
00051         return trivial_virt_to_user ( addr );
00052 }
00053 
00054 static inline __always_inline void *
00055 UACCESS_INLINE ( linux, user_to_virt ) ( userptr_t userptr, off_t offset ) {
00056         return trivial_user_to_virt ( userptr, offset );
00057 }
00058 
00059 static inline __always_inline userptr_t
00060 UACCESS_INLINE ( linux, userptr_add ) ( userptr_t userptr, off_t offset ) {
00061         return trivial_userptr_add ( userptr, offset );
00062 }
00063 
00064 static inline __always_inline off_t
00065 UACCESS_INLINE ( linux, userptr_sub ) ( userptr_t userptr,
00066                                         userptr_t subtrahend ) {
00067         return trivial_userptr_sub ( userptr, subtrahend );
00068 }
00069 
00070 static inline __always_inline void
00071 UACCESS_INLINE ( linux, memcpy_user ) ( userptr_t dest, off_t dest_off,
00072                                         userptr_t src, off_t src_off,
00073                                         size_t len ) {
00074         trivial_memcpy_user ( dest, dest_off, src, src_off, len );
00075 }
00076 
00077 static inline __always_inline void
00078 UACCESS_INLINE ( linux, memmove_user ) ( userptr_t dest, off_t dest_off,
00079                                          userptr_t src, off_t src_off,
00080                                          size_t len ) {
00081         trivial_memmove_user ( dest, dest_off, src, src_off, len );
00082 }
00083 
00084 static inline __always_inline int
00085 UACCESS_INLINE ( linux, memcmp_user ) ( userptr_t first, off_t first_off,
00086                                         userptr_t second, off_t second_off,
00087                                         size_t len ) {
00088         return trivial_memcmp_user ( first, first_off, second, second_off, len);
00089 }
00090 
00091 static inline __always_inline void
00092 UACCESS_INLINE ( linux, memset_user ) ( userptr_t buffer, off_t offset,
00093                                         int c, size_t len ) {
00094         trivial_memset_user ( buffer, offset, c, len );
00095 }
00096 
00097 static inline __always_inline size_t
00098 UACCESS_INLINE ( linux, strlen_user ) ( userptr_t buffer, off_t offset ) {
00099         return trivial_strlen_user ( buffer, offset );
00100 }
00101 
00102 static inline __always_inline off_t
00103 UACCESS_INLINE ( linux, memchr_user ) ( userptr_t buffer, off_t offset,
00104                                         int c, size_t len ) {
00105         return trivial_memchr_user ( buffer, offset, c, len );
00106 }
00107 
00108 #endif /* _IPXE_LINUX_UACCESS_H */