iPXE
Macros | Typedefs | Functions
uaccess.h File Reference

Access to external ("user") memory. More...

#include <stdint.h>
#include <string.h>
#include <ipxe/api.h>
#include <config/ioapi.h>
#include <ipxe/efi/efi_uaccess.h>
#include <ipxe/linux/linux_uaccess.h>
#include <bits/uaccess.h>

Go to the source code of this file.

Macros

#define UNULL   ( ( userptr_t ) 0 )
 Equivalent of NULL for user pointers. More...
 
#define UACCESS_INLINE(_subsys, _api_func)   SINGLE_API_INLINE ( UACCESS_PREFIX_ ## _subsys, _api_func )
 Calculate static inline user access API function name. More...
 
#define PROVIDE_UACCESS(_subsys, _api_func, _func)   PROVIDE_SINGLE_API ( UACCESS_PREFIX_ ## _subsys, _api_func, _func )
 Provide an user access API implementation. More...
 
#define PROVIDE_UACCESS_INLINE(_subsys, _api_func)   PROVIDE_SINGLE_API_INLINE ( UACCESS_PREFIX_ ## _subsys, _api_func )
 Provide a static inline user access API implementation. More...
 

Typedefs

typedef unsigned long userptr_t
 A pointer to a user buffer. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static __always_inline userptr_t trivial_virt_to_user (volatile const void *addr)
 Convert virtual address to user pointer. More...
 
static __always_inline void * trivial_user_to_virt (userptr_t userptr, off_t offset)
 Convert user pointer to virtual address. More...
 
static __always_inline userptr_t trivial_userptr_add (userptr_t userptr, off_t offset)
 Add offset to user pointer. More...
 
static __always_inline off_t trivial_userptr_sub (userptr_t userptr, userptr_t subtrahend)
 Subtract user pointers. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
static __always_inline size_t trivial_strlen_user (userptr_t buffer, off_t offset)
 Find length of NUL-terminated string in user buffer. More...
 
static __always_inline off_t trivial_memchr_user (userptr_t buffer, off_t offset, int c, size_t len)
 Find character in user buffer. More...
 
userptr_t phys_to_user (unsigned long phys_addr)
 Convert physical address to user pointer. More...
 
unsigned long user_to_phys (userptr_t userptr, off_t offset)
 Convert user pointer to physical address. More...
 
userptr_t virt_to_user (volatile const void *addr)
 Convert virtual address to user pointer. More...
 
void * user_to_virt (userptr_t userptr, off_t offset)
 Convert user pointer to virtual address. More...
 
userptr_t userptr_add (userptr_t userptr, off_t offset)
 Add offset to user pointer. More...
 
off_t userptr_sub (userptr_t userptr, userptr_t subtrahend)
 Subtract user pointers. More...
 
static __always_inline unsigned long virt_to_phys (volatile const void *addr)
 Convert virtual address to a physical address. More...
 
static __always_inline void * phys_to_virt (unsigned long phys_addr)
 Convert physical address to a virtual address. More...
 
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. More...
 
static __always_inline void copy_to_user (userptr_t dest, off_t dest_off, const void *src, size_t len)
 Copy data to user buffer. More...
 
static __always_inline void copy_from_user (void *dest, userptr_t src, off_t src_off, size_t len)
 Copy data from user buffer. More...
 
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. More...
 
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. More...
 
void memset_user (userptr_t userptr, off_t offset, int c, size_t len)
 Fill user buffer with a constant byte. More...
 
size_t strlen_user (userptr_t userptr, off_t offset)
 Find length of NUL-terminated string in user buffer. More...
 
off_t memchr_user (userptr_t userptr, off_t offset, int c, size_t len)
 Find character in user buffer. More...
 

Detailed Description

Access to external ("user") memory.

iPXE often needs to transfer data between internal and external buffers. On i386, the external buffers may require access via a different segment, and the buffer address cannot be encoded into a simple void * pointer. The userptr_t type encapsulates the information needed to identify an external buffer, and the copy_to_user() and copy_from_user() functions provide methods for transferring data between internal and external buffers.

Note that userptr_t is an opaque type; in particular, performing arithmetic upon a userptr_t is not allowed.

Definition in file uaccess.h.

Macro Definition Documentation

◆ UNULL

#define UNULL   ( ( userptr_t ) 0 )

Equivalent of NULL for user pointers.

Definition at line 36 of file uaccess.h.

◆ UACCESS_INLINE

#define UACCESS_INLINE (   _subsys,
  _api_func 
)    SINGLE_API_INLINE ( UACCESS_PREFIX_ ## _subsys, _api_func )

Calculate static inline user access API function name.

Parameters
_prefixSubsystem prefix
_api_funcAPI function
Return values
_subsys_funcSubsystem API function

Definition at line 197 of file uaccess.h.

◆ PROVIDE_UACCESS

#define PROVIDE_UACCESS (   _subsys,
  _api_func,
  _func 
)    PROVIDE_SINGLE_API ( UACCESS_PREFIX_ ## _subsys, _api_func, _func )

Provide an user access API implementation.

Parameters
_prefixSubsystem prefix
_api_funcAPI function
_funcImplementing function

Definition at line 207 of file uaccess.h.

◆ PROVIDE_UACCESS_INLINE

#define PROVIDE_UACCESS_INLINE (   _subsys,
  _api_func 
)    PROVIDE_SINGLE_API_INLINE ( UACCESS_PREFIX_ ## _subsys, _api_func )

Provide a static inline user access API implementation.

Parameters
_prefixSubsystem prefix
_api_funcAPI function

Definition at line 216 of file uaccess.h.

Typedef Documentation

◆ userptr_t

typedef unsigned long userptr_t

A pointer to a user buffer.

Definition at line 33 of file uaccess.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ phys_to_user()

userptr_t phys_to_user ( unsigned long  phys_addr)

◆ user_to_phys()

unsigned long user_to_phys ( userptr_t  userptr,
off_t  offset 
)

◆ virt_to_user()

userptr_t virt_to_user ( volatile const void *  addr)

◆ user_to_virt()

void* user_to_virt ( userptr_t  userptr,
off_t  offset 
)

Convert user pointer to virtual address.

Parameters
userptrUser pointer
offsetOffset from user pointer
Return values
addrVirtual address

This operation is not available under all memory models.

Referenced by bzimage_check_initrds(), bzimage_load_initrd(), efi_image_exec(), efi_image_probe(), initrd_dump(), and phys_to_virt().

◆ userptr_add()

userptr_t userptr_add ( userptr_t  userptr,
off_t  offset 
)

Add offset to user pointer.

Parameters
userptrUser pointer
offsetOffset
Return values
userptrNew pointer value

Referenced by bzimage_check_initrds(), bzimage_load_initrds(), ecollect_free(), init_eheap(), initrd_startup(), initrd_swap(), initrd_swap_any(), memtop_urealloc(), nbi_process_segments(), and sandev_rw().

◆ userptr_sub()

off_t userptr_sub ( userptr_t  userptr,
userptr_t  subtrahend 
)

Subtract user pointers.

Parameters
userptrUser pointer
subtrahendUser pointer to be subtracted
Return values
offsetOffset

Referenced by bzimage_load_initrds(), initrd_reshuffle(), initrd_reshuffle_check(), and initrd_squash_high().

◆ virt_to_phys()

static __always_inline unsigned long virt_to_phys ( volatile const void *  addr)
inlinestatic

Convert virtual address to a physical address.

Parameters
addrVirtual address
Return values
phys_addrPhysical address

Definition at line 287 of file uaccess.h.

287  {
288  return user_to_phys ( virt_to_user ( addr ), 0 );
289 }
unsigned long user_to_phys(userptr_t userptr, off_t offset)
Convert user pointer to physical address.
u32 addr
Definition: sky2.h:8
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.

References addr, user_to_phys(), and virt_to_user().

Referenced by alloc_iob_okx(), alloc_memblock(), arbel_alloc_icm(), arbel_cmd(), arbel_complete(), arbel_create_cq(), arbel_create_eq(), arbel_create_qp(), arbel_poll_eq(), arbel_post_send(), arbel_ring_doorbell(), com32_exec_loop(), ehci_bus_open(), ehci_ctrl_reachable(), ehci_endpoint_reset(), ehci_enqueue(), ehci_init(), ehci_link_qh(), ehci_ring_alloc(), ena_admin(), ena_create_admin(), ena_create_cq(), ena_create_sq(), flexboot_nodnic_poll_cq(), fnrec_dump(), gdbmach_set_breakpoint(), hermon_alloc_mtt(), hermon_cmd(), hermon_complete(), hermon_create_cq(), hermon_create_eq(), hermon_create_qp(), hermon_poll_cq(), hermon_poll_eq(), hermon_post_send(), hide_etherboot(), hide_textdata(), hide_umalloc(), hv_map_hypercall(), hv_map_synic(), hvm_ioremap(), hvm_iounmap(), hvm_map_grant(), hvm_map_hypercall(), hvm_map_shared_info(), icplus_transmit(), init_idt(), intelxl_admin_command(), intelxl_poll_admin(), IOMAP_INLINE(), multiboot_add_cmdline(), multiboot_exec(), nbi_boot32(), netfront_create_ring(), netfront_poll_rx(), netfront_push(), netfront_refill_rx(), netfront_transmit(), pxe_start_nbp(), relocate(), uhci_bus_open(), uhci_describe(), uhci_endpoint_poll(), uhci_enqueue(), uhci_link_qh(), uhci_reachable(), uhci_restart(), virt_to_bus(), vmbus_initiate_contact(), vmbus_open(), vmbus_send_data(), vp_find_vq(), vpm_find_vqs(), vring_add_buf(), vring_init(), xen_hvm_get_param(), xhci_abort(), xhci_address_device_input(), xhci_command_alloc(), xhci_configure_endpoint_input(), xhci_context(), xhci_dcbaa_alloc(), xhci_device_open(), xhci_endpoint_message(), xhci_endpoint_open(), xhci_endpoint_stream(), xhci_event_alloc(), xhci_event_poll(), xhci_init(), xhci_ring_alloc(), xhci_ring_consumed(), xhci_scratchpad_alloc(), and xhci_set_tr_dequeue_pointer().

◆ phys_to_virt()

static __always_inline void* phys_to_virt ( unsigned long  phys_addr)
inlinestatic

Convert physical address to a virtual address.

Parameters
addrVirtual address
Return values
phys_addrPhysical address

This operation is not available under all memory models.

Definition at line 299 of file uaccess.h.

299  {
300  return user_to_virt ( phys_to_user ( phys_addr ), 0 );
301 }
userptr_t phys_to_user(unsigned long phys_addr)
Convert physical address to user pointer.
void * user_to_virt(userptr_t userptr, off_t offset)
Convert user pointer to virtual address.

References phys_to_user(), and user_to_virt().

Referenced by bus_to_virt(), fnrec_init(), interrupt_dump(), myri10ge_net_open(), video_init(), and vring_init().

◆ memcpy_user()

void memcpy_user ( userptr_t  dest,
off_t  dest_off,
userptr_t  src,
off_t  src_off,
size_t  len 
)

◆ copy_to_user()

static __always_inline void copy_to_user ( userptr_t  dest,
off_t  dest_off,
const void *  src,
size_t  len 
)
inlinestatic

Copy data to user buffer.

Parameters
destDestination
dest_offDestination offset
srcSource
lenLength

Definition at line 324 of file uaccess.h.

324  {
326 }
static __always_inline void off_t dest_off
Definition: efi_uaccess.h:66
static void * dest
Definition: strings.h:176
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
uint32_t len
Length.
Definition: ena.h:14
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
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.

References dest, dest_off, len, memcpy_user(), src, and virt_to_user().

Referenced by aoecmd_ata_rsp(), blktrans_xferbuf_write(), bofm(), bzimage_load_initrd(), bzimage_set_cmdline(), bzimage_update_header(), comboot_copy_cmdline(), comboot_init_psp(), copy_to_real(), efi_urealloc(), efifb_glyphs(), fbcon_clear(), fbcon_draw(), fbcon_picture_init(), fbcon_store(), fcpcmd_recv_rddata(), iscsi_rx_data_in(), memtop_urealloc(), png_pixels_pass(), png_unfilter_pass(), pnm_data(), pxe_api_call(), pxe_loader_call(), pxe_tftp_xfer_deliver(), pxenv_file_cmdline(), pxenv_get_cached_info(), pxenv_udp_read(), read_user(), txnic_refill_rq(), txnic_send(), and xferbuf_umalloc_write().

◆ copy_from_user()

static __always_inline void copy_from_user ( void *  dest,
userptr_t  src,
off_t  src_off,
size_t  len 
)
inlinestatic

Copy data from user buffer.

Parameters
destDestination
srcSource
src_offSource offset
lenLength

Definition at line 337 of file uaccess.h.

337  {
338  memcpy_user ( virt_to_user ( dest ), 0, src, src_off, len );
339 }
static __always_inline void off_t userptr_t off_t src_off
Definition: efi_uaccess.h:66
static void * dest
Definition: strings.h:176
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
uint32_t len
Length.
Definition: ena.h:14
userptr_t virt_to_user(volatile const void *addr)
Convert virtual address to user pointer.
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.

References dest, len, memcpy_user(), src, src_off, and virt_to_user().

Referenced by acpi_checksum(), acpi_find(), acpi_poweroff(), acpi_settings_fetch(), acpi_sx(), acpi_sx_zsdt(), acpi_timer_probe(), aoecmd_ata_cmd(), blktrans_xferbuf_read(), bofm(), bofm_locate_section(), bzimage_parse_header(), cachedhcp_init(), cmdline_init(), cms_digest(), com32_identify(), copy_from_real(), deflate_accumulate(), der_asn1(), der_probe(), digest_exec(), ecollect_free(), efi_file_read(), efi_urealloc(), efifb_glyph(), elf_load(), elf_segments(), elfboot_probe(), exanic_poll_rx(), fbcon_draw_cursor(), fbcon_picture_init(), fbcon_redraw(), fcpcmd_send_wrdata(), find_smbios_entry(), find_smbios_structure(), find_strings_terminator(), int13_load_eltorito(), int22(), iscsi_tx_data_out(), memtop_urealloc(), multiboot_find_header(), nbi_exec(), nbi_probe(), nbi_process_segments(), netvsc_buffer_copy(), peerdist_info_get(), pem_asn1(), pem_marker(), png_image_header(), png_palette(), png_pixbuf(), png_pixels_pass(), png_probe(), png_unfilter_pass(), pnm_ascii(), pnm_binary(), pnm_probe(), pnm_type(), print_user_string(), process_script(), pxe_api_call(), pxe_loader_call(), pxe_probe_no_mz(), pxenv_file_exec(), pxenv_file_open(), pxenv_udp_write(), read_smbios_string(), read_smbios_structure(), rsdp_find_rsdt_range(), script_probe(), sdi_parse_header(), shuffle(), txnic_poll_cq(), vesafb_mode_list(), vram_fetch(), and xferbuf_umalloc_read().

◆ memmove_user()

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.

Parameters
destDestination
dest_offDestination offset
srcSource
src_offSource offset
lenLength

Referenced by bzimage_load_initrd(), fbcon_scroll(), initrd_squash_high(), initrd_swap(), memtop_urealloc(), and shuffle().

◆ memcmp_user()

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.

Parameters
firstFirst buffer
first_offFirst buffer offset
secondSecond buffer
second_offSecond buffer offset
lenLength
Return values
diffDifference

Referenced by pixbuf_okx().

◆ memset_user()

void memset_user ( userptr_t  userptr,
off_t  offset,
int  c,
size_t  len 
)

Fill user buffer with a constant byte.

Parameters
userptrUser buffer
offsetOffset within buffer
cConstant byte with which to fill
lenLength

Referenced by bzimage_load_initrd(), comboot_prepare_segment(), efifb_glyphs(), exanic_open(), fbcon_draw(), fbcon_init(), fbcon_picture_init(), prep_segment(), shuffle(), and xhci_scratchpad_alloc().

◆ strlen_user()

size_t strlen_user ( userptr_t  userptr,
off_t  offset 
)

Find length of NUL-terminated string in user buffer.

Parameters
userptrUser buffer
offsetOffset within buffer
Return values
lenLength of string (excluding NUL)

Referenced by cmdline_init(), int22(), pxenv_file_exec(), pxenv_file_open(), and read_smbios_string().

◆ memchr_user()

off_t memchr_user ( userptr_t  userptr,
off_t  offset,
int  c,
size_t  len 
)

Find character in user buffer.

Parameters
userptrUser buffer
offsetStarting offset within buffer
cCharacter to search for
lenLength of user buffer
Return values
offsetOffset of character, or <0 if not found

Referenced by pem_next(), and process_script().