#include "shm.h" #include "catch.hpp" #include "shm_helper.h" #include "file_base.h" typedef void* (__cdecl* DllMallocPtr)(size_t bytes); typedef void*(__cdecl*DllReallocPtr)(void* old_ptr, size_t new_bytes); typedef void(__cdecl*DllFreePtr)(void*); TEST_CASE("Shmdll, ShmMalloc ShmFree") { char _dll_name[256]; disk_file::dll_name("./testshmdll.dll", _dll_name, sizeof(_dll_name)); DllMallocPtr mallocdll = nullptr; DllReallocPtr reallocdll = nullptr; DllFreePtr freedll = nullptr; dll_handle_t hModule = disk_file::dll_open(_dll_name); REQUIRE(hModule); mallocdll = (DllMallocPtr)disk_file::dll_symbol(hModule,"DllMalloc"); reallocdll = (DllReallocPtr)disk_file::dll_symbol(hModule, "DllRealloc"); freedll = (DllFreePtr)disk_file::dll_symbol(hModule,"DllFree"); bg::ShmOptions opts(false, "Test", nullptr); opts.fix_vptr_on_init = false; REQUIRE(bg::ShmInit(opts) == true); for(size_t bytes = 8; bytes < (0x40000 << 4); bytes = bytes << 1) { void* memory = mallocdll(bytes); REQUIRE(memory); memset(memory, 0, bytes); *(int*)memory = 1; *(int*)((uintptr_t)memory + bytes - 4) = 2; void* memory1 = reallocdll(memory, bytes << 1); REQUIRE(memory1); REQUIRE(*(int*)memory1 == 1); REQUIRE(*(int*)((uintptr_t)memory1 + bytes - 4) == 2); freedll(memory1); } bg::ShmFini(); }