Index: trunk/src/kernel32/dbglocal.cpp
===================================================================
--- trunk/src/kernel32/dbglocal.cpp	(revision 9944)
+++ trunk/src/kernel32/dbglocal.cpp	(revision 9945)
@@ -1,3 +1,3 @@
-/* $Id: dbglocal.cpp,v 1.27 2002-07-13 15:58:20 sandervl Exp $ */
+/* $Id: dbglocal.cpp,v 1.28 2003-03-27 14:00:52 sandervl Exp $ */
 
 /*
@@ -142,4 +142,7 @@
 "conodin32",
 "oslibmem",
+"mmapview",
+"mmapdup",
+"oslibthread"
 };
 //******************************************************************************
Index: trunk/src/kernel32/dbglocal.h
===================================================================
--- trunk/src/kernel32/dbglocal.h	(revision 9944)
+++ trunk/src/kernel32/dbglocal.h	(revision 9945)
@@ -138,5 +138,8 @@
 #define DBG_conodin32      118
 #define DBG_oslibmem       119
-#define DBG_MAXFILES       120
+#define DBG_mmapview       120
+#define DBG_mmapdup        121
+#define DBG_oslibthread    122
+#define DBG_MAXFILES       123
 
 extern USHORT DbgEnabledKERNEL32[DBG_MAXFILES];
Index: trunk/src/kernel32/kernel32.mak
===================================================================
--- trunk/src/kernel32/kernel32.mak	(revision 9944)
+++ trunk/src/kernel32/kernel32.mak	(revision 9945)
@@ -1,3 +1,3 @@
-# $Id: kernel32.mak,v 1.42 2003-03-06 10:44:33 sandervl Exp $
+# $Id: kernel32.mak,v 1.43 2003-03-27 14:00:52 sandervl Exp $
 
 #
@@ -100,4 +100,6 @@
 $(OBJDIR)\time.obj \
 $(OBJDIR)\mmap.obj \
+$(OBJDIR)\mmapview.obj \
+$(OBJDIR)\mmapdup.obj \
 $(OBJDIR)\winimagepe2lx.obj \
 $(OBJDIR)\winimagepeldr.obj \
@@ -138,4 +140,5 @@
 $(OBJDIR)\queue.obj \
 $(OBJDIR)\hmthread.obj \
+$(OBJDIR)\oslibthread.obj \
 $(OBJDIR)\hmnpipe.obj \
 $(OBJDIR)\hmdisk.obj \
Index: trunk/src/kernel32/oslibdos.cpp
===================================================================
--- trunk/src/kernel32/oslibdos.cpp	(revision 9944)
+++ trunk/src/kernel32/oslibdos.cpp	(revision 9945)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.cpp,v 1.118 2003-03-03 16:39:11 sandervl Exp $ */
+/* $Id: oslibdos.cpp,v 1.119 2003-03-27 14:00:52 sandervl Exp $ */
 /*
  * Wrappers for OS/2 Dos* API
@@ -3293,61 +3293,7 @@
 //******************************************************************************
 //******************************************************************************
-DWORD OSLibDosSetPriority(ULONG tid, int priority)
-{
-    DWORD  ret, os2priorityclass;
-    LONG   os2prioritydelta;
-    APIRET rc;
-
-    switch(priority)
-    {
-    case THREAD_PRIORITY_IDLE_W:
-        os2priorityclass = PRTYC_IDLETIME;
-        os2prioritydelta = 0;
-        break;
-    case THREAD_PRIORITY_LOWEST_W:
-        os2priorityclass = PRTYC_REGULAR;
-        os2prioritydelta = PRTYD_MINIMUM;
-        break;
-    case THREAD_PRIORITY_BELOW_NORMAL_W:
-        os2priorityclass = PRTYC_REGULAR;
-        os2prioritydelta = -15;
-        break;
-    case THREAD_PRIORITY_NORMAL_W:
-        os2priorityclass = PRTYC_REGULAR;
-        os2prioritydelta = 0;
-        break;
-    case THREAD_PRIORITY_ABOVE_NORMAL_W:
-        os2priorityclass = PRTYC_REGULAR;
-        os2prioritydelta = 15;
-        break;
-    case THREAD_PRIORITY_HIGHEST_W:
-        os2priorityclass = PRTYC_REGULAR;
-        os2prioritydelta = PRTYD_MAXIMUM;
-        break;
-    case THREAD_PRIORITY_TIME_CRITICAL_W:
-        os2priorityclass = PRTYC_TIMECRITICAL;
-        os2prioritydelta = 0;
-        break;
-    default:
-        dprintf(("!WARNING!: Invalid priority!!"));
-        SetLastError(ERROR_INVALID_PARAMETER_W);
-        return ERROR_INVALID_PARAMETER_W;
-    }
-    rc = DosSetPriority(PRTYS_THREAD, os2priorityclass, os2prioritydelta, tid);
-    ret = error2WinError(rc, ERROR_INVALID_PARAMETER);
-    SetLastError(ret);
-    return ret;
-}
-//******************************************************************************
-//******************************************************************************
 void  OSLibDosSleep(ULONG msecs)
 {
   DosSleep(msecs);
-}
-//******************************************************************************
-//******************************************************************************
-void OSLibDosExitThread(ULONG retcode)
-{
-  DosExit(EXIT_THREAD, retcode);
 }
 //******************************************************************************
Index: trunk/src/kernel32/oslibdos.h
===================================================================
--- trunk/src/kernel32/oslibdos.h	(revision 9944)
+++ trunk/src/kernel32/oslibdos.h	(revision 9945)
@@ -1,3 +1,3 @@
-/* $Id: oslibdos.h,v 1.51 2003-01-10 12:57:14 sandervl Exp $ */
+/* $Id: oslibdos.h,v 1.52 2003-03-27 14:00:53 sandervl Exp $ */
 
 /*
@@ -356,7 +356,4 @@
 DWORD OSLibDosDevConfig(PVOID pdevinfo, ULONG item);
 void  OSLibDosSleep(ULONG msecs);
-void  OSLibDosExitThread(ULONG retcode);
-
-DWORD OSLibDosSetPriority(ULONG tid, int priority);
 
 //functions for physical disk & partition information
Index: trunk/src/kernel32/oslibmem.cpp
===================================================================
--- trunk/src/kernel32/oslibmem.cpp	(revision 9944)
+++ trunk/src/kernel32/oslibmem.cpp	(revision 9945)
@@ -1,3 +1,3 @@
-/* $Id: oslibmem.cpp,v 1.6 2003-03-06 10:44:34 sandervl Exp $ */
+/* $Id: oslibmem.cpp,v 1.7 2003-03-27 14:00:53 sandervl Exp $ */
 /*
  * Wrappers for OS/2 Dos* API
@@ -44,4 +44,5 @@
 //******************************************************************************
 //TODO: Check if this works for code aliases...
+//NOTE: DosAliasMem fails if the address isn't page aligned
 //******************************************************************************
 DWORD OSLibDosAliasMem(LPVOID pb, ULONG cb, LPVOID *ppbAlias, ULONG fl)
Index: trunk/src/kernel32/oslibthread.cpp
===================================================================
--- trunk/src/kernel32/oslibthread.cpp	(revision 9945)
+++ trunk/src/kernel32/oslibthread.cpp	(revision 9945)
@@ -0,0 +1,177 @@
+/* $Id: oslibthread.cpp,v 1.1 2003-03-27 14:00:53 sandervl Exp $ */
+/*
+ * Wrappers for OS/2 Dos* API (Thread)
+ *
+ * Copyright 1998-2002 Sander van Leeuwen (sandervl@xs4all.nl)
+ * Copyright 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#define INCL_BASE
+#define INCL_DOSEXCEPTIONS
+#define INCL_DOSMEMMGR
+#define INCL_DOSPROCESS
+#define INCL_DOSFILEMGR
+#define INCL_DOSERRORS
+#define INCL_DOSDEVIOCTL
+#define INCL_DOSDEVICES
+#define INCL_NPIPES
+#include <os2wrap.h>                     //Odin32 OS/2 api wrappers
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <win32api.h>
+#include <winconst.h>
+#include <dbglog.h>
+#include "oslibdos.h"
+#include "oslibthread.h"
+#include "exceptions.h"
+
+#define DBG_LOCALLOG    DBG_oslibthread
+#include "dbglocal.h"
+
+//******************************************************************************
+//******************************************************************************
+DWORD OSLibDosSetPriority(ULONG tid, int priority)
+{
+    DWORD  ret, os2priorityclass;
+    LONG   os2prioritydelta;
+    APIRET rc;
+
+    switch(priority)
+    {
+    case THREAD_PRIORITY_IDLE_W:
+        os2priorityclass = PRTYC_IDLETIME;
+        os2prioritydelta = 0;
+        break;
+    case THREAD_PRIORITY_LOWEST_W:
+        os2priorityclass = PRTYC_REGULAR;
+        os2prioritydelta = PRTYD_MINIMUM;
+        break;
+    case THREAD_PRIORITY_BELOW_NORMAL_W:
+        os2priorityclass = PRTYC_REGULAR;
+        os2prioritydelta = -15;
+        break;
+    case THREAD_PRIORITY_NORMAL_W:
+        os2priorityclass = PRTYC_REGULAR;
+        os2prioritydelta = 0;
+        break;
+    case THREAD_PRIORITY_ABOVE_NORMAL_W:
+        os2priorityclass = PRTYC_REGULAR;
+        os2prioritydelta = 15;
+        break;
+    case THREAD_PRIORITY_HIGHEST_W:
+        os2priorityclass = PRTYC_REGULAR;
+        os2prioritydelta = PRTYD_MAXIMUM;
+        break;
+    case THREAD_PRIORITY_TIME_CRITICAL_W:
+        //NOTE: There is code relying on the fact that win32 threads can never
+        //      have the maximum priority available in OS/2!!
+        //      (e.g. SetThreadContext)
+        dprintf(("PRTYC_TIMECRITICAL!!"));
+        os2priorityclass = PRTYC_TIMECRITICAL;
+        os2prioritydelta = 0;
+        break;
+    default:
+        dprintf(("!WARNING!: Invalid priority!!"));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return ERROR_INVALID_PARAMETER_W;
+    }
+    rc = DosSetPriority(PRTYS_THREAD, os2priorityclass, os2prioritydelta, tid);
+    ret = error2WinError(rc, ERROR_INVALID_PARAMETER);
+    SetLastError(ret);
+    return ret;
+}
+//******************************************************************************
+//Useful to temporarily boost the priority to max to ensure it's scheduled first
+//Windows threads never receive such a high priority (time critical, delta 0 = max)
+//******************************************************************************
+void OSLibDosSetMaxPriority(ULONG tid)
+{
+    APIRET rc;
+
+    dprintf(("OSLibDosSetMaxPriority for %x", tid));
+    rc = DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, tid);
+    if(rc != NO_ERROR) {
+        DebugInt3();
+    }
+}
+//******************************************************************************
+//******************************************************************************
+void OSLibDosExitThread(ULONG retcode)
+{
+    DosExit(EXIT_THREAD, retcode);
+}
+//******************************************************************************
+//******************************************************************************
+BOOL OSLibQueryThreadContext(ULONG ulThreadId, ULONG teb_sel, CONTEXT *lpContext)
+{
+    CONTEXTRECORD ctxrec;
+    APIRET        rc;
+    int           nrtries = 0;
+
+tryagain:
+    rc = DosQueryThreadContext(ulThreadId, CONTEXT_FULL, &ctxrec);
+    if(rc != NO_ERROR) {
+        dprintf(("ERROR: DosQueryThreadContext failed with rc %d!!", rc));
+        if(rc == ERROR_NOT_FROZEN && ++nrtries < 5) {
+            DosSleep(50);
+            goto tryagain;
+        }
+        SetLastError(error2WinError(rc, ERROR_INVALID_PARAMETER));
+        return FALSE;
+    }
+    if(lpContext->ContextFlags & WINCONTEXT_CONTROL) {
+        lpContext->Ebp     = ctxrec.ctx_RegEbp;
+        lpContext->Eip     = ctxrec.ctx_RegEip;
+        lpContext->SegCs   = ctxrec.ctx_SegCs;
+        lpContext->EFlags  = ctxrec.ctx_EFlags;
+        lpContext->Esp     = ctxrec.ctx_RegEsp;
+        lpContext->SegSs   = ctxrec.ctx_SegSs;
+    }
+    if(lpContext->ContextFlags & WINCONTEXT_INTEGER) {
+        lpContext->Edi     = ctxrec.ctx_RegEdi;
+        lpContext->Esi     = ctxrec.ctx_RegEsi;
+        lpContext->Ebx     = ctxrec.ctx_RegEbx;
+        lpContext->Edx     = ctxrec.ctx_RegEdx;
+        lpContext->Ecx     = ctxrec.ctx_RegEcx;
+        lpContext->Eax     = ctxrec.ctx_RegEax;
+    }
+    if(lpContext->ContextFlags & WINCONTEXT_SEGMENTS) {
+        lpContext->SegGs   = ctxrec.ctx_SegGs;
+//   This resets FS to 0x150B - we DON'T want that!!
+//      lpContext->SegFs   = ctxrec.ctx_SegFs;
+        lpContext->SegFs   = teb_sel;
+        lpContext->SegEs   = ctxrec.ctx_SegEs;
+        lpContext->SegDs   = ctxrec.ctx_SegDs;
+    }
+    if(lpContext->ContextFlags & WINCONTEXT_FLOATING_POINT) {
+        //TODO: First 7 dwords the same?
+        memcpy(&lpContext->FloatSave, ctxrec.ctx_env, sizeof(ctxrec.ctx_env));
+        memcpy(&lpContext->FloatSave.RegisterArea, ctxrec.ctx_stack, sizeof(ctxrec.ctx_stack));
+    }
+    SetLastError(ERROR_SUCCESS_W);
+    return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+void OSLibDisableThreadSwitching()
+{
+    DosEnterCritSec();
+}
+//******************************************************************************
+//******************************************************************************
+void OSLibEnableThreadSwitching()
+{
+    DosExitCritSec();
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/kernel32/oslibthread.h
===================================================================
--- trunk/src/kernel32/oslibthread.h	(revision 9945)
+++ trunk/src/kernel32/oslibthread.h	(revision 9945)
@@ -0,0 +1,29 @@
+/* $Id: oslibthread.h,v 1.1 2003-03-27 14:00:54 sandervl Exp $ */
+
+/*
+ * OS/2 thread apis
+ *
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#ifndef __OSLIBTHREAD_H__
+#define __OSLIBTHREAD_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+BOOL  OSLibQueryThreadContext(ULONG ulThreadId, ULONG teb_sel, CONTEXT *lpContext);
+void  OSLibDosExitThread(ULONG retcode);
+DWORD OSLibDosSetPriority(ULONG tid, int priority);
+void  OSLibDosSetMaxPriority(ULONG tid);
+
+void  OSLibDisableThreadSwitching();
+void  OSLibEnableThreadSwitching();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //__OSLIBTHREAD_H__
Index: trunk/src/kernel32/thread.cpp
===================================================================
--- trunk/src/kernel32/thread.cpp	(revision 9944)
+++ trunk/src/kernel32/thread.cpp	(revision 9945)
@@ -1,3 +1,3 @@
-/* $Id: thread.cpp,v 1.52 2003-03-06 12:49:08 sandervl Exp $ */
+/* $Id: thread.cpp,v 1.53 2003-03-27 14:00:54 sandervl Exp $ */
 
 /*
@@ -32,4 +32,5 @@
 #include "oslibmisc.h"
 #include "oslibdos.h"
+#include "oslibthread.h"
 #include <handlemanager.h>
 #include <codepage.h>
