From 77975a3b203577ed2c6247db5cd6cf7094449578 Mon Sep 17 00:00:00 2001 From: EllipticEllipsis Date: Wed, 26 Oct 2022 02:48:37 +0100 Subject: [PATCH] Format libc_impl (#34) * Format libc_impl * Octal constants in comments --- libc_impl.c | 574 ++++++++++++++++++++++++++-------------------------- 1 file changed, 289 insertions(+), 285 deletions(-) diff --git a/libc_impl.c b/libc_impl.c index 78970c4..b20c327 100644 --- a/libc_impl.c +++ b/libc_impl.c @@ -40,10 +40,11 @@ #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) -#define STRING(param) size_t param##_len = wrapper_strlen(mem, param##_addr); \ - char param[param##_len + 1]; \ - for (size_t i = 0; i <= param##_len; i++) { \ - param[i] = MEM_S8(param##_addr + i); \ +#define STRING(param) \ + size_t param##_len = wrapper_strlen(mem, param##_addr); \ + char param[param##_len + 1]; \ + for (size_t i = 0; i <= param##_len; i++) { \ + param[i] = MEM_S8(param##_addr + i); \ } #if !defined(IDO53) && !defined(IDO71) && !defined(IDO72) @@ -73,19 +74,19 @@ #ifdef IDO72 // IDO 7.2 -#define IOB_ADDR 0x0fb49454 +#define IOB_ADDR 0x0fb49454 #define ERRNO_ADDR 0x0fb49290 #define CTYPE_ADDR 0x0fb46db0 -#define LIBC_ADDR 0x0fb46000 -#define LIBC_SIZE 0x4000 +#define LIBC_ADDR 0x0fb46000 +#define LIBC_SIZE 0x4000 #endif #define STDIN_ADDR IOB_ADDR #define STDOUT_ADDR (IOB_ADDR + 0x10) #define STDERR_ADDR (IOB_ADDR + 0x20) -#define STDIN ((struct FILE_irix *)&MEM_U32(STDIN_ADDR)) -#define STDOUT ((struct FILE_irix *)&MEM_U32(STDOUT_ADDR)) -#define STDERR ((struct FILE_irix *)&MEM_U32(STDERR_ADDR)) +#define STDIN ((struct FILE_irix*)&MEM_U32(STDIN_ADDR)) +#define STDOUT ((struct FILE_irix*)&MEM_U32(STDOUT_ADDR)) +#define STDERR ((struct FILE_irix*)&MEM_U32(STDERR_ADDR)) #define MALLOC_BINS_ADDR custom_libc_data_addr #define STRTOK_DATA_ADDR (MALLOC_BINS_ADDR + (30 - 3) * 4) @@ -101,9 +102,9 @@ #define IOEOF 0020 /* EOF reached on read */ #define IOERR 0040 /* I/O error from system */ -#define IOREAD 0001 /* currently reading */ -#define IOWRT 0002 /* currently writing */ -#define IORW 0200 /* opened for reading and writing */ +#define IOREAD 0001 /* currently reading */ +#define IOWRT 0002 /* currently writing */ +#define IORW 0200 /* opened for reading and writing */ #define IOMYBUF 0010 /* stdio malloc()'d buffer */ #define STDIO_BUFSIZE 16384 @@ -124,8 +125,9 @@ struct FILE_irix { static struct { struct { - uint64_t (*trampoline)(uint8_t *mem, uint32_t sp, uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t fp_dest); - uint8_t *mem; + uint64_t (*trampoline)(uint8_t* mem, uint32_t sp, uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3, + uint32_t fp_dest); + uint8_t* mem; uint32_t fp_dest; } handlers[65]; volatile uint32_t recursion_level; @@ -144,42 +146,43 @@ static uint32_t custom_libc_data_addr; #define _B 0100 /* Blank */ #define _X 0200 /* heXadecimal digit */ -static char ctype[] = { 0, - -/* 0 1 2 3 4 5 6 7 */ - -/* 0*/ _C, _C, _C, _C, _C, _C, _C, _C, -/* 10*/ _C, _S|_C, _S|_C, _S|_C, _S|_C, _S|_C, _C, _C, -/* 20*/ _C, _C, _C, _C, _C, _C, _C, _C, -/* 30*/ _C, _C, _C, _C, _C, _C, _C, _C, -/* 40*/ _S|_B, _P, _P, _P, _P, _P, _P, _P, -/* 50*/ _P, _P, _P, _P, _P, _P, _P, _P, -/* 60*/ _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, -/* 70*/ _N|_X, _N|_X, _P, _P, _P, _P, _P, _P, -/*100*/ _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, -/*110*/ _U, _U, _U, _U, _U, _U, _U, _U, -/*120*/ _U, _U, _U, _U, _U, _U, _U, _U, -/*130*/ _U, _U, _U, _P, _P, _P, _P, _P, -/*140*/ _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, -/*150*/ _L, _L, _L, _L, _L, _L, _L, _L, -/*160*/ _L, _L, _L, _L, _L, _L, _L, _L, -/*170*/ _L, _L, _L, _P, _P, _P, _P, _C, -/*200*/ 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 +static char ctype[] = { + 0, + // clang-format off +/* 00 01 02 03 04 05 06 07 */ +/* 0 */ _C, _C, _C, _C, _C, _C, _C, _C, +/* 010 */ _C, _S|_C, _S|_C, _S|_C, _S|_C, _S|_C, _C, _C, +/* 020 */ _C, _C, _C, _C, _C, _C, _C, _C, +/* 030 */ _C, _C, _C, _C, _C, _C, _C, _C, +/* 040 */ _S|_B, _P, _P, _P, _P, _P, _P, _P, +/* 050 */ _P, _P, _P, _P, _P, _P, _P, _P, +/* 060 */ _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, +/* 070 */ _N|_X, _N|_X, _P, _P, _P, _P, _P, _P, +/* 0100 */ _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, +/* 0110 */ _U, _U, _U, _U, _U, _U, _U, _U, +/* 0120 */ _U, _U, _U, _U, _U, _U, _U, _U, +/* 0130 */ _U, _U, _U, _P, _P, _P, _P, _P, +/* 0140 */ _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, +/* 0150 */ _L, _L, _L, _L, _L, _L, _L, _L, +/* 0160 */ _L, _L, _L, _L, _L, _L, _L, _L, +/* 0170 */ _L, _L, _L, _P, _P, _P, _P, _C, +/* 0200 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0210 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0220 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0230 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0240 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0250 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0260 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0270 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0300 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0310 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0320 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0330 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0340 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0350 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0360 */ 0, 0, 0, 0, 0, 0, 0, 0, +/* 0370 */ 0, 0, 0, 0, 0, 0, 0, 0, + // clang-format on }; #define REDIRECT_USR_LIB @@ -189,7 +192,6 @@ static char bin_dir[PATH_MAX + 1]; #endif static int g_file_max = 3; - /* Compilation Target/Emulation Host Page Size Determination */ #if defined(__CYGWIN__) || (defined(__linux__) && defined(__aarch64__)) #define RUNTIME_PAGESIZE @@ -211,15 +213,15 @@ static size_t g_Pagesize; #define ROUND_PAGE(x) (TRUNC_PAGE((x) + (0x1000 - 1))) #endif /* PageSize Macros */ -static uint8_t *memory_map(size_t length) -{ +static uint8_t* memory_map(size_t length) { #ifdef __CYGWIN__ - uint8_t *mem = mmap(0, length, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); + uint8_t* mem = mmap(0, length, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0); #else - uint8_t *mem = mmap(0, length, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + uint8_t* mem = mmap(0, length, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); #endif - assert(TRUNC_PAGE((uintptr_t)mem) == (uintptr_t)mem && "Page size too small, try increasing `page_size` in recomp.cpp"); + assert(TRUNC_PAGE((uintptr_t)mem) == (uintptr_t)mem && + "Page size too small, try increasing `page_size` in recomp.cpp"); if (mem == MAP_FAILED) { perror("mmap (memory_map)"); exit(1); @@ -227,8 +229,7 @@ static uint8_t *memory_map(size_t length) return mem; } -static void memory_allocate(uint8_t *mem, uint32_t start, uint32_t end) -{ +static void memory_allocate(uint8_t* mem, uint32_t start, uint32_t end) { assert(start >= MEM_REGION_START); assert(end <= MEM_REGION_START + MEM_REGION_SIZE); // `start` will be passed to mmap, @@ -238,12 +239,12 @@ static void memory_allocate(uint8_t *mem, uint32_t start, uint32_t end) uintptr_t _start = TRUNC_PAGE((uintptr_t)mem + start); uintptr_t _end = ROUND_PAGE((uintptr_t)mem + end); - if(mprotect((void*)_start, _end - _start, PROT_READ | PROT_WRITE) < 0) { + if (mprotect((void*)_start, _end - _start, PROT_READ | PROT_WRITE) < 0) { perror("mprotect (memory_allocate)"); exit(1); } #else - void *addr = (void *)TRUNC_PAGE((uintptr_t)mem + start); + void* addr = (void*)TRUNC_PAGE((uintptr_t)mem + start); size_t len = end - start; if (mmap(addr, len, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0) == MAP_FAILED) { @@ -253,17 +254,15 @@ static void memory_allocate(uint8_t *mem, uint32_t start, uint32_t end) #endif /* __CYGWIN__ */ } -static void memory_unmap(uint8_t *mem, size_t length) -{ +static void memory_unmap(uint8_t* mem, size_t length) { if (munmap(mem, length)) { perror("munmap"); exit(1); } } - -static void free_all_file_bufs(uint8_t *mem) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(IOB_ADDR); +static void free_all_file_bufs(uint8_t* mem) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(IOB_ADDR); for (int i = 0; i < g_file_max; i++) { if (f[i]._flag & IOMYBUF) { wrapper_free(mem, f[i]._base_addr); @@ -274,7 +273,7 @@ static void free_all_file_bufs(uint8_t *mem) { static void find_bin_dir(void) { #ifdef REDIRECT_USR_LIB // gets the current executable's path - char path[PATH_MAX + 1] = {0}; + char path[PATH_MAX + 1] = { 0 }; #ifdef __CYGWIN__ uint32_t size = GetModuleFileName(NULL, path, PATH_MAX); if (size == 0 || size == PATH_MAX) { @@ -288,7 +287,7 @@ static void find_bin_dir(void) { #else ssize_t size = readlink("/proc/self/exe", path, PATH_MAX); if (size < 0 || size == PATH_MAX) { - char *ido_cc = NULL; + char* ido_cc = NULL; if ((!(ido_cc = getenv("IDO_CC"))) || (snprintf(path, PATH_MAX, "%s", ido_cc) >= PATH_MAX)) { return; } @@ -299,14 +298,14 @@ static void find_bin_dir(void) { #endif } -void final_cleanup(uint8_t *mem) { +void final_cleanup(uint8_t* mem) { wrapper_fflush(mem, 0); free_all_file_bufs(mem); mem += MEM_REGION_START; memory_unmap(mem, MEM_REGION_SIZE); } -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { int ret; find_bin_dir(); @@ -314,15 +313,15 @@ int main(int argc, char *argv[]) { g_Pagesize = sysconf(_SC_PAGESIZE); #endif /* RUNTIME_PAGESIZE */ - uint8_t *mem = memory_map(MEM_REGION_SIZE); + uint8_t* mem = memory_map(MEM_REGION_SIZE); mem -= MEM_REGION_START; - int run(uint8_t *mem, int argc, char *argv[]); + int run(uint8_t * mem, int argc, char* argv[]); ret = run(mem, argc, argv); final_cleanup(mem); return ret; } -void mmap_initial_data_range(uint8_t *mem, uint32_t start, uint32_t end) { +void mmap_initial_data_range(uint8_t* mem, uint32_t start, uint32_t end) { custom_libc_data_addr = end; #ifdef __APPLE__ end += vm_page_size; @@ -333,7 +332,7 @@ void mmap_initial_data_range(uint8_t *mem, uint32_t start, uint32_t end) { cur_sbrk = end; } -void setup_libc_data(uint8_t *mem) { +void setup_libc_data(uint8_t* mem) { memory_allocate(mem, LIBC_ADDR, (LIBC_ADDR + LIBC_SIZE)); for (size_t i = 0; i < sizeof(ctype); i++) { MEM_S8(CTYPE_ADDR + i) = ctype[i]; @@ -346,7 +345,7 @@ void setup_libc_data(uint8_t *mem) { STDERR->_file = 2; } -static uint32_t strcpy1(uint8_t *mem, uint32_t dest_addr, const char *str) { +static uint32_t strcpy1(uint8_t* mem, uint32_t dest_addr, const char* str) { for (;;) { char c = *str; ++str; @@ -358,7 +357,7 @@ static uint32_t strcpy1(uint8_t *mem, uint32_t dest_addr, const char *str) { } } -static uint32_t strcpy2(uint8_t *mem, uint32_t dest_addr, uint32_t src_addr) { +static uint32_t strcpy2(uint8_t* mem, uint32_t dest_addr, uint32_t src_addr) { for (;;) { char c = MEM_S8(src_addr); ++src_addr; @@ -370,7 +369,7 @@ static uint32_t strcpy2(uint8_t *mem, uint32_t dest_addr, uint32_t src_addr) { } } -uint32_t wrapper_sbrk(uint8_t *mem, int increment) { +uint32_t wrapper_sbrk(uint8_t* mem, int increment) { uint32_t old = cur_sbrk; size_t alignedInc = ROUND_PAGE(old + increment) - old; memory_allocate(mem, old, old + alignedInc); @@ -420,7 +419,7 @@ size_t mem_allocated; size_t max_mem_used; size_t num_sbrks; size_t num_allocs; -uint32_t wrapper_malloc(uint8_t *mem, uint32_t size) { +uint32_t wrapper_malloc(uint8_t* mem, uint32_t size) { int bin = -1; for (int i = 3; i < 30; i++) { if (size <= (1 << i)) { @@ -466,14 +465,14 @@ uint32_t wrapper_malloc(uint8_t *mem, uint32_t size) { return node_ptr + 8; } -uint32_t wrapper_calloc(uint8_t *mem, uint32_t num, uint32_t size) { +uint32_t wrapper_calloc(uint8_t* mem, uint32_t num, uint32_t size) { uint64_t new_size = (uint64_t)num * size; assert(new_size == (uint32_t)new_size); uint32_t ret = wrapper_malloc(mem, new_size); return wrapper_memset(mem, ret, 0, new_size); } -uint32_t wrapper_realloc(uint8_t *mem, uint32_t data_addr, uint32_t size) { +uint32_t wrapper_realloc(uint8_t* mem, uint32_t data_addr, uint32_t size) { if (data_addr == 0) { return wrapper_malloc(mem, size); } else { @@ -496,7 +495,7 @@ uint32_t wrapper_realloc(uint8_t *mem, uint32_t data_addr, uint32_t size) { } } -void wrapper_free(uint8_t *mem, uint32_t data_addr) { +void wrapper_free(uint8_t* mem, uint32_t data_addr) { uint32_t node_ptr = data_addr - 8; int bin = MEM_U32(node_ptr); uint32_t size = MEM_U32(node_ptr + 4); @@ -509,8 +508,8 @@ void wrapper_free(uint8_t *mem, uint32_t data_addr) { mem_used -= size; } -int wrapper_fscanf(uint8_t *mem, uint32_t fp_addr, uint32_t format_addr, uint32_t sp) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +int wrapper_fscanf(uint8_t* mem, uint32_t fp_addr, uint32_t format_addr, uint32_t sp) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); STRING(format) // for debug int ret = 0; @@ -536,7 +535,7 @@ int wrapper_fscanf(uint8_t *mem, uint32_t fp_addr, uint32_t format_addr, uint32_ } } bool l = false; - continue_format: + continue_format: switch (c) { case 'l': assert(!l && "ll not implemented in fscanf"); @@ -544,8 +543,7 @@ int wrapper_fscanf(uint8_t *mem, uint32_t fp_addr, uint32_t format_addr, uint32_ c = MEM_S8(format_addr); ++format_addr; goto continue_format; - case 'd': - { + case 'd': { int64_t num = 0; int sign = 1; bool found_first = false; @@ -586,7 +584,7 @@ int wrapper_fscanf(uint8_t *mem, uint32_t fp_addr, uint32_t format_addr, uint32_ } else if (c == '\0') { break; } else { - percent: + percent: ch = wrapper_fgetc(mem, fp_addr); if (ch == -1) { break; @@ -600,7 +598,7 @@ int wrapper_fscanf(uint8_t *mem, uint32_t fp_addr, uint32_t format_addr, uint32_ return ret; } -int wrapper_printf(uint8_t *mem, uint32_t format_addr, uint32_t sp) { +int wrapper_printf(uint8_t* mem, uint32_t format_addr, uint32_t sp) { STRING(format) if (!strcmp(format, " child died due to signal %d.\n")) { printf(format, MEM_U32(sp + 4)); @@ -610,7 +608,7 @@ int wrapper_printf(uint8_t *mem, uint32_t format_addr, uint32_t sp) { return 0; } -int wrapper_sprintf(uint8_t *mem, uint32_t str_addr, uint32_t format_addr, uint32_t sp) { +int wrapper_sprintf(uint8_t* mem, uint32_t str_addr, uint32_t format_addr, uint32_t sp) { STRING(format) // for debug char temp[32]; @@ -650,7 +648,7 @@ int wrapper_sprintf(uint8_t *mem, uint32_t str_addr, uint32_t format_addr, uint3 ++pos; uint32_t zeros = 0; bool zero_prefix = false; - continue_format: + continue_format: switch (c) { case '\0': goto finish_str; @@ -748,8 +746,8 @@ int wrapper_sprintf(uint8_t *mem, uint32_t str_addr, uint32_t format_addr, uint3 return ret; } -int wrapper_fprintf(uint8_t *mem, uint32_t fp_addr, uint32_t format_addr, uint32_t sp) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +int wrapper_fprintf(uint8_t* mem, uint32_t fp_addr, uint32_t format_addr, uint32_t sp) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); STRING(format) sp += 8; @@ -812,11 +810,10 @@ int wrapper_fprintf(uint8_t *mem, uint32_t fp_addr, uint32_t format_addr, uint32 case 'x': case 'X': case 'c': - case 'u': - { + case 'u': { char buf[32]; - char formatSpecifier[0x100] = {0}; + char formatSpecifier[0x100] = { 0 }; formatSpecifier[0] = '%'; formatSpecifier[1] = width + '0'; @@ -832,8 +829,7 @@ int wrapper_fprintf(uint8_t *mem, uint32_t fp_addr, uint32_t format_addr, uint32 ++ret; break; } - case 's': - { + case 's': { if (wrapper_fputs(mem, MEM_U32(sp), fp_addr) == -1) { return ret; } @@ -850,12 +846,12 @@ int wrapper_fprintf(uint8_t *mem, uint32_t fp_addr, uint32_t format_addr, uint32 return ret; } -int wrapper__doprnt(uint8_t *mem, uint32_t format_addr, uint32_t params_addr, uint32_t fp_addr) { +int wrapper__doprnt(uint8_t* mem, uint32_t format_addr, uint32_t params_addr, uint32_t fp_addr) { assert(0 && "_doprnt not implemented"); return 0; } -uint32_t wrapper_strlen(uint8_t *mem, uint32_t str_addr) { +uint32_t wrapper_strlen(uint8_t* mem, uint32_t str_addr) { uint32_t len = 0; while (MEM_S8(str_addr) != '\0') { ++str_addr; @@ -864,7 +860,7 @@ uint32_t wrapper_strlen(uint8_t *mem, uint32_t str_addr) { return len; } -int wrapper_open(uint8_t *mem, uint32_t pathname_addr, int flags, int mode) { +int wrapper_open(uint8_t* mem, uint32_t pathname_addr, int flags, int mode) { STRING(pathname) int f = flags & O_ACCMODE; if (flags & 0x100) { @@ -887,7 +883,7 @@ int wrapper_open(uint8_t *mem, uint32_t pathname_addr, int flags, int mode) { return fd; } -int wrapper_creat(uint8_t *mem, uint32_t pathname_addr, int mode) { +int wrapper_creat(uint8_t* mem, uint32_t pathname_addr, int mode) { STRING(pathname) int ret = creat(pathname, mode); if (ret < 0) { @@ -896,7 +892,7 @@ int wrapper_creat(uint8_t *mem, uint32_t pathname_addr, int mode) { return ret; } -int wrapper_access(uint8_t *mem, uint32_t pathname_addr, int mode) { +int wrapper_access(uint8_t* mem, uint32_t pathname_addr, int mode) { STRING(pathname) int ret = access(pathname, mode); if (ret != 0) { @@ -905,7 +901,7 @@ int wrapper_access(uint8_t *mem, uint32_t pathname_addr, int mode) { return ret; } -int wrapper_rename(uint8_t *mem, uint32_t oldpath_addr, uint32_t newpath_addr) { +int wrapper_rename(uint8_t* mem, uint32_t oldpath_addr, uint32_t newpath_addr) { STRING(oldpath) STRING(newpath) int ret = rename(oldpath, newpath); @@ -915,9 +911,9 @@ int wrapper_rename(uint8_t *mem, uint32_t oldpath_addr, uint32_t newpath_addr) { return ret; } -int wrapper_utime(uint8_t *mem, uint32_t filename_addr, uint32_t times_addr) { +int wrapper_utime(uint8_t* mem, uint32_t filename_addr, uint32_t times_addr) { STRING(filename) - struct utimbuf buf = {0, 0}; + struct utimbuf buf = { 0, 0 }; int ret = utime(filename, times_addr == 0 ? NULL : &buf); if (ret == 0) { if (times_addr != 0) { @@ -930,7 +926,7 @@ int wrapper_utime(uint8_t *mem, uint32_t filename_addr, uint32_t times_addr) { return ret; } -int wrapper_flock(uint8_t *mem, int fd, int operation) { +int wrapper_flock(uint8_t* mem, int fd, int operation) { int ret = flock(fd, operation); if (ret != 0) { MEM_U32(ERRNO_ADDR) = errno; @@ -938,7 +934,7 @@ int wrapper_flock(uint8_t *mem, int fd, int operation) { return ret; } -int wrapper_chmod(uint8_t *mem, uint32_t path_addr, uint32_t mode) { +int wrapper_chmod(uint8_t* mem, uint32_t path_addr, uint32_t mode) { STRING(path) int ret = chmod(path, mode); if (ret < 0) { @@ -951,11 +947,11 @@ int wrapper_umask(int mode) { return umask(mode); } -uint32_t wrapper_ecvt(uint8_t *mem, double number, int ndigits, uint32_t decpt_addr, uint32_t sign_addr) { +uint32_t wrapper_ecvt(uint8_t* mem, double number, int ndigits, uint32_t decpt_addr, uint32_t sign_addr) { assert(0); } -uint32_t wrapper_fcvt(uint8_t *mem, double number, int ndigits, uint32_t decpt_addr, uint32_t sign_addr) { +uint32_t wrapper_fcvt(uint8_t* mem, double number, int ndigits, uint32_t decpt_addr, uint32_t sign_addr) { assert(0); } @@ -967,23 +963,23 @@ float wrapper_sqrtf(float v) { return sqrtf(v); } -int wrapper_atoi(uint8_t *mem, uint32_t nptr_addr) { +int wrapper_atoi(uint8_t* mem, uint32_t nptr_addr) { STRING(nptr) return atoi(nptr); } -int wrapper_atol(uint8_t *mem, uint32_t nptr_addr) { +int wrapper_atol(uint8_t* mem, uint32_t nptr_addr) { return wrapper_atoi(mem, nptr_addr); } -double wrapper_atof(uint8_t *mem, uint32_t nptr_addr) { +double wrapper_atof(uint8_t* mem, uint32_t nptr_addr) { STRING(nptr); return atof(nptr); } -int wrapper_strtol(uint8_t *mem, uint32_t nptr_addr, uint32_t endptr_addr, int base) { +int wrapper_strtol(uint8_t* mem, uint32_t nptr_addr, uint32_t endptr_addr, int base) { STRING(nptr) - char *endptr = NULL; + char* endptr = NULL; int64_t res = strtoll(nptr, endptr_addr != 0 ? &endptr : NULL, base); if (res > INT_MAX) { MEM_U32(ERRNO_ADDR) = ERANGE; @@ -999,9 +995,9 @@ int wrapper_strtol(uint8_t *mem, uint32_t nptr_addr, uint32_t endptr_addr, int b return res; } -uint32_t wrapper_strtoul(uint8_t *mem, uint32_t nptr_addr, uint32_t endptr_addr, int base) { +uint32_t wrapper_strtoul(uint8_t* mem, uint32_t nptr_addr, uint32_t endptr_addr, int base) { STRING(nptr) - char *endptr = NULL; + char* endptr = NULL; uint64_t res = strtoull(nptr, endptr_addr != 0 ? &endptr : NULL, base); if (res > INT_MAX) { MEM_U32(ERRNO_ADDR) = ERANGE; @@ -1013,9 +1009,9 @@ uint32_t wrapper_strtoul(uint8_t *mem, uint32_t nptr_addr, uint32_t endptr_addr, return res; } -int64_t wrapper_strtoll(uint8_t *mem, uint32_t nptr_addr, uint32_t endptr_addr, int base) { +int64_t wrapper_strtoll(uint8_t* mem, uint32_t nptr_addr, uint32_t endptr_addr, int base) { STRING(nptr) - char *endptr = NULL; + char* endptr = NULL; errno = 0; int64_t res = strtoll(nptr, endptr_addr != 0 ? &endptr : NULL, base); if (errno != 0) { @@ -1027,9 +1023,9 @@ int64_t wrapper_strtoll(uint8_t *mem, uint32_t nptr_addr, uint32_t endptr_addr, return res; } -uint64_t wrapper_strtoull(uint8_t *mem, uint32_t nptr_addr, uint32_t endptr_addr, int base) { +uint64_t wrapper_strtoull(uint8_t* mem, uint32_t nptr_addr, uint32_t endptr_addr, int base) { STRING(nptr) - char *endptr = NULL; + char* endptr = NULL; errno = 0; uint64_t res = strtoull(nptr, endptr_addr != 0 ? &endptr : NULL, base); if (errno != 0) { @@ -1041,9 +1037,9 @@ uint64_t wrapper_strtoull(uint8_t *mem, uint32_t nptr_addr, uint32_t endptr_addr return res; } -double wrapper_strtod(uint8_t *mem, uint32_t nptr_addr, uint32_t endptr_addr) { +double wrapper_strtod(uint8_t* mem, uint32_t nptr_addr, uint32_t endptr_addr) { STRING(nptr) - char *endptr = NULL; + char* endptr = NULL; errno = 0; double res = strtod(nptr, endptr_addr != 0 ? &endptr : NULL); if (errno != 0) { @@ -1055,7 +1051,7 @@ double wrapper_strtod(uint8_t *mem, uint32_t nptr_addr, uint32_t endptr_addr) { return res; } -uint32_t wrapper_strchr(uint8_t *mem, uint32_t str_addr, int c) { +uint32_t wrapper_strchr(uint8_t* mem, uint32_t str_addr, int c) { c = c & 0xff; for (;;) { unsigned char ch = MEM_U8(str_addr); @@ -1069,7 +1065,7 @@ uint32_t wrapper_strchr(uint8_t *mem, uint32_t str_addr, int c) { } } -uint32_t wrapper_strrchr(uint8_t *mem, uint32_t str_addr, int c) { +uint32_t wrapper_strrchr(uint8_t* mem, uint32_t str_addr, int c) { c = c & 0xff; uint32_t ret = 0; for (;;) { @@ -1084,7 +1080,7 @@ uint32_t wrapper_strrchr(uint8_t *mem, uint32_t str_addr, int c) { } } -uint32_t wrapper_strcspn(uint8_t *mem, uint32_t str_addr, uint32_t invalid_addr) { +uint32_t wrapper_strcspn(uint8_t* mem, uint32_t str_addr, uint32_t invalid_addr) { STRING(invalid) uint32_t n = strlen(invalid); uint32_t pos = 0; @@ -1101,7 +1097,7 @@ uint32_t wrapper_strcspn(uint8_t *mem, uint32_t str_addr, uint32_t invalid_addr) return pos; } -uint32_t wrapper_strpbrk(uint8_t *mem, uint32_t str_addr, uint32_t accept_addr) { +uint32_t wrapper_strpbrk(uint8_t* mem, uint32_t str_addr, uint32_t accept_addr) { STRING(accept) uint32_t n = strlen(accept); char c; @@ -1116,7 +1112,7 @@ uint32_t wrapper_strpbrk(uint8_t *mem, uint32_t str_addr, uint32_t accept_addr) return 0; } -static void stat_common(uint8_t *mem, uint32_t buf_addr, struct stat *statbuf) { +static void stat_common(uint8_t* mem, uint32_t buf_addr, struct stat* statbuf) { struct irix_stat { int st_dev; int pad1[3]; @@ -1151,17 +1147,17 @@ static void stat_common(uint8_t *mem, uint32_t buf_addr, struct stat *statbuf) { s.st_ctim.tv_sec = statbuf->st_ctimespec.tv_sec; s.st_ctim.tv_nsec = statbuf->st_ctimespec.tv_nsec; #else - s.st_atim.tv_sec = statbuf->st_atim.tv_sec; - s.st_atim.tv_nsec = statbuf->st_atim.tv_nsec; - s.st_mtim.tv_sec = statbuf->st_mtim.tv_sec; - s.st_mtim.tv_nsec = statbuf->st_mtim.tv_nsec; - s.st_ctim.tv_sec = statbuf->st_ctim.tv_sec; - s.st_ctim.tv_nsec = statbuf->st_ctim.tv_nsec; + s.st_atim.tv_sec = statbuf->st_atim.tv_sec; + s.st_atim.tv_nsec = statbuf->st_atim.tv_nsec; + s.st_mtim.tv_sec = statbuf->st_mtim.tv_sec; + s.st_mtim.tv_nsec = statbuf->st_mtim.tv_nsec; + s.st_ctim.tv_sec = statbuf->st_ctim.tv_sec; + s.st_ctim.tv_nsec = statbuf->st_ctim.tv_nsec; #endif memcpy(&MEM_U32(buf_addr), &s, sizeof(s)); } -int wrapper_fstat(uint8_t *mem, int fildes, uint32_t buf_addr) { +int wrapper_fstat(uint8_t* mem, int fildes, uint32_t buf_addr) { struct stat statbuf; if (fstat(fildes, &statbuf) < 0) { MEM_U32(ERRNO_ADDR) = errno; @@ -1172,7 +1168,7 @@ int wrapper_fstat(uint8_t *mem, int fildes, uint32_t buf_addr) { } } -int wrapper_stat(uint8_t *mem, uint32_t pathname_addr, uint32_t buf_addr) { +int wrapper_stat(uint8_t* mem, uint32_t pathname_addr, uint32_t buf_addr) { STRING(pathname) struct stat statbuf; if (stat(pathname, &statbuf) < 0) { @@ -1184,7 +1180,7 @@ int wrapper_stat(uint8_t *mem, uint32_t pathname_addr, uint32_t buf_addr) { } } -int wrapper_ftruncate(uint8_t *mem, int fd, int length) { +int wrapper_ftruncate(uint8_t* mem, int fd, int length) { int ret = ftruncate(fd, length); if (ret != 0) { MEM_U32(ERRNO_ADDR) = errno; @@ -1192,7 +1188,7 @@ int wrapper_ftruncate(uint8_t *mem, int fd, int length) { return ret; } -void wrapper_bcopy(uint8_t *mem, uint32_t src_addr, uint32_t dst_addr, uint32_t len) { +void wrapper_bcopy(uint8_t* mem, uint32_t src_addr, uint32_t dst_addr, uint32_t len) { if (dst_addr % 4 == 0 && src_addr % 4 == 0 && len % 4 == 0) { // Use memmove to copy regions that are 4-byte aligned. // This prevents the byte-swapped mem from causing issues when copying normally. @@ -1223,12 +1219,12 @@ void wrapper_bcopy(uint8_t *mem, uint32_t src_addr, uint32_t dst_addr, uint32_t * both pointer should not overlap, (UB otherwise). * Because of this, we only use host bcopy since it can handle overlapping regions */ -uint32_t wrapper_memcpy(uint8_t *mem, uint32_t dst_addr, uint32_t src_addr, uint32_t len) { +uint32_t wrapper_memcpy(uint8_t* mem, uint32_t dst_addr, uint32_t src_addr, uint32_t len) { wrapper_bcopy(mem, src_addr, dst_addr, len); return dst_addr; } -uint32_t wrapper_memccpy(uint8_t *mem, uint32_t dst_addr, uint32_t src_addr, int c, uint32_t len) { +uint32_t wrapper_memccpy(uint8_t* mem, uint32_t dst_addr, uint32_t src_addr, int c, uint32_t len) { while (len--) { uint8_t ch = MEM_U8(src_addr); MEM_U8(dst_addr) = ch; @@ -1241,8 +1237,8 @@ uint32_t wrapper_memccpy(uint8_t *mem, uint32_t dst_addr, uint32_t src_addr, int return 0; } -int wrapper_read(uint8_t *mem, int fd, uint32_t buf_addr, uint32_t nbytes) { - uint8_t *buf = (uint8_t *)malloc(nbytes); +int wrapper_read(uint8_t* mem, int fd, uint32_t buf_addr, uint32_t nbytes) { + uint8_t* buf = (uint8_t*)malloc(nbytes); ssize_t ret = read(fd, buf, nbytes); if (ret < 0) { MEM_U32(ERRNO_ADDR) = errno; @@ -1255,8 +1251,8 @@ int wrapper_read(uint8_t *mem, int fd, uint32_t buf_addr, uint32_t nbytes) { return (int)ret; } -int wrapper_write(uint8_t *mem, int fd, uint32_t buf_addr, uint32_t nbytes) { - uint8_t *buf = (uint8_t *)malloc(nbytes); +int wrapper_write(uint8_t* mem, int fd, uint32_t buf_addr, uint32_t nbytes) { + uint8_t* buf = (uint8_t*)malloc(nbytes); for (size_t i = 0; i < nbytes; i++) { buf[i] = MEM_U8(buf_addr + i); } @@ -1268,7 +1264,7 @@ int wrapper_write(uint8_t *mem, int fd, uint32_t buf_addr, uint32_t nbytes) { return (int)ret; } -static uint32_t init_file(uint8_t *mem, int fd, int i, const char *path, const char *mode) { +static uint32_t init_file(uint8_t* mem, int fd, int i, const char* path, const char* mode) { int flags = O_RDONLY; if (strcmp(mode, "r") == 0 || strcmp(mode, "rb") == 0) { flags = O_RDONLY; @@ -1300,7 +1296,7 @@ static uint32_t init_file(uint8_t *mem, int fd, int i, const char *path, const c return 0; } } - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(IOB_ADDR); + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(IOB_ADDR); uint32_t ret = 0; if (i == -1) { for (i = 3; i < NFILE; i++) { @@ -1323,7 +1319,7 @@ static uint32_t init_file(uint8_t *mem, int fd, int i, const char *path, const c return ret; } -uint32_t wrapper_fopen(uint8_t *mem, uint32_t path_addr, uint32_t mode_addr) { +uint32_t wrapper_fopen(uint8_t* mem, uint32_t path_addr, uint32_t mode_addr) { assert(path_addr != 0); assert(mode_addr != 0); @@ -1332,16 +1328,16 @@ uint32_t wrapper_fopen(uint8_t *mem, uint32_t path_addr, uint32_t mode_addr) { return init_file(mem, -1, -1, path, mode); } -uint32_t wrapper_freopen(uint8_t *mem, uint32_t path_addr, uint32_t mode_addr, uint32_t fp_addr) { +uint32_t wrapper_freopen(uint8_t* mem, uint32_t path_addr, uint32_t mode_addr, uint32_t fp_addr) { STRING(path) STRING(mode) - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); wrapper_fclose(mem, fp_addr); - return init_file(mem, -1, f - (struct FILE_irix *)&MEM_U32(IOB_ADDR), path, mode); + return init_file(mem, -1, f - (struct FILE_irix*)&MEM_U32(IOB_ADDR), path, mode); } -int wrapper_fclose(uint8_t *mem, uint32_t fp_addr) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +int wrapper_fclose(uint8_t* mem, uint32_t fp_addr) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); wrapper_fflush(mem, fp_addr); if (f->_flag & IOMYBUF) { wrapper_free(mem, f->_base_addr); @@ -1351,8 +1347,8 @@ int wrapper_fclose(uint8_t *mem, uint32_t fp_addr) { return 0; } -static int flush_all(uint8_t *mem) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(IOB_ADDR); +static int flush_all(uint8_t* mem) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(IOB_ADDR); int ret = 0; for (int i = 0; i < g_file_max; i++) { if (f[i]._flag & IOWRT) { @@ -1362,12 +1358,12 @@ static int flush_all(uint8_t *mem) { return ret; } -int wrapper_fflush(uint8_t *mem, uint32_t fp_addr) { +int wrapper_fflush(uint8_t* mem, uint32_t fp_addr) { if (fp_addr == 0) { // Flush all return flush_all(mem); } - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); if (f->_flag & IOWRT) { int p = 0; int to_flush = f->_ptr_addr - f->_base_addr; @@ -1387,8 +1383,8 @@ int wrapper_fflush(uint8_t *mem, uint32_t fp_addr) { return 0; } -int wrapper_ftell(uint8_t *mem, uint32_t fp_addr) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +int wrapper_ftell(uint8_t* mem, uint32_t fp_addr) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); int adjust; if (f->_cnt < 0) { f->_cnt = 0; @@ -1410,14 +1406,14 @@ int wrapper_ftell(uint8_t *mem, uint32_t fp_addr) { return res; } -void wrapper_rewind(uint8_t *mem, uint32_t fp_addr) { +void wrapper_rewind(uint8_t* mem, uint32_t fp_addr) { (void)wrapper_fseek(mem, fp_addr, 0, SEEK_SET); - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); f->_flag &= ~IOERR; } -int wrapper_fseek(uint8_t *mem, uint32_t fp_addr, int offset, int origin) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +int wrapper_fseek(uint8_t* mem, uint32_t fp_addr, int offset, int origin) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); int c, p; f->_flag &= ~IOEOF; if (f->_flag & IOREAD) { @@ -1457,7 +1453,7 @@ int wrapper_fseek(uint8_t *mem, uint32_t fp_addr, int offset, int origin) { return 0; } -int wrapper_lseek(uint8_t *mem, int fd, int offset, int whence) { +int wrapper_lseek(uint8_t* mem, int fd, int offset, int whence) { int ret = (int)lseek(fd, offset, whence); if (ret == -1) { MEM_U32(ERRNO_ADDR) = errno; @@ -1465,7 +1461,7 @@ int wrapper_lseek(uint8_t *mem, int fd, int offset, int whence) { return ret; } -int wrapper_dup(uint8_t *mem, int fd) { +int wrapper_dup(uint8_t* mem, int fd) { fd = dup(fd); if (fd < 0) { MEM_U32(ERRNO_ADDR) = errno; @@ -1473,7 +1469,7 @@ int wrapper_dup(uint8_t *mem, int fd) { return fd; } -int wrapper_dup2(uint8_t *mem, int oldfd, int newfd) { +int wrapper_dup2(uint8_t* mem, int oldfd, int newfd) { int fd = dup2(oldfd, newfd); if (fd < 0) { MEM_U32(ERRNO_ADDR) = errno; @@ -1481,7 +1477,7 @@ int wrapper_dup2(uint8_t *mem, int oldfd, int newfd) { return fd; } -int wrapper_pipe(uint8_t *mem, uint32_t pipefd_addr) { +int wrapper_pipe(uint8_t* mem, uint32_t pipefd_addr) { int pipefd[2]; int ret = pipe(pipefd); if (ret == 0) { @@ -1493,17 +1489,17 @@ int wrapper_pipe(uint8_t *mem, uint32_t pipefd_addr) { return ret; } -void wrapper_perror(uint8_t *mem, uint32_t str_addr) { +void wrapper_perror(uint8_t* mem, uint32_t str_addr) { STRING(str) perror(str); } -int wrapper_fdopen(uint8_t *mem, int fd, uint32_t mode_addr) { +int wrapper_fdopen(uint8_t* mem, int fd, uint32_t mode_addr) { STRING(mode) return init_file(mem, fd, -1, NULL, mode); } -uint32_t wrapper_memset(uint8_t *mem, uint32_t dest_addr, int byte, uint32_t n) { +uint32_t wrapper_memset(uint8_t* mem, uint32_t dest_addr, int byte, uint32_t n) { uint32_t saved = dest_addr; if (dest_addr % 4 == 0 && n % 4 == 0) { memset(&MEM_U32(dest_addr), byte, n); @@ -1516,7 +1512,7 @@ uint32_t wrapper_memset(uint8_t *mem, uint32_t dest_addr, int byte, uint32_t n) return saved; } -int wrapper_bcmp(uint8_t *mem, uint32_t s1_addr, uint32_t s2_addr, uint32_t n) { +int wrapper_bcmp(uint8_t* mem, uint32_t s1_addr, uint32_t s2_addr, uint32_t n) { while (n--) { if (MEM_U8(s1_addr) != MEM_U8(s2_addr)) { return 1; @@ -1527,7 +1523,7 @@ int wrapper_bcmp(uint8_t *mem, uint32_t s1_addr, uint32_t s2_addr, uint32_t n) { return 0; } -int wrapper_memcmp(uint8_t *mem, uint32_t s1_addr, uint32_t s2_addr, uint32_t n) { +int wrapper_memcmp(uint8_t* mem, uint32_t s1_addr, uint32_t s2_addr, uint32_t n) { while (n--) { unsigned char c1 = MEM_U8(s1_addr); unsigned char c2 = MEM_U8(s2_addr); @@ -1547,7 +1543,7 @@ int wrapper_getpid(void) { return getpid(); } -int wrapper_getpgrp(uint8_t *mem) { +int wrapper_getpgrp(uint8_t* mem) { int ret = getpgrp(); if (ret == -1) { MEM_U32(ERRNO_ADDR) = errno; @@ -1555,7 +1551,7 @@ int wrapper_getpgrp(uint8_t *mem) { return ret; } -int wrapper_remove(uint8_t *mem, uint32_t path_addr) { +int wrapper_remove(uint8_t* mem, uint32_t path_addr) { STRING(path) int ret = remove(path); if (ret < 0) { @@ -1564,7 +1560,7 @@ int wrapper_remove(uint8_t *mem, uint32_t path_addr) { return ret; } -int wrapper_unlink(uint8_t *mem, uint32_t path_addr) { +int wrapper_unlink(uint8_t* mem, uint32_t path_addr) { if (path_addr == 0) { fprintf(stderr, "Warning: unlink with NULL as arguement\n"); MEM_U32(ERRNO_ADDR) = EFAULT; @@ -1578,7 +1574,7 @@ int wrapper_unlink(uint8_t *mem, uint32_t path_addr) { return ret; } -int wrapper_close(uint8_t *mem, int fd) { +int wrapper_close(uint8_t* mem, int fd) { int ret = close(fd); if (ret < 0) { MEM_U32(ERRNO_ADDR) = errno; @@ -1586,7 +1582,7 @@ int wrapper_close(uint8_t *mem, int fd) { return ret; } -int wrapper_strcmp(uint8_t *mem, uint32_t s1_addr, uint32_t s2_addr) { +int wrapper_strcmp(uint8_t* mem, uint32_t s1_addr, uint32_t s2_addr) { for (;;) { char c1 = MEM_S8(s1_addr); char c2 = MEM_S8(s2_addr); @@ -1601,7 +1597,7 @@ int wrapper_strcmp(uint8_t *mem, uint32_t s1_addr, uint32_t s2_addr) { } } -int wrapper_strncmp(uint8_t *mem, uint32_t s1_addr, uint32_t s2_addr, uint32_t n) { +int wrapper_strncmp(uint8_t* mem, uint32_t s1_addr, uint32_t s2_addr, uint32_t n) { if (n == 0) { return 0; } @@ -1619,7 +1615,7 @@ int wrapper_strncmp(uint8_t *mem, uint32_t s1_addr, uint32_t s2_addr, uint32_t n } } -uint32_t wrapper_strcpy(uint8_t *mem, uint32_t dest_addr, uint32_t src_addr) { +uint32_t wrapper_strcpy(uint8_t* mem, uint32_t dest_addr, uint32_t src_addr) { uint32_t saved = dest_addr; for (;;) { char c = MEM_S8(src_addr); @@ -1632,7 +1628,7 @@ uint32_t wrapper_strcpy(uint8_t *mem, uint32_t dest_addr, uint32_t src_addr) { } } -uint32_t wrapper_strncpy(uint8_t *mem, uint32_t dest_addr, uint32_t src_addr, uint32_t n) { +uint32_t wrapper_strncpy(uint8_t* mem, uint32_t dest_addr, uint32_t src_addr, uint32_t n) { uint32_t i; for (i = 0; i < n && MEM_S8(src_addr) != '\0'; i++) { MEM_S8(dest_addr + i) = MEM_S8(src_addr + i); @@ -1643,7 +1639,7 @@ uint32_t wrapper_strncpy(uint8_t *mem, uint32_t dest_addr, uint32_t src_addr, ui return dest_addr; } -uint32_t wrapper_strcat(uint8_t *mem, uint32_t dest_addr, uint32_t src_addr) { +uint32_t wrapper_strcat(uint8_t* mem, uint32_t dest_addr, uint32_t src_addr) { uint32_t saved = dest_addr; while (MEM_S8(dest_addr) != '\0') { ++dest_addr; @@ -1657,7 +1653,7 @@ uint32_t wrapper_strcat(uint8_t *mem, uint32_t dest_addr, uint32_t src_addr) { return saved; } -uint32_t wrapper_strncat(uint8_t *mem, uint32_t dest_addr, uint32_t src_addr, uint32_t n) { +uint32_t wrapper_strncat(uint8_t* mem, uint32_t dest_addr, uint32_t src_addr, uint32_t n) { uint32_t saved = dest_addr; while (MEM_S8(dest_addr) != '\0') { ++dest_addr; @@ -1671,7 +1667,7 @@ uint32_t wrapper_strncat(uint8_t *mem, uint32_t dest_addr, uint32_t src_addr, ui return saved; } -uint32_t wrapper_strtok(uint8_t *mem, uint32_t str_addr, uint32_t delimiters_addr) { +uint32_t wrapper_strtok(uint8_t* mem, uint32_t str_addr, uint32_t delimiters_addr) { if (str_addr == 0) { str_addr = MEM_U32(STRTOK_DATA_ADDR); } @@ -1682,8 +1678,7 @@ uint32_t wrapper_strtok(uint8_t *mem, uint32_t str_addr, uint32_t delimiters_add uint32_t p; for (p = str_addr; MEM_S8(p) != '\0'; p++) { uint32_t q; - for (q = delimiters_addr; MEM_S8(q) != '\0' && MEM_S8(q) != MEM_S8(p); q++) { - } + for (q = delimiters_addr; MEM_S8(q) != '\0' && MEM_S8(q) != MEM_S8(p); q++) {} if (MEM_S8(q) == '\0') { break; } @@ -1694,8 +1689,7 @@ uint32_t wrapper_strtok(uint8_t *mem, uint32_t str_addr, uint32_t delimiters_add uint32_t ret = p; for (;;) { uint32_t q; - for (q = delimiters_addr; MEM_S8(q) != '\0' && MEM_S8(q) != MEM_S8(p); q++) { - } + for (q = delimiters_addr; MEM_S8(q) != '\0' && MEM_S8(q) != MEM_S8(p); q++) {} if (MEM_S8(q) != '\0') { MEM_S8(p) = '\0'; MEM_U32(STRTOK_DATA_ADDR) = ++p; @@ -1710,7 +1704,7 @@ uint32_t wrapper_strtok(uint8_t *mem, uint32_t str_addr, uint32_t delimiters_add } } -uint32_t wrapper_strstr(uint8_t *mem, uint32_t str1_addr, uint32_t str2_addr) { +uint32_t wrapper_strstr(uint8_t* mem, uint32_t str1_addr, uint32_t str2_addr) { for (;;) { if (MEM_S8(str1_addr) == '\0') { return 0; @@ -1733,7 +1727,7 @@ uint32_t wrapper_strstr(uint8_t *mem, uint32_t str1_addr, uint32_t str2_addr) { } } -uint32_t wrapper_strdup(uint8_t *mem, uint32_t str_addr) { +uint32_t wrapper_strdup(uint8_t* mem, uint32_t str_addr) { uint32_t len = wrapper_strlen(mem, str_addr) + 1; uint32_t ret = wrapper_malloc(mem, len); if (ret == 0) { @@ -1751,8 +1745,8 @@ int wrapper_tolower(int c) { return tolower(c); } -int wrapper_gethostname(uint8_t *mem, uint32_t name_addr, uint32_t len) { - char buf[256] = {0}; +int wrapper_gethostname(uint8_t* mem, uint32_t name_addr, uint32_t len) { + char buf[256] = { 0 }; if (len > 256) { len = 256; } @@ -1767,7 +1761,7 @@ int wrapper_gethostname(uint8_t *mem, uint32_t name_addr, uint32_t len) { return ret; } -int wrapper_isatty(uint8_t *mem, int fd) { +int wrapper_isatty(uint8_t* mem, int fd) { int ret = isatty(fd); if (ret == 0) { MEM_U32(ERRNO_ADDR) = errno; @@ -1775,12 +1769,13 @@ int wrapper_isatty(uint8_t *mem, int fd) { return ret; } -uint32_t wrapper_strftime(uint8_t *mem, uint32_t ptr_addr, uint32_t maxsize, uint32_t format_addr, uint32_t timeptr_addr) { +uint32_t wrapper_strftime(uint8_t* mem, uint32_t ptr_addr, uint32_t maxsize, uint32_t format_addr, + uint32_t timeptr_addr) { MEM_S8(ptr_addr) = 0; return 0; } -int wrapper_times(uint8_t *mem, uint32_t buffer_addr) { +int wrapper_times(uint8_t* mem, uint32_t buffer_addr) { struct tms_irix { int tms_utime; int tms_stime; @@ -1808,9 +1803,9 @@ int wrapper_clock(void) { return (int)clock(); } -uint32_t wrapper_ctime(uint8_t *mem, uint32_t timep_addr) { +uint32_t wrapper_ctime(uint8_t* mem, uint32_t timep_addr) { time_t t = MEM_S32(timep_addr); - char *res = ctime(&t); + char* res = ctime(&t); size_t len = strlen(res) + 1; uint32_t ret_addr = wrapper_malloc(mem, len); uint32_t pos = ret_addr; @@ -1822,7 +1817,7 @@ uint32_t wrapper_ctime(uint8_t *mem, uint32_t timep_addr) { return ret_addr; } -uint32_t wrapper_localtime(uint8_t *mem, uint32_t timep_addr) { +uint32_t wrapper_localtime(uint8_t* mem, uint32_t timep_addr) { time_t t = MEM_S32(timep_addr); struct irix_tm { int tm_sec; @@ -1836,8 +1831,8 @@ uint32_t wrapper_localtime(uint8_t *mem, uint32_t timep_addr) { int tm_isdst; }; uint32_t ret = wrapper_malloc(mem, sizeof(struct irix_tm)); - struct irix_tm *r = (struct irix_tm *)&MEM_U32(ret); - struct tm *l = localtime(&t); + struct irix_tm* r = (struct irix_tm*)&MEM_U32(ret); + struct tm* l = localtime(&t); r->tm_sec = l->tm_sec; r->tm_min = l->tm_min; r->tm_hour = l->tm_hour; @@ -1850,8 +1845,8 @@ uint32_t wrapper_localtime(uint8_t *mem, uint32_t timep_addr) { return ret; } -int wrapper_setvbuf(uint8_t *mem, uint32_t fp_addr, uint32_t buf_addr, int mode, uint32_t size) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +int wrapper_setvbuf(uint8_t* mem, uint32_t fp_addr, uint32_t buf_addr, int mode, uint32_t size) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); wrapper_fflush(mem, fp_addr); if ((f->_flag & IOMYBUF) && f->_base_addr != 0) { wrapper_free(mem, f->_base_addr); @@ -1872,16 +1867,16 @@ int wrapper_setvbuf(uint8_t *mem, uint32_t fp_addr, uint32_t buf_addr, int mode, return 0; } -int wrapper___semgetc(uint8_t *mem, uint32_t fp_addr) { +int wrapper___semgetc(uint8_t* mem, uint32_t fp_addr) { assert(0); } -int wrapper___semputc(uint8_t *mem, int c, uint32_t fp_addr) { +int wrapper___semputc(uint8_t* mem, int c, uint32_t fp_addr) { assert(0); } -int wrapper_fgetc(uint8_t *mem, uint32_t fp_addr) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +int wrapper_fgetc(uint8_t* mem, uint32_t fp_addr) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); if (--f->_cnt < 0) { return wrapper___filbuf(mem, fp_addr); } else { @@ -1891,7 +1886,7 @@ int wrapper_fgetc(uint8_t *mem, uint32_t fp_addr) { } } -int wrapper_fgets(uint8_t *mem, uint32_t str_addr, int count, uint32_t fp_addr) { +int wrapper_fgets(uint8_t* mem, uint32_t str_addr, int count, uint32_t fp_addr) { bool modified = false; uint32_t saved = str_addr; for (count--; count > 0; count--) { @@ -1911,16 +1906,16 @@ int wrapper_fgets(uint8_t *mem, uint32_t str_addr, int count, uint32_t fp_addr) return saved; } -static void file_assign_buffer(uint8_t *mem, struct FILE_irix *f) { +static void file_assign_buffer(uint8_t* mem, struct FILE_irix* f) { f->_base_addr = wrapper_malloc(mem, STDIO_BUFSIZE); f->_ptr_addr = f->_base_addr; f->_flag |= IOMYBUF; f->_cnt = 0; - bufendtab[f - (struct FILE_irix *)&MEM_U32(IOB_ADDR)] = STDIO_BUFSIZE; + bufendtab[f - (struct FILE_irix*)&MEM_U32(IOB_ADDR)] = STDIO_BUFSIZE; } -int wrapper___filbuf(uint8_t *mem, uint32_t fp_addr) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +int wrapper___filbuf(uint8_t* mem, uint32_t fp_addr) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); if (!(f->_flag & IOREAD)) { if (f->_flag & IORW) { f->_flag |= IOREAD; @@ -1949,14 +1944,14 @@ int wrapper___filbuf(uint8_t *mem, uint32_t fp_addr) { return ret; } -int wrapper___flsbuf(uint8_t *mem, int ch, uint32_t fp_addr) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +int wrapper___flsbuf(uint8_t* mem, int ch, uint32_t fp_addr) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); if (wrapper_fflush(mem, fp_addr) != 0) { return -1; } if (f->_base_addr == 0) { file_assign_buffer(mem, f); - f->_cnt = bufendtab[f - (struct FILE_irix *)&MEM_U32(IOB_ADDR)]; + f->_cnt = bufendtab[f - (struct FILE_irix*)&MEM_U32(IOB_ADDR)]; } MEM_U8(f->_ptr_addr) = ch; ++f->_ptr_addr; @@ -1970,8 +1965,8 @@ int wrapper___flsbuf(uint8_t *mem, int ch, uint32_t fp_addr) { return ch; } -int wrapper_ungetc(uint8_t *mem, int ch, uint32_t fp_addr) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +int wrapper_ungetc(uint8_t* mem, int ch, uint32_t fp_addr) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); if (ch == -1 || f->_ptr_addr == f->_base_addr) { return -1; } @@ -1982,7 +1977,7 @@ int wrapper_ungetc(uint8_t *mem, int ch, uint32_t fp_addr) { return ch; } -uint32_t wrapper_gets(uint8_t *mem, uint32_t str_addr) { +uint32_t wrapper_gets(uint8_t* mem, uint32_t str_addr) { uint32_t p, str0 = str_addr; int n; @@ -2015,8 +2010,8 @@ uint32_t wrapper_gets(uint8_t *mem, uint32_t str_addr) { return str0; } -uint32_t wrapper_fread(uint8_t *mem, uint32_t data_addr, uint32_t size, uint32_t count, uint32_t fp_addr) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +uint32_t wrapper_fread(uint8_t* mem, uint32_t data_addr, uint32_t size, uint32_t count, uint32_t fp_addr) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); int nleft = count * size; int n; for (;;) { @@ -2037,11 +2032,11 @@ uint32_t wrapper_fread(uint8_t *mem, uint32_t data_addr, uint32_t size, uint32_t } } -uint32_t wrapper_fwrite(uint8_t *mem, uint32_t data_addr, uint32_t size, uint32_t count, uint32_t fp_addr) { - struct FILE_irix *f = (struct FILE_irix *)&MEM_U32(fp_addr); +uint32_t wrapper_fwrite(uint8_t* mem, uint32_t data_addr, uint32_t size, uint32_t count, uint32_t fp_addr) { + struct FILE_irix* f = (struct FILE_irix*)&MEM_U32(fp_addr); if (size > 0 && count > 0 && f->_base_addr == 0) { file_assign_buffer(mem, f); - f->_cnt = bufendtab[f - (struct FILE_irix *)&MEM_U32(IOB_ADDR)]; + f->_cnt = bufendtab[f - (struct FILE_irix*)&MEM_U32(IOB_ADDR)]; f->_flag |= IOWRT; } uint32_t num_written = 0; @@ -2071,7 +2066,7 @@ uint32_t wrapper_fwrite(uint8_t *mem, uint32_t data_addr, uint32_t size, uint32_ return num_written; } -int wrapper_fputs(uint8_t *mem, uint32_t str_addr, uint32_t fp_addr) { +int wrapper_fputs(uint8_t* mem, uint32_t str_addr, uint32_t fp_addr) { assert(str_addr != 0); uint32_t len = wrapper_strlen(mem, str_addr); @@ -2079,12 +2074,12 @@ int wrapper_fputs(uint8_t *mem, uint32_t str_addr, uint32_t fp_addr) { return ret == 0 && len != 0 ? -1 : 0; } -int wrapper_puts(uint8_t *mem, uint32_t str_addr) { +int wrapper_puts(uint8_t* mem, uint32_t str_addr) { int ret = wrapper_fputs(mem, str_addr, STDOUT_ADDR); if (ret != 0) { return ret; } - struct FILE_irix *f = STDOUT; + struct FILE_irix* f = STDOUT; if (--f->_cnt < 0) { if (wrapper___flsbuf(mem, '\n', STDOUT_ADDR) != '\n') { return -1; @@ -2096,7 +2091,7 @@ int wrapper_puts(uint8_t *mem, uint32_t str_addr) { return 0; } -uint32_t wrapper_getcwd(uint8_t *mem, uint32_t buf_addr, uint32_t size) { +uint32_t wrapper_getcwd(uint8_t* mem, uint32_t buf_addr, uint32_t size) { char buf[size]; if (getcwd(buf, size) == NULL) { MEM_U32(ERRNO_ADDR) = errno; @@ -2110,7 +2105,7 @@ uint32_t wrapper_getcwd(uint8_t *mem, uint32_t buf_addr, uint32_t size) { } } -int wrapper_time(uint8_t *mem, uint32_t tloc_addr) { +int wrapper_time(uint8_t* mem, uint32_t tloc_addr) { time_t ret = time(NULL); if (ret == (time_t)-1) { MEM_U32(ERRNO_ADDR) = errno; @@ -2120,7 +2115,7 @@ int wrapper_time(uint8_t *mem, uint32_t tloc_addr) { return ret; } -void wrapper_bzero(uint8_t *mem, uint32_t str_addr, uint32_t n) { +void wrapper_bzero(uint8_t* mem, uint32_t str_addr, uint32_t n) { while (n--) { MEM_U8(str_addr) = 0; ++str_addr; @@ -2133,7 +2128,7 @@ int wrapper_fp_class_d(double d) { double d; } bits; bits.d = d; - uint32_t a2 = bits.w[1]; + uint32_t a2 = bits.w[1]; uint32_t a1 = a2 >> 20; uint32_t a0 = a1; a2 &= 0xfffff; @@ -2224,43 +2219,43 @@ double wrapper___ll_to_d(int64_t v) { return v; } -void wrapper_abort(uint8_t *mem) { +void wrapper_abort(uint8_t* mem) { abort(); } -void wrapper_exit(uint8_t *mem, int status) { +void wrapper_exit(uint8_t* mem, int status) { final_cleanup(mem); exit(status); } -void wrapper__exit(uint8_t *mem, int status) { +void wrapper__exit(uint8_t* mem, int status) { assert(0 && "_exit not implemented"); // exit() is already overridden } -void wrapper__cleanup(uint8_t *mem) { +void wrapper__cleanup(uint8_t* mem) { } -uint32_t wrapper__rld_new_interface(uint8_t *mem, uint32_t operation, uint32_t sp) { +uint32_t wrapper__rld_new_interface(uint8_t* mem, uint32_t operation, uint32_t sp) { assert(0 && "_rld_new_interface not implemented"); return 0; } -void wrapper__exithandle(uint8_t *mem) { +void wrapper__exithandle(uint8_t* mem) { assert(0 && "_exithandle not implemented"); } -int wrapper__prctl(uint8_t *mem, int operation, uint32_t sp) { +int wrapper__prctl(uint8_t* mem, int operation, uint32_t sp) { assert(0 && "_prctl not implemented"); return 0; } -double wrapper__atod(uint8_t *mem, uint32_t buffer_addr, int ndigits, int dexp) { +double wrapper__atod(uint8_t* mem, uint32_t buffer_addr, int ndigits, int dexp) { // ftp://atoum.hst.nerim.net/irix/src/irix-6.5.5-src/6.5.5/m/irix/lib/libc/src/math/atod.c assert(0 && "_atod not implemented"); return 0.0; } -int wrapper_pathconf(uint8_t *mem, uint32_t path_addr, int name) { +int wrapper_pathconf(uint8_t* mem, uint32_t path_addr, int name) { STRING(path) if (name == 5) { errno = 0; @@ -2274,9 +2269,9 @@ int wrapper_pathconf(uint8_t *mem, uint32_t path_addr, int name) { return 0; } -uint32_t wrapper_getenv(uint8_t *mem, uint32_t name_addr) { +uint32_t wrapper_getenv(uint8_t* mem, uint32_t name_addr) { STRING(name); - const char *value = getenv(name); + const char* value = getenv(name); if (value == NULL) { return 0; } @@ -2286,75 +2281,81 @@ uint32_t wrapper_getenv(uint8_t *mem, uint32_t name_addr) { return buf_addr; } -uint32_t wrapper_gettxt(uint8_t *mem, uint32_t msgid_addr, uint32_t default_str_addr) { +uint32_t wrapper_gettxt(uint8_t* mem, uint32_t msgid_addr, uint32_t default_str_addr) { // Return default for now return default_str_addr; } -uint32_t wrapper_setlocale(uint8_t *mem, int category, uint32_t locale_addr) { +uint32_t wrapper_setlocale(uint8_t* mem, int category, uint32_t locale_addr) { assert(locale_addr != 0); STRING(locale) assert(category == 6); // LC_ALL - char *ret = setlocale(LC_ALL, locale); + char* ret = setlocale(LC_ALL, locale); // Let's hope the caller doesn't use the return value return 0; } -uint32_t wrapper_mmap(uint8_t *mem, uint32_t addr, uint32_t length, int prot, int flags, int fd, int offset) { +uint32_t wrapper_mmap(uint8_t* mem, uint32_t addr, uint32_t length, int prot, int flags, int fd, int offset) { assert(0 && "mmap not implemented"); return 0; } -int wrapper_munmap(uint8_t *mem, uint32_t addr, uint32_t length) { +int wrapper_munmap(uint8_t* mem, uint32_t addr, uint32_t length) { assert(0 && "munmap not implemented"); return 0; } -int wrapper_mprotect(uint8_t *mem, uint32_t addr, uint32_t length, int prot) { +int wrapper_mprotect(uint8_t* mem, uint32_t addr, uint32_t length, int prot) { assert(0 && "mprotect not implemented"); return 0; } -int wrapper_sysconf(uint8_t *mem, int name) { +int wrapper_sysconf(uint8_t* mem, int name) { assert(0 && "sysconf not implemented"); return 0; } -int wrapper_getpagesize(uint8_t *mem) { +int wrapper_getpagesize(uint8_t* mem) { return 4096; } -int wrapper_strerror(uint8_t *mem, int errnum) { +int wrapper_strerror(uint8_t* mem, int errnum) { errno = errnum; perror("strerror"); assert(0 && "strerror not implemented"); return 0; } -int wrapper_ioctl(uint8_t *mem, int fd, uint32_t request, uint32_t sp) { +int wrapper_ioctl(uint8_t* mem, int fd, uint32_t request, uint32_t sp) { assert(0 && "ioctl not implemented"); return 0; } -int wrapper_fcntl(uint8_t *mem, int fd, int cmd, uint32_t sp) { +int wrapper_fcntl(uint8_t* mem, int fd, int cmd, uint32_t sp) { assert(0 && "fcntl not implemented"); return 0; } static void signal_handler(int signum) { uint32_t level = signal_context.recursion_level++; - uint8_t *mem = signal_context.handlers[signum].mem; + uint8_t* mem = signal_context.handlers[signum].mem; uint32_t fp_dest = signal_context.handlers[signum].fp_dest; uint32_t sp = SIGNAL_HANDLER_STACK_START - 16 - level * 0x1000; signal_context.handlers[signum].trampoline(mem, sp, signum, 0, 0, 0, fp_dest); signal_context.recursion_level--; } -uint32_t wrapper_signal(uint8_t *mem, int signum, uint64_t (*trampoline)(uint8_t *mem, uint32_t sp, uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t fp_dest), uint32_t handler_addr, uint32_t sp) { +uint32_t wrapper_signal(uint8_t* mem, int signum, + uint64_t (*trampoline)(uint8_t* mem, uint32_t sp, uint32_t a0, uint32_t a1, uint32_t a2, + uint32_t a3, uint32_t fp_dest), + uint32_t handler_addr, uint32_t sp) { return 0; } -uint32_t wrapper_sigset(uint8_t *mem, int signum, uint64_t (*trampoline)(uint8_t *mem, uint32_t sp, uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t fp_dest), uint32_t disp_addr, uint32_t sp) { +uint32_t wrapper_sigset(uint8_t* mem, int signum, + uint64_t (*trampoline)(uint8_t* mem, uint32_t sp, uint32_t a0, uint32_t a1, uint32_t a2, + uint32_t a3, uint32_t fp_dest), + uint32_t disp_addr, uint32_t sp) { void (*handler)(int) = signal_handler; if ((int)disp_addr >= -1 && (int)disp_addr <= 1) { @@ -2384,28 +2385,28 @@ uint32_t wrapper_sigset(uint8_t *mem, int signum, uint64_t (*trampoline)(uint8_t return (uint32_t)(uintptr_t)sigset(signum, handler); // for now only support SIG_DFL etc. as return value } -int wrapper_get_fpc_csr(uint8_t *mem) { +int wrapper_get_fpc_csr(uint8_t* mem) { return 0; } -int wrapper_set_fpc_csr(uint8_t *mem, int csr) { +int wrapper_set_fpc_csr(uint8_t* mem, int csr) { return 0; } -int wrapper_setjmp(uint8_t *mem, uint32_t addr) { +int wrapper_setjmp(uint8_t* mem, uint32_t addr) { return 0; } -void wrapper_longjmp(uint8_t *mem, uint32_t addr, int status) { +void wrapper_longjmp(uint8_t* mem, uint32_t addr, int status) { assert(0 && "longjmp not implemented"); } -uint32_t wrapper_tempnam(uint8_t *mem, uint32_t dir_addr, uint32_t pfx_addr) { +uint32_t wrapper_tempnam(uint8_t* mem, uint32_t dir_addr, uint32_t pfx_addr) { char template[1024]; int fd; size_t len; uint32_t ret_addr; - const char *tmpdir; + const char* tmpdir; tmpdir = getenv("TMPDIR"); @@ -2451,7 +2452,7 @@ uint32_t wrapper_tempnam(uint8_t *mem, uint32_t dir_addr, uint32_t pfx_addr) { return ret_addr; } -uint32_t wrapper_tmpnam(uint8_t *mem, uint32_t str_addr) { +uint32_t wrapper_tmpnam(uint8_t* mem, uint32_t str_addr) { char template[1024]; int fd; @@ -2471,7 +2472,7 @@ uint32_t wrapper_tmpnam(uint8_t *mem, uint32_t str_addr) { return str_addr; } -uint32_t wrapper_mktemp(uint8_t *mem, uint32_t template_addr) { +uint32_t wrapper_mktemp(uint8_t* mem, uint32_t template_addr) { int fd; STRING(template) @@ -2488,7 +2489,7 @@ uint32_t wrapper_mktemp(uint8_t *mem, uint32_t template_addr) { return template_addr; } -int wrapper_mkstemp(uint8_t *mem, uint32_t name_addr) { +int wrapper_mkstemp(uint8_t* mem, uint32_t name_addr) { STRING(name) int fd = mkstemp(name); if (fd < 0) { @@ -2499,14 +2500,14 @@ int wrapper_mkstemp(uint8_t *mem, uint32_t name_addr) { return fd; } -uint32_t wrapper_tmpfile(uint8_t *mem) { +uint32_t wrapper_tmpfile(uint8_t* mem) { // create and fopen a temporary file that is removed when the program exits - const char *tmpdir = getenv("TMPDIR"); + const char* tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) { tmpdir = "/tmp"; } - char name[PATH_MAX + 1] = {0}; + char name[PATH_MAX + 1] = { 0 }; int n = snprintf(name, sizeof(name), "%s/copt_temp_XXXXXX", tmpdir); if (n < 0 || n >= sizeof(name)) { // This isn't the best errno code, but it is one that can be returned by tmpfile @@ -2531,14 +2532,14 @@ uint32_t wrapper_tmpfile(uint8_t *mem) { return ret; } -int wrapper_wait(uint8_t *mem, uint32_t wstatus_addr) { +int wrapper_wait(uint8_t* mem, uint32_t wstatus_addr) { int wstatus; pid_t ret = wait(&wstatus); MEM_S32(wstatus_addr) = wstatus; return ret; } -int wrapper_kill(uint8_t *mem, int pid, int sig) { +int wrapper_kill(uint8_t* mem, int pid, int sig) { int ret = kill(pid, sig); if (ret != 0) { MEM_U32(ERRNO_ADDR) = errno; @@ -2546,23 +2547,23 @@ int wrapper_kill(uint8_t *mem, int pid, int sig) { return ret; } -int wrapper_execlp(uint8_t *mem, uint32_t file_addr, uint32_t sp) { +int wrapper_execlp(uint8_t* mem, uint32_t file_addr, uint32_t sp) { uint32_t argv_addr = sp + 4; return wrapper_execvp(mem, file_addr, argv_addr); } -int wrapper_execv(uint8_t *mem, uint32_t pathname_addr, uint32_t argv_addr) { +int wrapper_execv(uint8_t* mem, uint32_t pathname_addr, uint32_t argv_addr) { STRING(pathname) uint32_t argc = 0; while (MEM_U32(argv_addr + argc * 4) != 0) { ++argc; } - char *argv[argc + 1]; + char* argv[argc + 1]; for (uint32_t i = 0; i < argc; i++) { uint32_t str_addr = MEM_U32(argv_addr + i * 4); uint32_t len = wrapper_strlen(mem, str_addr) + 1; - argv[i] = (char *)malloc(len); - char *pos = argv[i]; + argv[i] = (char*)malloc(len); + char* pos = argv[i]; while (len--) { *pos++ = MEM_S8(str_addr); ++str_addr; @@ -2577,18 +2578,18 @@ int wrapper_execv(uint8_t *mem, uint32_t pathname_addr, uint32_t argv_addr) { return -1; } -int wrapper_execvp(uint8_t *mem, uint32_t file_addr, uint32_t argv_addr) { +int wrapper_execvp(uint8_t* mem, uint32_t file_addr, uint32_t argv_addr) { STRING(file) uint32_t argc = 0; while (MEM_U32(argv_addr + argc * 4) != 0) { ++argc; } - char *argv[argc + 1]; + char* argv[argc + 1]; for (uint32_t i = 0; i < argc; i++) { uint32_t str_addr = MEM_U32(argv_addr + i * 4); uint32_t len = wrapper_strlen(mem, str_addr) + 1; - argv[i] = (char *)malloc(len); - char *pos = argv[i]; + argv[i] = (char*)malloc(len); + char* pos = argv[i]; while (len--) { *pos++ = MEM_S8(str_addr); ++str_addr; @@ -2623,7 +2624,7 @@ int wrapper_execvp(uint8_t *mem, uint32_t file_addr, uint32_t argv_addr) { return -1; } -int wrapper_fork(uint8_t *mem) { +int wrapper_fork(uint8_t* mem) { int ret = fork(); if (ret == -1) { MEM_U32(ERRNO_ADDR) = errno; @@ -2631,16 +2632,16 @@ int wrapper_fork(uint8_t *mem) { return ret; } -int wrapper_system(uint8_t *mem, uint32_t command_addr) { +int wrapper_system(uint8_t* mem, uint32_t command_addr) { STRING(command) return system(command); // no errno } -static int name_compare(uint8_t *mem, uint32_t a_addr, uint32_t b_addr) { +static int name_compare(uint8_t* mem, uint32_t a_addr, uint32_t b_addr) { return wrapper_strcmp(mem, MEM_U32(a_addr), MEM_U32(b_addr)); } -static uint32_t tsearch_tfind(uint8_t *mem, uint32_t key_addr, uint32_t rootp_addr, uint32_t compar_addr, bool insert) { +static uint32_t tsearch_tfind(uint8_t* mem, uint32_t key_addr, uint32_t rootp_addr, uint32_t compar_addr, bool insert) { if (rootp_addr == 0) { return 0; } @@ -2665,33 +2666,36 @@ static uint32_t tsearch_tfind(uint8_t *mem, uint32_t key_addr, uint32_t rootp_ad return 0; } -uint32_t wrapper_tsearch(uint8_t *mem, uint32_t key_addr, uint32_t rootp_addr, uint32_t compar_addr) { +uint32_t wrapper_tsearch(uint8_t* mem, uint32_t key_addr, uint32_t rootp_addr, uint32_t compar_addr) { return tsearch_tfind(mem, key_addr, rootp_addr, compar_addr, true); } -uint32_t wrapper_tfind(uint8_t *mem, uint32_t key_addr, uint32_t rootp_addr, uint32_t compar_addr) { +uint32_t wrapper_tfind(uint8_t* mem, uint32_t key_addr, uint32_t rootp_addr, uint32_t compar_addr) { return tsearch_tfind(mem, key_addr, rootp_addr, compar_addr, false); } -uint32_t wrapper_qsort(uint8_t *mem, uint32_t base_addr, uint32_t num, uint32_t size, uint64_t (*trampoline)(uint8_t *mem, uint32_t sp, uint32_t a0, uint32_t a1, uint32_t a2, uint32_t a3, uint32_t fp_dest), uint32_t compare_addr, uint32_t sp) { +uint32_t wrapper_qsort(uint8_t* mem, uint32_t base_addr, uint32_t num, uint32_t size, + uint64_t (*trampoline)(uint8_t* mem, uint32_t sp, uint32_t a0, uint32_t a1, uint32_t a2, + uint32_t a3, uint32_t fp_dest), + uint32_t compare_addr, uint32_t sp) { assert(0 && "qsort not implemented"); return 0; } -uint32_t wrapper_regcmp(uint8_t *mem, uint32_t string1_addr, uint32_t sp) { +uint32_t wrapper_regcmp(uint8_t* mem, uint32_t string1_addr, uint32_t sp) { STRING(string1); fprintf(stderr, "regex string: %s\n", string1); assert(0 && "regcmp not implemented"); return 0; } -uint32_t wrapper_regex(uint8_t *mem, uint32_t re_addr, uint32_t subject_addr, uint32_t sp) { +uint32_t wrapper_regex(uint8_t* mem, uint32_t re_addr, uint32_t subject_addr, uint32_t sp) { STRING(subject); assert(0 && "regex not implemented"); return 0; } -void wrapper___assert(uint8_t *mem, uint32_t assertion_addr, uint32_t file_addr, int line) { +void wrapper___assert(uint8_t* mem, uint32_t assertion_addr, uint32_t file_addr, int line) { STRING(assertion) STRING(file) __assert(assertion, file, line); @@ -2723,7 +2727,7 @@ double double_from_FloatReg(union FloatReg floatreg) { return val.d; } -double double_from_memory(uint8_t *mem, uint32_t address) { +double double_from_memory(uint8_t* mem, uint32_t address) { union host_doubleword val; val.ww = MEM_U32(address);