From 6878c5210fad967c7b32020e294bc2ffbb0c88be Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Thu, 11 Dec 2025 16:57:23 +0000 Subject: [PATCH] Fix weird definition of NULL --- common/target-stdint.h | 1 + common/uvm32_target.h | 9 +++++++++ precompiled/self.bin | Bin 5780 -> 5780 bytes uvm32/uvm32.c | 26 ++++++++++++++++---------- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/common/target-stdint.h b/common/target-stdint.h index 190ffbc..3eaf355 100644 --- a/common/target-stdint.h +++ b/common/target-stdint.h @@ -27,5 +27,6 @@ size_assert(int16_t, 2); size_assert(int8_t, 1); #define INT32_MIN 0 +#define INT16_MAX 32767 #endif diff --git a/common/uvm32_target.h b/common/uvm32_target.h index c466ef2..207b45a 100644 --- a/common/uvm32_target.h +++ b/common/uvm32_target.h @@ -11,6 +11,15 @@ #include "target-stdint.h" +typedef uint32_t size_t; +typedef int32_t ssize_t; + +#define NULL 0 + +void *memcpy(void *dst, const void *src, int len); +void *memset(void *buf, int c, int len); +void *memmove(void *dest, const void *src, size_t len); + static uint32_t syscall(uint32_t id, uint32_t param1, uint32_t param2) { register uint32_t a0 asm("a0") = (uint32_t)(param1); register uint32_t a1 asm("a1") = (uint32_t)(param2); diff --git a/precompiled/self.bin b/precompiled/self.bin index 46ba41c40172aee8daf70016664225a071a9803b..d5be60a4d6e56e40f1e960be7550a5d5866dacfe 100755 GIT binary patch delta 854 zcmZ|KKWGzS7zXh7uJR{^|{~(2ADCp3kkfB{lG6>C>p+kmBg$i~M8c=B@75khT8Uh)9+&#~C-}`-+8O#i> zeo}hQO-gqE11YcnB)dN-+tDYoeRh%emD5-3wB9xQe$!`}D)DoboM$?9Z0f{%L}7J; zoZbVP9WdQqV>LjQYSMmnXM+=JM6nbi7V6a@OVO|+Ku$;_E3MPo2@-1|qRYJ`>`0v~ zLm~D~5YNxw<+Q>(>STvy{Nn3cRvPDBtsuXq{IWhQ$#00aJ?9bGV~mBJZsW1_^x%)v zr$1sf{{M7;-96o7FV|_hn%&@>5tCmLe=%YhHsH;=LrUJ5eC8#0nm66iW9Bz4X#fBK delta 890 zcmZ|KKWGzS7zXh7yWZt`xwN@>BB>S={bE~+^$&&C&6-JciIAa)U`kLN3RQ6EP|TGE zq$)^xGXx1HLczr$5W&IV9|+W;;L;&rqy+_+LNl~fOhlinhK4|gA9v4l-}ipsWkxb1 z#jk2AGOx&!ONtzt5^~@k1QZ!Q(IwBE7xMHaA&0LC8JQPYBV_o67}a-3s(P<&YQ&E< zvQ-bUYEg3U>7kO|poNz!J;_Hpb*<>cdRS#GLCN4QEex83-ou(jwr0{+JzwU!b(n8x zK6O;hOz^Ze5n|niIo!Bjx8#GhTzvG+{RZa=sFrpYJ zy?J*~#T!-Dm$=)!;*O7-&otrZE$h0HQ~7G(*zwTsnflX@wtkM>i+{`gXyQ*v7Tl5k z51bB+iJSa3uvCg2vXoTKPtFe;v5kvBVXvm^Vg{k`s-{*F9^e8C{60QjET zJM0z0YbZkn`g_Tlg#^?B|77tV_o9PoaEH(0nTCo<&MK@y4Yq-NwATKit=~AH e-#noI+0j>#>(GQ%h(YUzj5xv*$nvctXa52irTxwT diff --git a/uvm32/uvm32.c b/uvm32/uvm32.c index 4c251ac..876329b 100644 --- a/uvm32/uvm32.c +++ b/uvm32/uvm32.c @@ -5,7 +5,13 @@ #error Define UVM32_MEMORY_SIZE #endif -#define UVM32_NULL (void *)0 +#ifndef CUSTOM_STDLIB_H +#include +#include +#include +#else +#include CUSTOM_STDLIB_H +#endif // On an invalid operation, an error is set in uvm32_state_t, but a valid pointer still needs to be temporarily used static uint32_t garbage; @@ -70,7 +76,7 @@ void uvm32_init(uvm32_state_t *vmst) { vmst->status = UVM32_STATUS_PAUSED; vmst->extramLen = 0; - vmst->extram = (uint32_t *)UVM32_NULL; + vmst->extram = (uint32_t *)NULL; vmst->extramDirty = false; vmst->core.pc = MINIRV32_RAM_IMAGE_OFFSET; @@ -91,7 +97,7 @@ bool uvm32_load(uvm32_state_t *vmst, const uint8_t *rom, int len) { } UVM32_MEMCPY(vmst->memory, rom, len); - vmst->stack_canary = (uint8_t *)UVM32_NULL; + vmst->stack_canary = (uint8_t *)NULL; return true; } @@ -102,7 +108,7 @@ bool get_safeptr_null_terminated(uvm32_state_t *vmst, uint32_t addr, uvm32_evt_s uint32_t p = ptrstart; if (p >= UVM32_MEMORY_SIZE) { setStatusErr(vmst, UVM32_ERR_MEM_RD); - buf->ptr = (uint8_t *)UVM32_NULL; + buf->ptr = (uint8_t *)NULL; buf->len = 0; return false; } @@ -110,7 +116,7 @@ bool get_safeptr_null_terminated(uvm32_state_t *vmst, uint32_t addr, uvm32_evt_s p++; if (p >= UVM32_MEMORY_SIZE) { setStatusErr(vmst, UVM32_ERR_MEM_RD); - buf->ptr = (uint8_t *)UVM32_NULL; + buf->ptr = (uint8_t *)NULL; buf->len = 0; return false; } @@ -124,7 +130,7 @@ bool get_safeptr(uvm32_state_t *vmst, uint32_t addr, uint32_t len, uvm32_evt_sys uint32_t ptrstart = addr - MINIRV32_RAM_IMAGE_OFFSET; if ((ptrstart > UVM32_MEMORY_SIZE) || (ptrstart + len >= UVM32_MEMORY_SIZE)) { setStatusErr(vmst, UVM32_ERR_MEM_RD); - buf->ptr = (uint8_t *)UVM32_NULL; + buf->ptr = (uint8_t *)NULL; buf->len = 0; return false; } @@ -152,7 +158,7 @@ uint32_t uvm32_run(uvm32_state_t *vmst, uvm32_evt_t *evt, uint32_t instr_meter) orig_instr_meter = min_instrs; } - if (vmst->stack_canary != UVM32_NULL && *vmst->stack_canary != STACK_CANARY_VALUE) { + if (vmst->stack_canary != NULL && *vmst->stack_canary != STACK_CANARY_VALUE) { setStatusErr(vmst, UVM32_ERR_INTERNAL_CORE); setup_err_evt(vmst, evt); return orig_instr_meter - instr_meter; @@ -189,7 +195,7 @@ uint32_t uvm32_run(uvm32_state_t *vmst, uvm32_evt_t *evt, uint32_t instr_meter) break; case UVM32_SYSCALL_STACKPROTECT: { // don't allow errant code to change it once set - if (vmst->stack_canary == (uint8_t *)UVM32_NULL) { + if (vmst->stack_canary == (uint8_t *)NULL) { uint32_t param0 = vmst->core.regs[10]; // a0 uint32_t mem_offset = param0 - MINIRV32_RAM_IMAGE_OFFSET; mem_offset &= ~0xF; // round up by 16 bytes @@ -332,7 +338,7 @@ uint32_t uvm32_extramLoad(void *userdata, uint32_t addr, uint32_t accessTyp) { uvm32_state_t *vmst = (uvm32_state_t *)userdata; addr -= UVM32_EXTRAM_BASE; - if (vmst->extram != UVM32_NULL) { + if (vmst->extram != NULL) { if (addr < vmst->extramLen) { switch(accessTyp) { case 0: @@ -365,7 +371,7 @@ uint32_t uvm32_extramLoad(void *userdata, uint32_t addr, uint32_t accessTyp) { uint32_t uvm32_extramStore(void *userdata, uint32_t addr, uint32_t val, uint32_t accessTyp) { uvm32_state_t *vmst = (uvm32_state_t *)userdata; addr -= UVM32_EXTRAM_BASE; - if (vmst->extram != UVM32_NULL) { + if (vmst->extram != NULL) { if (addr < vmst->extramLen) { switch(accessTyp) { case 0: