Fix global variable casting

This commit is contained in:
2024-09-24 20:33:59 +08:00
parent ee08c57515
commit ae2fb42e87
9 changed files with 94 additions and 55 deletions

View File

@@ -1,5 +1,6 @@
#include "static_mem.h"
#include <spdlog/spdlog.h>
#include <string_view>
unsigned char gh_static_mem[GH_DATA_SIZE];
void gh_init_data_segment() {
@@ -12,5 +13,19 @@ void gh_init_data_segment() {
if (actual != gh_data_size) {
throw std::runtime_error("Failed to read gh_datasegment.bin");
}
fclose(f);
}
}
void gh_static_mem_check() {
// Quick check
const char *testValue = (const char *)&GH_MEM(0x5b68f8);
if (std::string_view(testValue) != "Directory") {
throw std::runtime_error("gh_datasegment.bin is corrupted");
}
const char *otherValue = (const char *)&GH_MEM(0x005b683c);
if (std::string_view(otherValue) != "%s") {
throw std::runtime_error("gh_datasegment.bin is corrupted");
}
}

View File

@@ -17,6 +17,9 @@ inline uint8_t *memoryMapSafe(size_t addr) {
return (uint8_t *)(gh_static_mem + (addr - GH_DATA_START));
}
void gh_init_data_segment();
void gh_static_mem_check();
#define GH_MEM(addr) (checkMappedMemory<addr>(), *memoryMapSafe(addr))
#endif /* A18E3E17_2A80_4DBD_96CD_1CE0120A164E */