summaryrefslogtreecommitdiffstatshomepage
path: root/src/osd/modules/lib/osdlib_uwp.cpp
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2021-01-06 01:25:58 +1100
committer Vas Crabb <vas@vastheman.com>2021-01-06 02:18:04 +1100
commit4eca05fe67e6a61a30af9d168590f3f3aaf9f639 (patch)
tree8ca9d1878d84d54ffaa11d0bafe43ea28b638f33 /src/osd/modules/lib/osdlib_uwp.cpp
parent7b22d972aea2dca442de9b8fb58687504e4444bc (diff)
cpu: Allow recompilers to work with W^X policy
Diffstat (limited to 'src/osd/modules/lib/osdlib_uwp.cpp')
-rw-r--r--src/osd/modules/lib/osdlib_uwp.cpp85
1 files changed, 51 insertions, 34 deletions
diff --git a/src/osd/modules/lib/osdlib_uwp.cpp b/src/osd/modules/lib/osdlib_uwp.cpp
index 680594d9cc8..f9a3e6a5cf9 100644
--- a/src/osd/modules/lib/osdlib_uwp.cpp
+++ b/src/osd/modules/lib/osdlib_uwp.cpp
@@ -8,30 +8,27 @@
//
//============================================================
-#include <windows.h>
-#include <mmsystem.h>
-
-#include <cstdlib>
-
-#include <cstdio>
-#include <memory>
-
// MAME headers
#include "osdlib.h"
#include "osdcomm.h"
#include "osdcore.h"
#include "strconv.h"
+#include <cstdio>
+#include <cstdlib>
+#include <map>
+#include <memory>
+
#include <windows.h>
+#include <memoryapi.h>
+
#include <wrl\client.h>
-#include "strconv.h"
using namespace Platform;
using namespace Windows::ApplicationModel::DataTransfer;
using namespace Windows::Foundation;
-#include <map>
//============================================================
// GLOBAL VARIABLES
@@ -89,30 +86,6 @@ void osd_process_kill()
}
//============================================================
-// osd_alloc_executable
-//
-// allocates "size" bytes of executable memory. this must take
-// things like NX support into account.
-//============================================================
-
-void *osd_alloc_executable(size_t size)
-{
- return nullptr;
-}
-
-
-//============================================================
-// osd_free_executable
-//
-// frees memory allocated with osd_alloc_executable
-//============================================================
-
-void osd_free_executable(void *ptr, size_t size)
-{
-}
-
-
-//============================================================
// osd_break_into_debugger
//============================================================
@@ -188,3 +161,47 @@ int osd_getpid(void)
return GetCurrentProcessId();
}
+
+namespace osd {
+
+bool invalidate_instruction_cache(void const *start, std::size_t size)
+{
+ return FlushInstructionCache(GetCurrentProcess(), start, size) != 0;
+}
+
+
+void *virtual_memory_allocation::do_alloc(std::initializer_list<std::size_t> blocks, std::size_t &size, std::size_t &page_size)
+{
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+ SIZE_T s(0);
+ for (std::size_t b : blocks)
+ s += (b + info.dwPageSize - 1) / info.dwPageSize;
+ s *= info.dwPageSize;
+ if (!s)
+ return nullptr;
+ LPVOID const result(VirtualAllocFromApp(nullptr, s, MEM_COMMIT, PAGE_NOACCESS));
+ if (result)
+ {
+ size = s;
+ page_size = info.dwPageSize;
+ }
+ return result;
+}
+
+void virtual_memory_allocation::do_free(void *start, std::size_t size)
+{
+ VirtualFree(start, 0, MEM_RELEASE);
+}
+
+bool virtual_memory_allocation::do_set_access(void *start, std::size_t size, unsigned access)
+{
+ ULONG p, o;
+ if (access & EXECUTE)
+ p = (access & WRITE) ? PAGE_EXECUTE_READWRITE : (access & READ) ? PAGE_EXECUTE_READ : PAGE_EXECUTE;
+ else
+ p = (access & WRITE) ? PAGE_READWRITE : (access & READ) ? PAGE_READONLY : PAGE_NOACCESS;
+ return VirtualProtectFromApp(start, size, p, &o) != 0;
+}
+
+} // namespace osd