Set a custom OSDynLoad Allocator when processing relocations

This commit is contained in:
Maschell
2022-10-03 21:51:12 +02:00
parent 0a254e59f4
commit 2882635f6f
3 changed files with 41 additions and 3 deletions

View File

@@ -1,4 +1,5 @@
#include "utils/logger.h"
#include "utils.h"
#include "logger.h"
#include <coreinit/ios.h>
#include <cstring>
#include <malloc.h>
@@ -53,3 +54,25 @@ void dumpHex(const void *data, size_t size) {
}
}
}
OSDynLoad_Error CustomDynLoadAlloc(int32_t size, int32_t align, void **outAddr) {
if (!outAddr) {
return OS_DYNLOAD_INVALID_ALLOCATOR_PTR;
}
if (align >= 0 && align < 4) {
align = 4;
} else if (align < 0 && align > -4) {
align = -4;
}
if (!(*outAddr = memalign(align, size))) {
return OS_DYNLOAD_OUT_OF_MEMORY;
}
return OS_DYNLOAD_OK;
}
void CustomDynLoadFree(void *addr) {
free(addr);
}