Tweak os_validate to support running SBCL on recent versions of Wine
authorDavid Lichteblau <david@lichteblau.com>
Tue, 9 Aug 2011 18:51:06 +0000 (20:51 +0200)
committerDavid Lichteblau <david@lichteblau.com>
Wed, 10 Aug 2011 18:04:15 +0000 (20:04 +0200)
  SBCL now builds and runs on Wine reliably.

  Credits: Fix developed by Anton Kovalenko.

NEWS
src/runtime/win32-os.c

diff --git a/NEWS b/NEWS
index ff52c7d..53f446f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,8 @@ changes relative to sbcl-1.0.50:
     chroot. (Use "SBCL_ARCH=x86 sh make.sh" to build.)
   * enhancement: added new toplevel options --quit and --non-interactive
     (lp#822712).
+  * enhancement: the Windows port of SBCL now builds and runs on Wine
+    (thanks to Anton Kovalenko).
   * optimization: unsigned integer divisions by a constant are implemented
     using multiplication (affects CEILING, FLOOR, TRUNCATE, MOD, and REM.)
   * optimization: improved type-derivation for LOAD-TIME-VALUE.
index c674ca6..a767461 100644 (file)
@@ -161,7 +161,22 @@ os_validate(os_vm_address_t addr, os_vm_size_t len)
         return 0;
     }
 
-    if ((mem_info.State == MEM_RESERVE) && (mem_info.RegionSize >=len)) return addr;
+    if ((mem_info.State == MEM_RESERVE) && (mem_info.RegionSize >=len)) {
+      /* It would be correct to return here. However, support for Wine
+       * is beneficial, and Wine has a strange behavior in this
+       * department. It reports all memory below KERNEL32.DLL as
+       * reserved, but disallows MEM_COMMIT.
+       *
+       * Let's work around it: reserve the region we need for a second
+       * time. The second reservation is documented to fail on normal NT
+       * family, but it will succeed on Wine if this region is
+       * actually free.
+       */
+      VirtualAlloc(addr, len, MEM_RESERVE, PAGE_EXECUTE_READWRITE);
+      /* If it is wine, the second call has succeded, and now the region
+       * is really reserved. */
+      return addr;
+    }
 
     if (mem_info.State == MEM_RESERVE) {
         fprintf(stderr, "validation of reserved space too short.\n");