mirror of
https://github.com/wiiu-env/MemoryMappingModule.git
synced 2024-11-21 17:29:21 +01:00
Improve logging and resolve any compiler warnings
This commit is contained in:
parent
59300aad22
commit
7bb906f83f
11
.github/workflows/pr.yml
vendored
11
.github/workflows/pr.yml
vendored
@ -10,6 +10,17 @@ jobs:
|
||||
- name: clang-format
|
||||
run: |
|
||||
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
|
||||
check-build-with-logging:
|
||||
runs-on: ubuntu-18.04
|
||||
needs: clang-format
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: build binary with logging
|
||||
run: |
|
||||
docker build . -t builder
|
||||
docker run --rm -v ${PWD}:/project builder make DEBUG=VERBOSE
|
||||
docker run --rm -v ${PWD}:/project builder make clean
|
||||
docker run --rm -v ${PWD}:/project builder make DEBUG=1
|
||||
build-binary:
|
||||
runs-on: ubuntu-18.04
|
||||
needs: clang-format
|
||||
|
5
Makefile
5
Makefile
@ -43,6 +43,11 @@ CXXFLAGS += -DDEBUG -g
|
||||
CFLAGS += -DDEBUG -g
|
||||
endif
|
||||
|
||||
ifeq ($(DEBUG),VERBOSE)
|
||||
CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
|
||||
CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
|
||||
endif
|
||||
|
||||
LIBS := -lwums -lwut -lkernel -lfunctionpatcher
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
@ -4,6 +4,15 @@
|
||||
1. Copy the file `MemoryMappingModule.wms` into `sd:/wiiu/environments/[ENVIRONMENT]/modules`.
|
||||
2. Requires the [WUMSLoader](https://github.com/wiiu-env/WUMSLoader) in `sd:/wiiu/environments/[ENVIRONMENT]/modules/setup`.
|
||||
|
||||
## Buildflags
|
||||
|
||||
### Logging
|
||||
Building via `make` only logs errors (via OSReport). To enable logging via the [LoggingModule](https://github.com/wiiu-env/LoggingModule) set `DEBUG` to `1` or `VERBOSE`.
|
||||
|
||||
`make` Logs errors only (via OSReport).
|
||||
`make DEBUG=1` Enables information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule).
|
||||
`make DEBUG=VERBOSE` Enables verbose information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule).
|
||||
|
||||
## Building using the Dockerfile
|
||||
|
||||
It's possible to use a docker image for building. This way you don't need anything installed on your host system.
|
||||
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <coreinit/debug.h>
|
||||
#include <string.h>
|
||||
#include <whb/log.h>
|
||||
|
||||
@ -7,30 +8,52 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define LOG_APP_TYPE "M"
|
||||
#define LOG_APP_NAME "memory_mapping"
|
||||
|
||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
||||
|
||||
#define LOG(LOG_FUNC, FMT, ARGS...) LOG_EX_DEFAULT(LOG_FUNC, "", "", FMT, ##ARGS)
|
||||
|
||||
#define LOG_EX_DEFAULT(LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) LOG_EX(__FILENAME__, __FUNCTION__, __LINE__, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ##ARGS)
|
||||
|
||||
#define LOG_EX(FILENAME, FUNCTION, LINE, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) \
|
||||
do { \
|
||||
LOG_FUNC("[(%s)%18s][%23s]%30s@L%04d: " LOG_LEVEL "" FMT "" LINE_END, LOG_APP_TYPE, LOG_APP_NAME, FILENAME, FUNCTION, LINE, ##ARGS); \
|
||||
} while (0)
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
||||
#ifdef VERBOSE_DEBUG
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) LOG(WHBLogPrintf, FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "", "", FMT, ##ARGS);
|
||||
#else
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FMT, ARGS...) while (0)
|
||||
#endif
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) LOG(WHBLogPrintf, FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
|
||||
do { \
|
||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
|
||||
} while (0)
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) LOG(WHBLogWritef, FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
|
||||
do { \
|
||||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
|
||||
} while (0)
|
||||
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS);
|
||||
|
||||
#else
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, OSReport, "##ERROR## ", "\n", FMT, ##ARGS);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -109,6 +109,7 @@ bool MemoryMapping_isMemoryMapped() {
|
||||
}
|
||||
|
||||
void MemoryMapping_searchEmptyMemoryRegions() {
|
||||
#ifdef DEBUG
|
||||
DEBUG_FUNCTION_LINE("Searching for empty memory.");
|
||||
|
||||
for (int32_t i = 0;; i++) {
|
||||
@ -181,6 +182,7 @@ void MemoryMapping_searchEmptyMemoryRegions() {
|
||||
}
|
||||
}
|
||||
DEBUG_FUNCTION_LINE("All tests done.");
|
||||
#endif
|
||||
}
|
||||
|
||||
void MemoryMapping_writeTestValuesToMemory() {
|
||||
@ -233,6 +235,7 @@ void MemoryMapping_writeTestValuesToMemory() {
|
||||
}
|
||||
|
||||
void MemoryMapping_readTestValuesFromMemory() {
|
||||
#ifdef DEBUG
|
||||
DEBUG_FUNCTION_LINE("Testing reading the written values.");
|
||||
|
||||
for (int32_t i = 0;; i++) {
|
||||
@ -295,6 +298,7 @@ void MemoryMapping_readTestValuesFromMemory() {
|
||||
}
|
||||
}
|
||||
DEBUG_FUNCTION_LINE("All tests done.");
|
||||
#endif
|
||||
}
|
||||
|
||||
void MemoryMapping_memoryMappingForRegions(const memory_mapping_t *memory_mapping, sr_table_t SRTable, uint32_t *translation_table) {
|
||||
@ -407,7 +411,6 @@ void *MemoryMapping_allocEx(uint32_t size, int32_t align, bool videoOnly) {
|
||||
}
|
||||
uint32_t effectiveAddress = mem_mapping[i].effective_start_address;
|
||||
auto heapHandle = (MEMHeapHandle) effectiveAddress;
|
||||
auto *heap = (MEMExpHeap *) heapHandle;
|
||||
|
||||
// Skip non-video memory
|
||||
if (videoOnly && ((effectiveAddress < MEMORY_START_VIDEO) || (effectiveAddress > MEMORY_END_VIDEO))) {
|
||||
@ -475,10 +478,7 @@ void MemoryMapping_free(void *ptr) {
|
||||
}
|
||||
if (ptr_val > mem_mapping[i].effective_start_address && ptr_val < mem_mapping[i].effective_end_address) {
|
||||
auto heapHandle = (MEMHeapHandle) mem_mapping[i].effective_start_address;
|
||||
auto *heap = (MEMExpHeap *) heapHandle;
|
||||
|
||||
MEMFreeToExpHeap((MEMHeapHandle) mem_mapping[i].effective_start_address, ptr);
|
||||
auto cur = heap->usedList.head;
|
||||
MEMFreeToExpHeap(heapHandle, ptr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -532,8 +532,13 @@ void MemoryMapping_CreateHeaps() {
|
||||
uint32_t size = mem_mapping[i].effective_end_address - mem_mapping[i].effective_start_address;
|
||||
|
||||
memset(reinterpret_cast<void *>(mem_mapping[i].effective_start_address), 0, size);
|
||||
auto heap = MEMCreateExpHeapEx(address, size, MEM_HEAP_FLAG_USE_LOCK);
|
||||
#ifdef DEBUG
|
||||
auto heap =
|
||||
#endif
|
||||
MEMCreateExpHeapEx(address, size, MEM_HEAP_FLAG_USE_LOCK);
|
||||
#ifdef DEBUG
|
||||
DEBUG_FUNCTION_LINE("Created heap @%08X, size %d KiB", heap, size / 1024);
|
||||
#endif
|
||||
}
|
||||
OSUnlockMutex(&allocMutex);
|
||||
}
|
||||
@ -741,6 +746,7 @@ void MemoryMapping_printPageTableTranslation(sr_table_t srTable, uint32_t *trans
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
const char *access1[] = {"read/write", "read/write", "read/write", "read only"};
|
||||
const char *access2[] = {"no access", "read only", "read/write", "read only"};
|
||||
|
||||
@ -749,6 +755,7 @@ void MemoryMapping_printPageTableTranslation(sr_table_t srTable, uint32_t *trans
|
||||
cur.kp ? access2[cur.pp] : access1[cur.pp],
|
||||
cur.ks ? access2[cur.pp] : access1[cur.pp], cur.nx ? "not executable" : "executable");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user