Merge pull request #6 from neuschaefer/dev

Space savings, memory functions, .gitignore
This commit is contained in:
Maschell 2017-04-29 12:50:39 +02:00 committed by GitHub
commit d2f15cc9b6
3 changed files with 49 additions and 11 deletions

3
.gitignore vendored
View File

@ -45,3 +45,6 @@ $RECYCLE.BIN/
Network Trash Folder Network Trash Folder
Temporary Items Temporary Items
.apdisk .apdisk
# Build artifacts
*.o

View File

@ -99,6 +99,9 @@ EXPORT_DECL(void *, MEMAllocFromExpHeapEx, s32 heap, u32 size, s32 align);
EXPORT_DECL(s32 , MEMCreateExpHeapEx, void* address, u32 size, unsigned short flags); EXPORT_DECL(s32 , MEMCreateExpHeapEx, void* address, u32 size, unsigned short flags);
EXPORT_DECL(void *, MEMDestroyExpHeap, s32 heap); EXPORT_DECL(void *, MEMDestroyExpHeap, s32 heap);
EXPORT_DECL(void, MEMFreeToExpHeap, s32 heap, void* ptr); EXPORT_DECL(void, MEMFreeToExpHeap, s32 heap, void* ptr);
EXPORT_DECL(void *, OSAllocFromSystem, int size, int alignment);
EXPORT_DECL(void, OSFreeToSystem, void *addr);
EXPORT_DECL(int, OSIsAddressValid, void *ptr);
//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! MCP functions //! MCP functions
@ -149,6 +152,37 @@ 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_Open,char *path, u32 mode);
EXPORT_DECL(s32, IOS_Close,s32 fd); 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) void InitAcquireOS(void)
{ {
//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -237,6 +271,9 @@ void InitOSFunctionPointers(void)
OS_FIND_EXPORT(coreinit_handle, MEMCreateExpHeapEx); OS_FIND_EXPORT(coreinit_handle, MEMCreateExpHeapEx);
OS_FIND_EXPORT(coreinit_handle, MEMDestroyExpHeap); OS_FIND_EXPORT(coreinit_handle, MEMDestroyExpHeap);
OS_FIND_EXPORT(coreinit_handle, MEMFreeToExpHeap); OS_FIND_EXPORT(coreinit_handle, MEMFreeToExpHeap);
OS_FIND_EXPORT(coreinit_handle, OSAllocFromSystem);
OS_FIND_EXPORT(coreinit_handle, OSFreeToSystem);
OS_FIND_EXPORT(coreinit_handle, OSIsAddressValid);
//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Other function addresses //! Other function addresses

View File

@ -49,25 +49,20 @@ extern "C" {
#define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val #define EXPORT_FUNC_WRITE(func, val) *(u32*)(((u32)&func) + 0) = (u32)val
#define OS_FIND_EXPORT(handle, func) funcPointer = 0; \ #define OS_FIND_EXPORT(handle, func) _os_find_export(handle, # func, &funcPointer); \
OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \
if(!funcPointer) \
OSFatal("Function " # func " is NULL"); \
EXPORT_FUNC_WRITE(func, funcPointer); EXPORT_FUNC_WRITE(func, funcPointer);
#define OS_FIND_EXPORT_EX(handle, func, func_p) \ #define OS_FIND_EXPORT_EX(handle, func, func_p) \
funcPointer = 0; \ _os_find_export(handle, # func, &funcPointer); \
OSDynLoad_FindExport(handle, 0, # func, &funcPointer); \
if(!funcPointer) \
OSFatal("Function " # func " is NULL"); \
EXPORT_FUNC_WRITE(func_p, funcPointer); EXPORT_FUNC_WRITE(func_p, funcPointer);
#define OS_MUTEX_SIZE 44 #define OS_MUTEX_SIZE 44
/* Handle for coreinit */ /* Handle for coreinit */
extern u32 coreinit_handle; extern u32 coreinit_handle;
void InitOSFunctionPointers(void); extern void _os_find_export(u32 handle, const char *funcName, void *funcPointer);
void InitAcquireOS(void); extern void InitAcquireOS(void);
extern void InitOSFunctionPointers(void);
//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Lib handle functions //! Lib handle functions
@ -143,6 +138,9 @@ extern void *(* MEMAllocFromExpHeapEx)(s32 heap, u32 size, s32 align);
extern s32 (* MEMCreateExpHeapEx)(void* address, u32 size, unsigned short flags); extern s32 (* MEMCreateExpHeapEx)(void* address, u32 size, unsigned short flags);
extern void *(* MEMDestroyExpHeap)(s32 heap); extern void *(* MEMDestroyExpHeap)(s32 heap);
extern void (* MEMFreeToExpHeap)(s32 heap, void* ptr); extern void (* MEMFreeToExpHeap)(s32 heap, void* ptr);
extern void* (* OSAllocFromSystem)(int size, int alignment);
extern void (* OSFreeToSystem)(void *addr);
extern int (* OSIsAddressValid)(void *ptr);
//!---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! MCP functions //! MCP functions