summaryrefslogtreecommitdiff
path: root/win32/win32.c
diff options
context:
space:
mode:
authorU.Nakamura <usa@ruby-lang.org>2021-12-27 15:56:23 +0900
committerU.Nakamura <usa@ruby-lang.org>2021-12-27 15:56:23 +0900
commit85a426dc8678f04a78ffd799943b690ce2984c49 (patch)
treedb4a2ccd3de67b69651ccbe66830ff313150072e /win32/win32.c
parentf486566f133ae191c6f9d5ff0001abf8efc9984f (diff)
downloadruby-85a426dc8678f04a78ffd799943b690ce2984c49.tar.gz
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`.
Diffstat (limited to 'win32/win32.c')
-rw-r--r--win32/win32.c31
1 files changed, 31 insertions, 0 deletions
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;
+}