[pypy-commit] pypy default: merge safe-win-mmap into default

mattip noreply at buildbot.pypy.org
Mon Sep 16 21:18:36 CEST 2013


Author: Matti Picus <matti.picus at gmail.com>
Branch: 
Changeset: r66978:4c42c8e043b5
Date: 2013-09-16 22:17 +0300
http://bitbucket.org/pypy/pypy/changeset/4c42c8e043b5/

Log:	merge safe-win-mmap into default

diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -81,6 +81,7 @@
 .. branch: numpypy-inplace-op
 .. branch: rewritten-loop-logging
 .. branch: no-release-gil
+.. branch: safe-win-mmap
 
 .. branch: nobold-backtrace
 Work on improving UnionError messages and stack trace displays.
diff --git a/rpython/rlib/rmmap.py b/rpython/rlib/rmmap.py
--- a/rpython/rlib/rmmap.py
+++ b/rpython/rlib/rmmap.py
@@ -118,10 +118,16 @@
     return unsafe, safe
 
 def winexternal(name, args, result, **kwargs):
-    return rffi.llexternal(name, args, result,
+    unsafe = rffi.llexternal(name, args, result,
                            compilation_info=CConfig._compilation_info_,
                            calling_conv='win',
                            **kwargs)
+    safe = rffi.llexternal(name, args, result,
+                           compilation_info=CConfig._compilation_info_,
+                           calling_conv='win',
+                           sandboxsafe=True, releasegil=False,
+                           **kwargs)
+    return unsafe, safe
 
 PTR = rffi.CCHARP
 
@@ -188,32 +194,29 @@
     SYSTEM_INFO = config['SYSTEM_INFO']
     SYSTEM_INFO_P = lltype.Ptr(SYSTEM_INFO)
 
-    GetSystemInfo = winexternal('GetSystemInfo', [SYSTEM_INFO_P], lltype.Void)
-    GetFileSize = winexternal('GetFileSize', [HANDLE, LPDWORD], DWORD)
-    GetCurrentProcess = winexternal('GetCurrentProcess', [], HANDLE)
-    DuplicateHandle = winexternal('DuplicateHandle', [HANDLE, HANDLE, HANDLE, LPHANDLE, DWORD, BOOL, DWORD], BOOL)
-    CreateFileMapping = winexternal('CreateFileMappingA', [HANDLE, rwin32.LPSECURITY_ATTRIBUTES, DWORD, DWORD, DWORD, LPCSTR], HANDLE)
-    MapViewOfFile = winexternal('MapViewOfFile', [HANDLE, DWORD, DWORD, DWORD, SIZE_T], LPCSTR)##!!LPVOID)
-    UnmapViewOfFile = winexternal('UnmapViewOfFile', [LPCSTR], BOOL,
-                                  releasegil=False)
-    FlushViewOfFile = winexternal('FlushViewOfFile', [LPCSTR, SIZE_T], BOOL)
-    SetFilePointer = winexternal('SetFilePointer', [HANDLE, LONG, PLONG, DWORD], DWORD)
-    SetEndOfFile = winexternal('SetEndOfFile', [HANDLE], BOOL)
-    VirtualAlloc = winexternal('VirtualAlloc',
+    GetSystemInfo, _ = winexternal('GetSystemInfo', [SYSTEM_INFO_P], lltype.Void)
+    GetFileSize, _ = winexternal('GetFileSize', [HANDLE, LPDWORD], DWORD)
+    GetCurrentProcess, _ = winexternal('GetCurrentProcess', [], HANDLE)
+    DuplicateHandle, _ = winexternal('DuplicateHandle', [HANDLE, HANDLE, HANDLE, LPHANDLE, DWORD, BOOL, DWORD], BOOL)
+    CreateFileMapping, _ = winexternal('CreateFileMappingA', [HANDLE, rwin32.LPSECURITY_ATTRIBUTES, DWORD, DWORD, DWORD, LPCSTR], HANDLE)
+    MapViewOfFile, _ = winexternal('MapViewOfFile', [HANDLE, DWORD, DWORD, DWORD, SIZE_T], LPCSTR)##!!LPVOID)
+    _, UnmapViewOfFile_safe = winexternal('UnmapViewOfFile', [LPCSTR], BOOL)
+    FlushViewOfFile, _ = winexternal('FlushViewOfFile', [LPCSTR, SIZE_T], BOOL)
+    SetFilePointer, _ = winexternal('SetFilePointer', [HANDLE, LONG, PLONG, DWORD], DWORD)
+    SetEndOfFile, _ = winexternal('SetEndOfFile', [HANDLE], BOOL)
+    VirtualAlloc, VirtualAlloc_safe = winexternal('VirtualAlloc',
                                [rffi.VOIDP, rffi.SIZE_T, DWORD, DWORD],
                                rffi.VOIDP)
-    # VirtualProtect is used in llarena and should not release the GIL
-    _VirtualProtect = winexternal('VirtualProtect',
+    _, _VirtualProtect_safe = winexternal('VirtualProtect',
                                   [rffi.VOIDP, rffi.SIZE_T, DWORD, LPDWORD],
-                                  BOOL,
-                                  _nowrapper=True)
+                                  BOOL)
     def VirtualProtect(addr, size, mode, oldmode_ptr):
-        return _VirtualProtect(addr,
+        return _VirtualProtect_safe(addr,
                                rffi.cast(rffi.SIZE_T, size),
                                rffi.cast(DWORD, mode),
                                oldmode_ptr)
     VirtualProtect._annspecialcase_ = 'specialize:ll'
-    VirtualFree = winexternal('VirtualFree',
+    VirtualFree, VirtualFree_safe = winexternal('VirtualFree',
                               [rffi.VOIDP, rffi.SIZE_T, DWORD], BOOL)
 
     def _get_page_size():
@@ -300,7 +303,7 @@
 
     def unmap(self):
         if _MS_WINDOWS:
-            UnmapViewOfFile(self.getptr(0))
+            UnmapViewOfFile_safe(self.getptr(0))
         elif _POSIX:
             self.unmap_range(0, self.size)
 
@@ -575,6 +578,7 @@
 
     def getitem(self, index):
         # simplified version, for rpython
+        self.check_valid()
         if index < 0:
             index += self.size
         return self.data[index]
@@ -846,7 +850,7 @@
         case of a sandboxed process
         """
         null = lltype.nullptr(rffi.VOIDP.TO)
-        res = VirtualAlloc(null, map_size, MEM_COMMIT | MEM_RESERVE,
+        res = VirtualAlloc_safe(null, map_size, MEM_COMMIT | MEM_RESERVE,
                            PAGE_EXECUTE_READWRITE)
         if not res:
             raise MemoryError
@@ -858,6 +862,6 @@
     alloc._annenforceargs_ = (int,)
 
     def free(ptr, map_size):
-        VirtualFree(ptr, 0, MEM_RELEASE)
+        VirtualFree_safe(ptr, 0, MEM_RELEASE)
 
 # register_external here?
diff --git a/rpython/rtyper/lltypesystem/llarena.py b/rpython/rtyper/lltypesystem/llarena.py
--- a/rpython/rtyper/lltypesystem/llarena.py
+++ b/rpython/rtyper/lltypesystem/llarena.py
@@ -535,6 +535,7 @@
         else:
             from rpython.rlib.rmmap import PAGE_READWRITE as newprotect
         arg = lltype.malloc(LPDWORD.TO, 1, zero=True, flavor='raw')
+        #does not release the GIL
         VirtualProtect(rffi.cast(rffi.VOIDP, addr),
                        size, newprotect, arg)
         # ignore potential errors
diff --git a/rpython/rtyper/tool/rffi_platform.py b/rpython/rtyper/tool/rffi_platform.py
--- a/rpython/rtyper/tool/rffi_platform.py
+++ b/rpython/rtyper/tool/rffi_platform.py
@@ -844,6 +844,10 @@
             library_dir = ''
             libraries = ['gc64_dll']
             includes = ['gc.h']
+        # since config_external_library does not use a platform kwarg,
+        # somehow using a platform kw arg make the merge fail in
+        # config_external_library
+        platform = None    
     else:
         library_dir = ''
         libraries = ['gc', 'dl']


More information about the pypy-commit mailing list