From 85a426dc8678f04a78ffd799943b690ce2984c49 Mon Sep 17 00:00:00 2001 From: "U.Nakamura" Date: Mon, 27 Dec 2021 15:56:23 +0900 Subject: Tiny mmap emulation for Windows - prerequisite of supporting YJIT with VC++. - note that now can specfily `--yjit` on mswin64, but not enabled YJIT'ed code because of YJIT requires `OPT_DIRECT_THREADED_CODE` or `OPT_CALL_THREADED_CODE` in `rb_yjit_compile_iseq`. --- win32/win32.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'win32/win32.c') diff --git a/win32/win32.c b/win32/win32.c index c938e197a7..889046ceaa 100644 --- a/win32/win32.c +++ b/win32/win32.c @@ -8204,3 +8204,34 @@ VALUE (*const rb_f_notimplement_)(int, const VALUE *, VALUE, VALUE) = rb_f_notim #if RUBY_MSVCRT_VERSION < 120 #include "missing/nextafter.c" #endif + +void * +rb_w32_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) +{ + void *ptr; + + if (fd > 0 || offset) { + /* not supported */ + errno = EINVAL; + return MAP_FAILED; + } + + ptr = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); + if (!ptr) { + errno = rb_w32_map_errno(GetLastError()); + return MAP_FAILED; + } + + return ptr; +} + +int +rb_w32_munmap(void *addr, size_t len) +{ + if (!VirtualFree(addr, 0, MEM_RELEASE)) { + errno = rb_w32_map_errno(GetLastError()); + return -1; + } + + return 0; +} -- cgit v1.2.1