Commits

mattip  committed 4c42c8e Merge

merge safe-win-mmap into default

  • Participants
  • Parent commits 55b0874, c11afff

Comments (0)

Files changed (4)

File pypy/doc/whatsnew-head.rst

 .. 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.

File rpython/rlib/rmmap.py

     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
 
     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():
 
     def unmap(self):
         if _MS_WINDOWS:
-            UnmapViewOfFile(self.getptr(0))
+            UnmapViewOfFile_safe(self.getptr(0))
         elif _POSIX:
             self.unmap_range(0, self.size)
 
 
     def getitem(self, index):
         # simplified version, for rpython
+        self.check_valid()
         if index < 0:
             index += self.size
         return self.data[index]
         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
     alloc._annenforceargs_ = (int,)
 
     def free(ptr, map_size):
-        VirtualFree(ptr, 0, MEM_RELEASE)
+        VirtualFree_safe(ptr, 0, MEM_RELEASE)
 
 # register_external here?

File rpython/rtyper/lltypesystem/llarena.py

         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

File rpython/rtyper/tool/rffi_platform.py

             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']