[前][次][番号順一覧][スレッド一覧]

ruby-changes:70620

From: U.Nakamura <ko1@a...>
Date: Mon, 27 Dec 2021 17:15:42 +0900 (JST)
Subject: [ruby-changes:70620] 4e007d705c (master): Fix some bornheads

https://git.ruby-lang.org/ruby.git/commit/?id=4e007d705c

From 4e007d705c7879a843cba4ef9d4bea8a422de3f9 Mon Sep 17 00:00:00 2001
From: "U.Nakamura" <usa@r...>
Date: Mon, 27 Dec 2021 17:15:09 +0900
Subject: Fix some bornheads

---
 include/ruby/win32.h | 13 +------------
 win32/win32.c        | 39 ++++++++++++++++++++++++++++++++++++++-
 2 files changed, 39 insertions(+), 13 deletions(-)

diff --git a/include/ruby/win32.h b/include/ruby/win32.h
index ac8d94f7787..1d1f0ff9c14 100644
--- a/include/ruby/win32.h
+++ b/include/ruby/win32.h
@@ -813,18 +813,7 @@ extern int rb_w32_mprotect(void *, size_t, int); https://github.com/ruby/ruby/blob/trunk/include/ruby/win32.h#L813
 
 #define mmap(a, l, p, f, d, o) rb_w32_mmap(a, l, p, f, d, o)
 #define munmap(a, l) rb_w32_munmap(a, l)
-
-static inline int
-mprotect(void *addr, size_t len, int prot)
-{
-    if (prot | PROT_EXEC) {
-        if (!FlushInstructionCache(GetCurrentProcess(), addr, len)) {
-            errno = rb_w32_map_errno(GetLastError());
-            return -1;
-        }
-    }
-    return 0;
-}
+#define mprotect(a, l, prot) rb_w32_mprotect(a, l, prot)
 
 #if defined(__cplusplus)
 #if 0
diff --git a/win32/win32.c b/win32/win32.c
index 889046ceaa5..c9bd18c8cdb 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -8209,6 +8209,8 @@ void * https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L8209
 rb_w32_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset)
 {
     void *ptr;
+    //DWORD protect = 0;
+    DWORD protect = PAGE_EXECUTE_READWRITE;
 
     if (fd > 0 || offset) {
         /* not supported */
@@ -8216,7 +8218,16 @@ rb_w32_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L8218
         return MAP_FAILED;
     }
 
-    ptr = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
+/*
+    if (prot & PROT_EXEC) {
+        if (prot & PROT_WRITE) protect = PAGE_EXECUTE_READWRITE;
+        else if (prot & PROT_READ) protect = PAGE_EXECUTE_READ;
+        else protect = PAGE_EXECUTE;
+    }
+    else if (prot & PROT_WRITE) protect = PAGE_READWRITE;
+    else if (prot & PROT_READ) protect = PAGE_READONLY;
+*/
+    ptr = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, protect);
     if (!ptr) {
         errno = rb_w32_map_errno(GetLastError());
         return MAP_FAILED;
@@ -8235,3 +8246,29 @@ rb_w32_munmap(void *addr, size_t len) https://github.com/ruby/ruby/blob/trunk/win32/win32.c#L8246
 
     return 0;
 }
+
+inline int
+rb_w32_mprotect(void *addr, size_t len, int prot)
+{
+/*
+    DWORD protect = 0;
+    if (prot & PROT_EXEC) {
+        if (prot & PROT_WRITE) protect = PAGE_EXECUTE_READWRITE;
+        else if (prot & PROT_READ) protect = PAGE_EXECUTE_READ;
+        else protect = PAGE_EXECUTE;
+    }
+    else if (prot & PROT_WRITE) protect = PAGE_READWRITE;
+    else if (prot & PROT_READ) protect = PAGE_READONLY;
+    if (!VirtualProtect(addr, len, protect, NULL)) {
+        errno = rb_w32_map_errno(GetLastError());
+        return -1;
+    }
+*/
+    if (prot | PROT_EXEC) {
+        if (!FlushInstructionCache(GetCurrentProcess(), addr, len)) {
+            errno = rb_w32_map_errno(GetLastError());
+            return -1;
+        }
+    }
+    return 0;
+}
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]