diff --git a/os_functions.c b/os_functions.c index 1c4b256..a0a4928 100644 --- a/os_functions.c +++ b/os_functions.c @@ -149,9 +149,40 @@ EXPORT_DECL(s32, IOS_Ioctl,s32 fd, u32 request, void *input_buffer,u32 input_buf EXPORT_DECL(s32, IOS_Open,char *path, u32 mode); EXPORT_DECL(s32, IOS_Close,s32 fd); +void _os_find_export(u32 handle, const char *funcName, void *funcPointer) +{ + OSDynLoad_FindExport(handle, 0, funcName, funcPointer); + + if(!*(u32 *)funcPointer) { + /* + * This is effectively OSFatal("Function %s is NULL", funcName), + * but we can't rely on any library functions like snprintf or + * strcpy at this point. + * + * Buffer bounds are not checked. Beware! + */ + char buf[256], *bufp = buf; + const char a[] = "Function ", b[] = " is NULL", *p; + int i; + + for (i = 0; i < sizeof(a) - 1; i++) + *bufp++ = a[i]; + + for (p = funcName; *p; p++) + *bufp++ = *p; + + for (i = 0; i < sizeof(b) - 1; i++) + *bufp++ = b[i]; + + *bufp++ = '\0'; + + OSFatal(buf); + } +} + void InitAcquireOS(void) { - //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! Lib handle functions //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- EXPORT_FUNC_WRITE(OSDynLoad_Acquire, (s32 (*)(const char*, unsigned *))OS_SPECIFICS->addr_OSDynLoad_Acquire); diff --git a/os_functions.h b/os_functions.h index 54b9c8b..6aad386 100644 --- a/os_functions.h +++ b/os_functions.h @@ -49,25 +49,20 @@ extern "C" { #define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val -#define OS_FIND_EXPORT(handle, func) funcPointer = 0; \ - OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \ - if(!funcPointer) \ - OSFatal("Function " # func " is NULL"); \ +#define OS_FIND_EXPORT(handle, func) _os_find_export(handle, # func, &funcPointer); \ EXPORT_FUNC_WRITE(func, funcPointer); #define OS_FIND_EXPORT_EX(handle, func, func_p) \ - funcPointer = 0; \ - OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \ - if(!funcPointer) \ - OSFatal("Function " # func " is NULL"); \ + _os_find_export(handle, # func, &funcPointer); \ EXPORT_FUNC_WRITE(func_p, funcPointer); #define OS_MUTEX_SIZE 44 /* Handle for coreinit */ extern u32 coreinit_handle; -void InitOSFunctionPointers(void); -void InitAcquireOS(void); +extern void _os_find_export(u32 handle, const char *funcName, void *funcPointer); +extern void InitAcquireOS(void); +extern void InitOSFunctionPointers(void); //!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //! Lib handle functions