Index: trunk/src/kernel32/KERNEL32.CPP
===================================================================
--- trunk/src/kernel32/KERNEL32.CPP	(revision 1640)
+++ trunk/src/kernel32/KERNEL32.CPP	(revision 1641)
@@ -1,3 +1,3 @@
-/* $Id: KERNEL32.CPP,v 1.27 1999-11-08 13:43:12 sandervl Exp $ */
+/* $Id: KERNEL32.CPP,v 1.28 1999-11-08 20:53:24 sandervl Exp $ */
 
 /*
@@ -317,67 +317,4 @@
 //******************************************************************************
 //******************************************************************************
-VOID WIN32API EnterCriticalSection(CRITICAL_SECTION * lpcsCriticalSection)
-{
-////    dprintf(("KERNEL32:  EnterCriticalSection\n"));
-    O32_EnterCriticalSection(lpcsCriticalSection);
-}
-//******************************************************************************
-//******************************************************************************
-VOID WIN32API LeaveCriticalSection(CRITICAL_SECTION * arg1)
-{
-////    dprintf(("KERNEL32:  LeaveCriticalSection\n"));
-    O32_LeaveCriticalSection(arg1);
-}
-//******************************************************************************
-//******************************************************************************
-VOID WIN32API InitializeCriticalSection(CRITICAL_SECTION * arg1)
-{
-    dprintf(("KERNEL32:  InitializeCriticalSection\n"));
-    O32_InitializeCriticalSection(arg1);
-}
-//******************************************************************************
-//******************************************************************************
-void WIN32API MakeCriticalSectionGlobal( CRITICAL_SECTION *arg1 )
-{
-    dprintf(("KERNEL32:  MakeCriticalSectionGlobal not implemented correctly\n"));
-}
-//******************************************************************************
-//******************************************************************************
-/***********************************************************************
- *           ReinitializeCriticalSection   (KERNEL32.581)
- */
-void WIN32API ReinitializeCriticalSection( CRITICAL_SECTION *crit )
-{
-    dprintf(("KERNEL32: ReinitializeCriticalSection\n"));
-    if ( !crit->LockSemaphore )
-        InitializeCriticalSection( crit );
-
-    else if ( crit->Reserved && crit->Reserved != GetCurrentProcessId() )
-    {
-//        FIXME_(win32)("(%p) called for %08lx first, %08lx now: making global\n", 
-//               crit, crit->Reserved, GetCurrentProcessId() );
-
-        MakeCriticalSectionGlobal( crit );
-    }
-}
-//******************************************************************************
-//******************************************************************************
-/***********************************************************************
- *           UninitializeCriticalSection   (KERNEL32.703)
- */
-void WIN32API UninitializeCriticalSection( CRITICAL_SECTION *crit )
-{
-    dprintf(("KERNEL32: UninitializeCriticalSection\n"));
-    if ( crit->LockSemaphore )
-    {
-        if ( crit->Reserved )  /* not global */
-            DeleteCriticalSection( crit );
-//        else
-//            FIXME_(win32)("(%p) for %08lx: Crst is global, don't know whether to delete\n", 
-//                   crit, GetCurrentProcessId() );
-    }
-}
-//******************************************************************************
-//******************************************************************************
 BOOL WIN32API SetEnvironmentVariableA(LPCSTR arg1, LPCSTR arg2)
 {
@@ -456,5 +393,5 @@
 DWORD WIN32API GetCurrentProcessId(void)
 {
-    dprintf(("KERNEL32:  GetCurrentProcessId\n"));
+//    dprintf(("KERNEL32:  GetCurrentProcessId\n"));
     return O32_GetCurrentProcessId();
 }
@@ -527,11 +464,4 @@
 //******************************************************************************
 //SvL: 24-6-'97 - Added
-//******************************************************************************
-VOID WIN32API DeleteCriticalSection( CRITICAL_SECTION * arg1)
-{
-    dprintf(("KERNEL32:  OS2DeleteCriticalSection\n"));
-    O32_DeleteCriticalSection(arg1);
-}
-//******************************************************************************
 //******************************************************************************
 BOOL WIN32API Beep( DWORD arg1, DWORD  arg2)
Index: trunk/src/kernel32/critsection.cpp
===================================================================
--- trunk/src/kernel32/critsection.cpp	(revision 1641)
+++ trunk/src/kernel32/critsection.cpp	(revision 1641)
@@ -0,0 +1,206 @@
+/* $Id: critsection.cpp,v 1.1 1999-11-08 20:53:24 sandervl Exp $ */
+/*
+ * Win32 critical sections
+ * 
+ *
+ *
+ * Copyright 1998 Alexandre Julliard (991031 Port)
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#include <os2win.h>
+#include <assert.h>
+#include <stdio.h>
+#include "debugtools.h"
+#include <misc.h>
+#include <odinwrap.h>
+
+DEFAULT_DEBUG_CHANNEL(win32)
+DECLARE_DEBUG_CHANNEL(relay)
+
+
+HANDLE ODIN_EXTERN(CreateSemaphoreA) (LPSECURITY_ATTRIBUTES arg1, LONG arg2, LONG arg3,
+                                      LPCSTR arg4);
+
+DWORD ODIN_EXTERN(WaitForSingleObject)(HANDLE hObject, DWORD timeout);
+
+HANDLE ODIN_EXTERN(ConvertToGlobalHandle)(HANDLE hHandle);
+
+/***********************************************************************
+ *           InitializeCriticalSection   (KERNEL32.472) (NTDLL.406)
+ */
+void WINAPI InitializeCriticalSection( CRITICAL_SECTION *crit )
+{
+    dprintf(("InitializeCriticalSection %x", crit));
+    crit->LockCount      = -1;
+    crit->RecursionCount = 0;
+    crit->OwningThread   = 0;
+    crit->LockSemaphore  = ODIN_CreateSemaphoreA( NULL, 0, 1, NULL );
+    crit->Reserved       = GetCurrentProcessId();
+}
+
+
+/***********************************************************************
+ *           DeleteCriticalSection   (KERNEL32.185) (NTDLL.327)
+ */
+void WINAPI DeleteCriticalSection( CRITICAL_SECTION *crit )
+{
+    dprintf(("DeleteCriticalSection %x", crit));
+
+    if (crit->LockSemaphore)
+    {
+        if (crit->RecursionCount)  /* Should not happen */
+            dprintf(("Deleting owned critical section (%p)\n", crit ));
+
+        crit->LockCount      = -1;
+        crit->RecursionCount = 0;
+        crit->OwningThread   = 0;
+        CloseHandle( crit->LockSemaphore );
+        crit->LockSemaphore  = 0;
+        crit->Reserved       = (DWORD)-1;
+    }
+}
+
+
+/***********************************************************************
+ *           EnterCriticalSection   (KERNEL32.195) (NTDLL.344)
+ */
+void WINAPI EnterCriticalSection( CRITICAL_SECTION *crit )
+{
+    DWORD res;
+
+    if (!crit->LockSemaphore)
+    {
+    	dprintf(("entering uninitialized section(%p)?\n",crit));
+    	InitializeCriticalSection(crit);
+    }
+    if (InterlockedIncrement( &crit->LockCount ))
+    {
+        if (crit->OwningThread == GetCurrentThreadId())
+        {
+            crit->RecursionCount++;
+            return;
+        }
+        /* Now wait for it */
+
+        if ( crit->Reserved && crit->Reserved != GetCurrentProcessId() )
+        {
+            dprintf(("Crst %p belongs to process %ld, current is %ld!\n", 
+                          crit, crit->Reserved, GetCurrentProcessId() ));
+            return;
+        }
+
+        res = ODIN_WaitForSingleObject( crit->LockSemaphore, 5000L );
+        if ( res == WAIT_TIMEOUT )
+        {
+            dprintf(("Critical section %p wait timed out, retrying (60 sec)\n", crit ));
+            res = WaitForSingleObject( crit->LockSemaphore, 60000L );
+        }
+        if ( res == WAIT_TIMEOUT && TRACE_ON(relay) )
+        {
+            dprintf(("Critical section %p wait timed out, retrying (5 min)\n", crit ));
+            res = WaitForSingleObject( crit->LockSemaphore, 300000L );
+        }
+        if (res != STATUS_WAIT_0)
+        {
+            dprintf(("Critical section %p wait failed err=%lx\n", crit, res ));
+            /* FIXME: should raise an exception */
+        }
+    }
+    crit->OwningThread   = GetCurrentThreadId();
+    crit->RecursionCount = 1;
+}
+
+
+/***********************************************************************
+ *           TryEnterCriticalSection   (KERNEL32.898) (NTDLL.969)
+ */
+BOOL WINAPI TryEnterCriticalSection( CRITICAL_SECTION *crit )
+{
+    if (InterlockedIncrement( &crit->LockCount ))
+    {
+        if (crit->OwningThread == GetCurrentThreadId())
+        {
+            crit->RecursionCount++;
+            return TRUE;
+        }
+        /* FIXME: this doesn't work */
+        InterlockedDecrement( &crit->LockCount );
+        return FALSE;
+    }
+    crit->OwningThread   = GetCurrentThreadId();
+    crit->RecursionCount = 1;
+    return TRUE;
+}
+
+
+/***********************************************************************
+ *           LeaveCriticalSection   (KERNEL32.494) (NTDLL.426)
+ */
+void WINAPI LeaveCriticalSection( CRITICAL_SECTION *crit )
+{
+    if (crit->OwningThread != GetCurrentThreadId()) return;
+       
+    if (--crit->RecursionCount)
+    {
+        InterlockedDecrement( &crit->LockCount );
+        return;
+    }
+    crit->OwningThread = 0;
+    if (InterlockedDecrement( &crit->LockCount ) >= 0)
+    {
+        /* Someone is waiting */
+        ReleaseSemaphore( crit->LockSemaphore, 1, NULL );
+    }
+}
+
+
+/***********************************************************************
+ *           MakeCriticalSectionGlobal   (KERNEL32.515)
+ */
+void WINAPI MakeCriticalSectionGlobal( CRITICAL_SECTION *crit )
+{
+    dprintf(("MakeCriticalSectionGlobal %x", crit));
+    crit->LockSemaphore = ODIN_ConvertToGlobalHandle( crit->LockSemaphore );
+    crit->Reserved      = 0L;
+}
+
+
+/***********************************************************************
+ *           ReinitializeCriticalSection   (KERNEL32.581)
+ */
+void WINAPI ReinitializeCriticalSection( CRITICAL_SECTION *crit )
+{
+    dprintf(("ReinitializeCriticalSection %x", crit));
+
+    if ( !crit->LockSemaphore )
+        InitializeCriticalSection( crit );
+
+    else if ( crit->Reserved && crit->Reserved != GetCurrentProcessId() )
+    {
+        dprintf(("(%p) called for %08lx first, %08lx now: making global\n", 
+               crit, crit->Reserved, GetCurrentProcessId() ));
+
+        MakeCriticalSectionGlobal( crit );
+    }
+}
+
+
+/***********************************************************************
+ *           UninitializeCriticalSection   (KERNEL32.703)
+ */
+void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit )
+{
+    dprintf(("UninitializeCriticalSection %x", crit));
+    if ( crit->LockSemaphore )
+    {
+        if ( crit->Reserved )  /* not global */
+            DeleteCriticalSection( crit );
+        else
+            dprintf(("(%p) for %08lx: Crst is global, don't know whether to delete\n", 
+                     crit, GetCurrentProcessId() ));
+    }
+}
+
Index: trunk/src/kernel32/kobjects.cpp
===================================================================
--- trunk/src/kernel32/kobjects.cpp	(revision 1640)
+++ trunk/src/kernel32/kobjects.cpp	(revision 1641)
@@ -1,3 +1,3 @@
-/* $Id: kobjects.cpp,v 1.7 1999-11-04 20:03:08 phaller Exp $ */
+/* $Id: kobjects.cpp,v 1.8 1999-11-08 20:53:24 sandervl Exp $ */
 
 /*
@@ -389,7 +389,4 @@
               LPCSTR, arg4)
 {
-  dprintf(("KERNEL32: CreateSemaphoreA(%s)\n",
-           arg4));
-
   return HMCreateSemaphore(arg1,
                            arg2,
Index: trunk/src/kernel32/makefile
===================================================================
--- trunk/src/kernel32/makefile	(revision 1640)
+++ trunk/src/kernel32/makefile	(revision 1641)
@@ -1,3 +1,3 @@
-# $Id: makefile,v 1.52 1999-11-08 13:43:12 sandervl Exp $
+# $Id: makefile,v 1.53 1999-11-08 20:53:24 sandervl Exp $
 
 #
@@ -31,5 +31,5 @@
 winimagebase.OBJ windllbase.OBJ winexebase.OBJ time.obj mmap.obj \
 winimagepe2lx.obj winimagepeldr.obj windllpe2lx.obj windlllx.obj windllpeldr.obj \
-winexepe2lx.obj winexelx.obj winexepeldr.obj WINRES.OBJ \
+winexepe2lx.obj winexelx.obj winexepeldr.obj WINRES.OBJ critsection.obj \
 pefile.OBJ winimgres.OBJ wintls.obj async.OBJ fileio.obj \
 atom.obj disk.obj directory.obj cvtbitmap.obj hmmmap.obj winfakepeldr.obj \
Index: trunk/src/kernel32/mmap.cpp
===================================================================
--- trunk/src/kernel32/mmap.cpp	(revision 1640)
+++ trunk/src/kernel32/mmap.cpp	(revision 1641)
@@ -1,3 +1,3 @@
-/* $Id: mmap.cpp,v 1.20 1999-10-27 18:11:39 sandervl Exp $ */
+/* $Id: mmap.cpp,v 1.21 1999-11-08 20:53:24 sandervl Exp $ */
 
 /*
@@ -79,4 +79,10 @@
 		goto fail;
 	}
+	//SvL: Temporary limitation of size (Warp Server Advanced doesn't allow
+        //     one to reserve more than 450 MB of continuous memory; (Warp 4
+        //     much less))
+	if(mSize > 64*1024*1024) {
+		mSize = 64*1024*1024;
+	}
   }
 
