mirror of
https://github.com/wiiu-env/wut.git
synced 2024-12-13 09:22:38 +01:00
Add libdefaultheap.
Gives you access to MEMAllocFromDefaultHeap{Ex} and MEMFreeToDefaultHeap. This is a workaround until we can support data imports.
This commit is contained in:
parent
c9d177651e
commit
ad35efc97c
@ -28,6 +28,16 @@ externalproject_add(rpl
|
||||
-DCMAKE_INSTALL_PREFIX:string=<INSTALL_DIR>
|
||||
-DCMAKE_TOOLCHAIN_FILE:string=${CMAKE_SOURCE_DIR}/cmake/wut-toolchain.cmake)
|
||||
|
||||
externalproject_add(libdefaultheap
|
||||
SOURCE_DIR "${CMAKE_SOURCE_DIR}/src/libdefaultheap"
|
||||
CMAKE_GENERATOR "Unix Makefiles"
|
||||
INSTALL_DIR "${CMAKE_BINARY_DIR}/staging"
|
||||
CMAKE_CACHE_ARGS
|
||||
-DDEVKITPPC:string=${DEVKITPPC}
|
||||
-DWUT_ROOT:string=${CMAKE_SOURCE_DIR}
|
||||
-DCMAKE_INSTALL_PREFIX:string=<INSTALL_DIR>
|
||||
-DCMAKE_TOOLCHAIN_FILE:string=${CMAKE_SOURCE_DIR}/cmake/wut-toolchain.cmake)
|
||||
|
||||
externalproject_add(libgfd
|
||||
SOURCE_DIR "${CMAKE_SOURCE_DIR}/src/libgfd"
|
||||
CMAKE_GENERATOR "Unix Makefiles"
|
||||
@ -57,6 +67,12 @@ externalproject_add_step(rpl forcebuild
|
||||
DEPENDERS "build"
|
||||
ALWAYS 1)
|
||||
|
||||
externalproject_add_step(libdefaultheap forcebuild
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Force build of libdefaultheap"
|
||||
DEPENDEES "configure"
|
||||
DEPENDERS "build"
|
||||
ALWAYS 1)
|
||||
|
||||
externalproject_add_step(libgfd forcebuild
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Force build of libgfd"
|
||||
DEPENDEES "configure"
|
||||
|
16
src/libdefaultheap/CMakeLists.txt
Normal file
16
src/libdefaultheap/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.2)
|
||||
project(libdefaultheap)
|
||||
|
||||
file(GLOB_RECURSE SOURCE_FILES *.c)
|
||||
file(GLOB_RECURSE HEADER_FILES *.h)
|
||||
|
||||
add_library(defaultheap STATIC ${SOURCE_FILES} ${HEADER_FILES})
|
||||
|
||||
target_include_directories(defaultheap PRIVATE "../../include")
|
||||
target_include_directories(defaultheap PUBLIC "include")
|
||||
|
||||
install(TARGETS defaultheap
|
||||
ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/lib")
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
|
||||
DESTINATION "${CMAKE_INSTALL_PREFIX}/include"
|
||||
FILES_MATCHING PATTERN "*.h*")
|
20
src/libdefaultheap/include/defaultheap.h
Normal file
20
src/libdefaultheap/include/defaultheap.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <wut.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void *
|
||||
MEMAllocFromDefaultHeap(uint32_t size);
|
||||
|
||||
void *
|
||||
MEMAllocFromDefaultHeapEx(uint32_t size,
|
||||
int32_t alignment);
|
||||
|
||||
void
|
||||
MEMFreeToDefaultHeap(void *block);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
75
src/libdefaultheap/src/defaultheap.c
Normal file
75
src/libdefaultheap/src/defaultheap.c
Normal file
@ -0,0 +1,75 @@
|
||||
#include "defaultheap.h"
|
||||
#include <coreinit/dynload.h>
|
||||
|
||||
typedef void *(*MEMAllocFromDefaultHeapFn)(uint32_t size);
|
||||
typedef void *(*MEMAllocFromDefaultHeapExFn)(uint32_t size, int32_t alignment);
|
||||
typedef void (*MEMFreeToDefaultHeapFn)(void *block);
|
||||
|
||||
static OSDynLoadModule sCoreinitHandle = 0;
|
||||
static MEMAllocFromDefaultHeapFn *MEMAllocFromDefaultHeapPtr = NULL;
|
||||
static MEMAllocFromDefaultHeapExFn *MEMAllocFromDefaultHeapExPtr = NULL;
|
||||
static MEMFreeToDefaultHeapFn *MEMFreeToDefaultHeapPtr = NULL;
|
||||
|
||||
void *
|
||||
MEMAllocFromDefaultHeap(uint32_t size)
|
||||
{
|
||||
if (!sCoreinitHandle) {
|
||||
if (OSDynLoad_Acquire("coreinit.rpl", &sCoreinitHandle)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!MEMAllocFromDefaultHeapPtr) {
|
||||
if (OSDynLoad_FindExport(sCoreinitHandle,
|
||||
TRUE,
|
||||
"MEMAllocFromDefaultHeap",
|
||||
(void **)&MEMAllocFromDefaultHeapPtr)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return (**MEMAllocFromDefaultHeapPtr)(size);
|
||||
}
|
||||
|
||||
void *
|
||||
MEMAllocFromDefaultHeapEx(uint32_t size,
|
||||
int32_t alignment)
|
||||
{
|
||||
if (!sCoreinitHandle) {
|
||||
if (OSDynLoad_Acquire("coreinit.rpl", &sCoreinitHandle)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!MEMAllocFromDefaultHeapExPtr) {
|
||||
if (OSDynLoad_FindExport(sCoreinitHandle,
|
||||
TRUE,
|
||||
"MEMAllocFromDefaultHeapEx",
|
||||
(void **)&MEMAllocFromDefaultHeapExPtr)) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return (**MEMAllocFromDefaultHeapExPtr)(size, alignment);
|
||||
}
|
||||
|
||||
void
|
||||
MEMFreeToDefaultHeap(void *block)
|
||||
{
|
||||
if (!sCoreinitHandle) {
|
||||
if (OSDynLoad_Acquire("coreinit.rpl", &sCoreinitHandle)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!MEMFreeToDefaultHeapPtr) {
|
||||
if (OSDynLoad_FindExport(sCoreinitHandle,
|
||||
TRUE,
|
||||
"MEMFreeToDefaultHeap",
|
||||
(void **)&MEMFreeToDefaultHeapPtr)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
(**MEMFreeToDefaultHeapPtr)(block);
|
||||
}
|
Loading…
Reference in New Issue
Block a user