From d8bf7a88e89866d63cedd73224a2078eeaec6d13 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 11 Nov 2016 10:11:16 +0100 Subject: MALLOC_DEBUG part is not able to compile on UWP (nw) --- src/osd/modules/lib/osdlib_uwp.cpp | 88 +------------------------------------- 1 file changed, 2 insertions(+), 86 deletions(-) (limited to 'src/osd/modules/lib/osdlib_uwp.cpp') diff --git a/src/osd/modules/lib/osdlib_uwp.cpp b/src/osd/modules/lib/osdlib_uwp.cpp index 484ed3fb44c..ccdd3f3886a 100644 --- a/src/osd/modules/lib/osdlib_uwp.cpp +++ b/src/osd/modules/lib/osdlib_uwp.cpp @@ -1,5 +1,5 @@ // license:BSD-3-Clause -// copyright-holders:Olivier Galibert, R. Belmont +// copyright-holders:Olivier Galibert, R. Belmont, Brad Hughes //============================================================ // // sdlos_*.c - OS specific low level code @@ -13,9 +13,6 @@ #include #include -#ifndef _MSC_VER -#include -#endif #include #include @@ -120,24 +117,7 @@ void osd_process_kill() void *osd_malloc(size_t size) { -#ifndef MALLOC_DEBUG return malloc(size); -#else - // add in space for the size and offset - size += MAX_ALIGNMENT + sizeof(size_t) + 2; - size &= ~size_t(1); - - // basic objects just come from the heap - uint8_t *const block = reinterpret_cast(HeapAlloc(GetProcessHeap(), 0, size)); - if (block == nullptr) - return nullptr; - uint8_t *const result = reinterpret_cast(reinterpret_cast(block + sizeof(size_t) + MAX_ALIGNMENT) & ~(uintptr_t(MAX_ALIGNMENT) - 1)); - - // store the size and return and pointer to the data afterward - *reinterpret_cast(block) = size; - *(result - 1) = result - block; - return result; -#endif } @@ -147,35 +127,7 @@ void *osd_malloc(size_t size) void *osd_malloc_array(size_t size) { -#ifndef MALLOC_DEBUG return malloc(size); -#else - // add in space for the size and offset - size += MAX_ALIGNMENT + sizeof(size_t) + 2; - size &= ~size_t(1); - - // round the size up to a page boundary - size_t const rounded_size = ((size + sizeof(void *) + PAGE_SIZE - 1) / PAGE_SIZE) * PAGE_SIZE; - - // reserve that much memory, plus two guard pages - void *page_base = VirtualAlloc(nullptr, rounded_size + 2 * PAGE_SIZE, MEM_RESERVE, PAGE_NOACCESS); - if (page_base == nullptr) - return nullptr; - - // now allow access to everything but the first and last pages - page_base = VirtualAlloc(reinterpret_cast(page_base) + PAGE_SIZE, rounded_size, MEM_COMMIT, PAGE_READWRITE); - if (page_base == nullptr) - return nullptr; - - // work backwards from the page base to get to the block base - uint8_t *const block = GUARD_ALIGN_START ? reinterpret_cast(page_base) : (reinterpret_cast(page_base) + rounded_size - size); - uint8_t *const result = reinterpret_cast(reinterpret_cast(block + sizeof(size_t) + MAX_ALIGNMENT) & ~(uintptr_t(MAX_ALIGNMENT) - 1)); - - // store the size at the start with a flag indicating it has a guard page - *reinterpret_cast(block) = size | 1; - *(result - 1) = result - block; - return result; -#endif } @@ -185,25 +137,7 @@ void *osd_malloc_array(size_t size) void osd_free(void *ptr) { -#ifndef MALLOC_DEBUG free(ptr); -#else - uint8_t const offset = *(reinterpret_cast(ptr) - 1); - uint8_t *const block = reinterpret_cast(ptr) - offset; - size_t const size = *reinterpret_cast(block); - - if ((size & 0x1) == 0) - { - // if no guard page, just free the pointer - HeapFree(GetProcessHeap(), 0, block); - } - else - { - // large items need more care - ULONG_PTR const page_base = reinterpret_cast(block) & ~(PAGE_SIZE - 1); - VirtualFree(reinterpret_cast(page_base - PAGE_SIZE), 0, MEM_RELEASE); - } -#endif } @@ -237,21 +171,11 @@ void osd_free_executable(void *ptr, size_t size) void osd_break_into_debugger(const char *message) { -#ifdef OSD_WINDOWS - if (IsDebuggerPresent()) - { - win_output_debug_string_utf8(message); - DebugBreak(); - } - else if (s_debugger_stack_crawler != nullptr) - (*s_debugger_stack_crawler)(); -#else if (IsDebuggerPresent()) { OutputDebugStringA(message); __debugbreak(); } -#endif } //============================================================ @@ -309,13 +233,7 @@ char *osd_get_clipboard_text(void) //============================================================ // osd_dynamic_bind //============================================================ - -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) -// for classic desktop applications -#define load_library(filename) LoadLibrary(filename) -#else // for Windows Store universal applications - // This needs to change ASAP as it won't be allowed in the store typedef HMODULE __stdcall t_LLA(const char *); typedef FARPROC __stdcall t_GPA(HMODULE H, const char *); @@ -457,7 +375,7 @@ void find_load_exports() #define load_library(filename) g_LoadLibraryA(osd::text::from_wstring(filename).c_str()) #define get_proc_address(mod, proc) g_GetProcAddressA(mod, proc) -#endif + namespace osd { class dynamic_module_win32_impl : public dynamic_module @@ -467,9 +385,7 @@ public: : m_module(nullptr) { m_libraries = libraries; -#if defined(OSD_UWP) find_load_exports(); -#endif } virtual ~dynamic_module_win32_impl() override -- cgit v1.2.3-70-g09d2