From: Michael Brown Date: Mon, 21 Apr 2025 17:28:56 +0000 (+0100) Subject: [uaccess] Replace real_to_user() with real_to_virt() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=050df80bbc455efaf8c44ea00d55fd344d96f808;p=thirdparty%2Fipxe.git [uaccess] Replace real_to_user() with real_to_virt() Remove the intermediate concept of a user pointer from real address conversion, leaving real_to_virt() as the directly implemented function. Signed-off-by: Michael Brown --- diff --git a/src/arch/x86/image/bzimage.c b/src/arch/x86/image/bzimage.c index 0f373c1c8..b6a159847 100644 --- a/src/arch/x86/image/bzimage.c +++ b/src/arch/x86/image/bzimage.c @@ -158,7 +158,7 @@ static int bzimage_parse_header ( struct image *image, /* Calculate load address of real-mode portion */ bzimg->rm_kernel_seg = ( is_bzimage ? 0x1000 : 0x9000 ); - bzimg->rm_kernel = real_to_user ( bzimg->rm_kernel_seg, 0 ); + bzimg->rm_kernel = real_to_virt ( bzimg->rm_kernel_seg, 0 ); /* Allow space for the stack and heap */ bzimg->rm_memsz += BZI_STACK_SIZE; diff --git a/src/arch/x86/image/com32.c b/src/arch/x86/image/com32.c index a2b60987d..9a5793b7c 100644 --- a/src/arch/x86/image/com32.c +++ b/src/arch/x86/image/com32.c @@ -236,7 +236,7 @@ static int com32_prepare_bounce_buffer ( struct image * image ) { int rc; seg = COM32_BOUNCE_SEG; - seg_userptr = real_to_user ( seg, 0 ); + seg_userptr = real_to_virt ( seg, 0 ); /* Ensure the entire 64k segment is free */ memsz = 0xFFFF; diff --git a/src/arch/x86/image/comboot.c b/src/arch/x86/image/comboot.c index 8609eb0f7..b171ecb02 100644 --- a/src/arch/x86/image/comboot.c +++ b/src/arch/x86/image/comboot.c @@ -132,7 +132,7 @@ static void comboot_init_psp ( struct image * image, userptr_t seg_userptr ) { * @ret rc Return status code */ static int comboot_exec_loop ( struct image *image ) { - userptr_t seg_userptr = real_to_user ( COMBOOT_PSP_SEG, 0 ); + userptr_t seg_userptr = real_to_virt ( COMBOOT_PSP_SEG, 0 ); int state; state = rmsetjmp ( comboot_return ); @@ -251,7 +251,7 @@ static int comboot_prepare_segment ( struct image *image ) int rc; /* Load image in segment */ - seg_userptr = real_to_user ( COMBOOT_PSP_SEG, 0 ); + seg_userptr = real_to_virt ( COMBOOT_PSP_SEG, 0 ); /* Allow etra 0x100 bytes before image for PSP */ filesz = image->len + 0x100; diff --git a/src/arch/x86/image/nbi.c b/src/arch/x86/image/nbi.c index 1f72c1287..41c6e6ffd 100644 --- a/src/arch/x86/image/nbi.c +++ b/src/arch/x86/image/nbi.c @@ -159,7 +159,7 @@ static int nbi_process_segments ( struct image *image, int rc; /* Copy image header to target location */ - dest = real_to_user ( imgheader->location.segment, + dest = real_to_virt ( imgheader->location.segment, imgheader->location.offset ); filesz = memsz = NBI_HEADER_LENGTH; if ( ( rc = process ( image, offset, dest, filesz, memsz ) ) != 0 ) diff --git a/src/arch/x86/image/pxe_image.c b/src/arch/x86/image/pxe_image.c index bdce165ca..5472ea594 100644 --- a/src/arch/x86/image/pxe_image.c +++ b/src/arch/x86/image/pxe_image.c @@ -54,7 +54,7 @@ const char *pxe_cmdline; * @ret rc Return status code */ static int pxe_exec ( struct image *image ) { - userptr_t buffer = real_to_user ( 0, 0x7c00 ); + userptr_t buffer = real_to_virt ( 0, 0x7c00 ); struct net_device *netdev; int rc; diff --git a/src/arch/x86/image/sdi.c b/src/arch/x86/image/sdi.c index 5e22daeb3..40fab2a10 100644 --- a/src/arch/x86/image/sdi.c +++ b/src/arch/x86/image/sdi.c @@ -98,7 +98,7 @@ static int sdi_exec ( struct image *image ) { sdi.boot_size ); /* Copy boot code */ - memcpy ( real_to_user ( SDI_BOOT_SEG, SDI_BOOT_OFF ), + memcpy ( real_to_virt ( SDI_BOOT_SEG, SDI_BOOT_OFF ), ( image->data + sdi.boot_offset ), sdi.boot_size ); /* Jump to boot code */ diff --git a/src/arch/x86/include/libkir.h b/src/arch/x86/include/libkir.h index 1f5b13504..76766b6c2 100644 --- a/src/arch/x86/include/libkir.h +++ b/src/arch/x86/include/libkir.h @@ -194,7 +194,7 @@ copy_from_user ( void *dest, userptr_t buffer, off_t offset, size_t len ) { * @ret buffer User buffer */ static inline __attribute__ (( always_inline )) userptr_t -real_to_user ( unsigned int segment, unsigned int offset ) { +real_to_virt ( unsigned int segment, unsigned int offset ) { return ( ( segment << 16 ) | offset ); } @@ -210,7 +210,7 @@ real_to_user ( unsigned int segment, unsigned int offset ) { */ static inline __attribute__ (( always_inline )) userptr_t virt_to_user ( void * virtual ) { - return real_to_user ( rm_ds, ( intptr_t ) virtual ); + return real_to_virt ( rm_ds, ( intptr_t ) virtual ); } /* TEXT16_CODE: declare a fragment of code that resides in .text16 */ diff --git a/src/arch/x86/include/realmode.h b/src/arch/x86/include/realmode.h index 616db5eb9..0017b42c0 100644 --- a/src/arch/x86/include/realmode.h +++ b/src/arch/x86/include/realmode.h @@ -65,14 +65,14 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); */ /** - * Convert segment:offset address to user buffer + * Convert segment:offset address to virtual address * * @v segment Real-mode segment * @v offset Real-mode offset - * @ret buffer User buffer + * @ret virt Virtual address */ -static inline __always_inline userptr_t -real_to_user ( unsigned int segment, unsigned int offset ) { +static inline __always_inline void * +real_to_virt ( unsigned int segment, unsigned int offset ) { return ( phys_to_virt ( ( segment << 4 ) + offset ) ); } @@ -87,7 +87,7 @@ real_to_user ( unsigned int segment, unsigned int offset ) { static inline __always_inline void copy_to_real ( unsigned int dest_seg, unsigned int dest_off, void *src, size_t n ) { - copy_to_user ( real_to_user ( dest_seg, dest_off ), 0, src, n ); + copy_to_user ( real_to_virt ( dest_seg, dest_off ), 0, src, n ); } /** @@ -101,7 +101,7 @@ copy_to_real ( unsigned int dest_seg, unsigned int dest_off, static inline __always_inline void copy_from_real ( void *dest, unsigned int src_seg, unsigned int src_off, size_t n ) { - copy_from_user ( dest, real_to_user ( src_seg, src_off ), 0, n ); + copy_from_user ( dest, real_to_virt ( src_seg, src_off ), 0, n ); } /** diff --git a/src/arch/x86/interface/pcbios/bios_smbios.c b/src/arch/x86/interface/pcbios/bios_smbios.c index ab53d424b..e43c74bad 100644 --- a/src/arch/x86/interface/pcbios/bios_smbios.c +++ b/src/arch/x86/interface/pcbios/bios_smbios.c @@ -49,7 +49,7 @@ static int bios_find_smbios2 ( struct smbios *smbios ) { int rc; /* Scan through BIOS segment to find SMBIOS 32-bit entry point */ - if ( ( rc = find_smbios_entry ( real_to_user ( BIOS_SEG, 0 ), 0x10000, + if ( ( rc = find_smbios_entry ( real_to_virt ( BIOS_SEG, 0 ), 0x10000, &entry ) ) != 0 ) return rc; @@ -73,7 +73,7 @@ static int bios_find_smbios3 ( struct smbios *smbios ) { int rc; /* Scan through BIOS segment to find SMBIOS 64-bit entry point */ - if ( ( rc = find_smbios3_entry ( real_to_user ( BIOS_SEG, 0 ), 0x10000, + if ( ( rc = find_smbios3_entry ( real_to_virt ( BIOS_SEG, 0 ), 0x10000, &entry ) ) != 0 ) return rc; diff --git a/src/arch/x86/interface/pcbios/int13.c b/src/arch/x86/interface/pcbios/int13.c index d60f7c7cc..498676b70 100644 --- a/src/arch/x86/interface/pcbios/int13.c +++ b/src/arch/x86/interface/pcbios/int13.c @@ -549,7 +549,7 @@ static int int13_rw_sectors ( struct san_device *sandev, lba = ( ( ( ( cylinder * int13->heads ) + head ) * int13->sectors_per_track ) + sector - 1 ); count = ix86->regs.al; - buffer = real_to_user ( ix86->segs.es, ix86->regs.bx ); + buffer = real_to_virt ( ix86->segs.es, ix86->regs.bx ); DBGC2 ( sandev->drive, "C/H/S %d/%d/%d = LBA %08lx <-> %04x:%04x " "(count %d)\n", cylinder, head, sector, lba, ix86->segs.es, @@ -747,7 +747,7 @@ static int int13_extended_rw ( struct san_device *sandev, DBGC2 ( sandev->drive, "%08llx", ( ( unsigned long long ) addr.buffer_phys ) ); } else { - buffer = real_to_user ( addr.buffer.segment, + buffer = real_to_virt ( addr.buffer.segment, addr.buffer.offset ); DBGC2 ( sandev->drive, "%04x:%04x", addr.buffer.segment, addr.buffer.offset ); diff --git a/src/arch/x86/interface/pcbios/rsdp.c b/src/arch/x86/interface/pcbios/rsdp.c index 02c58c780..c2534c7f6 100644 --- a/src/arch/x86/interface/pcbios/rsdp.c +++ b/src/arch/x86/interface/pcbios/rsdp.c @@ -106,7 +106,7 @@ static userptr_t rsdp_find_rsdt ( void ) { /* Search EBDA */ get_real ( ebda_seg, BDA_SEG, BDA_EBDA ); if ( ebda_seg < RSDP_EBDA_END_SEG ) { - ebda = real_to_user ( ebda_seg, 0 ); + ebda = real_to_virt ( ebda_seg, 0 ); ebda_len = ( ( RSDP_EBDA_END_SEG - ebda_seg ) * 16 ); rsdt = rsdp_find_rsdt_range ( ebda, ebda_len ); if ( rsdt ) diff --git a/src/arch/x86/interface/pcbios/vesafb.c b/src/arch/x86/interface/pcbios/vesafb.c index 61609fa8c..cfa935126 100644 --- a/src/arch/x86/interface/pcbios/vesafb.c +++ b/src/arch/x86/interface/pcbios/vesafb.c @@ -243,7 +243,7 @@ static int vesafb_mode_list ( uint16_t **mode_numbers ) { controller->video_mode_ptr.offset ); /* Calculate length of mode list */ - video_mode_ptr = real_to_user ( controller->video_mode_ptr.segment, + video_mode_ptr = real_to_virt ( controller->video_mode_ptr.segment, controller->video_mode_ptr.offset ); len = 0; do { diff --git a/src/arch/x86/interface/pxe/pxe_call.c b/src/arch/x86/interface/pxe/pxe_call.c index 0e8d5c5a8..f88943fb2 100644 --- a/src/arch/x86/interface/pxe/pxe_call.c +++ b/src/arch/x86/interface/pxe/pxe_call.c @@ -144,7 +144,7 @@ static struct profiler * pxe_api_profiler ( unsigned int opcode ) { */ __asmcall void pxe_api_call ( struct i386_all_regs *ix86 ) { uint16_t opcode = ix86->regs.bx; - userptr_t uparams = real_to_user ( ix86->segs.es, ix86->regs.di ); + userptr_t uparams = real_to_virt ( ix86->segs.es, ix86->regs.di ); struct profiler *profiler = pxe_api_profiler ( opcode ); struct pxe_api_call *call; union u_PXENV_ANY params; @@ -195,7 +195,7 @@ int pxe_api_call_weak ( struct i386_all_regs *ix86 ) { * @ret ax PXE exit code */ __asmcall void pxe_loader_call ( struct i386_all_regs *ix86 ) { - userptr_t uparams = real_to_user ( ix86->segs.es, ix86->regs.di ); + userptr_t uparams = real_to_virt ( ix86->segs.es, ix86->regs.di ); struct s_UNDI_LOADER params; PXENV_EXIT_t ret; diff --git a/src/arch/x86/interface/pxe/pxe_file.c b/src/arch/x86/interface/pxe/pxe_file.c index 1235520de..64bc335f2 100644 --- a/src/arch/x86/interface/pxe/pxe_file.c +++ b/src/arch/x86/interface/pxe/pxe_file.c @@ -60,7 +60,7 @@ static PXENV_EXIT_t pxenv_file_open ( struct s_PXENV_FILE_OPEN *file_open ) { DBG ( "PXENV_FILE_OPEN" ); /* Copy name from external program, and open it */ - filename = real_to_user ( file_open->FileName.segment, + filename = real_to_virt ( file_open->FileName.segment, file_open->FileName.offset ); filename_len = strlen ( filename ); { @@ -155,7 +155,7 @@ static PXENV_EXIT_t pxenv_file_read ( struct s_PXENV_FILE_READ *file_read ) { file_read->Buffer.segment, file_read->Buffer.offset, file_read->BufferSize ); - buffer = real_to_user ( file_read->Buffer.segment, + buffer = real_to_virt ( file_read->Buffer.segment, file_read->Buffer.offset ); if ( ( len = read_user ( file_read->FileHandle, buffer, 0, file_read->BufferSize ) ) < 0 ) { @@ -217,7 +217,7 @@ static PXENV_EXIT_t pxenv_file_exec ( struct s_PXENV_FILE_EXEC *file_exec ) { DBG ( "PXENV_FILE_EXEC" ); /* Copy name from external program, and exec it */ - command = real_to_user ( file_exec->Command.segment, + command = real_to_virt ( file_exec->Command.segment, file_exec->Command.offset ); command_len = strlen ( command ); { @@ -259,7 +259,7 @@ pxenv_file_cmdline ( struct s_PXENV_FILE_CMDLINE *file_cmdline ) { file_cmdline->Buffer.segment, file_cmdline->Buffer.offset, file_cmdline->BufferSize, pxe_cmdline ); - buffer = real_to_user ( file_cmdline->Buffer.segment, + buffer = real_to_virt ( file_cmdline->Buffer.segment, file_cmdline->Buffer.offset ); len = file_cmdline->BufferSize; max_len = ( pxe_cmdline ? diff --git a/src/arch/x86/interface/pxe/pxe_preboot.c b/src/arch/x86/interface/pxe/pxe_preboot.c index 09e721b34..727d8e1ea 100644 --- a/src/arch/x86/interface/pxe/pxe_preboot.c +++ b/src/arch/x86/interface/pxe/pxe_preboot.c @@ -243,7 +243,7 @@ pxenv_get_cached_info ( struct s_PXENV_GET_CACHED_INFO *get_cached_info ) { len = sizeof ( *info ); if ( len < sizeof ( *info ) ) DBGC ( &pxe_netdev, " buffer may be too short" ); - buffer = real_to_user ( get_cached_info->Buffer.segment, + buffer = real_to_virt ( get_cached_info->Buffer.segment, get_cached_info->Buffer.offset ); copy_to_user ( buffer, 0, info, len ); get_cached_info->BufferSize = len; diff --git a/src/arch/x86/interface/pxe/pxe_tftp.c b/src/arch/x86/interface/pxe/pxe_tftp.c index 2c2eccca4..073414dce 100644 --- a/src/arch/x86/interface/pxe/pxe_tftp.c +++ b/src/arch/x86/interface/pxe/pxe_tftp.c @@ -378,7 +378,7 @@ static PXENV_EXIT_t pxenv_tftp_read ( struct s_PXENV_TFTP_READ *tftp_read ) { tftp_read->Buffer.segment, tftp_read->Buffer.offset ); /* Read single block into buffer */ - pxe_tftp.buffer = real_to_user ( tftp_read->Buffer.segment, + pxe_tftp.buffer = real_to_virt ( tftp_read->Buffer.segment, tftp_read->Buffer.offset ); pxe_tftp.size = pxe_tftp.blksize; pxe_tftp.start = pxe_tftp.offset; diff --git a/src/arch/x86/interface/pxe/pxe_udp.c b/src/arch/x86/interface/pxe/pxe_udp.c index a5d5eb77b..47abb7df4 100644 --- a/src/arch/x86/interface/pxe/pxe_udp.c +++ b/src/arch/x86/interface/pxe/pxe_udp.c @@ -328,7 +328,7 @@ pxenv_udp_write ( struct s_PXENV_UDP_WRITE *pxenv_udp_write ) { pxenv_udp_write->Status = PXENV_STATUS_OUT_OF_RESOURCES; return PXENV_EXIT_FAILURE; } - buffer = real_to_user ( pxenv_udp_write->buffer.segment, + buffer = real_to_virt ( pxenv_udp_write->buffer.segment, pxenv_udp_write->buffer.offset ); copy_from_user ( iob_put ( iobuf, len ), buffer, 0, len ); @@ -438,7 +438,7 @@ static PXENV_EXIT_t pxenv_udp_read ( struct s_PXENV_UDP_READ *pxenv_udp_read ) { } /* Copy packet to buffer and record length */ - buffer = real_to_user ( pxenv_udp_read->buffer.segment, + buffer = real_to_virt ( pxenv_udp_read->buffer.segment, pxenv_udp_read->buffer.offset ); len = iob_len ( iobuf ); if ( len > pxenv_udp_read->buffer_size ) diff --git a/src/arch/x86/interface/syslinux/comboot_call.c b/src/arch/x86/interface/syslinux/comboot_call.c index d7e923b70..d8c245757 100644 --- a/src/arch/x86/interface/syslinux/comboot_call.c +++ b/src/arch/x86/interface/syslinux/comboot_call.c @@ -90,7 +90,7 @@ static uint16_t comboot_graphics_mode = 0; static void print_user_string ( unsigned int segment, unsigned int offset, char terminator ) { int i = 0; char c; - userptr_t str = real_to_user ( segment, offset ); + userptr_t str = real_to_virt ( segment, offset ); for ( ; ; ) { copy_from_user ( &c, str, i, 1 ); if ( c == terminator ) break; @@ -109,7 +109,7 @@ static void shuffle ( unsigned int list_segment, unsigned int list_offset, unsig unsigned int i; /* Copy shuffle descriptor list so it doesn't get overwritten */ - copy_from_user ( shuf, real_to_user ( list_segment, list_offset ), 0, + copy_from_user ( shuf, real_to_virt ( list_segment, list_offset ), 0, count * sizeof( comboot_shuffle_descriptor ) ); /* Do the copies */ @@ -346,7 +346,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 ); + userptr_t cmd_u = real_to_virt ( ix86->segs.es, ix86->regs.bx ); int len = strlen ( cmd_u ); char cmd[len + 1]; copy_from_user ( cmd, cmd_u, 0, len + 1 ); @@ -370,7 +370,7 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) { case 0x0006: /* Open file */ { int fd; - userptr_t file_u = real_to_user ( ix86->segs.es, ix86->regs.si ); + userptr_t file_u = real_to_virt ( ix86->segs.es, ix86->regs.si ); int len = strlen ( file_u ); char file[len + 1]; @@ -410,7 +410,7 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) { int len = ix86->regs.cx * COMBOOT_FILE_BLOCKSZ; int rc; fd_set fds; - userptr_t buf = real_to_user ( ix86->segs.es, ix86->regs.bx ); + userptr_t buf = real_to_virt ( ix86->segs.es, ix86->regs.bx ); /* Wait for data ready to read */ FD_ZERO ( &fds ); @@ -483,7 +483,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 ); + userptr_t hostname_u = real_to_virt ( ix86->segs.es, ix86->regs.bx ); int len = strlen ( hostname_u ); char hostname[len]; struct in_addr addr; @@ -549,8 +549,8 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) { case 0x0016: /* Run kernel image */ { - 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 ); + userptr_t file_u = real_to_virt ( ix86->segs.ds, ix86->regs.si ); + userptr_t cmd_u = real_to_virt ( ix86->segs.es, ix86->regs.bx ); int file_len = strlen ( file_u ); int cmd_len = strlen ( cmd_u ); char file[file_len + 1]; @@ -595,8 +595,8 @@ 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 ( real_to_user ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ), - real_to_user ( ix86->segs.ds, ix86->regs.si ), + memcpy ( real_to_virt ( rm_cs, (unsigned) __from_text16 ( &comboot_initial_regs ) ), + real_to_virt ( ix86->segs.ds, ix86->regs.si ), sizeof(syslinux_rm_regs) ); /* Load initial register values */ diff --git a/src/arch/x86/transitions/librm_mgmt.c b/src/arch/x86/transitions/librm_mgmt.c index fbc653969..e0679f0ff 100644 --- a/src/arch/x86/transitions/librm_mgmt.c +++ b/src/arch/x86/transitions/librm_mgmt.c @@ -68,7 +68,7 @@ static struct profiler other_irq_profiler __profiler = { .name = "irq.other" }; 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 ); + rm_stack = real_to_virt ( rm_ss, rm_sp ); memcpy ( rm_stack, data, size ); return rm_sp; }; @@ -82,7 +82,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 ); + userptr_t rm_stack = real_to_virt ( rm_ss, rm_sp ); memcpy ( rm_stack, data, size ); } rm_sp += size;