[uaccess] Remove redundant memcpy_user() and related string functions

The memcpy_user(), memmove_user(), memcmp_user(), memset_user(), and
strlen_user() functions are now just straightforward wrappers around
the corresponding standard library functions.

Remove these redundant wrappers.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-04-20 18:29:48 +01:00
parent ef03849185
commit 89fe788689
35 changed files with 83 additions and 331 deletions

View File

@@ -125,7 +125,7 @@ static int cmdline_init ( void ) {
return 0;
}
cmdline_user = phys_to_user ( cmdline_phys );
len = ( strlen_user ( cmdline_user, 0 ) + 1 /* NUL */ );
len = ( strlen ( cmdline_user ) + 1 /* NUL */ );
/* Allocate and copy command line */
cmdline_copy = malloc ( len );

View File

@@ -369,8 +369,8 @@ static size_t bzimage_load_initrd ( struct image *image,
/* Copy in initrd image body and construct any cpio headers */
if ( address ) {
memmove_user ( address, len, initrd->data, 0, initrd->len );
memset_user ( address, 0, 0, len );
memmove ( ( address + len ), initrd->data, initrd->len );
memset ( address, 0, len );
offset = 0;
for ( i = 0 ; ( cpio_len = cpio_header ( initrd, i, &cpio ) ) ;
i++ ) {
@@ -395,7 +395,7 @@ static size_t bzimage_load_initrd ( struct image *image,
/* Zero-pad to next INITRD_ALIGN boundary */
pad_len = ( ( -len ) & ( INITRD_ALIGN - 1 ) );
if ( address )
memset_user ( address, len, 0, pad_len );
memset ( ( address + len ), 0, pad_len );
return len;
}
@@ -562,10 +562,9 @@ static int bzimage_exec ( struct image *image ) {
unregister_image ( image_get ( image ) );
/* Load segments */
memcpy_user ( bzimg.rm_kernel, 0, image->data,
0, bzimg.rm_filesz );
memcpy_user ( bzimg.pm_kernel, 0, image->data,
bzimg.rm_filesz, bzimg.pm_sz );
memcpy ( bzimg.rm_kernel, image->data, bzimg.rm_filesz );
memcpy ( bzimg.pm_kernel, ( image->data + bzimg.rm_filesz ),
bzimg.pm_sz );
/* Store command line */
bzimage_set_cmdline ( image, &bzimg );

View File

@@ -219,7 +219,7 @@ static int com32_load_image ( struct image *image ) {
}
/* Copy image to segment */
memcpy_user ( buffer, 0, image->data, 0, filesz );
memcpy ( buffer, image->data, filesz );
return 0;
}

View File

@@ -267,10 +267,10 @@ static int comboot_prepare_segment ( struct image *image )
}
/* Zero PSP */
memset_user ( seg_userptr, 0, 0, 0x100 );
memset ( seg_userptr, 0, 0x100 );
/* Copy image to segment:0100 */
memcpy_user ( seg_userptr, 0x100, image->data, 0, image->len );
memcpy ( ( seg_userptr + 0x100 ), image->data, image->len );
return 0;
}

View File

@@ -80,7 +80,7 @@ static userptr_t initrd_squash_high ( userptr_t top ) {
user_to_phys ( highest->data, highest->len ),
user_to_phys ( current, 0 ),
user_to_phys ( current, highest->len ) );
memmove_user ( current, 0, highest->data, 0, highest->len );
memmove ( current, highest->data, highest->len );
highest->data = current;
}
@@ -96,8 +96,7 @@ static userptr_t initrd_squash_high ( userptr_t top ) {
user_to_phys ( initrd->data, initrd->len ),
user_to_phys ( current, 0 ),
user_to_phys ( current, initrd->len ) );
memcpy_user ( current, 0, initrd->data, 0,
initrd->len );
memcpy ( current, initrd->data, initrd->len );
initrd->data = current;
}
}
@@ -140,9 +139,10 @@ static void initrd_swap ( struct image *low, struct image *high,
~( INITRD_ALIGN - 1 ) );
/* Swap fragments */
memcpy_user ( free, 0, high->data, len, frag_len );
memmove_user ( low->data, new_len, low->data, len, low->len );
memcpy_user ( low->data, len, free, 0, frag_len );
memcpy ( free, ( high->data + len ), frag_len );
memmove ( ( low->data + new_len ), ( low->data + len ),
low->len );
memcpy ( ( low->data + len ), free, frag_len );
len = new_len;
}

View File

@@ -222,8 +222,8 @@ static int multiboot_add_modules ( struct image *image, physaddr_t start,
}
/* Copy module */
memcpy_user ( phys_to_user ( start ), 0,
module_image->data, 0, module_image->len );
memcpy ( phys_to_user ( start ), module_image->data,
module_image->len );
/* Add module to list */
module = &modules[mbinfo->mods_count++];
@@ -350,7 +350,7 @@ static int multiboot_load_raw ( struct image *image,
}
/* Copy image to segment */
memcpy_user ( buffer, 0, image->data, offset, filesz );
memcpy ( buffer, ( image->data + offset ), filesz );
/* Record execution entry point and maximum used address */
*entry = hdr->mb.entry_addr;

View File

@@ -131,7 +131,7 @@ static int nbi_prepare_segment ( struct image *image, size_t offset __unused,
static int nbi_load_segment ( struct image *image, size_t offset,
userptr_t dest, size_t filesz,
size_t memsz __unused ) {
memcpy_user ( dest, 0, image->data, offset, filesz );
memcpy ( dest, ( image->data + offset ), filesz );
return 0;
}

View File

@@ -66,7 +66,7 @@ static int pxe_exec ( struct image *image ) {
}
/* Copy image to segment */
memcpy_user ( buffer, 0, image->data, 0, image->len );
memcpy ( buffer, image->data, image->len );
/* Arbitrarily pick the most recently opened network device */
if ( ( netdev = last_opened_netdev() ) == NULL ) {

View File

@@ -97,8 +97,8 @@ static int sdi_exec ( struct image *image ) {
user_to_phys ( image->data, sdi.boot_offset ), sdi.boot_size );
/* Copy boot code */
memcpy_user ( real_to_user ( SDI_BOOT_SEG, SDI_BOOT_OFF ), 0,
image->data, sdi.boot_offset, sdi.boot_size );
memcpy ( real_to_user ( SDI_BOOT_SEG, SDI_BOOT_OFF ),
( image->data + sdi.boot_offset ), sdi.boot_size );
/* Jump to boot code */
sdiptr = ( user_to_phys ( image->data, 0 ) | SDI_WTF );

View File

@@ -256,7 +256,7 @@ static int ucode_update_all ( struct image *image,
rc = -ENOMEM;
goto err_alloc;
}
memset_user ( status, 0, 0, len );
memset ( status, 0, len );
/* Construct control structure */
memset ( &control, 0, sizeof ( control ) );

View File

@@ -137,38 +137,6 @@ UACCESS_INLINE ( librm, user_to_virt ) ( userptr_t userptr, off_t offset ) {
return trivial_user_to_virt ( userptr, offset );
}
static inline __always_inline void
UACCESS_INLINE ( librm, memcpy_user ) ( userptr_t dest, off_t dest_off,
userptr_t src, off_t src_off,
size_t len ) {
trivial_memcpy_user ( dest, dest_off, src, src_off, len );
}
static inline __always_inline void
UACCESS_INLINE ( librm, memmove_user ) ( userptr_t dest, off_t dest_off,
userptr_t src, off_t src_off,
size_t len ) {
trivial_memmove_user ( dest, dest_off, src, src_off, len );
}
static inline __always_inline int
UACCESS_INLINE ( librm, memcmp_user ) ( userptr_t first, off_t first_off,
userptr_t second, off_t second_off,
size_t len ) {
return trivial_memcmp_user ( first, first_off, second, second_off, len);
}
static inline __always_inline void
UACCESS_INLINE ( librm, memset_user ) ( userptr_t buffer, off_t offset,
int c, size_t len ) {
trivial_memset_user ( buffer, offset, c, len );
}
static inline __always_inline size_t
UACCESS_INLINE ( librm, strlen_user ) ( userptr_t buffer, off_t offset ) {
return trivial_strlen_user ( buffer, offset );
}
static inline __always_inline off_t
UACCESS_INLINE ( librm, memchr_user ) ( userptr_t buffer, off_t offset,
int c, size_t len ) {

View File

@@ -203,8 +203,8 @@ static userptr_t memtop_urealloc ( userptr_t ptr, size_t new_size ) {
user_to_phys ( ptr, extmem.size ),
user_to_phys ( new, 0 ),
user_to_phys ( new, new_size ));
memmove_user ( new, 0, ptr, 0, ( ( extmem.size < new_size ) ?
extmem.size : new_size ) );
memmove ( new, ptr, ( ( extmem.size < new_size ) ?
extmem.size : new_size ) );
bottom = new;
heap_size -= ( new_size - extmem.size );
extmem.size = new_size;

View File

@@ -61,8 +61,8 @@ static PXENV_EXIT_t pxenv_file_open ( struct s_PXENV_FILE_OPEN *file_open ) {
/* Copy name from external program, and open it */
filename = real_to_user ( file_open->FileName.segment,
file_open->FileName.offset );
filename_len = strlen_user ( filename, 0 );
file_open->FileName.offset );
filename_len = strlen ( filename );
{
char uri_string[ filename_len + 1 ];
@@ -219,7 +219,7 @@ static PXENV_EXIT_t pxenv_file_exec ( struct s_PXENV_FILE_EXEC *file_exec ) {
/* Copy name from external program, and exec it */
command = real_to_user ( file_exec->Command.segment,
file_exec->Command.offset );
command_len = strlen_user ( command, 0 );
command_len = strlen ( command );
{
char command_string[ command_len + 1 ];

View File

@@ -49,9 +49,8 @@ void __asmcall com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physad
DBGC ( &com32_regs, "COM32 INT%x in %#08lx out %#08lx\n",
interrupt, inregs_phys, outregs_phys );
memcpy_user ( virt_to_user( &com32_regs ), 0,
phys_to_user ( inregs_phys ), 0,
sizeof(com32sys_t) );
memcpy ( virt_to_user( &com32_regs ), phys_to_user ( inregs_phys ),
sizeof ( com32sys_t ) );
com32_int_vector = interrupt;
@@ -108,9 +107,8 @@ void __asmcall com32_intcall ( uint8_t interrupt, physaddr_t inregs_phys, physad
: : );
if ( outregs_phys ) {
memcpy_user ( phys_to_user ( outregs_phys ), 0,
virt_to_user( &com32_regs ), 0,
sizeof(com32sys_t) );
memcpy ( phys_to_user ( outregs_phys ),
virt_to_user ( &com32_regs ), sizeof ( com32sys_t ) );
}
}
@@ -122,9 +120,8 @@ void __asmcall com32_farcall ( uint32_t proc, physaddr_t inregs_phys, physaddr_t
DBGC ( &com32_regs, "COM32 farcall %04x:%04x in %#08lx out %#08lx\n",
( proc >> 16 ), ( proc & 0xffff ), inregs_phys, outregs_phys );
memcpy_user ( virt_to_user( &com32_regs ), 0,
phys_to_user ( inregs_phys ), 0,
sizeof(com32sys_t) );
memcpy ( virt_to_user( &com32_regs ), phys_to_user ( inregs_phys ),
sizeof ( com32sys_t ) );
com32_farcall_proc = proc;
@@ -170,9 +167,8 @@ void __asmcall com32_farcall ( uint32_t proc, physaddr_t inregs_phys, physaddr_t
: : );
if ( outregs_phys ) {
memcpy_user ( phys_to_user ( outregs_phys ), 0,
virt_to_user( &com32_regs ), 0,
sizeof(com32sys_t) );
memcpy ( phys_to_user ( outregs_phys ),
virt_to_user ( &com32_regs ), sizeof ( com32sys_t ) );
}
}

View File

@@ -119,7 +119,7 @@ static void shuffle ( unsigned int list_segment, unsigned int list_offset, unsig
if ( shuf[ i ].src == 0xFFFFFFFF ) {
/* Fill with 0 instead of copying */
memset_user ( dest_u, 0, 0, shuf[ i ].len );
memset ( dest_u, 0, shuf[ i ].len );
} else if ( shuf[ i ].dest == 0xFFFFFFFF ) {
/* Copy new list of descriptors */
count = shuf[ i ].len / sizeof( comboot_shuffle_descriptor );
@@ -128,7 +128,7 @@ static void shuffle ( unsigned int list_segment, unsigned int list_offset, unsig
i = -1;
} else {
/* Regular copy */
memmove_user ( dest_u, 0, src_u, 0, shuf[ i ].len );
memmove ( dest_u, src_u, shuf[ i ].len );
}
}
}
@@ -347,7 +347,7 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) {
case 0x0003: /* Run command */
{
userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
int len = strlen_user ( cmd_u, 0 );
int len = strlen ( cmd_u );
char cmd[len + 1];
copy_from_user ( cmd, cmd_u, 0, len + 1 );
DBG ( "COMBOOT: executing command '%s'\n", cmd );
@@ -371,7 +371,7 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) {
{
int fd;
userptr_t file_u = real_to_user ( ix86->segs.es, ix86->regs.si );
int len = strlen_user ( file_u, 0 );
int len = strlen ( file_u );
char file[len + 1];
copy_from_user ( file, file_u, 0, len + 1 );
@@ -484,7 +484,7 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) {
case 0x0010: /* Resolve hostname */
{
userptr_t hostname_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
int len = strlen_user ( hostname_u, 0 );
int len = strlen ( hostname_u );
char hostname[len];
struct in_addr addr;
@@ -551,8 +551,8 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) {
{
userptr_t file_u = real_to_user ( ix86->segs.ds, ix86->regs.si );
userptr_t cmd_u = real_to_user ( ix86->segs.es, ix86->regs.bx );
int file_len = strlen_user ( file_u, 0 );
int cmd_len = strlen_user ( cmd_u, 0 );
int file_len = strlen ( file_u );
int cmd_len = strlen ( cmd_u );
char file[file_len + 1];
char cmd[cmd_len + 1];
@@ -595,9 +595,9 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) {
shuffle ( ix86->segs.es, ix86->regs.di, ix86->regs.cx );
/* Copy initial register values to .text16 */
memcpy_user ( real_to_user ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ), 0,
real_to_user ( ix86->segs.ds, ix86->regs.si ), 0,
sizeof(syslinux_rm_regs) );
memcpy ( real_to_user ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ),
real_to_user ( ix86->segs.ds, ix86->regs.si ),
sizeof(syslinux_rm_regs) );
/* Load initial register values */
__asm__ __volatile__ (

View File

@@ -69,7 +69,7 @@ uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) {
userptr_t rm_stack;
rm_sp -= size;
rm_stack = real_to_user ( rm_ss, rm_sp );
memcpy_user ( rm_stack, 0, data, 0, size );
memcpy ( rm_stack, data, size );
return rm_sp;
};
@@ -83,7 +83,7 @@ uint16_t copy_user_to_rm_stack ( userptr_t data, size_t size ) {
void remove_user_from_rm_stack ( userptr_t data, size_t size ) {
if ( data ) {
userptr_t rm_stack = real_to_user ( rm_ss, rm_sp );
memcpy_user ( rm_stack, 0, data, 0, size );
memcpy ( rm_stack, data, size );
}
rm_sp += size;
};
@@ -432,10 +432,6 @@ PROVIDE_UACCESS_INLINE ( librm, phys_to_user );
PROVIDE_UACCESS_INLINE ( librm, user_to_phys );
PROVIDE_UACCESS_INLINE ( librm, virt_to_user );
PROVIDE_UACCESS_INLINE ( librm, user_to_virt );
PROVIDE_UACCESS_INLINE ( librm, memcpy_user );
PROVIDE_UACCESS_INLINE ( librm, memmove_user );
PROVIDE_UACCESS_INLINE ( librm, memset_user );
PROVIDE_UACCESS_INLINE ( librm, strlen_user );
PROVIDE_UACCESS_INLINE ( librm, memchr_user );
PROVIDE_IOMAP_INLINE ( pages, io_to_bus );
PROVIDE_IOMAP ( pages, ioremap, ioremap_pages );