iPXE
Defines | 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.

Defines

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

Typedefs

typedef unsigned long userptr_t
 A pointer to a user buffer.

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

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.


Define Documentation

#define UNULL   ( ( userptr_t ) 0 )
#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.

#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.

#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

typedef unsigned long userptr_t

A pointer to a user buffer.

Definition at line 33 of file uaccess.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
userptr_t phys_to_user ( unsigned long  phys_addr)
unsigned long user_to_phys ( userptr_t  userptr,
off_t  offset 
)
userptr_t virt_to_user ( volatile const void *  addr)
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_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().

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().

static __always_inline unsigned long virt_to_phys ( volatile const void *  addr) [inline, static]

Convert virtual address to a physical address.

Parameters:
addrVirtual address
Return values:
phys_addrPhysical address

Definition at line 287 of file uaccess.h.

References 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(), 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().

                                           {
        return user_to_phys ( virt_to_user ( addr ), 0 );
}
static __always_inline void* phys_to_virt ( unsigned long  phys_addr) [inline, static]

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.

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().

                                                                              {
        return user_to_virt ( phys_to_user ( phys_addr ), 0 );
}
void memcpy_user ( userptr_t  dest,
off_t  dest_off,
userptr_t  src,
off_t  src_off,
size_t  len 
)
static __always_inline void copy_to_user ( userptr_t  dest,
off_t  dest_off,
const void *  src,
size_t  len 
) [inline, static]
static __always_inline void copy_from_user ( void *  dest,
userptr_t  src,
off_t  src_off,
size_t  len 
) [inline, static]

Copy data from user buffer.

Parameters:
destDestination
srcSource
src_offSource offset
lenLength

Definition at line 337 of file uaccess.h.

References memcpy_user(), 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().

                                                                        {
        memcpy_user ( virt_to_user ( dest ), 0, src, src_off, len );
}
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().

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().

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().

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().

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().