From f1c1b3fbf9d592ece99cec89d57d4f776ac68f92 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Fri, 22 Mar 2024 20:10:55 -0500 Subject: [PATCH 1/4] refactor: [loadfile] add/adjust copyright header --- iop/system/loadfile/Makefile | 2 +- iop/system/loadfile/src/eeelfloader.c | 2 +- iop/system/loadfile/src/eeelfloader.h | 9 +++++++++ iop/system/loadfile/src/irx_imports.h | 2 +- iop/system/loadfile/src/loadfile.c | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/iop/system/loadfile/Makefile b/iop/system/loadfile/Makefile index 152ae514719..33713623a34 100644 --- a/iop/system/loadfile/Makefile +++ b/iop/system/loadfile/Makefile @@ -2,7 +2,7 @@ # ____| | ____| | | |____| # | ___| |____ ___| ____| | \ PS2DEV Open Source Project. #----------------------------------------------------------------------- -# Copyright 2001-2004, ps2dev - http://www.ps2dev.org +# Copyright ps2dev - http://www.ps2dev.org # Licenced under Academic Free License version 2.0 # Review ps2sdk README & LICENSE files for further details. diff --git a/iop/system/loadfile/src/eeelfloader.c b/iop/system/loadfile/src/eeelfloader.c index 530b1cdd28d..3b605ca7e03 100644 --- a/iop/system/loadfile/src/eeelfloader.c +++ b/iop/system/loadfile/src/eeelfloader.c @@ -3,7 +3,7 @@ # ____| | ____| | | |____| # | ___| |____ ___| ____| | \ PS2DEV Open Source Project. #----------------------------------------------------------------------- -# Copyright 2001-2009, ps2dev - http://www.ps2dev.org +# Copyright ps2dev - http://www.ps2dev.org # Licenced under Academic Free License version 2.0 # Review ps2sdk README & LICENSE files for further details. */ diff --git a/iop/system/loadfile/src/eeelfloader.h b/iop/system/loadfile/src/eeelfloader.h index e3912f843d8..61374c31eaf 100644 --- a/iop/system/loadfile/src/eeelfloader.h +++ b/iop/system/loadfile/src/eeelfloader.h @@ -1,3 +1,12 @@ +/* +# _____ ___ ____ ___ ____ +# ____| | ____| | | |____| +# | ___| |____ ___| ____| | \ PS2DEV Open Source Project. +#----------------------------------------------------------------------- +# Copyright ps2dev - http://www.ps2dev.org +# Licenced under Academic Free License version 2.0 +# Review ps2sdk README & LICENSE files for further details. +*/ #ifndef __EEELFLOADER_H__ #define __EEELFLOADER_H__ diff --git a/iop/system/loadfile/src/irx_imports.h b/iop/system/loadfile/src/irx_imports.h index 683aa2039e6..aec772312ef 100644 --- a/iop/system/loadfile/src/irx_imports.h +++ b/iop/system/loadfile/src/irx_imports.h @@ -3,7 +3,7 @@ # ____| | ____| | | |____| # | ___| |____ ___| ____| | \ PS2DEV Open Source Project. #----------------------------------------------------------------------- -# Copyright 2001-2009, ps2dev - http://www.ps2dev.org +# Copyright ps2dev - http://www.ps2dev.org # Licenced under Academic Free License version 2.0 # Review ps2sdk README & LICENSE files for further details. # diff --git a/iop/system/loadfile/src/loadfile.c b/iop/system/loadfile/src/loadfile.c index a08188486d8..8db17370cc7 100644 --- a/iop/system/loadfile/src/loadfile.c +++ b/iop/system/loadfile/src/loadfile.c @@ -3,7 +3,7 @@ # ____| | ____| | | |____| # | ___| |____ ___| ____| | \ PS2DEV Open Source Project. #----------------------------------------------------------------------- -# Copyright 2001-2009, ps2dev - http://www.ps2dev.org +# Copyright ps2dev - http://www.ps2dev.org # Licenced under Academic Free License version 2.0 # Review ps2sdk README & LICENSE files for further details. */ From abb33e3470149402b77a065deb2908d19b46a1ee Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Fri, 22 Mar 2024 20:11:55 -0500 Subject: [PATCH 2/4] refactor: [loadfile] format --- iop/system/loadfile/src/eeelfloader.c | 1174 +++++++++++++------------ iop/system/loadfile/src/eeelfloader.h | 6 +- iop/system/loadfile/src/loadfile.c | 347 ++++---- 3 files changed, 814 insertions(+), 713 deletions(-) diff --git a/iop/system/loadfile/src/eeelfloader.c b/iop/system/loadfile/src/eeelfloader.c index 3b605ca7e03..71a72fbee74 100644 --- a/iop/system/loadfile/src/eeelfloader.c +++ b/iop/system/loadfile/src/eeelfloader.c @@ -15,628 +15,698 @@ // It has been changed to be basically a stack allocator static void *heap_buffer_base = NULL; -static void *heap_buffer = NULL; -static void *heap_buffer_end = NULL; +static void *heap_buffer = NULL; +static void *heap_buffer_end = NULL; static int *allocate_heap_buffer(unsigned int lower_bound, unsigned int upper_bound) { - unsigned int v1; - - v1 = upper_bound; - // Align to 4 bytes - if ((v1 & 3) != 0) { - v1 += (4 - (v1 & 3)); - } - CpuDisableIntr(); - heap_buffer_base = AllocSysMemory(ALLOC_LAST, v1, NULL); - CpuEnableIntr(); - if (heap_buffer_base != NULL) { - heap_buffer = heap_buffer_base; - heap_buffer_end = &(((u8 *)heap_buffer_base)[v1]); - return heap_buffer_base; - } - printf("memory allocation failed.\n"); - return NULL; + unsigned int v1; + + v1 = upper_bound; + // Align to 4 bytes + if ( (v1 & 3) != 0 ) + { + v1 += (4 - (v1 & 3)); + } + CpuDisableIntr(); + heap_buffer_base = AllocSysMemory(ALLOC_LAST, v1, NULL); + CpuEnableIntr(); + if ( heap_buffer_base != NULL ) + { + heap_buffer = heap_buffer_base; + heap_buffer_end = &(((u8 *)heap_buffer_base)[v1]); + return heap_buffer_base; + } + printf("memory allocation failed.\n"); + return NULL; } static void *elf_load_alloc_buffer_from_heap(u32 alloc_size) { - u32 v1; - - v1 = alloc_size; - // Align to 4 bytes - if ((alloc_size & 3) != 0) { - v1 += (4 - (alloc_size & 3)); - } - // Validity check... - { - u8 *new_ptr; - - new_ptr = heap_buffer; - new_ptr += 4; - new_ptr += v1; - if ((u8 *)new_ptr > (u8 *)heap_buffer_end) { - return NULL; - } - } - // Do the allocation - { - u8 *new_ptr; - u8 *ret_ptr; - - new_ptr = heap_buffer; - - ((u32 *)new_ptr)[0] = v1; - new_ptr += sizeof(v1); - - ret_ptr = new_ptr; - new_ptr += v1; - - - heap_buffer = new_ptr; - return ret_ptr; - } + u32 v1; + + v1 = alloc_size; + // Align to 4 bytes + if ( (alloc_size & 3) != 0 ) + { + v1 += (4 - (alloc_size & 3)); + } + // Validity check... + { + u8 *new_ptr; + + new_ptr = heap_buffer; + new_ptr += 4; + new_ptr += v1; + if ( (u8 *)new_ptr > (u8 *)heap_buffer_end ) + { + return NULL; + } + } + // Do the allocation + { + u8 *new_ptr; + u8 *ret_ptr; + + new_ptr = heap_buffer; + + ((u32 *)new_ptr)[0] = v1; + new_ptr += sizeof(v1); + + ret_ptr = new_ptr; + new_ptr += v1; + + heap_buffer = new_ptr; + return ret_ptr; + } } static void elf_load_dealloc_buffer_from_heap(void *alloc_memory) { - u32 chunk_size; - // Check if NULL - if (alloc_memory == NULL) { - return; - } - // Check if in range of heap buffer - if ((((u8 *)alloc_memory) - 4 < ((u8 *)heap_buffer_base)) || ((u8 *)alloc_memory) >= ((u8 *)heap_buffer_end)) { - return; - } - // Get size - chunk_size = *((u32 *)(((u8 *)alloc_memory) - 4)); - // Check if this is the current heap position - if (((u8 *)alloc_memory) + chunk_size != ((u8 *)heap_buffer)) { - return; - } - // Do the deallocation - heap_buffer = ((u8 *)alloc_memory) - 4; + u32 chunk_size; + // Check if NULL + if ( alloc_memory == NULL ) + { + return; + } + // Check if in range of heap buffer + if ( (((u8 *)alloc_memory) - 4 < ((u8 *)heap_buffer_base)) || ((u8 *)alloc_memory) >= ((u8 *)heap_buffer_end) ) + { + return; + } + // Get size + chunk_size = *((u32 *)(((u8 *)alloc_memory) - 4)); + // Check if this is the current heap position + if ( ((u8 *)alloc_memory) + chunk_size != ((u8 *)heap_buffer) ) + { + return; + } + // Do the deallocation + heap_buffer = ((u8 *)alloc_memory) - 4; } typedef struct loadfile_elf_program_header_size_offset_ { - int index_of_ph_contents; - int offset_of_ph_contents; + int index_of_ph_contents; + int offset_of_ph_contents; } loadfile_elf_program_header_size_offset_t; static int check_elf_header(const loadfile_elf32_ehdr_t **header) { - const loadfile_elf32_ehdr_t *v1; - - v1 = *header; - if (v1->e_ident[0] != '\x7F') { - return -1; - } - if (v1->e_ident[1] != 'E') { - return -1; - } - if (v1->e_ident[2] != 'L') { - return -1; - } - if (v1->e_ident[3] != 'F') { - return -1; - } - return 0; + const loadfile_elf32_ehdr_t *v1; + + v1 = *header; + if ( v1->e_ident[0] != '\x7F' ) + { + return -1; + } + if ( v1->e_ident[1] != 'E' ) + { + return -1; + } + if ( v1->e_ident[2] != 'L' ) + { + return -1; + } + if ( v1->e_ident[3] != 'F' ) + { + return -1; + } + return 0; } static int check_elf_architecture(const loadfile_file_load_handler_struct_t *flhs) { - if (flhs->elf_header.e_ident[4] != 1) { - return -1; - } - if (flhs->elf_header.e_ident[5] != 1) { - return -2; - } - if (flhs->elf_header.e_type != 2) { - return -3; - } - if (flhs->elf_header.e_machine != 8) { - return -4; - } - if (flhs->elf_header.e_ehsize != 52) { - return -5; - } - if (flhs->elf_header.e_phentsize != 32) { - return -6; - } - if (!flhs->elf_header.e_shnum) { - return 1; - } - if (flhs->elf_header.e_shentsize != 40) { - return -7; - } - return 1; + if ( flhs->elf_header.e_ident[4] != 1 ) + { + return -1; + } + if ( flhs->elf_header.e_ident[5] != 1 ) + { + return -2; + } + if ( flhs->elf_header.e_type != 2 ) + { + return -3; + } + if ( flhs->elf_header.e_machine != 8 ) + { + return -4; + } + if ( flhs->elf_header.e_ehsize != 52 ) + { + return -5; + } + if ( flhs->elf_header.e_phentsize != 32 ) + { + return -6; + } + if ( !flhs->elf_header.e_shnum ) + { + return 1; + } + if ( flhs->elf_header.e_shentsize != 40 ) + { + return -7; + } + return 1; } -static int check_valid_ee_elf(loadfile_allocate_handler_struct_t *allocate_info, loadfile_file_load_handler_struct_t *flhs) +static int +check_valid_ee_elf(loadfile_allocate_handler_struct_t *allocate_info, loadfile_file_load_handler_struct_t *flhs) { - const loadfile_elf32_ehdr_t **v3; - int v4; - loadfile_elf32_ehdr_t *p_elf_header; - - v3 = (const loadfile_elf32_ehdr_t **)&allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; - v4 = check_elf_header(v3); - p_elf_header = &flhs->elf_header; - if (v4 < 0) { - printf("File is not ELF format(%d)\n", v4); - return KE_ILLEGAL_OBJECT; - } - memcpy(p_elf_header, *v3, sizeof(*p_elf_header)); - v4 = check_elf_architecture(flhs); - if (v4 < 0) { - printf("File is not for target architecture(%d)\n", v4); - return KE_ILLEGAL_OBJECT; - } - return 0; + const loadfile_elf32_ehdr_t **v3; + int v4; + loadfile_elf32_ehdr_t *p_elf_header; + + v3 = (const loadfile_elf32_ehdr_t **)&allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; + v4 = check_elf_header(v3); + p_elf_header = &flhs->elf_header; + if ( v4 < 0 ) + { + printf("File is not ELF format(%d)\n", v4); + return KE_ILLEGAL_OBJECT; + } + memcpy(p_elf_header, *v3, sizeof(*p_elf_header)); + v4 = check_elf_architecture(flhs); + if ( v4 < 0 ) + { + printf("File is not for target architecture(%d)\n", v4); + return KE_ILLEGAL_OBJECT; + } + return 0; } -static int elf_get_program_header(loadfile_allocate_handler_struct_t *allocate_info, loadfile_file_load_handler_struct_t *flhs) +static int +elf_get_program_header(loadfile_allocate_handler_struct_t *allocate_info, loadfile_file_load_handler_struct_t *flhs) { - int v4; - u8 *alloc_buffer_from_heap; - - v4 = flhs->elf_header.e_phentsize * flhs->elf_header.e_phnum; - alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(v4); - flhs->program_header = (loadfile_elf32_phdr_t *)alloc_buffer_from_heap; - if (alloc_buffer_from_heap == NULL) { - return KE_NO_MEMORY; - } - memcpy(alloc_buffer_from_heap, &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index].buffer_base[flhs->elf_header.e_phoff], v4); - return 0; + int v4; + u8 *alloc_buffer_from_heap; + + v4 = flhs->elf_header.e_phentsize * flhs->elf_header.e_phnum; + alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(v4); + flhs->program_header = (loadfile_elf32_phdr_t *)alloc_buffer_from_heap; + if ( alloc_buffer_from_heap == NULL ) + { + return KE_NO_MEMORY; + } + memcpy( + alloc_buffer_from_heap, + &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index].buffer_base[flhs->elf_header.e_phoff], + v4); + return 0; } static int elf_read_header_section_headers(loadfile_file_load_handler_struct_t *flhs) { - int v2; - u8 *alloc_buffer_from_heap; - - lseek(flhs->fd, flhs->elf_header.e_shoff, 0); - v2 = flhs->elf_header.e_shentsize * flhs->elf_header.e_shnum; - alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(v2); - flhs->section_headers = (loadfile_elf32_shdr_t *)alloc_buffer_from_heap; - if (alloc_buffer_from_heap == NULL) { - return KE_NO_MEMORY; - } - if (read(flhs->fd, alloc_buffer_from_heap, v2) != v2) { - elf_load_dealloc_buffer_from_heap(flhs->section_headers); - flhs->section_headers = 0; - return KE_FILEERR; - } - return 0; + int v2; + u8 *alloc_buffer_from_heap; + + lseek(flhs->fd, flhs->elf_header.e_shoff, 0); + v2 = flhs->elf_header.e_shentsize * flhs->elf_header.e_shnum; + alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(v2); + flhs->section_headers = (loadfile_elf32_shdr_t *)alloc_buffer_from_heap; + if ( alloc_buffer_from_heap == NULL ) + { + return KE_NO_MEMORY; + } + if ( read(flhs->fd, alloc_buffer_from_heap, v2) != v2 ) + { + elf_load_dealloc_buffer_from_heap(flhs->section_headers); + flhs->section_headers = 0; + return KE_FILEERR; + } + return 0; } static int elf_read_section_contents(loadfile_file_load_handler_struct_t *flhs) { - loadfile_elf32_shdr_t *v2; - u8 *alloc_buffer_from_heap; - - v2 = &flhs->section_headers[flhs->elf_header.e_shstrndx]; - if (v2->sh_type != 3 || v2->sh_flags != 0 || v2->sh_link != 0 || v2->sh_info != 0) { - flhs->section_contents = 0; - return KE_ILLEGAL_OBJECT; - } - alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(v2->sh_size); - flhs->section_contents = alloc_buffer_from_heap; - if (alloc_buffer_from_heap == NULL) { - return KE_NO_MEMORY; - } - lseek(flhs->fd, v2->sh_offset, 0); - if ((u32)(read(flhs->fd, flhs->section_contents, v2->sh_size)) != v2->sh_size) { - elf_load_dealloc_buffer_from_heap(flhs->section_contents); - flhs->section_contents = 0; - return KE_FILEERR; - } - return 0; + loadfile_elf32_shdr_t *v2; + u8 *alloc_buffer_from_heap; + + v2 = &flhs->section_headers[flhs->elf_header.e_shstrndx]; + if ( v2->sh_type != 3 || v2->sh_flags != 0 || v2->sh_link != 0 || v2->sh_info != 0 ) + { + flhs->section_contents = 0; + return KE_ILLEGAL_OBJECT; + } + alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(v2->sh_size); + flhs->section_contents = alloc_buffer_from_heap; + if ( alloc_buffer_from_heap == NULL ) + { + return KE_NO_MEMORY; + } + lseek(flhs->fd, v2->sh_offset, 0); + if ( (u32)(read(flhs->fd, flhs->section_contents, v2->sh_size)) != v2->sh_size ) + { + elf_load_dealloc_buffer_from_heap(flhs->section_contents); + flhs->section_contents = 0; + return KE_FILEERR; + } + return 0; } static void sort_ph_contents(int ph_count, loadfile_elf_program_header_size_offset_t *ph_size_offset_data) { - if (ph_count > 1) { - int v2; - loadfile_elf_program_header_size_offset_t *v4; - - v2 = 1; - v4 = ph_size_offset_data + 1; - do { - int v5; - loadfile_elf_program_header_size_offset_t *v9; - int index_of_ph_contents; - unsigned int offset_of_ph_contents; - - index_of_ph_contents = v4->index_of_ph_contents; - offset_of_ph_contents = v4->offset_of_ph_contents; - v5 = v2 - 1; - if (v5 >= 0) { - loadfile_elf_program_header_size_offset_t *v6; - - v6 = &ph_size_offset_data[v5]; - for (;;) { - if (offset_of_ph_contents >= (u32)(v6->offset_of_ph_contents)) - break; - v6[1].index_of_ph_contents = v6->index_of_ph_contents; - v6[1].offset_of_ph_contents = v6->offset_of_ph_contents; - v5 -= 1; - v6 -= 1; - if (v5 < 0) { - break; - } - } - } - v9 = &ph_size_offset_data[v5]; - v9[1].index_of_ph_contents = index_of_ph_contents; - v9[1].offset_of_ph_contents = offset_of_ph_contents; - v2 += 1; - v4 += 1; - } while (v2 < ph_count); - } + if ( ph_count > 1 ) + { + int v2; + loadfile_elf_program_header_size_offset_t *v4; + + v2 = 1; + v4 = ph_size_offset_data + 1; + do + { + int v5; + loadfile_elf_program_header_size_offset_t *v9; + int index_of_ph_contents; + unsigned int offset_of_ph_contents; + + index_of_ph_contents = v4->index_of_ph_contents; + offset_of_ph_contents = v4->offset_of_ph_contents; + v5 = v2 - 1; + if ( v5 >= 0 ) + { + loadfile_elf_program_header_size_offset_t *v6; + + v6 = &ph_size_offset_data[v5]; + for ( ;; ) + { + if ( offset_of_ph_contents >= (u32)(v6->offset_of_ph_contents) ) + break; + v6[1].index_of_ph_contents = v6->index_of_ph_contents; + v6[1].offset_of_ph_contents = v6->offset_of_ph_contents; + v5 -= 1; + v6 -= 1; + if ( v5 < 0 ) + { + break; + } + } + } + v9 = &ph_size_offset_data[v5]; + v9[1].index_of_ph_contents = index_of_ph_contents; + v9[1].offset_of_ph_contents = offset_of_ph_contents; + v2 += 1; + v4 += 1; + } while ( v2 < ph_count ); + } } static int fileio_reader_function(int fd, loadfile_allocate_handler_struct_t *allocate_info, void *userdata) { - int read_buffer_offset; - loadfile_ee_elf_ringbuffer_content_t *v5; - int v7; - - read_buffer_offset = allocate_info->read_buffer_offset; - v5 = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; - v5->buffer_offset = read_buffer_offset; - v7 = read(fd, v5->buffer_base, allocate_info->read_buffer_length); - v5->buffer_length = v7; - allocate_info->read_buffer_offset += v7; - return 0; + int read_buffer_offset; + loadfile_ee_elf_ringbuffer_content_t *v5; + int v7; + + read_buffer_offset = allocate_info->read_buffer_offset; + v5 = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; + v5->buffer_offset = read_buffer_offset; + v7 = read(fd, v5->buffer_base, allocate_info->read_buffer_length); + v5->buffer_length = v7; + allocate_info->read_buffer_offset += v7; + return 0; } -static int elf_load_proc(loadfile_allocate_handler_struct_t *allocate_info, loadfile_file_load_handler_struct_t *flhs, void *read_callback_userdata, loadfile_read_chunk_callback_t read_callback) +static int elf_load_proc( + loadfile_allocate_handler_struct_t *allocate_info, + loadfile_file_load_handler_struct_t *flhs, + void *read_callback_userdata, + loadfile_read_chunk_callback_t read_callback) { - int v12; - int v13; - int index_of_ph_contents; - loadfile_elf32_phdr_t *v15; - unsigned int p_filesz; - loadfile_ee_elf_ringbuffer_content_t *v17; - unsigned int v18; - unsigned int v20; - int v21; - int v23; - int v24; - SifDmaTransfer_t v25; - loadfile_elf_program_header_size_offset_t v26[32]; - int state; - int ph_count; - - if (flhs->program_header == NULL) { - return KE_ILLEGAL_OBJECT; - } - ph_count = 0; - { - int i; - - for (i = 0; i < flhs->elf_header.e_phnum; i += 1) { - loadfile_elf32_phdr_t *v10; - - v10 = &flhs->program_header[i]; - if (v10->p_type == 1 && v10->p_filesz) { - v26[ph_count].index_of_ph_contents = i; - v26[ph_count].offset_of_ph_contents = v10->p_offset; - ph_count += 1; - } - } - } - sort_ph_contents(ph_count, v26); - v12 = 0; - printf("Input ELF format filename = %s\n", flhs->filename); - v13 = 0; - if (ph_count <= 0) { - LABEL_21: - printf("Loaded, %s\n", flhs->filename); - return 0; - } else { - for (;;) { - index_of_ph_contents = v26[v12].index_of_ph_contents; - v15 = &flhs->program_header[index_of_ph_contents]; - p_filesz = v15->p_filesz; - printf("%d %08x %08x ", index_of_ph_contents, v15->p_vaddr, p_filesz); - if (p_filesz) - break; - LABEL_20: - v12 += 1; - printf("\n"); - v13 = 0; - if (v12 >= ph_count) - goto LABEL_21; - } - for (;;) { - printf("."); - v17 = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; - while (sceSifDmaStat(v17->dma_handle) >= 0) - ; - v18 = v15->p_offset + v13; - if (v18 >= (u32)(allocate_info->read_buffer_offset)) - break; - LABEL_16: - v20 = v18 - v17->buffer_offset; - v21 = p_filesz; - if (v17->buffer_length - v20 < p_filesz) - v21 = v17->buffer_length - v20; - v25.src = &v17->buffer_base[v20]; - p_filesz -= v21; - v25.size = v21; - v25.attr = 0; - v25.dest = (void *)((v15->p_vaddr) + v13); - CpuSuspendIntr(&state); - v23 = sceSifSetDma(&v25, 1); - v24 = state; - v13 += v21; - v17->dma_handle = v23; - CpuResumeIntr(v24); - if (!p_filesz) - goto LABEL_20; - allocate_info->ring_buffer_index = (allocate_info->ring_buffer_index + 1) & 1; - } - for (;;) { - if (read_callback(flhs->fd, allocate_info, read_callback_userdata) != 0) - break; - if (v18 < (u32)(allocate_info->read_buffer_offset)) - goto LABEL_16; - } - } - return KE_FILEERR; + int v12; + int v13; + int index_of_ph_contents; + loadfile_elf32_phdr_t *v15; + unsigned int p_filesz; + loadfile_ee_elf_ringbuffer_content_t *v17; + unsigned int v18; + unsigned int v20; + int v21; + int v23; + int v24; + SifDmaTransfer_t v25; + loadfile_elf_program_header_size_offset_t v26[32]; + int state; + int ph_count; + + if ( flhs->program_header == NULL ) + { + return KE_ILLEGAL_OBJECT; + } + ph_count = 0; + { + int i; + + for ( i = 0; i < flhs->elf_header.e_phnum; i += 1 ) + { + loadfile_elf32_phdr_t *v10; + + v10 = &flhs->program_header[i]; + if ( v10->p_type == 1 && v10->p_filesz ) + { + v26[ph_count].index_of_ph_contents = i; + v26[ph_count].offset_of_ph_contents = v10->p_offset; + ph_count += 1; + } + } + } + sort_ph_contents(ph_count, v26); + v12 = 0; + printf("Input ELF format filename = %s\n", flhs->filename); + v13 = 0; + if ( ph_count <= 0 ) + { + LABEL_21: + printf("Loaded, %s\n", flhs->filename); + return 0; + } + else + { + for ( ;; ) + { + index_of_ph_contents = v26[v12].index_of_ph_contents; + v15 = &flhs->program_header[index_of_ph_contents]; + p_filesz = v15->p_filesz; + printf("%d %08x %08x ", index_of_ph_contents, v15->p_vaddr, p_filesz); + if ( p_filesz ) + break; + LABEL_20: + v12 += 1; + printf("\n"); + v13 = 0; + if ( v12 >= ph_count ) + goto LABEL_21; + } + for ( ;; ) + { + printf("."); + v17 = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; + while ( sceSifDmaStat(v17->dma_handle) >= 0 ) + ; + v18 = v15->p_offset + v13; + if ( v18 >= (u32)(allocate_info->read_buffer_offset) ) + break; + LABEL_16: + v20 = v18 - v17->buffer_offset; + v21 = p_filesz; + if ( v17->buffer_length - v20 < p_filesz ) + v21 = v17->buffer_length - v20; + v25.src = &v17->buffer_base[v20]; + p_filesz -= v21; + v25.size = v21; + v25.attr = 0; + v25.dest = (void *)((v15->p_vaddr) + v13); + CpuSuspendIntr(&state); + v23 = sceSifSetDma(&v25, 1); + v24 = state; + v13 += v21; + v17->dma_handle = v23; + CpuResumeIntr(v24); + if ( !p_filesz ) + goto LABEL_20; + allocate_info->ring_buffer_index = (allocate_info->ring_buffer_index + 1) & 1; + } + for ( ;; ) + { + if ( read_callback(flhs->fd, allocate_info, read_callback_userdata) != 0 ) + break; + if ( v18 < (u32)(allocate_info->read_buffer_offset) ) + goto LABEL_16; + } + } + return KE_FILEERR; } static int elf_load_single_section( - loadfile_allocate_handler_struct_t *allocate_info, - loadfile_file_load_handler_struct_t *flhs, - int epc, - const char *section_name) + loadfile_allocate_handler_struct_t *allocate_info, + loadfile_file_load_handler_struct_t *flhs, + int epc, + const char *section_name) { - loadfile_elf32_shdr_t *v7; - int result; - int v12; - unsigned int sh_size; - loadfile_ee_elf_ringbuffer_content_t *v14; - SifDmaTransfer_t v22; - int state; - - v7 = NULL; - if (read(flhs->fd, &flhs->elf_header, 0x34) != 0x34) { - return KE_FILEERR; - } - result = elf_read_header_section_headers(flhs); - if (result < 0) { - return result; - } - result = elf_read_section_contents(flhs); - if (result < 0) { - return result; - } - { - int i; - - for (i = 0; i < flhs->elf_header.e_shnum; i += 1) { - v7 = &flhs->section_headers[i]; - if (!strcmp((const char *)&flhs->section_contents[v7->sh_name], section_name) && v7->sh_size) - break; - v7 = NULL; - } - } - if (v7 == NULL || v7->sh_addr < 0x80000) { - return KE_ILLEGAL_OBJECT; - } - v12 = 0; - lseek(flhs->fd, v7->sh_offset, 0); - allocate_info->read_buffer_offset = v7->sh_offset; - sh_size = v7->sh_size; - printf("%s: %08x %08x ", section_name, v7->sh_addr, sh_size); - while (sh_size != 0) { - loadfile_allocate_handler_struct_t *i; - unsigned int v15; - unsigned int v17; - int v18; - int v20; - int v21; - - - printf("."); - v14 = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; - while (sceSifDmaStat(v14->dma_handle) >= 0) - ; - v15 = v7->sh_offset + v12; - for (i = allocate_info; v15 >= (u32)(allocate_info->read_buffer_offset); i = allocate_info) - fileio_reader_function(flhs->fd, i, 0); - v17 = v15 - v14->buffer_offset; - v18 = sh_size; - if (v14->buffer_length - v17 < sh_size) - v18 = v14->buffer_length - v17; - v22.src = &v14->buffer_base[v17]; - sh_size -= v18; - v22.size = v18; - v22.attr = 0; - v22.dest = (void *)((v7->sh_addr) + v12); - CpuSuspendIntr(&state); - v20 = sceSifSetDma(&v22, 1); - v21 = state; - v12 += v18; - v14->dma_handle = v20; - CpuResumeIntr(v21); - allocate_info->ring_buffer_index = (allocate_info->ring_buffer_index + 1) & 1; - } - printf("\nLoaded, %s:%s\n", flhs->filename, section_name); - return 0; + loadfile_elf32_shdr_t *v7; + int result; + int v12; + unsigned int sh_size; + loadfile_ee_elf_ringbuffer_content_t *v14; + SifDmaTransfer_t v22; + int state; + + v7 = NULL; + if ( read(flhs->fd, &flhs->elf_header, 0x34) != 0x34 ) + { + return KE_FILEERR; + } + result = elf_read_header_section_headers(flhs); + if ( result < 0 ) + { + return result; + } + result = elf_read_section_contents(flhs); + if ( result < 0 ) + { + return result; + } + { + int i; + + for ( i = 0; i < flhs->elf_header.e_shnum; i += 1 ) + { + v7 = &flhs->section_headers[i]; + if ( !strcmp((const char *)&flhs->section_contents[v7->sh_name], section_name) && v7->sh_size ) + break; + v7 = NULL; + } + } + if ( v7 == NULL || v7->sh_addr < 0x80000 ) + { + return KE_ILLEGAL_OBJECT; + } + v12 = 0; + lseek(flhs->fd, v7->sh_offset, 0); + allocate_info->read_buffer_offset = v7->sh_offset; + sh_size = v7->sh_size; + printf("%s: %08x %08x ", section_name, v7->sh_addr, sh_size); + while ( sh_size != 0 ) + { + loadfile_allocate_handler_struct_t *i; + unsigned int v15; + unsigned int v17; + int v18; + int v20; + int v21; + + printf("."); + v14 = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; + while ( sceSifDmaStat(v14->dma_handle) >= 0 ) + ; + v15 = v7->sh_offset + v12; + for ( i = allocate_info; v15 >= (u32)(allocate_info->read_buffer_offset); i = allocate_info ) + fileio_reader_function(flhs->fd, i, 0); + v17 = v15 - v14->buffer_offset; + v18 = sh_size; + if ( v14->buffer_length - v17 < sh_size ) + v18 = v14->buffer_length - v17; + v22.src = &v14->buffer_base[v17]; + sh_size -= v18; + v22.size = v18; + v22.attr = 0; + v22.dest = (void *)((v7->sh_addr) + v12); + CpuSuspendIntr(&state); + v20 = sceSifSetDma(&v22, 1); + v21 = state; + v12 += v18; + v14->dma_handle = v20; + CpuResumeIntr(v21); + allocate_info->ring_buffer_index = (allocate_info->ring_buffer_index + 1) & 1; + } + printf("\nLoaded, %s:%s\n", flhs->filename, section_name); + return 0; } int elf_load_all_section( - loadfile_allocate_handler_struct_t *allocate_info, - loadfile_file_load_handler_struct_t *flhs, - int *result_out, - int *result_module_out) + loadfile_allocate_handler_struct_t *allocate_info, + loadfile_file_load_handler_struct_t *flhs, + int *result_out, + int *result_module_out) { - int result; - - fileio_reader_function(flhs->fd, allocate_info, 0); - result = check_valid_ee_elf(allocate_info, flhs); - if (result < 0) { - return result; - } - result = elf_get_program_header(allocate_info, flhs); - if (result < 0) { - return result; - } - { - int i; - loadfile_elf32_phdr_t *program_headers; - - program_headers = flhs->program_header; - for (i = 0; i < flhs->elf_header.e_phnum; i += 1) { - if (program_headers[i].p_type == 1 && program_headers[i].p_filesz && program_headers[i].p_vaddr < 0x80000) { - return KE_ILLEGAL_OBJECT; - } - } - } - result = elf_load_proc(allocate_info, flhs, 0, fileio_reader_function); - if (result < 0) { - return result; - } - *result_out = flhs->elf_header.e_entry; - *result_module_out = 0; - printf("start address %#08x\n", *result_out); - printf("gp address %#08x\n", *result_module_out); - return 0; + int result; + + fileio_reader_function(flhs->fd, allocate_info, 0); + result = check_valid_ee_elf(allocate_info, flhs); + if ( result < 0 ) + { + return result; + } + result = elf_get_program_header(allocate_info, flhs); + if ( result < 0 ) + { + return result; + } + { + int i; + loadfile_elf32_phdr_t *program_headers; + + program_headers = flhs->program_header; + for ( i = 0; i < flhs->elf_header.e_phnum; i += 1 ) + { + if ( program_headers[i].p_type == 1 && program_headers[i].p_filesz && program_headers[i].p_vaddr < 0x80000 ) + { + return KE_ILLEGAL_OBJECT; + } + } + } + result = elf_load_proc(allocate_info, flhs, 0, fileio_reader_function); + if ( result < 0 ) + { + return result; + } + *result_out = flhs->elf_header.e_entry; + *result_module_out = 0; + printf("start address %#08x\n", *result_out); + printf("gp address %#08x\n", *result_module_out); + return 0; } static void empty_loadfile_information(loadfile_file_load_handler_struct_t *flhs) { - flhs->fd = -1; - flhs->filename = 0; - flhs->section_contents = 0; - flhs->unknown_0C = 0; - flhs->program_header = 0; - flhs->section_headers = 0; - flhs->unknown_4C = 0; + flhs->fd = -1; + flhs->filename = 0; + flhs->section_contents = 0; + flhs->unknown_0C = 0; + flhs->program_header = 0; + flhs->section_headers = 0; + flhs->unknown_4C = 0; } -static int elf_load_common(const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out, int is_mg_elf) +static int elf_load_common( + const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out, int is_mg_elf) { - int *heap_buffer; - int v11; - int v12; - char *v13; - loadfile_allocate_handler_struct_t *p_allocate_info; - int result; - loadfile_allocate_handler_struct_t allocate_info; - loadfile_file_load_handler_struct_t flhs; - SetLoadfileCallbacks_struct_t loadfile_functions; - CheckKelfPath_callback_t CheckKelfPath_fnc; - SetLoadfileCallbacks_callback_t SetLoadfileCallbacks_fnc; - int v23; - int v24; - - printf("%s", "loadelf version 3.30\n"); - empty_loadfile_information(&flhs); - flhs.filename = filename; - flhs.fd = open(filename, 1); - if (flhs.fd < 0) { - printf("Cannot openfile\n"); - result = KE_NOFILE; - goto finish_returnresult; - } - heap_buffer = allocate_heap_buffer(0, 0x10000); - v11 = 0x20000; - if (heap_buffer == NULL) { - printf("Error Can't Get heap buffer\n"); - result = KE_NO_MEMORY; - goto finish_closefd; - } - v12 = 0; - for (;;) { - CpuDisableIntr(); - v13 = (char *)AllocSysMemory(ALLOC_LAST, v11, NULL); - CpuEnableIntr(); - if (v13) - break; - v11 /= 2; - if (++v12 >= 8) { - printf("Error Can't Get read buffer\n"); - result = KE_NO_MEMORY; - goto finish_freeheapbuffer; - } - } - p_allocate_info = &allocate_info; - allocate_info.ring_buffer_index = 0; - allocate_info.read_buffer_length = (unsigned int)v11 >> 1; - allocate_info.read_buffer_offset = 0; - { - int i; - - for (i = 0; i < 2; i += 1) { - int v16; - - v16 = allocate_info.read_buffer_length * i; - p_allocate_info->ring_buffer_contents[i].buffer_offset = 0; - p_allocate_info->ring_buffer_contents[i].buffer_length = 0; - p_allocate_info->ring_buffer_contents[i].dma_handle = 0; - p_allocate_info->ring_buffer_contents[i].buffer_base = (u8 *)&v13[v16]; - } - } - result = KE_ILLEGAL_OBJECT; - if (is_mg_elf) { - GetLoadfileCallbacks(&CheckKelfPath_fnc, &SetLoadfileCallbacks_fnc); - if (SetLoadfileCallbacks_fnc) { - loadfile_functions.elf_load_proc = elf_load_proc; - loadfile_functions.check_valid_ee_elf = check_valid_ee_elf; - loadfile_functions.elf_get_program_header = elf_get_program_header; - loadfile_functions.elf_load_alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap; - loadfile_functions.elf_load_dealloc_buffer_from_heap = elf_load_dealloc_buffer_from_heap; - SetLoadfileCallbacks_fnc(&loadfile_functions); - if (CheckKelfPath_fnc && CheckKelfPath_fnc(filename, &v23, &v24)) { - if (loadfile_functions.load_kelf_from_card) { - result = loadfile_functions.load_kelf_from_card( - &allocate_info, - &flhs, - v23, - v24, - result_out, - result_module_out); - } - } else if (loadfile_functions.load_kelf_from_disk) { - result = loadfile_functions.load_kelf_from_disk( - &allocate_info, - &flhs, - result_out, - result_module_out); - } - } - } else if (!strcmp(section_name, "all")) { - result = elf_load_all_section(&allocate_info, &flhs, result_out, result_module_out); - } else { - result = elf_load_single_section(&allocate_info, &flhs, epc, section_name); - } - FreeSysMemory(v13); + int *heap_buffer; + int v11; + int v12; + char *v13; + loadfile_allocate_handler_struct_t *p_allocate_info; + int result; + loadfile_allocate_handler_struct_t allocate_info; + loadfile_file_load_handler_struct_t flhs; + SetLoadfileCallbacks_struct_t loadfile_functions; + CheckKelfPath_callback_t CheckKelfPath_fnc; + SetLoadfileCallbacks_callback_t SetLoadfileCallbacks_fnc; + int v23; + int v24; + + printf("%s", "loadelf version 3.30\n"); + empty_loadfile_information(&flhs); + flhs.filename = filename; + flhs.fd = open(filename, 1); + if ( flhs.fd < 0 ) + { + printf("Cannot openfile\n"); + result = KE_NOFILE; + goto finish_returnresult; + } + heap_buffer = allocate_heap_buffer(0, 0x10000); + v11 = 0x20000; + if ( heap_buffer == NULL ) + { + printf("Error Can't Get heap buffer\n"); + result = KE_NO_MEMORY; + goto finish_closefd; + } + v12 = 0; + for ( ;; ) + { + CpuDisableIntr(); + v13 = (char *)AllocSysMemory(ALLOC_LAST, v11, NULL); + CpuEnableIntr(); + if ( v13 ) + break; + v11 /= 2; + if ( ++v12 >= 8 ) + { + printf("Error Can't Get read buffer\n"); + result = KE_NO_MEMORY; + goto finish_freeheapbuffer; + } + } + p_allocate_info = &allocate_info; + allocate_info.ring_buffer_index = 0; + allocate_info.read_buffer_length = (unsigned int)v11 >> 1; + allocate_info.read_buffer_offset = 0; + { + int i; + + for ( i = 0; i < 2; i += 1 ) + { + int v16; + + v16 = allocate_info.read_buffer_length * i; + p_allocate_info->ring_buffer_contents[i].buffer_offset = 0; + p_allocate_info->ring_buffer_contents[i].buffer_length = 0; + p_allocate_info->ring_buffer_contents[i].dma_handle = 0; + p_allocate_info->ring_buffer_contents[i].buffer_base = (u8 *)&v13[v16]; + } + } + result = KE_ILLEGAL_OBJECT; + if ( is_mg_elf ) + { + GetLoadfileCallbacks(&CheckKelfPath_fnc, &SetLoadfileCallbacks_fnc); + if ( SetLoadfileCallbacks_fnc ) + { + loadfile_functions.elf_load_proc = elf_load_proc; + loadfile_functions.check_valid_ee_elf = check_valid_ee_elf; + loadfile_functions.elf_get_program_header = elf_get_program_header; + loadfile_functions.elf_load_alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap; + loadfile_functions.elf_load_dealloc_buffer_from_heap = elf_load_dealloc_buffer_from_heap; + SetLoadfileCallbacks_fnc(&loadfile_functions); + if ( CheckKelfPath_fnc && CheckKelfPath_fnc(filename, &v23, &v24) ) + { + if ( loadfile_functions.load_kelf_from_card ) + { + result = + loadfile_functions.load_kelf_from_card(&allocate_info, &flhs, v23, v24, result_out, result_module_out); + } + } + else if ( loadfile_functions.load_kelf_from_disk ) + { + result = loadfile_functions.load_kelf_from_disk(&allocate_info, &flhs, result_out, result_module_out); + } + } + } + else if ( !strcmp(section_name, "all") ) + { + result = elf_load_all_section(&allocate_info, &flhs, result_out, result_module_out); + } + else + { + result = elf_load_single_section(&allocate_info, &flhs, epc, section_name); + } + FreeSysMemory(v13); finish_freeheapbuffer: - FreeSysMemory(heap_buffer); + FreeSysMemory(heap_buffer); finish_closefd: - close(flhs.fd); + close(flhs.fd); finish_returnresult: - return result; + return result; } -int loadfile_elfload_innerproc(const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out) +int loadfile_elfload_innerproc( + const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out) { - if (IsIllegalBootDevice(filename) != 0) { - return KE_ILLEGAL_OBJECT; - } - return elf_load_common(filename, epc, section_name, result_out, result_module_out, 0); + if ( IsIllegalBootDevice(filename) != 0 ) + { + return KE_ILLEGAL_OBJECT; + } + return elf_load_common(filename, epc, section_name, result_out, result_module_out, 0); } -int loadfile_mg_elfload_proc(const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out) +int loadfile_mg_elfload_proc( + const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out) { - if (strcmp(section_name, "all") != 0) { - return KE_ILLEGAL_MODE; - } - return elf_load_common(filename, epc, section_name, result_out, result_module_out, 1); + if ( strcmp(section_name, "all") != 0 ) + { + return KE_ILLEGAL_MODE; + } + return elf_load_common(filename, epc, section_name, result_out, result_module_out, 1); } diff --git a/iop/system/loadfile/src/eeelfloader.h b/iop/system/loadfile/src/eeelfloader.h index 61374c31eaf..0a0ad966fc5 100644 --- a/iop/system/loadfile/src/eeelfloader.h +++ b/iop/system/loadfile/src/eeelfloader.h @@ -11,7 +11,9 @@ #ifndef __EEELFLOADER_H__ #define __EEELFLOADER_H__ -extern int loadfile_elfload_innerproc(const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out); -extern int loadfile_mg_elfload_proc(const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out); +extern int loadfile_elfload_innerproc( + const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out); +extern int loadfile_mg_elfload_proc( + const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out); #endif diff --git a/iop/system/loadfile/src/loadfile.c b/iop/system/loadfile/src/loadfile.c index 8db17370cc7..4932caea314 100644 --- a/iop/system/loadfile/src/loadfile.c +++ b/iop/system/loadfile/src/loadfile.c @@ -8,10 +8,10 @@ # Review ps2sdk README & LICENSE files for further details. */ -#include "irx_imports.h" #include "eeelfloader.h" -#include +#include "irx_imports.h" #include +#include #ifdef _IOP IRX_ID("LoadModuleByEE", 0, 0); @@ -22,191 +22,213 @@ static void loadfile_rpc_start_thread(void *param); int _start(int argc, char *argv[]) { - int *BootMode; - int thread_id; - iop_thread_t thread_param; - - FlushDcache(); - BootMode = QueryBootMode(3); - if (BootMode) { - int iop_boot_param; - - iop_boot_param = BootMode[1]; - if ((iop_boot_param & 1) != 0) { - printf(" No SIF service(loadfile)\n"); - return MODULE_NO_RESIDENT_END; - } - if ((iop_boot_param & 2) != 0) { - printf(" No LoadFile service\n"); - return MODULE_NO_RESIDENT_END; - } - } - CpuEnableIntr(); - thread_param.attr = 0x2000000; - thread_param.thread = loadfile_rpc_start_thread; - thread_param.priority = 88; - thread_param.stacksize = 4096; - thread_param.option = 0; - thread_id = CreateThread(&thread_param); - if (thread_id <= 0) { - return MODULE_NO_RESIDENT_END; - } - StartThread(thread_id, 0); - return MODULE_RESIDENT_END; + int *BootMode; + int thread_id; + iop_thread_t thread_param; + + FlushDcache(); + BootMode = QueryBootMode(3); + if ( BootMode ) + { + int iop_boot_param; + + iop_boot_param = BootMode[1]; + if ( (iop_boot_param & 1) != 0 ) + { + printf(" No SIF service(loadfile)\n"); + return MODULE_NO_RESIDENT_END; + } + if ( (iop_boot_param & 2) != 0 ) + { + printf(" No LoadFile service\n"); + return MODULE_NO_RESIDENT_END; + } + } + CpuEnableIntr(); + thread_param.attr = 0x2000000; + thread_param.thread = loadfile_rpc_start_thread; + thread_param.priority = 88; + thread_param.stacksize = 4096; + thread_param.option = 0; + thread_id = CreateThread(&thread_param); + if ( thread_id <= 0 ) + { + return MODULE_NO_RESIDENT_END; + } + StartThread(thread_id, 0); + return MODULE_RESIDENT_END; } static int *loadfile_modload(struct _lf_module_load_arg *in_packet, int length, int *outbuffer) { - char *path; - - path = in_packet->path; - if (IsIllegalBootDevice(path)) { - outbuffer[0] = KE_ILLEGAL_OBJECT; - } else { - printf("loadmodule: fname %s args %d arg %s\n", path, in_packet->p.arg_len, in_packet->args); - outbuffer[0] = LoadStartModule(path, in_packet->p.arg_len, in_packet->args, &outbuffer[1]); - printf("loadmodule: id %d, ret %d\n", outbuffer[0], outbuffer[1]); - } - return outbuffer; + char *path; + + path = in_packet->path; + if ( IsIllegalBootDevice(path) ) + { + outbuffer[0] = KE_ILLEGAL_OBJECT; + } + else + { + printf("loadmodule: fname %s args %d arg %s\n", path, in_packet->p.arg_len, in_packet->args); + outbuffer[0] = LoadStartModule(path, in_packet->p.arg_len, in_packet->args, &outbuffer[1]); + printf("loadmodule: id %d, ret %d\n", outbuffer[0], outbuffer[1]); + } + return outbuffer; } static int *loadfile_elfload(struct _lf_elf_load_arg *in_packet, int length, int *outbuffer) { - char *path; - int v5; - int v6; - - path = in_packet->path; - if (IsIllegalBootDevice(path)) { - outbuffer[0] = KE_FILEERR; - } else { - int v4; - - printf("loadelf: fname %s secname %s\n", path, in_packet->secname); - v4 = loadfile_elfload_innerproc(path, in_packet->epc, in_packet->secname, &v5, &v6); - outbuffer[0] = v4; - if (v4 >= 0) { - outbuffer[2] = 0; - outbuffer[0] = v5; - outbuffer[1] = v6; - } else { - outbuffer[3] = v4; - outbuffer[0] = 0; - } - } - return outbuffer; + char *path; + int v5; + int v6; + + path = in_packet->path; + if ( IsIllegalBootDevice(path) ) + { + outbuffer[0] = KE_FILEERR; + } + else + { + int v4; + + printf("loadelf: fname %s secname %s\n", path, in_packet->secname); + v4 = loadfile_elfload_innerproc(path, in_packet->epc, in_packet->secname, &v5, &v6); + outbuffer[0] = v4; + if ( v4 >= 0 ) + { + outbuffer[2] = 0; + outbuffer[0] = v5; + outbuffer[1] = v6; + } + else + { + outbuffer[3] = v4; + outbuffer[0] = 0; + } + } + return outbuffer; } static int *loadfile_setaddr(struct _lf_iop_val_arg *in_packet, int length, int *outbuffer) { - void *iop_addr; - int type; - - iop_addr = (void *)in_packet->p.iop_addr; - type = in_packet->type; - printf("set val add %p type %x ", iop_addr, type); - switch (type) { - case LF_VAL_BYTE: - *(u8 *)iop_addr = in_packet->val.b; - break; - case LF_VAL_SHORT: - *(u16 *)iop_addr = in_packet->val.s; - break; - case LF_VAL_LONG: - *(u32 *)iop_addr = in_packet->val.l; - break; - default: - break; - } - outbuffer[0] = 0; - return outbuffer; + void *iop_addr; + int type; + + iop_addr = (void *)in_packet->p.iop_addr; + type = in_packet->type; + printf("set val add %p type %x ", iop_addr, type); + switch ( type ) + { + case LF_VAL_BYTE: + *(u8 *)iop_addr = in_packet->val.b; + break; + case LF_VAL_SHORT: + *(u16 *)iop_addr = in_packet->val.s; + break; + case LF_VAL_LONG: + *(u32 *)iop_addr = in_packet->val.l; + break; + default: + break; + } + outbuffer[0] = 0; + return outbuffer; } static int *loadfile_getaddr(struct _lf_iop_val_arg *in_packet, int length, int *outbuffer) { - void *iop_addr; - int type; - - iop_addr = (void *)in_packet->p.iop_addr; - type = in_packet->type; - printf("get val add %p type %x ", iop_addr, type); - switch (type) { - case LF_VAL_BYTE: - outbuffer[0] = *(u8 *)iop_addr; - break; - case LF_VAL_SHORT: - outbuffer[0] = *(u16 *)iop_addr; - break; - case LF_VAL_LONG: - outbuffer[0] = *(u32 *)iop_addr; - break; - default: - break; - } - printf("ret %x\n", outbuffer[0]); - return outbuffer; + void *iop_addr; + int type; + + iop_addr = (void *)in_packet->p.iop_addr; + type = in_packet->type; + printf("get val add %p type %x ", iop_addr, type); + switch ( type ) + { + case LF_VAL_BYTE: + outbuffer[0] = *(u8 *)iop_addr; + break; + case LF_VAL_SHORT: + outbuffer[0] = *(u16 *)iop_addr; + break; + case LF_VAL_LONG: + outbuffer[0] = *(u32 *)iop_addr; + break; + default: + break; + } + printf("ret %x\n", outbuffer[0]); + return outbuffer; } static int *loadfile_mg_modload(struct _lf_module_load_arg *in_packet, int length, int *outbuffer) { - outbuffer[0] = LoadStartKelfModule(in_packet->path, in_packet->p.arg_len, in_packet->args, &outbuffer[1]); - return outbuffer; + outbuffer[0] = LoadStartKelfModule(in_packet->path, in_packet->p.arg_len, in_packet->args, &outbuffer[1]); + return outbuffer; } static int *loadfile_mg_elfload(struct _lf_elf_load_arg *in_packet, int length, int *outbuffer) { - int v2; - int v3; - - outbuffer[0] = loadfile_mg_elfload_proc(in_packet->path, in_packet->epc, in_packet->secname, &v2, &v3); - if (outbuffer[0] >= 0) { - outbuffer[2] = 0; - outbuffer[0] = v2; - outbuffer[1] = v3; - } else { - outbuffer[0] = 0; - } - return outbuffer; + int v2; + int v3; + + outbuffer[0] = loadfile_mg_elfload_proc(in_packet->path, in_packet->epc, in_packet->secname, &v2, &v3); + if ( outbuffer[0] >= 0 ) + { + outbuffer[2] = 0; + outbuffer[0] = v2; + outbuffer[1] = v3; + } + else + { + outbuffer[0] = 0; + } + return outbuffer; } // The following function was added in 110U ROM. static int *loadfile_loadmodulebuffer(struct _lf_module_buffer_load_arg *in_packet, int length, int *outbuffer) { - int ModuleBuffer; - - printf("loadbuffer: addrres %x args %d arg %s\n", in_packet->p.result, in_packet->q.arg_len, in_packet->args); - ModuleBuffer = LoadModuleBuffer(in_packet->p.ptr); - if (ModuleBuffer >= 0) { - outbuffer[0] = StartModule(ModuleBuffer, "LBbyEE", in_packet->q.arg_len, in_packet->args, &outbuffer[1]); - } else { - outbuffer[0] = ModuleBuffer; - } - printf("loadbuffer: id %d, ret %d\n", outbuffer[0], outbuffer[1]); - return outbuffer; + int ModuleBuffer; + + printf("loadbuffer: addrres %x args %d arg %s\n", in_packet->p.result, in_packet->q.arg_len, in_packet->args); + ModuleBuffer = LoadModuleBuffer(in_packet->p.ptr); + if ( ModuleBuffer >= 0 ) + { + outbuffer[0] = StartModule(ModuleBuffer, "LBbyEE", in_packet->q.arg_len, in_packet->args, &outbuffer[1]); + } + else + { + outbuffer[0] = ModuleBuffer; + } + printf("loadbuffer: id %d, ret %d\n", outbuffer[0], outbuffer[1]); + return outbuffer; } static int loadfile_rpc_outbuf[0x4] __attribute__((aligned(16))); static int *loadfile_rpc_service_handler(int fno, void *buffer, int length) { - switch (fno) { - case LF_F_MOD_LOAD: - return loadfile_modload((struct _lf_module_load_arg *)buffer, length, loadfile_rpc_outbuf); - case LF_F_ELF_LOAD: - return loadfile_elfload((struct _lf_elf_load_arg *)buffer, length, loadfile_rpc_outbuf); - case LF_F_SET_ADDR: - return loadfile_setaddr((struct _lf_iop_val_arg *)buffer, length, loadfile_rpc_outbuf); - case LF_F_GET_ADDR: - return loadfile_getaddr((struct _lf_iop_val_arg *)buffer, length, loadfile_rpc_outbuf); - case LF_F_MG_MOD_LOAD: - return loadfile_mg_modload((struct _lf_module_load_arg *)buffer, length, loadfile_rpc_outbuf); - case LF_F_MG_ELF_LOAD: - return loadfile_mg_elfload((struct _lf_elf_load_arg *)buffer, length, loadfile_rpc_outbuf); - case LF_F_MOD_BUF_LOAD: - return loadfile_loadmodulebuffer((struct _lf_module_buffer_load_arg *)buffer, length, loadfile_rpc_outbuf); - default: - return NULL; - } + switch ( fno ) + { + case LF_F_MOD_LOAD: + return loadfile_modload((struct _lf_module_load_arg *)buffer, length, loadfile_rpc_outbuf); + case LF_F_ELF_LOAD: + return loadfile_elfload((struct _lf_elf_load_arg *)buffer, length, loadfile_rpc_outbuf); + case LF_F_SET_ADDR: + return loadfile_setaddr((struct _lf_iop_val_arg *)buffer, length, loadfile_rpc_outbuf); + case LF_F_GET_ADDR: + return loadfile_getaddr((struct _lf_iop_val_arg *)buffer, length, loadfile_rpc_outbuf); + case LF_F_MG_MOD_LOAD: + return loadfile_mg_modload((struct _lf_module_load_arg *)buffer, length, loadfile_rpc_outbuf); + case LF_F_MG_ELF_LOAD: + return loadfile_mg_elfload((struct _lf_elf_load_arg *)buffer, length, loadfile_rpc_outbuf); + case LF_F_MOD_BUF_LOAD: + return loadfile_loadmodulebuffer((struct _lf_module_buffer_load_arg *)buffer, length, loadfile_rpc_outbuf); + default: + return NULL; + } } static SifRpcDataQueue_t loadfile_rpc_service_queue __attribute__((aligned(16))); @@ -215,11 +237,18 @@ static int loadfile_rpc_service_in_buf[0x112] __attribute__((aligned(16))); static void loadfile_rpc_start_thread(void *param) { - (void)param; - - printf("Load File service.(99/11/05)\n"); - sceSifInitRpc(0); - sceSifSetRpcQueue(&loadfile_rpc_service_queue, GetThreadId()); - sceSifRegisterRpc(&loadfile_rpc_service_data, 0x80000006, (SifRpcFunc_t)loadfile_rpc_service_handler, loadfile_rpc_service_in_buf, 0, 0, &loadfile_rpc_service_queue); - sceSifRpcLoop(&loadfile_rpc_service_queue); + (void)param; + + printf("Load File service.(99/11/05)\n"); + sceSifInitRpc(0); + sceSifSetRpcQueue(&loadfile_rpc_service_queue, GetThreadId()); + sceSifRegisterRpc( + &loadfile_rpc_service_data, + 0x80000006, + (SifRpcFunc_t)loadfile_rpc_service_handler, + loadfile_rpc_service_in_buf, + 0, + 0, + &loadfile_rpc_service_queue); + sceSifRpcLoop(&loadfile_rpc_service_queue); } From 47d66015642034849a8b96b2f9891ae27feb0e18 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Fri, 22 Mar 2024 23:25:31 -0500 Subject: [PATCH 3/4] cleanup: [loadfile] name, local variable, control flow cleanup --- iop/system/loadfile/src/eeelfloader.c | 453 ++++++++++++-------------- iop/system/loadfile/src/loadfile.c | 85 +++-- 2 files changed, 247 insertions(+), 291 deletions(-) diff --git a/iop/system/loadfile/src/eeelfloader.c b/iop/system/loadfile/src/eeelfloader.c index 71a72fbee74..cd9fadfa32c 100644 --- a/iop/system/loadfile/src/eeelfloader.c +++ b/iop/system/loadfile/src/eeelfloader.c @@ -20,21 +20,21 @@ static void *heap_buffer_end = NULL; static int *allocate_heap_buffer(unsigned int lower_bound, unsigned int upper_bound) { - unsigned int v1; + unsigned int upper_bound_rounded; - v1 = upper_bound; + upper_bound_rounded = upper_bound; // Align to 4 bytes - if ( (v1 & 3) != 0 ) + if ( (upper_bound_rounded & 3) != 0 ) { - v1 += (4 - (v1 & 3)); + upper_bound_rounded += (4 - (upper_bound_rounded & 3)); } CpuDisableIntr(); - heap_buffer_base = AllocSysMemory(ALLOC_LAST, v1, NULL); + heap_buffer_base = AllocSysMemory(ALLOC_LAST, upper_bound_rounded, NULL); CpuEnableIntr(); if ( heap_buffer_base != NULL ) { heap_buffer = heap_buffer_base; - heap_buffer_end = &(((u8 *)heap_buffer_base)[v1]); + heap_buffer_end = &(((u8 *)heap_buffer_base)[upper_bound_rounded]); return heap_buffer_base; } printf("memory allocation failed.\n"); @@ -43,13 +43,13 @@ static int *allocate_heap_buffer(unsigned int lower_bound, unsigned int upper_bo static void *elf_load_alloc_buffer_from_heap(u32 alloc_size) { - u32 v1; + u32 alloc_size_rounded; - v1 = alloc_size; + alloc_size_rounded = alloc_size; // Align to 4 bytes if ( (alloc_size & 3) != 0 ) { - v1 += (4 - (alloc_size & 3)); + alloc_size_rounded += (4 - (alloc_size & 3)); } // Validity check... { @@ -57,7 +57,7 @@ static void *elf_load_alloc_buffer_from_heap(u32 alloc_size) new_ptr = heap_buffer; new_ptr += 4; - new_ptr += v1; + new_ptr += alloc_size_rounded; if ( (u8 *)new_ptr > (u8 *)heap_buffer_end ) { return NULL; @@ -70,11 +70,11 @@ static void *elf_load_alloc_buffer_from_heap(u32 alloc_size) new_ptr = heap_buffer; - ((u32 *)new_ptr)[0] = v1; - new_ptr += sizeof(v1); + ((u32 *)new_ptr)[0] = alloc_size_rounded; + new_ptr += sizeof(alloc_size_rounded); ret_ptr = new_ptr; - new_ptr += v1; + new_ptr += alloc_size_rounded; heap_buffer = new_ptr; return ret_ptr; @@ -111,24 +111,24 @@ typedef struct loadfile_elf_program_header_size_offset_ int offset_of_ph_contents; } loadfile_elf_program_header_size_offset_t; -static int check_elf_header(const loadfile_elf32_ehdr_t **header) +static int check_elf_header(const loadfile_elf32_ehdr_t **pehdr) { - const loadfile_elf32_ehdr_t *v1; + const loadfile_elf32_ehdr_t *ehdr; - v1 = *header; - if ( v1->e_ident[0] != '\x7F' ) + ehdr = *pehdr; + if ( ehdr->e_ident[0] != '\x7F' ) { return -1; } - if ( v1->e_ident[1] != 'E' ) + if ( ehdr->e_ident[1] != 'E' ) { return -1; } - if ( v1->e_ident[2] != 'L' ) + if ( ehdr->e_ident[2] != 'L' ) { return -1; } - if ( v1->e_ident[3] != 'F' ) + if ( ehdr->e_ident[3] != 'F' ) { return -1; } @@ -175,23 +175,23 @@ static int check_elf_architecture(const loadfile_file_load_handler_struct_t *flh static int check_valid_ee_elf(loadfile_allocate_handler_struct_t *allocate_info, loadfile_file_load_handler_struct_t *flhs) { - const loadfile_elf32_ehdr_t **v3; - int v4; - loadfile_elf32_ehdr_t *p_elf_header; + const loadfile_elf32_ehdr_t **pehdr; + int hdrchkres; + loadfile_elf32_ehdr_t *ehdr; - v3 = (const loadfile_elf32_ehdr_t **)&allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; - v4 = check_elf_header(v3); - p_elf_header = &flhs->elf_header; - if ( v4 < 0 ) + pehdr = (const loadfile_elf32_ehdr_t **)&allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; + hdrchkres = check_elf_header(pehdr); + ehdr = &flhs->elf_header; + if ( hdrchkres < 0 ) { - printf("File is not ELF format(%d)\n", v4); + printf("File is not ELF format(%d)\n", hdrchkres); return KE_ILLEGAL_OBJECT; } - memcpy(p_elf_header, *v3, sizeof(*p_elf_header)); - v4 = check_elf_architecture(flhs); - if ( v4 < 0 ) + memcpy(ehdr, *pehdr, sizeof(*ehdr)); + hdrchkres = check_elf_architecture(flhs); + if ( hdrchkres < 0 ) { - printf("File is not for target architecture(%d)\n", v4); + printf("File is not for target architecture(%d)\n", hdrchkres); return KE_ILLEGAL_OBJECT; } return 0; @@ -200,11 +200,11 @@ check_valid_ee_elf(loadfile_allocate_handler_struct_t *allocate_info, loadfile_f static int elf_get_program_header(loadfile_allocate_handler_struct_t *allocate_info, loadfile_file_load_handler_struct_t *flhs) { - int v4; + int totalphsize; u8 *alloc_buffer_from_heap; - v4 = flhs->elf_header.e_phentsize * flhs->elf_header.e_phnum; - alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(v4); + totalphsize = flhs->elf_header.e_phentsize * flhs->elf_header.e_phnum; + alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(totalphsize); flhs->program_header = (loadfile_elf32_phdr_t *)alloc_buffer_from_heap; if ( alloc_buffer_from_heap == NULL ) { @@ -213,24 +213,24 @@ elf_get_program_header(loadfile_allocate_handler_struct_t *allocate_info, loadfi memcpy( alloc_buffer_from_heap, &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index].buffer_base[flhs->elf_header.e_phoff], - v4); + totalphsize); return 0; } static int elf_read_header_section_headers(loadfile_file_load_handler_struct_t *flhs) { - int v2; + int totahshsize; u8 *alloc_buffer_from_heap; lseek(flhs->fd, flhs->elf_header.e_shoff, 0); - v2 = flhs->elf_header.e_shentsize * flhs->elf_header.e_shnum; - alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(v2); + totahshsize = flhs->elf_header.e_shentsize * flhs->elf_header.e_shnum; + alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(totahshsize); flhs->section_headers = (loadfile_elf32_shdr_t *)alloc_buffer_from_heap; if ( alloc_buffer_from_heap == NULL ) { return KE_NO_MEMORY; } - if ( read(flhs->fd, alloc_buffer_from_heap, v2) != v2 ) + if ( read(flhs->fd, alloc_buffer_from_heap, totahshsize) != totahshsize ) { elf_load_dealloc_buffer_from_heap(flhs->section_headers); flhs->section_headers = 0; @@ -241,23 +241,23 @@ static int elf_read_header_section_headers(loadfile_file_load_handler_struct_t * static int elf_read_section_contents(loadfile_file_load_handler_struct_t *flhs) { - loadfile_elf32_shdr_t *v2; + loadfile_elf32_shdr_t *shdr; u8 *alloc_buffer_from_heap; - v2 = &flhs->section_headers[flhs->elf_header.e_shstrndx]; - if ( v2->sh_type != 3 || v2->sh_flags != 0 || v2->sh_link != 0 || v2->sh_info != 0 ) + shdr = &flhs->section_headers[flhs->elf_header.e_shstrndx]; + if ( shdr->sh_type != 3 || shdr->sh_flags != 0 || shdr->sh_link != 0 || shdr->sh_info != 0 ) { flhs->section_contents = 0; return KE_ILLEGAL_OBJECT; } - alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(v2->sh_size); + alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap(shdr->sh_size); flhs->section_contents = alloc_buffer_from_heap; if ( alloc_buffer_from_heap == NULL ) { return KE_NO_MEMORY; } - lseek(flhs->fd, v2->sh_offset, 0); - if ( (u32)(read(flhs->fd, flhs->section_contents, v2->sh_size)) != v2->sh_size ) + lseek(flhs->fd, shdr->sh_offset, 0); + if ( (u32)(read(flhs->fd, flhs->section_contents, shdr->sh_size)) != shdr->sh_size ) { elf_load_dealloc_buffer_from_heap(flhs->section_contents); flhs->section_contents = 0; @@ -268,63 +268,50 @@ static int elf_read_section_contents(loadfile_file_load_handler_struct_t *flhs) static void sort_ph_contents(int ph_count, loadfile_elf_program_header_size_offset_t *ph_size_offset_data) { - if ( ph_count > 1 ) - { - int v2; - loadfile_elf_program_header_size_offset_t *v4; - - v2 = 1; - v4 = ph_size_offset_data + 1; - do + int ph_i1; + loadfile_elf_program_header_size_offset_t *szo1; + + ph_i1 = 1; + szo1 = ph_size_offset_data + 1; + while ( ph_i1 < ph_count ) + { + int ph_i2; + loadfile_elf_program_header_size_offset_t *szo2; + int index_of_ph_contents; + unsigned int offset_of_ph_contents; + loadfile_elf_program_header_size_offset_t *szo3; + + index_of_ph_contents = szo1->index_of_ph_contents; + offset_of_ph_contents = szo1->offset_of_ph_contents; + ph_i2 = ph_i1 - 1; + szo3 = &ph_size_offset_data[ph_i2]; + while ( ph_i2 >= 0 && offset_of_ph_contents < (u32)(szo3->offset_of_ph_contents) ) { - int v5; - loadfile_elf_program_header_size_offset_t *v9; - int index_of_ph_contents; - unsigned int offset_of_ph_contents; - - index_of_ph_contents = v4->index_of_ph_contents; - offset_of_ph_contents = v4->offset_of_ph_contents; - v5 = v2 - 1; - if ( v5 >= 0 ) - { - loadfile_elf_program_header_size_offset_t *v6; - - v6 = &ph_size_offset_data[v5]; - for ( ;; ) - { - if ( offset_of_ph_contents >= (u32)(v6->offset_of_ph_contents) ) - break; - v6[1].index_of_ph_contents = v6->index_of_ph_contents; - v6[1].offset_of_ph_contents = v6->offset_of_ph_contents; - v5 -= 1; - v6 -= 1; - if ( v5 < 0 ) - { - break; - } - } - } - v9 = &ph_size_offset_data[v5]; - v9[1].index_of_ph_contents = index_of_ph_contents; - v9[1].offset_of_ph_contents = offset_of_ph_contents; - v2 += 1; - v4 += 1; - } while ( v2 < ph_count ); + szo3[1].index_of_ph_contents = szo3->index_of_ph_contents; + szo3[1].offset_of_ph_contents = szo3->offset_of_ph_contents; + ph_i2 -= 1; + szo3 -= 1; + } + szo2 = &ph_size_offset_data[ph_i2]; + szo2[1].index_of_ph_contents = index_of_ph_contents; + szo2[1].offset_of_ph_contents = offset_of_ph_contents; + ph_i1 += 1; + szo1 += 1; } } static int fileio_reader_function(int fd, loadfile_allocate_handler_struct_t *allocate_info, void *userdata) { int read_buffer_offset; - loadfile_ee_elf_ringbuffer_content_t *v5; - int v7; + loadfile_ee_elf_ringbuffer_content_t *rbc; + int read_res; read_buffer_offset = allocate_info->read_buffer_offset; - v5 = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; - v5->buffer_offset = read_buffer_offset; - v7 = read(fd, v5->buffer_base, allocate_info->read_buffer_length); - v5->buffer_length = v7; - allocate_info->read_buffer_offset += v7; + rbc = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; + rbc->buffer_offset = read_buffer_offset; + read_res = read(fd, rbc->buffer_base, allocate_info->read_buffer_length); + rbc->buffer_length = read_res; + allocate_info->read_buffer_offset += read_res; return 0; } @@ -334,19 +321,13 @@ static int elf_load_proc( void *read_callback_userdata, loadfile_read_chunk_callback_t read_callback) { - int v12; - int v13; - int index_of_ph_contents; - loadfile_elf32_phdr_t *v15; - unsigned int p_filesz; - loadfile_ee_elf_ringbuffer_content_t *v17; - unsigned int v18; - unsigned int v20; - int v21; - int v23; - int v24; - SifDmaTransfer_t v25; - loadfile_elf_program_header_size_offset_t v26[32]; + int ph_i2; + loadfile_ee_elf_ringbuffer_content_t *rbc; + unsigned int sh_offset_total; + unsigned int sh_size_for_offset; + int sh_size_for_alignment; + SifDmaTransfer_t dmat; + loadfile_elf_program_header_size_offset_t phso[32]; int state; int ph_count; @@ -360,82 +341,64 @@ static int elf_load_proc( for ( i = 0; i < flhs->elf_header.e_phnum; i += 1 ) { - loadfile_elf32_phdr_t *v10; + const loadfile_elf32_phdr_t *phdr1; - v10 = &flhs->program_header[i]; - if ( v10->p_type == 1 && v10->p_filesz ) + phdr1 = &flhs->program_header[i]; + if ( phdr1->p_type == 1 && phdr1->p_filesz ) { - v26[ph_count].index_of_ph_contents = i; - v26[ph_count].offset_of_ph_contents = v10->p_offset; + phso[ph_count].index_of_ph_contents = i; + phso[ph_count].offset_of_ph_contents = phdr1->p_offset; ph_count += 1; } } } - sort_ph_contents(ph_count, v26); - v12 = 0; + sort_ph_contents(ph_count, phso); printf("Input ELF format filename = %s\n", flhs->filename); - v13 = 0; - if ( ph_count <= 0 ) - { - LABEL_21: - printf("Loaded, %s\n", flhs->filename); - return 0; - } - else - { - for ( ;; ) - { - index_of_ph_contents = v26[v12].index_of_ph_contents; - v15 = &flhs->program_header[index_of_ph_contents]; - p_filesz = v15->p_filesz; - printf("%d %08x %08x ", index_of_ph_contents, v15->p_vaddr, p_filesz); - if ( p_filesz ) - break; - LABEL_20: - v12 += 1; - printf("\n"); - v13 = 0; - if ( v12 >= ph_count ) - goto LABEL_21; - } - for ( ;; ) + for ( ph_i2 = 0; ph_i2 < ph_count; ph_i2 += 1 ) + { + int total_offset; + int index_of_ph_contents; + const loadfile_elf32_phdr_t *phdr2; + unsigned int sh_size_cur; + + index_of_ph_contents = phso[ph_i2].index_of_ph_contents; + phdr2 = &flhs->program_header[index_of_ph_contents]; + sh_size_cur = phdr2->p_filesz; + printf("%d %08x %08x ", index_of_ph_contents, phdr2->p_vaddr, sh_size_cur); + total_offset = 0; + while ( sh_size_cur != 0 ) { printf("."); - v17 = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; - while ( sceSifDmaStat(v17->dma_handle) >= 0 ) + rbc = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; + while ( sceSifDmaStat(rbc->dma_handle) >= 0 ) ; - v18 = v15->p_offset + v13; - if ( v18 >= (u32)(allocate_info->read_buffer_offset) ) - break; - LABEL_16: - v20 = v18 - v17->buffer_offset; - v21 = p_filesz; - if ( v17->buffer_length - v20 < p_filesz ) - v21 = v17->buffer_length - v20; - v25.src = &v17->buffer_base[v20]; - p_filesz -= v21; - v25.size = v21; - v25.attr = 0; - v25.dest = (void *)((v15->p_vaddr) + v13); + sh_offset_total = phdr2->p_offset + total_offset; + while ( sh_offset_total >= (u32)(allocate_info->read_buffer_offset) ) + { + if ( read_callback(flhs->fd, allocate_info, read_callback_userdata) != 0 ) + { + return KE_FILEERR; + } + } + sh_size_for_offset = sh_offset_total - rbc->buffer_offset; + sh_size_for_alignment = sh_size_cur; + if ( rbc->buffer_length - sh_size_for_offset < sh_size_cur ) + sh_size_for_alignment = rbc->buffer_length - sh_size_for_offset; + dmat.src = &rbc->buffer_base[sh_size_for_offset]; + sh_size_cur -= sh_size_for_alignment; + dmat.size = sh_size_for_alignment; + dmat.attr = 0; + dmat.dest = (void *)((phdr2->p_vaddr) + total_offset); + total_offset += sh_size_for_alignment; CpuSuspendIntr(&state); - v23 = sceSifSetDma(&v25, 1); - v24 = state; - v13 += v21; - v17->dma_handle = v23; - CpuResumeIntr(v24); - if ( !p_filesz ) - goto LABEL_20; + rbc->dma_handle = sceSifSetDma(&dmat, 1); + CpuResumeIntr(state); allocate_info->ring_buffer_index = (allocate_info->ring_buffer_index + 1) & 1; } - for ( ;; ) - { - if ( read_callback(flhs->fd, allocate_info, read_callback_userdata) != 0 ) - break; - if ( v18 < (u32)(allocate_info->read_buffer_offset) ) - goto LABEL_16; - } + printf("\n"); } - return KE_FILEERR; + printf("Loaded, %s\n", flhs->filename); + return 0; } static int elf_load_single_section( @@ -444,15 +407,15 @@ static int elf_load_single_section( int epc, const char *section_name) { - loadfile_elf32_shdr_t *v7; + loadfile_elf32_shdr_t *shdr; int result; - int v12; + int total_offset; unsigned int sh_size; - loadfile_ee_elf_ringbuffer_content_t *v14; - SifDmaTransfer_t v22; + loadfile_ee_elf_ringbuffer_content_t *rbc; + SifDmaTransfer_t dmat; int state; - v7 = NULL; + shdr = NULL; if ( read(flhs->fd, &flhs->elf_header, 0x34) != 0x34 ) { return KE_FILEERR; @@ -472,52 +435,48 @@ static int elf_load_single_section( for ( i = 0; i < flhs->elf_header.e_shnum; i += 1 ) { - v7 = &flhs->section_headers[i]; - if ( !strcmp((const char *)&flhs->section_contents[v7->sh_name], section_name) && v7->sh_size ) + shdr = &flhs->section_headers[i]; + if ( !strcmp((const char *)&flhs->section_contents[shdr->sh_name], section_name) && shdr->sh_size ) break; - v7 = NULL; + shdr = NULL; } } - if ( v7 == NULL || v7->sh_addr < 0x80000 ) + if ( shdr == NULL || shdr->sh_addr < 0x80000 ) { return KE_ILLEGAL_OBJECT; } - v12 = 0; - lseek(flhs->fd, v7->sh_offset, 0); - allocate_info->read_buffer_offset = v7->sh_offset; - sh_size = v7->sh_size; - printf("%s: %08x %08x ", section_name, v7->sh_addr, sh_size); + total_offset = 0; + lseek(flhs->fd, shdr->sh_offset, 0); + allocate_info->read_buffer_offset = shdr->sh_offset; + sh_size = shdr->sh_size; + printf("%s: %08x %08x ", section_name, shdr->sh_addr, sh_size); while ( sh_size != 0 ) { loadfile_allocate_handler_struct_t *i; - unsigned int v15; - unsigned int v17; - int v18; - int v20; - int v21; + unsigned int sh_offset_total; + unsigned int sh_size_for_offset; + int sh_size_for_alignment; printf("."); - v14 = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; - while ( sceSifDmaStat(v14->dma_handle) >= 0 ) + rbc = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; + while ( sceSifDmaStat(rbc->dma_handle) >= 0 ) ; - v15 = v7->sh_offset + v12; - for ( i = allocate_info; v15 >= (u32)(allocate_info->read_buffer_offset); i = allocate_info ) + sh_offset_total = shdr->sh_offset + total_offset; + for ( i = allocate_info; sh_offset_total >= (u32)(allocate_info->read_buffer_offset); i = allocate_info ) fileio_reader_function(flhs->fd, i, 0); - v17 = v15 - v14->buffer_offset; - v18 = sh_size; - if ( v14->buffer_length - v17 < sh_size ) - v18 = v14->buffer_length - v17; - v22.src = &v14->buffer_base[v17]; - sh_size -= v18; - v22.size = v18; - v22.attr = 0; - v22.dest = (void *)((v7->sh_addr) + v12); + sh_size_for_offset = sh_offset_total - rbc->buffer_offset; + sh_size_for_alignment = sh_size; + if ( rbc->buffer_length - sh_size_for_offset < sh_size ) + sh_size_for_alignment = rbc->buffer_length - sh_size_for_offset; + dmat.src = &rbc->buffer_base[sh_size_for_offset]; + sh_size -= sh_size_for_alignment; + dmat.size = sh_size_for_alignment; + dmat.attr = 0; + dmat.dest = (void *)((shdr->sh_addr) + total_offset); CpuSuspendIntr(&state); - v20 = sceSifSetDma(&v22, 1); - v21 = state; - v12 += v18; - v14->dma_handle = v20; - CpuResumeIntr(v21); + total_offset += sh_size_for_alignment; + rbc->dma_handle = sceSifSetDma(&dmat, 1); + CpuResumeIntr(state); allocate_info->ring_buffer_index = (allocate_info->ring_buffer_index + 1) & 1; } printf("\nLoaded, %s:%s\n", flhs->filename, section_name); @@ -545,12 +504,13 @@ int elf_load_all_section( } { int i; - loadfile_elf32_phdr_t *program_headers; - program_headers = flhs->program_header; for ( i = 0; i < flhs->elf_header.e_phnum; i += 1 ) { - if ( program_headers[i].p_type == 1 && program_headers[i].p_filesz && program_headers[i].p_vaddr < 0x80000 ) + const loadfile_elf32_phdr_t *phdr1; + + phdr1 = &(flhs->program_header[i]); + if ( phdr1->p_type == 1 && phdr1->p_filesz && phdr1->p_vaddr < 0x80000 ) { return KE_ILLEGAL_OBJECT; } @@ -582,70 +542,67 @@ static void empty_loadfile_information(loadfile_file_load_handler_struct_t *flhs static int elf_load_common( const char *filename, int epc, const char *section_name, int *result_out, int *result_module_out, int is_mg_elf) { - int *heap_buffer; - int v11; - int v12; - char *v13; - loadfile_allocate_handler_struct_t *p_allocate_info; + int *heap_buffer_cur; + int bufsz; + int bufsz_divisor; + char *read_buffer; int result; loadfile_allocate_handler_struct_t allocate_info; - loadfile_file_load_handler_struct_t flhs; + loadfile_file_load_handler_struct_t flh; SetLoadfileCallbacks_struct_t loadfile_functions; CheckKelfPath_callback_t CheckKelfPath_fnc; SetLoadfileCallbacks_callback_t SetLoadfileCallbacks_fnc; - int v23; - int v24; + int card_port; + int card_slot; printf("%s", "loadelf version 3.30\n"); - empty_loadfile_information(&flhs); - flhs.filename = filename; - flhs.fd = open(filename, 1); - if ( flhs.fd < 0 ) + empty_loadfile_information(&flh); + flh.filename = filename; + flh.fd = open(filename, 1); + if ( flh.fd < 0 ) { printf("Cannot openfile\n"); result = KE_NOFILE; goto finish_returnresult; } - heap_buffer = allocate_heap_buffer(0, 0x10000); - v11 = 0x20000; - if ( heap_buffer == NULL ) + heap_buffer_cur = allocate_heap_buffer(0, 0x10000); + bufsz = 0x20000; + if ( heap_buffer_cur == NULL ) { printf("Error Can't Get heap buffer\n"); result = KE_NO_MEMORY; goto finish_closefd; } - v12 = 0; - for ( ;; ) + bufsz_divisor = 0; + read_buffer = NULL; + while ( read_buffer == NULL ) { CpuDisableIntr(); - v13 = (char *)AllocSysMemory(ALLOC_LAST, v11, NULL); + read_buffer = (char *)AllocSysMemory(ALLOC_LAST, bufsz, NULL); CpuEnableIntr(); - if ( v13 ) + if ( read_buffer ) break; - v11 /= 2; - if ( ++v12 >= 8 ) + bufsz /= 2; + bufsz_divisor += 1; + if ( bufsz_divisor >= 8 ) { printf("Error Can't Get read buffer\n"); result = KE_NO_MEMORY; goto finish_freeheapbuffer; } } - p_allocate_info = &allocate_info; allocate_info.ring_buffer_index = 0; - allocate_info.read_buffer_length = (unsigned int)v11 >> 1; + allocate_info.read_buffer_length = (unsigned int)bufsz >> 1; allocate_info.read_buffer_offset = 0; { int i; for ( i = 0; i < 2; i += 1 ) { - int v16; - - v16 = allocate_info.read_buffer_length * i; - p_allocate_info->ring_buffer_contents[i].buffer_offset = 0; - p_allocate_info->ring_buffer_contents[i].buffer_length = 0; - p_allocate_info->ring_buffer_contents[i].dma_handle = 0; - p_allocate_info->ring_buffer_contents[i].buffer_base = (u8 *)&v13[v16]; + allocate_info.ring_buffer_contents[i].buffer_offset = 0; + allocate_info.ring_buffer_contents[i].buffer_length = 0; + allocate_info.ring_buffer_contents[i].dma_handle = 0; + allocate_info.ring_buffer_contents[i].buffer_base = (u8 *)&read_buffer[allocate_info.read_buffer_length * i]; } } result = KE_ILLEGAL_OBJECT; @@ -660,33 +617,33 @@ static int elf_load_common( loadfile_functions.elf_load_alloc_buffer_from_heap = elf_load_alloc_buffer_from_heap; loadfile_functions.elf_load_dealloc_buffer_from_heap = elf_load_dealloc_buffer_from_heap; SetLoadfileCallbacks_fnc(&loadfile_functions); - if ( CheckKelfPath_fnc && CheckKelfPath_fnc(filename, &v23, &v24) ) + if ( CheckKelfPath_fnc && CheckKelfPath_fnc(filename, &card_port, &card_slot) ) { if ( loadfile_functions.load_kelf_from_card ) { - result = - loadfile_functions.load_kelf_from_card(&allocate_info, &flhs, v23, v24, result_out, result_module_out); + result = loadfile_functions.load_kelf_from_card( + &allocate_info, &flh, card_port, card_slot, result_out, result_module_out); } } else if ( loadfile_functions.load_kelf_from_disk ) { - result = loadfile_functions.load_kelf_from_disk(&allocate_info, &flhs, result_out, result_module_out); + result = loadfile_functions.load_kelf_from_disk(&allocate_info, &flh, result_out, result_module_out); } } } else if ( !strcmp(section_name, "all") ) { - result = elf_load_all_section(&allocate_info, &flhs, result_out, result_module_out); + result = elf_load_all_section(&allocate_info, &flh, result_out, result_module_out); } else { - result = elf_load_single_section(&allocate_info, &flhs, epc, section_name); + result = elf_load_single_section(&allocate_info, &flh, epc, section_name); } - FreeSysMemory(v13); + FreeSysMemory(read_buffer); finish_freeheapbuffer: - FreeSysMemory(heap_buffer); + FreeSysMemory(heap_buffer_cur); finish_closefd: - close(flhs.fd); + close(flh.fd); finish_returnresult: return result; } diff --git a/iop/system/loadfile/src/loadfile.c b/iop/system/loadfile/src/loadfile.c index 4932caea314..760da87ecae 100644 --- a/iop/system/loadfile/src/loadfile.c +++ b/iop/system/loadfile/src/loadfile.c @@ -18,50 +18,50 @@ IRX_ID("LoadModuleByEE", 0, 0); #endif // Mostly based on the module from SCE SDK 1.3.4, with additions from 110U ROM. -static void loadfile_rpc_start_thread(void *param); +static void loadfile_rpc_service_thread(void *param); int _start(int argc, char *argv[]) { - int *BootMode; - int thread_id; - iop_thread_t thread_param; + const int *BootMode_3; + int thid; + iop_thread_t thparam; FlushDcache(); - BootMode = QueryBootMode(3); - if ( BootMode ) + BootMode_3 = QueryBootMode(3); + if ( BootMode_3 ) { - int iop_boot_param; + int BootMode_3_1; - iop_boot_param = BootMode[1]; - if ( (iop_boot_param & 1) != 0 ) + BootMode_3_1 = BootMode_3[1]; + if ( (BootMode_3_1 & 1) != 0 ) { printf(" No SIF service(loadfile)\n"); return MODULE_NO_RESIDENT_END; } - if ( (iop_boot_param & 2) != 0 ) + if ( (BootMode_3_1 & 2) != 0 ) { printf(" No LoadFile service\n"); return MODULE_NO_RESIDENT_END; } } CpuEnableIntr(); - thread_param.attr = 0x2000000; - thread_param.thread = loadfile_rpc_start_thread; - thread_param.priority = 88; - thread_param.stacksize = 4096; - thread_param.option = 0; - thread_id = CreateThread(&thread_param); - if ( thread_id <= 0 ) + thparam.attr = 0x2000000; + thparam.thread = loadfile_rpc_service_thread; + thparam.priority = 88; + thparam.stacksize = 4096; + thparam.option = 0; + thid = CreateThread(&thparam); + if ( thid <= 0 ) { return MODULE_NO_RESIDENT_END; } - StartThread(thread_id, 0); + StartThread(thid, 0); return MODULE_RESIDENT_END; } -static int *loadfile_modload(struct _lf_module_load_arg *in_packet, int length, int *outbuffer) +static int *loadfile_modload(const struct _lf_module_load_arg *in_packet, int length, int *outbuffer) { - char *path; + const char *path; path = in_packet->path; if ( IsIllegalBootDevice(path) ) @@ -77,11 +77,11 @@ static int *loadfile_modload(struct _lf_module_load_arg *in_packet, int length, return outbuffer; } -static int *loadfile_elfload(struct _lf_elf_load_arg *in_packet, int length, int *outbuffer) +static int *loadfile_elfload(const struct _lf_elf_load_arg *in_packet, int length, int *outbuffer) { - char *path; - int v5; - int v6; + const char *path; + int result_out; + int result_module_out; path = in_packet->path; if ( IsIllegalBootDevice(path) ) @@ -90,27 +90,25 @@ static int *loadfile_elfload(struct _lf_elf_load_arg *in_packet, int length, int } else { - int v4; - printf("loadelf: fname %s secname %s\n", path, in_packet->secname); - v4 = loadfile_elfload_innerproc(path, in_packet->epc, in_packet->secname, &v5, &v6); - outbuffer[0] = v4; - if ( v4 >= 0 ) + outbuffer[0] = + loadfile_elfload_innerproc(path, in_packet->epc, in_packet->secname, &result_out, &result_module_out); + if ( outbuffer[0] >= 0 ) { outbuffer[2] = 0; - outbuffer[0] = v5; - outbuffer[1] = v6; + outbuffer[0] = result_out; + outbuffer[1] = result_module_out; } else { - outbuffer[3] = v4; + outbuffer[3] = outbuffer[0]; outbuffer[0] = 0; } } return outbuffer; } -static int *loadfile_setaddr(struct _lf_iop_val_arg *in_packet, int length, int *outbuffer) +static int *loadfile_setaddr(const struct _lf_iop_val_arg *in_packet, int length, int *outbuffer) { void *iop_addr; int type; @@ -136,7 +134,7 @@ static int *loadfile_setaddr(struct _lf_iop_val_arg *in_packet, int length, int return outbuffer; } -static int *loadfile_getaddr(struct _lf_iop_val_arg *in_packet, int length, int *outbuffer) +static int *loadfile_getaddr(const struct _lf_iop_val_arg *in_packet, int length, int *outbuffer) { void *iop_addr; int type; @@ -162,23 +160,24 @@ static int *loadfile_getaddr(struct _lf_iop_val_arg *in_packet, int length, int return outbuffer; } -static int *loadfile_mg_modload(struct _lf_module_load_arg *in_packet, int length, int *outbuffer) +static int *loadfile_mg_modload(const struct _lf_module_load_arg *in_packet, int length, int *outbuffer) { outbuffer[0] = LoadStartKelfModule(in_packet->path, in_packet->p.arg_len, in_packet->args, &outbuffer[1]); return outbuffer; } -static int *loadfile_mg_elfload(struct _lf_elf_load_arg *in_packet, int length, int *outbuffer) +static int *loadfile_mg_elfload(const struct _lf_elf_load_arg *in_packet, int length, int *outbuffer) { - int v2; - int v3; + int result_out; + int result_module_out; - outbuffer[0] = loadfile_mg_elfload_proc(in_packet->path, in_packet->epc, in_packet->secname, &v2, &v3); + outbuffer[0] = + loadfile_mg_elfload_proc(in_packet->path, in_packet->epc, in_packet->secname, &result_out, &result_module_out); if ( outbuffer[0] >= 0 ) { outbuffer[2] = 0; - outbuffer[0] = v2; - outbuffer[1] = v3; + outbuffer[0] = result_out; + outbuffer[1] = result_module_out; } else { @@ -188,7 +187,7 @@ static int *loadfile_mg_elfload(struct _lf_elf_load_arg *in_packet, int length, } // The following function was added in 110U ROM. -static int *loadfile_loadmodulebuffer(struct _lf_module_buffer_load_arg *in_packet, int length, int *outbuffer) +static int *loadfile_loadmodulebuffer(const struct _lf_module_buffer_load_arg *in_packet, int length, int *outbuffer) { int ModuleBuffer; @@ -235,7 +234,7 @@ static SifRpcDataQueue_t loadfile_rpc_service_queue __attribute__((aligned(16))) static SifRpcServerData_t loadfile_rpc_service_data __attribute__((aligned(16))); static int loadfile_rpc_service_in_buf[0x112] __attribute__((aligned(16))); -static void loadfile_rpc_start_thread(void *param) +static void loadfile_rpc_service_thread(void *param) { (void)param; From 592cb9e9cc97417548728d9e2ba524337a757c16 Mon Sep 17 00:00:00 2001 From: Julian Uy Date: Fri, 22 Mar 2024 23:30:18 -0500 Subject: [PATCH 4/4] fix: [loadfile] fix instances of -Wunused-parameter --- iop/system/loadfile/src/eeelfloader.c | 6 ++++++ iop/system/loadfile/src/loadfile.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/iop/system/loadfile/src/eeelfloader.c b/iop/system/loadfile/src/eeelfloader.c index cd9fadfa32c..09dfa922b6e 100644 --- a/iop/system/loadfile/src/eeelfloader.c +++ b/iop/system/loadfile/src/eeelfloader.c @@ -22,6 +22,8 @@ static int *allocate_heap_buffer(unsigned int lower_bound, unsigned int upper_bo { unsigned int upper_bound_rounded; + (void)lower_bound; + upper_bound_rounded = upper_bound; // Align to 4 bytes if ( (upper_bound_rounded & 3) != 0 ) @@ -306,6 +308,8 @@ static int fileio_reader_function(int fd, loadfile_allocate_handler_struct_t *al loadfile_ee_elf_ringbuffer_content_t *rbc; int read_res; + (void)userdata; + read_buffer_offset = allocate_info->read_buffer_offset; rbc = &allocate_info->ring_buffer_contents[allocate_info->ring_buffer_index]; rbc->buffer_offset = read_buffer_offset; @@ -415,6 +419,8 @@ static int elf_load_single_section( SifDmaTransfer_t dmat; int state; + (void)epc; + shdr = NULL; if ( read(flhs->fd, &flhs->elf_header, 0x34) != 0x34 ) { diff --git a/iop/system/loadfile/src/loadfile.c b/iop/system/loadfile/src/loadfile.c index 760da87ecae..ff18645dde3 100644 --- a/iop/system/loadfile/src/loadfile.c +++ b/iop/system/loadfile/src/loadfile.c @@ -26,6 +26,9 @@ int _start(int argc, char *argv[]) int thid; iop_thread_t thparam; + (void)argc; + (void)argv; + FlushDcache(); BootMode_3 = QueryBootMode(3); if ( BootMode_3 ) @@ -63,6 +66,8 @@ static int *loadfile_modload(const struct _lf_module_load_arg *in_packet, int le { const char *path; + (void)length; + path = in_packet->path; if ( IsIllegalBootDevice(path) ) { @@ -83,6 +88,8 @@ static int *loadfile_elfload(const struct _lf_elf_load_arg *in_packet, int lengt int result_out; int result_module_out; + (void)length; + path = in_packet->path; if ( IsIllegalBootDevice(path) ) { @@ -113,6 +120,8 @@ static int *loadfile_setaddr(const struct _lf_iop_val_arg *in_packet, int length void *iop_addr; int type; + (void)length; + iop_addr = (void *)in_packet->p.iop_addr; type = in_packet->type; printf("set val add %p type %x ", iop_addr, type); @@ -139,6 +148,8 @@ static int *loadfile_getaddr(const struct _lf_iop_val_arg *in_packet, int length void *iop_addr; int type; + (void)length; + iop_addr = (void *)in_packet->p.iop_addr; type = in_packet->type; printf("get val add %p type %x ", iop_addr, type); @@ -162,6 +173,8 @@ static int *loadfile_getaddr(const struct _lf_iop_val_arg *in_packet, int length static int *loadfile_mg_modload(const struct _lf_module_load_arg *in_packet, int length, int *outbuffer) { + (void)length; + outbuffer[0] = LoadStartKelfModule(in_packet->path, in_packet->p.arg_len, in_packet->args, &outbuffer[1]); return outbuffer; } @@ -171,6 +184,8 @@ static int *loadfile_mg_elfload(const struct _lf_elf_load_arg *in_packet, int le int result_out; int result_module_out; + (void)length; + outbuffer[0] = loadfile_mg_elfload_proc(in_packet->path, in_packet->epc, in_packet->secname, &result_out, &result_module_out); if ( outbuffer[0] >= 0 ) @@ -191,6 +206,8 @@ static int *loadfile_loadmodulebuffer(const struct _lf_module_buffer_load_arg *i { int ModuleBuffer; + (void)length; + printf("loadbuffer: addrres %x args %d arg %s\n", in_packet->p.result, in_packet->q.arg_len, in_packet->args); ModuleBuffer = LoadModuleBuffer(in_packet->p.ptr); if ( ModuleBuffer >= 0 )