diff options
| author | spicyjpeg <thatspicyjpeg@gmail.com> | 2023-04-04 15:09:38 +0200 |
|---|---|---|
| committer | spicyjpeg <thatspicyjpeg@gmail.com> | 2023-04-04 15:09:38 +0200 |
| commit | 870f4dca9d7b5e86544216d0e36863d17aefef62 (patch) | |
| tree | f6186004da976cea19ee5764b795a51f932f77fb /libpsn00b/psxetc | |
| parent | f7d9c309661f3027d5bfd119b3daf814e26ef589 (diff) | |
| download | psn00bsdk-870f4dca9d7b5e86544216d0e36863d17aefef62.tar.gz | |
Add argument validation to most libpsn00b functions
Diffstat (limited to 'libpsn00b/psxetc')
| -rw-r--r-- | libpsn00b/psxetc/dl.c | 13 | ||||
| -rw-r--r-- | libpsn00b/psxetc/interrupts.c | 19 |
2 files changed, 18 insertions, 14 deletions
diff --git a/libpsn00b/psxetc/dl.c b/libpsn00b/psxetc/dl.c index ff712eb..06302e2 100644 --- a/libpsn00b/psxetc/dl.c +++ b/libpsn00b/psxetc/dl.c @@ -112,6 +112,8 @@ static uint32_t _elf_hash(const char *str) { /* Symbol map loading/introspection API */ int DL_InitSymbolMap(int num_entries) { + _sdk_validate_args(num_entries, -1); + if (_symbol_map.entries) DL_UnloadSymbolMap(); @@ -151,6 +153,8 @@ void DL_UnloadSymbolMap(void) { } void DL_AddMapSymbol(const char *name, void *ptr) { + _sdk_validate_args_void(name); + uint32_t hash = _elf_hash(name); int index = _symbol_map.index; _symbol_map.index = index + 1; @@ -168,6 +172,8 @@ void DL_AddMapSymbol(const char *name, void *ptr) { } int DL_ParseSymbolMap(const char *ptr, size_t size) { + _sdk_validate_args(ptr && size, 0); + int entries = 0; // Perform a quick scan over the entire map text and count the number of @@ -232,6 +238,8 @@ int DL_ParseSymbolMap(const char *ptr, size_t size) { } void *DL_GetMapSymbol(const char *name) { + _sdk_validate_args(name, 0); + if (!_symbol_map.entries) { _sdk_log("DL_GetMapSymbol() with no map loaded\n"); return 0; @@ -275,8 +283,7 @@ void *DL_SetResolveCallback(void *(*callback)(DLL *, const char *)) { /* Library loading and linking API */ DLL *DL_CreateDLL(DLL *dll, void *ptr, size_t size, DL_ResolveMode mode) { - if (!dll || !ptr) - return 0; + _sdk_validate_args(dll && ptr && size, 0); dll->ptr = ptr; dll->malloc_ptr = (mode & DL_FREE_ON_DESTROY) ? ptr : 0; @@ -463,6 +470,8 @@ void DL_DestroyDLL(DLL *dll) { } void *DL_GetDLLSymbol(const DLL *dll, const char *name) { + _sdk_validate_args(name, 0); + if (!dll) return DL_GetMapSymbol(name); //return _dl_resolve_callback(0, name); diff --git a/libpsn00b/psxetc/interrupts.c b/libpsn00b/psxetc/interrupts.c index 7c8b206..b7bbd07 100644 --- a/libpsn00b/psxetc/interrupts.c +++ b/libpsn00b/psxetc/interrupts.c @@ -4,6 +4,7 @@ */ #include <stdint.h> +#include <assert.h> #include <psxapi.h> #include <psxetc.h> #include <hwregs_c.h> @@ -99,8 +100,7 @@ static void _global_dma_handler(void) { /* IRQ and DMA handler API */ void *InterruptCallback(IRQ_Channel irq, void (*func)(void)) { - if ((irq < 0) || (irq >= NUM_IRQ_CHANNELS)) - return 0; + _sdk_validate_args((irq >= 0) && (irq < NUM_IRQ_CHANNELS), 0); void *old_callback = _irq_handlers[irq]; _irq_handlers[irq] = func; @@ -116,15 +116,13 @@ void *InterruptCallback(IRQ_Channel irq, void (*func)(void)) { } void *GetInterruptCallback(IRQ_Channel irq) { - if ((irq < 0) || (irq >= NUM_IRQ_CHANNELS)) - return 0; + _sdk_validate_args((irq >= 0) && (irq < NUM_IRQ_CHANNELS), 0); return _irq_handlers[irq]; } void *DMACallback(DMA_Channel dma, void (*func)(void)) { - if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) - return 0; + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), 0); void *old_callback = _dma_handlers[dma]; _dma_handlers[dma] = func; @@ -151,8 +149,7 @@ void *DMACallback(DMA_Channel dma, void (*func)(void)) { } void *GetDMACallback(DMA_Channel dma) { - if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) - return 0; + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), 0); return _dma_handlers[dma]; } @@ -160,8 +157,7 @@ void *GetDMACallback(DMA_Channel dma) { /* DMA channel priority API */ int SetDMAPriority(DMA_Channel dma, int priority) { - if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) - return -1; + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), -1); uint32_t dpcr = DMA_DPCR; uint32_t channel = dpcr >> (dma * 4); @@ -175,8 +171,7 @@ int SetDMAPriority(DMA_Channel dma, int priority) { } int GetDMAPriority(DMA_Channel dma) { - if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) - return -1; + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), -1); uint32_t channel = DMA_DPCR >> (dma * 4); return (channel & 8) ? (channel & 7) : -1; |
