[comboot] Remove userptr_t from COMBOOT API implementation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-04-28 22:50:23 +01:00
parent ef97119589
commit f001e61a68

View File

@@ -88,14 +88,9 @@ static uint16_t comboot_graphics_mode = 0;
* Print a string with a particular terminator * Print a string with a particular terminator
*/ */
static void print_user_string ( unsigned int segment, unsigned int offset, char terminator ) { static void print_user_string ( unsigned int segment, unsigned int offset, char terminator ) {
int i = 0; char *c;
char c; for ( c = real_to_virt ( segment, offset ) ; *c != terminator ; c++ ) {
userptr_t str = real_to_virt ( segment, offset ); putchar ( *c );
for ( ; ; ) {
copy_from_user ( &c, str, i, 1 );
if ( c == terminator ) break;
putchar ( c );
i++;
} }
} }
@@ -109,26 +104,26 @@ static void shuffle ( unsigned int list_segment, unsigned int list_offset, unsig
unsigned int i; unsigned int i;
/* Copy shuffle descriptor list so it doesn't get overwritten */ /* Copy shuffle descriptor list so it doesn't get overwritten */
copy_from_user ( shuf, real_to_virt ( list_segment, list_offset ), 0, memcpy ( shuf, real_to_virt ( list_segment, list_offset ),
count * sizeof( comboot_shuffle_descriptor ) ); count * sizeof( comboot_shuffle_descriptor ) );
/* Do the copies */ /* Do the copies */
for ( i = 0; i < count; i++ ) { for ( i = 0; i < count; i++ ) {
userptr_t src_u = phys_to_virt ( shuf[ i ].src ); const void *src = phys_to_virt ( shuf[ i ].src );
userptr_t dest_u = phys_to_virt ( shuf[ i ].dest ); void *dest = phys_to_virt ( shuf[ i ].dest );
if ( shuf[ i ].src == 0xFFFFFFFF ) { if ( shuf[ i ].src == 0xFFFFFFFF ) {
/* Fill with 0 instead of copying */ /* Fill with 0 instead of copying */
memset ( dest_u, 0, shuf[ i ].len ); memset ( dest, 0, shuf[ i ].len );
} else if ( shuf[ i ].dest == 0xFFFFFFFF ) { } else if ( shuf[ i ].dest == 0xFFFFFFFF ) {
/* Copy new list of descriptors */ /* Copy new list of descriptors */
count = shuf[ i ].len / sizeof( comboot_shuffle_descriptor ); count = shuf[ i ].len / sizeof( comboot_shuffle_descriptor );
assert ( count <= COMBOOT_MAX_SHUFFLE_DESCRIPTORS ); assert ( count <= COMBOOT_MAX_SHUFFLE_DESCRIPTORS );
copy_from_user ( shuf, src_u, 0, shuf[ i ].len ); memcpy ( shuf, src, shuf[ i ].len );
i = -1; i = -1;
} else { } else {
/* Regular copy */ /* Regular copy */
memmove ( dest_u, src_u, shuf[ i ].len ); memmove ( dest, src, shuf[ i ].len );
} }
} }
} }
@@ -164,7 +159,7 @@ void comboot_force_text_mode ( void ) {
/** /**
* Fetch kernel and optional initrd * Fetch kernel and optional initrd
*/ */
static int comboot_fetch_kernel ( char *kernel_file, char *cmdline ) { static int comboot_fetch_kernel ( const char *kernel_file, char *cmdline ) {
struct image *kernel; struct image *kernel;
struct image *initrd; struct image *initrd;
char *initrd_file; char *initrd_file;
@@ -346,10 +341,8 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) {
case 0x0003: /* Run command */ case 0x0003: /* Run command */
{ {
userptr_t cmd_u = real_to_virt ( ix86->segs.es, ix86->regs.bx ); const char *cmd = real_to_virt ( ix86->segs.es,
int len = strlen ( cmd_u ); ix86->regs.bx );
char cmd[len + 1];
copy_from_user ( cmd, cmd_u, 0, len + 1 );
DBG ( "COMBOOT: executing command '%s'\n", cmd ); DBG ( "COMBOOT: executing command '%s'\n", cmd );
system ( cmd ); system ( cmd );
DBG ( "COMBOOT: exiting after executing command...\n" ); DBG ( "COMBOOT: exiting after executing command...\n" );
@@ -370,11 +363,8 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) {
case 0x0006: /* Open file */ case 0x0006: /* Open file */
{ {
int fd; int fd;
userptr_t file_u = real_to_virt ( ix86->segs.es, ix86->regs.si ); const char *file = real_to_virt ( ix86->segs.es,
int len = strlen ( file_u ); ix86->regs.si );
char file[len + 1];
copy_from_user ( file, file_u, 0, len + 1 );
if ( file[0] == '\0' ) { if ( file[0] == '\0' ) {
DBG ( "COMBOOT: attempted open with empty file name\n" ); DBG ( "COMBOOT: attempted open with empty file name\n" );
@@ -484,13 +474,10 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) {
case 0x0010: /* Resolve hostname */ case 0x0010: /* Resolve hostname */
{ {
userptr_t hostname_u = real_to_virt ( ix86->segs.es, ix86->regs.bx ); const char *hostname = real_to_virt ( ix86->segs.es,
int len = strlen ( hostname_u ); ix86->regs.bx );
char hostname[len];
struct in_addr addr; struct in_addr addr;
copy_from_user ( hostname, hostname_u, 0, len + 1 );
/* TODO: /* TODO:
* "If the hostname does not contain a dot (.), the * "If the hostname does not contain a dot (.), the
* local domain name is automatically appended." * local domain name is automatically appended."
@@ -550,15 +537,10 @@ static __asmcall __used void int22 ( struct i386_all_regs *ix86 ) {
case 0x0016: /* Run kernel image */ case 0x0016: /* Run kernel image */
{ {
userptr_t file_u = real_to_virt ( ix86->segs.ds, ix86->regs.si ); const char *file = real_to_virt ( ix86->segs.ds,
userptr_t cmd_u = real_to_virt ( ix86->segs.es, ix86->regs.bx ); ix86->regs.si );
int file_len = strlen ( file_u ); char *cmd = real_to_virt ( ix86->segs.es,
int cmd_len = strlen ( cmd_u ); ix86->regs.bx );
char file[file_len + 1];
char cmd[cmd_len + 1];
copy_from_user ( file, file_u, 0, file_len + 1 );
copy_from_user ( cmd, cmd_u, 0, cmd_len + 1 );
DBG ( "COMBOOT: run kernel %s %s\n", file, cmd ); DBG ( "COMBOOT: run kernel %s %s\n", file, cmd );
comboot_fetch_kernel ( file, cmd ); comboot_fetch_kernel ( file, cmd );