Index: trunk/src/kernel32/oslibdos.cpp
===================================================================
--- trunk/src/kernel32/oslibdos.cpp	(revision 5191)
+++ trunk/src/kernel32/oslibdos.cpp	(revision 5193)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.cpp,v 1.56 2001-01-23 11:59:45 sandervl Exp $ */
+/* $Id: oslibdos.cpp,v 1.57 2001-02-19 17:25:14 bird Exp $ */
 /*
  * Wrappers for OS/2 Dos* API
@@ -31,4 +31,5 @@
 #include "oslibdos.h"
 #include "dosqss.h"
+#include "win32k.h"
 
 #define DBG_LOCALLOG    DBG_oslibdos
@@ -293,31 +294,49 @@
 //NT returns addresses aligned at 64k, so we do too.
 //******************************************************************************
-DWORD OSLibDosAllocMem(LPVOID *lplpMemAddr, DWORD size, DWORD flags)
-{
- LPVOID memaddr;
- DWORD  offset;
- APIRET rc;
-
-  rc = DosAllocMem(&memaddr, size, PAG_READ | flAllocMem);
-  if(rc) {
+DWORD OSLibDosAllocMem(LPVOID *lplpMemAddr, DWORD cb, DWORD flFlags)
+{
+    PVOID   pvMemAddr;
+    DWORD   offset;
+    APIRET  rc;
+
+    /*
+     * Let's try use the exteneded DosAllocMem API of Win32k.sys.
+     */
+    if (libWin32kInstalled())
+    {
+        rc = DosAllocMemEx(&pvMemAddr, cb, flFlags | flAllocMem | OBJ_ALIGN64K);
+        if (rc != ERROR_NOT_SUPPORTED)  /* This call was stubbed until recently. */
+            return rc;
+    }
+
+    /*
+     * If no or old Win32k fall back to old method.
+     */
+    rc = DosAllocMem(&pvMemAddr, cb, PAG_READ | flAllocMem);
+    if (rc)
+    {
         return rc;
-  }
-  DosEnterCritSec();
-  DosFreeMem(memaddr);
-  offset = (DWORD)memaddr & 0xFFFF;
-  if(offset) {
-        DosAllocMem(&memaddr, 64*1024 - offset, PAG_READ | flAllocMem);
-  }
-  rc = DosAllocMem(lplpMemAddr, size, flags | flAllocMem);
-  DosExitCritSec();
-  if((DWORD)*lplpMemAddr & 0xFFFF) {//still not at 64k boundary?
+    }
+    DosEnterCritSec();
+    DosFreeMem(pvMemAddr);
+    offset = (DWORD)pvMemAddr & 0xFFFF;
+    if (offset)
+    {
+        DosAllocMem(&pvMemAddr, 64*1024 - offset, PAG_READ | flAllocMem);
+    }
+    rc = DosAllocMem(lplpMemAddr, cb, flFlags | flAllocMem);
+    DosExitCritSec();
+    if ((DWORD)*lplpMemAddr & 0xFFFF)
+    {   //still not at 64k boundary?
         DosFreeMem(*lplpMemAddr);
-        rc = OSLibDosAllocMem(lplpMemAddr, size, flags);
-  }
-  if(offset) {
-        DosFreeMem(memaddr);
-  }
-
-  return rc;
+        rc = OSLibDosAllocMem(lplpMemAddr, cb, flFlags);
+    }
+    if (offset)
+    {
+        DosFreeMem(pvMemAddr);
+    }
+
+
+    return rc;
 }
 //******************************************************************************
@@ -591,5 +610,5 @@
   dosTime = *(USHORT*)pTime;
   dosDate = *(USHORT*)pDate;
-  
+
   // PH: probably replace with faster implementation than calling Open32
   // through the external interface!
@@ -1700,5 +1719,5 @@
       return;
     }
-    
+
     if (longName[1] == '.' && longName[2] == 0) // ".."
     {
@@ -1716,5 +1735,5 @@
       return;
     }
-  
+
   INT x;
   CHAR *source = longName;
@@ -1723,8 +1742,8 @@
   // the filename.
   BOOL flag83 = TRUE;
-  
+
   // verify forbidden characters
-  for (x = 0; 
-       (x < 8) && 
+  for (x = 0;
+       (x < 8) &&
        (flag83 == TRUE);
        x++)
@@ -1735,5 +1754,5 @@
         x=1000;
         break;
-      
+
       case '/':      case '?':
       case '*':      case ':':
@@ -1747,5 +1766,5 @@
     }
   }
-  
+
   // verify we're on a period now
   if (flag83 == TRUE)
@@ -1753,5 +1772,5 @@
          flag83 = FALSE;
     else source++;
-  
+
   // verify extension
   if (flag83 == TRUE)
@@ -1771,10 +1790,10 @@
       source++;
     }
-  
+
   // verify we're at the end of the string now
   if (flag83 == TRUE)
     if (*source != 0)
       flag83 = FALSE;
-  
+
   // OK, done
   if (flag83 == TRUE)
@@ -1784,16 +1803,16 @@
     // would surely fail.
     strcpy(shortName, longName);
-    
+
     return; // Done
   }
-  
-  
+
+
   // @@@PH
   shortName[0] = 0; // this function is disabled anyway ...
   return;
-  
+
   CHAR *dest = shortName;
   CHAR *ext = strrchr(longName,'.');
-  
+
   //CB: quick and dirty, real FILE~12.EXT is too slow
   //PH: We'd have to count the number of non-8:3-compliant files
@@ -1859,8 +1878,8 @@
     name++;
     strcpy(pFind->cFileName,name);
-  } 
-  else 
+  }
+  else
     pFind->cFileName[0] = 0;
-  
+
   long2ShortName(pFind->cFileName,pFind->cAlternateFileName);
 }
@@ -1922,5 +1941,5 @@
   DosError(FERR_ENABLEHARDERR | FERR_ENABLEEXCEPTION);
 
-  if(rc) 
+  if(rc)
   {
     DosFindClose(hDir);
