[pypy-svn] r79958 - in pypy/trunk/pypy: rlib rpython/lltypesystem

afa at codespeak.net afa at codespeak.net
Fri Dec 10 16:01:49 CET 2010


Author: afa
Date: Fri Dec 10 16:01:48 2010
New Revision: 79958

Modified:
   pypy/trunk/pypy/rlib/rmmap.py
   pypy/trunk/pypy/rpython/lltypesystem/llarena.py
Log:
Don't release the GIL when VirtualProtect is called to protect recently freed memory.


Modified: pypy/trunk/pypy/rlib/rmmap.py
==============================================================================
--- pypy/trunk/pypy/rlib/rmmap.py	(original)
+++ pypy/trunk/pypy/rlib/rmmap.py	Fri Dec 10 16:01:48 2010
@@ -100,8 +100,11 @@
                            sandboxsafe=True, threadsafe=False)
     return unsafe, safe
 
-def winexternal(name, args, result):
-    return rffi.llexternal(name, args, result, compilation_info=CConfig._compilation_info_, calling_conv='win')
+def winexternal(name, args, result, **kwargs):
+    return rffi.llexternal(name, args, result,
+                           compilation_info=CConfig._compilation_info_,
+                           calling_conv='win',
+                           **kwargs)
 
 PTR = rffi.CCHARP
 
@@ -189,9 +192,17 @@
     VirtualAlloc = winexternal('VirtualAlloc',
                                [rffi.VOIDP, rffi.SIZE_T, DWORD, DWORD],
                                rffi.VOIDP)
-    VirtualProtect = winexternal('VirtualProtect',
-                                 [rffi.VOIDP, rffi.SIZE_T, DWORD, LPDWORD],
-                                 BOOL)
+    # VirtualProtect is used in llarena and should not release the GIL
+    _VirtualProtect = winexternal('VirtualProtect',
+                                  [rffi.VOIDP, rffi.SIZE_T, DWORD, LPDWORD],
+                                  BOOL,
+                                  _nowrapper=True)
+    def VirtualProtect(addr, size, mode, oldmode_ptr):
+        return _VirtualProtect(addr,
+                               rffi.cast(rffi.SIZE_T, size),
+                               rffi.cast(DWORD, mode),
+                               oldmode_ptr)
+    VirtualProtect._annspecialcase_ = 'specialize:ll'
     VirtualFree = winexternal('VirtualFree',
                               [rffi.VOIDP, rffi.SIZE_T, DWORD], BOOL)
 

Modified: pypy/trunk/pypy/rpython/lltypesystem/llarena.py
==============================================================================
--- pypy/trunk/pypy/rpython/lltypesystem/llarena.py	(original)
+++ pypy/trunk/pypy/rpython/lltypesystem/llarena.py	Fri Dec 10 16:01:48 2010
@@ -531,9 +531,7 @@
             from pypy.rlib.rmmap import PAGE_READWRITE as newprotect
         arg = lltype.malloc(LPDWORD.TO, 1, zero=True, flavor='raw')
         VirtualProtect(rffi.cast(rffi.VOIDP, addr),
-                       rffi.cast(rffi.SIZE_T, size),
-                       newprotect,
-                       arg)
+                       size, newprotect, arg)
         # ignore potential errors
         lltype.free(arg, flavor='raw')
     has_protect = True



More information about the Pypy-commit mailing list