Index: /trunk/kProfiler2/Makefile.kmk
===================================================================
--- /trunk/kProfiler2/Makefile.kmk	(revision 8)
+++ /trunk/kProfiler2/Makefile.kmk	(revision 9)
@@ -38,4 +38,8 @@
 #
 TEMPLATE_kPrf2 = kProfiler Template
+if1of ($(BUILD_TARGET), win)
+TEMPLATE_kPrf2_EXTENDS = kStuff
+
+else # Eliminate these
 TEMPLATE_kPrf2_TOOL             = GCC3
 TEMPLATE_kPrf2_TOOL.os2         = GCC3OMF
@@ -47,13 +51,8 @@
 TEMPLATE_kPrf2_SDKS.win         = WINPSDK
 
-TEMPLATE_kPrf2_DEFS.freebsd     = KPRF_OS_FREEBSD
-TEMPLATE_kPrf2_DEFS.linux       = KPRF_OS_LINUX
-TEMPLATE_kPrf2_DEFS.os2         = KPRF_OS_OS2
-TEMPLATE_kPrf2_DEFS.win         = KPRF_OS_WINDOWS
-
 TEMPLATE_kPrf2_CXXFLAGS.freebsd = -g
 TEMPLATE_kPrf2_CXXFLAGS.linux   = -g
 TEMPLATE_kPrf2_CXXFLAGS.os2     = -g
-TEMPLATE_kPrf2_CXXFLAGS.win     = -Zi -Zl -MD -W3 -GF -GR-
+TEMPLATE_kPrf2_CXXFLAGS.win     = -Zi -Zl -W3 -GF -GR-
 TEMPLATE_kPrf2_CXXFLAGS.win.amd64 = -GS- #-FAcs
 ifneq ($(BUILD_TYPE),debug)
@@ -61,5 +60,5 @@
 TEMPLATE_kPrf2_CXXFLAGS.linux  += -O3
 TEMPLATE_kPrf2_CXXFLAGS.os2    += -O3
-TEMPLATE_kPrf2_CXXFLAGS.win    += -O2xtg -Oi -Ob2
+TEMPLATE_kPrf2_CXXFLAGS.win    += -O2b2
 endif
 
@@ -81,10 +80,13 @@
 TEMPLATE_kPrf2_LIBS.linux       =
 TEMPLATE_kPrf2_LIBS.os2         =
-TEMPLATE_kPrf2_LIBS.win        = \
+TEMPLATE_kPrf2_LIBS.win         = \
 	$(PATH_SDK_WINPSDK_LIB)/psapi.Lib
 TEMPLATE_kPrf2_LIBS.win.x86     = \
-	$(PATH_TOOL_VCC70_LIB)/msvcrt.lib \
-	$(PATH_TOOL_VCC70_LIB)/msvcprt.lib \
+	$(PATH_TOOL_VCC70_LIB)/libcmt.lib \
 	$(PATH_TOOL_VCC70_LIB)/oldnames.lib
+TEMPLATE_kPrf2_LIBS.win.amd64   = \
+	$(PATH_TOOL_VCC80AMD64_LIB)/oldnames.lib \
+	$(PATH_TOOL_VCC80AMD64_LIB)/libcmt.lib
+endif
 
 
@@ -116,5 +118,4 @@
 # kPrf2Read - The read & producer of statistics.
 #
-#kPrf2Read_TEMPLATE = kPrf2
 kPrf2Read_TEMPLATE = kStuffEXE
 kPrf2Read_SOURCES  = \
@@ -132,5 +133,5 @@
 tst_TOOL = VCC70
 tst_SDKS = WINPSDK
-tst_CFLAGS = -GH -Gh -Zi -Zl -GR- -GX- -GF- -MD -W3 -wd4244
+tst_CFLAGS = -GH -Gh -Zi -Zl -GR- -GX- -GF- -W3 -wd4244
 tst_SOURCES = tst.c
 tst.c_CFLAGS = -Od
Index: /trunk/kProfiler2/kProfileR3.cpp
===================================================================
--- /trunk/kProfiler2/kProfileR3.cpp	(revision 8)
+++ /trunk/kProfiler2/kProfileR3.cpp	(revision 9)
@@ -29,5 +29,6 @@
 *   Header Files                                                               *
 *******************************************************************************/
-#if defined(KPRF_OS_WINDOWS)
+#include <k/kDefs.h>
+#if K_OS == K_OS_WINDOWS
 # include <windows.h>
 # include <psapi.h>
@@ -38,5 +39,5 @@
 # endif
 
-#elif defined(KPRF_OS_LINUX) || defined(KPRF_OS_FREEBSD)
+#elif K_OS == K_OS_LINUX || K_OS == K_OS_FREEBSD
 # define KPRF_USE_PTHREAD
 # include <pthread.h>
@@ -51,5 +52,5 @@
 # endif
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
 # define INCL_BASE
 # include <os2.h>
@@ -69,5 +70,5 @@
 #define KPRF_NAME(Suffix)               KPrf##Suffix
 #define KPRF_TYPE(Prefix,Suffix)        Prefix##KPRF##Suffix
-#if defined(KPRF_OS_WINDOWS) || defined(KPRF_OS_OS2)
+#if K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
 # define KPRF_DECL_FUNC(type, name)     extern "C"  __declspec(dllexport) type __cdecl KPRF_NAME(name)
 #else
@@ -94,7 +95,7 @@
 #if defined(KPRF_USE_PTHREAD)
 typedef pthread_mutex_t     KPRF_TYPE(,MUTEX);
-#elif defined(KPRF_OS_WINDOWS)
+#elif K_OS == K_OS_WINDOWS
 typedef CRITICAL_SECTION    KPRF_TYPE(,MUTEX);
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
 typedef struct _fmutex      KPRF_TYPE(,MUTEX);
 #endif
@@ -106,5 +107,5 @@
 /** Read/Write lock type. */
 typedef pthread_rwlock_t    KPRF_TYPE(,RWLOCK);
-#elif defined(KPRF_OS_WINDOWS) || defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
 /** Read/Write lock state. */
 typedef enum KPRF_TYPE(,RWLOCKSTATE)
@@ -132,10 +133,10 @@
     /** The current number of waiting writers. */
     KU32                    cWritersWaiting;
-# if defined(KPRF_OS_WINDOWS)
+# if K_OS == K_OS_WINDOWS
     /** The handle of the event object on which the waiting readers block. (manual reset). */
     HANDLE                  hevReaders;
     /** The handle of the event object on which the waiting writers block. (manual reset). */
     HANDLE                  hevWriters;
-# elif defined(KPRF_OS_OS2)
+# elif K_OS == K_OS_OS2
     /** The handle of the event semaphore on which the waiting readers block. */
     HEV                     hevReaders;
@@ -156,5 +157,5 @@
 *******************************************************************************/
 /** The TLS index / key. */
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
 static DWORD                g_dwThreadTLS = TLS_OUT_OF_INDEXES;
 
@@ -162,5 +163,5 @@
 static pthread_key_t        g_ThreadKey = (pthread_key_t)-1;
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
 static KPRF_TYPE(P,THREAD) *g_ppThread = NULL;
 
@@ -211,5 +212,5 @@
 
 /* Win32/64 */
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     pThread = (KPRF_TYPE(P,THREAD))TlsGetValue(g_dwThreadTLS);
 
@@ -218,5 +219,5 @@
     pThread = (KPRF_TYPE(P,THREAD))pthread_getspecific(g_ThreadKey);
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     pThread = *g_ppThread;
 
@@ -239,5 +240,5 @@
 {
 /* Win32/64 */
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     KUPTR ThreadId = (KUPTR)GetCurrentThreadId();
 
@@ -246,5 +247,5 @@
     KUPTR ThreadId = (KUPTR)pthread_self();
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     PTIB pTib;
     PPIB pPib;
@@ -269,8 +270,8 @@
 {
 /* Win32/64 */
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     KUPTR ThreadId = (KUPTR)GetProcessId(GetCurrentProcess());
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     PTIB pTib;
     PPIB pPib;
@@ -299,5 +300,5 @@
 {
 /* Win32/64 */
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     BOOL fRc = TlsSetValue(g_dwThreadTLS, pThread);
 
@@ -306,5 +307,5 @@
     int rc = pthread_setspecific(g_ThreadKey, pThread);
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     *g_ppThread = pThread;
 
@@ -506,9 +507,9 @@
     return -1;
 
-#elif defined(KPRF_OS_WINDOWS)
+#elif K_OS == K_OS_WINDOWS
     InitializeCriticalSection(pMutex);
     return 0;
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     if (!_fmutex_create(pMutex, 0))
         return 0;
@@ -527,8 +528,8 @@
     pthread_mutex_destroy(pMutex);
 
-#elif defined(KPRF_OS_WINDOWS)
+#elif K_OS == K_OS_WINDOWS
     DeleteCriticalSection(pMutex);
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     _fmutex_close(pMutex);
 #endif
@@ -541,5 +542,5 @@
 static inline void kPrfMutexAcquire(KPRF_TYPE(P,MUTEX) pMutex)
 {
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     EnterCriticalSection(pMutex);
 
@@ -547,5 +548,5 @@
     pthread_mutex_lock(pMutex);
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     fmutex_request(pMutex);
 #endif
@@ -559,5 +560,5 @@
 static inline void kPrfMutexRelease(KPRF_TYPE(P,MUTEX) pMutex)
 {
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     LeaveCriticalSection(pMutex);
 
@@ -565,5 +566,5 @@
     pthread_mutex_lock(pMutex);
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     fmutex_request(pMutex);
 #endif
@@ -592,5 +593,5 @@
     return -1;
 
-#elif defined(KPRF_OS_WINDOWS) || defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     if (kPrfMutexInit(&pRWLock->Mutex))
         return -1;
@@ -599,5 +600,5 @@
     pRWLock->cWritersWaiting = 0;
     pRWLock->enmState = RWLOCK_STATE_SHARED;
-# if defined(KPRF_OS_WINDOWS)
+# if K_OS == K_OS_WINDOWS
     pRWLock->hevReaders = CreateEvent(NULL, TRUE, TRUE, NULL);
     pRWLock->hevWriters = CreateEvent(NULL, FALSE, FALSE, NULL);
@@ -608,5 +609,5 @@
     CloseHandle(pRWLock->hevWriters);
 
-# elif defined(KPRF_OS_OS2)
+# elif K_OS == K_OS_OS2
     APIRET rc = DosCreateEventSem(NULL, &pRWLock->hevReaders, 0, TRUE);
     if (!rc)
@@ -638,5 +639,5 @@
     pthread_rwlock_destroy(pRWLock);
 
-#elif defined(KPRF_OS_WINDOWS) || defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     if (pRWLock->enmState == RWLOCK_STATE_UNINITIALIZED)
         return;
@@ -647,5 +648,5 @@
     pRWLock->cReadersWaiting = 0;
     pRWLock->cWritersWaiting = 0;
-# if defined(KPRF_OS_WINDOWS)
+# if K_OS == K_OS_WINDOWS
     CloseHandle(pRWLock->hevReaders);
     pRWLock->hevReaders = INVALID_HANDLE_VALUE;
@@ -653,5 +654,5 @@
     pRWLock->hevWriters = INVALID_HANDLE_VALUE;
 
-# elif defined(KPRF_OS_OS2)
+# elif K_OS == K_OS_OS2
     DosCloseEventSem(pRWLock->hevReaders);
     pRWLock->hevReaders = NULLHANDLE;
@@ -672,5 +673,5 @@
     pthread_rwlock_rdlock(pRWLock);
 
-#elif defined(KPRF_OS_WINDOWS) || defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     if (pRWLock->enmState == RWLOCK_STATE_UNINITIALIZED)
         return;
@@ -688,9 +689,9 @@
         /* have to wait */
         KPRF_ATOMIC_INC32(&pRWLock->cReadersWaiting);
-# if defined(KPRF_OS_WINDOWS)
+# if K_OS == K_OS_WINDOWS
         HANDLE hev = pRWLock->hevReaders;
         ResetEvent(hev);
 
-# elif defined(KPRF_OS_OS2)
+# elif K_OS == K_OS_OS2
         HEV    hev = pRWLock->hevReaders;
         ULONG cIgnored;
@@ -700,5 +701,5 @@
         kPrfMutexRelease(&pRWLock->Mutex);
 
-# if defined(KPRF_OS_WINDOWS)
+# if K_OS == K_OS_WINDOWS
         switch (WaitForSingleObject(hev, INFINITE))
         {
@@ -712,5 +713,5 @@
         }
 
-# elif defined(KPRF_OS_OS2)
+# elif K_OS == K_OS_OS2
         switch (DosWaitEventSem(hev, SEM_INDEFINITE_WAIT))
         {
@@ -747,5 +748,5 @@
     pthread_rwlock_unlock(pRWLock);
 
-#elif defined(KPRF_OS_WINDOWS) || defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     if (pRWLock->enmState == RWLOCK_STATE_UNINITIALIZED)
         return;
@@ -771,7 +772,7 @@
      * Wake up one (or more on OS/2) waiting writers.
      */
-# if defined(KPRF_OS_WINDOWS)
+# if K_OS == K_OS_WINDOWS
     SetEvent(pRWLock->hevWriters);
-# elif defined(KPRF_OS_OS2)
+# elif K_OS == K_OS_OS2
     DosPostEvent(pRWLock->hevwriters);
 # endif
@@ -791,5 +792,5 @@
     pthread_rwlock_wrlock(pRWLock);
 
-#elif defined(KPRF_OS_WINDOWS) || defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     if (pRWLock->enmState == RWLOCK_STATE_UNINITIALIZED)
         return;
@@ -814,11 +815,11 @@
     for (;;)
     {
-# if defined(KPRF_OS_WINDOWS)
+# if K_OS == K_OS_WINDOWS
         HANDLE hev = pRWLock->hevWriters;
-# elif defined(KPRF_OS_OS2)
+# elif K_OS == K_OS_OS2
         HEV    hev = pRWLock->hevWriters;
 # endif
         kPrfMutexRelease(&pRWLock->Mutex);
-# if defined(KPRF_OS_WINDOWS)
+# if K_OS == K_OS_WINDOWS
         switch (WaitForSingleObject(hev, INFINITE))
         {
@@ -833,5 +834,5 @@
         }
 
-# elif defined(KPRF_OS_OS2)
+# elif K_OS == K_OS_OS2
         switch (DosWaitEventSem(hev, SEM_INDEFINITE_WAIT))
         {
@@ -877,5 +878,5 @@
     pthread_rwlock_unlock(pRWLock);
 
-#elif defined(KPRF_OS_WINDOWS) || defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_WINDOWS || K_OS == K_OS_OS2
     if (pRWLock->enmState == RWLOCK_STATE_UNINITIALIZED)
         return;
@@ -902,7 +903,7 @@
      * Someone is waiting, wake them up as we change the state.
      */
-# if defined(KPRF_OS_WINDOWS)
+# if K_OS == K_OS_WINDOWS
     HANDLE hev = INVALID_HANDLE_VALUE;
-# elif defined(KPRF_OS_OS2)
+# elif K_OS == K_OS_OS2
     HEV    hev = NULLHANDLE;
 # endif
@@ -918,7 +919,7 @@
         hev = pRWLock->hevReaders;
     }
-# if defined(KPRF_OS_WINDOWS)
+# if K_OS == K_OS_WINDOWS
     SetEvent(hev);
-# elif defined(KPRF_OS_OS2)
+# elif K_OS == K_OS_OS2
     DosPostEvent(pRWLock->hevwriters);
 # endif
@@ -943,5 +944,5 @@
                          KPRF_TYPE(P,UPTR) puBasePtr, KPRF_TYPE(P,UPTR) pcbSegmentMinusOne)
 {
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     /*
      * Enumerate the module handles.
@@ -1061,5 +1062,5 @@
     }
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     /*
      * Just ask the loader.
@@ -1142,5 +1143,5 @@
      * Some limit stuff in posix / ansi also comes to mind... */
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     PTIB pTib;
     PPIB pPib;
@@ -1172,9 +1173,9 @@
 static char *kPrfGetEnvString(const char *pszVar, char *pszValue, KU32 cchValue, const char *pszDefault)
 {
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     if (GetEnvironmentVariable(pszVar, pszValue, cchValue))
         return pszValue;
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     PSZ pszValue;
     if (    !DosScanEnv((PCSZ)pszVar, &pszValue)
@@ -1211,5 +1212,5 @@
 static KU32 kPrfGetEnvValue(const char *pszVar, KU32 uDefault)
 {
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     char szBuf[128];
     const char *pszValue = szBuf;
@@ -1217,5 +1218,5 @@
         pszValue = NULL;
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     PSZ pszValue;
     if (DosScanEnv((PCSZ)pszVar, &pszValue))
@@ -1300,5 +1301,5 @@
 static void *kPrfAllocMem(KU32 cb)
 {
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     void *pv = VirtualAlloc(NULL, cb, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
 
@@ -1306,5 +1307,5 @@
     void *pv = mmap(NULL, cb, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     void *pv;
 # ifdef INCL_DOSEXAPIS
@@ -1329,5 +1330,5 @@
 static void kPrfFreeMem(void *pv)
 {
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     VirtualFree(pv, 0, MEM_RELEASE);
 
@@ -1335,5 +1336,5 @@
     munmap(pv, 0); /** @todo check if 0 is allowed here.. */
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
 # ifdef INCL_DOSEXAPIS
     DosFreeMemEx(&pv);
@@ -1363,5 +1364,5 @@
 static int kPrfWriteFile(const char *pszName, const void *pvData, KU32 cbData)
 {
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     int rc = -1;
     HANDLE hFile = CreateFile(pszName,GENERIC_WRITE, FILE_SHARE_READ, NULL,
@@ -1377,5 +1378,5 @@
     return rc;
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     HFILE hFile;
     ULONG ulAction = 0;
@@ -1462,5 +1463,5 @@
                      * Allocate the TLS entry.
                      */
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
                     g_dwThreadTLS = TlsAlloc();
                     if (g_dwThreadTLS != TLS_OUT_OF_INDEXES)
@@ -1470,5 +1471,5 @@
                     if (!rc)
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
                     int rc = DosAllocThreadLocalMemory(sizeof(void *), (PULONG*)&g_ppThread); /** @todo check if this is a count or a size. */
                     if (!rc)
@@ -1481,5 +1482,5 @@
                         if (fAffinity)
                         {
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
                             SetProcessAffinityMask(GetCurrentProcess(), fAffinity);
 #endif
@@ -1525,7 +1526,7 @@
         return -1;
 
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     Sleep(10);
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     DosSleep(10);
 #else
@@ -1541,5 +1542,5 @@
      * Use the stack space to fill in process details.
      */
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     /* all is one single string */
     const char *pszCommandLine = GetCommandLine();
@@ -1547,5 +1548,5 @@
         KPRF_NAME(SetCommandLine)(pHdr, 1, &pszCommandLine);
 
-#elif defined(KPRF_OS_OS2) || defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2 || K_OS == K_OS_OS2
     PTIB pTib;
     PPIB pPib;
@@ -1611,5 +1612,5 @@
      */
     kPrfFreeMem(pHdr);
-#if defined(KPRF_OS_WINDOWS)
+#if K_OS == K_OS_WINDOWS
     TlsFree(g_dwThreadTLS);
     g_dwThreadTLS = TLS_OUT_OF_INDEXES;
@@ -1619,5 +1620,5 @@
     g_ThreadKey = (pthread_key_t)-1;
 
-#elif defined(KPRF_OS_OS2)
+#elif K_OS == K_OS_OS2
     DosFreeThreadLocalMemory((PULONG)g_ppThread);
     g_ppThread = NULL;
