Index: trunk/src/win32k/kKrnlLib/src/tstDH.asm
===================================================================
--- trunk/src/win32k/kKrnlLib/src/tstDH.asm	(revision 8211)
+++ trunk/src/win32k/kKrnlLib/src/tstDH.asm	(revision 8211)
@@ -0,0 +1,747 @@
+; $Id: tstDH.asm,v 1.1 2002-04-07 22:39:13 bird Exp $
+;
+; Device Helper Router.
+; Stack Thunker.
+;
+; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+;
+; Project Odin Software License can be found in LICENSE.TXT
+;
+    .386
+
+
+;
+; Include files
+;
+    include devsegdf.inc
+    include devhlp.inc
+
+
+;
+; Exported symbols
+;
+    public  ThunkStack16To32
+    public  ThunkStack32To16
+    public  TKSSBase
+    public  getDHRouterFarPtr
+    ;public  DHRouter
+
+
+;
+; extrns
+;
+    extrn DOS32ALLOCMEM:PROC
+    extrn DOS32FREEMEM:PROC
+    extrn DOS16GETINFOSEG:PROC
+    extrn DOS16SYSTRACE:PROC
+    extrn _Device_Help:DWORD
+    extrn pulTKSSBase32:DWORD
+    extrn _TKSSBase16:DWORD
+    extrn _R0FlatCS16:WORD
+    extrn _R0FlatDS16:WORD
+
+
+
+
+CODE16 SEGMENT
+    ASSUME cs:CODE16, ds:FLAT
+
+
+
+;;
+; Devhelp routiner routine.
+; @cproto none
+; @param     dl     Devhelper routine.
+; @uses      none but the ones returned.
+; @sketch
+; @status
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark
+DHRouter PROC FAR
+    ASSUME cs:CODE16, ds:NOTHING, es:NOTHING, ss:NOTHING
+    ;
+    ; Preserve nearly everything (as a start)
+    ;
+    push    ds
+    push    es
+    push    fs
+    push    gs
+    push    edi
+    push    esi
+    push    ebp
+    push    edx
+    push    ecx
+    push    ebx
+
+
+    cmp     dl, DevHlp_RAS
+    jne     dhr0
+    call    dh_RAS
+    jmp     dhr_ret
+
+dhr0:
+    cmp     dl, DevHlp_VirtToLin
+    jne     dhr1
+    call    dh_VirtToLin
+    jmp     dhr_ret
+
+dhr1:
+    cmp     dl, DevHlp_VMAlloc
+    jne     dhr2
+    call    dh_VMAlloc
+    jmp     dhr_ret
+
+dhr2:
+    cmp     dl, DevHlp_VMFree
+    jne     dhr3
+    call    dh_VMFree
+    jmp     dhr_ret
+
+dhr3:
+    cmp     dl, DevHlp_GetDOSVar
+    jne     dhr4
+    call    dh_GetDOSVar
+    add     sp, 4                       ; remove ebx from stack
+    jmp     dhr_ret_ebx
+
+dhr4:
+    cmp     dl, DevHlp_VMLock
+    jne     dhr5
+    call    dh_VMLock
+    jmp     dhr_ret
+
+dhr5:
+    cmp     dl, DevHlp_VMUnlock
+    jne     dhr6
+    call    dh_VMUnlock
+    jmp     dhr_ret
+
+dhr6:
+    cmp     dl, DevHlp_VerifyAccess
+    jne     dhr7
+    call    dh_VerifyAccess
+    jmp     dhr_ret
+
+dhr7:
+
+dhr_notimplemented:
+    stc
+    mov     eax, 87 ;ERROR_INVALID_PARAMETER
+
+    ;
+    ; Restore nearly everything (as a start)
+    ;
+dhr_ret:
+    pop     ebx
+dhr_ret_ebx:
+    pop     ecx
+    pop     edx
+    pop     ebp
+    pop     esi
+    pop     edi
+    pop     gs
+    pop     fs
+    pop     es
+    pop     ds
+    ret
+DHRouter ENDP
+
+
+;;
+; Insert trace information to the system trace buffer.
+; @cproto   none
+; @param    AX      Major trace event code.
+; @param    BX      Length of data area.
+; @param    CX      Major trace event code.
+; @param    DS:SI   Pointer to trace data.
+; @returns  Success:
+;               CF      clear
+;               AX      ??
+;           Failure:
+;               CF      set
+;               AX      error code.
+; @uses      ax
+; @status    completely impelemented.
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+dh_RAS PROC NEAR
+    push    ax
+    push    bx
+    push    cx
+    push    ds
+    push    si
+
+    call far ptr DOS16SYSTRACE
+    or      ax, ax
+    jz      dh_RAS_ret
+    stc
+
+dh_RAS_ret:
+    ret
+dh_RAS ENDP
+
+
+;;
+; Converts a virtual (sel:off) address to a linear address.
+; @cproto    none
+; @param     AX     Selector
+; @param     ESI    Offset
+; @param     DL     DevHelp_VirtToLin
+; @returns   Success:
+;               CF      clear
+;               EAX     Linear address
+;
+;            Failure:
+;               CF      set
+;               EAX     Error code.
+;
+; @uses      eax
+; @status    completely impelemented.
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+dh_VirtToLin PROC NEAR
+    ASSUME cs:CODE16, ds:NOTHING, es:NOTHING, ss:NOTHING
+    shl     eax, SEL_FLAT_SHIFT
+    and     eax, SEL_FLATMASK
+    add     eax, esi
+vtl_retok:
+    clc
+    ret
+
+vtl_reterr:
+    stc
+    ret
+dh_VirtToLin ENDP
+
+
+
+
+;;
+; Allocates virtual memory.
+; @cproto    none
+; @param     ECX    Amount of memory to allocate.
+; @param     EDI    Pointer to DD var containing physical address to be mapped.
+;                   -1 if not used.
+; @param     EAX    Flags. These flags are supported:
+;                       VMDHA_SWAP
+;                       VMDHA_USEHIGHMEM
+;                       VMDHA_RESERVE
+; @param     DH     DevHlp_VMAlloc
+;
+; @returns   Success:
+;               CF      Clear
+;               EAX     Linear address of object.
+;
+;            Failure:
+;               CF      Set.
+;               EAX     Error code. ERROR_INVALID_PARAMETER.
+;
+; @uses      edx, ecx, eax
+; @equiv
+; @time
+; @sketch    For it into an call to DosAllocMem
+; @status
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark
+dh_VMAlloc PROC NEAR
+    ASSUME cs:CODE16, ds:NOTHING, es:NOTHING, ss:NOTHING
+
+; define the flags which are used here
+VMDHA_SWAP          EQU 0004h
+VMDHA_RESERVE       EQU 0100h
+VMDHA_USEHIGHMEM    EQU 0800h
+
+    ;
+    ; Check input parametes.
+    ;
+    mov     edx, eax
+    and     edx, NOT (VMDHA_SWAP OR VMDHA_USEHIGHMEM OR VMDHA_RESERVE)
+    jnz     vma_reterr                  ; Jump if unsupported flag(s) are set.
+    cmp     edi, 0ffffffffh             ; Check that EDI is -1.
+    jne     vma_reterr                  ; Jump if EDI != -1
+
+    jmp     far ptr FLAT:Thunk32_dh_VMAlloc
+Thunk16_dh_VMAlloc::
+    or      eax, eax                    ; Successful return from Dos32AllocMem?
+    jnz     vma_reterr                  ; Jump on failure.
+    mov     eax, edx                    ; EAX is now 32-bit pointer to the allocated memory.
+
+vma_retok:
+    clc
+    ret
+
+vma_reterr:
+    mov     eax, 87                     ; ERROR_INVALID_PARAMETER
+    stc
+    ret
+dh_VMAlloc ENDP
+CODE16 ENDS
+
+
+CODE32 SEGMENT
+Thunk32_dh_VMAlloc::
+    ASSUME cs:CODE32, ds:NOTHING, es:NOTHING, ss:NOTHING
+    ;
+    ; Call Dos32AllocMem to allocate the requested memory.
+    ;
+    push    eax                         ; Make space for return pointer.
+    mov     edx, esp                    ; Take address of return pointer.
+    test    edx, 0ffff0000h
+    jnz     vma_stack32                 ; Jump if stack is 32-bit
+    xor     edx, edx
+    mov     dx, ss                      ; Make 32-bit pointer to return pointer.
+    shl     edx, SEL_FLAT_SHIFT
+    and     edx, SEL_FLATMASK
+    mov     dx,  sp                     ; EDX is now 32-bit pointer to return pointer.
+vma_stack32:
+
+    test    eax, VMDHA_RESERVE
+    jz      vma1
+    push    0043h                       ; Flags: OBJ_TILE | PAG_READ | PAG_WRITE
+    jmp     vma2
+vma1:
+    push    0053h                       ; Flags: OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE
+vma2:
+    push    ecx                         ; Number of bytes to allocate.
+    push    edx                         ; Pointer to return pointer.
+    call    DOS32ALLOCMEM
+    add     esp, 12
+    pop     edx                         ; Pointer to allocated memory if any...
+
+    jmp     far ptr CODE16:Thunk16_dh_VMAlloc
+CODE32 ENDS
+
+
+CODE16 SEGMENT
+;;
+; Frees memory allocated with VMAlloc.
+; @cproto    none
+; @param     EAX        Linear address of the memory to be freed.
+; @returns   Success:
+;               CF      Clear
+;
+;            Failure:
+;               CF      Set
+;               EAX     Errorcode
+;                       ERROR_ACCESS_DENIED
+;                       ERROR_INVALID_PARAMETER
+;
+; @uses      eax, ecx, edx
+; @status    completely implemented.
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+dh_VMFree PROC NEAR
+    ASSUME cs:CODE16, ds:NOTHING, es:NOTHING, ss:NOTHING
+    jmp     far ptr FLAT:Thunk32_dh_VMFree
+Thunk16_dh_VMFree::
+    or      eax, eax
+    jnz     vmf_reterr
+
+vmf_retok:
+    clc
+    ret
+
+vmf_reterr:
+    stc
+    ret
+dh_VMFree ENDP
+CODE16 ENDS
+
+
+CODE32 SEGMENT
+; 32-bit part of the dh_VMFree worker
+Thunk32_dh_VMFree::
+    ASSUME cs:CODE32, ds:NOTHING, es:NOTHING, ss:NOTHING
+    push    eax
+    call    DOS32FREEMEM
+    sub     esp, 4
+    jmp     far ptr CODE16:Thunk16_dh_VMFree
+CODE32 ENDS
+
+
+CODE16 SEGMENT
+;;
+; Get addresses of kernel variables.
+; @cproto    none.
+; @param     AL     Index.
+;                   These indexes are supported:
+;                       DHGETDOSV_SYSINFOSEG     1
+;                       DHGETDOSV_LOCINFOSEG     2
+;                       DHGETDOSV_YIELDFLAG      7
+;                       DHGETDOSV_TCYIELDFLAG    8
+;                       DHGETDOSV_DOSTABLE       9
+;
+;
+; @param     CX     VarMember (only index 14 and 16)
+; @param     DL     DevHlp_GetDOSVar
+; @returns   Success:
+;               CF      Clear
+;               AX:BX   Points to the index.
+;
+;            Failure:
+;               CF      Set.
+;
+; @uses     eax, ebx, ecx, edx
+; @sketch
+; @status
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark
+dh_GetDOSVar PROC NEAR
+    ASSUME cs:CODE16, ds:NOTHING, es:NOTHING, ss:NOTHING
+    cmp     al, 1
+    je      gdv_12
+    cmp     al, 2
+    je      gdv_12
+    cmp     al, 7
+    je      gdv_8
+    cmp     al, 8
+    je      gdv_8
+    cmp     al, 9
+    je      gdv_9
+    jmp     gdv_reterr
+
+gdv_12:
+    push    ax
+    push    ax                          ; make space for selGIS
+    mov     ax, sp                      ; offset selGIS
+    push    ax                          ; make space for selLIS
+    mov     bx, sp                      ; offset selLIS
+    push    ss
+    push    ax                          ; &selGIS
+    push    ss
+    push    bx                          ; &selLIS
+    call    far ptr DOS16GETINFOSEG
+    pop     bx                          ; selLIS
+    pop     cx                          ; selGIS
+    pop     dx                          ; index parameter
+    or      ax, ax                      ; Did it fail?
+    jnz     gdv_reterr                  ; Jump if it failed.
+    cmp     dx, 1
+    je      gdv_12_1
+    mov     bx, cx                      ; bx <- selGIS
+gdv_12_1:
+    xor     ax, ax
+    jmp     gdv_retok
+
+gdv_7:
+    mov     ebx, offset YieldFlag
+    mov     ax, seg YieldFlag
+    jmp     gdv_retok
+
+gdv_8:
+    mov     ebx, offset TCYieldFlag
+    mov     ax, seg TCYieldFlag
+    jmp     gdv_retok
+
+gdv_9:
+    mov     ebx, offset DosTable
+    mov     ax, seg DosTable
+    jmp     gdv_retok
+
+gdv_retok:
+    clc
+    ret
+
+gdv_reterr:
+    stc
+    ret
+dh_GetDOSVar ENDP
+CODE16 ENDS
+
+
+DATA16 SEGMENT
+;; GetDosVar data
+;
+; The two YieldFlags
+;
+YieldFlag                       db 0
+TCYieldFlag                     db 0
+DATA16 ENDS
+
+
+DATA32 SEGMENT
+;
+; 32-bit flat stack base.
+;
+TKSSBase                        dd 0
+DATA32 ENDS
+
+DATA16 SEGMENT
+    ASSUME ds:NOTHING, es:NOTHING, ss:NOTHING
+;
+; The two dostables.
+;
+DosTable                        db 17
+  DosTable_fph_HardError        dd 0
+  DosTable_fph_UCase            dd 0
+  DosTable_UnknownOrReserved1   dd 0
+  DosTable_UnknownOrReserved2   dd 0
+  DosTable_UnknownOrReserved3   dd 0
+  DosTable_fph_MemMapAlias      dd 0
+  DosTable_fph_MemUnmapAlias    dd 0
+  DosTable_fph_GoProtAll        dd 0
+  DosTable_fph_GoRealAll        dd 0
+  DosTable_fph_doshlp_RedirDev  dd 0
+  DosTable_UnknownOrReserved4   dd 0
+  DosTable_UnknownOrReserved5   dd 0
+  DosTable_fph_SFFromSFN        dd 0
+  DosTable_fph_SegGetInfo       dd 0
+  DosTable_fph_AsgCheckDrive    dd 0
+  DosTable_UnknownOrReserved6   dd 0
+  DosTable_UnknownOrReserved7   dd 0
+
+DosTabel2                       db  19
+  DosTable2_fpErrMap24          dd 0
+  DosTable2_fpErrMap24End       dd 0
+  DosTable2_fpErr_Table_24      dd 0
+  DosTable2_fpCDSAddr           dd 0
+  DosTable2_fpGDT_RDR1          dd 0
+  DosTable2_fpInterrupLevel     dd 0
+  DosTable2_fp_cInDos           dd 0
+  DosTable2_UnknownOrReserved1  dd 0
+  DosTable2_UnknownOrReserved2  dd 0
+  DosTable2_R0FlatCS            dw seg FLAT:CODE32
+                                dw 0
+  DosTable2_R0FlatDS            dw seg FLAT:DATA32
+                                dw 0
+  DosTable2_pTKSSBase           dd offset FLAT:DATA32:TKSSBase
+  DosTable2_pintSwitchStack     dd 0
+  DosTable2_pprivatStack        dd 0
+  DosTable2_fpPhysDiskTablePtr  dd 0
+  DosTable2_pforceEMHandler     dd 0
+  DosTable2_pReserveVM          dd 0
+  DosTable2_p_pgpPageDir        dd 0
+  DosTable2_UnknownOrReserved3  dd 0
+DATA16 ENDS
+
+
+CODE16 SEGMENT
+
+
+;;
+; VMLock stub.
+; @returns  NO_ERROR. (0)
+; @param    ignored.
+; @uses     eax
+; @status   stub.
+; @author   knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+dh_VMLock PROC NEAR
+    xor     eax, eax
+    clc
+    ret
+dh_VMLock ENDP
+
+
+
+;;
+; VMUnlock stub.
+; @returns  NO_ERROR. (0)
+; @param    ignored.
+; @uses     eax
+; @status   stub.
+; @author   knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+dh_VMUnlock PROC NEAR
+    xor     eax, eax
+    clc
+    ret
+dh_VMUnlock ENDP
+
+
+;;
+; VerifyAccess stub.
+; @returns  NO_ERROR. (0)
+; @param    ignored.
+; @uses     eax
+; @status   stub.
+; @author   knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+dh_VerifyAccess PROC NEAR
+    xor     eax, eax
+    clc
+    ret
+dh_VerifyAccess ENDP
+
+
+CODE16 ENDS
+
+
+
+
+CODE32 SEGMENT
+;;
+; Initiates the Device_Help function pointer.
+;
+; During startup the C library startup routines needs to use the heap.
+; So the heap has to work before main is able to initiate it. The heap
+; uses device helpers so they have to be initiated too. So, this init
+; routine is called during heap init, _rmem_init.
+;
+; @cproto    void _Optlink dhinit(void)
+; @returns   NO_ERROR.
+; @param     none.
+; @uses      eax
+; @sketch
+; @status    completly implemented
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark
+dhinit PROC NEAR
+    ASSUME cs:CODE32, ds:FLAT, es:NOTHING, ss:NOTHING
+    ;
+    ; _Device_Help - d16globl.c
+    ;
+if 0 ;done during device init.
+    mov     ax, seg DHRouter
+    shl     eax, 16
+    mov     ax, offset DHRouter
+    mov     _Device_Help, eax
+endif
+
+    ;
+    ; pulTKSSBase32
+    ; DosTable2_pTKSSBase
+    ; DosTable2_R0FlatCS
+    ; DosTable2_R0FlatDS
+    ;
+    mov     eax, offset FLAT:TKSSBase
+    mov     pulTKSSBase32, eax          ; We need it as our testing subsystem uses it too.
+if 0 ; not neede any longer
+    ;mov     DosTable2_pTKSSBase, eax
+    ;mov     _TKSSBase16, eax
+
+    ;xor     eax, eax
+    ;mov     ax, seg FLAT:CODE32
+    ;mov     DosTable2_R0FlatCS, ax
+    ;mov     _R0FlatCS16, ax
+
+    ;mov     ax, seg FLAT:DATA32
+    ;mov     DosTable2_R0FlatDS, ax
+    ;mov     _R0FlatDS16, ax
+endif
+
+    ;
+    ; return NO_ERROR
+    ;
+    xor     eax, eax
+    ret
+dhinit ENDP
+
+
+;;
+; Gets the a 16-bit far pointer to the DHRouter routine.
+; @cproto    ULONG  _Optlink getDHRouterFarPtr(VOID); /* dh.asm */
+; @returns   16-bit far pointer to the DHRouter routine.
+; @uses      EAX
+; @status    completely implemented.
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark
+getDHRouterFarPtr PROC NEAR
+    ASSUME cs:CODE32, ds:FLAT, es:NOTHING, ss:NOTHING
+    mov     ax, seg CODE16:DHRouter
+    shl     eax, 16
+    mov     ax, offset CODE16:DHRouter
+    ret
+getDHRouterFarPtr ENDP
+
+
+
+
+
+;;
+; Thunks the stack from 16-bits to 32-bits.
+; !The stack has to be 16-bits on entry!
+; @cproto    VOID _Optlink ThunkStack16To32(VOID)
+; @returns   void
+;            Stack is 32-bits!
+;            EBP and SS:ESP is thunked
+;
+; @uses      EAX, EDX
+; @sketch
+; @status    completly implemented.
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark    RING 3 only.
+ThunkStack16To32 PROC NEAR
+    ASSUME cs:CODE32, ds:FLAT, es:NOTHING, ss:NOTHING
+    movzx   esp, sp                     ; Make sure high end of esp is zero.
+    mov     ax, ss                      ; Find the linary base of the segment addressed by ss.
+    shl     eax, SEL_FLAT_SHIFT
+    and     eax, SEL_FLATMASK
+    mov     ax, sp                      ; Add the segment offset, which is sp.
+                                        ; eax is now the linear stack address equal to ss:sp.
+
+    mov     dx, seg FLAT:DATA32         ; ALP bug? Can't: push seg FLAT:DATA32
+                                        ; Have to move it to dx before pushing it.
+    push    dx                          ; Make lss quad word: new ss, new esp
+    push    eax
+    lss     esp, ss:[esp]               ; load new ss and esp values.
+
+    ;
+    ; Fix ebp
+    ; Creates new ebp from high word of esp and low word of ebp.
+    ;
+    mov     eax, esp
+    mov     ax, bp
+    mov     ebp, eax
+
+    ;
+    ; Update TKSSBase
+    ;
+    push    ds
+    mov     ds, dx
+    ASSUME  ds:FLAT
+    mov     TKSSBase, 0
+    pop     ds
+    ret
+ThunkStack16To32 ENDP
+
+
+;;
+; Thunks the stack from 32-bits to 16-bits.
+; !The stack has to be 32-bits on entry!
+; @cproto    VOID _Optlink ThunkStack32To16(VOID)
+; @returns   void
+;            Stack is 16-bits!
+;            EBP and SS:ESP is thunked
+;
+; @uses      EAX, EDX
+; @sketch
+; @status    completly implemented.
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark    RING 3 only.
+ThunkStack32To16 PROC NEAR
+    ASSUME cs:CODE32, ds:FLAT, es:NOTHING, ss:NOTHING
+
+    mov     edx, esp                    ; save esp for later use (setting TKSSBase).
+
+    ;
+    ; calc LDT selector from linear esp and load new ss:esp.
+    ;
+    mov     eax, esp
+    shr     eax, SEL_FLAT_SHIFT
+    or      ax,  SEL_LDT_RPL3           ; ax new ss LDT (RING3).
+    rol     eax, 16
+    mov     ax, sp
+    push    eax
+    lss     sp, dword ptr [esp]         ; load ss:sp.
+    movzx   esp, sp                     ; Zero upper part of esp.
+                                        ; Stack is now 16 bits
+    ;
+    ; Fix ebp
+    ;
+    movzx   ebp, bp                     ; Zero upper part of ebp.
+
+    ;
+    ; Update TKSSBase
+    ;
+    push    ds
+    mov     ax, seg FLAT:DATA32
+    mov     ds, ax
+    ASSUME  ds:FLAT
+    xor     dx, dx                      ; zero lower word of dx to get linear
+                                        ; address of 16-bits stack base
+    mov     TKSSBase, edx
+    pop     ds
+
+    ret
+ThunkStack32To16 ENDP
+
+
+CODE32 ENDS
+
+end
+
Index: trunk/src/win32k/kKrnlLib/src/tstDos.c
===================================================================
--- trunk/src/win32k/kKrnlLib/src/tstDos.c	(revision 8211)
+++ trunk/src/win32k/kKrnlLib/src/tstDos.c	(revision 8211)
@@ -0,0 +1,149 @@
+/* $Id: tstDos.c,v 1.1 2002-04-07 22:39:14 bird Exp $
+ *
+ * Thunkers for OS/2 APIs.
+ *
+ * Some APIs requires Linear Stack, some have to overridden to
+ * emulate different things.
+ *
+ * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+/*******************************************************************************
+*   Defined Constants And Macros                                               *
+*******************************************************************************/
+#define INCL_BASE
+#define INCL_NO_FAKE
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <os2.h>
+
+#include "devSegDf.h"                   /* kKrnlLib segment definitions. */
+
+#include "testcase.h"
+
+
+/*******************************************************************************
+*   External Functions                                                         *
+* (These are prototypes for functions in the IMPORTS section of the def-file.) *
+*******************************************************************************/
+APIRET  APIENTRY        _DosWrite(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual);
+APIRET  APIENTRY        _DosClose(HFILE hFile);
+APIRET  APIENTRY        _DosOpen(
+                            PSZ     pszFileName,
+                            PHFILE  pHf,
+                            PULONG  pulAction,
+                            ULONG   cbFile,
+                            ULONG   ulAttribute,
+                            ULONG   fsOpenFlags,
+                            ULONG   fsOpenMode,
+                            PEAOP2  peaop2);
+APIRET  APIENTRY        _DosSetFilePtr(
+                            HFILE   hFile,
+                            LONG    ib,
+                            ULONG   method,
+                            PULONG  ibActual);
+
+/**
+ * DosWrite overload. Ensures that the stack is 32-bit!
+ */
+APIRET  APIENTRY        DosWrite(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual)
+{
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+    APIRET  rc;
+    if (!f32Stack)
+        ThunkStack16To32();
+
+    rc = _DosWrite(hFile, pBuffer, cbWrite, pcbActual);
+
+    if (!f32Stack)
+        ThunkStack32To16();
+
+    return rc;
+}
+
+
+/**
+ * DosClose overload. Ensures that the stack is 32-bit!
+ */
+APIRET  APIENTRY        DosClose(HFILE hFile)
+{
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+    APIRET  rc;
+    if (!f32Stack)
+        ThunkStack16To32();
+
+    rc = _DosClose(hFile);
+
+    if (!f32Stack)
+        ThunkStack32To16();
+
+    return rc;
+}
+
+
+/**
+ * DosOpen overload. Ensures that the stack is 32-bit!
+ */
+APIRET  APIENTRY        DosOpen(
+                            PSZ    pszFileName,
+                            PHFILE pHf,
+                            PULONG pulAction,
+                            ULONG  cbFile,
+                            ULONG  ulAttribute,
+                            ULONG  fsOpenFlags,
+                            ULONG  fsOpenMode,
+                            PEAOP2 peaop2)
+{
+    BOOL    f32Stack = ((int)&cbFile > 0x10000);
+    APIRET  rc;
+    if (!f32Stack)
+        ThunkStack16To32();
+
+    rc = _DosOpen(pszFileName,
+                   pHf,
+                   pulAction,
+                   cbFile,
+                   ulAttribute,
+                   fsOpenFlags,
+                   fsOpenMode,
+                   peaop2);
+
+    if (!f32Stack)
+        ThunkStack32To16();
+
+    return rc;
+}
+
+
+/**
+ * DosSetFilePtr overload. Ensures that the stack is 32-bit!
+ */
+APIRET  APIENTRY        DosSetFilePtr(
+                            HFILE   hFile,
+                            LONG    ib,
+                            ULONG   method,
+                            PULONG  ibActual)
+{
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+    APIRET  rc;
+    if (!f32Stack)
+        ThunkStack16To32();
+
+    rc = _DosSetFilePtr(hFile,
+                        ib,
+                        method,
+                        ibActual);
+
+    if (!f32Stack)
+        ThunkStack32To16();
+
+    return rc;
+}
+
+
+
Index: trunk/src/win32k/kKrnlLib/src/tstDosA.asm
===================================================================
--- trunk/src/win32k/kKrnlLib/src/tstDosA.asm	(revision 8211)
+++ trunk/src/win32k/kKrnlLib/src/tstDosA.asm	(revision 8211)
@@ -0,0 +1,294 @@
+; $Id: tstDosA.asm,v 1.1 2002-04-07 22:39:14 bird Exp $
+;
+; 16-bits Dos calls overloader
+;
+; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+;
+; Project Odin Software License can be found in LICENSE.TXT
+;
+    .386
+
+
+;
+; Include files
+;
+    include devsegdf.inc
+    INCL_DOSERRORS EQU 1
+    include os2.inc
+    include devsym.inc
+
+
+;
+; Exported symbols
+;
+    public  DOS16OPEN
+    public  DOS16CLOSE
+    public  DOS16DEVIOCTL
+
+
+;
+; extrns
+;
+    extrn   _strategyAsm0:FAR
+    extrn   _DOS16OPEN:FAR     ;70
+    extrn   _DOS16CLOSE:FAR    ;59
+
+    extrn   ThunkStack16To32:PROC
+    extrn   ThunkStack32To16:PROC
+    extrn   TKSSBase:PROC
+
+    extrn   _TKSSBase16:DWORD
+    extrn   _R0FlatCS16:WORD
+    extrn   _R0FlatDS16:WORD
+
+DATA16 SEGMENT
+szDevName   db  "\dev\$KrnlHlp",0
+szDevNameEnd db 0
+DATA16 ENDS
+
+
+
+CODE16 SEGMENT
+    ASSUME cs:CODE16, ds:DATA16
+
+hkKrnlHlp  EQU     0fE1Fh               ; Value of the kKrnlHlp handle
+
+;;
+; Fake opening of kKrnlHlp
+;
+; PASCAL convention: Parameters pushed left to right of C prototype.
+;                    We'll have to do the cleanup.
+;
+; @cproto APIRET  APIENTRY  DosOpen(
+;                               PSZ     pszFname,
+;                               PHFILE  phfOpen,
+;                               PUSHORT pusAction,
+;                               ULONG   ulFSize,
+;                               USHORT  usAttr,
+;                               USHORT  fsOpenFlags,
+;                               USHORT  fsOpenMode,
+;                               ULONG   ulReserved);
+;
+; @returns
+; @param     pszFname       bp +1c  dd
+; @param     phfOpen        bp +18  dd
+; @param     pusAction      bp +14  dd
+; @param     ulFSize        bp +10  dd
+; @param     usAttr         bp + e  dw
+; @param     fsOpenFlags    bp + c  dw
+; @param     fsOpenMode     bp + a  dw
+; @param     ulReserved     bp + 6  dd
+;
+; @uses
+; @equiv
+; @time
+; @sketch
+; @status
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark
+DOS16OPEN PROC FAR
+    ASSUME CS:CODE16, DS:NOTHING, ES:NOTHING, SS:NOTHING
+    push    bp
+    mov     bp, sp
+
+    ;
+    ; Is this an attempt to open the kKrnlHlp device driver?
+    ;
+    push    ds
+    push    es
+    push    si
+    push    di
+    push    cx
+
+    lds     si, [bp + 1ch]
+    mov     di, seg szDevName
+    mov     es, di
+    mov     di, offset szDevName
+    mov     cx, offset szDevNameEnd - offset szDevName
+    repe cmpsb
+    jne     do_notkKrnlHlp
+
+    ;
+    ; found filename string equal to "\dev\kKrnlHlp".
+    ;
+    ; return phFile equal to kKrnlHlp handle and pusAction set to 1 (FILE EXISTED).
+    ;
+    lds     di, [bp + 18h]
+    mov     word ptr ds:[di], hkKrnlHlp ; *phFile <- hkKrnlHlp
+    lds     di, [bp + 14h]
+    mov     word ptr ds:[di], 1         ; *pusAction <- File existed.
+
+    ; return successfully.
+    xor     eax, eax
+
+do_ret:
+    ;
+    ; restore registers and return.
+    ;
+    pop     cx
+    pop     di
+    pop     si
+    pop     es
+    pop     ds
+    leave
+    ret     01ah
+
+do_notkKrnlHlp:
+    push    dword ptr [bp +01ch]
+    push    dword ptr [bp +018h]
+    push    dword ptr [bp +014h]
+    push    dword ptr [bp +010h]
+    push    word  ptr [bp + 0eh]
+    push    word  ptr [bp + 0ch]
+    push    word  ptr [bp + 0ah]
+    push    dword ptr [bp + 06h]
+    call far ptr _DOS16OPEN
+    jmp do_ret
+DOS16OPEN ENDP
+
+
+;;
+; Fake close of kKrnlHlp
+; @cproto    APIRET  APIENTRY DosClose(HFILE hf);
+; @returns   OS/2 return code. (NO_ERROR)
+; @param     hFile  bp + 6
+; @uses      EAX
+; @status    completly implemented.
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+DOS16CLOSE PROC FAR
+    ASSUME CS:CODE16, DS:NOTHING, ES:NOTHING, SS:NOTHING
+    push    bp
+    mov     bp, sp
+
+    ;
+    ; Is it the kKrnlHlp handle?
+    ;
+    mov     ax, [bp + 6]
+    cmp     ax, hkKrnlHlp
+    jne     dc_notkKrnlHlp
+    xor     eax, eax
+    leave
+    ret     2
+
+dc_notkKrnlHlp:
+    push    word ptr [bp + 6]           ; can't jump to higher privilege
+    call    _DOS16CLOSE
+    leave
+    ret     2
+DOS16CLOSE ENDP
+
+
+
+;;
+;
+; @cproto    APIRET  APIENTRY   DosDevIOCtl(
+;                                   PVOID   pData,
+;                                   PVOID   pParms,
+;                                   USHORT  usFun,
+;                                   USHORT  usCategory,
+;                                   HFILE   hDev);
+; @returns
+; @param     pData       bp +10 dd
+; @param     pParms      bp + c dd
+; @param     usFun       bp + a dw
+; @param     usCategory  bp + 8 dw
+; @param     hDev        bp + 6 dw
+; @param
+; @uses      eax
+; @sketch
+; @status    completly implemented
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark
+DOS16DEVIOCTL PROC FAR
+    ASSUME CS:CODE16, DS:NOTHING, ES:NOTHING, SS:NOTHING
+    LOCAL   pkt:Packet
+
+    push    bx
+    push    es
+
+
+    ;
+    ; Check that it really is the kKrnlHlp handle.
+    ;
+    mov     ax, word ptr [bp + 6]
+    cmp     word ptr [bp + 6], hkKrnlHlp
+    jne     ddioc_invalidhandle
+
+    ;
+    ; Then we'll have to call _strategyAsm0. But first will have to
+    ; build a request packet for this IOCtl
+    ;
+    mov     pkt.PktLen, LENGenIOCTL     ; PktLen          db      ?               ; length in bytes of packet
+    mov     pkt.PktUnit, 0              ; PktUnit         db      ?               ; subunit number of block device
+    mov     pkt.PktCmd, CMDGenIOCTL     ; PktCmd          db      ?               ; command code
+    mov     pkt.PktStatus, 0            ; PktStatus       dw      ?               ; status word
+    mov     pkt.PktFlag, 0              ; PktFlag         db      ?               ; disk driver internal flags
+    mov     pkt.PktFlag+1, 0            ;                 db      3 dup(?)        ; reserved
+    mov     pkt.PktFlag+2, 0            ;
+    mov     pkt.PktFlag+3, 0            ;
+    mov     pkt.PktDevLink, 0           ; PktDevLink      dd      ?               ; device multiple-request link
+    mov     ax, [bp + 8]
+    mov     byte  ptr pkt.PktData + 0, al   ; Category Code
+    mov     ax, [bp + 0ah]
+    mov     byte ptr pkt.PktData + 1, al    ; Function code
+    mov     eax, [bp + 0ch]
+    mov     dword ptr pkt.PktData + 2, eax  ; pointer to parameter packet
+    mov     eax, [bp + 10h]
+    mov     dword ptr pkt.PktData + 6, eax  ; pointer to data packet
+    mov     word ptr  pkt.PktData + 10, 0   ; SFN of the driver.
+
+    ; do the call - who cleans up the stack?
+    mov     bx, ss
+    mov     es, bx
+    lea     bx, pkt
+    ;call    far ptr _strategyAsm0      ; why did this make it into a 16:32 call?
+    call    far ptr CODE16:_strategyAsm0
+
+    ;
+    ; We'll check if the status to see wether it failed or not.
+    ;
+    test    pkt.PktStatus, STERR
+    jnz     ddioc_error
+    test    pkt.PktStatus, STDON
+    jz      ddioc_notdone
+    test    pkt.PktStatus, STINTER
+    jnz     ddioc_interchar
+    test    pkt.PktStatus, STBUI
+    jnz     ddioc_busy
+    xor     eax, eax                    ; return NO_ERROR
+    jmp ddioc_ret
+
+ddioc_error:
+    mov     ax, pkt.PktStatus
+    and     ax, STECODE
+    jmp ddioc_ret
+
+ddioc_notdone:
+    mov     eax, 31                     ; ERROR_GEN_FAILURE
+    jmp ddioc_ret
+
+ddioc_interchar:
+    mov     eax, 31                     ; ERROR_GEN_FAILURE
+    jmp ddioc_ret
+
+ddioc_busy:
+    mov     eax, 31                     ; ERROR_GEN_FAILURE
+    jmp ddioc_ret
+
+ddioc_invalidhandle:
+    mov     eax, 6                      ; ERROR_INVALID_HANDLE
+    jmp     ddioc_ret
+
+ddioc_ret:
+    pop     es
+    pop     bx
+    leave
+    ret     0eh
+DOS16DEVIOCTL ENDP
+
+
+
+CODE16 ENDS
+
+END
+
Index: trunk/src/win32k/kKrnlLib/src/tstFake.c
===================================================================
--- trunk/src/win32k/kKrnlLib/src/tstFake.c	(revision 8211)
+++ trunk/src/win32k/kKrnlLib/src/tstFake.c	(revision 8211)
@@ -0,0 +1,2664 @@
+/* $Id: tstFake.c,v 1.1 2002-04-07 22:39:14 bird Exp $
+ *
+ * Fake stubs for the ldr and kernel functions we imports or overloads.
+ *
+ * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#ifndef NOFILEID
+static const char szFileId[] = "$Id: tstFake.c,v 1.1 2002-04-07 22:39:14 bird Exp $";
+#endif
+
+/*******************************************************************************
+*   Defined Constants And Macros                                               *
+*******************************************************************************/
+#define INCL_BASE
+#define INCL_KKL_LOG
+#define INCL_KKL_PRINTF
+#define INCL_OS2KRNL_ALL
+#define FOR_EXEHDR 1                    /* To make all object flags OBJ???. */
+#define DWORD  ULONG
+#define WORD   USHORT
+
+#define DUMMY()     volatile int dummy1, dummy2; \
+                    dummy1 = 23; \
+                    dummy2 = 42; \
+                    dummy1 = dummy1 + 1 + dummy2;
+
+#define Assert(expr) \
+        if (!(expr))                                                                \
+        {                                                                           \
+            printf("%s(%d) - %s: %s\n", __FILE__, __FUNCTION__, __LINE__, #expr);   \
+            INT3();                                                                 \
+        }
+
+/*******************************************************************************
+*   Header Files                                                               *
+*******************************************************************************/
+#include <os2.h>
+#include <newexe.h>                     /* OS/2 NE structs and definitions. */
+#include <exe386.h>                     /* OS/2 LX structs and definitions. */
+
+#include <string.h>
+
+#include "devSegDf.h"                   /* kKrnlLib segment definitions. */
+
+#include <kKrnlLib.h>
+#include <OS2Krnl.h>
+#include "dev32.h"
+#include "testcase.h"
+#include "kLib/kTypes.h"
+
+#include "kKLmalloc.h"
+
+/*******************************************************************************
+*   Structures and Typedefs                                                    *
+*******************************************************************************/
+typedef struct ldrrei_s /* #memb 7 size 20 (0x014) - from 14040W4 kernel.sdf */
+{
+    PVOID                   ei_startaddr;      /* off:   0(00)  size:  4(04) */
+    PVOID                   ei_stackaddr;      /* off:   4(04)  size:  4(04) */
+    PVOID                   ei_pstackmax;      /* off:   8(08)  size:  4(04) */
+    USHORT                  ei_ds;             /* off:  12(0c)  size:  2(02) */
+    USHORT                  ei_stacksize;      /* off:  14(0e)  size:  2(02) */
+    USHORT                  ei_heapsize;       /* off:  16(10)  size:  2(02) */
+    USHORT                  ei_loadtype;       /* off:  18(12)  size:  2(02) */
+} ldrrei_t;
+
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+/*
+ * Pointer to the loader semaphore.
+ */
+KSEMMTX         fakeLdrSem;
+
+CHAR            szBeginLibPath[1024];
+CHAR            szEndLibPath[1024];
+CHAR            szLibPath[1024];
+PSZ             fakeLDRLibPath = &szLibPath[0];
+
+CHAR            szldrpFileNameBuf[CCHMAXPATH];
+PSZ             fakeldrpFileNameBuf = &szldrpFileNameBuf[0];
+
+static CHAR     achHeaderBuffer[256];   /* Buffer to read exe header into. */
+PVOID           pheaderbuf = &achHeaderBuffer[0];
+
+/*
+ * Mte list pointers.
+ */
+PMTE            fakemte_h;
+PMTE            fakeglobal_h;
+PMTE            fakeglobal_l;
+PMTE            fakespecific_h;
+PMTE            fakespecific_l;
+PMTE            fakeprogram_h;
+PMTE            fakeprogram_l;
+
+
+/*
+ * table use by fakeldrMTEValidatePtrs.
+ */
+USHORT          validatetbl[] =
+{
+    FIELDOFFSET(SMTE, smte_objmap),
+    FIELDOFFSET(SMTE, smte_rsrctab),
+    FIELDOFFSET(SMTE, smte_restab),
+    FIELDOFFSET(SMTE, smte_enttab),
+    FIELDOFFSET(SMTE, smte_fpagetab),
+    FIELDOFFSET(SMTE, smte_frectab),
+    FIELDOFFSET(SMTE, smte_impmod),
+    FIELDOFFSET(SMTE, smte_impproc),
+    0xDEAD
+};
+
+
+/*
+ * More fake variables.
+ */
+ULONG fakeSMcDFInuse;
+ULONG fakesmFileSize;
+ULONG fakeSMswapping;
+ULONG fakesmcBrokenDF;
+ULONG fakepgPhysPages;
+ULONG fakeSMcInMemFile;
+ULONG fakeSMCFGMinFree;
+ULONG fakesmcGrowFails;
+ULONG fakePGSwapEnabled;
+ULONG fakepgcPageFaults;
+ULONG fakeSMCFGSwapSize;
+ULONG fakepgResidentPages;
+ULONG fakepgSwappablePages;
+ULONG fakepgDiscardableInmem;
+ULONG fakepgDiscardablePages;
+ULONG fakeSMMinFree;
+ULONG fakepgcPageFaultsActive;
+ULONG fakepgPhysMax;
+ULONG fakeVirtualAddressLimit;
+
+VMAH  fakeahvmShr;
+VMAH  fakeahvmSys;
+VMAH  fakeahvmhShr;
+
+
+
+/*******************************************************************************
+*   External Functions                                                         *
+*******************************************************************************/
+#define QHINF_EXEINFO       1 /* NE exeinfo. */
+#define QHINF_READRSRCTBL   2 /* Reads from the resource table. */
+#define QHINF_READFILE      3 /* Reads from the executable file. */
+#define QHINF_LIBPATHLENGTH 4 /* Gets the libpath length. */
+#define QHINF_LIBPATH       5 /* Gets the entire libpath. */
+#define QHINF_FIXENTRY      6 /* NE only */
+#define QHINF_STE           7 /* NE only */
+#define QHINF_MAPSEL        8 /* NE only */
+
+APIRET APIENTRY DosQueryHeaderInfo(HMODULE hmod,
+                                   ULONG   ulIndex,
+                                   PVOID   pvBuffer,
+                                   ULONG   cbBuffer,
+                                   ULONG   ulSubFunction);
+
+/*******************************************************************************
+*   Internal Functions                                                         *
+*******************************************************************************/
+#pragma info(nopar)
+ULONG LDRCALL   fakeLDRLoadExe(PSZ pszFilename, ldrrei_t *pEI);
+ULONG LDRCALL   fakeldrGetModule(PSZ pszFilename, ULONG ul);
+ULONG LDRCALL   fakeldrGetMte(PCHAR pachFilename, USHORT cchFilename, UCHAR fchType, UCHAR fchClass, PPMTE ppmte);
+ULONG LDRCALL   fakeldrOpenNewExe(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PUSHORT pus);
+ULONG LDRCALL   fakeldrCreateMte(struct e32_exe * pe32, ldrlv_t *plv);
+ULONG LDRCALL   fakeldrLoadImports(PMTE pmte);
+ULONG LDRCALL   fakeldrMTEValidatePtrs(PSMTE psmte, ULONG ulMaxAddr, ULONG off);
+unsigned short  getSlot(void);
+
+
+
+/**
+ * Initiate workers (imported kernel functions / vars)
+ * @status    partially implemented.
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+void  workersinit(void)
+{
+    KLOGENTRY0("void");
+    APIRET rc;
+
+    /*
+     * Make code writable.
+     */
+    DosSetMem(&CODE16START, &CODE16END - &CODE16START, PAG_WRITE | PAG_READ);
+    DosSetMem(&CODE32START, &CODE32END - &CODE32START, PAG_WRITE | PAG_READ);
+
+    /*
+     * Loader semaphore
+     */
+    fakeKSEMInit((PKSEM)(void*)&fakeLdrSem, KSEM_MUTEX, KSEM_DEFAULT);
+
+    /*
+     * Intra process semaphore.
+     */
+    fakeKSEMInit((PKSEM)(void*)&fakeptda_ptdasem, KSEM_MUTEX, KSEM_DEFAULT);
+
+    /*
+     * LIBPaths
+     */
+    rc = DosQueryExtLIBPATH(szBeginLibPath, BEGIN_LIBPATH);
+    rc = DosQueryHeaderInfo(NULLHANDLE, 0, szLibPath, sizeof(szLibPath), QHINF_LIBPATH);
+    rc = DosQueryExtLIBPATH(szEndLibPath, END_LIBPATH);
+
+    if (_usFakeVerMinor < 45)
+        fakeVirtualAddressLimit = 0xFFFFFFFF;
+    else
+        fakeVirtualAddressLimit = 0x80000000;
+
+
+    if (fakeVirtualAddressLimit != 0xFFFFFFFF)
+    {   /* high memory supported */
+        fakeahvmSys.ah_laddrMax = 0xFFFE0000;
+        fakeahvmSys.ah_laddrMin = 0x80000000;
+        fakeahvmShr.ah_laddrMin = 0x08000000;
+        fakeahvmhShr.ah_laddrMin = 0x70000000;
+    }
+    else
+    {   /* high memory not supported */
+        fakeahvmSys.ah_laddrMax = 0xFFFE0000;
+        fakeahvmSys.ah_laddrMin = 0x40000000;
+        fakeahvmShr.ah_laddrMin = 0x08000000;
+        fakeahvmhShr.ah_laddrMin = 0xffffffff;
+    }
+
+    rc = rc;
+    KLOGEXITVOID();
+}
+
+
+/**
+ * Fake ldrClose
+ * @returns OS2 return code.
+ * @param   hFile    Filehandle of the file to be closed.
+ * @status  completely impelemented.
+ * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG LDRCALL fakeldrClose(SFN hFile)
+{
+    KLOGENTRY1("ULONG LDRCALL","SFN hFile", hFile);
+    APIRET  rc;
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    rc =  DosClose(hFile);
+
+    if (!f32Stack) ThunkStack32To16();
+
+    printf("fakeldrClose:                   hFile = 0x%04x, rc = %d\n", hFile, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+/**
+ * Fake ldrOpen.
+ * @returns   OS2 return code.
+ * @param     phFile        Pointer to return handle.
+ * @param     pszFilename   Pointer to filename.
+ * @param     pfl           Pointer to media flags? *pfl is set to zero!
+ * @sketch    Do a DosOpen on the filename.
+ * @status    partially implemented.
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG LDRCALL fakeldrOpen(PSFN phFile, PSZ pszFilename, PULONG pfl)
+{
+    KLOGENTRY3("ULONG LDRCALL","PSFN phFile, PSZ pszFilename, PULONG pfl", phFile, pszFilename, pfl);
+    ULONG   ulAction;
+    HFILE   hFile;
+    APIRET  rc;
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    hFile = 0;
+    ulAction = 0;
+    rc =  DosOpen(pszFilename, &hFile, &ulAction, 0, FILE_NORMAL,
+                  OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
+                  OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE,
+                  NULL);
+    if (rc == NO_ERROR)
+    {
+        *phFile = (USHORT)hFile;
+        if (pfl != NULL)
+            *pfl = 0;
+        rc = DosQueryPathInfo(pszFilename, FIL_QUERYFULLNAME, fakeldrpFileNameBuf, CCHMAXPATH);
+        rc = NO_ERROR;
+    }
+
+    if (!f32Stack) ThunkStack32To16();
+
+    printf("fakeldrOpen:                    phFile = %p; *phFile = 0x%04x, pszFilename = %s, pfl = %p, rc = %d\n",
+           phFile, *phFile, pszFilename, pfl, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * ldrRead fake.
+ * @returns   OS/2 return code. (NO_ERROR on success...)
+ * @param     hFile     Handle to file.
+ * @param     ulOffset  Offset in the file to start reading at.
+ * @param     pvBuffer  Pointer to output buffer.
+ * @param     fpBuffer  Far pointer to buffer. (ignored)
+ * @param     cbToRead  Count of bytes to read.
+ * @param     pMTE      MTE pointer (used for caching?)
+ *
+ * @sketch    Set Change filepointer to ulOffset.
+ *            Read cbToRead into pvBufer.
+ * @status    completely tested.
+ * @author    knut st. osmundsen
+ * @remark
+ */
+ULONG LDRCALL fakeldrRead(SFN hFile, ULONG ulOffset, PVOID pvBuffer, ULONG fpBuffer, ULONG cbToRead, PMTE pMTE)
+{
+    KLOGENTRY6("ULONG LDRCALL","SFN hFile, ULONG ulOffset, PVOID pvBuffer, ULONG fpBuffer, ULONG cbToRead, PMTE pMTE", hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE);
+    ULONG   cbRead,
+            ulMoved;
+    APIRET  rc;
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    rc = DosSetFilePtr(hFile, ulOffset, FILE_BEGIN, &ulMoved);
+    if (rc == NO_ERROR)
+        rc = DosRead(hFile, pvBuffer, cbToRead, &cbRead);
+    else
+        kprintf(("DosSetFilePtr(hfile, 0x%08x(%d),..) failed with rc = %d.\n",
+                 ulOffset, ulOffset, rc));
+
+    if (!f32Stack) ThunkStack32To16();
+
+    printf("fakeldrRead:                    hFile = 0x%04x, ulOffset = 0x%08x, pvBuffer = %p, fpBuffer = 0x%08x, cbToRead = 0x%08x, pMte = %p, rc = %d\n",
+           hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * LDRQAppType faker.
+ * @returns   OS/2 return code.
+ * @param     pszFilename   Pointer to executable to query app type for.
+ * @param     pul           Pointer to flag variable to return apptype flags in.
+ * @sketch
+ * @status    stub.
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG LDRCALL fakeLDRQAppType(PSZ pszFilename, PULONG pul)
+{
+    KLOGENTRY2("ULONG LDRCALL","PSZ pszFilename, PULONG pul", pszFilename, pul);
+    DUMMY();
+    printf("fakeLDRQAppType:                pszFilename = %s, pul = %p, rc = 0\n", pszFilename, pul);
+    KLOGEXIT(NO_ERROR);
+    return NO_ERROR;
+}
+
+
+/**
+ * ldrEnum32bitRelRecs
+ * @param   pMTE           Pointer to MTE for this module.
+ * @param   iObject        Object index. 0-based!
+ * @param   iPageTabl      Page index. 0-based!
+ * @param   pvPage         Pointer to page buffer.
+ * @param   ulPageAddress  Note! Page is not present.
+ * @param   pPTDA
+ * @status  stub
+ */
+ULONG LDRCALL fakeldrEnum32bitRelRecs(
+    PMTE    pMTE,
+    ULONG   iObject,
+    ULONG   iPageTable,
+    PVOID   pvPage,
+    ULONG   ulPageAddress,
+    PVOID   pvPTDA
+    )
+{
+    KLOGENTRY6("ULONG LDRCALL","PMTE pMTE, ULONG iObject, ULONG iPageTable, PVOID pvPage, ULONG ulPageAddress, PVOID pvPTDA", pMTE, iObject, iPageTable, pvPage, ulPageAddress, pvPTDA);
+    DUMMY();
+    printf("fakeldrEnum32bitRelRecs:        pMTE = %p, iObject = 0x%08x, iPageTable = 0x%08x, pvPage = 0x%08x, ulPageAddress = 0x%08x, pvPTDA = %p\n",
+           pMTE, iObject, iPageTable, pvPage, ulPageAddress, pvPTDA);
+
+    KLOGEXIT(NO_ERROR);
+    return NO_ERROR;
+}
+
+
+/**
+ * Sets the VM flags for an executable object.
+ * @returns     void
+ * @param       pMTE        Pointer to the module table entry.
+ * @param       flObj       LX Object flags.
+ * @param       pflFlags1   Pointer to the flFlags1 of VMAllocMem (out).
+ * @param       pflFlags2   Pointer to the flFlags2 of VMAllocMem (out).
+ */
+ULONG LDRCALL fakeldrSetVMflags(
+    PMTE        pMTE,
+    ULONG       flObj,
+    PULONG      pflFlags1,
+    PULONG      pflFlags2
+    )
+{
+    KLOGENTRY4("ULONG LDRCALL","PMTE pMTE, ULONG flObj, PULONG pflFlags1, PULONG pflFlags2", pMTE, flObj, pflFlags1, pflFlags2);
+    *pflFlags1 = 0;
+    *pflFlags2 = 0;
+    flObj = flObj;
+    pMTE = pMTE;
+    KLOGEXIT(0);
+    return 0;
+}
+
+/**
+ * Opens a given file.
+ * @returns  NO_ERROR on success. OS/2 error code on error.
+ * @param    pszFilename   Pointer to filename.
+ * @param    flOpenFlags   Open flags. (similar to DosOpen)
+ * @param    fsOpenMode    Open mode flags. (similar to DosOpen)
+ * @param    phFile        Pointer to filehandle.
+ * @param    pulsomething  16-bit near (?) pointer to a variable - unknown. NULL is allowed. EA?
+ */
+APIRET KRNLCALL fakeIOSftOpen(
+    PSZ pszFilename,
+    ULONG flOpenFlags,
+    ULONG fsOpenMode,
+    PSFN phFile,
+    PULONG pulsomething
+    )
+{
+    KLOGENTRY5("APIRET KRNLCALL","PSZ pszFilename, ULONG flOpenFlags, ULONG fsOpenMode, PSFN phFile, PULONG pulsomething", pszFilename, flOpenFlags, fsOpenMode, phFile, pulsomething);
+    ULONG   ulAction;
+    HFILE   hFile;
+    APIRET  rc;
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    hFile = 0;
+    ulAction = 0;
+    rc =  DosOpen(pszFilename, &hFile, &ulAction, 0, FILE_NORMAL,
+                  flOpenFlags,
+                  fsOpenMode,
+                  NULL);
+    if (rc == NO_ERROR)
+        *phFile = (USHORT)hFile;
+
+    if (!f32Stack) ThunkStack32To16();
+
+    printf("fakeIOSftOpen:                  pszFilename = %s, flOpenFlags = 0x%08x, fsOpenMode = 0x%08x, phFile = %p; *phFile = 0x%04, pulsomething = %p, rc = %d\n",
+           pszFilename, flOpenFlags, fsOpenMode, phFile, *phFile, pulsomething, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * Closes the specified file.
+ * @returns  NO_ERROR on success. OS/2 error code on error.
+ * @param    hFile      File handle - System File Number.
+ */
+APIRET KRNLCALL fakeIOSftClose(
+    SFN hFile
+    )
+{
+    KLOGENTRY1("APIRET KRNLCALL","SFN hFile", hFile);
+    APIRET  rc;
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    rc =  DosClose(hFile);
+
+    if (!f32Stack) ThunkStack32To16();
+
+    printf("fakeIOSftClose:                 hFile = 0x%04, rc = %d\n",
+           hFile, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * Probably this function will expand a relative path to a full path.
+ * @returns  NO_ERROR on success. OS/2 error code on error.
+ *           The ldr filename buffer will hold the expanded
+ *           pathname upon successfull return.
+ * @param    pszPath  Pointer to path to expand.  (?)
+ * @status   completely implemented.
+ */
+APIRET KRNLCALL fakeIOSftTransPath(
+    PSZ pszPath
+    )
+{
+    KLOGENTRY1("APIRET KRNLCALL","PSZ pszPath", pszPath);
+    char    szBuffer[CCHMAXPATH];
+    APIRET  rc;
+    BOOL    f32Stack = ((int)&pszPath > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    rc = DosQueryPathInfo(pszPath, FIL_QUERYFULLNAME, &szBuffer, sizeof(szBuffer));
+    printf("fakeIOSftTransPath:              pszPath(in) = %s, pszPath(out) = %s, rc = %d\n",
+           pszPath, szBuffer, rc);
+    if (rc == NO_ERROR)
+        strcpy(pszPath, szBuffer);
+    else
+        kprintf(("fakeIOSftTransPath: DosQueryPathInfo failed with rc=%d\n", rc));
+
+
+    if (!f32Stack) ThunkStack32To16();
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * Read at a given offset in the a file.
+ * @returns  NO_ERROR on success. OS/2 error code on error.
+ * @param    hFile      File handle - System File Number.
+ * @param    pcbActual  Pointer to variable which upon input holds the number
+ *                      of bytes to read, on output the actual number of bytes read.
+ * @param    pvBuffer   Pointer to the read buffer.
+ * @param    fpBuffer   16 far pointer to buffer. (ignored)
+ * @param    ulOffset   File offset to read from. (0=start of file)
+ */
+APIRET KRNLCALL fakeIOSftReadAt(
+    SFN hFile,
+    PULONG pcbActual,
+    PVOID pvBuffer,
+    ULONG fpBuffer,
+    ULONG ulOffset
+    )
+{
+    KLOGENTRY5("APIRET KRNLCALL","SFN hFile, PULONG pcbActual, PVOID pvBuffer, ULONG fpBuffer, ULONG ulOffset", hFile, pcbActual, pvBuffer, fpBuffer, ulOffset);
+    ULONG   ulMoved;
+    APIRET  rc;
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    rc = DosSetFilePtr(hFile, ulOffset, FILE_BEGIN, &ulMoved);
+    if (rc == NO_ERROR)
+        rc = DosRead(hFile, pvBuffer, *pcbActual, pcbActual);
+    else
+        kprintf(("fakeIOSftReadAt: DosSetFilePtr(hfile, 0x%08x(%d),..) failed with rc = %d.",
+                 ulOffset, ulOffset, rc));
+
+    if (!f32Stack) ThunkStack32To16();
+
+    printf("fakeIOSftReadAt:                hFile = 0x%04, pcbActual = %p; *pcbActual = 0x%08x, pvBuffer = %p, fpBuffer = %x, ulOffset = 0x%08x, rc = %d\n",
+           hFile, pcbActual, pvBuffer, fpBuffer, ulOffset, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * Write at a given offset in the a file.
+ * @returns  NO_ERROR on success. OS/2 error code on error.
+ * @param    hFile      File handle - System File Number.
+ * @param    pcbActual  Pointer to variable which upon input holds the number
+ *                      of bytes to write, on output the actual number of bytes write.
+ * @param    pvBuffer   Pointer to the write buffer.
+ * @param    fpBuffer   16 far pointer to buffer. (ignored)
+ * @param    ulOffset   File offset to write from. (0=start of file)
+ */
+APIRET KRNLCALL fakeIOSftWriteAt(
+    SFN hFile,
+    PULONG pcbActual,
+    PVOID pvBuffer,
+    ULONG fpBuffer,
+    ULONG ulOffset
+    )
+{
+    KLOGENTRY5("APIRET KRNLCALL","SFN hFile, PULONG pcbActual, PVOID pvBuffer, ULONG fpBuffer, ULONG ulOffset", hFile, pcbActual, pvBuffer, fpBuffer, ulOffset);
+    ULONG   ulMoved;
+    APIRET  rc;
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    rc = DosSetFilePtr(hFile, ulOffset, FILE_BEGIN, &ulMoved);
+    if (rc == NO_ERROR)
+        rc = DosWrite(hFile, pvBuffer, *pcbActual, pcbActual);
+    else
+        kprintf(("fakeIOSftWriteAt: DosSetFilePtr(hfile, 0x%08x(%d),..) failed with rc = %d.",
+                 ulOffset, ulOffset, rc));
+
+    if (!f32Stack) ThunkStack32To16();
+
+    printf("fakeIOSftWriteAt:               hFile = 0x%04, pcbActual = %p; *pcbActual = 0x%08x, pvBuffer = %p, fpBuffer = %x, ulOffset = 0x%08x, rc = %d\n",
+           hFile, pcbActual, pvBuffer, fpBuffer, ulOffset, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * Gets the filesize.
+ * @returns   NO_ERROR on success; OS/2 error code on error.
+ * @param     hFile    File handle - System File Number.
+ * @param     pcbFile  Pointer to ULONG which will hold the file size upon return.
+ */
+APIRET KRNLCALL fakeSftFileSize(
+    SFN hFile,
+    PULONG pcbFile
+    )
+{
+    KLOGENTRY2("APIRET KRNLCALL","SFN hFile, PULONG pcbFile", hFile, pcbFile);
+    FILESTATUS3     fsts3;
+    APIRET          rc;
+    BOOL            f32Stack = ((int)&hFile > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    rc = DosQueryFileInfo(hFile,
+                          FIL_STANDARD,
+                          &fsts3,
+                          sizeof(fsts3));
+    if (rc == NO_ERROR)
+        *pcbFile = fsts3.cbFile;
+    else
+        kprintf(("fakeSftFileSize: DosQueryFileInfo failed with rc=%d\n", rc));
+
+    if (!f32Stack) ThunkStack32To16();
+
+    printf("fakeSftFileSize:                hFile = 0x%04x, pcbFile = %p; *pcbFile = 0x%08x, rc = %d\n",
+           hFile, pcbFile, *pcbFile, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * @status    stub
+ */
+HMTE KRNLCALL fakeVMGetOwner(
+    ULONG ulCS,
+    ULONG ulEIP)
+{
+    KLOGENTRY2("HMTE KRNLCALL","ULONG ulCS, ULONG ulEIP", ulCS, ulEIP);
+    DUMMY();
+
+    printf("fakeVMGetOwner:                 ulCS = 0x%04x, ulEiP = 0x%08x, rc = %d\n",
+           ulCS, ulEIP, 0);
+
+    KLOGEXIT(0);
+    return 0;
+}
+
+
+/**
+ * @status    stub
+ */
+APIRET KRNLCALL fakeVMAllocMem(
+    ULONG   cbSize,
+    ULONG   cbCommit,
+    ULONG   flFlags1,
+    HPTDA   hPTDA,
+    USHORT  usVMOwnerId,
+    HMTE    hMTE,
+    ULONG   flFlags2,
+    ULONG   SomeArg2,
+    PVMAC   pvmac)
+{
+    KLOGENTRY9("APIRET KRNLCALL","ULONG cbSize, ULONG cbCommit, ULONG flFlags1, HPTDA hPTDA, USHORT usVMOwnerId, HMTE hMTE, ULONG flFlags2, ULONG SomeArg2, PVMAC pvmac", cbSize, cbCommit, flFlags1, hPTDA, usVMOwnerId, hMTE, flFlags2, SomeArg2, pvmac);
+    DUMMY();
+    printf("fakeVMAllocMem:                 cbSize = 0x%08x, cbCommit = 0x%08x, flFlags1 = 0x%08x, hPTDA = 0x%04x, usVMOwnerId = 0x%04x, hMTE = 0x%04x, flFlags2 = 0x%08x, SomeArg2 = 0x%08x, pvmac = %p, rc = %d\n",
+           cbSize, cbCommit, flFlags1, hPTDA, usVMOwnerId, hMTE, flFlags2, SomeArg2, pvmac, ERROR_NOT_SUPPORTED);
+
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+
+/**
+ * @status    stub
+ */
+APIRET KRNLCALL fakeVMFreeMem(
+    PVOID   pv,
+    USHORT  hPTDA,
+    ULONG   flFlags
+    )
+{
+    KLOGENTRY3("APIRET KRNLCALL","PVOID pv, USHORT hPTDA, ULONG flFlags", pv, hPTDA, flFlags);
+    DUMMY();
+    printf("fakeVMFreeMem:                  pv = %p, hPTDA = 0x%04x, flFlags = %08x, rc = %d\n",
+           pv, hPTDA, flFlags, ERROR_NOT_SUPPORTED);
+
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+
+/**
+ * @status    stub
+ * @remark    Used by environment stuff...
+ */
+APIRET KRNLCALL fakeVMObjHandleInfo(
+    USHORT  usHob,
+    PULONG  pulAddr,
+    PUSHORT pushPTDA)
+{
+    KLOGENTRY3("APIRET KRNLCALL","USHORT usHob, PULONG pulAddr, PUSHORT pushPTDA", usHob, pulAddr, pushPTDA);
+    APIRET          rc = NO_ERROR;
+    BOOL            f32Stack = ((int)&usHob > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    if (pulAddr > (PULONG)0x10000 && pushPTDA > (PUSHORT)0x10000)
+    {
+        PTIB pTib;
+        PPIB pPib;
+        DosGetInfoBlocks(&pTib, &pPib);
+        switch (usHob)
+        {
+            case 1: *pulAddr = (ULONG)pPib->pib_pchenv; break; //PTDA environ (fakea.asm)
+            default:
+                printf("fakeVMObjHandleInfo:            Invalid handle! (usHob=0x%#4x)\n", usHob);
+                rc = ERROR_INVALID_HANDLE;
+        }
+        *pushPTDA = 10; //dummy
+    }
+    else
+        rc = ERROR_INVALID_PARAMETER;
+
+    if (!f32Stack) ThunkStack32To16();
+
+    printf("fakeVMObjHandleInfo:            usHob = 0x%04x, pulAddr = %p, pushPTDA = %p, rc = %d\n",
+           usHob, pulAddr, pushPTDA, rc);
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+APIRET KRNLCALL fakeVMMapDebugAlias(
+    ULONG   flVMFlags,
+    ULONG   ulAddress,
+    ULONG   cbSize,
+    HPTDA   hPTDA,
+    PVMAC   pvmac)
+{
+    KLOGENTRY5("APIRET KRNLCALL","ULONG flVMFlags, ULONG ulAddress, ULONG cbSize, HPTDA hPTDA, PVMAC pvmac", flVMFlags, ulAddress, cbSize, hPTDA, pvmac);
+    printf("fakeVMMapDebugAlias:            flVMFlags = 0x%08x, ulAddress = 0x%08, cbSize = 0x%08x, hPTDA = 0x%04x, pvmac = %p - not implemented\n",
+           flVMFlags,
+           ulAddress,
+           cbSize,
+           hPTDA,
+           pvmac);
+
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+
+/**
+ * Creates a pseudo handle for a given memory address.
+ * @returns OS/2 return code. NO_ERROR on success.
+ * @param   pvData      Pointer to the data which the handle should represent.
+ * @param   hobOwner    Owner of the pseudo handle.
+ * @param   phob        Pointer to object handle variable. Upon successful return
+ *                      this will hold the handle value of the crated pseudo handle.
+ * @remark  Used for many types of handles within the kernel.
+ *          Among them are the loader HMTEs. The loader uses usOwner = 0xffa6 (ldrmte).
+ */
+APIRET KRNLCALL fakeVMCreatePseudoHandle(
+    PVOID   pvData,
+    VMHOB   usOwner,
+    PVMHOB  phob)
+{
+    KLOGENTRY3("APIRET KRNLCALL","PVOID pvData, VMHOB usOwner, PVMHOB phob", pvData, usOwner, phob);
+    DUMMY();
+    printf("fakeVMCreatePseudoHandle:              - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+
+/**
+ * This call frees a pseudo handle pointer previously allocated by
+ * VMCreatePseudoHandle.
+ * @returns OS/2 return code.
+ * @param   hob     Handle to be freed.
+ */
+APIRET KRNLCALL fakeVMFreePseudoHandle(
+    VMHOB   hob)
+{
+    KLOGENTRY1("APIRET KRNLCALL","VMHOB hob", hob);
+    DUMMY();
+    printf("fakeVMFreePseudoHandle:                - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+
+/**
+ * ldrOpenPath - ldrOpenPath for build 14053 and above.
+ * kernel 14053 and above.
+ *
+ * @returns   OS2 return code.
+ *            plv->lv_sfn  is set to filename handle.
+ * @param     pachFilename  Pointer to modulename. Not zero terminated!
+ * @param     cchFilename   Modulename length.
+ * @param     plv           Loader local variables? (Struct from KERNEL.SDF)
+ * @param     pful          Pointer to flags which are passed on to ldrOpen.
+ * @param     lLibPath      New parameter in build 14053.
+ *                          ldrGetMte calls with 1
+ *                          ldrOpenNewExe calls with 3
+ *                          This is compared to the initial libpath index.
+ *                              The libpath index is:
+ *                                  BEGINLIBPATH    1
+ *                                  LIBPATH         2
+ *                                  ENDLIBPATH      3
+ *                              The initial libpath index is either 1 or 2.
+ *                          - ignored -
+ *
+ */
+ULONG LDRCALL fakeldrOpenPath_new( /* retd  0x14 */
+    PCHAR       pachFilename,      /* ebp + 0x08 */
+    USHORT      cchFilename,       /* ebp + 0x0c */
+    ldrlv_t *   plv,               /* ebp + 0x10 */
+    PULONG      pful,              /* ebp + 0x14 */
+    ULONG       lLibPath           /* ebp + 0x18 */
+    )
+ {
+     KLOGENTRY5("ULONG LDRCALL","PCHAR pachFilename, USHORT cchFilename, ldrlv_t * plv, PULONG pful, ULONG lLibPath", pachFilename, cchFilename, plv, pful, lLibPath);
+     KNOREF(lLibPath);
+     KLOGEXIT(fakeldrOpenPath_old(pachFilename, cchFilename, plv, pful));
+     return fakeldrOpenPath_old(pachFilename, cchFilename, plv, pful);
+ }
+
+
+/**
+ * myldrOpenPath - opens file eventually searching loader specific paths
+ * Pre kernel 14053.
+ *
+ * @returns   OS2 return code.
+ *            pLdrLv->lv_sfn  is set to filename handle.
+ * @param     pachFilename  Pointer to modulename. Not zero terminated?
+ * @param     cchFilename   Modulename length.
+ * @param     plv           Loader local variables? (Struct from KERNEL.SDF)
+ * @param     pful          Pointer to flags which are passed on to ldrOpen.
+ * @status    stub
+ */
+ULONG LDRCALL fakeldrOpenPath_old(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful)
+{
+    KLOGENTRY4("ULONG LDRCALL","PCHAR pachFilename, USHORT cchFilename, ldrlv_t * plv, PULONG pful", pachFilename, cchFilename, plv, pful);
+    static char     szPath[1024];       /* Path buffer. Used to store pathlists. 1024 should be enough */
+                                        /* for LIBPATH (which at had a limit of ca. 750 chars). */
+    static char     sz[CCHMAXPATH];     /* Filename/path buffer. (Normally used to build filenames */
+                                        /* which are passed in as search experessions to DosFindFirst.) */
+
+    APIRET          rc;                 /* Return value. (Pessimistic attitude! Init it to FALSE...) */
+
+    printf("fakeldrOpenPath:        *entry* pachFilename = %.*s, cchFilename = %d,  plv = %p, pful = %p\n",
+           cchFilename, pachFilename, cchFilename, plv, pful);
+
+    if (plv->lv_class != CLASS_GLOBAL)
+        rc = fakeldrOpen(&plv->lv_sfn, pachFilename, pful);
+    else
+    {
+        int iPath;                      /* Current path or pathlist being examined. This is the loop */
+                                        /* variable looping on the FINDDLL_* defines. */
+
+        /* These defines sets the order the paths and pathlists are examined. */
+        #define FINDDLL_BEGINLIBPATH    7
+        #define FINDDLL_LIBPATH         8
+        #define FINDDLL_ENDLIBPATH      9
+        #define FINDDLL_FIRST           FINDDLL_BEGINLIBPATH
+        #define FINDDLL_LAST            FINDDLL_ENDLIBPATH
+
+        /*
+         * Remove DLL extention from the filename.
+         */
+        if (cchFilename > 4 && !strncmp(&pachFilename[cchFilename - 4], ".DLL", 4))
+        {
+            cchFilename -= 4;
+            pachFilename[cchFilename] = '\0';
+        }
+
+        /** @sketch
+         * Loop thru the paths and pathlists searching them for the filename.
+         */
+        rc = ERROR_FILE_NOT_FOUND;
+        for (iPath = FINDDLL_FIRST; iPath <= FINDDLL_LAST; iPath++)
+        {
+            const char  *   pszPath;        /* Pointer to the path being examined. */
+
+            /** @sketch Get the path/dir to examin. (This is determined by the value if iPath.) */
+            switch (iPath)
+            {
+                case FINDDLL_BEGINLIBPATH:
+                    rc = DosQueryExtLIBPATH(szPath, BEGIN_LIBPATH);
+                    break;
+                case FINDDLL_LIBPATH:
+                    rc = DosQueryHeaderInfo(NULLHANDLE, 0, szPath, sizeof(szPath), QHINF_LIBPATH);
+                    break;
+                case FINDDLL_ENDLIBPATH:
+                    rc = DosQueryExtLIBPATH(szPath, END_LIBPATH);
+                    break;
+                default: /* !internalerror! */
+                    KLOGEXIT(ERROR_FILE_NOT_FOUND);
+                    return ERROR_FILE_NOT_FOUND;
+            }
+            if (rc != NO_ERROR)
+            {
+                printf("fakeldrOpenPath: DosQueryExtLIBPATH/DosQueryHeadInfo failed with rc=%d, iPath=%d", rc, iPath);
+                continue;
+            }
+            pszPath = szPath;
+
+
+            /** @sketch
+             * pszPath is now set to the pathlist to be searched.
+             * So we'll loop thru all the paths in the list.
+             */
+            while (pszPath != NULL && *pszPath != '\0')
+            {
+                char *  pszNext;            /* Pointer to the next pathlist path */
+                int     cch;                /* Length of path (including the slash after the slash is added). */
+
+                /** @sketch
+                 * Find the end of the path.
+                 * Copy the path into the sz buffer.
+                 * Set pszNext.
+                 */
+                pszNext = strchr(pszPath, ';');
+                if (pszNext != NULL)
+                {
+                    cch = pszNext - pszPath;
+                    pszNext++;
+                }
+                else
+                    cch = strlen(pszPath);
+
+                if (cch + cchFilename + 1 >= sizeof(sz)) /* assertion */
+                {
+                    printf("fakeldrOpenPath: cch (%d) + cchFilename (%d) + 1 < sizeof(plv->sz) (%d) - paths too long!, iPath=%d",
+                           cch, cchFilename, sizeof(sz), iPath);
+                    pszPath = pszNext;
+                    continue;
+                }
+                memcpy(sz, pszPath, cch);
+
+                /** @sketch
+                 * Add a '\\' and the filename (pszFullname) to the path;
+                 * then we'll have a fullpath.
+                 */
+                sz[cch++] = '\\';
+                memcpy(&sz[cch], pachFilename, cchFilename);
+                memcpy(&sz[cch + cchFilename], ".DLL", 5);
+
+                rc = fakeldrOpen(&plv->lv_sfn, sz, pful);
+                switch (rc)
+                {
+                    case ERROR_FILE_NOT_FOUND:          case ERROR_PATH_NOT_FOUND:          case ERROR_ACCESS_DENIED:           case ERROR_INVALID_ACCESS:
+                    case ERROR_INVALID_DRIVE:           case ERROR_NOT_DOS_DISK:            case ERROR_REM_NOT_LIST:            case ERROR_BAD_NETPATH:
+                    case ERROR_NETWORK_BUSY:            case ERROR_DEV_NOT_EXIST:           case ERROR_TOO_MANY_CMDS:           case ERROR_ADAP_HDW_ERR:
+                    case ERROR_UNEXP_NET_ERR:           case ERROR_BAD_REM_ADAP:            case ERROR_NETNAME_DELETED:         case ERROR_BAD_DEV_TYPE:
+                    case ERROR_NETWORK_ACCESS_DENIED:   case ERROR_BAD_NET_NAME:            case ERROR_TOO_MANY_SESS:           case ERROR_REQ_NOT_ACCEP:
+                    case ERROR_INVALID_PASSWORD:        case ERROR_OPEN_FAILED:             case ERROR_INVALID_NAME:            case ERROR_FILENAME_EXCED_RANGE:
+                    case ERROR_VC_DISCONNECTED:
+                        rc = ERROR_FILE_NOT_FOUND;
+                        pszPath = pszNext;
+                        continue;
+                }
+
+                /*
+                 * Fatal error or success.
+                 */
+                printf("fakeldrOpenPath:        *exit*  plv->lv_sfn = 0x%04x, rc = %d\n", plv->lv_sfn, rc);
+                KLOGEXIT(rc);
+                return rc;
+            }
+        } /* for iPath */
+    }
+
+    printf("fakeldrOpenPath:        *exit*  plv->lv_sfn = 0x%04x, rc = %d\n", plv->lv_sfn, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * LDRClearSem - Clears the loader semaphore.
+ * (It does some garbage collection on release.)
+ * @returns   NO_ERROR on sucess.
+ *            OS/2 error on failure. (ERROR_INTERRUPT?)
+ * @status    completely implemented.
+ */
+ULONG LDRCALL fakeLDRClearSem(void)
+{
+    KLOGENTRY0("ULONG LDRCALL");
+    KLOGEXIT(fakeKSEMReleaseMutex(&fakeLdrSem));
+    return fakeKSEMReleaseMutex(&fakeLdrSem);
+}
+
+/**
+ * KSEMReuqestMutex faker.
+ * @returns   NO_ERROR
+ * @param     hkmtx
+ * @param     ulTimeout
+ * @status    completely implemented.
+ * @remark
+ */
+ULONG KRNLCALL fakeKSEMRequestMutex(HKSEMMTX hkmtx, ULONG ulTimeout)
+{
+    KLOGENTRY2("ULONG KRNLCALL","HKSEMMTX hkmtx, ULONG ulTimeout", hkmtx, ulTimeout);
+    unsigned short usSlot = getSlot();
+    ULONG          rc = NO_ERROR;
+
+    if (memcmp(&hkmtx->debug.ksem_achSignature[0], "KSEM", 4) != 0)
+    {
+        printf("fakeKSEMQueryMutex:             hkmtx = %p, invalid signature (%.4s)\n", hkmtx, hkmtx->debug.ksem_achSignature);
+        KLOGEXIT(FALSE);
+        return FALSE;
+    }
+
+    if (hkmtx->debug.ksem_Owner == 0)
+    {
+        hkmtx->debug.ksem_Owner = usSlot;
+        hkmtx->debug.ksem_cusNest = 1;
+    }
+    else if (hkmtx->debug.ksem_Owner == usSlot)
+        hkmtx->debug.ksem_cusNest++;
+    else
+        rc = ERROR_SEM_BUSY;
+
+    printf("fakeKSEMRequestMutex:           hkmtx = %p, ulTimeout = 0x%x, owner = %d, usage count = %d, rc = %d\n",
+           hkmtx, ulTimeout, hkmtx->debug.ksem_cusNest, hkmtx->debug.ksem_Owner, ERROR_SEM_BUSY);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * KSEMReleaseMutex faker.
+ * @returns   NO_ERROR
+ * @param     hkmtx
+ * @param     ulTimeout
+ * @status    completely implemented.
+ * @remark
+ */
+ULONG KRNLCALL fakeKSEMReleaseMutex(HKSEMMTX hkmtx)
+{
+    KLOGENTRY1("ULONG KRNLCALL","HKSEMMTX hkmtx", hkmtx);
+    unsigned int    usSlot = getSlot();
+    int rc = NO_ERROR;
+
+    if (memcmp(&hkmtx->debug.ksem_achSignature[0], "KSEM", 4) != 0)
+    {
+        printf("fakeKSEMQueryMutex:             hkmtx = %p, invalid signature (%.4s)\n", hkmtx, hkmtx->debug.ksem_achSignature);
+        KLOGEXIT(FALSE);
+        return FALSE;
+    }
+
+    if (hkmtx->debug.ksem_Owner == usSlot)
+    {
+        if (--hkmtx->debug.ksem_cusNest == 0)
+            hkmtx->debug.ksem_Owner = 0;
+    }
+    else
+        rc = ERROR_NOT_OWNER;
+
+    printf("fakeKSEMReleaseMutex:           hkmtx = %p, usage count = %d, owner = %d, rc = %d\n",
+           hkmtx, hkmtx->debug.ksem_cusNest, hkmtx->debug.ksem_Owner, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+
+/**
+ * KSEMQueryMutex faker.
+ * @returns     TRUE if owner or clear. Clear if *pcusNest is 0.
+ *              FALSE if other owner.
+ * @param       hkmtx       Handle to kernel mutex.
+ * @param       pcusNest    Pointer to variable which is to receive the nesting count.
+ *                          (ie. the number of times we have taken this semaphore.)
+ * @status      completely implemented.
+ * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+BOOL KRNLCALL  fakeKSEMQueryMutex(HKSEMMTX hkmtx, PUSHORT pcusNest)
+{
+    KLOGENTRY2("BOOL KRNLCALL","HKSEMMTX hkmtx, PUSHORT pcusNest", hkmtx, pcusNest);
+    unsigned int    usSlot = getSlot();
+    BOOL            fRc = TRUE;
+
+    if (memcmp(&hkmtx->debug.ksem_achSignature[0], "KSEM", 4) != 0)
+    {
+        printf("fakeKSEMQueryMutex:             hkmtx = %p, invalid signature (%.4s)\n", hkmtx, hkmtx->debug.ksem_achSignature);
+        KLOGEXIT(FALSE);
+        return FALSE;
+    }
+
+    if (hkmtx->debug.ksem_Owner == 0)
+    {
+        if (pcusNest)
+            *pcusNest = 0;
+        fRc = FALSE;
+    }
+    else
+    {
+        fRc = (hkmtx->debug.ksem_Owner == usSlot);
+        if (pcusNest)
+            *pcusNest = hkmtx->debug.ksem_cusNest;
+    }
+
+    printf("fakeKSEMQueryMutex:             hkmtx = %p, usage count = %d, owner = %d, *pcusNest = %d, rc = %d\n",
+           hkmtx, hkmtx->debug.ksem_cusNest, hkmtx->debug.ksem_Owner, pcusNest ? *pcusNest : -1, fRc);
+
+    KLOGEXIT(fRc);
+    return fRc;
+}
+
+
+/**
+ * KSEMInit faker.
+ * @param       pksem       Pointer to the semaphore struct to initiate.
+ * @param       fulType     Semaphore type. (only KSEM_MUTEX is supported)
+ * @param       fulFlags    Semaphore flags. (not validated)
+ * @status      partially implemented.
+ * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+VOID  KRNLCALL  fakeKSEMInit(PKSEM pksem, ULONG fulType, ULONG fulFlags)
+{
+    KLOGENTRY3("VOID KRNLCALL","PKSEM pksem, ULONG fulType, ULONG fulFlags", pksem, fulType, fulFlags);
+    if (fulType != KSEM_MUTEX && fulType != KSEM_SHARED)
+    {
+        printf("fakeKSEMInit:                   Invalid fulType parameter (%d).\n", fulType);
+        KLOGEXITVOID();
+        return; /*ERROR_INVALID_PARAMETER;*/
+    }
+
+    memcpy(pksem->mtx.debug.ksem_achSignature, "KSEM", 4);
+    pksem->mtx.debug.ksem_bFlags = (char)fulFlags;
+    pksem->mtx.debug.ksem_bType = fulType;
+    pksem->mtx.debug.ksem_cusNest = 0;
+    pksem->mtx.debug.ksem_cusPendingWriters = 0;
+    pksem->mtx.debug.ksem_Owner = 0;
+
+    printf("fakeKSEMInit:                   pksem=%p, fulType=%d, fulFlags=0x%x.\n", pksem, fulType, fulFlags);
+    KLOGEXITVOID();
+}
+
+
+ULONG KRNLCALL  fakeKSEMRequestExclusive(HKSEMSHR hkshr, ULONG ulTimeout)
+{
+    //KLOGENTRY2("ULONG","HKSEMSHR hkshr, ULONG ulTimeout", hkshr, ulTimeout);  /* used bye kLog.c */
+    DUMMY();
+    KNOREF(ulTimeout);
+
+    Assert(!memcmp(hkshr->debug.ks_achSignature, "KSEM", 4));
+    Assert(hkshr->debug.ks_bType == KSEM_SHARED);
+    Assert(hkshr->debug.ks_Owner == 0);
+    hkshr->debug.ks_Owner = 1;
+    //KLOGEXIT(0);
+    return 0;
+}
+
+
+ULONG KRNLCALL  fakeKSEMRequestShared(HKSEMSHR hkshr, ULONG ulTimeout)
+{
+    //KLOGENTRY2("ULONG","HKSEMSHR hkshr, ULONG ulTimeout", hkshr, ulTimeout);  /* used bye kLog.c */
+    DUMMY();
+    KNOREF(ulTimeout);
+
+    Assert(!memcmp(hkshr->debug.ks_achSignature, "KSEM", 4));
+    Assert(hkshr->debug.ks_bType == KSEM_SHARED);
+    Assert(hkshr->debug.ks_Owner == 0);
+    hkshr->debug.ks_Owner = 42;
+    //KLOGEXIT(0);
+    return 0;
+}
+
+
+VOID  KRNLCALL  fakeKSEMRelease(HKSEM hksem)
+{
+    //KLOGENTRY1("VOID","HKSEM hksem", hksem);                                  /* used bye kLog.c */
+    DUMMY();
+
+    Assert(!memcmp(hksem->shr.debug.ks_achSignature, "KSEM", 4));
+    switch (hksem->shr.debug.ks_bType)
+    {
+        case KSEM_SHARED:
+            Assert(hksem->shr.debug.ks_Owner != 0);
+            hksem->shr.debug.ks_Owner = 0;
+            break;
+        case KSEM_MUTEX:
+            Assert(hksem->mtx.debug.ksem_Owner != 0);
+            hksem->mtx.debug.ksem_Owner = 0;
+            break;
+        default:
+            INT3();
+    }
+    //KLOGEXITVOID();
+}
+
+
+VOID  KRNLCALL  fakeKSEMQuery(HKSEM hksem, PULONG pul)
+{
+    KLOGENTRY2("VOID","HKSEM hksem, PULONG pul", hksem, pul);
+    DUMMY();
+    KNOREF(hksem);
+    KNOREF(pul);
+    KLOGEXITVOID();
+}
+
+
+VOID  KRNLCALL  fakeKSEMResetEvent(HKSEMEVT hkev)
+{
+    KLOGENTRY1("VOID","HKSEMEVT hkev", hkev);
+    DUMMY();
+    KNOREF(hkev);
+    KLOGEXITVOID();
+}
+
+
+VOID  KRNLCALL  fakeKSEMPostEvent(HKSEMEVT hkev)
+{
+    KLOGENTRY1("VOID KRNLCALL","HKSEMEVT hkev", hkev);
+    DUMMY();
+    KNOREF(hkev);
+    KLOGEXITVOID();
+}
+
+
+ULONG KRNLCALL  fakeKSEMWaitEvent(HKSEMEVT hkev, ULONG ulTimeout)
+{
+    KLOGENTRY2("ULONG","HKSEMEVT hkev, ULONG ulTimeout", hkev, ulTimeout);
+    DUMMY();
+    KNOREF(hkev);
+    KNOREF(ulTimeout);
+    KLOGEXIT(-1);
+    return -1;
+}
+
+
+/**
+ * Gets the thread slot number.
+ * @returns     Thread slot number.
+ * @status      completely implemented.
+ * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+unsigned short getSlot(void)
+{
+    KLOGENTRY0("unsigned short");
+    PPIB ppib;
+    PTIB ptib;
+    BOOL            f32Stack = ((int)&ppib > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+    DosGetInfoBlocks(&ptib, &ppib);
+
+    if (!f32Stack) ThunkStack32To16();
+
+    KLOGEXIT((unsigned short)ptib->tib_ordinal);
+    return (unsigned short)ptib->tib_ordinal;
+}
+
+
+/**
+ * Copy user memory into system memory.
+ * @returns   OS/2 return code. (NO_ERROR is success)
+ * @param     pv     Pointer to target (system) data area.
+ * @param     pvUsr  Pointer to source (user) data area.
+ * @param     cb     Count of bytes to copy.
+ * @param     fl     Flags.
+ * @status  Partially implemented.
+ * @remark  Ignores fl. Crashes on error.
+ */
+ULONG KRNLCALL   fakeTKFuBuff(PVOID pv, PVOID pvUsr, ULONG cb, ULONG fl)
+{
+    KLOGENTRY4("ULONG KRNLCALL","PVOID pv, PVOID pvUsr, ULONG cb, ULONG fl", pv, pvUsr, cb, fl);
+    memcpy(pv, pvUsr, cb);
+
+    printf("fakeTKFuBuff:                   pv = %p, pvUsr = %p, cb = 0x%08x, fl = 0x%08x, rc = %d\n",
+           pv, pvUsr, cb, fl, NO_ERROR);
+
+    KLOGEXIT(NO_ERROR);
+    return NO_ERROR;
+}
+
+
+/**
+ * Copy system memory to user memory.
+ * @returns   OS/2 return code. (NO_ERROR is success)
+ * @param     pvUsr  Pointer to target (user) data area.
+ * @param     pv     Pointer to source (system) data area.
+ * @param     cb     Count of bytes to copy.
+ * @param     fl     Flags.
+ * @status  Partially implemented.
+ * @remark  Ignores fl. Crashes on error.
+ */
+ULONG KRNLCALL   fakeTKSuBuff(PVOID pvUsr, PVOID pv, ULONG cb, ULONG fl)
+{
+    KLOGENTRY4("ULONG KRNLCALL","PVOID pvUsr, PVOID pv, ULONG cb, ULONG fl", pvUsr, pv, cb, fl);
+    memcpy(pvUsr, pv, cb);
+
+    printf("fakeTKSuBuff:                   pvUsr = %p, pv = %p, cb = 0x%08x, fl = 0x%08x, rc = %d\n",
+           pvUsr, pv, cb, fl, NO_ERROR);
+
+    KLOGEXIT(NO_ERROR);
+    return NO_ERROR;
+}
+
+
+/**
+ * String length. (includes NULL(s))
+ * @returns   OS/2 return code. (NO_ERROR is success)
+ *            ERROR_TERMINATOR_NOT_FOUND
+ * @param     pcch      Pointer to length variable.
+ * @param     pvUsr     Pointer to user data to preform string length on.
+ * @param     cchMax    Max string length.
+ * @param     fl        Flags.
+ * @param     fDblNULL  TRUE:  Double '\0' (ie. '\0\0') terminated. Usefull for scanning environments.
+ *                      FALSE: Single string. (ie. one '\0').
+ * @status  Partially implemented.
+ * @remark  Ignores fl. Crashes on error.
+ */
+ULONG KRNLCALL   fakeTKFuBufLen(PLONG pcch, PVOID pvUsr, ULONG cchMax, ULONG fl, BOOL fDblNULL)
+{
+    KLOGENTRY5("ULONG KRNLCALL","PLONG pcch, PVOID pvUsr, ULONG cchMax, ULONG fl, BOOL fDblNULL", pcch, pvUsr, cchMax, fl, fDblNULL);
+    ULONG   rc;
+    PSZ     psz = pvUsr;
+
+    cchMax += (ULONG)pvUsr;
+
+    while ((ULONG)psz < cchMax)
+    {
+        if (*psz++ == '\0')
+            if (!fDblNULL || (ULONG)psz == cchMax || *psz++ != '\0')
+                break;
+    }
+
+    *pcch = (ULONG)psz - (ULONG)pvUsr;
+
+    /* Hope this is the correct definition of max length: Not inclusive. */
+    if ((ULONG)psz == cchMax)
+        rc = ERROR_TERMINATOR_NOT_FOUND;
+    else
+        rc = NO_ERROR;
+
+    printf("fakeTKFuBufLen:                 pcch = %p; *pcch = 0x%08x, pvUsr = %p, cchMax = 0x%08x, fl = 0x%08x, fDblNULL = %x, rc = %d\n",
+           pcch, *pcch, pvUsr, cchMax, fl, fDblNULL, NO_ERROR);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * Copy user memory to user memory.
+ * @returns   OS/2 return code. (NO_ERROR is success)
+ * @param     pvUsr  Pointer to target (user) data area.
+ * @param     pv     Pointer to source (user) data area.
+ * @param     cb     Count of bytes to copy.
+ * @param     fl     Flags.
+ * @status  Partially implemented.
+ * @remark  Ignores fl. Crashes on error.
+ */
+ULONG KRNLCALL   fakeTKSuFuBuff(PVOID pvTarget, PVOID pvSource, ULONG cb, ULONG fl)
+{
+    KLOGENTRY4("ULONG KRNLCALL","PVOID pvTarget, PVOID pvSource, ULONG cb, ULONG fl", pvTarget, pvSource, cb, fl);
+    memcpy(pvTarget, pvSource, cb);
+
+    printf("fakeTKSuFuBuff:                   pvTarget = %p, pvSource = %p, cb = 0x%08x, fl = 0x%08x, rc = %d\n",
+           pvTarget, pvSource, cb, fl, NO_ERROR);
+
+    KLOGEXIT(NO_ERROR);
+    return NO_ERROR;
+}
+
+
+/**
+ * Validates an hMTE and gets the MTE pointer - FAKE.
+ * @returns Pointer to MTE on success.
+ *          NULL on error.
+ * @param   hMTE  MTE handle.
+ * @remark  If you wan't to this faster:
+ *            Use the hMTE as a HOB and get the HOB address (by using VMGetHandleInfo).
+ * @status  stub.
+ */
+PMTE LDRCALL fakeldrValidateMteHandle(HMTE hMTE)
+{
+    KLOGENTRY1("PMTE LDRCALL","HMTE hMTE", hMTE);
+    DUMMY();
+
+    printf("fakeldrValidateMteHandle:       hMTE = 0x%04x, pMTE (rc) = %p\n",
+           hMTE, NULL);
+
+    KLOGEXIT(NULL);
+    return NULL;
+}
+
+
+/**
+ * C worker function for fakeg_tkExecPgm. This is called by fakeg_tkExecPgm (fakea.asm).
+ * @returns   OS/2 return code.
+ * @param     execFlag      Exec flag (DosExecPgm execFlag).
+ * @param     pArg          Pointer to arguments. (NULL allowed)
+ * @param     pEnv          Pointer to environment. (NULL allowed)
+ * @param     pszFilename   Pointer to filename.
+ * @sketch
+ * @status
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG _Optlink tkExecPgmWorker(ULONG execFlag, PSZ pArg, PSZ pEnv, PSZ pszFilename)
+{
+    KLOGENTRY4("ULONG","ULONG execFlag, PSZ pArg, PSZ pEnv, PSZ pszFilename", execFlag, pArg, pEnv, pszFilename);
+    APIRET      rc;
+    ldrrei_t    rei;
+
+    printf("tkExecPgmWorker:                execFlag = %d, pArg = %p, pEnv = %p, pszFilename = %s\n", execFlag, pArg, pEnv, pszFilename);
+
+    /*
+     * Take loader semaphore.
+     */
+    rc = KSEMRequestMutex(&fakeLdrSem, KSEM_INDEFINITE_WAIT);
+    if (rc != NO_ERROR)
+    {
+        KLOGEXIT(rc);
+        return rc;
+    }
+
+    /*
+     * Simulate loading.
+     */
+    rc = fakeLDRLoadExe(pszFilename, SSToDS(&rei));
+
+    KNOREF(pArg);
+    KNOREF(pEnv);
+    KNOREF(execFlag);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * Fake implementation of LDRLoadExe.
+ * Not currently overriden, but used by tkExecPgmWorker to load executables.
+ * @returns   OS/2 return code.
+ * @param     pszFilename   Name of executable image to load.
+ * @param     pEI           It seems this is a pointer to a ldrrei_s struct.
+ *                          (currently ignored)
+ * @sketch
+ * @status
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG LDRCALL fakeLDRLoadExe(PSZ pszFilename, ldrrei_t *pEI)
+{
+    KLOGENTRY2("ULONG LDRCALL","PSZ pszFilename, ldrrei_t * pEI", pszFilename, pEI);
+    APIRET  rc;
+    int     cchFilename = strlen(pszFilename);
+
+    printf("fakeLDRLoadExe:         *entry* pszFilename = %s, pEI = %p\n",
+           pszFilename, pEI);
+
+    rc = fakeldrGetModule(pszFilename, (cchFilename << 16) | (LVTYPE_EXE << 8) | CLASS_PROGRAM);
+
+    printf("fakeLDRLoadExe:         *exit*  pszFilename = %s, pEI = %p, rc = %d\n",
+           pszFilename, pEI, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+
+/**
+ * Fake implementeation of ldrGetModule.
+ * Not currently overriden, but used by fakeLDRLoadExe to load executables.
+ * @returns   OS/2 return code.
+ * @param     pszFilename   Name of executable image to load.
+ * @param     ul            low 8 bits:     Module CLASS_*.
+ *                          high 8 bits:    Executable type LVTYPE_* ?
+ *                          high 16 bits:   Filename length.
+ * @sketch
+ *  OS/2 kernel seems to do:
+ *      Call Sec32GetModule
+ *      Call ldrGetMte which does the necessary loading / attaching.
+ *      Call ldrLoadImports for all imported DLLs. (and the exe?)
+ *      Call ldrProcessObjects for LX and ldrPreloadLDT for NE imported DLLs. (and the exe?)
+ *      Call ldrProcessImports.
+ *
+ *  We do:
+ *      Call fakeldrGetMte.
+ *      Call fakeldrLoadImports.
+ *
+ * @status
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG LDRCALL fakeldrGetModule(PSZ pszFilename, ULONG ul)
+{
+    KLOGENTRY2("ULONG LDRCALL","PSZ pszFilename, ULONG ul", pszFilename, ul);
+    APIRET  rc;
+    PMTE    pmte = NULL;
+
+    printf("fakeldrGetModule:       *entry* pszFilename = %s, ul = 0x%08x\n",
+           pszFilename, ul);
+
+    rc = fakeldrGetMte(pszFilename, (USHORT)(ul >> 16), (UCHAR)((ul & 0xff00) >> 8), (UCHAR)(ul & 0x00ff), SSToDS(&pmte));
+    if (rc == NO_ERROR)
+    {
+        rc = fakeldrLoadImports(pmte);
+    }
+
+    printf("fakeldrGetModule:       *exit*  pszFilename = %s, ul = 0x%08x, rc = %d\n",
+           pszFilename, ul, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ *
+ * @returns
+ * @param
+ * @equiv
+ * @time
+ * @sketch
+ *  OS/2 kernel seems to do:
+ *      IF not device driver THEN
+ *          Uppercase the name.
+ *          Call ldrFindModule to try find the module within currenly loaded modules.
+ *      ENDIF
+ *
+ *    tryagain:
+ *      IF found THEN
+ *          Set MTEGETMTEDONE flag in mte_flags2.
+ *          Call ldrChkLoadType to ensure correct load type.
+ *          IF attached or special modules (DOSMOD, VDDMOD, FSHMOD or MVDMMOD)
+ *              IF miniIFS and !FSHMOD THEN Fail with rc=ERROR_INVALID_NAME
+ *              return successfully.
+ *          ENDIF
+ *          lv_sfn <- mte_sfn
+ *          Set the USED flag in mte_flags1
+ *          Set the MTELOADORATTACH flag in mte_flags2
+ *          Some processing of packed segments???? Dll init flags???
+ *      ELSE *not found*
+ *          IF class is CLASS_SPECIFIC AND ldrCheckGlobal returned TRUE THEN
+ *              * this is because some specific modules is promoted to global
+ *              * modules for some reasons I haven't ivestigated. (ldrPrmoteMTE)
+ *              tryagain.
+ *          ENDIF
+ *          Set some flag to false.
+ *          Calls to ldrOpenNewExe to load the exectuble from disk.
+ *          IF this failes THEN fail.
+ *          IF class is CLASS_GLOBAL and module is loaded as specific
+ *              (ldrCheckSpecific returns TRUE) THEN
+ *              Close and retry with the mte returned ldrCheckSpecific
+ *              tryagain.
+ *          ENDIF
+ *          Sets some local variable to point at pheaderbuf, where ldrOpenNewExe
+ *              has put the executable header.
+ *          Call ldrCheckLoadType and fail if this failes.
+ *          Call ldrCreateMte and fail if this failes.
+ *          Set some local variables to lv_pmte and lv_pmte->mte_swapmte.
+ *          Set the MTELOADORATTACH and MTEGETMTEDONE flags.
+ *          Call ldrInvTgtErrTxt.
+ *          IF DDInitTime AND DEVDRVMOD OR FSDMOD THEN
+ *              ptda_module of current PTDA to the mtehandle of the module.
+ *          ENDIF
+ *          IF DOSCALL1 (checks name) THEN
+ *              Set DOSLIB flag of mte_flags1.
+ *              Set global pmteDoscall1 to point to the mte.
+ *              Set global hmteDoscall1 to the handle of the mte.
+ *          ENDIF
+ *      ENDIF
+ *      IF VDDMOD THEN
+ *          call VDMMLoadingVDD with the mte handle.
+ *      ENDIF
+ *      IF NE executable THEN
+ *          Call ldrAllocSegments
+ *      ELSE
+ *          Call ldrAllocObjects
+ *      ENDIF
+ *      IF failed THEN fail.
+ *      IF LVTYPE_EXE THEN
+ *          Set the ptda_module of the ExecChild PTDA to mtehandle.
+ *          IF MTELONGNAMES THEN
+ *              Set ptda_NewFiles to something.
+ *          ENDIF
+ *          Increment usage count, ie. mte_usecnt-
+ *      ELSE IF LVTYPE_DLL AND !somelocalflag AND NOINTERNFIXUPS THEN
+ *          Remove Internal fixups?
+ *          (Calls ldrIsInternalFixup and VMReallocKHB during this processing.)
+ *      ENDIF
+ *      Clears the MTEPROCESSED flag of mte_flags1.
+ *      Sets the return mte pointer. (ppmte)
+ *      return successfully.
+ *
+ *  We do:
+ *      Uppercase the string. (do we have to switch stack?)
+ *      Call fakeldrOpenNewExe to do it's work.
+ *      Call fakeldrCreateMte to create a fake mte.
+ *      return.
+ *
+ * @status
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG LDRCALL   fakeldrGetMte(PCHAR pachFilename, USHORT cchFilename, UCHAR fchType, UCHAR fchClass, PPMTE ppmte)
+{
+    KLOGENTRY5("ULONG LDRCALL","PCHAR pachFilename, USHORT cchFilename, UCHAR fchType, UCHAR fchClass, PPMTE ppmte", pachFilename, cchFilename, fchType, fchClass, ppmte);
+    ldrlv_t         lv;
+    APIRET          rc;
+
+    printf("fakeldrGetMte:          *entry* pachFilename = %.*s, cchFilename = %#02x, fchType %#2x, fchClass = %#2x, ppmte = %p\n",
+           cchFilename, pachFilename, cchFilename, fchType, fchClass, ppmte);
+
+    /*
+     * Initiate the local variables.
+     */
+    memset(SSToDS(&lv), 0, sizeof(lv));
+    lv.lv_sfn = (USHORT)-1;
+    lv.lv_type = fchType;
+    lv.lv_class = fchClass;
+
+    /*
+     * Uppercase the string.
+     */
+    fakeldrUCaseString(pachFilename, cchFilename);
+
+    /*
+     * Open the new executable.
+     */
+    rc = fakeldrOpenNewExe(pachFilename, cchFilename, SSToDS(&lv), NULL);
+    if (rc != NO_ERROR)
+    {
+        fakeldrClose(lv.lv_sfn);
+        printf("fakeldrGetMte:          *exit*  pachFilename = %.*s, ppmte = %p; *ppmte = %p, rc = %d\n",
+               cchFilename, pachFilename, ppmte, *ppmte, rc);
+        KLOGEXIT(rc);
+        return rc;
+    }
+
+    /*
+     * Create MTE for the opened file.
+     */
+    rc = fakeldrCreateMte(pheaderbuf, SSToDS(&lv));
+    if (rc == NO_ERROR)
+    {
+        /*
+         * Set some flags... More?
+         */
+        lv.lv_pmte->mte_flags2 |= MTEGETMTEDONE | MTELOADORATTACH;
+        *ppmte = lv.lv_pmte;
+    }
+
+    printf("fakeldrGetMte:          *exit*  pachFilename = %.*s, ppmte = %p; *ppmte = %p, rc = %d\n",
+           cchFilename, pachFilename, ppmte, *ppmte, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+
+/**
+ * Opens an executable module.
+ * @returns   OS2 error code.
+ * @param     pachFilename      Filename of the executable module to open.
+ * @param     cchFilename       Filename length.
+ * @param     plv               Pointer to local variables.
+ * @param     pus               Pointer to some flags (LDRQAppType flags?!).
+ * @sketch
+ *  OS/2 kernel seems to do:
+ *      Call ldrOpenPath to open the file.
+ *      IF this fail THEN
+ *          Set lv_sfn to -1 and return errorcode.
+ *      ENDIF
+ *      Set local variable to pheaderbuf.
+ *      IF pus THEN set *pus to 1
+ *      Call ldrRead to read the MZ header.
+ *      Fail if this failed. (Don't close file caller does that.)
+ *      IF LXMAGIC of NEMAGIC found THEN
+ *          lv_new_exe_off <- 0;
+ *      ELSE
+ *          IF !EMAGIC or 'OZ' THEN
+ *              Fail with rc=ERROR_INVALID_EXE_SIGNATURE.
+ *          ENDIF
+ *          IF pus THEN set *pus to 2.
+ *          lv_new_exe_off <- e_lfanew.
+ *      ENDIF
+ *      Call ldrRead to read LX/NE header at lv_new_exe_off.
+ *      Fail if this failed.
+ *      IF NOT  LXMAGIC OR NEMAGIC THEN
+ *          IF LEMAGIC AND pus THEN Set *pus to 0.
+ *          IF PEMAGIC and pus THEN Set *pus to 3.
+ *          Fail with rc=ERROR_INVALID_EXE_SIGNATURE.
+ *      ENDIF
+ *      IF pus THEN Set *pus to 0.
+ *      IF invalid LX exeheader THEN
+ *          Fail with rc=ERROR_INVALID_EXE_SIGNATURE.
+ *      ENDIF
+ *      IF NEMAGIC THEN
+ *          Call ldrExpandHeader
+ *      ELSE
+ *          Set the MTELONGNAMES flag in e32_mflags.
+ *      ENDIF
+ *      IF LDRINVALID (in e32_mflags) THEN
+ *          Fail with rc=ERROR_EXE_MARKED_INVALID.
+ *      ENDIF
+ *      Clear some e32_mflags, MTE_MEDIAFIXED, MTEMEDIACONTIG and MTEMEDIA16M.
+ *      Or in flags set by ldrOpenPath into e32_mflags. (media type flags?!)
+ *      Call ldrMungeFlags
+ *      return retur code from ldrMungeFlags.
+ *
+ *  We do:
+ *      Call fakeldrOpenPath to open the file.
+ *      IF this fail THEN
+ *          Set lv_sfn to -1 and return errorcode.
+ *      ENDIF
+ *      IF pus THEN set *pus to 1
+ *      Call ldrRead to read the MZ header.
+ *      Fail if this failed. (Don't close file caller does that.)
+ *      If MZ header Then
+ *          Set lv_new_exe_off to e_lfanew.
+ *      else
+ *          Set lv_new_exe_off to 0.
+ *      Call ldrRead to read the LX header.
+ *      Fail if this failed. (Don't close file caller does that.)
+ *      If Not LX signature Then
+ *          Fail.
+ *      return successfully.
+ *
+ * @status
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG LDRCALL   fakeldrOpenNewExe(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PUSHORT pus)
+{
+    KLOGENTRY4("ULONG LDRCALL","PCHAR pachFilename, USHORT cchFilename, ldrlv_t * plv, PUSHORT pus", pachFilename, cchFilename, plv, pus);
+    APIRET  rc;
+    ULONG   ful;
+
+    printf("fakeldrOpenNewExe:      *entry* pachFilename = %.*s, cchFilename = %#2, plv = %p, pus = %p\n",
+           cchFilename, pachFilename, cchFilename, plv, pus);
+
+    rc = fakeldrOpenPath(pachFilename, cchFilename, plv, SSToDS(&ful), 1);
+    if (rc != NO_ERROR)
+    {
+        plv->lv_sfn = 0xffff;
+        printf("fakeldrOpenNewExe:      *exit*  pachFilename = %.*s, plv->lv_sfn = %#4x, rc = %d\n",
+               cchFilename, pachFilename, plv->lv_sfn, rc);
+        KLOGEXIT(rc);
+        return rc;
+    }
+    if (pus) *pus = 1;
+
+    memset(pheaderbuf, 0, sizeof(struct exe_hdr)); //zero it just in case....
+    rc = fakeldrRead(plv->lv_sfn, 0, pheaderbuf, 0, sizeof(struct exe_hdr), NULL);
+    if (rc != NO_ERROR)
+    {
+        plv->lv_sfn = 0xffff;
+        printf("fakeldrOpenNewExe:      *exit*  pachFilename = %.*s, plv->lv_sfn = %#4x, rc = %d\n",
+               cchFilename, pachFilename, plv->lv_sfn, rc);
+        KLOGEXIT(rc);
+        return rc;
+    }
+
+    if (*(PUSHORT)pheaderbuf == EMAGIC)
+        plv->lv_new_exe_off = ((struct exe_hdr *)pheaderbuf)->e_lfanew;
+    else
+        plv->lv_new_exe_off = 0;
+
+    memset(pheaderbuf, 0, sizeof(struct e32_exe)); //zero it just in case....
+    rc = fakeldrRead(plv->lv_sfn, plv->lv_new_exe_off, pheaderbuf, 0, sizeof(struct e32_exe), NULL);
+    if (rc != NO_ERROR)
+    {
+        plv->lv_sfn = 0xffff;
+        printf("fakeldrOpenNewExe:      *exit*  pachFilename = %.*s, plv->lv_sfn = %#4x, rc = %d\n",
+               cchFilename, pachFilename, plv->lv_sfn, rc);
+        KLOGEXIT(rc);
+        return rc;
+    }
+
+    if (*(PUSHORT)pheaderbuf != E32MAGIC)
+    {
+        plv->lv_sfn = 0xffff;
+        rc = ERROR_INVALID_EXE_SIGNATURE;
+        printf("fakeldrOpenNewExe:      *exit*  pachFilename = %.*s, plv->lv_sfn = %#4x, rc = %d\n",
+               cchFilename, pachFilename, plv->lv_sfn, rc);
+        KLOGEXIT(rc);
+        return rc;
+    }
+
+    printf("fakeldrOpenNewExe:      *exit*  pachFilename = %.*s, plv->lv_sfn = %#4x, rc = %d\n",
+           cchFilename, pachFilename, plv->lv_sfn, rc);
+
+    KLOGEXIT(NO_ERROR);
+    return NO_ERROR;
+}
+
+
+/**
+ * Fake ldrCreateMte implementation.
+ * @returns
+ * @param     pe32  Pointer to the LX/NE header we've just read.
+ * @param     plv   Pointer to local variables.
+ * @sketch    !This does a lot of thing!
+ *
+ *  OS/2 Kernel seems to do:
+ *      Allocate a kernel heap block for the MTE
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *  We do:
+ *
+ *
+ * @status
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG LDRCALL   fakeldrCreateMte(struct e32_exe *pe32, ldrlv_t *plv)
+{
+    KLOGENTRY2("ULONG LDRCALL","struct e32_exe * pe32, ldrlv_t * plv", pe32, plv);
+    ULONG   rc;
+    PMTE    pMte;
+    PSMTE   pSMte;
+    PCHAR   pch;
+
+    printf("fakeldrCreateMte:       *entry* pe32 = %p, plv = %d\n",
+           pe32, plv);
+
+    /*
+     * Allocate mte and smte.
+     * The MTE has an array of mte pointers at the end for imported modules + 1.
+     * The SMTE has the fullpath filename, loader section and fixup section.
+     */
+    pMte = malloc(sizeof(MTE) + sizeof(PMTE) + sizeof(PMTE)*pe32->e32_impmodcnt);
+    if (pMte == NULL)
+    {
+        rc = ERROR_NOT_ENOUGH_MEMORY;
+        goto createmte_exit;
+    }
+
+    plv->lv_csmte = sizeof(SMTE) + 260 + pe32->e32_ldrsize + pe32->e32_fixupsize;
+    pSMte = malloc(plv->lv_csmte);
+    if (pSMte == NULL)
+    {
+        rc = ERROR_NOT_ENOUGH_MEMORY;
+        goto createmte_exit;
+    }
+    pch = (PCHAR)(PVOID)pSMte + sizeof(SMTE) + 260;
+
+
+    /*
+     * Initialize the MTE.
+     */
+    pMte->mte_flags2    = MTEFORMATLX;
+    pMte->mte_handle    = 20;
+    pMte->mte_swapmte   = pSMte;
+    pMte->mte_link      = NULL;
+    pMte->mte_flags1    = pe32->e32_mflags;
+    pMte->mte_impmodcnt = pe32->e32_impmodcnt;
+    pMte->mte_sfn       = plv->lv_sfn;
+    pMte->mte_usecnt    = 0;
+    pMte->mte_modname[0]= '\0';
+
+    /*
+     * Initialize the SMTE.
+     */
+    pSMte->smte_mpages = pe32->e32_mpages;
+    /*- magic,border,worder,level,cpu,os,ver,mflags */
+    pSMte->smte_mpages      = pe32->e32_mpages;        /* 00  Module # pages */
+    pSMte->smte_startobj    = pe32->e32_startobj;      /* 04  Object # for instruction */
+    pSMte->smte_eip         = pe32->e32_eip;           /* 08  Extended instruction pointer */
+    pSMte->smte_stackobj    = pe32->e32_stackobj;      /* 0c  Object # for stack pointer */
+    pSMte->smte_esp         = pe32->e32_esp;           /* 10  Extended stack pointer */
+        /*- pagesize*/
+    pSMte->smte_pageshift   = pe32->e32_pageshift;     /* 14  Page alignment shift in .EXE */
+    pSMte->smte_fixupsize   = pe32->e32_fixupsize;     /* 18  Fixup section size */
+        /*- fixupsum,ldrsize,ldrsum*/
+    pSMte->smte_objtab      = (POTE)pe32->e32_objtab;  /* 1c  Object table offset - POINTER */
+    pSMte->smte_objcnt      = pe32->e32_objcnt;        /* 20  Number of objects in module */
+    pSMte->smte_objmap      = pe32->e32_objmap;        /* 24  Object page map offset - POINTER */
+    pSMte->smte_itermap     = pe32->e32_itermap;       /* 28  Object iterated data map offset */
+    pSMte->smte_rsrctab     = pe32->e32_rsrctab;       /* 2c  Offset of Resource Table */
+    pSMte->smte_rsrccnt     = pe32->e32_rsrccnt;       /* 30  Number of resource entries */
+    pSMte->smte_restab      = pe32->e32_restab;        /* 34  Offset of resident name table - POINTER */
+    pSMte->smte_enttab      = pe32->e32_enttab;        /* 38  Offset of Entry Table - POINTER */
+    pSMte->smte_fpagetab    = pe32->e32_fpagetab;      /* 3c  Offset of Fixup Page Table - POINTER */
+    pSMte->smte_frectab     = pe32->e32_frectab;       /* 40  Offset of Fixup Record Table - POINTER */
+    pSMte->smte_impmod      = pe32->e32_impmod;        /* 44  Offset of Import Module Name Table - POINTER */
+        /*- impmodcnt*/
+    pSMte->smte_impproc     = pe32->e32_impproc;       /* 48  Offset of Imp Procedure Name Tab - POINTER */
+        /*- pagesum*/
+    pSMte->smte_datapage    = pe32->e32_datapage;      /* 4c  Offset of Enumerated Data Pages */
+        /*- preload*/
+    pSMte->smte_nrestab     = pe32->e32_nrestab;       /* 50  Offset of Non-resident Names Table */
+    pSMte->smte_cbnrestab   = pe32->e32_cbnrestab;     /* 54  Size of Non-resident Name Table */
+        /*- nressum*/
+    pSMte->smte_autods      = pe32->e32_autodata;      /* 58  Object # for automatic data object */
+    pSMte->smte_debuginfo   = pe32->e32_debuginfo;     /* 5c  Offset of the debugging info */
+    pSMte->smte_debuglen    = pe32->e32_debuglen;      /* 60  The len of the debug info in */
+        /*- instpreload,instdemand*/
+    pSMte->smte_heapsize    = pe32->e32_heapsize;      /* 64  use for converted 16-bit modules */
+        /*- res3*/
+    /* extra */
+    pSMte->smte_path        = 0;                       /* 68  full pathname - POINTER */
+    pSMte->smte_semcount    = 0;                       /* 6c  Count of threads waiting on MTE semaphore. 0 => semaphore is free */
+    pSMte->smte_semowner    = 0;                       /* 6e  Slot number of the owner of MTE semahore */
+    pSMte->smte_pfilecache  = 0;                       /* 70  Pointer to file cache for Dos32CacheModule */
+    pSMte->smte_stacksize   = 0;                       /* 74  Thread 1 Stack size from the exe header */
+    pSMte->smte_alignshift  = 0;                       /* 78  use for converted 16-bit modules */
+    pSMte->smte_NEexpver    = 0;                       /* 7a  expver from NE header */
+    pSMte->smte_pathlen     = 0;                       /* 7c  length of full pathname */
+    pSMte->smte_NEexetype   = 0;                       /* 7e  exetype from NE header */
+    pSMte->smte_csegpack    = 0;                       /* 80  count of segs to pack */
+
+    /*
+     * Copy filename (from where?)
+     */
+    pSMte->smte_path        = (PCHAR)(PVOID)pSMte + sizeof(SMTE);
+    pSMte->smte_pathlen     = 0;
+    memcpy(pSMte->smte_path, "", pSMte->smte_pathlen);
+
+
+    /*
+     * Read loader and fixup sections.
+     */
+    rc = fakeldrRead(plv->lv_sfn,
+                     (ULONG)pSMte->smte_objtab + plv->lv_new_exe_off,
+                     pch,
+                     0,
+                     pe32->e32_ldrsize + pe32->e32_fixupsize,
+                     NULL);
+    if (rc)
+    {
+        goto createmte_exit;
+    }
+
+    /*
+     * Set pointers.
+     */
+    pSMte->smte_objtab = (POTE)(PVOID)pch;
+    rc = fakeldrMTEValidatePtrs(pSMte,
+                                (ULONG)pch + plv->lv_csmte,
+                                (ULONG)pch - (ULONG)pe32->e32_objtab);
+    if (rc)
+    {
+        goto createmte_exit;
+    }
+
+    /*
+     * Set mte pointer in plv.
+     * Set hobmte in plv.
+     */
+    plv->lv_pmte = pMte;
+    plv->lv_hobmte = pMte->mte_handle;
+
+    /*
+     * Fix flags...
+     */
+    pMte->mte_flags1 |= plv->lv_class;
+
+createmte_exit:
+    printf("fakeldrCreateMte:       *exit*  pe32 = %p, plv = %d, rc = %d\n",
+           pe32, plv, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+
+/**
+ * Fake ldrLoadImports - loads the import modules for the given module (pmte).
+ * @returns   OS2 error code.
+ * @param     pmte  Pointer to mte to load imports for.
+ * @sketch
+ *  OS/2 kernel seems to do:
+ *      Loop thru the importe module table (reverse order for NE files)
+ *          IF VDD module THEN
+ *              Uppercase the name.
+ *              try find it using ldrFindModule
+ *              fail if error, not found, not VDDMOD/MVDMMOD.
+ *              Add to array of imported module.
+ *          ENDIF
+ *          IF Not found OR !MTEGETMTEDONE THEN
+ *              call ldrGetMte to load the module (class global).
+ *              fail if error.
+ *              set MTEGETMTEDONE
+ *              Add to array of imported module.
+ *          ENDIF
+ *          IF DOSMOD and !ldrMiniFileIOFlag THEN
+ *              Replace module pointer with doscall1 pmte.
+ *          ENDIF
+ *      ENDLOOP
+ *
+ *  We do:
+ *      Parameter validation.
+ *      Loop thru the imported module table issuing fakeldrGetMte on each entry.
+ *      'DOSCALLS' is ignored.
+ *
+ * @status
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG LDRCALL   fakeldrLoadImports(PMTE pmte)
+{
+    KLOGENTRY1("ULONG LDRCALL","PMTE pmte", pmte);
+    int     i;                          /* Module index. */
+    PSZ     psz;                        /* Module name pointer. (really pointer to pascal strings...) */
+    PPMTE   papmte;                     /* Pointer to array of PMTEs for imported modules. */
+    APIRET  rc;
+
+    printf("fakeldrLoadImport:      *entry* pmte = %p, pmte->mte_impmodcnt = %d\n",
+           pmte, pmte->mte_impmodcnt);
+
+    /*
+     * Parameter validation.
+     */
+    if (pmte == NULL)
+    {
+        kprintf(("fakeldrLoadImports: !ASSERTION! pmte == NULL\n"));
+        KLOGEXIT(ERROR_INVALID_PARAMETER);
+        return ERROR_INVALID_PARAMETER;
+    }
+    if (pmte->mte_swapmte == NULL)
+    {
+        kprintf(("fakeldrLoadImports: !ASSERTION! pmte->mte_swapmte == NULL\n"));
+        KLOGEXIT(ERROR_INVALID_PARAMETER);
+        return ERROR_INVALID_PARAMETER;
+    }
+
+    /*
+     * Any imported modules?
+     */
+    if (pmte->mte_impmodcnt == 0)
+    {
+        printf("fakeldrLoadImport:      *exit*  pmte = %p, rc = %d\n",
+               pmte, rc);
+        KLOGEXIT(NO_ERROR);
+        return NO_ERROR;
+    }
+
+    /* We have reserved space for imported module pointers after the mte. */
+    papmte = (PPMTE)((unsigned)pmte  + sizeof(MTE));
+
+    /*
+     * Process the imported module table.
+     */
+    for (i = 0, rc = NO_ERROR, psz = (PSZ)pmte->mte_swapmte->smte_impmod;
+         i < pmte->mte_impmodcnt && rc == NO_ERROR;
+         i++, psz += 1 + *psz)
+    {
+        if (*psz == 8 && !strnicmp(psz+1, "DOSCALLS", 8))
+            continue;
+
+        rc = fakeldrGetMte(psz + 1, *psz, LVTYPE_DLL, CLASS_GLOBAL, &papmte[i]);
+    }
+
+    printf("fakeldrLoadImport:      *exit*  pmte = %p, rc = %d\n",
+           pmte, rc);
+
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * Checks if the internal name (first name in the resident nametable) matches
+ * the filename.
+ * @returns     NO_ERROR on success (the name matched).
+ *              ERROR_INVALID_NAME if mismatch.
+ * @param       pMTE    Pointer to the MTE of the module to check.<br>
+ *                      Assumes! that the filename for this module is present in ldrpFileNameBuf.
+ */
+ULONG LDRCALL   fakeldrCheckInternalName(PMTE pMTE)
+{
+    KLOGENTRY1("ULONG LDRCALL","PMTE pMTE", pMTE);
+    PCHAR   pachName;                   /* Pointer to the name part of pachFilename. */
+    int     cchName;                    /* Length of the name part of pachFilename.
+                                         * Includes extention if extention is not .DLL.
+                                         * this is the length relative to pachName used to match the internal name. */
+    PCHAR   pachExt;                    /* Pointer to the extention part of pachFilename. (not dot!) */
+    int     cchExt;                     /* Length of the extention part of pachFilename. (not dot!) */
+
+
+    /* Return successfully if not library module. */
+    if (!(pMTE->mte_flags1 & LIBRARYMOD))
+    {
+        KLOGEXIT(NO_ERROR);
+        return NO_ERROR;
+    }
+
+    /* Uppercase and parse filename in ldrpFileNameBuf */
+    cchName = (int)fakeldrGetFileName(ldrpFileNameBuf, (PCHAR*)SSToDS(&pachName), (PCHAR*)SSToDS(&pachExt));
+    cchExt = (pachExt) ? strlen(pachExt) : 0;
+    ldrUCaseString(pachName, cchName + cchExt + 1);
+
+    /* Compare the internal name with the filename and return accordingly. */
+    KLOGEXIT((    cchName <= 8
+            &&  !memcmp(pMTE->mte_modname, pachName, cchName)
+            &&  (cchName == 8 || pMTE->mte_modname[cchName] == '\0')
+            )
+            ? NO_ERROR
+            : ERROR_INVALID_NAME);
+    return (    cchName <= 8
+            &&  !memcmp(pMTE->mte_modname, pachName, cchName)
+            &&  (cchName == 8 || pMTE->mte_modname[cchName] == '\0')
+            )
+            ? NO_ERROR
+            : ERROR_INVALID_NAME;
+}
+
+
+/**
+ * Translates a relative filename to a full qualified filename.
+ * @returns NO_ERROR on success.
+ *          Errorcode on error.
+ * @param   pszFilename     Pointer to nullterminated filename.
+ */
+ULONG LDRCALL   fakeldrTransPath(PSZ pszFilename)
+{
+    KLOGENTRY1("ULONG LDRCALL","PSZ pszFilename", pszFilename);
+    KLOGEXIT(fakeIOSftTransPath(pszFilename));
+    return  fakeIOSftTransPath(pszFilename);
+}
+
+
+/**
+ * Parses a filename to find the name and extention.
+ * @returns Length of the filename without the extention.
+ * @param   pachFilename    Pointer to filename to parse - must have path!
+ * @param   ppachName       Pointer to pointer which should hold the name pointer upon successfull return.
+ * @param   ppachExt        Pointer to pointer which should hold the extention pointer upon successfull return.
+ */
+ULONG LDRCALL   fakeldrGetFileName(PSZ pszFilename, PCHAR *ppchName, PCHAR *ppchExt)
+{
+    KLOGENTRY3("ULONG LDRCALL","PSZ pszFilename, PCHAR * ppchName, PCHAR * ppchExt", pszFilename, ppchName, ppchExt);
+    int     cchName;
+    PSZ     pchName;
+    PSZ     pchExt = NULL;
+
+    while (*pszFilename)
+    {
+        if (*pszFilename == '\\' || *pszFilename == '/')
+            pchName = pszFilename + 1;
+        else if (*pszFilename == '.')
+            pchExt = pszFilename + 1;
+        pszFilename++;
+    }
+
+    cchName = (pchExt <= pchName) ? strlen(pchName) : pchExt - pchName - 1;
+    *ppchExt = pchExt;
+    *ppchName = pchName;
+
+    KLOGEXIT(cchName);
+    return cchName;
+}
+
+
+/**
+ * Uppercases the string.
+ * @param     pachString    String to uppercase.
+ * @param     cchString     Length of string.
+ * @sketch    Loop thru the string converting all english letters to uppercase.
+ * @status    partially implemented.
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark    This is probably written in assembly and does DBCS checks...
+ */
+VOID LDRCALL    fakeldrUCaseString(PCHAR pachString, unsigned cchString)
+{
+    KLOGENTRY2("VOID LDRCALL","PCHAR pachString, unsigned cchString", pachString, cchString);
+    printf("fakeldrUCaseString:             pachString = %.*s, cchString = %#8x\n",
+           cchString, pachString, cchString);
+
+    while (cchString-- != 0)
+    {
+        if (*pachString >= 'a' && *pachString <= 'z')
+            *pachString -= ('a' - 'A');
+        pachString++;
+    }
+    KLOGEXITVOID();
+}
+
+
+
+
+/**
+ * Checks and updates the members of the swap-mte which is to be
+ * pointers into the loader/fixup section. An array, validatetbl, contains
+ * the offsets of the smte pointers.
+ *
+ * @returns     NO_ERROR    on success.
+ *              ERROR_BAD_EXE_FORMAT on error.
+ * @param       psmte
+ * @param       ulMaxAddr   Maximum (exclusive) address.
+ * @param       off         Offset delta to add to the pointer members (which
+ *                          are all offsets relative to the start of the new
+ *                          header) to make them pointers.
+ * @sketch
+ *  Loop thru the validatetbl and update each field (which isn't null) by adding
+ *  the off value, and validate that the pointer is ok.
+ * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ * @remark
+ */
+ULONG LDRCALL   fakeldrMTEValidatePtrs(PSMTE psmte, ULONG ulMaxAddr, ULONG off)
+{
+    KLOGENTRY3("ULONG LDRCALL","PSMTE psmte, ULONG ulMaxAddr, ULONG off", psmte, ulMaxAddr, off);
+    int     i;
+
+    printf("fakeldrMTEValidatePtrs: *entry* psmte = %p, ulMaxAddr = %p, off = %p\n",
+           psmte, ulMaxAddr, off);
+
+    for (i = 0; validatetbl[i] != 0xDEAD; i++)
+    {
+        PULONG  pul = (PULONG)(PVOID)((PCHAR)(PVOID)psmte + validatetbl[i]);
+        if (*pul != 0UL)
+        {
+            *pul += off;
+            if (*pul >= ulMaxAddr)
+            {
+                printf("fakeldrMTEValidatePtrs: *exit*  psmte = %p, ulMaxAddr = %p, off = %p, rc = %d\n",
+                       psmte, ulMaxAddr, off, ERROR_BAD_EXE_FORMAT);
+                KLOGEXIT(ERROR_BAD_EXE_FORMAT);
+                return ERROR_BAD_EXE_FORMAT;
+            }
+        }
+    }
+
+    printf("fakeldrMTEValidatePtrs: *exit*  psmte = %p, ulMaxAddr = %p, off = %p, rc = %d\n",
+           psmte, ulMaxAddr, off, NO_ERROR);
+    KLOGEXIT(NO_ERROR);
+    return NO_ERROR;
+}
+
+
+PMTE KRNLCALL fakeldrASMpMTEFromHandle(HMTE  hMTE)
+{
+    KLOGENTRY1("PMTE KRNLCALL","HMTE hMTE", hMTE);
+    PMTE pMte = (PMTE)hMTE;
+
+    pMte += 10; //just do something!
+
+    KLOGEXIT(NULL);
+    return NULL;
+}
+
+ULONG LDRCALL   fakeldrFindModule(PCHAR pachFilename, USHORT cchFilename, USHORT usClass, PPMTE ppMTE)
+{
+    KLOGENTRY4("ULONG LDRCALL","PCHAR pachFilename, USHORT cchFilename, USHORT usClass, PPMTE ppMTE", pachFilename, cchFilename, usClass, ppMTE);
+    APIRET rc = NO_ERROR;
+    usClass = usClass;
+    cchFilename = cchFilename;
+    pachFilename = pachFilename;
+    *ppMTE = NULL;
+    KLOGEXIT(rc);
+    return rc;
+}
+
+
+/**
+ * Gets the path (name with fully qualified path) from a SFN.
+ * @returns     Pointer to the path of hFile.
+ * @param       hFile   SFN filehandle.
+ */
+PSZ SECCALL fakeSecPathFromSFN(SFN hFile)
+{
+    KLOGENTRY1("PSZ SECCALL","SFN hFile", hFile);
+    BOOL    f32Stack = ((int)&hFile > 0x10000);
+
+    if (!f32Stack) ThunkStack16To32();
+
+
+    if (!f32Stack) ThunkStack32To16();
+
+    printf("fakeSecPathFromSFN:                    - not implemented - hFile = 0x%04x\n", hFile);
+
+    KLOGEXIT(NULL);
+    return NULL;
+}
+
+/**
+ * PID to PTDA pointer.
+ * @returns     OS/2 return code.
+ * @param       pid     Process Identifier.
+ * @param       ppPTDA  Pointer to the PTDA-pointer variabel which is to receive
+ *                      the PTDA pointer on successful return.
+ */
+ULONG KRNLCALL  fakeTKPidToPTDA(PID pid, PPPTDA ppPTDA)
+{
+    KLOGENTRY2("ULONG KRNLCALL","PID pid, PPPTDA ppPTDA", pid, ppPTDA);
+    DUMMY();
+    printf("fakeTKPidToPTDA:                       - not implemented - pid = 0x%04x, ppPTDA=%p\n", pid, ppPTDA);
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+/**
+ *
+ * @returns     OS/2 return code.
+ * @param       pid     Process Identifier.
+ * @param       ppPTDA  Pointer to the PTDA-pointer variabel which is to receive
+ *                      the PTDA pointer on successful return.
+ */
+ULONG KRNLCALL   fakeTKScanTasks(ULONG flFlags, ULONG id, PTKSCANTASKWORKER pfnWorker, ULONG ulArg)
+{
+    KLOGENTRY4("ULONG KRNLCALL","ULONG flFlags, ULONG id, PTKSCANTASKWORKER pfnWorker, ULONG ulArg", flFlags, id, pfnWorker, ulArg);
+    DUMMY();
+    printf("fakeTKScanTasks:                       - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+/**
+ * Force a thread to be made ready.
+ * @param   flFlag  Which flag(s?) to set.
+ * @param   pTCB    Pointer to the thread control block of the thread to be forced.
+ */
+void KRNLCALL fakeTKForceThread(ULONG flFlag, PTCB pTCB)
+{
+    KLOGENTRY2("void KRNLCALL","ULONG flFlag, PTCB pTCB", flFlag, pTCB);
+    DUMMY();
+    printf("fakeTKForceThread:                     - not implemented\n");
+    KLOGEXITVOID();
+}
+
+/**
+ * Set force flag on a task.
+ * @param   flFlag  Which flag(s?) to set.
+ * @param   pPTDA   Pointer to the PTDA of the task to be processed.
+ * @param   fForce  FALSE   Just set the flag on all threads.
+ *                  TRUE    Force all threads ready by calling TKForceThread.
+ */
+void KRNLCALL  fakeTKForceTask(ULONG flFlag, PPTDA pPTDA, BOOL fForce)
+{
+    KLOGENTRY3("void KRNLCALL","ULONG flFlag, PPTDA pPTDA, BOOL fForce", flFlag, pPTDA, fForce);
+    DUMMY();
+    printf("fakeTKForceTask:                       - not implemented\n");
+    KLOGEXITVOID();
+}
+
+/**
+ * Get priotity of a thread.
+ * @returns Thread priority.
+ * @param   pTCB    pointer to the TCB of the thread in question.
+ */
+ULONG KRNLCALL fakeTKGetPriority(PTCB pTCB)
+{
+    KLOGENTRY1("ULONG KRNLCALL","PTCB pTCB", pTCB);
+    DUMMY();
+    printf("fakeTKGetPriority:                     - not implemented\n");
+    KLOGEXIT(-1);
+    return -1;
+}
+
+/**
+ * Make current thread sleep.
+ * @returns NO_ERROR on success.
+ *          ERROR_INTERRUPT if a signal is forced on the thread.
+ *          ERROR_TIMEOUT if we timeout.
+ * @param   ulSleepId   32-bit sleep id which TKWakeup will be called with.
+ * @param   ulTimeout   Number of milliseconds to sleep. (0 is not yield)
+ *                      -1 means forever or till wakeup.
+ * @param   fUnint      TRUE:  may not interrupt sleep.
+ *                      FALSE: may interrupt sleep.
+ * @param   flSleepType ???
+ */
+ULONG KRNLCALL fakeTKSleep(ULONG ulSleepId, ULONG ulTimeout, ULONG fUnInterruptable, ULONG flWakeupType)
+{
+    KLOGENTRY4("ULONG KRNLCALL","ULONG ulSleepId, ULONG ulTimeout, ULONG fUnInterruptable, ULONG flWakeupType", ulSleepId, ulTimeout, fUnInterruptable, flWakeupType);
+    DUMMY();
+    printf("fakeTKSleep:                           - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+/**
+ * Wakeup sleeping thread(s).
+ * @returns NO_ERROR on succes.
+ *          Appropriate error code on failure.
+ * @param   ulSleepId       32-bit sleep id which threads are sleeping on.
+ * @param   flWakeUpType    How/what to wakeup.
+ * @param   pcWakedUp       Pointer to variable which is to hold the count of
+ *                          thread waked up.
+ */
+ULONG KRNLCALL fakeTKWakeup(ULONG ulSleepId, ULONG flWakeupType, PULONG cWakedUp)
+{
+    KLOGENTRY3("ULONG KRNLCALL","ULONG ulSleepId, ULONG flWakeupType, PULONG cWakedUp", ulSleepId, flWakeupType, cWakedUp);
+    DUMMY();
+    printf("fakeTKWakeup:                          - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+
+/**
+ * Wake up a single thread.
+ * @returns NO_ERROR on succes.
+ *          Appropriate error code on failure.
+ * @param   pTCB    Pointer to the TCB of the thread to be waken.
+ */
+ULONG KRNLCALL fakeTKWakeThread(PTCB pTCB)
+{
+    KLOGENTRY1("ULONG KRNLCALL","PTCB pTCB", pTCB);
+    DUMMY();
+    printf("fakeTKWakeThread:                      - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+/**
+ * See which thread will be Wakeup.
+ * @returns Pointer to TCB of the thread on success.
+ *          NULL on failure or no threads.
+ * @param   ulSleepId       32-bit sleep id which threads are sleeping on.
+ * @param   flWakeUpType    How/what to wakeup.
+ */
+PTCB  KRNLCALL fakeTKQueryWakeup(ULONG ulSleepId, ULONG flWakeupType)
+{
+    KLOGENTRY2("PTCB KRNLCALL","ULONG ulSleepId, ULONG flWakeupType", ulSleepId, flWakeupType);
+    DUMMY();
+    printf("fakeTKQueryWakeup:                     - not implemented\n");
+    KLOGEXIT(NULL);
+    return NULL;
+}
+
+/**
+ * Returns the number of bytes of physical memory available.
+ */
+ULONG KRNLCALL fakePGPhysAvail(void)
+{
+    KLOGENTRY0("ULONG KRNLCALL");
+    DUMMY();
+    printf("fakePGPhysAvail                        - returns 0x234563\n");
+    KLOGEXIT(0x234563);
+    return 0x234563;
+}
+
+
+/**
+ * Returns the number of pageframes currently in use.
+ */
+ULONG KRNLCALL fakePGPhysPresent(void)
+{
+    KLOGENTRY0("ULONG KRNLCALL");
+    DUMMY();
+    printf("fakePGPhysPresent                      - returns 0x123534\n");
+    KLOGEXIT(0x123534);
+    return 0x123534;
+}
+
+
+/**
+ * This function seems to find the top of the private arena.
+ * And for high arena kernels (AURORA and W3SMP?) it is modified
+ * to calc the top of the high private arena, given flFlag = 4.
+ * --
+ * This function is really intented for resizing / recaling the size of
+ * the shared arena(s). But, it's useful for finding the highest used
+ * private arena(s).
+ * @param   flFlags             VMRSBF_* flags.
+ * @param   pulSentinelAddress  Pointer to return variable (optional).
+ */
+VOID    KRNLCALL fakevmRecalcShrBound(
+    ULONG   flFlags,
+    PULONG  pulSentinelAddress)
+{
+    KLOGENTRY2("VOID KRNLCALL","ULONG flFlags, PULONG pulSentinelAddress", flFlags, pulSentinelAddress);
+    ULONG ulRet;
+    DUMMY();
+
+    if ((flFlags & 6) == 0)
+    {   /* shared  tiled memory */
+        ulRet = 128*1024*1024;
+    }
+    else
+    {
+        ulRet = 0x2c000000;
+        if (_usFakeVerMinor < 45)        /* bad emulation for Warp 3 SMP - FIXME */
+            printf("fakePGPhysPresent                      - error: bad flags for non-highmem OS/2 versionn");
+    }
+
+    if (pulSentinelAddress)
+        *pulSentinelAddress = ulRet;
+
+    printf("fakePGPhysPresent                      - returns %x - flFlags=0x%02x, pulSentinelAddress=0x%08x\n",
+           ulRet, flFlags, pulSentinelAddress);
+
+    KLOGEXITVOID();
+}
+
+
+/**
+ * Resolves the ordinal number of an name export.
+ * @returns OS2 return code. (I.e. ON_ERROR on success)
+ * @param   pMTE            Pointer to the module table entry for the
+ *                          module.
+ * @param   pszExportName   Name to resolve. This is case sensitive.
+ * @param   pusOrdinal      Pointer to variable which on success will hold
+ *                          the ordinal value found for the name export.
+ */
+ULONG LDRCALL   fakeldrGetOrdNum(PMTE pMTE, PSZ pszExportName, PUSHORT pusOrdinal)
+{
+    KLOGENTRY3("ULONG LDRCALL","PMTE pMTE, PSZ pszExportName, PUSHORT pusOrdinal", pMTE, pszExportName, pusOrdinal);
+    DUMMY();
+    printf("fakeldrGetOrdNum:                      - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+
+/**
+ * Checks if a module was loaded using DosLoadModule.
+ * This is called from LDRGetProcAddr and LDRFreeModule.
+ * @returns NO_ERROR if the module was LoadModuled or executable.
+ *          ERROR_INVALID_HANDLE if not LoadModuled.
+ * @param   hmte    MTE handle.
+ * @param   pptda   Pointer to the PTDA of the process calling. (current)
+ * @param   pcUsage Pointer to usage variable. (output)
+ *                  The usage count is returned.
+ * @sketch
+ */
+ULONG LDRCALL   fakeldrWasLoadModuled(HMTE hmte, PPTDA pptda, PULONG pcUsage)
+{
+    KLOGENTRY3("ULONG LDRCALL","HMTE hmte, PPTDA pptda, PULONG pcUsage", hmte, pptda, pcUsage);
+    DUMMY();
+    printf("fakeldrWasLoadModuled:                 - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+/**
+ * LDRGetProcAddr gets address and proctype for a entry point to a module.
+ * @returns NO_ERROR if the module was LoadModuled.
+ *          ERROR_INVALID_HANDLE if not LoadModuled.
+ * @param   hmte            Handle of module.
+ * @param   ulOrdinal       Procedure ordinal.
+ * @param   pszName         Pointer to procedure name.
+ *                          NULL is allowed. Ignored if ulOrdinal is not zero.
+ * @param   pulAddress      Pointer to address variable. (output)
+ * @param   fFlat           TRUE if a flat 0:32 address is to be returned.
+ *                          FALSE if a far 16:16 address is to be returned.
+ * @param   pulProcType     Pointer to procedure type variable. (output)
+ *                          NULL is allowed. (DosQueryProcAddr uses NULL)
+ *                          In user space.
+ * @sketch
+ */
+ULONG LDRCALL fakeLDRGetProcAddr(HMTE hmte, ULONG ulOrdinal, PCSZ pszName, PULONG pulAddress, BOOL fFlat, PULONG pulProcType)
+{
+    KLOGENTRY6("ULONG LDRCALL","HMTE hmte, ULONG ulOrdinal, PCSZ pszName, PULONG pulAddress, BOOL fFlat, PULONG pulProcType", hmte, ulOrdinal, pszName, pulAddress, fFlat, pulProcType);
+    DUMMY();
+    printf("fakeLDRGetProcAddr:                    - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+
+/**
+ * Frees a task.
+ * @param   pPTDA   Pointer to per task data area of the task to be freed.
+ */
+void KRNLCALL fakeLDRFreeTask(PPTDA pPTDA)
+{
+    KLOGENTRY1("void KRNLCALL","PPTDA pPTDA", pPTDA);
+    DUMMY();
+    printf("fakeLDRFreeTask:                       - not implemented\n");
+    KLOGEXITVOID();
+}
+
+/**
+ * Converts 16:32 address to FLAT 32-bits address.
+ * @returns Flat 32-bits address.
+ *          -1 on error.
+ * @param   ulOffset    Offset.
+ * @param   usSel       Selector.
+ */
+PVOID KRNLCALL   fakeSELVirtToLin(ULONG ulOffset, USHORT usSel)
+{
+    KLOGENTRY2("PVOID KRNLCALL","ULONG ulOffset, USHORT usSel", ulOffset, usSel);
+    DUMMY();
+    printf("fakeSELVirtToLin:                      - not implemented\n");
+    KLOGEXIT((void*)-1);
+    return (void*)-1;
+}
+
+/**
+ * Converts selector to linar address.
+ * @returns Flat 32-bits address.
+ *          -1 on error.
+ * @param   usSel       Selector.
+ */
+PVOID KRNLCALL   fakeSELConvertToLinear(USHORT usSel, PPTDA pPTDA)
+{
+    KLOGENTRY2("PVOID KRNLCALL","USHORT usSel, PPTDA pPTDA", usSel, pPTDA);
+    DUMMY();
+    printf("fakeSELConvertToLinear:                - not implemented\n");
+    KLOGEXIT((void*)-1);
+    return (void*)-1;
+}
+
+/**
+ * Converts a 32-bit flat pointer to an selector if possible.
+ * @returns Selector (eax), offset (edx).
+ * @param   pv      Flat 32-bit address.
+ * @param   ulRPL   Requested privilege level of the selector.
+ * @param   hPTDA   PTDA handle. NULLHANDLE means current PTDA.
+ */
+USHORT KRNLCALL  fakeSELConvertToSelector(PVOID pv, ULONG ulRPL, HPTDA hPTDA)
+{
+    KLOGENTRY3("USHORT KRNLCALL","PVOID pv, ULONG ulRPL, HPTDA hPTDA", pv, ulRPL, hPTDA);
+    DUMMY();
+    printf("fakeSELConvertToSelector:              - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
+/**
+ * Allocates a GDT selector.
+ * @returns OS2 return code. (I.e. NO_ERROR on success.)
+ * @param   pusSel  Where to put the selector on successful return.
+ */
+ULONG  KRNLCALL  fakeSELAllocGDT(PUSHORT pusSel)
+{
+    KLOGENTRY1("ULONG KRNLCALL","PUSHORT pusSel", pusSel);
+    DUMMY();
+    printf("fakeSELAllocGDT:                       - not implemented\n");
+    KLOGEXIT(ERROR_NOT_SUPPORTED);
+    return ERROR_NOT_SUPPORTED;
+}
+
Index: trunk/src/win32k/kKrnlLib/src/tstFakeA.asm
===================================================================
--- trunk/src/win32k/kKrnlLib/src/tstFakeA.asm	(revision 8211)
+++ trunk/src/win32k/kKrnlLib/src/tstFakeA.asm	(revision 8211)
@@ -0,0 +1,637 @@
+; $Id: tstFakeA.asm,v 1.1 2002-04-07 22:39:15 bird Exp $
+;
+; Fake assembly imports.
+;
+; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+;
+; Project Odin Software License can be found in LICENSE.TXT
+;
+
+    .386
+
+;
+;   Defined Constants And Macros
+;
+    INCL_BASE EQU 1
+
+;
+;   Include files
+;
+    include devsegdf.inc
+    include devhlp.inc
+    include os2.inc
+    include options.inc
+
+
+;
+;   Exported symbols
+;
+    public fakepTCBCur
+    public fakepPTDACur
+    public fakeptda_start
+    public fakeptda_environ
+    public fakeptda_handle
+    public fakeptda_module
+    public fakeptda_ptdasem
+    public fakeptda_pBeginLIBPATH
+    public fakef_FuStrLenZ
+    public fakef_FuStrLen
+    public fakef_FuBuff
+    public fakeg_tkExecPgm
+    public faketkStartProcess
+    public CalltkExecPgm
+    public _fakeldrOpenPath@20
+    public fakeKMEnterKmodeSEF
+    public fakeKMExitKmodeSEF8
+    public fakeRASRST
+    public fakedh_SendEvent
+    public fakeh_POST_SIGNAL
+    public _exeentry                    ; VAC stuff
+
+
+;
+;   Imported Functions and Variables.
+;
+    extrn tkExecPgmWorker:PROC          ; fake.c
+    extrn _fakeLDRClearSem@0:PROC       ; fake.c
+    extrn _fakeKSEMRequestMutex@8:PROC  ; fake.c
+    extrn _fakeldrOpenPath_old@16:PROC  ; fake.c
+    extrn _fakeldrOpenPath_new@20:PROC  ; fake.c
+    extrn _options:kKLOptions           ; d16globl.c
+    extrn _exestart:FAR                 ; VAC stuff
+
+;
+; Stack segment
+;
+STACK32 segment para stack 'STACK' use32
+    db 1000h dup(?)
+STACK32 ends
+MYSTACKGROUP group STACK32              ; separates the stack from the other data segments.
+
+
+;
+; Prevent exeentry.obj from being linked in.
+; That way we can make our own stack.
+;
+DATA32 segment
+    _exeentry dd 0
+DATA32 ends
+
+
+
+DATA16 segment
+; Fake data in 16-bit segment.
+fakepTCBCur         dd      offset FLAT:fakeTCB
+fakepPTDACur        dd      offset FLAT:fakeptda_start
+
+; PTDA - Only use environ and ExecChild.
+fakeptda_start              LABEL DWORD
+fakeptda_pPTDAParent        dd      0
+fakeptda_pPTDASelf          dd      offset FLAT:fakeptda_start
+fakeptda_pPTDAFirstChild    dd      0
+fakeptda_pPTDAExecChild     dd      offset FLAT:fakeptda_start
+fakeptda_dummy              db  123 dup (0)
+fakeptda_environ            dw      1   ; 1 is the hardcoded HOB of the kKrnlLibtst.exe's environment.
+fakeptda_ptdasem            db  20  dup (0) ; PTDA semaphore - Intra-Process serialisation mutex KSEM (sg244640).
+fakeptda_handle             dw      2   ; 2 is the hardcoded HPTDA of the current process.
+fakeptda_module             dw      1   ; 1 is the hardcoded HMTE of the current executable module.
+fakeptda_pBeginLIBPATH      dd      0   ; BEGINLIBPATH not implemented.
+                            dd      0   ; ENDLIBPATH not implemented.
+
+
+; TCB - just needs some dummy data for reading and writing to the TCBFailErr.
+fakeTCB                     db 220h dup (0CCh)
+
+DATA16 ENDS
+
+
+CODE16 SEGMENT
+
+
+; Scans strings until empy-string is reached.
+; input:  bx:di
+; uses:   nearly all (save bp)
+; return: cx size - CF clear
+;         ax error- CF set
+fakef_FuStrLenZ PROC FAR
+    push    2                           ; required by all 16-bit far procedures.
+    push    2                           ; dummy code.
+    push    2                           ; dummy code.
+    push    2                           ; dummy code.
+    push    es
+
+    mov     dx, di                      ; save di pointer.
+    cmp     bx, 7                       ; check if NULL ptr.
+    jle     ffslz_badselector
+
+    mov     es, bx                      ; es:di -> string
+    mov     cx, di
+    not     cx                          ; maximum length is to segment end.
+    xor     ax, ax                      ; test against zero (scasb uses al to cmp with).
+
+ffslz_loop:
+    repnz scasb
+    jnz     ffslz_no_term               ; jump if cx = 0
+    dec     cx                          ; check if next is NULL too
+    scasb
+    jnz     ffslz_loop
+
+ffslz_retok:
+    mov     cx, di
+    sub     cx, dx                      ; cx <- size (end ptr - start ptr)
+    pop     es
+    add     sp, 8
+    clc
+    db      66h
+    retf
+
+ffslz_badselector:
+    mov     ax, ERROR_INVALID_SELECTOR
+    jmp     ffslz_reterr
+
+;ffslz_invalidptr:
+;    mov     ax, ERROR_INVALID_ACCESS
+;    jmp     ffslz_reterr
+
+ffslz_no_term:
+    mov     ax, ERROR_TERMINATOR_NOT_FOUND
+ffslz_reterr:
+    pop     es
+    add     sp, 8
+    stc
+    db      66h
+    retf
+fakef_FuStrLenZ ENDP
+
+
+;
+; Stringlength - Fake
+; input:  bx:di
+; uses:   nearly all (save bp)
+; return: cx size - CF clear
+;         ax error- CF set
+fakef_FuStrLen PROC FAR
+    push    2                           ; required by all 16-bit far procedures.
+    push    2                           ; dummy code.
+    push    2                           ; dummy code.
+    push    2                           ; dummy code.
+    push    es
+
+    mov     dx, di                      ; save di pointer.
+    cmp     bx, 7                       ; check if NULL ptr.
+    jle     ffslz_badselector
+
+    mov     es, bx                      ; es:di -> string
+    mov     cx, di
+    not     cx                          ; maximum length is to segment end.
+    xor     ax, ax                      ; test against zero (scasb uses al to cmp with).
+
+    repnz scasb
+    jnz     ffslz_no_term               ; jump if cx = 0
+
+ffslz_retok:
+    mov     cx, di
+    sub     cx, dx                      ; cx <- size (end ptr - start ptr)
+    pop     es
+    add     sp, 8
+    clc
+    db      66h
+    retf
+
+ffslz_badselector:
+    mov     ax, ERROR_INVALID_SELECTOR
+    jmp     ffslz_reterr
+
+;ffslz_invalidptr:
+;    mov     ax, ERROR_INVALID_ACCESS
+;    jmp     ffslz_reterr
+
+ffslz_no_term:
+    mov     ax, ERROR_TERMINATOR_NOT_FOUND
+ffslz_reterr:
+    pop     es
+    add     sp, 8
+    stc
+    db      66h
+    retf
+fakef_FuStrLen ENDP
+
+
+;memcpy
+;input:  bx:si pointer to source
+;        es:di pointer to target
+;        cx    count of bytes to copy
+;uses:   nearly all (save bp), es, ds
+;return: success CF clear
+;        failure CF set
+fakef_FuBuff PROC FAR
+    push    2                           ; required by all 16-bit far procedures.
+    push    2                           ; dummy code.
+    push    2                           ; dummy code.
+    push    2                           ; dummy code.
+    push    es
+
+    cmp     bx, 7                       ; check if NULL ptr.
+    jle     ffslz_badselector
+    mov     ax, es
+    cmp     bx, 7                       ; check if NULL ptr.
+    jle     ffslz_badselector
+
+    mov     ds, bx                      ; ds:si -> string
+    mov     ax, di
+    not     ax
+    cmp     ax, cx                      ; crosses segment boundrary...
+    jb      ffslz_invalidptr
+    mov     ax, si
+    not     ax
+    cmp     ax, cx                      ; crosses segment boundrary...
+    jb      ffslz_invalidptr
+
+;    movzx   esi, si
+;    movzx   edi, di
+;    movzx   ecx, cx
+;    db      66h                         ; force it use extended registers.
+    rep movsb
+
+ffslz_retok:
+    xor     ax, ax
+    mov     cx, di
+    sub     cx, dx                      ; cx <- size (end ptr - start ptr)
+    pop     es
+    add     sp, 8
+    clc
+    db      66h
+    retf
+
+ffslz_badselector:
+    mov     ax, ERROR_INVALID_SELECTOR
+    jmp     ffslz_reterr
+
+ffslz_invalidptr:
+    int     3
+    mov     ax, ERROR_INVALID_ACCESS
+    jmp     ffslz_reterr
+
+ffslz_no_term:
+    mov     ax, ERROR_TERMINATOR_NOT_FOUND
+ffslz_reterr:
+    pop     es
+    add     sp, 8
+    stc
+    db      66h
+    retf
+fakef_FuBuff ENDP
+
+
+;;
+; RASRST faker.
+; @status   stupid stub.
+fakeRASRST proc near
+    mov     ax, ds
+    mov     ax, ds
+    mov     ax, ds
+    mov     ax, ds
+    int     3
+fakeRASRST endp
+
+
+;;
+; dh_SendEvent faker.
+; @status   stupid stub.
+fakedh_SendEvent proc near
+    mov     ax, ds
+    mov     ax, ds
+    mov     ax, ds
+    mov     ax, ds
+    int     3
+fakedh_SendEvent endp
+
+
+;;
+; POST_SIGNAL faker
+fakeh_POST_SIGNAL proc near
+    ; dummy prolog.
+    mov     ax, ds
+    mov     ax, ds
+    mov     ax, ds
+    mov     ax, ds
+    int     3
+fakeh_POST_SIGNAL endp
+
+
+CODE16 ends
+
+
+
+CODE32 segment
+;;
+; Faker of which simply clears the loader semaphore.
+; @cproto    none! (void _Optlink   faketkStartProcess(void))
+; @returns
+; @param
+; @uses
+; @equiv
+; @time
+; @sketch
+; @status
+; @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+; @remark
+faketkStartProcess PROC NEAR
+    push    ebp
+    mov     ebp, esp
+
+    push    ebx
+    push    ecx
+
+    call    _fakeLDRClearSem@0
+
+    pop     ecx
+    pop     ebx
+
+    xor     eax, eax
+    leave
+    ret
+faketkStartProcess ENDP
+
+
+;;
+; Fake g_tkExecPgm implementation.
+; @proto     none. (void _Optlink fakeg_tkExecPgm(void);)
+; @returns   same as tkExecPgm: eax, edx and carry flag
+; @param     ax     Exec flag
+;            ds:dx  Filename address. (String)
+;            es:bx  Environment address. (String)
+;            di:si  Argument address. (String)
+; @uses      all - bp
+; @sketch    Copy the filename and arguments into a buffer we
+;            may modify later if this is a UNIX shellscript or
+;            a PE-file started by pe.exe.
+; @status    completely implemented.
+; @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+;
+;
+fakeg_tkExecPgm PROC NEAR
+    push    ebp
+    mov     ebp, esp
+
+    ;
+    ; Call C worker
+    ;
+    sub     esp, 10h
+    movzx   eax, ax
+    mov     [esp + 00h], eax            ; ExecFlag DWORD
+
+    mov     ax, es
+    SelToFlat
+    mov     [esp + 08h], eax            ; Environment ptr.
+    mov     ecx, eax
+
+    mov     ax, ds
+    mov     bx, dx
+    SelToFlat
+    mov     [esp + 0ch], eax            ; Filename ptr
+
+    mov     ax, di
+    mov     bx, si
+    SelToFlat
+    mov     [esp + 04h], eax            ; Argument ptr
+    mov     edx, eax
+
+    mov     eax, [esp + 00h]            ; ExecFlag DWORD in eax
+
+    mov     bx, seg FLAT:DATA32
+    mov     ds, bx                      ; Make ds flat
+    mov     es, bx                      ; Make es flat
+
+    call    tkExecPgmWorker             ;(ULONG flags, arg,    env,   prog)
+    add     esp, 10                     ;       eax,   edx,    ecx,
+                                        ;     ebp+8, ebp+c, ebp+10, ebp+14
+                                        ;     esp+0, esp+4, esp+08, esp+0c
+    or      eax, eax
+    jnz     ftkep_ret
+    call    faketkStartProcess          ; If succesfully so far. call start process.
+    jmp     ftkep_ret2                  ; <Currently no parameters are implemented.>
+
+ftkep_ret:
+    push    eax
+    call    _fakeLDRClearSem@0          ; clear the semaphore.
+    pop     eax
+
+ftkep_ret2:
+    leave
+    ret
+fakeg_tkExecPgm ENDP
+
+
+;;
+; Calls the fakeg_tkExecPgm procedure.
+; @cproto   ULONG _Optlink  CalltkExecPgm(
+;                               ULONG   execFlags,
+;                               PCSZ    pArg,
+;                               PCSZ    pEnv,
+;                               PCSZ    pExecName);
+; @returns
+; @param    eax (ebp +08h)  execFlags
+; @param    edx (ebp +0ch)  pArg
+; @param    ecx (ebp +10h)  pEnv
+; @param    ebp + 14h       pExecName
+; @uses     eax, ecx, edx
+; @status   completely implemented.
+; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+; @remark
+CalltkExecPgm PROC NEAR
+    push    ebp
+    mov     ebp, esp
+    push    ebx
+    push    edi
+    push    esi
+    push    es
+    push    ds
+
+    ; Save parameters
+    mov     [ebp+08h], eax
+
+    ;
+    ; create input for fakeg_tkExecPgm
+    ;
+    mov     eax, edx
+    xor     edi, edi
+    xor     esi, esi
+    or      eax, eax
+    jz      ctkep1
+    FlatToSel
+    mov     di, ax
+    mov     esi, ebx                    ; di:si -> arguments
+ctkep1:
+
+    mov     eax, [ebp + 14h]
+    xor     edx, edx
+    mov     ds, dx
+    or      eax, eax
+    jz      ctkep2
+    FlatToSel
+    mov     ds, ax
+    mov     edx, ebx                    ; ds:dx -> executable filename
+ctkep2:
+
+    mov     eax, ecx
+    xor     ebx, ebx
+    mov     es, bx
+    or      eax, eax
+    jz      ctkep3
+    FlatToSel
+    mov     es, ax
+    mov     eax, ebx                    ; es:bx -> environment.
+ctkep3:
+
+    mov     eax, [ebp+08h]              ; ax = exec flags.
+
+    call    far ptr FLAT:fakeg_tkExecPgm
+
+    ;
+    ; Restore and return.
+    ;
+    pop     ds
+    pop     es
+    pop     esi
+    pop     edi
+    pop     ebx
+    leave
+    ret
+CalltkExecPgm ENDP
+
+
+;;
+; Gets the selector for the CODE16 segment.
+; @cproto   USHORT  _Optlink GetSelectorCODE16(void)
+; @returns  Selector for the CODE16 segment.
+; @uses     eax
+; @status   completely implemented.
+; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+GetSelectorCODE16 PROC NEAR
+    xor     eax, eax
+    mov     ax, seg CODE16
+    ret
+GetSelectorCODE16 ENDP
+
+
+;;
+; Gets the selector for the DATA16 segment.
+; @cproto   USHORT  _Optlink GetSelectorDATA16(void)
+; @returns  Selector for the DATA16 segment.
+; @uses     eax
+; @status   completely implemented.
+; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+GetSelectorDATA16 PROC NEAR
+    xor     eax, eax
+    mov     ax, seg DATA16
+    ret
+GetSelectorDATA16 ENDP
+
+
+;;
+; Gets the selector for the CODE32 segment.
+; @cproto   USHORT  _Optlink GetSelectorCODE32(void)
+; @returns  Selector for the CODE32 segment.
+; @uses     eax
+; @status   completely implemented.
+; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+GetSelectorCODE32 PROC NEAR
+    xor     eax, eax
+    mov     ax, seg FLAT:CODE32
+    ret
+GetSelectorCODE32 ENDP
+
+;;
+; Gets the selector for the DATA32 segment.
+; @cproto   USHORT  _Optlink GetSelectorDATA32(void)
+; @returns  Selector for the DATA32 segment.
+; @uses     eax
+; @status   completely implemented.
+; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+GetSelectorDATA32 PROC NEAR
+    xor     eax, eax
+    mov     ax, seg FLAT:DATA32
+    ret
+GetSelectorDATA32 ENDP
+
+
+;;
+; Wrapper for fakeldrOpenPath.
+; @cproto       ULONG LDRCALL   fakeldrOpenPath(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful, ULONG lLibPath);
+; @returns      Return of the current fakeldrOpenPath
+; @param        pachFilename  Pointer to modulename. Not zero terminated!
+; @param        cchFilename   Modulename length.
+; @param        plv           Loader local variables? (Struct from KERNEL.SDF)
+; @param        pful          Pointer to flags which are passed on to ldrOpen.
+; @param        lLibPath      New parameter in build 14053.
+;                             ldrGetMte calls with 1
+;                             ldrOpenNewExe calls with 3
+;                             This is compared to the initial libpath index.
+;                                 The libpath index is:
+;                                     BEGINLIBPATH    1
+;                                     LIBPATH         2
+;                                     ENDLIBPATH      3
+;                                 The initial libpath index is either 1 or 2.
+;                             - ignored -
+; @uses         ecx, eax, edx
+; @sketch
+; @status
+; @author       knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+; @remark
+_fakeldrOpenPath@20 PROC NEAR
+    ASSUME ds:FLAT
+    ; dummy prolog.
+    push    ebp
+    mov     ebp, esp
+    sub     esp, 10h
+    add     esp, 10h
+    pop     ebp
+    ; real code
+    cmp     FLAT:DATA16:_options.ulBuild, 14053
+    jge     new
+    jmp     near ptr FLAT:CODE32:_fakeldrOpenPath_old@16
+new:
+    jmp     near ptr FLAT:CODE32:_fakeldrOpenPath_new@20
+_fakeldrOpenPath@20 ENDP
+
+
+
+;;
+; This is called at kernel entry.
+; @cproto   none
+; @returns  nothing
+; @param    none
+; @uses     nothing
+; @status   stub.
+; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+fakeKMEnterKmodeSEF proc near
+    ; dummy prolog.
+    push    ebp
+    mov     ebp, esp
+    sub     esp, 10h
+    leave
+    ret
+fakeKMEnterKmodeSEF endp
+
+
+;;
+; This is called at kernel exit.
+; @cproto   none
+; @returns  nothing
+; @param    none
+; @uses     nothing
+; @status   stub.
+; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+fakeKMExitKmodeSEF8 proc near
+    ; dummy prolog.
+    push    ebp
+    mov     ebp, esp
+    sub     esp, 10h
+    leave
+    ret
+fakeKMExitKmodeSEF8 endp
+
+CODE32 ends
+
+end _exestart
Index: trunk/src/win32k/kKrnlLib/src/tstInit.asm
===================================================================
--- trunk/src/win32k/kKrnlLib/src/tstInit.asm	(revision 8211)
+++ trunk/src/win32k/kKrnlLib/src/tstInit.asm	(revision 8211)
@@ -0,0 +1,141 @@
+; $Id: tstInit.asm,v 1.1 2002-04-07 22:39:16 bird Exp $
+;
+; Thunks to call stratgy entry points with init packets.
+;
+; Copyright (c) 2000-2001 knut st. osmundsen (kosmunds@csc.com)
+;
+; Project Odin Software License can be found in LICENSE.TXT
+;
+    .386
+
+;
+; Include files
+;
+    include devsegdf.inc
+    include os2.inc
+
+
+;
+; Exported symbols
+;
+    public  InitkKrnlHlp
+    public  InitkKrnlLib
+
+
+;
+; extrns
+;
+    extrn   _strategyAsm0:PROC
+    extrn   _strategyAsm1:PROC
+
+CODE32 SEGMENT
+;;
+; Initiates the kKrnlHlp device driver.
+; @cproto    ULONG _Optlink InitkKrnlHlp(PVOID pvPacket);
+; @returns
+; @param     (ss:)eax    pvPacket
+;                   This parameter is pointer to a stack object which haven't
+;                   had SSToDS() applied. This is done in this way because it
+;                   lightens the job to make a far 16 bits pointer of it.
+; @uses      eax, ecx, edx
+; @sketch
+; @status
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark
+InitkKrnlHlp PROC NEAR
+    ASSUME ds:FLAT, es:NOTHING, ss:NOTHING
+    push    ebx
+    push    ds
+    push    es
+    ;
+    ; Make 16:16 ptr to packet pointed to by ss:eax
+    ;
+    mov     bx, ss
+    mov     es, bx
+    mov     bx, ax
+
+    ;
+    ; Set ds to DATA16
+    ;
+    mov     ax, seg DATA16
+    mov     ds, ax
+
+    ;
+    ; Call stratgy entry point.
+    ;
+    jmp far ptr CODE16:Thunk16_kKrnlHlp
+Thunk32_kKrnlHlp::
+    movzx   eax, ax                     ; Cast USHORT to ULONG.
+
+    pop     es
+    pop     ds
+    pop     ebx
+    ret
+InitkKrnlHlp ENDP
+CODE32 ENDS
+
+CODE16 SEGMENT
+    ; Call strategy entry point for kKrnlHlp.
+Thunk16_kKrnlHlp::
+    call    far ptr CODE16:_strategyAsm0
+    jmp far ptr FLAT:Thunk32_kKrnlHlp
+CODE16 ENDS
+
+
+
+CODE32 SEGMENT
+;;
+; Initiates the kKrnlLib device driver.
+; @cproto    ULONG _Optlink InitkKrnlLib(PVOID pvPacket);
+; @returns
+; @param     (ss:)eax    pvPacket
+;                   This parameter is pointer to a stack object which haven't
+;                   had SSToDS() applied. This is done in this way because it
+;                   lightens the job to make a far 16 bits pointer of it.
+; @uses      eax, ecx, edx
+; @sketch
+; @status
+; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
+; @remark
+InitkKrnlLib PROC NEAR
+    ASSUME ds:FLAT, es:NOTHING, ss:NOTHING
+    push    ebx
+    push    ds
+    push    es
+    ;
+    ; Make 16:16 ptr to packet pointed to by ss:eax
+    ;
+    mov     bx, ss
+    mov     es, bx
+    mov     bx, ax
+
+    ;
+    ; Set ds to DATA16
+    ;
+    mov     ax, seg DATA16
+    mov     ds, ax
+
+    ;
+    ; Call stratgy entry point.
+    ;
+    jmp far ptr CODE16:Thunk16_InitkKrnlLib
+Thunk32_InitkKrnlLib::
+    movzx   eax, ax                     ; Cast USHORT to ULONG.
+
+    pop     es
+    pop     ds
+    pop     ebx
+    ret
+InitkKrnlLib ENDP
+CODE32 ENDS
+
+CODE16 SEGMENT
+    ; Call strategy entry point for kKrnlLib.
+Thunk16_InitkKrnlLib::
+    call    far ptr CODE16:_strategyAsm1
+    jmp far ptr FLAT:Thunk32_InitkKrnlLib
+
+CODE16 ENDS
+
+
+END
Index: trunk/src/win32k/kKrnlLib/src/tstkKrnlLib.c
===================================================================
--- trunk/src/win32k/kKrnlLib/src/tstkKrnlLib.c	(revision 8211)
+++ trunk/src/win32k/kKrnlLib/src/tstkKrnlLib.c	(revision 8211)
@@ -0,0 +1,892 @@
+/* $Id: tstkKrnlLib.c,v 1.1 2002-04-07 22:39:16 bird Exp $
+ *
+ * kKrnlLib test module.
+ *
+ * Copyright (c) 2000-2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+/*******************************************************************************
+*   Defined Constants And Macros                                               *
+*******************************************************************************/
+
+#define SEL_FLATMASK        0x01fff0000
+#define SEL_FLAT_SHIFT      0x0d
+#define SEL_LDT_RPL3        0x07
+
+#define SelToFlat(sel, off) \
+    (PVOID)( (((unsigned)(sel) << SEL_FLAT_SHIFT) & SEL_FLAT_MASK) + (unsigned)(off))
+
+#define FlatToSel(flataddr) \
+    (PVOID)( ( (((unsigned)(flataddr) << 3) & 0xfff80000) | (SEL_LDT_RPL3 << 16) ) | ((unsigned)(flataddr) & 0xffff) )
+
+#define assert(expr) ((expr) ? (void)0 : __interrupt(3))
+
+#define DWORD   ULONG
+#define WORD    USHORT
+
+/*******************************************************************************
+*   Internal Functions                                                         *
+*******************************************************************************/
+#define INCL_BASE
+#define INCL_SSTODS
+#define FOR_EXEHDR 1
+#include <os2.h>
+#include <exe386.h>
+#include <newexe.h>
+
+#include "devSegDf.h"                   /* kKrnlLib segment definitions. */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "options.h"
+#include "dev1632.h"
+#include "dev32.h"
+#include "devcmd.h"
+#define INCL_OS2KRNL_ALL
+#include "os2krnl.h"
+
+#define INCL_KKL_ALL
+#include "kKrnlLib.h"
+
+#include "ProbKrnl.h"
+#include "krnlPrivate.h"
+#include "testcase.h"
+
+#include <stdlib.h>
+
+
+
+
+/** @design kKrnlLib Ring-3 Testing
+ * I'll try to make it possible to test parts or all the kKrnlLib code in ring-3.
+ * To archive this the interface against the kernel has to be faked/emulated.
+ * More precisely:
+ *      - DevHelps.
+ *      - Worker routines for imported kernel functions. (calltab.asm jumps to them.)
+ *      - 16-bit stack 1Kb.
+ *      - Strategy calls.
+ *      - Fake module loadings (= testcases).
+ *      - ?
+ *
+ * Some of the initstuff has to be omitted, at least in the start. The first
+ * goal is to be able to test _ldrOpenPath and _ldrOpen.
+ *
+ *
+ * @subsection  Device Helper Routines
+ *
+ * These I think we'll implemented by providing the kernel interface, a far 16:16
+ * pointer to a dh-router. Our router will in most cases thunk back to 32-bit
+ * code and implementet the required devhelp routines in pure C code.
+ *
+ * These are the needed routines:
+ *      - DevHelp_VirtToLin   - ok
+ *      - DevHelp_VMAlloc     - ok
+ *      - DevHelp_VMFree      - ok
+ *      - DevHelp_GetDOSVar   - ok
+ *      - DevHelp_VMLock
+ *      - DevHelp_VMUnLock  ?
+ *      - DevHelp_VMSetMem  ?
+ *      - DevHelp_Yield     ?
+ *
+ *
+ * @subsection  Worker routines for imported kernel functions
+ *
+ * Create worker routines for the imported kernel functions. Calltab will be
+ * set up to jump to them. This is done in d32init.c, in stead of using
+ * the importtab.
+ *
+ * Some of these workers will be parts of testcases. For example g_tkExecPgm
+ * and _LDRQAppType.
+ *
+ * Only the imported functions are implemented on demand. Initially these
+ * functions will be provided:
+ *      - ldrOpen
+ *      - ldrRead
+ *      - ldrClose
+ *      - ldrOpenPath
+ *      - SftFileSize
+ *
+ *
+ * @subsection  16-bit stack
+ *
+ * To make this test real the stack has to be 16-bit and _very_ small (1KB).
+ * TKSSBase have to be implemented by the DevHelp_GetDOSVar DosTable2 stuff.
+ * The stack will be thunked to 16-bit by a thunking procedure called from
+ * main. This procedure thunks the stack (quite easy, we're in tiled memory!),
+ * set the value of TKSSBase, calls a C function which does all the rest of
+ * the testing. When taht function returns, the stack will be thunked back
+ * to 32-bit, TKSSBase will be zeroed, and the procedure returns to main.
+ *
+ *
+ * @subsection  Straegy routine calls (not implemented)
+ *
+ * We'll call the strategy entry points with init request packets. The initiation
+ * will require a replacement for DosDevIOCtl (16-bit) which calls the
+ * kKrnlHlp strategy routine. We'll also have to provide fakes for kernel probing,
+ * verifing and overloading in d32init.c.
+ *
+ *
+ * @subsection  Order of events
+ *
+ * This is the order this testing environment currently works:
+ *      1) init devhelp subsystem
+ *      2) init workers
+ *      3) thunk stack
+ *      4) Fake 16-bit init. Set TKSSBase, FlatDS, FlatCS, DevHelp pointer....
+ *      5) Call R0Init32().
+ *         (d32init.c is modified a bit to setup the calltab correctly.)
+ *      6) Start testing...
+ *      7) Testing finished - thunk stack back to 32-bit.
+ */
+
+
+/*******************************************************************************
+*   Structures and Typedefs                                                    *
+*******************************************************************************/
+#if !defined(QS_MTE) || defined(QS_MODVER)
+   /* From OS/2 Toolkit v4.5 (BSEDOS.H) */
+
+   /* Global Record structure
+    * Holds all global system information. Placed first in user buffer
+    */
+   typedef struct qsGrec_s {  /* qsGrec */
+           ULONG         cThrds;
+           ULONG         c32SSem;
+           ULONG         cMFTNodes;
+   }qsGrec_t;
+
+   /*
+    *      System wide MTE information
+    *      ________________________________
+    *      |       pNextRec                |----|
+    *      |-------------------------------|    |
+    *      |       hmte                    |    |
+    *      |-------------------------------|    |
+    *      |       ctImpMod                |    |
+    *      |-------------------------------|    |
+    *      |       ctObj                   |    |
+    *      |-------------------------------|    |
+    *      |       pObjInfo                |----|----------|
+    *      |-------------------------------|    |          |
+    *      |       pName                   |----|----|     |
+    *      |-------------------------------|    |    |     |
+    *      |       imported module handles |    |    |     |
+    *      |          .                    |    |    |     |
+    *      |          .                    |    |    |     |
+    *      |          .                    |    |    |     |
+    *      |-------------------------------| <--|----|     |
+    *      |       "pathname"              |    |          |
+    *      |-------------------------------| <--|----------|
+    *      |       Object records          |    |
+    *      |       (if requested)          |    |
+    *      |_______________________________|    |
+    *                                      <-----
+    *      NOTE that if the level bit is set to QS_MTE, the base Lib record will be followed
+    *      by a series of object records (qsLObj_t); one for each object of the
+    *      module.
+    */
+
+   typedef struct qsLObjrec_s {  /* qsLOrec */
+           ULONG         oaddr;  /* object address */
+           ULONG         osize;  /* object size */
+           ULONG         oflags; /* object flags */
+   } qsLObjrec_t;
+
+   typedef struct qsLrec_s {     /* qsLrec */
+           void  FAR        *pNextRec;      /* pointer to next record in buffer */
+           USHORT           hmte;           /* handle for this mte */
+           USHORT           fFlat;          /* true if 32 bit module */
+           ULONG            ctImpMod;       /* # of imported modules in table */
+           ULONG            ctObj;          /* # of objects in module (mte_objcnt)*/
+           qsLObjrec_t FAR  *pObjInfo;      /* pointer to per object info if any */
+           UCHAR     FAR    *pName;         /* -> name string following struc */
+   } qsLrec_t;
+
+
+
+   /* Pointer Record Structure
+    *      This structure is the first in the user buffer.
+    *      It contains pointers to heads of record types that are loaded
+    *      into the buffer.
+    */
+
+   typedef struct qsPtrRec_s {   /* qsPRec */
+           qsGrec_t        *pGlobalRec;
+           void            *pProcRec;      /* ptr to head of process records */
+           void            *p16SemRec;     /* ptr to head of 16 bit sem recds */
+           void            *p32SemRec;     /* ptr to head of 32 bit sem recds */
+           void            *pMemRec;       /* ptr to head of shared mem recs */
+           qsLrec_t        *pLibRec;       /* ptr to head of mte records */
+           void            *pShrMemRec;    /* ptr to head of shared mem records */
+           void            *pFSRec;        /* ptr to head of file sys records */
+   } qsPtrRec_t;
+
+#endif
+
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+extern BOOL     fInited;                /* malloc.c */
+int             iTestcaseNo;
+int             cObjectsFake = 14;
+OTE             aKrnlOTE[24];
+
+
+/*******************************************************************************
+*   External Functions                                                         *
+*******************************************************************************/
+#ifndef QS_MTE
+   /* from OS/2 Toolkit v4.5 */
+
+   APIRET APIENTRY DosQuerySysState(ULONG EntityList, ULONG EntityLevel, PID pid,
+                                    TID tid, PVOID pDataBuf, ULONG cbBuf);
+    #define QS_MTE         0x0004
+#endif
+
+
+/*******************************************************************************
+*   Internal Functions                                                         *
+*******************************************************************************/
+void    syntax(void);
+int     kernelInit(int iTest, int argc, char **argv);
+void    workersinit(void);
+void    initRPInit(RP32INIT *pRpInit, char *pszInitArgs);
+int     tests(int iTest, int argc, char **argv);
+int     TestCase1(int argc, char **argv);
+int     TestCase2(void);
+int     CompareOptions(struct kKLOptions *pOpt, ULONG fExpKernel, ULONG ulExpKernelBuild, USHORT usExpVerMajor, USHORT usExpVerMinor);
+int     TestCaseExeLoad2(void);
+int     WritekKrnlLibDll(void);
+
+
+/**
+ * Main function. Arguments _currently_ unused.
+ */
+int main(int argc, char **argv)
+{
+    int         rc;
+
+    /*
+     * Init devhelp subsystems.
+     */
+    dhinit();
+
+    /*
+     * Parse arguments.
+     * (printf don't work before dhinit is called...)
+     */
+    if (argc < 2 || (iTestcaseNo = atoi(argv[1])) <= 0)
+    {
+        syntax();
+        printf("syntax error\n");
+        return -1;
+    }
+
+    /*
+     * Init workers if necessary.
+     */
+    workersinit();
+
+    /*
+     * Init Kernel
+     */
+    if (!kernelInit(iTestcaseNo, argc, argv))
+        return -2;
+
+    /*
+     * Thunk Stack to 16-bits.
+     *
+     * IMPORTANT! From now on SSToDS have to be used when making pointers
+     *            to stack objects.
+     */
+    ThunkStack32To16();
+
+    rc = tests(iTestcaseNo, argc, argv);
+
+    /*
+     * Thunk Stack back to 32-bits.
+     */
+    ThunkStack16To32();
+
+
+    /*
+     * To avoid a sfree error message we'll set fInited (heap init flag) to false.
+     */
+    fInited = FALSE;
+    return rc;
+}
+
+
+/**
+ * Prints syntax information.
+ * @status  partially implemented.
+ * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+void    syntax(void)
+{
+    printf(
+           "kKrnlLibTst.exe v%d.%d.%d - Ring 3 testing of kKrnlLib.sys\n"
+           "syntax: kKrnlLibTst.exe <testcase number> [optional arguments]\n",
+           0,0,4
+           );
+}
+
+
+/**
+ * test case 1: Load the specified kernel
+ * other cases: Load running kernel.
+ * @returns Success indicator. (true/false)
+ * @param   iTest   Testcase number.
+ * @param   argc    main argc
+ * @param   argv    main argv
+ * @status  completely implemented.
+ * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+int     kernelInit(int iTest, int argc, char **argv)
+{
+    static char     achBuffer[1024*256];
+    char            szError[256];
+    HMODULE         hmod = NULLHANDLE;
+    int             rc;
+    char            szName[CCHMAXPATH];
+    char *          pszSrcName;
+    char *          pszTmp;
+    ULONG           ulAction;
+    HFILE           hFile;
+    struct e32_exe* pe32 = (struct e32_exe*)(void*)&achBuffer[0];
+    qsPtrRec_t *    pPtrRec = (qsPtrRec_t*)(void*)&achBuffer[0];
+    qsLrec_t *      pLrec;
+    int             i;
+    FILESTATUS3     fsts3;
+
+    /*
+     * If not testcase 1, use the running kernel.
+     */
+    if (iTest != 1)
+    {
+        ULONG   ulBootDrv = 3;
+        pszSrcName = "c:\\os2krnl";
+        DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, SSToDS(&ulBootDrv), sizeof(ulBootDrv));
+        pszSrcName[0] = (char)(ulBootDrv + 'a' - 1);
+    }
+    else
+    {
+        if (argc < 3)
+        {
+            printf("Missing parameter!\n");
+            return FALSE;
+        }
+        pszSrcName = argv[2];
+    }
+
+    /*
+     * Make a temporary copy of the kernel.
+     */
+    if (DosScanEnv("TMP", &pszTmp) != NO_ERROR || pszTmp == NULL)
+    {
+        printf("Environment variable TMP is not set.\n");
+        return FALSE;
+    }
+    strcpy(szName, pszTmp);
+    if (szName[strlen(pszTmp) - 1] != '\\' && szName[strlen(pszTmp) - 1] != '/')
+        strcat(szName, "\\");
+    strcat(szName, "os2krnl");
+    rc = DosCopy(pszSrcName, szName, DCPY_EXISTING);
+    if (rc != NO_ERROR)
+    {
+        printf("Failed to copy %s to %s.\n", pszSrcName, szName);
+        return FALSE;
+    }
+    if (DosQueryPathInfo(szName, FIL_STANDARD, &fsts3, sizeof(fsts3)) != NO_ERROR
+        ||  !(fsts3.attrFile = FILE_ARCHIVED)
+        ||  DosSetPathInfo(szName, FIL_STANDARD, &fsts3, sizeof(fsts3), 0) != NO_ERROR
+        )
+    {
+        printf("Failed to set attributes for %s.\n", szName);
+        return FALSE;
+    }
+
+    /*
+     * Patch the kernel.
+     *      Remove the entrypoint.
+     */
+    ulAction = 0;
+    rc = DosOpen(szName, &hFile, &ulAction, 0, FILE_NORMAL,
+                 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
+                 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
+                 NULL);
+    if (rc != NO_ERROR)
+    {
+        printf("Failed to open temporary kernel file. rc = %d\n", rc);
+        return FALSE;
+    }
+    rc = DosRead(hFile, &achBuffer[0], 0x200, &ulAction);
+    if (rc != NO_ERROR)
+    {
+        DosClose(hFile);
+        printf("Failed to read LX header from temporary kernel file.\n");
+        return FALSE;
+    }
+    pe32 = (struct e32_exe*)(void*)&achBuffer[*(unsigned long*)(void*)&achBuffer[0x3c]];
+    if (*(PUSHORT)pe32->e32_magic != E32MAGIC)
+    {
+        DosClose(hFile);
+        printf("Failed to read LX header from temporary kernel file (2).\n");
+        return FALSE;
+    }
+    pe32->e32_eip = 0;
+    pe32->e32_startobj = 0;
+    pe32->e32_mflags &= ~(E32LIBTERM | E32LIBINIT);
+    if ((rc = DosSetFilePtr(hFile, *(unsigned long*)(void*)&achBuffer[0x3c], FILE_BEGIN, &ulAction)) != NO_ERROR
+        || (rc = DosWrite(hFile, pe32, sizeof(struct e32_exe), &ulAction)) != NO_ERROR)
+    {
+        DosClose(hFile);
+        printf("Failed to write patched LX header to temporary kernel file.\n");
+        return FALSE;
+    }
+    DosClose(hFile);
+
+    /*
+     * Load the module.
+     */
+    rc = DosLoadModule(szError, sizeof(szError), szName, SSToDS(&hmod));
+    if (rc != NO_ERROR && (rc != ERROR_INVALID_PARAMETER && hmod == NULLHANDLE))
+    {
+        printf("Failed to load OS/2 kernel image %s.");
+        return FALSE;
+    }
+
+    /*
+     * Get object information.
+     */
+    rc = DosQuerySysState(QS_MTE, QS_MTE, 0L, 0L, pPtrRec, sizeof(achBuffer));
+    if (rc != NO_ERROR)
+    {
+        printf("DosQuerySysState failed with rc=%d.\n", rc);
+        return FALSE;
+    }
+
+    pLrec = pPtrRec->pLibRec;
+    while (pLrec != NULL)
+    {
+        /*
+         * Bug detected in OS/2 FP13. Probably a problem which occurs
+         * in _LDRSysMteInfo when qsCheckCache is calle before writing
+         * object info. The result is that the cache flushed and the
+         * attempt of updating the qsLrec_t next and object pointer is
+         * not done. This used to work earlier and on Aurora AFAIK.
+         *
+         * The fix for this problem is to check if the pObjInfo is NULL
+         * while the number of objects isn't 0 and correct this. pNextRec
+         * will also be NULL at this time. This will be have to corrected
+         * before we exit the loop or moves to the next record.
+         * There is also a nasty alignment of the object info... Hope
+         * I got it right. (This aligment seems new to FP13.)
+         */
+        if (pLrec->pObjInfo == NULL /*&& pLrec->pNextRec == NULL*/ && pLrec->ctObj > 0)
+            {
+            pLrec->pObjInfo = (qsLObjrec_t*)(void*)(
+                (char*)(void*)pLrec
+                + ((sizeof(qsLrec_t)                            /* size of the lib record */
+                   + pLrec->ctImpMod * sizeof(short)            /* size of the array of imported modules */
+                   + strlen((char*)(void*)pLrec->pName) + 1     /* size of the filename */
+                   + 3) & ~3));                                 /* the size is align on 4 bytes boundrary */
+            pLrec->pNextRec = (qsLrec_t*)(void*)((char*)(void*)pLrec->pObjInfo
+                                                 + sizeof(qsLObjrec_t) * pLrec->ctObj);
+            }
+        if (pLrec->hmte == hmod)
+            break;
+
+        /*
+         * Next record
+         */
+        pLrec = (qsLrec_t*)pLrec->pNextRec;
+    }
+
+    if (pLrec == NULL)
+    {
+        printf("DosQuerySysState(os2krnl): not found\n");
+        return FALSE;
+    }
+    if (pLrec->pObjInfo == NULL)
+    {
+        printf("DosQuerySysState(os2krnl): no object info\n");
+        return FALSE;
+    }
+
+    /*
+     * Fill the aKrnlOTE array.
+     */
+    for (i = 0; i < pLrec->ctObj; i++)
+    {
+        aKrnlOTE[i].ote_size    = pLrec->pObjInfo[i].osize;
+        aKrnlOTE[i].ote_base    = pLrec->pObjInfo[i].oaddr;
+        aKrnlOTE[i].ote_flags   = pLrec->pObjInfo[i].oflags;
+        aKrnlOTE[i].ote_pagemap = i > 0 ? aKrnlOTE[i-1].ote_pagemap + aKrnlOTE[i-1].ote_mapsize : 0;
+        aKrnlOTE[i].ote_mapsize = (pLrec->pObjInfo[i].osize + 0x0FFF) / 0x1000;
+        aKrnlOTE[i].ote_sel     = (USHORT)FlatToSel(pLrec->pObjInfo[i].oaddr);
+        aKrnlOTE[i].ote_hob     = 0;
+    }
+    cObjectsFake = pLrec->ctObj;
+
+    return TRUE;
+}
+
+
+/**
+ * Initiates a init reqest packet.
+ * @param   pRpInit         Pointer to request packet to init.
+ * @param   pszInitArgs     Pointer to init arguments.
+ * @status  completely implemented.
+ * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+void initRPInit(RP32INIT *pRpInit, char *pszInitArgs)
+{
+    /* kKrnlHlp */
+    memset(pRpInit, 0, sizeof(RP32INIT));
+    pRpInit->rph.Len  = sizeof(RP32INIT);
+    pRpInit->rph.Cmd  = CMDInit;
+    pRpInit->DevHlpEP = getDHRouterFarPtr();
+    pRpInit->InitArgs = (PSZ)FlatToSel(pszInitArgs);
+}
+
+
+/**
+ * Testcase fan-out.
+ * @returns Testcase return value.
+ *          -2 if testcase not found.
+ * @param   iTest   Testcase number.
+ * @param   argc    main argc
+ * @param   argv    main argv
+ * @status  completely implemented.
+ * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+int tests(int iTest, int argc, char **argv)
+{
+    int     rc;
+
+    printf("-------------------------------- Testcase %d:\n", iTest);
+    switch (iTest)
+    {
+        case 1:     rc = TestCase1(argc, argv);   break;
+        case 2:     rc = TestCase2();   break;
+
+        default:
+            printf("testcase no. %d is not found\n", iTest);
+            rc = -2;
+    }
+    printf("result %d -----------------------------------\n", rc);
+
+    KNOREF(argc);
+    KNOREF(argv);
+    return rc;
+}
+
+
+
+/**
+ * Test case 1.
+ * Checks that default initiation works fine for a given kernel.
+ *
+ * Syntax:  win32ktst.exe 1 <os2krnl> <majorver> <minorver> <build> <kerneltype: S|U|4> <buildtype: A|H|R> [rev] [os2krnl.sym]
+ *
+ * @sketch  Create init packet with no arguments.
+ *          Initiate kKrnlHlp
+ *          Create init packet with no arguments.
+ *          Initiate kKrnlLib
+ * @returns 0 on success.
+ *          1 on failure.
+ * @status  completely implemented.
+ * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+int TestCase1(int argc, char **argv)
+{
+    static char szInitArgs[CCHMAXPATH + 10];
+    int         rc = 1;
+    RP32INIT    rpinit;
+
+    /* verify argument count */
+    if (argc < 8 || argc > 10)
+    {
+        printf("Invalid parameter count for testcase 1.\n");
+        return ERROR_INVALID_PARAMETER;
+    }
+
+    /* init fake variabels */
+    _usFakeVerMajor = (USHORT)atoi(argv[3]);
+    _usFakeVerMinor = (USHORT)atoi(argv[4]);
+
+    /* make init string */
+    strcpy(szInitArgs, "-w3");
+    if (argc >= 9 && argv[argc-1][1] != '\0')
+        strcat(strcat(szInitArgs, " -S:"), argv[argc-1]);
+
+    /* kKrnlHlp */
+    initRPInit(SSToDS(&rpinit), szInitArgs);
+    rc = InitkKrnlHlp(&rpinit);              /* no SSToDS! */
+    printf("InitkKrnlHlp returned status=0x%04x\n", rpinit.rph.Status);
+    if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
+    {
+        /* kKrnlLib */
+        initRPInit(SSToDS(&rpinit), szInitArgs);
+        rc = InitkKrnlLib(&rpinit);       /* no SSToDS! */
+        printf("InitkKrnlLib returned status=0x%04x\n", rpinit.rph.Status);
+        if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
+        {
+            struct kKLOptions opt = DEFAULT_OPTION_ASSIGMENTS;
+            ULONG   fExpKernel = 0;
+            if (argv[6][0] == 'S')  fExpKernel |= KF_SMP;
+            if (argv[6][0] == '4')  fExpKernel |= KF_W4;
+            if (argv[6][0] == 'U')  fExpKernel |= KF_UNI;
+            if (argv[7][0] == 'A')  fExpKernel |= KF_ALLSTRICT;
+            if (argv[7][0] == 'H')  fExpKernel |= KF_HALFSTRICT;
+
+            if (argc >= 9 && argv[8][1] == '\0')
+                switch (argv[8][0])
+                {
+                    case '\0': break;
+                    default:
+                    fExpKernel |= (argv[8][0] - (argv[8][0] >= 'a' ? 'a'-1 : 'A'-1)) << KF_REV_SHIFT;
+                }
+            rc = CompareOptions(SSToDS(&opt), fExpKernel, atoi(argv[5]), (USHORT)atoi(argv[3]), (USHORT)atoi(argv[4]));
+        }
+        else
+            printf("!failed!\n");
+    }
+    else
+        printf("!failed!\n");
+
+    return rc;
+}
+
+/**
+ * Test case 2.
+ * Checks that all parameters are read correctly (1).
+ *
+ * @sketch  Create init packet with no arguments.
+ *          Initiate kKrnlHlp
+ *          Create init packet with no arguments.
+ *          Initiate kKrnlLib
+ * @returns 0 on success.
+ *          1 on failure.
+ * @status  completely implemented.
+ * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+int TestCase2(void)
+{
+    int         rc = 1;
+    RP32INIT    rpinit;
+    char *      pszInitArgs = "-C1 -L:E -Verbose -Elf:Yes -Pe:Mixed -Script:Yes -W4 -Heap:512000 -ResHeap:0256000 -HeapMax:4096000 -ResHeapMax:0x100000";
+
+    options.fLogging = TRUE;
+
+    /* kKrnlHlp */
+    initRPInit(SSToDS(&rpinit), pszInitArgs);
+    rc = InitkKrnlHlp(&rpinit);              /* no SSToDS! */
+    printf("InitkKrnlHlp returned status=0x%04x\n", rpinit.rph.Status);
+    if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
+    {
+        /* kKrnlLib */
+        initRPInit(SSToDS(&rpinit), pszInitArgs);
+        rc = InitkKrnlLib(&rpinit);       /* no SSToDS! */
+        printf("InitkKrnlLib returned status=0x%04x\n", rpinit.rph.Status);
+        if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
+        {
+            struct kKLOptions opt = DEFAULT_OPTION_ASSIGMENTS;
+            opt.cbSwpHeapInit   = 512000;
+            opt.cbSwpHeapMax    = 4096000;
+            opt.cbResHeapInit   = 0256000;
+            opt.cbResHeapMax    = 0x100000;
+            opt.fQuiet          = FALSE;
+            opt.fLogging        = TRUE;
+            opt.usCom           = OUTPUT_COM1;
+
+            rc = CompareOptions(SSToDS(&opt), -1, -1, (USHORT)-1, (USHORT)-1);
+            if (rc == NO_ERROR)
+            {
+                rc = WritekKrnlLibDll();
+            }
+        }
+        else
+            printf("!failed!\n");
+    }
+    else
+        printf("!failed!\n");
+
+    return rc;
+}
+
+
+
+int WritekKrnlLibDll(void)
+{
+    ULONG   ulAction;
+    int     rc;
+    HFILE   hFile = NULLHANDLE;
+
+    /*
+     * Open the file.
+     */
+    rc = DosOpen("kKrnlLib.Dll", SSToDS(&hFile), SSToDS(&ulAction), 0, FILE_NORMAL,
+                 OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS,
+                 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYREAD | OPEN_ACCESS_WRITEONLY,
+                 NULL);
+    if (rc == NO_ERROR)
+    {
+        static struct e32_exe   exehdr;
+        static struct o32_obj   aObjTab[24];
+        struct o32_map          page;
+        int                     i;
+        int                     j;
+        ULONG                   ulWritten;
+        ULONG                   ulPos;
+        ULONG                   ulNULL = 0;
+
+
+        /* make exehdr */
+        memset(&exehdr, 0, sizeof(exehdr));
+        exehdr.e32_magic[0] = E32MAGIC1;
+        exehdr.e32_magic[1] = E32MAGIC2;
+        exehdr.e32_cpu      = E32CPU486;
+        exehdr.e32_os       = NE_OS2;
+        exehdr.e32_mflags   = E32MODDLL | E32PMW;
+        exehdr.e32_mpages   = 0;
+        for (i = 0; i < KKL_SwapMTE.smte_objcnt; i++)
+            exehdr.e32_mpages += (KKL_SwapMTE.smte_objtab[i].ote_size + 0xfff) >> 12;
+        exehdr.e32_startobj = 2;
+        exehdr.e32_eip      = 0;
+        exehdr.e32_pagesize = 0x1000;
+        exehdr.e32_fixupsize= exehdr.e32_mpages * sizeof(unsigned long)
+                            + 4;
+        exehdr.e32_ldrsize  = KKL_SwapMTE.smte_objcnt * sizeof(struct o32_obj)
+                            + exehdr.e32_mpages * sizeof(struct o32_map)
+                            + &KKL_ResNameTabEND[0] - (char*)KKL_SwapMTE.smte_restab
+                            + exehdr.e32_mpages * sizeof(unsigned long)
+                            + 4;
+        exehdr.e32_objtab   = sizeof(exehdr);
+        exehdr.e32_objcnt   = KKL_SwapMTE.smte_objcnt;
+        exehdr.e32_objmap   = exehdr.e32_objtab + exehdr.e32_objcnt * sizeof(struct o32_obj);
+        exehdr.e32_restab   = exehdr.e32_objmap + exehdr.e32_mpages * sizeof(struct o32_map);
+        exehdr.e32_enttab   = exehdr.e32_restab + &KKL_ResNameTabEND[0] - (char*)KKL_SwapMTE.smte_restab;
+        exehdr.e32_fpagetab = exehdr.e32_enttab + &KKL_EntryTabEND[0] - (char*)KKL_SwapMTE.smte_enttab;
+        exehdr.e32_frectab  = exehdr.e32_fpagetab+exehdr.e32_mpages * sizeof(unsigned long);
+        exehdr.e32_datapage = exehdr.e32_frectab + 4;
+        exehdr.e32_nrestab  = 0;
+        exehdr.e32_cbnrestab= 0;
+
+        /* make object table */
+        memcpy(&aObjTab[0], KKL_SwapMTE.smte_objtab, KKL_SwapMTE.smte_objcnt * sizeof(struct o32_obj));
+        for (i = 0, j = 1; i < KKL_SwapMTE.smte_objcnt; i++)
+        {
+            aObjTab[i].o32_reserved = 0;
+            aObjTab[i].o32_pagemap = j;
+            j += aObjTab[i].o32_mapsize = (aObjTab[i].o32_size + 0xfff) >> 12;
+            printf("obj %02d: base=%08x size=%08x page=%08x pages=%08x\n",
+                   i, aObjTab[i].o32_base, aObjTab[i].o32_size, aObjTab[i].o32_pagemap, aObjTab[i].o32_mapsize);
+        }
+
+        /* write the header stuff */
+        DosWrite(hFile, &exehdr, sizeof(exehdr), SSToDS(&ulWritten));
+        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_objtab);
+        DosWrite(hFile, &aObjTab[0], exehdr.e32_objcnt * sizeof(struct o32_obj), SSToDS(&ulWritten));
+        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_objmap);
+        for (i = 0, page.o32_pagedataoffset = 0; i < KKL_SwapMTE.smte_objcnt; i++)
+        {
+            for (j = 0; j < aObjTab[i].o32_mapsize;j++, page.o32_pagedataoffset += 0x1000)
+            {
+                page.o32_pageflags = VALID;
+                page.o32_pagesize = 0x1000;
+                DosWrite(hFile, SSToDS(&page), sizeof(struct o32_map), SSToDS(&ulWritten));
+            }
+        }
+        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_restab);
+        DosWrite(hFile, &KKL_ResNameTab[0], &KKL_ResNameTabEND[0] - (char*)KKL_SwapMTE.smte_restab, SSToDS(&ulWritten));
+        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_enttab);
+        DosWrite(hFile, &KKL_EntryTab[0], &KKL_EntryTabEND[0] - (char*)KKL_SwapMTE.smte_enttab, SSToDS(&ulWritten));
+        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_fpagetab);
+        for (i = 0, page.o32_pagedataoffset = 0; i < KKL_SwapMTE.smte_objcnt; i++)
+        {
+            for (j = 0; j < aObjTab[i].o32_mapsize;j++, page.o32_pagedataoffset += 0x1000)
+                DosWrite(hFile, SSToDS(&ulNULL), sizeof(ulNULL), SSToDS(&ulWritten));
+        }
+        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_frectab);
+        DosWrite(hFile, SSToDS(&ulNULL), sizeof(ulNULL), SSToDS(&ulWritten));
+
+        /* Write data pages. */
+        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_datapage);
+        for (i = 0; i < KKL_SwapMTE.smte_objcnt; i++)
+            for (j = 0; j < aObjTab[i].o32_mapsize; j++)
+            {
+                static char achPage[0x1000];
+                char    *pchData = (char*)aObjTab[i].o32_base + j * 0x1000;
+                int k;
+                if (aObjTab[i].o32_flags & (OBJINVALID | OBJIOPL))
+                    memset(achPage[0], 0x1000, 0);
+                else
+                    for (k = 0; k < 0x1000; k++, pchData++)
+                        achPage[k] = *pchData;
+                DosWrite(hFile, &achPage[0], 0x1000, SSToDS(&ulWritten));
+            }
+
+        /*
+         * Close file - We're finished in a way.
+         */
+        DosClose(hFile);
+    }
+
+    return 0;
+}
+
+/**
+ * Compares the options with the option struct passed in.
+ * @returns 0 on success.
+ *          number of mismatches on error.
+ * @param   pOpt                Expected option struct.
+ * @param   fExpKernel          Expected stuff.
+ * @param   ulExpKernelBuild    Expected stuff.
+ * @param   usExpVerMajor       Expected stuff.
+ * @param   usExpVerMinor       Expected stuff.
+ * @status  completely implemented.
+ * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
+ */
+int CompareOptions(struct kKLOptions *pOpt, ULONG fExpKernel, ULONG ulExpKernelBuild,
+                   USHORT usExpVerMajor, USHORT usExpVerMinor)
+{
+    int rc = 0;
+    /*
+     *  Check that the option struct is correct.
+     */
+    if (options.fQuiet != pOpt->fQuiet)
+        printf("fQuiet = %d - should be %d\n", options.fQuiet, pOpt->fQuiet, rc++);
+    if (options.usCom != pOpt->usCom)
+        printf("usCom = %d - should be %d\n", options.usCom, pOpt->usCom, rc++);
+    if (options.fLogging != pOpt->fLogging)
+        printf("fLogging = %d - should be %d\n", options.fLogging, pOpt->fLogging, rc++);
+    if (ulExpKernelBuild != ~0UL)
+    {
+        if (fKernel != fExpKernel)
+            printf("fKernel = %x - should be %x\n", fKernel, fExpKernel, rc++);
+        if (ulKernelBuild != ulExpKernelBuild)
+            printf("ulBuild = %d - should be %d\n", ulKernelBuild, ulExpKernelBuild, rc++);
+        if (usVerMajor != usExpVerMajor)
+            printf("usVerMajor = %d - should be %d\n", usVerMajor, usExpVerMajor, rc++);
+        if (usVerMinor != usExpVerMinor)
+            printf("usVerMinor = %d - should be %d\n", usVerMinor, usExpVerMinor, rc++);
+    }
+    if (options.cbSwpHeapInit != pOpt->cbSwpHeapInit)
+        printf("cbSwpHeapInit = %d - should be %d\n", options.cbSwpHeapInit, pOpt->cbSwpHeapInit, rc++);
+    if (options.cbSwpHeapMax != pOpt->cbSwpHeapMax)
+        printf("cbSwpHeapMax = %d - should be %d\n", options.cbSwpHeapMax, pOpt->cbSwpHeapMax, rc++);
+    if (options.cbResHeapInit != pOpt->cbResHeapInit)
+        printf("cbResHeapInit = %d - should be %d\n", options.cbResHeapInit, pOpt->cbResHeapInit, rc++);
+    if (options.cbResHeapMax != pOpt->cbResHeapMax)
+        printf("cbResHeapMax = %d - should be %d\n", options.cbResHeapMax, pOpt->cbResHeapMax, rc++);
+
+    return rc;
+}
Index: trunk/src/win32k/kKrnlLib/testcase/tstDH.asm
===================================================================
--- trunk/src/win32k/kKrnlLib/testcase/tstDH.asm	(revision 8210)
+++ 	(revision )
@@ -1,747 +1,0 @@
-; $Id: tstDH.asm,v 1.1 2002-03-30 17:05:46 bird Exp $
-;
-; Device Helper Router.
-; Stack Thunker.
-;
-; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-;
-; Project Odin Software License can be found in LICENSE.TXT
-;
-    .386
-
-
-;
-; Include files
-;
-    include devsegdf.inc
-    include devhlp.inc
-
-
-;
-; Exported symbols
-;
-    public  ThunkStack16To32
-    public  ThunkStack32To16
-    public  TKSSBase
-    public  getDHRouterFarPtr
-    ;public  DHRouter
-
-
-;
-; extrns
-;
-    extrn DOS32ALLOCMEM:PROC
-    extrn DOS32FREEMEM:PROC
-    extrn DOS16GETINFOSEG:PROC
-    extrn DOS16SYSTRACE:PROC
-    extrn _Device_Help:DWORD
-    extrn pulTKSSBase32:DWORD
-    extrn _TKSSBase16:DWORD
-    extrn _R0FlatCS16:WORD
-    extrn _R0FlatDS16:WORD
-
-
-
-
-CODE16 SEGMENT
-    ASSUME cs:CODE16, ds:FLAT
-
-
-
-;;
-; Devhelp routiner routine.
-; @cproto none
-; @param     dl     Devhelper routine.
-; @uses      none but the ones returned.
-; @sketch
-; @status
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark
-DHRouter PROC FAR
-    ASSUME cs:CODE16, ds:NOTHING, es:NOTHING, ss:NOTHING
-    ;
-    ; Preserve nearly everything (as a start)
-    ;
-    push    ds
-    push    es
-    push    fs
-    push    gs
-    push    edi
-    push    esi
-    push    ebp
-    push    edx
-    push    ecx
-    push    ebx
-
-
-    cmp     dl, DevHlp_RAS
-    jne     dhr0
-    call    dh_RAS
-    jmp     dhr_ret
-
-dhr0:
-    cmp     dl, DevHlp_VirtToLin
-    jne     dhr1
-    call    dh_VirtToLin
-    jmp     dhr_ret
-
-dhr1:
-    cmp     dl, DevHlp_VMAlloc
-    jne     dhr2
-    call    dh_VMAlloc
-    jmp     dhr_ret
-
-dhr2:
-    cmp     dl, DevHlp_VMFree
-    jne     dhr3
-    call    dh_VMFree
-    jmp     dhr_ret
-
-dhr3:
-    cmp     dl, DevHlp_GetDOSVar
-    jne     dhr4
-    call    dh_GetDOSVar
-    add     sp, 4                       ; remove ebx from stack
-    jmp     dhr_ret_ebx
-
-dhr4:
-    cmp     dl, DevHlp_VMLock
-    jne     dhr5
-    call    dh_VMLock
-    jmp     dhr_ret
-
-dhr5:
-    cmp     dl, DevHlp_VMUnlock
-    jne     dhr6
-    call    dh_VMUnlock
-    jmp     dhr_ret
-
-dhr6:
-    cmp     dl, DevHlp_VerifyAccess
-    jne     dhr7
-    call    dh_VerifyAccess
-    jmp     dhr_ret
-
-dhr7:
-
-dhr_notimplemented:
-    stc
-    mov     eax, 87 ;ERROR_INVALID_PARAMETER
-
-    ;
-    ; Restore nearly everything (as a start)
-    ;
-dhr_ret:
-    pop     ebx
-dhr_ret_ebx:
-    pop     ecx
-    pop     edx
-    pop     ebp
-    pop     esi
-    pop     edi
-    pop     gs
-    pop     fs
-    pop     es
-    pop     ds
-    ret
-DHRouter ENDP
-
-
-;;
-; Insert trace information to the system trace buffer.
-; @cproto   none
-; @param    AX      Major trace event code.
-; @param    BX      Length of data area.
-; @param    CX      Major trace event code.
-; @param    DS:SI   Pointer to trace data.
-; @returns  Success:
-;               CF      clear
-;               AX      ??
-;           Failure:
-;               CF      set
-;               AX      error code.
-; @uses      ax
-; @status    completely impelemented.
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-dh_RAS PROC NEAR
-    push    ax
-    push    bx
-    push    cx
-    push    ds
-    push    si
-
-    call far ptr DOS16SYSTRACE
-    or      ax, ax
-    jz      dh_RAS_ret
-    stc
-
-dh_RAS_ret:
-    ret
-dh_RAS ENDP
-
-
-;;
-; Converts a virtual (sel:off) address to a linear address.
-; @cproto    none
-; @param     AX     Selector
-; @param     ESI    Offset
-; @param     DL     DevHelp_VirtToLin
-; @returns   Success:
-;               CF      clear
-;               EAX     Linear address
-;
-;            Failure:
-;               CF      set
-;               EAX     Error code.
-;
-; @uses      eax
-; @status    completely impelemented.
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-dh_VirtToLin PROC NEAR
-    ASSUME cs:CODE16, ds:NOTHING, es:NOTHING, ss:NOTHING
-    shl     eax, SEL_FLAT_SHIFT
-    and     eax, SEL_FLATMASK
-    add     eax, esi
-vtl_retok:
-    clc
-    ret
-
-vtl_reterr:
-    stc
-    ret
-dh_VirtToLin ENDP
-
-
-
-
-;;
-; Allocates virtual memory.
-; @cproto    none
-; @param     ECX    Amount of memory to allocate.
-; @param     EDI    Pointer to DD var containing physical address to be mapped.
-;                   -1 if not used.
-; @param     EAX    Flags. These flags are supported:
-;                       VMDHA_SWAP
-;                       VMDHA_USEHIGHMEM
-;                       VMDHA_RESERVE
-; @param     DH     DevHlp_VMAlloc
-;
-; @returns   Success:
-;               CF      Clear
-;               EAX     Linear address of object.
-;
-;            Failure:
-;               CF      Set.
-;               EAX     Error code. ERROR_INVALID_PARAMETER.
-;
-; @uses      edx, ecx, eax
-; @equiv
-; @time
-; @sketch    For it into an call to DosAllocMem
-; @status
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark
-dh_VMAlloc PROC NEAR
-    ASSUME cs:CODE16, ds:NOTHING, es:NOTHING, ss:NOTHING
-
-; define the flags which are used here
-VMDHA_SWAP          EQU 0004h
-VMDHA_RESERVE       EQU 0100h
-VMDHA_USEHIGHMEM    EQU 0800h
-
-    ;
-    ; Check input parametes.
-    ;
-    mov     edx, eax
-    and     edx, NOT (VMDHA_SWAP OR VMDHA_USEHIGHMEM OR VMDHA_RESERVE)
-    jnz     vma_reterr                  ; Jump if unsupported flag(s) are set.
-    cmp     edi, 0ffffffffh             ; Check that EDI is -1.
-    jne     vma_reterr                  ; Jump if EDI != -1
-
-    jmp     far ptr FLAT:Thunk32_dh_VMAlloc
-Thunk16_dh_VMAlloc::
-    or      eax, eax                    ; Successful return from Dos32AllocMem?
-    jnz     vma_reterr                  ; Jump on failure.
-    mov     eax, edx                    ; EAX is now 32-bit pointer to the allocated memory.
-
-vma_retok:
-    clc
-    ret
-
-vma_reterr:
-    mov     eax, 87                     ; ERROR_INVALID_PARAMETER
-    stc
-    ret
-dh_VMAlloc ENDP
-CODE16 ENDS
-
-
-CODE32 SEGMENT
-Thunk32_dh_VMAlloc::
-    ASSUME cs:CODE32, ds:NOTHING, es:NOTHING, ss:NOTHING
-    ;
-    ; Call Dos32AllocMem to allocate the requested memory.
-    ;
-    push    eax                         ; Make space for return pointer.
-    mov     edx, esp                    ; Take address of return pointer.
-    test    edx, 0ffff0000h
-    jnz     vma_stack32                 ; Jump if stack is 32-bit
-    xor     edx, edx
-    mov     dx, ss                      ; Make 32-bit pointer to return pointer.
-    shl     edx, SEL_FLAT_SHIFT
-    and     edx, SEL_FLATMASK
-    mov     dx,  sp                     ; EDX is now 32-bit pointer to return pointer.
-vma_stack32:
-
-    test    eax, VMDHA_RESERVE
-    jz      vma1
-    push    0043h                       ; Flags: OBJ_TILE | PAG_READ | PAG_WRITE
-    jmp     vma2
-vma1:
-    push    0053h                       ; Flags: OBJ_TILE | PAG_COMMIT | PAG_READ | PAG_WRITE
-vma2:
-    push    ecx                         ; Number of bytes to allocate.
-    push    edx                         ; Pointer to return pointer.
-    call    DOS32ALLOCMEM
-    add     esp, 12
-    pop     edx                         ; Pointer to allocated memory if any...
-
-    jmp     far ptr CODE16:Thunk16_dh_VMAlloc
-CODE32 ENDS
-
-
-CODE16 SEGMENT
-;;
-; Frees memory allocated with VMAlloc.
-; @cproto    none
-; @param     EAX        Linear address of the memory to be freed.
-; @returns   Success:
-;               CF      Clear
-;
-;            Failure:
-;               CF      Set
-;               EAX     Errorcode
-;                       ERROR_ACCESS_DENIED
-;                       ERROR_INVALID_PARAMETER
-;
-; @uses      eax, ecx, edx
-; @status    completely implemented.
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-dh_VMFree PROC NEAR
-    ASSUME cs:CODE16, ds:NOTHING, es:NOTHING, ss:NOTHING
-    jmp     far ptr FLAT:Thunk32_dh_VMFree
-Thunk16_dh_VMFree::
-    or      eax, eax
-    jnz     vmf_reterr
-
-vmf_retok:
-    clc
-    ret
-
-vmf_reterr:
-    stc
-    ret
-dh_VMFree ENDP
-CODE16 ENDS
-
-
-CODE32 SEGMENT
-; 32-bit part of the dh_VMFree worker
-Thunk32_dh_VMFree::
-    ASSUME cs:CODE32, ds:NOTHING, es:NOTHING, ss:NOTHING
-    push    eax
-    call    DOS32FREEMEM
-    sub     esp, 4
-    jmp     far ptr CODE16:Thunk16_dh_VMFree
-CODE32 ENDS
-
-
-CODE16 SEGMENT
-;;
-; Get addresses of kernel variables.
-; @cproto    none.
-; @param     AL     Index.
-;                   These indexes are supported:
-;                       DHGETDOSV_SYSINFOSEG     1
-;                       DHGETDOSV_LOCINFOSEG     2
-;                       DHGETDOSV_YIELDFLAG      7
-;                       DHGETDOSV_TCYIELDFLAG    8
-;                       DHGETDOSV_DOSTABLE       9
-;
-;
-; @param     CX     VarMember (only index 14 and 16)
-; @param     DL     DevHlp_GetDOSVar
-; @returns   Success:
-;               CF      Clear
-;               AX:BX   Points to the index.
-;
-;            Failure:
-;               CF      Set.
-;
-; @uses     eax, ebx, ecx, edx
-; @sketch
-; @status
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark
-dh_GetDOSVar PROC NEAR
-    ASSUME cs:CODE16, ds:NOTHING, es:NOTHING, ss:NOTHING
-    cmp     al, 1
-    je      gdv_12
-    cmp     al, 2
-    je      gdv_12
-    cmp     al, 7
-    je      gdv_8
-    cmp     al, 8
-    je      gdv_8
-    cmp     al, 9
-    je      gdv_9
-    jmp     gdv_reterr
-
-gdv_12:
-    push    ax
-    push    ax                          ; make space for selGIS
-    mov     ax, sp                      ; offset selGIS
-    push    ax                          ; make space for selLIS
-    mov     bx, sp                      ; offset selLIS
-    push    ss
-    push    ax                          ; &selGIS
-    push    ss
-    push    bx                          ; &selLIS
-    call    far ptr DOS16GETINFOSEG
-    pop     bx                          ; selLIS
-    pop     cx                          ; selGIS
-    pop     dx                          ; index parameter
-    or      ax, ax                      ; Did it fail?
-    jnz     gdv_reterr                  ; Jump if it failed.
-    cmp     dx, 1
-    je      gdv_12_1
-    mov     bx, cx                      ; bx <- selGIS
-gdv_12_1:
-    xor     ax, ax
-    jmp     gdv_retok
-
-gdv_7:
-    mov     ebx, offset YieldFlag
-    mov     ax, seg YieldFlag
-    jmp     gdv_retok
-
-gdv_8:
-    mov     ebx, offset TCYieldFlag
-    mov     ax, seg TCYieldFlag
-    jmp     gdv_retok
-
-gdv_9:
-    mov     ebx, offset DosTable
-    mov     ax, seg DosTable
-    jmp     gdv_retok
-
-gdv_retok:
-    clc
-    ret
-
-gdv_reterr:
-    stc
-    ret
-dh_GetDOSVar ENDP
-CODE16 ENDS
-
-
-DATA16 SEGMENT
-;; GetDosVar data
-;
-; The two YieldFlags
-;
-YieldFlag                       db 0
-TCYieldFlag                     db 0
-DATA16 ENDS
-
-
-DATA32 SEGMENT
-;
-; 32-bit flat stack base.
-;
-TKSSBase                        dd 0
-DATA32 ENDS
-
-DATA16 SEGMENT
-    ASSUME ds:NOTHING, es:NOTHING, ss:NOTHING
-;
-; The two dostables.
-;
-DosTable                        db 17
-  DosTable_fph_HardError        dd 0
-  DosTable_fph_UCase            dd 0
-  DosTable_UnknownOrReserved1   dd 0
-  DosTable_UnknownOrReserved2   dd 0
-  DosTable_UnknownOrReserved3   dd 0
-  DosTable_fph_MemMapAlias      dd 0
-  DosTable_fph_MemUnmapAlias    dd 0
-  DosTable_fph_GoProtAll        dd 0
-  DosTable_fph_GoRealAll        dd 0
-  DosTable_fph_doshlp_RedirDev  dd 0
-  DosTable_UnknownOrReserved4   dd 0
-  DosTable_UnknownOrReserved5   dd 0
-  DosTable_fph_SFFromSFN        dd 0
-  DosTable_fph_SegGetInfo       dd 0
-  DosTable_fph_AsgCheckDrive    dd 0
-  DosTable_UnknownOrReserved6   dd 0
-  DosTable_UnknownOrReserved7   dd 0
-
-DosTabel2                       db  19
-  DosTable2_fpErrMap24          dd 0
-  DosTable2_fpErrMap24End       dd 0
-  DosTable2_fpErr_Table_24      dd 0
-  DosTable2_fpCDSAddr           dd 0
-  DosTable2_fpGDT_RDR1          dd 0
-  DosTable2_fpInterrupLevel     dd 0
-  DosTable2_fp_cInDos           dd 0
-  DosTable2_UnknownOrReserved1  dd 0
-  DosTable2_UnknownOrReserved2  dd 0
-  DosTable2_R0FlatCS            dw seg FLAT:CODE32
-                                dw 0
-  DosTable2_R0FlatDS            dw seg FLAT:DATA32
-                                dw 0
-  DosTable2_pTKSSBase           dd offset FLAT:DATA32:TKSSBase
-  DosTable2_pintSwitchStack     dd 0
-  DosTable2_pprivatStack        dd 0
-  DosTable2_fpPhysDiskTablePtr  dd 0
-  DosTable2_pforceEMHandler     dd 0
-  DosTable2_pReserveVM          dd 0
-  DosTable2_p_pgpPageDir        dd 0
-  DosTable2_UnknownOrReserved3  dd 0
-DATA16 ENDS
-
-
-CODE16 SEGMENT
-
-
-;;
-; VMLock stub.
-; @returns  NO_ERROR. (0)
-; @param    ignored.
-; @uses     eax
-; @status   stub.
-; @author   knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-dh_VMLock PROC NEAR
-    xor     eax, eax
-    clc
-    ret
-dh_VMLock ENDP
-
-
-
-;;
-; VMUnlock stub.
-; @returns  NO_ERROR. (0)
-; @param    ignored.
-; @uses     eax
-; @status   stub.
-; @author   knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-dh_VMUnlock PROC NEAR
-    xor     eax, eax
-    clc
-    ret
-dh_VMUnlock ENDP
-
-
-;;
-; VerifyAccess stub.
-; @returns  NO_ERROR. (0)
-; @param    ignored.
-; @uses     eax
-; @status   stub.
-; @author   knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-dh_VerifyAccess PROC NEAR
-    xor     eax, eax
-    clc
-    ret
-dh_VerifyAccess ENDP
-
-
-CODE16 ENDS
-
-
-
-
-CODE32 SEGMENT
-;;
-; Initiates the Device_Help function pointer.
-;
-; During startup the C library startup routines needs to use the heap.
-; So the heap has to work before main is able to initiate it. The heap
-; uses device helpers so they have to be initiated too. So, this init
-; routine is called during heap init, _rmem_init.
-;
-; @cproto    void _Optlink dhinit(void)
-; @returns   NO_ERROR.
-; @param     none.
-; @uses      eax
-; @sketch
-; @status    completly implemented
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark
-dhinit PROC NEAR
-    ASSUME cs:CODE32, ds:FLAT, es:NOTHING, ss:NOTHING
-    ;
-    ; _Device_Help - d16globl.c
-    ;
-if 0 ;done during device init.
-    mov     ax, seg DHRouter
-    shl     eax, 16
-    mov     ax, offset DHRouter
-    mov     _Device_Help, eax
-endif
-
-    ;
-    ; pulTKSSBase32
-    ; DosTable2_pTKSSBase
-    ; DosTable2_R0FlatCS
-    ; DosTable2_R0FlatDS
-    ;
-    mov     eax, offset FLAT:TKSSBase
-    mov     pulTKSSBase32, eax          ; We need it as our testing subsystem uses it too.
-if 0 ; not neede any longer
-    ;mov     DosTable2_pTKSSBase, eax
-    ;mov     _TKSSBase16, eax
-
-    ;xor     eax, eax
-    ;mov     ax, seg FLAT:CODE32
-    ;mov     DosTable2_R0FlatCS, ax
-    ;mov     _R0FlatCS16, ax
-
-    ;mov     ax, seg FLAT:DATA32
-    ;mov     DosTable2_R0FlatDS, ax
-    ;mov     _R0FlatDS16, ax
-endif
-
-    ;
-    ; return NO_ERROR
-    ;
-    xor     eax, eax
-    ret
-dhinit ENDP
-
-
-;;
-; Gets the a 16-bit far pointer to the DHRouter routine.
-; @cproto    ULONG  _Optlink getDHRouterFarPtr(VOID); /* dh.asm */
-; @returns   16-bit far pointer to the DHRouter routine.
-; @uses      EAX
-; @status    completely implemented.
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark
-getDHRouterFarPtr PROC NEAR
-    ASSUME cs:CODE32, ds:FLAT, es:NOTHING, ss:NOTHING
-    mov     ax, seg CODE16:DHRouter
-    shl     eax, 16
-    mov     ax, offset CODE16:DHRouter
-    ret
-getDHRouterFarPtr ENDP
-
-
-
-
-
-;;
-; Thunks the stack from 16-bits to 32-bits.
-; !The stack has to be 16-bits on entry!
-; @cproto    VOID _Optlink ThunkStack16To32(VOID)
-; @returns   void
-;            Stack is 32-bits!
-;            EBP and SS:ESP is thunked
-;
-; @uses      EAX, EDX
-; @sketch
-; @status    completly implemented.
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark    RING 3 only.
-ThunkStack16To32 PROC NEAR
-    ASSUME cs:CODE32, ds:FLAT, es:NOTHING, ss:NOTHING
-    movzx   esp, sp                     ; Make sure high end of esp is zero.
-    mov     ax, ss                      ; Find the linary base of the segment addressed by ss.
-    shl     eax, SEL_FLAT_SHIFT
-    and     eax, SEL_FLATMASK
-    mov     ax, sp                      ; Add the segment offset, which is sp.
-                                        ; eax is now the linear stack address equal to ss:sp.
-
-    mov     dx, seg FLAT:DATA32         ; ALP bug? Can't: push seg FLAT:DATA32
-                                        ; Have to move it to dx before pushing it.
-    push    dx                          ; Make lss quad word: new ss, new esp
-    push    eax
-    lss     esp, ss:[esp]               ; load new ss and esp values.
-
-    ;
-    ; Fix ebp
-    ; Creates new ebp from high word of esp and low word of ebp.
-    ;
-    mov     eax, esp
-    mov     ax, bp
-    mov     ebp, eax
-
-    ;
-    ; Update TKSSBase
-    ;
-    push    ds
-    mov     ds, dx
-    ASSUME  ds:FLAT
-    mov     TKSSBase, 0
-    pop     ds
-    ret
-ThunkStack16To32 ENDP
-
-
-;;
-; Thunks the stack from 32-bits to 16-bits.
-; !The stack has to be 32-bits on entry!
-; @cproto    VOID _Optlink ThunkStack32To16(VOID)
-; @returns   void
-;            Stack is 16-bits!
-;            EBP and SS:ESP is thunked
-;
-; @uses      EAX, EDX
-; @sketch
-; @status    completly implemented.
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark    RING 3 only.
-ThunkStack32To16 PROC NEAR
-    ASSUME cs:CODE32, ds:FLAT, es:NOTHING, ss:NOTHING
-
-    mov     edx, esp                    ; save esp for later use (setting TKSSBase).
-
-    ;
-    ; calc LDT selector from linear esp and load new ss:esp.
-    ;
-    mov     eax, esp
-    shr     eax, SEL_FLAT_SHIFT
-    or      ax,  SEL_LDT_RPL3           ; ax new ss LDT (RING3).
-    rol     eax, 16
-    mov     ax, sp
-    push    eax
-    lss     sp, dword ptr [esp]         ; load ss:sp.
-    movzx   esp, sp                     ; Zero upper part of esp.
-                                        ; Stack is now 16 bits
-    ;
-    ; Fix ebp
-    ;
-    movzx   ebp, bp                     ; Zero upper part of ebp.
-
-    ;
-    ; Update TKSSBase
-    ;
-    push    ds
-    mov     ax, seg FLAT:DATA32
-    mov     ds, ax
-    ASSUME  ds:FLAT
-    xor     dx, dx                      ; zero lower word of dx to get linear
-                                        ; address of 16-bits stack base
-    mov     TKSSBase, edx
-    pop     ds
-
-    ret
-ThunkStack32To16 ENDP
-
-
-CODE32 ENDS
-
-end
-
Index: trunk/src/win32k/kKrnlLib/testcase/tstDos.c
===================================================================
--- trunk/src/win32k/kKrnlLib/testcase/tstDos.c	(revision 8210)
+++ 	(revision )
@@ -1,149 +1,0 @@
-/* $Id: tstDos.c,v 1.1 2002-03-30 17:05:46 bird Exp $
- *
- * Thunkers for OS/2 APIs.
- *
- * Some APIs requires Linear Stack, some have to overridden to
- * emulate different things.
- *
- * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- *
- * Project Odin Software License can be found in LICENSE.TXT
- *
- */
-
-/*******************************************************************************
-*   Defined Constants And Macros                                               *
-*******************************************************************************/
-#define INCL_BASE
-#define INCL_NO_FAKE
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#include <os2.h>
-
-#include "devSegDf.h"                   /* kKrnlLib segment definitions. */
-
-#include "testcase.h"
-
-
-/*******************************************************************************
-*   External Functions                                                         *
-* (These are prototypes for functions in the IMPORTS section of the def-file.) *
-*******************************************************************************/
-APIRET  APIENTRY        _DosWrite(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual);
-APIRET  APIENTRY        _DosClose(HFILE hFile);
-APIRET  APIENTRY        _DosOpen(
-                            PSZ     pszFileName,
-                            PHFILE  pHf,
-                            PULONG  pulAction,
-                            ULONG   cbFile,
-                            ULONG   ulAttribute,
-                            ULONG   fsOpenFlags,
-                            ULONG   fsOpenMode,
-                            PEAOP2  peaop2);
-APIRET  APIENTRY        _DosSetFilePtr(
-                            HFILE   hFile,
-                            LONG    ib,
-                            ULONG   method,
-                            PULONG  ibActual);
-
-/**
- * DosWrite overload. Ensures that the stack is 32-bit!
- */
-APIRET  APIENTRY        DosWrite(HFILE hFile, PVOID pBuffer, ULONG cbWrite, PULONG pcbActual)
-{
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-    APIRET  rc;
-    if (!f32Stack)
-        ThunkStack16To32();
-
-    rc = _DosWrite(hFile, pBuffer, cbWrite, pcbActual);
-
-    if (!f32Stack)
-        ThunkStack32To16();
-
-    return rc;
-}
-
-
-/**
- * DosClose overload. Ensures that the stack is 32-bit!
- */
-APIRET  APIENTRY        DosClose(HFILE hFile)
-{
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-    APIRET  rc;
-    if (!f32Stack)
-        ThunkStack16To32();
-
-    rc = _DosClose(hFile);
-
-    if (!f32Stack)
-        ThunkStack32To16();
-
-    return rc;
-}
-
-
-/**
- * DosOpen overload. Ensures that the stack is 32-bit!
- */
-APIRET  APIENTRY        DosOpen(
-                            PSZ    pszFileName,
-                            PHFILE pHf,
-                            PULONG pulAction,
-                            ULONG  cbFile,
-                            ULONG  ulAttribute,
-                            ULONG  fsOpenFlags,
-                            ULONG  fsOpenMode,
-                            PEAOP2 peaop2)
-{
-    BOOL    f32Stack = ((int)&cbFile > 0x10000);
-    APIRET  rc;
-    if (!f32Stack)
-        ThunkStack16To32();
-
-    rc = _DosOpen(pszFileName,
-                   pHf,
-                   pulAction,
-                   cbFile,
-                   ulAttribute,
-                   fsOpenFlags,
-                   fsOpenMode,
-                   peaop2);
-
-    if (!f32Stack)
-        ThunkStack32To16();
-
-    return rc;
-}
-
-
-/**
- * DosSetFilePtr overload. Ensures that the stack is 32-bit!
- */
-APIRET  APIENTRY        DosSetFilePtr(
-                            HFILE   hFile,
-                            LONG    ib,
-                            ULONG   method,
-                            PULONG  ibActual)
-{
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-    APIRET  rc;
-    if (!f32Stack)
-        ThunkStack16To32();
-
-    rc = _DosSetFilePtr(hFile,
-                        ib,
-                        method,
-                        ibActual);
-
-    if (!f32Stack)
-        ThunkStack32To16();
-
-    return rc;
-}
-
-
-
Index: trunk/src/win32k/kKrnlLib/testcase/tstDosA.asm
===================================================================
--- trunk/src/win32k/kKrnlLib/testcase/tstDosA.asm	(revision 8210)
+++ 	(revision )
@@ -1,294 +1,0 @@
-; $Id: tstDosA.asm,v 1.2 2002-03-31 19:01:19 bird Exp $
-;
-; 16-bits Dos calls overloader
-;
-; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-;
-; Project Odin Software License can be found in LICENSE.TXT
-;
-    .386
-
-
-;
-; Include files
-;
-    include devsegdf.inc
-    INCL_DOSERRORS EQU 1
-    include os2.inc
-    include devsym.inc
-
-
-;
-; Exported symbols
-;
-    public  DOS16OPEN
-    public  DOS16CLOSE
-    public  DOS16DEVIOCTL
-
-
-;
-; extrns
-;
-    extrn   _strategyAsm0:FAR
-    extrn   _DOS16OPEN:FAR     ;70
-    extrn   _DOS16CLOSE:FAR    ;59
-
-    extrn   ThunkStack16To32:PROC
-    extrn   ThunkStack32To16:PROC
-    extrn   TKSSBase:PROC
-
-    extrn   _TKSSBase16:DWORD
-    extrn   _R0FlatCS16:WORD
-    extrn   _R0FlatDS16:WORD
-
-DATA16 SEGMENT
-szDevName   db  "\dev\$KrnlHlp",0
-szDevNameEnd db 0
-DATA16 ENDS
-
-
-
-CODE16 SEGMENT
-    ASSUME cs:CODE16, ds:DATA16
-
-hkKrnlHlp  EQU     0fE1Fh               ; Value of the kKrnlHlp handle
-
-;;
-; Fake opening of kKrnlHlp
-;
-; PASCAL convention: Parameters pushed left to right of C prototype.
-;                    We'll have to do the cleanup.
-;
-; @cproto APIRET  APIENTRY  DosOpen(
-;                               PSZ     pszFname,
-;                               PHFILE  phfOpen,
-;                               PUSHORT pusAction,
-;                               ULONG   ulFSize,
-;                               USHORT  usAttr,
-;                               USHORT  fsOpenFlags,
-;                               USHORT  fsOpenMode,
-;                               ULONG   ulReserved);
-;
-; @returns
-; @param     pszFname       bp +1c  dd
-; @param     phfOpen        bp +18  dd
-; @param     pusAction      bp +14  dd
-; @param     ulFSize        bp +10  dd
-; @param     usAttr         bp + e  dw
-; @param     fsOpenFlags    bp + c  dw
-; @param     fsOpenMode     bp + a  dw
-; @param     ulReserved     bp + 6  dd
-;
-; @uses
-; @equiv
-; @time
-; @sketch
-; @status
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark
-DOS16OPEN PROC FAR
-    ASSUME CS:CODE16, DS:NOTHING, ES:NOTHING, SS:NOTHING
-    push    bp
-    mov     bp, sp
-
-    ;
-    ; Is this an attempt to open the kKrnlHlp device driver?
-    ;
-    push    ds
-    push    es
-    push    si
-    push    di
-    push    cx
-
-    lds     si, [bp + 1ch]
-    mov     di, seg szDevName
-    mov     es, di
-    mov     di, offset szDevName
-    mov     cx, offset szDevNameEnd - offset szDevName
-    repe cmpsb
-    jne     do_notkKrnlHlp
-
-    ;
-    ; found filename string equal to "\dev\kKrnlHlp".
-    ;
-    ; return phFile equal to kKrnlHlp handle and pusAction set to 1 (FILE EXISTED).
-    ;
-    lds     di, [bp + 18h]
-    mov     word ptr ds:[di], hkKrnlHlp ; *phFile <- hkKrnlHlp
-    lds     di, [bp + 14h]
-    mov     word ptr ds:[di], 1         ; *pusAction <- File existed.
-
-    ; return successfully.
-    xor     eax, eax
-
-do_ret:
-    ;
-    ; restore registers and return.
-    ;
-    pop     cx
-    pop     di
-    pop     si
-    pop     es
-    pop     ds
-    leave
-    ret     01ah
-
-do_notkKrnlHlp:
-    push    dword ptr [bp +01ch]
-    push    dword ptr [bp +018h]
-    push    dword ptr [bp +014h]
-    push    dword ptr [bp +010h]
-    push    word  ptr [bp + 0eh]
-    push    word  ptr [bp + 0ch]
-    push    word  ptr [bp + 0ah]
-    push    dword ptr [bp + 06h]
-    call far ptr _DOS16OPEN
-    jmp do_ret
-DOS16OPEN ENDP
-
-
-;;
-; Fake close of kKrnlHlp
-; @cproto    APIRET  APIENTRY DosClose(HFILE hf);
-; @returns   OS/2 return code. (NO_ERROR)
-; @param     hFile  bp + 6
-; @uses      EAX
-; @status    completly implemented.
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-DOS16CLOSE PROC FAR
-    ASSUME CS:CODE16, DS:NOTHING, ES:NOTHING, SS:NOTHING
-    push    bp
-    mov     bp, sp
-
-    ;
-    ; Is it the kKrnlHlp handle?
-    ;
-    mov     ax, [bp + 6]
-    cmp     ax, hkKrnlHlp
-    jne     dc_notkKrnlHlp
-    xor     eax, eax
-    leave
-    ret     2
-
-dc_notkKrnlHlp:
-    push    word ptr [bp + 6]           ; can't jump to higher privilege
-    call    _DOS16CLOSE
-    leave
-    ret     2
-DOS16CLOSE ENDP
-
-
-
-;;
-;
-; @cproto    APIRET  APIENTRY   DosDevIOCtl(
-;                                   PVOID   pData,
-;                                   PVOID   pParms,
-;                                   USHORT  usFun,
-;                                   USHORT  usCategory,
-;                                   HFILE   hDev);
-; @returns
-; @param     pData       bp +10 dd
-; @param     pParms      bp + c dd
-; @param     usFun       bp + a dw
-; @param     usCategory  bp + 8 dw
-; @param     hDev        bp + 6 dw
-; @param
-; @uses      eax
-; @sketch
-; @status    completly implemented
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark
-DOS16DEVIOCTL PROC FAR
-    ASSUME CS:CODE16, DS:NOTHING, ES:NOTHING, SS:NOTHING
-    LOCAL   pkt:Packet
-
-    push    bx
-    push    es
-
-
-    ;
-    ; Check that it really is the kKrnlHlp handle.
-    ;
-    mov     ax, word ptr [bp + 6]
-    cmp     word ptr [bp + 6], hkKrnlHlp
-    jne     ddioc_invalidhandle
-
-    ;
-    ; Then we'll have to call _strategyAsm0. But first will have to
-    ; build a request packet for this IOCtl
-    ;
-    mov     pkt.PktLen, LENGenIOCTL     ; PktLen          db      ?               ; length in bytes of packet
-    mov     pkt.PktUnit, 0              ; PktUnit         db      ?               ; subunit number of block device
-    mov     pkt.PktCmd, CMDGenIOCTL     ; PktCmd          db      ?               ; command code
-    mov     pkt.PktStatus, 0            ; PktStatus       dw      ?               ; status word
-    mov     pkt.PktFlag, 0              ; PktFlag         db      ?               ; disk driver internal flags
-    mov     pkt.PktFlag+1, 0            ;                 db      3 dup(?)        ; reserved
-    mov     pkt.PktFlag+2, 0            ;
-    mov     pkt.PktFlag+3, 0            ;
-    mov     pkt.PktDevLink, 0           ; PktDevLink      dd      ?               ; device multiple-request link
-    mov     ax, [bp + 8]
-    mov     byte  ptr pkt.PktData + 0, al   ; Category Code
-    mov     ax, [bp + 0ah]
-    mov     byte ptr pkt.PktData + 1, al    ; Function code
-    mov     eax, [bp + 0ch]
-    mov     dword ptr pkt.PktData + 2, eax  ; pointer to parameter packet
-    mov     eax, [bp + 10h]
-    mov     dword ptr pkt.PktData + 6, eax  ; pointer to data packet
-    mov     word ptr  pkt.PktData + 10, 0   ; SFN of the driver.
-
-    ; do the call - who cleans up the stack?
-    mov     bx, ss
-    mov     es, bx
-    lea     bx, pkt
-    ;call    far ptr _strategyAsm0      ; why did this make it into a 16:32 call?
-    call    far ptr CODE16:_strategyAsm0
-
-    ;
-    ; We'll check if the status to see wether it failed or not.
-    ;
-    test    pkt.PktStatus, STERR
-    jnz     ddioc_error
-    test    pkt.PktStatus, STDON
-    jz      ddioc_notdone
-    test    pkt.PktStatus, STINTER
-    jnz     ddioc_interchar
-    test    pkt.PktStatus, STBUI
-    jnz     ddioc_busy
-    xor     eax, eax                    ; return NO_ERROR
-    jmp ddioc_ret
-
-ddioc_error:
-    mov     ax, pkt.PktStatus
-    and     ax, STECODE
-    jmp ddioc_ret
-
-ddioc_notdone:
-    mov     eax, 31                     ; ERROR_GEN_FAILURE
-    jmp ddioc_ret
-
-ddioc_interchar:
-    mov     eax, 31                     ; ERROR_GEN_FAILURE
-    jmp ddioc_ret
-
-ddioc_busy:
-    mov     eax, 31                     ; ERROR_GEN_FAILURE
-    jmp ddioc_ret
-
-ddioc_invalidhandle:
-    mov     eax, 6                      ; ERROR_INVALID_HANDLE
-    jmp     ddioc_ret
-
-ddioc_ret:
-    pop     es
-    pop     bx
-    leave
-    ret     0eh
-DOS16DEVIOCTL ENDP
-
-
-
-CODE16 ENDS
-
-END
-
Index: trunk/src/win32k/kKrnlLib/testcase/tstFake.c
===================================================================
--- trunk/src/win32k/kKrnlLib/testcase/tstFake.c	(revision 8210)
+++ 	(revision )
@@ -1,2664 +1,0 @@
-/* $Id: tstFake.c,v 1.1 2002-03-30 17:05:46 bird Exp $
- *
- * Fake stubs for the ldr and kernel functions we imports or overloads.
- *
- * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- *
- * Project Odin Software License can be found in LICENSE.TXT
- *
- */
-#ifndef NOFILEID
-static const char szFileId[] = "$Id: tstFake.c,v 1.1 2002-03-30 17:05:46 bird Exp $";
-#endif
-
-/*******************************************************************************
-*   Defined Constants And Macros                                               *
-*******************************************************************************/
-#define INCL_BASE
-#define INCL_KKL_LOG
-#define INCL_KKL_PRINTF
-#define INCL_OS2KRNL_ALL
-#define FOR_EXEHDR 1                    /* To make all object flags OBJ???. */
-#define DWORD  ULONG
-#define WORD   USHORT
-
-#define DUMMY()     volatile int dummy1, dummy2; \
-                    dummy1 = 23; \
-                    dummy2 = 42; \
-                    dummy1 = dummy1 + 1 + dummy2;
-
-#define Assert(expr) \
-        if (!(expr))                                                                \
-        {                                                                           \
-            printf("%s(%d) - %s: %s\n", __FILE__, __FUNCTION__, __LINE__, #expr);   \
-            INT3();                                                                 \
-        }
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
-#include <os2.h>
-#include <newexe.h>                     /* OS/2 NE structs and definitions. */
-#include <exe386.h>                     /* OS/2 LX structs and definitions. */
-
-#include <string.h>
-
-#include "devSegDf.h"                   /* kKrnlLib segment definitions. */
-
-#include <kKrnlLib.h>
-#include <OS2Krnl.h>
-#include "dev32.h"
-#include "testcase.h"
-#include "kLib/kTypes.h"
-
-#include "kKLmalloc.h"
-
-/*******************************************************************************
-*   Structures and Typedefs                                                    *
-*******************************************************************************/
-typedef struct ldrrei_s /* #memb 7 size 20 (0x014) - from 14040W4 kernel.sdf */
-{
-    PVOID                   ei_startaddr;      /* off:   0(00)  size:  4(04) */
-    PVOID                   ei_stackaddr;      /* off:   4(04)  size:  4(04) */
-    PVOID                   ei_pstackmax;      /* off:   8(08)  size:  4(04) */
-    USHORT                  ei_ds;             /* off:  12(0c)  size:  2(02) */
-    USHORT                  ei_stacksize;      /* off:  14(0e)  size:  2(02) */
-    USHORT                  ei_heapsize;       /* off:  16(10)  size:  2(02) */
-    USHORT                  ei_loadtype;       /* off:  18(12)  size:  2(02) */
-} ldrrei_t;
-
-
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-/*
- * Pointer to the loader semaphore.
- */
-KSEMMTX         fakeLdrSem;
-
-CHAR            szBeginLibPath[1024];
-CHAR            szEndLibPath[1024];
-CHAR            szLibPath[1024];
-PSZ             fakeLDRLibPath = &szLibPath[0];
-
-CHAR            szldrpFileNameBuf[CCHMAXPATH];
-PSZ             fakeldrpFileNameBuf = &szldrpFileNameBuf[0];
-
-static CHAR     achHeaderBuffer[256];   /* Buffer to read exe header into. */
-PVOID           pheaderbuf = &achHeaderBuffer[0];
-
-/*
- * Mte list pointers.
- */
-PMTE            fakemte_h;
-PMTE            fakeglobal_h;
-PMTE            fakeglobal_l;
-PMTE            fakespecific_h;
-PMTE            fakespecific_l;
-PMTE            fakeprogram_h;
-PMTE            fakeprogram_l;
-
-
-/*
- * table use by fakeldrMTEValidatePtrs.
- */
-USHORT          validatetbl[] =
-{
-    FIELDOFFSET(SMTE, smte_objmap),
-    FIELDOFFSET(SMTE, smte_rsrctab),
-    FIELDOFFSET(SMTE, smte_restab),
-    FIELDOFFSET(SMTE, smte_enttab),
-    FIELDOFFSET(SMTE, smte_fpagetab),
-    FIELDOFFSET(SMTE, smte_frectab),
-    FIELDOFFSET(SMTE, smte_impmod),
-    FIELDOFFSET(SMTE, smte_impproc),
-    0xDEAD
-};
-
-
-/*
- * More fake variables.
- */
-ULONG fakeSMcDFInuse;
-ULONG fakesmFileSize;
-ULONG fakeSMswapping;
-ULONG fakesmcBrokenDF;
-ULONG fakepgPhysPages;
-ULONG fakeSMcInMemFile;
-ULONG fakeSMCFGMinFree;
-ULONG fakesmcGrowFails;
-ULONG fakePGSwapEnabled;
-ULONG fakepgcPageFaults;
-ULONG fakeSMCFGSwapSize;
-ULONG fakepgResidentPages;
-ULONG fakepgSwappablePages;
-ULONG fakepgDiscardableInmem;
-ULONG fakepgDiscardablePages;
-ULONG fakeSMMinFree;
-ULONG fakepgcPageFaultsActive;
-ULONG fakepgPhysMax;
-ULONG fakeVirtualAddressLimit;
-
-VMAH  fakeahvmShr;
-VMAH  fakeahvmSys;
-VMAH  fakeahvmhShr;
-
-
-
-/*******************************************************************************
-*   External Functions                                                         *
-*******************************************************************************/
-#define QHINF_EXEINFO       1 /* NE exeinfo. */
-#define QHINF_READRSRCTBL   2 /* Reads from the resource table. */
-#define QHINF_READFILE      3 /* Reads from the executable file. */
-#define QHINF_LIBPATHLENGTH 4 /* Gets the libpath length. */
-#define QHINF_LIBPATH       5 /* Gets the entire libpath. */
-#define QHINF_FIXENTRY      6 /* NE only */
-#define QHINF_STE           7 /* NE only */
-#define QHINF_MAPSEL        8 /* NE only */
-
-APIRET APIENTRY DosQueryHeaderInfo(HMODULE hmod,
-                                   ULONG   ulIndex,
-                                   PVOID   pvBuffer,
-                                   ULONG   cbBuffer,
-                                   ULONG   ulSubFunction);
-
-/*******************************************************************************
-*   Internal Functions                                                         *
-*******************************************************************************/
-#pragma info(nopar)
-ULONG LDRCALL   fakeLDRLoadExe(PSZ pszFilename, ldrrei_t *pEI);
-ULONG LDRCALL   fakeldrGetModule(PSZ pszFilename, ULONG ul);
-ULONG LDRCALL   fakeldrGetMte(PCHAR pachFilename, USHORT cchFilename, UCHAR fchType, UCHAR fchClass, PPMTE ppmte);
-ULONG LDRCALL   fakeldrOpenNewExe(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PUSHORT pus);
-ULONG LDRCALL   fakeldrCreateMte(struct e32_exe * pe32, ldrlv_t *plv);
-ULONG LDRCALL   fakeldrLoadImports(PMTE pmte);
-ULONG LDRCALL   fakeldrMTEValidatePtrs(PSMTE psmte, ULONG ulMaxAddr, ULONG off);
-unsigned short  getSlot(void);
-
-
-
-/**
- * Initiate workers (imported kernel functions / vars)
- * @status    partially implemented.
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-void  workersinit(void)
-{
-    KLOGENTRY0("void");
-    APIRET rc;
-
-    /*
-     * Make code writable.
-     */
-    DosSetMem(&CODE16START, &CODE16END - &CODE16START, PAG_WRITE | PAG_READ);
-    DosSetMem(&CODE32START, &CODE32END - &CODE32START, PAG_WRITE | PAG_READ);
-
-    /*
-     * Loader semaphore
-     */
-    fakeKSEMInit((PKSEM)(void*)&fakeLdrSem, KSEM_MUTEX, KSEM_DEFAULT);
-
-    /*
-     * Intra process semaphore.
-     */
-    fakeKSEMInit((PKSEM)(void*)&fakeptda_ptdasem, KSEM_MUTEX, KSEM_DEFAULT);
-
-    /*
-     * LIBPaths
-     */
-    rc = DosQueryExtLIBPATH(szBeginLibPath, BEGIN_LIBPATH);
-    rc = DosQueryHeaderInfo(NULLHANDLE, 0, szLibPath, sizeof(szLibPath), QHINF_LIBPATH);
-    rc = DosQueryExtLIBPATH(szEndLibPath, END_LIBPATH);
-
-    if (_usFakeVerMinor < 45)
-        fakeVirtualAddressLimit = 0xFFFFFFFF;
-    else
-        fakeVirtualAddressLimit = 0x80000000;
-
-
-    if (fakeVirtualAddressLimit != 0xFFFFFFFF)
-    {   /* high memory supported */
-        fakeahvmSys.ah_laddrMax = 0xFFFE0000;
-        fakeahvmSys.ah_laddrMin = 0x80000000;
-        fakeahvmShr.ah_laddrMin = 0x08000000;
-        fakeahvmhShr.ah_laddrMin = 0x70000000;
-    }
-    else
-    {   /* high memory not supported */
-        fakeahvmSys.ah_laddrMax = 0xFFFE0000;
-        fakeahvmSys.ah_laddrMin = 0x40000000;
-        fakeahvmShr.ah_laddrMin = 0x08000000;
-        fakeahvmhShr.ah_laddrMin = 0xffffffff;
-    }
-
-    rc = rc;
-    KLOGEXITVOID();
-}
-
-
-/**
- * Fake ldrClose
- * @returns OS2 return code.
- * @param   hFile    Filehandle of the file to be closed.
- * @status  completely impelemented.
- * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG LDRCALL fakeldrClose(SFN hFile)
-{
-    KLOGENTRY1("ULONG LDRCALL","SFN hFile", hFile);
-    APIRET  rc;
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    rc =  DosClose(hFile);
-
-    if (!f32Stack) ThunkStack32To16();
-
-    printf("fakeldrClose:                   hFile = 0x%04x, rc = %d\n", hFile, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-/**
- * Fake ldrOpen.
- * @returns   OS2 return code.
- * @param     phFile        Pointer to return handle.
- * @param     pszFilename   Pointer to filename.
- * @param     pfl           Pointer to media flags? *pfl is set to zero!
- * @sketch    Do a DosOpen on the filename.
- * @status    partially implemented.
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG LDRCALL fakeldrOpen(PSFN phFile, PSZ pszFilename, PULONG pfl)
-{
-    KLOGENTRY3("ULONG LDRCALL","PSFN phFile, PSZ pszFilename, PULONG pfl", phFile, pszFilename, pfl);
-    ULONG   ulAction;
-    HFILE   hFile;
-    APIRET  rc;
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    hFile = 0;
-    ulAction = 0;
-    rc =  DosOpen(pszFilename, &hFile, &ulAction, 0, FILE_NORMAL,
-                  OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
-                  OPEN_ACCESS_READONLY | OPEN_SHARE_DENYWRITE,
-                  NULL);
-    if (rc == NO_ERROR)
-    {
-        *phFile = (USHORT)hFile;
-        if (pfl != NULL)
-            *pfl = 0;
-        rc = DosQueryPathInfo(pszFilename, FIL_QUERYFULLNAME, fakeldrpFileNameBuf, CCHMAXPATH);
-        rc = NO_ERROR;
-    }
-
-    if (!f32Stack) ThunkStack32To16();
-
-    printf("fakeldrOpen:                    phFile = %p; *phFile = 0x%04x, pszFilename = %s, pfl = %p, rc = %d\n",
-           phFile, *phFile, pszFilename, pfl, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * ldrRead fake.
- * @returns   OS/2 return code. (NO_ERROR on success...)
- * @param     hFile     Handle to file.
- * @param     ulOffset  Offset in the file to start reading at.
- * @param     pvBuffer  Pointer to output buffer.
- * @param     fpBuffer  Far pointer to buffer. (ignored)
- * @param     cbToRead  Count of bytes to read.
- * @param     pMTE      MTE pointer (used for caching?)
- *
- * @sketch    Set Change filepointer to ulOffset.
- *            Read cbToRead into pvBufer.
- * @status    completely tested.
- * @author    knut st. osmundsen
- * @remark
- */
-ULONG LDRCALL fakeldrRead(SFN hFile, ULONG ulOffset, PVOID pvBuffer, ULONG fpBuffer, ULONG cbToRead, PMTE pMTE)
-{
-    KLOGENTRY6("ULONG LDRCALL","SFN hFile, ULONG ulOffset, PVOID pvBuffer, ULONG fpBuffer, ULONG cbToRead, PMTE pMTE", hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE);
-    ULONG   cbRead,
-            ulMoved;
-    APIRET  rc;
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    rc = DosSetFilePtr(hFile, ulOffset, FILE_BEGIN, &ulMoved);
-    if (rc == NO_ERROR)
-        rc = DosRead(hFile, pvBuffer, cbToRead, &cbRead);
-    else
-        kprintf(("DosSetFilePtr(hfile, 0x%08x(%d),..) failed with rc = %d.\n",
-                 ulOffset, ulOffset, rc));
-
-    if (!f32Stack) ThunkStack32To16();
-
-    printf("fakeldrRead:                    hFile = 0x%04x, ulOffset = 0x%08x, pvBuffer = %p, fpBuffer = 0x%08x, cbToRead = 0x%08x, pMte = %p, rc = %d\n",
-           hFile, ulOffset, pvBuffer, fpBuffer, cbToRead, pMTE, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * LDRQAppType faker.
- * @returns   OS/2 return code.
- * @param     pszFilename   Pointer to executable to query app type for.
- * @param     pul           Pointer to flag variable to return apptype flags in.
- * @sketch
- * @status    stub.
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG LDRCALL fakeLDRQAppType(PSZ pszFilename, PULONG pul)
-{
-    KLOGENTRY2("ULONG LDRCALL","PSZ pszFilename, PULONG pul", pszFilename, pul);
-    DUMMY();
-    printf("fakeLDRQAppType:                pszFilename = %s, pul = %p, rc = 0\n", pszFilename, pul);
-    KLOGEXIT(NO_ERROR);
-    return NO_ERROR;
-}
-
-
-/**
- * ldrEnum32bitRelRecs
- * @param   pMTE           Pointer to MTE for this module.
- * @param   iObject        Object index. 0-based!
- * @param   iPageTabl      Page index. 0-based!
- * @param   pvPage         Pointer to page buffer.
- * @param   ulPageAddress  Note! Page is not present.
- * @param   pPTDA
- * @status  stub
- */
-ULONG LDRCALL fakeldrEnum32bitRelRecs(
-    PMTE    pMTE,
-    ULONG   iObject,
-    ULONG   iPageTable,
-    PVOID   pvPage,
-    ULONG   ulPageAddress,
-    PVOID   pvPTDA
-    )
-{
-    KLOGENTRY6("ULONG LDRCALL","PMTE pMTE, ULONG iObject, ULONG iPageTable, PVOID pvPage, ULONG ulPageAddress, PVOID pvPTDA", pMTE, iObject, iPageTable, pvPage, ulPageAddress, pvPTDA);
-    DUMMY();
-    printf("fakeldrEnum32bitRelRecs:        pMTE = %p, iObject = 0x%08x, iPageTable = 0x%08x, pvPage = 0x%08x, ulPageAddress = 0x%08x, pvPTDA = %p\n",
-           pMTE, iObject, iPageTable, pvPage, ulPageAddress, pvPTDA);
-
-    KLOGEXIT(NO_ERROR);
-    return NO_ERROR;
-}
-
-
-/**
- * Sets the VM flags for an executable object.
- * @returns     void
- * @param       pMTE        Pointer to the module table entry.
- * @param       flObj       LX Object flags.
- * @param       pflFlags1   Pointer to the flFlags1 of VMAllocMem (out).
- * @param       pflFlags2   Pointer to the flFlags2 of VMAllocMem (out).
- */
-ULONG LDRCALL fakeldrSetVMflags(
-    PMTE        pMTE,
-    ULONG       flObj,
-    PULONG      pflFlags1,
-    PULONG      pflFlags2
-    )
-{
-    KLOGENTRY4("ULONG LDRCALL","PMTE pMTE, ULONG flObj, PULONG pflFlags1, PULONG pflFlags2", pMTE, flObj, pflFlags1, pflFlags2);
-    *pflFlags1 = 0;
-    *pflFlags2 = 0;
-    flObj = flObj;
-    pMTE = pMTE;
-    KLOGEXIT(0);
-    return 0;
-}
-
-/**
- * Opens a given file.
- * @returns  NO_ERROR on success. OS/2 error code on error.
- * @param    pszFilename   Pointer to filename.
- * @param    flOpenFlags   Open flags. (similar to DosOpen)
- * @param    fsOpenMode    Open mode flags. (similar to DosOpen)
- * @param    phFile        Pointer to filehandle.
- * @param    pulsomething  16-bit near (?) pointer to a variable - unknown. NULL is allowed. EA?
- */
-APIRET KRNLCALL fakeIOSftOpen(
-    PSZ pszFilename,
-    ULONG flOpenFlags,
-    ULONG fsOpenMode,
-    PSFN phFile,
-    PULONG pulsomething
-    )
-{
-    KLOGENTRY5("APIRET KRNLCALL","PSZ pszFilename, ULONG flOpenFlags, ULONG fsOpenMode, PSFN phFile, PULONG pulsomething", pszFilename, flOpenFlags, fsOpenMode, phFile, pulsomething);
-    ULONG   ulAction;
-    HFILE   hFile;
-    APIRET  rc;
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    hFile = 0;
-    ulAction = 0;
-    rc =  DosOpen(pszFilename, &hFile, &ulAction, 0, FILE_NORMAL,
-                  flOpenFlags,
-                  fsOpenMode,
-                  NULL);
-    if (rc == NO_ERROR)
-        *phFile = (USHORT)hFile;
-
-    if (!f32Stack) ThunkStack32To16();
-
-    printf("fakeIOSftOpen:                  pszFilename = %s, flOpenFlags = 0x%08x, fsOpenMode = 0x%08x, phFile = %p; *phFile = 0x%04, pulsomething = %p, rc = %d\n",
-           pszFilename, flOpenFlags, fsOpenMode, phFile, *phFile, pulsomething, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * Closes the specified file.
- * @returns  NO_ERROR on success. OS/2 error code on error.
- * @param    hFile      File handle - System File Number.
- */
-APIRET KRNLCALL fakeIOSftClose(
-    SFN hFile
-    )
-{
-    KLOGENTRY1("APIRET KRNLCALL","SFN hFile", hFile);
-    APIRET  rc;
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    rc =  DosClose(hFile);
-
-    if (!f32Stack) ThunkStack32To16();
-
-    printf("fakeIOSftClose:                 hFile = 0x%04, rc = %d\n",
-           hFile, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * Probably this function will expand a relative path to a full path.
- * @returns  NO_ERROR on success. OS/2 error code on error.
- *           The ldr filename buffer will hold the expanded
- *           pathname upon successfull return.
- * @param    pszPath  Pointer to path to expand.  (?)
- * @status   completely implemented.
- */
-APIRET KRNLCALL fakeIOSftTransPath(
-    PSZ pszPath
-    )
-{
-    KLOGENTRY1("APIRET KRNLCALL","PSZ pszPath", pszPath);
-    char    szBuffer[CCHMAXPATH];
-    APIRET  rc;
-    BOOL    f32Stack = ((int)&pszPath > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    rc = DosQueryPathInfo(pszPath, FIL_QUERYFULLNAME, &szBuffer, sizeof(szBuffer));
-    printf("fakeIOSftTransPath:              pszPath(in) = %s, pszPath(out) = %s, rc = %d\n",
-           pszPath, szBuffer, rc);
-    if (rc == NO_ERROR)
-        strcpy(pszPath, szBuffer);
-    else
-        kprintf(("fakeIOSftTransPath: DosQueryPathInfo failed with rc=%d\n", rc));
-
-
-    if (!f32Stack) ThunkStack32To16();
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * Read at a given offset in the a file.
- * @returns  NO_ERROR on success. OS/2 error code on error.
- * @param    hFile      File handle - System File Number.
- * @param    pcbActual  Pointer to variable which upon input holds the number
- *                      of bytes to read, on output the actual number of bytes read.
- * @param    pvBuffer   Pointer to the read buffer.
- * @param    fpBuffer   16 far pointer to buffer. (ignored)
- * @param    ulOffset   File offset to read from. (0=start of file)
- */
-APIRET KRNLCALL fakeIOSftReadAt(
-    SFN hFile,
-    PULONG pcbActual,
-    PVOID pvBuffer,
-    ULONG fpBuffer,
-    ULONG ulOffset
-    )
-{
-    KLOGENTRY5("APIRET KRNLCALL","SFN hFile, PULONG pcbActual, PVOID pvBuffer, ULONG fpBuffer, ULONG ulOffset", hFile, pcbActual, pvBuffer, fpBuffer, ulOffset);
-    ULONG   ulMoved;
-    APIRET  rc;
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    rc = DosSetFilePtr(hFile, ulOffset, FILE_BEGIN, &ulMoved);
-    if (rc == NO_ERROR)
-        rc = DosRead(hFile, pvBuffer, *pcbActual, pcbActual);
-    else
-        kprintf(("fakeIOSftReadAt: DosSetFilePtr(hfile, 0x%08x(%d),..) failed with rc = %d.",
-                 ulOffset, ulOffset, rc));
-
-    if (!f32Stack) ThunkStack32To16();
-
-    printf("fakeIOSftReadAt:                hFile = 0x%04, pcbActual = %p; *pcbActual = 0x%08x, pvBuffer = %p, fpBuffer = %x, ulOffset = 0x%08x, rc = %d\n",
-           hFile, pcbActual, pvBuffer, fpBuffer, ulOffset, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * Write at a given offset in the a file.
- * @returns  NO_ERROR on success. OS/2 error code on error.
- * @param    hFile      File handle - System File Number.
- * @param    pcbActual  Pointer to variable which upon input holds the number
- *                      of bytes to write, on output the actual number of bytes write.
- * @param    pvBuffer   Pointer to the write buffer.
- * @param    fpBuffer   16 far pointer to buffer. (ignored)
- * @param    ulOffset   File offset to write from. (0=start of file)
- */
-APIRET KRNLCALL fakeIOSftWriteAt(
-    SFN hFile,
-    PULONG pcbActual,
-    PVOID pvBuffer,
-    ULONG fpBuffer,
-    ULONG ulOffset
-    )
-{
-    KLOGENTRY5("APIRET KRNLCALL","SFN hFile, PULONG pcbActual, PVOID pvBuffer, ULONG fpBuffer, ULONG ulOffset", hFile, pcbActual, pvBuffer, fpBuffer, ulOffset);
-    ULONG   ulMoved;
-    APIRET  rc;
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    rc = DosSetFilePtr(hFile, ulOffset, FILE_BEGIN, &ulMoved);
-    if (rc == NO_ERROR)
-        rc = DosWrite(hFile, pvBuffer, *pcbActual, pcbActual);
-    else
-        kprintf(("fakeIOSftWriteAt: DosSetFilePtr(hfile, 0x%08x(%d),..) failed with rc = %d.",
-                 ulOffset, ulOffset, rc));
-
-    if (!f32Stack) ThunkStack32To16();
-
-    printf("fakeIOSftWriteAt:               hFile = 0x%04, pcbActual = %p; *pcbActual = 0x%08x, pvBuffer = %p, fpBuffer = %x, ulOffset = 0x%08x, rc = %d\n",
-           hFile, pcbActual, pvBuffer, fpBuffer, ulOffset, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * Gets the filesize.
- * @returns   NO_ERROR on success; OS/2 error code on error.
- * @param     hFile    File handle - System File Number.
- * @param     pcbFile  Pointer to ULONG which will hold the file size upon return.
- */
-APIRET KRNLCALL fakeSftFileSize(
-    SFN hFile,
-    PULONG pcbFile
-    )
-{
-    KLOGENTRY2("APIRET KRNLCALL","SFN hFile, PULONG pcbFile", hFile, pcbFile);
-    FILESTATUS3     fsts3;
-    APIRET          rc;
-    BOOL            f32Stack = ((int)&hFile > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    rc = DosQueryFileInfo(hFile,
-                          FIL_STANDARD,
-                          &fsts3,
-                          sizeof(fsts3));
-    if (rc == NO_ERROR)
-        *pcbFile = fsts3.cbFile;
-    else
-        kprintf(("fakeSftFileSize: DosQueryFileInfo failed with rc=%d\n", rc));
-
-    if (!f32Stack) ThunkStack32To16();
-
-    printf("fakeSftFileSize:                hFile = 0x%04x, pcbFile = %p; *pcbFile = 0x%08x, rc = %d\n",
-           hFile, pcbFile, *pcbFile, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * @status    stub
- */
-HMTE KRNLCALL fakeVMGetOwner(
-    ULONG ulCS,
-    ULONG ulEIP)
-{
-    KLOGENTRY2("HMTE KRNLCALL","ULONG ulCS, ULONG ulEIP", ulCS, ulEIP);
-    DUMMY();
-
-    printf("fakeVMGetOwner:                 ulCS = 0x%04x, ulEiP = 0x%08x, rc = %d\n",
-           ulCS, ulEIP, 0);
-
-    KLOGEXIT(0);
-    return 0;
-}
-
-
-/**
- * @status    stub
- */
-APIRET KRNLCALL fakeVMAllocMem(
-    ULONG   cbSize,
-    ULONG   cbCommit,
-    ULONG   flFlags1,
-    HPTDA   hPTDA,
-    USHORT  usVMOwnerId,
-    HMTE    hMTE,
-    ULONG   flFlags2,
-    ULONG   SomeArg2,
-    PVMAC   pvmac)
-{
-    KLOGENTRY9("APIRET KRNLCALL","ULONG cbSize, ULONG cbCommit, ULONG flFlags1, HPTDA hPTDA, USHORT usVMOwnerId, HMTE hMTE, ULONG flFlags2, ULONG SomeArg2, PVMAC pvmac", cbSize, cbCommit, flFlags1, hPTDA, usVMOwnerId, hMTE, flFlags2, SomeArg2, pvmac);
-    DUMMY();
-    printf("fakeVMAllocMem:                 cbSize = 0x%08x, cbCommit = 0x%08x, flFlags1 = 0x%08x, hPTDA = 0x%04x, usVMOwnerId = 0x%04x, hMTE = 0x%04x, flFlags2 = 0x%08x, SomeArg2 = 0x%08x, pvmac = %p, rc = %d\n",
-           cbSize, cbCommit, flFlags1, hPTDA, usVMOwnerId, hMTE, flFlags2, SomeArg2, pvmac, ERROR_NOT_SUPPORTED);
-
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-
-/**
- * @status    stub
- */
-APIRET KRNLCALL fakeVMFreeMem(
-    PVOID   pv,
-    USHORT  hPTDA,
-    ULONG   flFlags
-    )
-{
-    KLOGENTRY3("APIRET KRNLCALL","PVOID pv, USHORT hPTDA, ULONG flFlags", pv, hPTDA, flFlags);
-    DUMMY();
-    printf("fakeVMFreeMem:                  pv = %p, hPTDA = 0x%04x, flFlags = %08x, rc = %d\n",
-           pv, hPTDA, flFlags, ERROR_NOT_SUPPORTED);
-
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-
-/**
- * @status    stub
- * @remark    Used by environment stuff...
- */
-APIRET KRNLCALL fakeVMObjHandleInfo(
-    USHORT  usHob,
-    PULONG  pulAddr,
-    PUSHORT pushPTDA)
-{
-    KLOGENTRY3("APIRET KRNLCALL","USHORT usHob, PULONG pulAddr, PUSHORT pushPTDA", usHob, pulAddr, pushPTDA);
-    APIRET          rc = NO_ERROR;
-    BOOL            f32Stack = ((int)&usHob > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    if (pulAddr > (PULONG)0x10000 && pushPTDA > (PUSHORT)0x10000)
-    {
-        PTIB pTib;
-        PPIB pPib;
-        DosGetInfoBlocks(&pTib, &pPib);
-        switch (usHob)
-        {
-            case 1: *pulAddr = (ULONG)pPib->pib_pchenv; break; //PTDA environ (fakea.asm)
-            default:
-                printf("fakeVMObjHandleInfo:            Invalid handle! (usHob=0x%#4x)\n", usHob);
-                rc = ERROR_INVALID_HANDLE;
-        }
-        *pushPTDA = 10; //dummy
-    }
-    else
-        rc = ERROR_INVALID_PARAMETER;
-
-    if (!f32Stack) ThunkStack32To16();
-
-    printf("fakeVMObjHandleInfo:            usHob = 0x%04x, pulAddr = %p, pushPTDA = %p, rc = %d\n",
-           usHob, pulAddr, pushPTDA, rc);
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-APIRET KRNLCALL fakeVMMapDebugAlias(
-    ULONG   flVMFlags,
-    ULONG   ulAddress,
-    ULONG   cbSize,
-    HPTDA   hPTDA,
-    PVMAC   pvmac)
-{
-    KLOGENTRY5("APIRET KRNLCALL","ULONG flVMFlags, ULONG ulAddress, ULONG cbSize, HPTDA hPTDA, PVMAC pvmac", flVMFlags, ulAddress, cbSize, hPTDA, pvmac);
-    printf("fakeVMMapDebugAlias:            flVMFlags = 0x%08x, ulAddress = 0x%08, cbSize = 0x%08x, hPTDA = 0x%04x, pvmac = %p - not implemented\n",
-           flVMFlags,
-           ulAddress,
-           cbSize,
-           hPTDA,
-           pvmac);
-
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-
-/**
- * Creates a pseudo handle for a given memory address.
- * @returns OS/2 return code. NO_ERROR on success.
- * @param   pvData      Pointer to the data which the handle should represent.
- * @param   hobOwner    Owner of the pseudo handle.
- * @param   phob        Pointer to object handle variable. Upon successful return
- *                      this will hold the handle value of the crated pseudo handle.
- * @remark  Used for many types of handles within the kernel.
- *          Among them are the loader HMTEs. The loader uses usOwner = 0xffa6 (ldrmte).
- */
-APIRET KRNLCALL fakeVMCreatePseudoHandle(
-    PVOID   pvData,
-    VMHOB   usOwner,
-    PVMHOB  phob)
-{
-    KLOGENTRY3("APIRET KRNLCALL","PVOID pvData, VMHOB usOwner, PVMHOB phob", pvData, usOwner, phob);
-    DUMMY();
-    printf("fakeVMCreatePseudoHandle:              - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-
-/**
- * This call frees a pseudo handle pointer previously allocated by
- * VMCreatePseudoHandle.
- * @returns OS/2 return code.
- * @param   hob     Handle to be freed.
- */
-APIRET KRNLCALL fakeVMFreePseudoHandle(
-    VMHOB   hob)
-{
-    KLOGENTRY1("APIRET KRNLCALL","VMHOB hob", hob);
-    DUMMY();
-    printf("fakeVMFreePseudoHandle:                - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-
-/**
- * ldrOpenPath - ldrOpenPath for build 14053 and above.
- * kernel 14053 and above.
- *
- * @returns   OS2 return code.
- *            plv->lv_sfn  is set to filename handle.
- * @param     pachFilename  Pointer to modulename. Not zero terminated!
- * @param     cchFilename   Modulename length.
- * @param     plv           Loader local variables? (Struct from KERNEL.SDF)
- * @param     pful          Pointer to flags which are passed on to ldrOpen.
- * @param     lLibPath      New parameter in build 14053.
- *                          ldrGetMte calls with 1
- *                          ldrOpenNewExe calls with 3
- *                          This is compared to the initial libpath index.
- *                              The libpath index is:
- *                                  BEGINLIBPATH    1
- *                                  LIBPATH         2
- *                                  ENDLIBPATH      3
- *                              The initial libpath index is either 1 or 2.
- *                          - ignored -
- *
- */
-ULONG LDRCALL fakeldrOpenPath_new( /* retd  0x14 */
-    PCHAR       pachFilename,      /* ebp + 0x08 */
-    USHORT      cchFilename,       /* ebp + 0x0c */
-    ldrlv_t *   plv,               /* ebp + 0x10 */
-    PULONG      pful,              /* ebp + 0x14 */
-    ULONG       lLibPath           /* ebp + 0x18 */
-    )
- {
-     KLOGENTRY5("ULONG LDRCALL","PCHAR pachFilename, USHORT cchFilename, ldrlv_t * plv, PULONG pful, ULONG lLibPath", pachFilename, cchFilename, plv, pful, lLibPath);
-     KNOREF(lLibPath);
-     KLOGEXIT(fakeldrOpenPath_old(pachFilename, cchFilename, plv, pful));
-     return fakeldrOpenPath_old(pachFilename, cchFilename, plv, pful);
- }
-
-
-/**
- * myldrOpenPath - opens file eventually searching loader specific paths
- * Pre kernel 14053.
- *
- * @returns   OS2 return code.
- *            pLdrLv->lv_sfn  is set to filename handle.
- * @param     pachFilename  Pointer to modulename. Not zero terminated?
- * @param     cchFilename   Modulename length.
- * @param     plv           Loader local variables? (Struct from KERNEL.SDF)
- * @param     pful          Pointer to flags which are passed on to ldrOpen.
- * @status    stub
- */
-ULONG LDRCALL fakeldrOpenPath_old(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful)
-{
-    KLOGENTRY4("ULONG LDRCALL","PCHAR pachFilename, USHORT cchFilename, ldrlv_t * plv, PULONG pful", pachFilename, cchFilename, plv, pful);
-    static char     szPath[1024];       /* Path buffer. Used to store pathlists. 1024 should be enough */
-                                        /* for LIBPATH (which at had a limit of ca. 750 chars). */
-    static char     sz[CCHMAXPATH];     /* Filename/path buffer. (Normally used to build filenames */
-                                        /* which are passed in as search experessions to DosFindFirst.) */
-
-    APIRET          rc;                 /* Return value. (Pessimistic attitude! Init it to FALSE...) */
-
-    printf("fakeldrOpenPath:        *entry* pachFilename = %.*s, cchFilename = %d,  plv = %p, pful = %p\n",
-           cchFilename, pachFilename, cchFilename, plv, pful);
-
-    if (plv->lv_class != CLASS_GLOBAL)
-        rc = fakeldrOpen(&plv->lv_sfn, pachFilename, pful);
-    else
-    {
-        int iPath;                      /* Current path or pathlist being examined. This is the loop */
-                                        /* variable looping on the FINDDLL_* defines. */
-
-        /* These defines sets the order the paths and pathlists are examined. */
-        #define FINDDLL_BEGINLIBPATH    7
-        #define FINDDLL_LIBPATH         8
-        #define FINDDLL_ENDLIBPATH      9
-        #define FINDDLL_FIRST           FINDDLL_BEGINLIBPATH
-        #define FINDDLL_LAST            FINDDLL_ENDLIBPATH
-
-        /*
-         * Remove DLL extention from the filename.
-         */
-        if (cchFilename > 4 && !strncmp(&pachFilename[cchFilename - 4], ".DLL", 4))
-        {
-            cchFilename -= 4;
-            pachFilename[cchFilename] = '\0';
-        }
-
-        /** @sketch
-         * Loop thru the paths and pathlists searching them for the filename.
-         */
-        rc = ERROR_FILE_NOT_FOUND;
-        for (iPath = FINDDLL_FIRST; iPath <= FINDDLL_LAST; iPath++)
-        {
-            const char  *   pszPath;        /* Pointer to the path being examined. */
-
-            /** @sketch Get the path/dir to examin. (This is determined by the value if iPath.) */
-            switch (iPath)
-            {
-                case FINDDLL_BEGINLIBPATH:
-                    rc = DosQueryExtLIBPATH(szPath, BEGIN_LIBPATH);
-                    break;
-                case FINDDLL_LIBPATH:
-                    rc = DosQueryHeaderInfo(NULLHANDLE, 0, szPath, sizeof(szPath), QHINF_LIBPATH);
-                    break;
-                case FINDDLL_ENDLIBPATH:
-                    rc = DosQueryExtLIBPATH(szPath, END_LIBPATH);
-                    break;
-                default: /* !internalerror! */
-                    KLOGEXIT(ERROR_FILE_NOT_FOUND);
-                    return ERROR_FILE_NOT_FOUND;
-            }
-            if (rc != NO_ERROR)
-            {
-                printf("fakeldrOpenPath: DosQueryExtLIBPATH/DosQueryHeadInfo failed with rc=%d, iPath=%d", rc, iPath);
-                continue;
-            }
-            pszPath = szPath;
-
-
-            /** @sketch
-             * pszPath is now set to the pathlist to be searched.
-             * So we'll loop thru all the paths in the list.
-             */
-            while (pszPath != NULL && *pszPath != '\0')
-            {
-                char *  pszNext;            /* Pointer to the next pathlist path */
-                int     cch;                /* Length of path (including the slash after the slash is added). */
-
-                /** @sketch
-                 * Find the end of the path.
-                 * Copy the path into the sz buffer.
-                 * Set pszNext.
-                 */
-                pszNext = strchr(pszPath, ';');
-                if (pszNext != NULL)
-                {
-                    cch = pszNext - pszPath;
-                    pszNext++;
-                }
-                else
-                    cch = strlen(pszPath);
-
-                if (cch + cchFilename + 1 >= sizeof(sz)) /* assertion */
-                {
-                    printf("fakeldrOpenPath: cch (%d) + cchFilename (%d) + 1 < sizeof(plv->sz) (%d) - paths too long!, iPath=%d",
-                           cch, cchFilename, sizeof(sz), iPath);
-                    pszPath = pszNext;
-                    continue;
-                }
-                memcpy(sz, pszPath, cch);
-
-                /** @sketch
-                 * Add a '\\' and the filename (pszFullname) to the path;
-                 * then we'll have a fullpath.
-                 */
-                sz[cch++] = '\\';
-                memcpy(&sz[cch], pachFilename, cchFilename);
-                memcpy(&sz[cch + cchFilename], ".DLL", 5);
-
-                rc = fakeldrOpen(&plv->lv_sfn, sz, pful);
-                switch (rc)
-                {
-                    case ERROR_FILE_NOT_FOUND:          case ERROR_PATH_NOT_FOUND:          case ERROR_ACCESS_DENIED:           case ERROR_INVALID_ACCESS:
-                    case ERROR_INVALID_DRIVE:           case ERROR_NOT_DOS_DISK:            case ERROR_REM_NOT_LIST:            case ERROR_BAD_NETPATH:
-                    case ERROR_NETWORK_BUSY:            case ERROR_DEV_NOT_EXIST:           case ERROR_TOO_MANY_CMDS:           case ERROR_ADAP_HDW_ERR:
-                    case ERROR_UNEXP_NET_ERR:           case ERROR_BAD_REM_ADAP:            case ERROR_NETNAME_DELETED:         case ERROR_BAD_DEV_TYPE:
-                    case ERROR_NETWORK_ACCESS_DENIED:   case ERROR_BAD_NET_NAME:            case ERROR_TOO_MANY_SESS:           case ERROR_REQ_NOT_ACCEP:
-                    case ERROR_INVALID_PASSWORD:        case ERROR_OPEN_FAILED:             case ERROR_INVALID_NAME:            case ERROR_FILENAME_EXCED_RANGE:
-                    case ERROR_VC_DISCONNECTED:
-                        rc = ERROR_FILE_NOT_FOUND;
-                        pszPath = pszNext;
-                        continue;
-                }
-
-                /*
-                 * Fatal error or success.
-                 */
-                printf("fakeldrOpenPath:        *exit*  plv->lv_sfn = 0x%04x, rc = %d\n", plv->lv_sfn, rc);
-                KLOGEXIT(rc);
-                return rc;
-            }
-        } /* for iPath */
-    }
-
-    printf("fakeldrOpenPath:        *exit*  plv->lv_sfn = 0x%04x, rc = %d\n", plv->lv_sfn, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * LDRClearSem - Clears the loader semaphore.
- * (It does some garbage collection on release.)
- * @returns   NO_ERROR on sucess.
- *            OS/2 error on failure. (ERROR_INTERRUPT?)
- * @status    completely implemented.
- */
-ULONG LDRCALL fakeLDRClearSem(void)
-{
-    KLOGENTRY0("ULONG LDRCALL");
-    KLOGEXIT(fakeKSEMReleaseMutex(&fakeLdrSem));
-    return fakeKSEMReleaseMutex(&fakeLdrSem);
-}
-
-/**
- * KSEMReuqestMutex faker.
- * @returns   NO_ERROR
- * @param     hkmtx
- * @param     ulTimeout
- * @status    completely implemented.
- * @remark
- */
-ULONG KRNLCALL fakeKSEMRequestMutex(HKSEMMTX hkmtx, ULONG ulTimeout)
-{
-    KLOGENTRY2("ULONG KRNLCALL","HKSEMMTX hkmtx, ULONG ulTimeout", hkmtx, ulTimeout);
-    unsigned short usSlot = getSlot();
-    ULONG          rc = NO_ERROR;
-
-    if (memcmp(&hkmtx->debug.ksem_achSignature[0], "KSEM", 4) != 0)
-    {
-        printf("fakeKSEMQueryMutex:             hkmtx = %p, invalid signature (%.4s)\n", hkmtx, hkmtx->debug.ksem_achSignature);
-        KLOGEXIT(FALSE);
-        return FALSE;
-    }
-
-    if (hkmtx->debug.ksem_Owner == 0)
-    {
-        hkmtx->debug.ksem_Owner = usSlot;
-        hkmtx->debug.ksem_cusNest = 1;
-    }
-    else if (hkmtx->debug.ksem_Owner == usSlot)
-        hkmtx->debug.ksem_cusNest++;
-    else
-        rc = ERROR_SEM_BUSY;
-
-    printf("fakeKSEMRequestMutex:           hkmtx = %p, ulTimeout = 0x%x, owner = %d, usage count = %d, rc = %d\n",
-           hkmtx, ulTimeout, hkmtx->debug.ksem_cusNest, hkmtx->debug.ksem_Owner, ERROR_SEM_BUSY);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * KSEMReleaseMutex faker.
- * @returns   NO_ERROR
- * @param     hkmtx
- * @param     ulTimeout
- * @status    completely implemented.
- * @remark
- */
-ULONG KRNLCALL fakeKSEMReleaseMutex(HKSEMMTX hkmtx)
-{
-    KLOGENTRY1("ULONG KRNLCALL","HKSEMMTX hkmtx", hkmtx);
-    unsigned int    usSlot = getSlot();
-    int rc = NO_ERROR;
-
-    if (memcmp(&hkmtx->debug.ksem_achSignature[0], "KSEM", 4) != 0)
-    {
-        printf("fakeKSEMQueryMutex:             hkmtx = %p, invalid signature (%.4s)\n", hkmtx, hkmtx->debug.ksem_achSignature);
-        KLOGEXIT(FALSE);
-        return FALSE;
-    }
-
-    if (hkmtx->debug.ksem_Owner == usSlot)
-    {
-        if (--hkmtx->debug.ksem_cusNest == 0)
-            hkmtx->debug.ksem_Owner = 0;
-    }
-    else
-        rc = ERROR_NOT_OWNER;
-
-    printf("fakeKSEMReleaseMutex:           hkmtx = %p, usage count = %d, owner = %d, rc = %d\n",
-           hkmtx, hkmtx->debug.ksem_cusNest, hkmtx->debug.ksem_Owner, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-
-/**
- * KSEMQueryMutex faker.
- * @returns     TRUE if owner or clear. Clear if *pcusNest is 0.
- *              FALSE if other owner.
- * @param       hkmtx       Handle to kernel mutex.
- * @param       pcusNest    Pointer to variable which is to receive the nesting count.
- *                          (ie. the number of times we have taken this semaphore.)
- * @status      completely implemented.
- * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-BOOL KRNLCALL  fakeKSEMQueryMutex(HKSEMMTX hkmtx, PUSHORT pcusNest)
-{
-    KLOGENTRY2("BOOL KRNLCALL","HKSEMMTX hkmtx, PUSHORT pcusNest", hkmtx, pcusNest);
-    unsigned int    usSlot = getSlot();
-    BOOL            fRc = TRUE;
-
-    if (memcmp(&hkmtx->debug.ksem_achSignature[0], "KSEM", 4) != 0)
-    {
-        printf("fakeKSEMQueryMutex:             hkmtx = %p, invalid signature (%.4s)\n", hkmtx, hkmtx->debug.ksem_achSignature);
-        KLOGEXIT(FALSE);
-        return FALSE;
-    }
-
-    if (hkmtx->debug.ksem_Owner == 0)
-    {
-        if (pcusNest)
-            *pcusNest = 0;
-        fRc = FALSE;
-    }
-    else
-    {
-        fRc = (hkmtx->debug.ksem_Owner == usSlot);
-        if (pcusNest)
-            *pcusNest = hkmtx->debug.ksem_cusNest;
-    }
-
-    printf("fakeKSEMQueryMutex:             hkmtx = %p, usage count = %d, owner = %d, *pcusNest = %d, rc = %d\n",
-           hkmtx, hkmtx->debug.ksem_cusNest, hkmtx->debug.ksem_Owner, pcusNest ? *pcusNest : -1, fRc);
-
-    KLOGEXIT(fRc);
-    return fRc;
-}
-
-
-/**
- * KSEMInit faker.
- * @param       pksem       Pointer to the semaphore struct to initiate.
- * @param       fulType     Semaphore type. (only KSEM_MUTEX is supported)
- * @param       fulFlags    Semaphore flags. (not validated)
- * @status      partially implemented.
- * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-VOID  KRNLCALL  fakeKSEMInit(PKSEM pksem, ULONG fulType, ULONG fulFlags)
-{
-    KLOGENTRY3("VOID KRNLCALL","PKSEM pksem, ULONG fulType, ULONG fulFlags", pksem, fulType, fulFlags);
-    if (fulType != KSEM_MUTEX && fulType != KSEM_SHARED)
-    {
-        printf("fakeKSEMInit:                   Invalid fulType parameter (%d).\n", fulType);
-        KLOGEXITVOID();
-        return; /*ERROR_INVALID_PARAMETER;*/
-    }
-
-    memcpy(pksem->mtx.debug.ksem_achSignature, "KSEM", 4);
-    pksem->mtx.debug.ksem_bFlags = (char)fulFlags;
-    pksem->mtx.debug.ksem_bType = fulType;
-    pksem->mtx.debug.ksem_cusNest = 0;
-    pksem->mtx.debug.ksem_cusPendingWriters = 0;
-    pksem->mtx.debug.ksem_Owner = 0;
-
-    printf("fakeKSEMInit:                   pksem=%p, fulType=%d, fulFlags=0x%x.\n", pksem, fulType, fulFlags);
-    KLOGEXITVOID();
-}
-
-
-ULONG KRNLCALL  fakeKSEMRequestExclusive(HKSEMSHR hkshr, ULONG ulTimeout)
-{
-    //KLOGENTRY2("ULONG","HKSEMSHR hkshr, ULONG ulTimeout", hkshr, ulTimeout);  /* used bye kLog.c */
-    DUMMY();
-    KNOREF(ulTimeout);
-
-    Assert(!memcmp(hkshr->debug.ks_achSignature, "KSEM", 4));
-    Assert(hkshr->debug.ks_bType == KSEM_SHARED);
-    Assert(hkshr->debug.ks_Owner == 0);
-    hkshr->debug.ks_Owner = 1;
-    //KLOGEXIT(0);
-    return 0;
-}
-
-
-ULONG KRNLCALL  fakeKSEMRequestShared(HKSEMSHR hkshr, ULONG ulTimeout)
-{
-    //KLOGENTRY2("ULONG","HKSEMSHR hkshr, ULONG ulTimeout", hkshr, ulTimeout);  /* used bye kLog.c */
-    DUMMY();
-    KNOREF(ulTimeout);
-
-    Assert(!memcmp(hkshr->debug.ks_achSignature, "KSEM", 4));
-    Assert(hkshr->debug.ks_bType == KSEM_SHARED);
-    Assert(hkshr->debug.ks_Owner == 0);
-    hkshr->debug.ks_Owner = 42;
-    //KLOGEXIT(0);
-    return 0;
-}
-
-
-VOID  KRNLCALL  fakeKSEMRelease(HKSEM hksem)
-{
-    //KLOGENTRY1("VOID","HKSEM hksem", hksem);                                  /* used bye kLog.c */
-    DUMMY();
-
-    Assert(!memcmp(hksem->shr.debug.ks_achSignature, "KSEM", 4));
-    switch (hksem->shr.debug.ks_bType)
-    {
-        case KSEM_SHARED:
-            Assert(hksem->shr.debug.ks_Owner != 0);
-            hksem->shr.debug.ks_Owner = 0;
-            break;
-        case KSEM_MUTEX:
-            Assert(hksem->mtx.debug.ksem_Owner != 0);
-            hksem->mtx.debug.ksem_Owner = 0;
-            break;
-        default:
-            INT3();
-    }
-    //KLOGEXITVOID();
-}
-
-
-VOID  KRNLCALL  fakeKSEMQuery(HKSEM hksem, PULONG pul)
-{
-    KLOGENTRY2("VOID","HKSEM hksem, PULONG pul", hksem, pul);
-    DUMMY();
-    KNOREF(hksem);
-    KNOREF(pul);
-    KLOGEXITVOID();
-}
-
-
-VOID  KRNLCALL  fakeKSEMResetEvent(HKSEMEVT hkev)
-{
-    KLOGENTRY1("VOID","HKSEMEVT hkev", hkev);
-    DUMMY();
-    KNOREF(hkev);
-    KLOGEXITVOID();
-}
-
-
-VOID  KRNLCALL  fakeKSEMPostEvent(HKSEMEVT hkev)
-{
-    KLOGENTRY1("VOID KRNLCALL","HKSEMEVT hkev", hkev);
-    DUMMY();
-    KNOREF(hkev);
-    KLOGEXITVOID();
-}
-
-
-ULONG KRNLCALL  fakeKSEMWaitEvent(HKSEMEVT hkev, ULONG ulTimeout)
-{
-    KLOGENTRY2("ULONG","HKSEMEVT hkev, ULONG ulTimeout", hkev, ulTimeout);
-    DUMMY();
-    KNOREF(hkev);
-    KNOREF(ulTimeout);
-    KLOGEXIT(-1);
-    return -1;
-}
-
-
-/**
- * Gets the thread slot number.
- * @returns     Thread slot number.
- * @status      completely implemented.
- * @author      knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-unsigned short getSlot(void)
-{
-    KLOGENTRY0("unsigned short");
-    PPIB ppib;
-    PTIB ptib;
-    BOOL            f32Stack = ((int)&ppib > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-    DosGetInfoBlocks(&ptib, &ppib);
-
-    if (!f32Stack) ThunkStack32To16();
-
-    KLOGEXIT((unsigned short)ptib->tib_ordinal);
-    return (unsigned short)ptib->tib_ordinal;
-}
-
-
-/**
- * Copy user memory into system memory.
- * @returns   OS/2 return code. (NO_ERROR is success)
- * @param     pv     Pointer to target (system) data area.
- * @param     pvUsr  Pointer to source (user) data area.
- * @param     cb     Count of bytes to copy.
- * @param     fl     Flags.
- * @status  Partially implemented.
- * @remark  Ignores fl. Crashes on error.
- */
-ULONG KRNLCALL   fakeTKFuBuff(PVOID pv, PVOID pvUsr, ULONG cb, ULONG fl)
-{
-    KLOGENTRY4("ULONG KRNLCALL","PVOID pv, PVOID pvUsr, ULONG cb, ULONG fl", pv, pvUsr, cb, fl);
-    memcpy(pv, pvUsr, cb);
-
-    printf("fakeTKFuBuff:                   pv = %p, pvUsr = %p, cb = 0x%08x, fl = 0x%08x, rc = %d\n",
-           pv, pvUsr, cb, fl, NO_ERROR);
-
-    KLOGEXIT(NO_ERROR);
-    return NO_ERROR;
-}
-
-
-/**
- * Copy system memory to user memory.
- * @returns   OS/2 return code. (NO_ERROR is success)
- * @param     pvUsr  Pointer to target (user) data area.
- * @param     pv     Pointer to source (system) data area.
- * @param     cb     Count of bytes to copy.
- * @param     fl     Flags.
- * @status  Partially implemented.
- * @remark  Ignores fl. Crashes on error.
- */
-ULONG KRNLCALL   fakeTKSuBuff(PVOID pvUsr, PVOID pv, ULONG cb, ULONG fl)
-{
-    KLOGENTRY4("ULONG KRNLCALL","PVOID pvUsr, PVOID pv, ULONG cb, ULONG fl", pvUsr, pv, cb, fl);
-    memcpy(pvUsr, pv, cb);
-
-    printf("fakeTKSuBuff:                   pvUsr = %p, pv = %p, cb = 0x%08x, fl = 0x%08x, rc = %d\n",
-           pvUsr, pv, cb, fl, NO_ERROR);
-
-    KLOGEXIT(NO_ERROR);
-    return NO_ERROR;
-}
-
-
-/**
- * String length. (includes NULL(s))
- * @returns   OS/2 return code. (NO_ERROR is success)
- *            ERROR_TERMINATOR_NOT_FOUND
- * @param     pcch      Pointer to length variable.
- * @param     pvUsr     Pointer to user data to preform string length on.
- * @param     cchMax    Max string length.
- * @param     fl        Flags.
- * @param     fDblNULL  TRUE:  Double '\0' (ie. '\0\0') terminated. Usefull for scanning environments.
- *                      FALSE: Single string. (ie. one '\0').
- * @status  Partially implemented.
- * @remark  Ignores fl. Crashes on error.
- */
-ULONG KRNLCALL   fakeTKFuBufLen(PLONG pcch, PVOID pvUsr, ULONG cchMax, ULONG fl, BOOL fDblNULL)
-{
-    KLOGENTRY5("ULONG KRNLCALL","PLONG pcch, PVOID pvUsr, ULONG cchMax, ULONG fl, BOOL fDblNULL", pcch, pvUsr, cchMax, fl, fDblNULL);
-    ULONG   rc;
-    PSZ     psz = pvUsr;
-
-    cchMax += (ULONG)pvUsr;
-
-    while ((ULONG)psz < cchMax)
-    {
-        if (*psz++ == '\0')
-            if (!fDblNULL || (ULONG)psz == cchMax || *psz++ != '\0')
-                break;
-    }
-
-    *pcch = (ULONG)psz - (ULONG)pvUsr;
-
-    /* Hope this is the correct definition of max length: Not inclusive. */
-    if ((ULONG)psz == cchMax)
-        rc = ERROR_TERMINATOR_NOT_FOUND;
-    else
-        rc = NO_ERROR;
-
-    printf("fakeTKFuBufLen:                 pcch = %p; *pcch = 0x%08x, pvUsr = %p, cchMax = 0x%08x, fl = 0x%08x, fDblNULL = %x, rc = %d\n",
-           pcch, *pcch, pvUsr, cchMax, fl, fDblNULL, NO_ERROR);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * Copy user memory to user memory.
- * @returns   OS/2 return code. (NO_ERROR is success)
- * @param     pvUsr  Pointer to target (user) data area.
- * @param     pv     Pointer to source (user) data area.
- * @param     cb     Count of bytes to copy.
- * @param     fl     Flags.
- * @status  Partially implemented.
- * @remark  Ignores fl. Crashes on error.
- */
-ULONG KRNLCALL   fakeTKSuFuBuff(PVOID pvTarget, PVOID pvSource, ULONG cb, ULONG fl)
-{
-    KLOGENTRY4("ULONG KRNLCALL","PVOID pvTarget, PVOID pvSource, ULONG cb, ULONG fl", pvTarget, pvSource, cb, fl);
-    memcpy(pvTarget, pvSource, cb);
-
-    printf("fakeTKSuFuBuff:                   pvTarget = %p, pvSource = %p, cb = 0x%08x, fl = 0x%08x, rc = %d\n",
-           pvTarget, pvSource, cb, fl, NO_ERROR);
-
-    KLOGEXIT(NO_ERROR);
-    return NO_ERROR;
-}
-
-
-/**
- * Validates an hMTE and gets the MTE pointer - FAKE.
- * @returns Pointer to MTE on success.
- *          NULL on error.
- * @param   hMTE  MTE handle.
- * @remark  If you wan't to this faster:
- *            Use the hMTE as a HOB and get the HOB address (by using VMGetHandleInfo).
- * @status  stub.
- */
-PMTE LDRCALL fakeldrValidateMteHandle(HMTE hMTE)
-{
-    KLOGENTRY1("PMTE LDRCALL","HMTE hMTE", hMTE);
-    DUMMY();
-
-    printf("fakeldrValidateMteHandle:       hMTE = 0x%04x, pMTE (rc) = %p\n",
-           hMTE, NULL);
-
-    KLOGEXIT(NULL);
-    return NULL;
-}
-
-
-/**
- * C worker function for fakeg_tkExecPgm. This is called by fakeg_tkExecPgm (fakea.asm).
- * @returns   OS/2 return code.
- * @param     execFlag      Exec flag (DosExecPgm execFlag).
- * @param     pArg          Pointer to arguments. (NULL allowed)
- * @param     pEnv          Pointer to environment. (NULL allowed)
- * @param     pszFilename   Pointer to filename.
- * @sketch
- * @status
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG _Optlink tkExecPgmWorker(ULONG execFlag, PSZ pArg, PSZ pEnv, PSZ pszFilename)
-{
-    KLOGENTRY4("ULONG","ULONG execFlag, PSZ pArg, PSZ pEnv, PSZ pszFilename", execFlag, pArg, pEnv, pszFilename);
-    APIRET      rc;
-    ldrrei_t    rei;
-
-    printf("tkExecPgmWorker:                execFlag = %d, pArg = %p, pEnv = %p, pszFilename = %s\n", execFlag, pArg, pEnv, pszFilename);
-
-    /*
-     * Take loader semaphore.
-     */
-    rc = KSEMRequestMutex(&fakeLdrSem, KSEM_INDEFINITE_WAIT);
-    if (rc != NO_ERROR)
-    {
-        KLOGEXIT(rc);
-        return rc;
-    }
-
-    /*
-     * Simulate loading.
-     */
-    rc = fakeLDRLoadExe(pszFilename, SSToDS(&rei));
-
-    KNOREF(pArg);
-    KNOREF(pEnv);
-    KNOREF(execFlag);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * Fake implementation of LDRLoadExe.
- * Not currently overriden, but used by tkExecPgmWorker to load executables.
- * @returns   OS/2 return code.
- * @param     pszFilename   Name of executable image to load.
- * @param     pEI           It seems this is a pointer to a ldrrei_s struct.
- *                          (currently ignored)
- * @sketch
- * @status
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG LDRCALL fakeLDRLoadExe(PSZ pszFilename, ldrrei_t *pEI)
-{
-    KLOGENTRY2("ULONG LDRCALL","PSZ pszFilename, ldrrei_t * pEI", pszFilename, pEI);
-    APIRET  rc;
-    int     cchFilename = strlen(pszFilename);
-
-    printf("fakeLDRLoadExe:         *entry* pszFilename = %s, pEI = %p\n",
-           pszFilename, pEI);
-
-    rc = fakeldrGetModule(pszFilename, (cchFilename << 16) | (LVTYPE_EXE << 8) | CLASS_PROGRAM);
-
-    printf("fakeLDRLoadExe:         *exit*  pszFilename = %s, pEI = %p, rc = %d\n",
-           pszFilename, pEI, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-
-/**
- * Fake implementeation of ldrGetModule.
- * Not currently overriden, but used by fakeLDRLoadExe to load executables.
- * @returns   OS/2 return code.
- * @param     pszFilename   Name of executable image to load.
- * @param     ul            low 8 bits:     Module CLASS_*.
- *                          high 8 bits:    Executable type LVTYPE_* ?
- *                          high 16 bits:   Filename length.
- * @sketch
- *  OS/2 kernel seems to do:
- *      Call Sec32GetModule
- *      Call ldrGetMte which does the necessary loading / attaching.
- *      Call ldrLoadImports for all imported DLLs. (and the exe?)
- *      Call ldrProcessObjects for LX and ldrPreloadLDT for NE imported DLLs. (and the exe?)
- *      Call ldrProcessImports.
- *
- *  We do:
- *      Call fakeldrGetMte.
- *      Call fakeldrLoadImports.
- *
- * @status
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG LDRCALL fakeldrGetModule(PSZ pszFilename, ULONG ul)
-{
-    KLOGENTRY2("ULONG LDRCALL","PSZ pszFilename, ULONG ul", pszFilename, ul);
-    APIRET  rc;
-    PMTE    pmte = NULL;
-
-    printf("fakeldrGetModule:       *entry* pszFilename = %s, ul = 0x%08x\n",
-           pszFilename, ul);
-
-    rc = fakeldrGetMte(pszFilename, (USHORT)(ul >> 16), (UCHAR)((ul & 0xff00) >> 8), (UCHAR)(ul & 0x00ff), SSToDS(&pmte));
-    if (rc == NO_ERROR)
-    {
-        rc = fakeldrLoadImports(pmte);
-    }
-
-    printf("fakeldrGetModule:       *exit*  pszFilename = %s, ul = 0x%08x, rc = %d\n",
-           pszFilename, ul, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- *
- * @returns
- * @param
- * @equiv
- * @time
- * @sketch
- *  OS/2 kernel seems to do:
- *      IF not device driver THEN
- *          Uppercase the name.
- *          Call ldrFindModule to try find the module within currenly loaded modules.
- *      ENDIF
- *
- *    tryagain:
- *      IF found THEN
- *          Set MTEGETMTEDONE flag in mte_flags2.
- *          Call ldrChkLoadType to ensure correct load type.
- *          IF attached or special modules (DOSMOD, VDDMOD, FSHMOD or MVDMMOD)
- *              IF miniIFS and !FSHMOD THEN Fail with rc=ERROR_INVALID_NAME
- *              return successfully.
- *          ENDIF
- *          lv_sfn <- mte_sfn
- *          Set the USED flag in mte_flags1
- *          Set the MTELOADORATTACH flag in mte_flags2
- *          Some processing of packed segments???? Dll init flags???
- *      ELSE *not found*
- *          IF class is CLASS_SPECIFIC AND ldrCheckGlobal returned TRUE THEN
- *              * this is because some specific modules is promoted to global
- *              * modules for some reasons I haven't ivestigated. (ldrPrmoteMTE)
- *              tryagain.
- *          ENDIF
- *          Set some flag to false.
- *          Calls to ldrOpenNewExe to load the exectuble from disk.
- *          IF this failes THEN fail.
- *          IF class is CLASS_GLOBAL and module is loaded as specific
- *              (ldrCheckSpecific returns TRUE) THEN
- *              Close and retry with the mte returned ldrCheckSpecific
- *              tryagain.
- *          ENDIF
- *          Sets some local variable to point at pheaderbuf, where ldrOpenNewExe
- *              has put the executable header.
- *          Call ldrCheckLoadType and fail if this failes.
- *          Call ldrCreateMte and fail if this failes.
- *          Set some local variables to lv_pmte and lv_pmte->mte_swapmte.
- *          Set the MTELOADORATTACH and MTEGETMTEDONE flags.
- *          Call ldrInvTgtErrTxt.
- *          IF DDInitTime AND DEVDRVMOD OR FSDMOD THEN
- *              ptda_module of current PTDA to the mtehandle of the module.
- *          ENDIF
- *          IF DOSCALL1 (checks name) THEN
- *              Set DOSLIB flag of mte_flags1.
- *              Set global pmteDoscall1 to point to the mte.
- *              Set global hmteDoscall1 to the handle of the mte.
- *          ENDIF
- *      ENDIF
- *      IF VDDMOD THEN
- *          call VDMMLoadingVDD with the mte handle.
- *      ENDIF
- *      IF NE executable THEN
- *          Call ldrAllocSegments
- *      ELSE
- *          Call ldrAllocObjects
- *      ENDIF
- *      IF failed THEN fail.
- *      IF LVTYPE_EXE THEN
- *          Set the ptda_module of the ExecChild PTDA to mtehandle.
- *          IF MTELONGNAMES THEN
- *              Set ptda_NewFiles to something.
- *          ENDIF
- *          Increment usage count, ie. mte_usecnt-
- *      ELSE IF LVTYPE_DLL AND !somelocalflag AND NOINTERNFIXUPS THEN
- *          Remove Internal fixups?
- *          (Calls ldrIsInternalFixup and VMReallocKHB during this processing.)
- *      ENDIF
- *      Clears the MTEPROCESSED flag of mte_flags1.
- *      Sets the return mte pointer. (ppmte)
- *      return successfully.
- *
- *  We do:
- *      Uppercase the string. (do we have to switch stack?)
- *      Call fakeldrOpenNewExe to do it's work.
- *      Call fakeldrCreateMte to create a fake mte.
- *      return.
- *
- * @status
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG LDRCALL   fakeldrGetMte(PCHAR pachFilename, USHORT cchFilename, UCHAR fchType, UCHAR fchClass, PPMTE ppmte)
-{
-    KLOGENTRY5("ULONG LDRCALL","PCHAR pachFilename, USHORT cchFilename, UCHAR fchType, UCHAR fchClass, PPMTE ppmte", pachFilename, cchFilename, fchType, fchClass, ppmte);
-    ldrlv_t         lv;
-    APIRET          rc;
-
-    printf("fakeldrGetMte:          *entry* pachFilename = %.*s, cchFilename = %#02x, fchType %#2x, fchClass = %#2x, ppmte = %p\n",
-           cchFilename, pachFilename, cchFilename, fchType, fchClass, ppmte);
-
-    /*
-     * Initiate the local variables.
-     */
-    memset(SSToDS(&lv), 0, sizeof(lv));
-    lv.lv_sfn = (USHORT)-1;
-    lv.lv_type = fchType;
-    lv.lv_class = fchClass;
-
-    /*
-     * Uppercase the string.
-     */
-    fakeldrUCaseString(pachFilename, cchFilename);
-
-    /*
-     * Open the new executable.
-     */
-    rc = fakeldrOpenNewExe(pachFilename, cchFilename, SSToDS(&lv), NULL);
-    if (rc != NO_ERROR)
-    {
-        fakeldrClose(lv.lv_sfn);
-        printf("fakeldrGetMte:          *exit*  pachFilename = %.*s, ppmte = %p; *ppmte = %p, rc = %d\n",
-               cchFilename, pachFilename, ppmte, *ppmte, rc);
-        KLOGEXIT(rc);
-        return rc;
-    }
-
-    /*
-     * Create MTE for the opened file.
-     */
-    rc = fakeldrCreateMte(pheaderbuf, SSToDS(&lv));
-    if (rc == NO_ERROR)
-    {
-        /*
-         * Set some flags... More?
-         */
-        lv.lv_pmte->mte_flags2 |= MTEGETMTEDONE | MTELOADORATTACH;
-        *ppmte = lv.lv_pmte;
-    }
-
-    printf("fakeldrGetMte:          *exit*  pachFilename = %.*s, ppmte = %p; *ppmte = %p, rc = %d\n",
-           cchFilename, pachFilename, ppmte, *ppmte, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-
-/**
- * Opens an executable module.
- * @returns   OS2 error code.
- * @param     pachFilename      Filename of the executable module to open.
- * @param     cchFilename       Filename length.
- * @param     plv               Pointer to local variables.
- * @param     pus               Pointer to some flags (LDRQAppType flags?!).
- * @sketch
- *  OS/2 kernel seems to do:
- *      Call ldrOpenPath to open the file.
- *      IF this fail THEN
- *          Set lv_sfn to -1 and return errorcode.
- *      ENDIF
- *      Set local variable to pheaderbuf.
- *      IF pus THEN set *pus to 1
- *      Call ldrRead to read the MZ header.
- *      Fail if this failed. (Don't close file caller does that.)
- *      IF LXMAGIC of NEMAGIC found THEN
- *          lv_new_exe_off <- 0;
- *      ELSE
- *          IF !EMAGIC or 'OZ' THEN
- *              Fail with rc=ERROR_INVALID_EXE_SIGNATURE.
- *          ENDIF
- *          IF pus THEN set *pus to 2.
- *          lv_new_exe_off <- e_lfanew.
- *      ENDIF
- *      Call ldrRead to read LX/NE header at lv_new_exe_off.
- *      Fail if this failed.
- *      IF NOT  LXMAGIC OR NEMAGIC THEN
- *          IF LEMAGIC AND pus THEN Set *pus to 0.
- *          IF PEMAGIC and pus THEN Set *pus to 3.
- *          Fail with rc=ERROR_INVALID_EXE_SIGNATURE.
- *      ENDIF
- *      IF pus THEN Set *pus to 0.
- *      IF invalid LX exeheader THEN
- *          Fail with rc=ERROR_INVALID_EXE_SIGNATURE.
- *      ENDIF
- *      IF NEMAGIC THEN
- *          Call ldrExpandHeader
- *      ELSE
- *          Set the MTELONGNAMES flag in e32_mflags.
- *      ENDIF
- *      IF LDRINVALID (in e32_mflags) THEN
- *          Fail with rc=ERROR_EXE_MARKED_INVALID.
- *      ENDIF
- *      Clear some e32_mflags, MTE_MEDIAFIXED, MTEMEDIACONTIG and MTEMEDIA16M.
- *      Or in flags set by ldrOpenPath into e32_mflags. (media type flags?!)
- *      Call ldrMungeFlags
- *      return retur code from ldrMungeFlags.
- *
- *  We do:
- *      Call fakeldrOpenPath to open the file.
- *      IF this fail THEN
- *          Set lv_sfn to -1 and return errorcode.
- *      ENDIF
- *      IF pus THEN set *pus to 1
- *      Call ldrRead to read the MZ header.
- *      Fail if this failed. (Don't close file caller does that.)
- *      If MZ header Then
- *          Set lv_new_exe_off to e_lfanew.
- *      else
- *          Set lv_new_exe_off to 0.
- *      Call ldrRead to read the LX header.
- *      Fail if this failed. (Don't close file caller does that.)
- *      If Not LX signature Then
- *          Fail.
- *      return successfully.
- *
- * @status
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG LDRCALL   fakeldrOpenNewExe(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PUSHORT pus)
-{
-    KLOGENTRY4("ULONG LDRCALL","PCHAR pachFilename, USHORT cchFilename, ldrlv_t * plv, PUSHORT pus", pachFilename, cchFilename, plv, pus);
-    APIRET  rc;
-    ULONG   ful;
-
-    printf("fakeldrOpenNewExe:      *entry* pachFilename = %.*s, cchFilename = %#2, plv = %p, pus = %p\n",
-           cchFilename, pachFilename, cchFilename, plv, pus);
-
-    rc = fakeldrOpenPath(pachFilename, cchFilename, plv, SSToDS(&ful), 1);
-    if (rc != NO_ERROR)
-    {
-        plv->lv_sfn = 0xffff;
-        printf("fakeldrOpenNewExe:      *exit*  pachFilename = %.*s, plv->lv_sfn = %#4x, rc = %d\n",
-               cchFilename, pachFilename, plv->lv_sfn, rc);
-        KLOGEXIT(rc);
-        return rc;
-    }
-    if (pus) *pus = 1;
-
-    memset(pheaderbuf, 0, sizeof(struct exe_hdr)); //zero it just in case....
-    rc = fakeldrRead(plv->lv_sfn, 0, pheaderbuf, 0, sizeof(struct exe_hdr), NULL);
-    if (rc != NO_ERROR)
-    {
-        plv->lv_sfn = 0xffff;
-        printf("fakeldrOpenNewExe:      *exit*  pachFilename = %.*s, plv->lv_sfn = %#4x, rc = %d\n",
-               cchFilename, pachFilename, plv->lv_sfn, rc);
-        KLOGEXIT(rc);
-        return rc;
-    }
-
-    if (*(PUSHORT)pheaderbuf == EMAGIC)
-        plv->lv_new_exe_off = ((struct exe_hdr *)pheaderbuf)->e_lfanew;
-    else
-        plv->lv_new_exe_off = 0;
-
-    memset(pheaderbuf, 0, sizeof(struct e32_exe)); //zero it just in case....
-    rc = fakeldrRead(plv->lv_sfn, plv->lv_new_exe_off, pheaderbuf, 0, sizeof(struct e32_exe), NULL);
-    if (rc != NO_ERROR)
-    {
-        plv->lv_sfn = 0xffff;
-        printf("fakeldrOpenNewExe:      *exit*  pachFilename = %.*s, plv->lv_sfn = %#4x, rc = %d\n",
-               cchFilename, pachFilename, plv->lv_sfn, rc);
-        KLOGEXIT(rc);
-        return rc;
-    }
-
-    if (*(PUSHORT)pheaderbuf != E32MAGIC)
-    {
-        plv->lv_sfn = 0xffff;
-        rc = ERROR_INVALID_EXE_SIGNATURE;
-        printf("fakeldrOpenNewExe:      *exit*  pachFilename = %.*s, plv->lv_sfn = %#4x, rc = %d\n",
-               cchFilename, pachFilename, plv->lv_sfn, rc);
-        KLOGEXIT(rc);
-        return rc;
-    }
-
-    printf("fakeldrOpenNewExe:      *exit*  pachFilename = %.*s, plv->lv_sfn = %#4x, rc = %d\n",
-           cchFilename, pachFilename, plv->lv_sfn, rc);
-
-    KLOGEXIT(NO_ERROR);
-    return NO_ERROR;
-}
-
-
-/**
- * Fake ldrCreateMte implementation.
- * @returns
- * @param     pe32  Pointer to the LX/NE header we've just read.
- * @param     plv   Pointer to local variables.
- * @sketch    !This does a lot of thing!
- *
- *  OS/2 Kernel seems to do:
- *      Allocate a kernel heap block for the MTE
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *  We do:
- *
- *
- * @status
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG LDRCALL   fakeldrCreateMte(struct e32_exe *pe32, ldrlv_t *plv)
-{
-    KLOGENTRY2("ULONG LDRCALL","struct e32_exe * pe32, ldrlv_t * plv", pe32, plv);
-    ULONG   rc;
-    PMTE    pMte;
-    PSMTE   pSMte;
-    PCHAR   pch;
-
-    printf("fakeldrCreateMte:       *entry* pe32 = %p, plv = %d\n",
-           pe32, plv);
-
-    /*
-     * Allocate mte and smte.
-     * The MTE has an array of mte pointers at the end for imported modules + 1.
-     * The SMTE has the fullpath filename, loader section and fixup section.
-     */
-    pMte = malloc(sizeof(MTE) + sizeof(PMTE) + sizeof(PMTE)*pe32->e32_impmodcnt);
-    if (pMte == NULL)
-    {
-        rc = ERROR_NOT_ENOUGH_MEMORY;
-        goto createmte_exit;
-    }
-
-    plv->lv_csmte = sizeof(SMTE) + 260 + pe32->e32_ldrsize + pe32->e32_fixupsize;
-    pSMte = malloc(plv->lv_csmte);
-    if (pSMte == NULL)
-    {
-        rc = ERROR_NOT_ENOUGH_MEMORY;
-        goto createmte_exit;
-    }
-    pch = (PCHAR)(PVOID)pSMte + sizeof(SMTE) + 260;
-
-
-    /*
-     * Initialize the MTE.
-     */
-    pMte->mte_flags2    = MTEFORMATLX;
-    pMte->mte_handle    = 20;
-    pMte->mte_swapmte   = pSMte;
-    pMte->mte_link      = NULL;
-    pMte->mte_flags1    = pe32->e32_mflags;
-    pMte->mte_impmodcnt = pe32->e32_impmodcnt;
-    pMte->mte_sfn       = plv->lv_sfn;
-    pMte->mte_usecnt    = 0;
-    pMte->mte_modname[0]= '\0';
-
-    /*
-     * Initialize the SMTE.
-     */
-    pSMte->smte_mpages = pe32->e32_mpages;
-    /*- magic,border,worder,level,cpu,os,ver,mflags */
-    pSMte->smte_mpages      = pe32->e32_mpages;        /* 00  Module # pages */
-    pSMte->smte_startobj    = pe32->e32_startobj;      /* 04  Object # for instruction */
-    pSMte->smte_eip         = pe32->e32_eip;           /* 08  Extended instruction pointer */
-    pSMte->smte_stackobj    = pe32->e32_stackobj;      /* 0c  Object # for stack pointer */
-    pSMte->smte_esp         = pe32->e32_esp;           /* 10  Extended stack pointer */
-        /*- pagesize*/
-    pSMte->smte_pageshift   = pe32->e32_pageshift;     /* 14  Page alignment shift in .EXE */
-    pSMte->smte_fixupsize   = pe32->e32_fixupsize;     /* 18  Fixup section size */
-        /*- fixupsum,ldrsize,ldrsum*/
-    pSMte->smte_objtab      = (POTE)pe32->e32_objtab;  /* 1c  Object table offset - POINTER */
-    pSMte->smte_objcnt      = pe32->e32_objcnt;        /* 20  Number of objects in module */
-    pSMte->smte_objmap      = pe32->e32_objmap;        /* 24  Object page map offset - POINTER */
-    pSMte->smte_itermap     = pe32->e32_itermap;       /* 28  Object iterated data map offset */
-    pSMte->smte_rsrctab     = pe32->e32_rsrctab;       /* 2c  Offset of Resource Table */
-    pSMte->smte_rsrccnt     = pe32->e32_rsrccnt;       /* 30  Number of resource entries */
-    pSMte->smte_restab      = pe32->e32_restab;        /* 34  Offset of resident name table - POINTER */
-    pSMte->smte_enttab      = pe32->e32_enttab;        /* 38  Offset of Entry Table - POINTER */
-    pSMte->smte_fpagetab    = pe32->e32_fpagetab;      /* 3c  Offset of Fixup Page Table - POINTER */
-    pSMte->smte_frectab     = pe32->e32_frectab;       /* 40  Offset of Fixup Record Table - POINTER */
-    pSMte->smte_impmod      = pe32->e32_impmod;        /* 44  Offset of Import Module Name Table - POINTER */
-        /*- impmodcnt*/
-    pSMte->smte_impproc     = pe32->e32_impproc;       /* 48  Offset of Imp Procedure Name Tab - POINTER */
-        /*- pagesum*/
-    pSMte->smte_datapage    = pe32->e32_datapage;      /* 4c  Offset of Enumerated Data Pages */
-        /*- preload*/
-    pSMte->smte_nrestab     = pe32->e32_nrestab;       /* 50  Offset of Non-resident Names Table */
-    pSMte->smte_cbnrestab   = pe32->e32_cbnrestab;     /* 54  Size of Non-resident Name Table */
-        /*- nressum*/
-    pSMte->smte_autods      = pe32->e32_autodata;      /* 58  Object # for automatic data object */
-    pSMte->smte_debuginfo   = pe32->e32_debuginfo;     /* 5c  Offset of the debugging info */
-    pSMte->smte_debuglen    = pe32->e32_debuglen;      /* 60  The len of the debug info in */
-        /*- instpreload,instdemand*/
-    pSMte->smte_heapsize    = pe32->e32_heapsize;      /* 64  use for converted 16-bit modules */
-        /*- res3*/
-    /* extra */
-    pSMte->smte_path        = 0;                       /* 68  full pathname - POINTER */
-    pSMte->smte_semcount    = 0;                       /* 6c  Count of threads waiting on MTE semaphore. 0 => semaphore is free */
-    pSMte->smte_semowner    = 0;                       /* 6e  Slot number of the owner of MTE semahore */
-    pSMte->smte_pfilecache  = 0;                       /* 70  Pointer to file cache for Dos32CacheModule */
-    pSMte->smte_stacksize   = 0;                       /* 74  Thread 1 Stack size from the exe header */
-    pSMte->smte_alignshift  = 0;                       /* 78  use for converted 16-bit modules */
-    pSMte->smte_NEexpver    = 0;                       /* 7a  expver from NE header */
-    pSMte->smte_pathlen     = 0;                       /* 7c  length of full pathname */
-    pSMte->smte_NEexetype   = 0;                       /* 7e  exetype from NE header */
-    pSMte->smte_csegpack    = 0;                       /* 80  count of segs to pack */
-
-    /*
-     * Copy filename (from where?)
-     */
-    pSMte->smte_path        = (PCHAR)(PVOID)pSMte + sizeof(SMTE);
-    pSMte->smte_pathlen     = 0;
-    memcpy(pSMte->smte_path, "", pSMte->smte_pathlen);
-
-
-    /*
-     * Read loader and fixup sections.
-     */
-    rc = fakeldrRead(plv->lv_sfn,
-                     (ULONG)pSMte->smte_objtab + plv->lv_new_exe_off,
-                     pch,
-                     0,
-                     pe32->e32_ldrsize + pe32->e32_fixupsize,
-                     NULL);
-    if (rc)
-    {
-        goto createmte_exit;
-    }
-
-    /*
-     * Set pointers.
-     */
-    pSMte->smte_objtab = (POTE)(PVOID)pch;
-    rc = fakeldrMTEValidatePtrs(pSMte,
-                                (ULONG)pch + plv->lv_csmte,
-                                (ULONG)pch - (ULONG)pe32->e32_objtab);
-    if (rc)
-    {
-        goto createmte_exit;
-    }
-
-    /*
-     * Set mte pointer in plv.
-     * Set hobmte in plv.
-     */
-    plv->lv_pmte = pMte;
-    plv->lv_hobmte = pMte->mte_handle;
-
-    /*
-     * Fix flags...
-     */
-    pMte->mte_flags1 |= plv->lv_class;
-
-createmte_exit:
-    printf("fakeldrCreateMte:       *exit*  pe32 = %p, plv = %d, rc = %d\n",
-           pe32, plv, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-
-/**
- * Fake ldrLoadImports - loads the import modules for the given module (pmte).
- * @returns   OS2 error code.
- * @param     pmte  Pointer to mte to load imports for.
- * @sketch
- *  OS/2 kernel seems to do:
- *      Loop thru the importe module table (reverse order for NE files)
- *          IF VDD module THEN
- *              Uppercase the name.
- *              try find it using ldrFindModule
- *              fail if error, not found, not VDDMOD/MVDMMOD.
- *              Add to array of imported module.
- *          ENDIF
- *          IF Not found OR !MTEGETMTEDONE THEN
- *              call ldrGetMte to load the module (class global).
- *              fail if error.
- *              set MTEGETMTEDONE
- *              Add to array of imported module.
- *          ENDIF
- *          IF DOSMOD and !ldrMiniFileIOFlag THEN
- *              Replace module pointer with doscall1 pmte.
- *          ENDIF
- *      ENDLOOP
- *
- *  We do:
- *      Parameter validation.
- *      Loop thru the imported module table issuing fakeldrGetMte on each entry.
- *      'DOSCALLS' is ignored.
- *
- * @status
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG LDRCALL   fakeldrLoadImports(PMTE pmte)
-{
-    KLOGENTRY1("ULONG LDRCALL","PMTE pmte", pmte);
-    int     i;                          /* Module index. */
-    PSZ     psz;                        /* Module name pointer. (really pointer to pascal strings...) */
-    PPMTE   papmte;                     /* Pointer to array of PMTEs for imported modules. */
-    APIRET  rc;
-
-    printf("fakeldrLoadImport:      *entry* pmte = %p, pmte->mte_impmodcnt = %d\n",
-           pmte, pmte->mte_impmodcnt);
-
-    /*
-     * Parameter validation.
-     */
-    if (pmte == NULL)
-    {
-        kprintf(("fakeldrLoadImports: !ASSERTION! pmte == NULL\n"));
-        KLOGEXIT(ERROR_INVALID_PARAMETER);
-        return ERROR_INVALID_PARAMETER;
-    }
-    if (pmte->mte_swapmte == NULL)
-    {
-        kprintf(("fakeldrLoadImports: !ASSERTION! pmte->mte_swapmte == NULL\n"));
-        KLOGEXIT(ERROR_INVALID_PARAMETER);
-        return ERROR_INVALID_PARAMETER;
-    }
-
-    /*
-     * Any imported modules?
-     */
-    if (pmte->mte_impmodcnt == 0)
-    {
-        printf("fakeldrLoadImport:      *exit*  pmte = %p, rc = %d\n",
-               pmte, rc);
-        KLOGEXIT(NO_ERROR);
-        return NO_ERROR;
-    }
-
-    /* We have reserved space for imported module pointers after the mte. */
-    papmte = (PPMTE)((unsigned)pmte  + sizeof(MTE));
-
-    /*
-     * Process the imported module table.
-     */
-    for (i = 0, rc = NO_ERROR, psz = (PSZ)pmte->mte_swapmte->smte_impmod;
-         i < pmte->mte_impmodcnt && rc == NO_ERROR;
-         i++, psz += 1 + *psz)
-    {
-        if (*psz == 8 && !strnicmp(psz+1, "DOSCALLS", 8))
-            continue;
-
-        rc = fakeldrGetMte(psz + 1, *psz, LVTYPE_DLL, CLASS_GLOBAL, &papmte[i]);
-    }
-
-    printf("fakeldrLoadImport:      *exit*  pmte = %p, rc = %d\n",
-           pmte, rc);
-
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * Checks if the internal name (first name in the resident nametable) matches
- * the filename.
- * @returns     NO_ERROR on success (the name matched).
- *              ERROR_INVALID_NAME if mismatch.
- * @param       pMTE    Pointer to the MTE of the module to check.<br>
- *                      Assumes! that the filename for this module is present in ldrpFileNameBuf.
- */
-ULONG LDRCALL   fakeldrCheckInternalName(PMTE pMTE)
-{
-    KLOGENTRY1("ULONG LDRCALL","PMTE pMTE", pMTE);
-    PCHAR   pachName;                   /* Pointer to the name part of pachFilename. */
-    int     cchName;                    /* Length of the name part of pachFilename.
-                                         * Includes extention if extention is not .DLL.
-                                         * this is the length relative to pachName used to match the internal name. */
-    PCHAR   pachExt;                    /* Pointer to the extention part of pachFilename. (not dot!) */
-    int     cchExt;                     /* Length of the extention part of pachFilename. (not dot!) */
-
-
-    /* Return successfully if not library module. */
-    if (!(pMTE->mte_flags1 & LIBRARYMOD))
-    {
-        KLOGEXIT(NO_ERROR);
-        return NO_ERROR;
-    }
-
-    /* Uppercase and parse filename in ldrpFileNameBuf */
-    cchName = (int)fakeldrGetFileName(ldrpFileNameBuf, (PCHAR*)SSToDS(&pachName), (PCHAR*)SSToDS(&pachExt));
-    cchExt = (pachExt) ? strlen(pachExt) : 0;
-    ldrUCaseString(pachName, cchName + cchExt + 1);
-
-    /* Compare the internal name with the filename and return accordingly. */
-    KLOGEXIT((    cchName <= 8
-            &&  !memcmp(pMTE->mte_modname, pachName, cchName)
-            &&  (cchName == 8 || pMTE->mte_modname[cchName] == '\0')
-            )
-            ? NO_ERROR
-            : ERROR_INVALID_NAME);
-    return (    cchName <= 8
-            &&  !memcmp(pMTE->mte_modname, pachName, cchName)
-            &&  (cchName == 8 || pMTE->mte_modname[cchName] == '\0')
-            )
-            ? NO_ERROR
-            : ERROR_INVALID_NAME;
-}
-
-
-/**
- * Translates a relative filename to a full qualified filename.
- * @returns NO_ERROR on success.
- *          Errorcode on error.
- * @param   pszFilename     Pointer to nullterminated filename.
- */
-ULONG LDRCALL   fakeldrTransPath(PSZ pszFilename)
-{
-    KLOGENTRY1("ULONG LDRCALL","PSZ pszFilename", pszFilename);
-    KLOGEXIT(fakeIOSftTransPath(pszFilename));
-    return  fakeIOSftTransPath(pszFilename);
-}
-
-
-/**
- * Parses a filename to find the name and extention.
- * @returns Length of the filename without the extention.
- * @param   pachFilename    Pointer to filename to parse - must have path!
- * @param   ppachName       Pointer to pointer which should hold the name pointer upon successfull return.
- * @param   ppachExt        Pointer to pointer which should hold the extention pointer upon successfull return.
- */
-ULONG LDRCALL   fakeldrGetFileName(PSZ pszFilename, PCHAR *ppchName, PCHAR *ppchExt)
-{
-    KLOGENTRY3("ULONG LDRCALL","PSZ pszFilename, PCHAR * ppchName, PCHAR * ppchExt", pszFilename, ppchName, ppchExt);
-    int     cchName;
-    PSZ     pchName;
-    PSZ     pchExt = NULL;
-
-    while (*pszFilename)
-    {
-        if (*pszFilename == '\\' || *pszFilename == '/')
-            pchName = pszFilename + 1;
-        else if (*pszFilename == '.')
-            pchExt = pszFilename + 1;
-        pszFilename++;
-    }
-
-    cchName = (pchExt <= pchName) ? strlen(pchName) : pchExt - pchName - 1;
-    *ppchExt = pchExt;
-    *ppchName = pchName;
-
-    KLOGEXIT(cchName);
-    return cchName;
-}
-
-
-/**
- * Uppercases the string.
- * @param     pachString    String to uppercase.
- * @param     cchString     Length of string.
- * @sketch    Loop thru the string converting all english letters to uppercase.
- * @status    partially implemented.
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark    This is probably written in assembly and does DBCS checks...
- */
-VOID LDRCALL    fakeldrUCaseString(PCHAR pachString, unsigned cchString)
-{
-    KLOGENTRY2("VOID LDRCALL","PCHAR pachString, unsigned cchString", pachString, cchString);
-    printf("fakeldrUCaseString:             pachString = %.*s, cchString = %#8x\n",
-           cchString, pachString, cchString);
-
-    while (cchString-- != 0)
-    {
-        if (*pachString >= 'a' && *pachString <= 'z')
-            *pachString -= ('a' - 'A');
-        pachString++;
-    }
-    KLOGEXITVOID();
-}
-
-
-
-
-/**
- * Checks and updates the members of the swap-mte which is to be
- * pointers into the loader/fixup section. An array, validatetbl, contains
- * the offsets of the smte pointers.
- *
- * @returns     NO_ERROR    on success.
- *              ERROR_BAD_EXE_FORMAT on error.
- * @param       psmte
- * @param       ulMaxAddr   Maximum (exclusive) address.
- * @param       off         Offset delta to add to the pointer members (which
- *                          are all offsets relative to the start of the new
- *                          header) to make them pointers.
- * @sketch
- *  Loop thru the validatetbl and update each field (which isn't null) by adding
- *  the off value, and validate that the pointer is ok.
- * @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- * @remark
- */
-ULONG LDRCALL   fakeldrMTEValidatePtrs(PSMTE psmte, ULONG ulMaxAddr, ULONG off)
-{
-    KLOGENTRY3("ULONG LDRCALL","PSMTE psmte, ULONG ulMaxAddr, ULONG off", psmte, ulMaxAddr, off);
-    int     i;
-
-    printf("fakeldrMTEValidatePtrs: *entry* psmte = %p, ulMaxAddr = %p, off = %p\n",
-           psmte, ulMaxAddr, off);
-
-    for (i = 0; validatetbl[i] != 0xDEAD; i++)
-    {
-        PULONG  pul = (PULONG)(PVOID)((PCHAR)(PVOID)psmte + validatetbl[i]);
-        if (*pul != 0UL)
-        {
-            *pul += off;
-            if (*pul >= ulMaxAddr)
-            {
-                printf("fakeldrMTEValidatePtrs: *exit*  psmte = %p, ulMaxAddr = %p, off = %p, rc = %d\n",
-                       psmte, ulMaxAddr, off, ERROR_BAD_EXE_FORMAT);
-                KLOGEXIT(ERROR_BAD_EXE_FORMAT);
-                return ERROR_BAD_EXE_FORMAT;
-            }
-        }
-    }
-
-    printf("fakeldrMTEValidatePtrs: *exit*  psmte = %p, ulMaxAddr = %p, off = %p, rc = %d\n",
-           psmte, ulMaxAddr, off, NO_ERROR);
-    KLOGEXIT(NO_ERROR);
-    return NO_ERROR;
-}
-
-
-PMTE KRNLCALL fakeldrASMpMTEFromHandle(HMTE  hMTE)
-{
-    KLOGENTRY1("PMTE KRNLCALL","HMTE hMTE", hMTE);
-    PMTE pMte = (PMTE)hMTE;
-
-    pMte += 10; //just do something!
-
-    KLOGEXIT(NULL);
-    return NULL;
-}
-
-ULONG LDRCALL   fakeldrFindModule(PCHAR pachFilename, USHORT cchFilename, USHORT usClass, PPMTE ppMTE)
-{
-    KLOGENTRY4("ULONG LDRCALL","PCHAR pachFilename, USHORT cchFilename, USHORT usClass, PPMTE ppMTE", pachFilename, cchFilename, usClass, ppMTE);
-    APIRET rc = NO_ERROR;
-    usClass = usClass;
-    cchFilename = cchFilename;
-    pachFilename = pachFilename;
-    *ppMTE = NULL;
-    KLOGEXIT(rc);
-    return rc;
-}
-
-
-/**
- * Gets the path (name with fully qualified path) from a SFN.
- * @returns     Pointer to the path of hFile.
- * @param       hFile   SFN filehandle.
- */
-PSZ SECCALL fakeSecPathFromSFN(SFN hFile)
-{
-    KLOGENTRY1("PSZ SECCALL","SFN hFile", hFile);
-    BOOL    f32Stack = ((int)&hFile > 0x10000);
-
-    if (!f32Stack) ThunkStack16To32();
-
-
-    if (!f32Stack) ThunkStack32To16();
-
-    printf("fakeSecPathFromSFN:                    - not implemented - hFile = 0x%04x\n", hFile);
-
-    KLOGEXIT(NULL);
-    return NULL;
-}
-
-/**
- * PID to PTDA pointer.
- * @returns     OS/2 return code.
- * @param       pid     Process Identifier.
- * @param       ppPTDA  Pointer to the PTDA-pointer variabel which is to receive
- *                      the PTDA pointer on successful return.
- */
-ULONG KRNLCALL  fakeTKPidToPTDA(PID pid, PPPTDA ppPTDA)
-{
-    KLOGENTRY2("ULONG KRNLCALL","PID pid, PPPTDA ppPTDA", pid, ppPTDA);
-    DUMMY();
-    printf("fakeTKPidToPTDA:                       - not implemented - pid = 0x%04x, ppPTDA=%p\n", pid, ppPTDA);
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-/**
- *
- * @returns     OS/2 return code.
- * @param       pid     Process Identifier.
- * @param       ppPTDA  Pointer to the PTDA-pointer variabel which is to receive
- *                      the PTDA pointer on successful return.
- */
-ULONG KRNLCALL   fakeTKScanTasks(ULONG flFlags, ULONG id, PTKSCANTASKWORKER pfnWorker, ULONG ulArg)
-{
-    KLOGENTRY4("ULONG KRNLCALL","ULONG flFlags, ULONG id, PTKSCANTASKWORKER pfnWorker, ULONG ulArg", flFlags, id, pfnWorker, ulArg);
-    DUMMY();
-    printf("fakeTKScanTasks:                       - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-/**
- * Force a thread to be made ready.
- * @param   flFlag  Which flag(s?) to set.
- * @param   pTCB    Pointer to the thread control block of the thread to be forced.
- */
-void KRNLCALL fakeTKForceThread(ULONG flFlag, PTCB pTCB)
-{
-    KLOGENTRY2("void KRNLCALL","ULONG flFlag, PTCB pTCB", flFlag, pTCB);
-    DUMMY();
-    printf("fakeTKForceThread:                     - not implemented\n");
-    KLOGEXITVOID();
-}
-
-/**
- * Set force flag on a task.
- * @param   flFlag  Which flag(s?) to set.
- * @param   pPTDA   Pointer to the PTDA of the task to be processed.
- * @param   fForce  FALSE   Just set the flag on all threads.
- *                  TRUE    Force all threads ready by calling TKForceThread.
- */
-void KRNLCALL  fakeTKForceTask(ULONG flFlag, PPTDA pPTDA, BOOL fForce)
-{
-    KLOGENTRY3("void KRNLCALL","ULONG flFlag, PPTDA pPTDA, BOOL fForce", flFlag, pPTDA, fForce);
-    DUMMY();
-    printf("fakeTKForceTask:                       - not implemented\n");
-    KLOGEXITVOID();
-}
-
-/**
- * Get priotity of a thread.
- * @returns Thread priority.
- * @param   pTCB    pointer to the TCB of the thread in question.
- */
-ULONG KRNLCALL fakeTKGetPriority(PTCB pTCB)
-{
-    KLOGENTRY1("ULONG KRNLCALL","PTCB pTCB", pTCB);
-    DUMMY();
-    printf("fakeTKGetPriority:                     - not implemented\n");
-    KLOGEXIT(-1);
-    return -1;
-}
-
-/**
- * Make current thread sleep.
- * @returns NO_ERROR on success.
- *          ERROR_INTERRUPT if a signal is forced on the thread.
- *          ERROR_TIMEOUT if we timeout.
- * @param   ulSleepId   32-bit sleep id which TKWakeup will be called with.
- * @param   ulTimeout   Number of milliseconds to sleep. (0 is not yield)
- *                      -1 means forever or till wakeup.
- * @param   fUnint      TRUE:  may not interrupt sleep.
- *                      FALSE: may interrupt sleep.
- * @param   flSleepType ???
- */
-ULONG KRNLCALL fakeTKSleep(ULONG ulSleepId, ULONG ulTimeout, ULONG fUnInterruptable, ULONG flWakeupType)
-{
-    KLOGENTRY4("ULONG KRNLCALL","ULONG ulSleepId, ULONG ulTimeout, ULONG fUnInterruptable, ULONG flWakeupType", ulSleepId, ulTimeout, fUnInterruptable, flWakeupType);
-    DUMMY();
-    printf("fakeTKSleep:                           - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-/**
- * Wakeup sleeping thread(s).
- * @returns NO_ERROR on succes.
- *          Appropriate error code on failure.
- * @param   ulSleepId       32-bit sleep id which threads are sleeping on.
- * @param   flWakeUpType    How/what to wakeup.
- * @param   pcWakedUp       Pointer to variable which is to hold the count of
- *                          thread waked up.
- */
-ULONG KRNLCALL fakeTKWakeup(ULONG ulSleepId, ULONG flWakeupType, PULONG cWakedUp)
-{
-    KLOGENTRY3("ULONG KRNLCALL","ULONG ulSleepId, ULONG flWakeupType, PULONG cWakedUp", ulSleepId, flWakeupType, cWakedUp);
-    DUMMY();
-    printf("fakeTKWakeup:                          - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-
-/**
- * Wake up a single thread.
- * @returns NO_ERROR on succes.
- *          Appropriate error code on failure.
- * @param   pTCB    Pointer to the TCB of the thread to be waken.
- */
-ULONG KRNLCALL fakeTKWakeThread(PTCB pTCB)
-{
-    KLOGENTRY1("ULONG KRNLCALL","PTCB pTCB", pTCB);
-    DUMMY();
-    printf("fakeTKWakeThread:                      - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-/**
- * See which thread will be Wakeup.
- * @returns Pointer to TCB of the thread on success.
- *          NULL on failure or no threads.
- * @param   ulSleepId       32-bit sleep id which threads are sleeping on.
- * @param   flWakeUpType    How/what to wakeup.
- */
-PTCB  KRNLCALL fakeTKQueryWakeup(ULONG ulSleepId, ULONG flWakeupType)
-{
-    KLOGENTRY2("PTCB KRNLCALL","ULONG ulSleepId, ULONG flWakeupType", ulSleepId, flWakeupType);
-    DUMMY();
-    printf("fakeTKQueryWakeup:                     - not implemented\n");
-    KLOGEXIT(NULL);
-    return NULL;
-}
-
-/**
- * Returns the number of bytes of physical memory available.
- */
-ULONG KRNLCALL fakePGPhysAvail(void)
-{
-    KLOGENTRY0("ULONG KRNLCALL");
-    DUMMY();
-    printf("fakePGPhysAvail                        - returns 0x234563\n");
-    KLOGEXIT(0x234563);
-    return 0x234563;
-}
-
-
-/**
- * Returns the number of pageframes currently in use.
- */
-ULONG KRNLCALL fakePGPhysPresent(void)
-{
-    KLOGENTRY0("ULONG KRNLCALL");
-    DUMMY();
-    printf("fakePGPhysPresent                      - returns 0x123534\n");
-    KLOGEXIT(0x123534);
-    return 0x123534;
-}
-
-
-/**
- * This function seems to find the top of the private arena.
- * And for high arena kernels (AURORA and W3SMP?) it is modified
- * to calc the top of the high private arena, given flFlag = 4.
- * --
- * This function is really intented for resizing / recaling the size of
- * the shared arena(s). But, it's useful for finding the highest used
- * private arena(s).
- * @param   flFlags             VMRSBF_* flags.
- * @param   pulSentinelAddress  Pointer to return variable (optional).
- */
-VOID    KRNLCALL fakevmRecalcShrBound(
-    ULONG   flFlags,
-    PULONG  pulSentinelAddress)
-{
-    KLOGENTRY2("VOID KRNLCALL","ULONG flFlags, PULONG pulSentinelAddress", flFlags, pulSentinelAddress);
-    ULONG ulRet;
-    DUMMY();
-
-    if ((flFlags & 6) == 0)
-    {   /* shared  tiled memory */
-        ulRet = 128*1024*1024;
-    }
-    else
-    {
-        ulRet = 0x2c000000;
-        if (_usFakeVerMinor < 45)        /* bad emulation for Warp 3 SMP - FIXME */
-            printf("fakePGPhysPresent                      - error: bad flags for non-highmem OS/2 versionn");
-    }
-
-    if (pulSentinelAddress)
-        *pulSentinelAddress = ulRet;
-
-    printf("fakePGPhysPresent                      - returns %x - flFlags=0x%02x, pulSentinelAddress=0x%08x\n",
-           ulRet, flFlags, pulSentinelAddress);
-
-    KLOGEXITVOID();
-}
-
-
-/**
- * Resolves the ordinal number of an name export.
- * @returns OS2 return code. (I.e. ON_ERROR on success)
- * @param   pMTE            Pointer to the module table entry for the
- *                          module.
- * @param   pszExportName   Name to resolve. This is case sensitive.
- * @param   pusOrdinal      Pointer to variable which on success will hold
- *                          the ordinal value found for the name export.
- */
-ULONG LDRCALL   fakeldrGetOrdNum(PMTE pMTE, PSZ pszExportName, PUSHORT pusOrdinal)
-{
-    KLOGENTRY3("ULONG LDRCALL","PMTE pMTE, PSZ pszExportName, PUSHORT pusOrdinal", pMTE, pszExportName, pusOrdinal);
-    DUMMY();
-    printf("fakeldrGetOrdNum:                      - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-
-/**
- * Checks if a module was loaded using DosLoadModule.
- * This is called from LDRGetProcAddr and LDRFreeModule.
- * @returns NO_ERROR if the module was LoadModuled or executable.
- *          ERROR_INVALID_HANDLE if not LoadModuled.
- * @param   hmte    MTE handle.
- * @param   pptda   Pointer to the PTDA of the process calling. (current)
- * @param   pcUsage Pointer to usage variable. (output)
- *                  The usage count is returned.
- * @sketch
- */
-ULONG LDRCALL   fakeldrWasLoadModuled(HMTE hmte, PPTDA pptda, PULONG pcUsage)
-{
-    KLOGENTRY3("ULONG LDRCALL","HMTE hmte, PPTDA pptda, PULONG pcUsage", hmte, pptda, pcUsage);
-    DUMMY();
-    printf("fakeldrWasLoadModuled:                 - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-/**
- * LDRGetProcAddr gets address and proctype for a entry point to a module.
- * @returns NO_ERROR if the module was LoadModuled.
- *          ERROR_INVALID_HANDLE if not LoadModuled.
- * @param   hmte            Handle of module.
- * @param   ulOrdinal       Procedure ordinal.
- * @param   pszName         Pointer to procedure name.
- *                          NULL is allowed. Ignored if ulOrdinal is not zero.
- * @param   pulAddress      Pointer to address variable. (output)
- * @param   fFlat           TRUE if a flat 0:32 address is to be returned.
- *                          FALSE if a far 16:16 address is to be returned.
- * @param   pulProcType     Pointer to procedure type variable. (output)
- *                          NULL is allowed. (DosQueryProcAddr uses NULL)
- *                          In user space.
- * @sketch
- */
-ULONG LDRCALL fakeLDRGetProcAddr(HMTE hmte, ULONG ulOrdinal, PCSZ pszName, PULONG pulAddress, BOOL fFlat, PULONG pulProcType)
-{
-    KLOGENTRY6("ULONG LDRCALL","HMTE hmte, ULONG ulOrdinal, PCSZ pszName, PULONG pulAddress, BOOL fFlat, PULONG pulProcType", hmte, ulOrdinal, pszName, pulAddress, fFlat, pulProcType);
-    DUMMY();
-    printf("fakeLDRGetProcAddr:                    - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-
-/**
- * Frees a task.
- * @param   pPTDA   Pointer to per task data area of the task to be freed.
- */
-void KRNLCALL fakeLDRFreeTask(PPTDA pPTDA)
-{
-    KLOGENTRY1("void KRNLCALL","PPTDA pPTDA", pPTDA);
-    DUMMY();
-    printf("fakeLDRFreeTask:                       - not implemented\n");
-    KLOGEXITVOID();
-}
-
-/**
- * Converts 16:32 address to FLAT 32-bits address.
- * @returns Flat 32-bits address.
- *          -1 on error.
- * @param   ulOffset    Offset.
- * @param   usSel       Selector.
- */
-PVOID KRNLCALL   fakeSELVirtToLin(ULONG ulOffset, USHORT usSel)
-{
-    KLOGENTRY2("PVOID KRNLCALL","ULONG ulOffset, USHORT usSel", ulOffset, usSel);
-    DUMMY();
-    printf("fakeSELVirtToLin:                      - not implemented\n");
-    KLOGEXIT((void*)-1);
-    return (void*)-1;
-}
-
-/**
- * Converts selector to linar address.
- * @returns Flat 32-bits address.
- *          -1 on error.
- * @param   usSel       Selector.
- */
-PVOID KRNLCALL   fakeSELConvertToLinear(USHORT usSel, PPTDA pPTDA)
-{
-    KLOGENTRY2("PVOID KRNLCALL","USHORT usSel, PPTDA pPTDA", usSel, pPTDA);
-    DUMMY();
-    printf("fakeSELConvertToLinear:                - not implemented\n");
-    KLOGEXIT((void*)-1);
-    return (void*)-1;
-}
-
-/**
- * Converts a 32-bit flat pointer to an selector if possible.
- * @returns Selector (eax), offset (edx).
- * @param   pv      Flat 32-bit address.
- * @param   ulRPL   Requested privilege level of the selector.
- * @param   hPTDA   PTDA handle. NULLHANDLE means current PTDA.
- */
-USHORT KRNLCALL  fakeSELConvertToSelector(PVOID pv, ULONG ulRPL, HPTDA hPTDA)
-{
-    KLOGENTRY3("USHORT KRNLCALL","PVOID pv, ULONG ulRPL, HPTDA hPTDA", pv, ulRPL, hPTDA);
-    DUMMY();
-    printf("fakeSELConvertToSelector:              - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
-/**
- * Allocates a GDT selector.
- * @returns OS2 return code. (I.e. NO_ERROR on success.)
- * @param   pusSel  Where to put the selector on successful return.
- */
-ULONG  KRNLCALL  fakeSELAllocGDT(PUSHORT pusSel)
-{
-    KLOGENTRY1("ULONG KRNLCALL","PUSHORT pusSel", pusSel);
-    DUMMY();
-    printf("fakeSELAllocGDT:                       - not implemented\n");
-    KLOGEXIT(ERROR_NOT_SUPPORTED);
-    return ERROR_NOT_SUPPORTED;
-}
-
Index: trunk/src/win32k/kKrnlLib/testcase/tstFakeA.asm
===================================================================
--- trunk/src/win32k/kKrnlLib/testcase/tstFakeA.asm	(revision 8210)
+++ 	(revision )
@@ -1,637 +1,0 @@
-; $Id: tstFakeA.asm,v 1.1 2002-03-30 17:05:47 bird Exp $
-;
-; Fake assembly imports.
-;
-; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-;
-; Project Odin Software License can be found in LICENSE.TXT
-;
-
-    .386
-
-;
-;   Defined Constants And Macros
-;
-    INCL_BASE EQU 1
-
-;
-;   Include files
-;
-    include devsegdf.inc
-    include devhlp.inc
-    include os2.inc
-    include options.inc
-
-
-;
-;   Exported symbols
-;
-    public fakepTCBCur
-    public fakepPTDACur
-    public fakeptda_start
-    public fakeptda_environ
-    public fakeptda_handle
-    public fakeptda_module
-    public fakeptda_ptdasem
-    public fakeptda_pBeginLIBPATH
-    public fakef_FuStrLenZ
-    public fakef_FuStrLen
-    public fakef_FuBuff
-    public fakeg_tkExecPgm
-    public faketkStartProcess
-    public CalltkExecPgm
-    public _fakeldrOpenPath@20
-    public fakeKMEnterKmodeSEF
-    public fakeKMExitKmodeSEF8
-    public fakeRASRST
-    public fakedh_SendEvent
-    public fakeh_POST_SIGNAL
-    public _exeentry                    ; VAC stuff
-
-
-;
-;   Imported Functions and Variables.
-;
-    extrn tkExecPgmWorker:PROC          ; fake.c
-    extrn _fakeLDRClearSem@0:PROC       ; fake.c
-    extrn _fakeKSEMRequestMutex@8:PROC  ; fake.c
-    extrn _fakeldrOpenPath_old@16:PROC  ; fake.c
-    extrn _fakeldrOpenPath_new@20:PROC  ; fake.c
-    extrn _options:kKLOptions           ; d16globl.c
-    extrn _exestart:FAR                 ; VAC stuff
-
-;
-; Stack segment
-;
-STACK32 segment para stack 'STACK' use32
-    db 1000h dup(?)
-STACK32 ends
-MYSTACKGROUP group STACK32              ; separates the stack from the other data segments.
-
-
-;
-; Prevent exeentry.obj from being linked in.
-; That way we can make our own stack.
-;
-DATA32 segment
-    _exeentry dd 0
-DATA32 ends
-
-
-
-DATA16 segment
-; Fake data in 16-bit segment.
-fakepTCBCur         dd      offset FLAT:fakeTCB
-fakepPTDACur        dd      offset FLAT:fakeptda_start
-
-; PTDA - Only use environ and ExecChild.
-fakeptda_start              LABEL DWORD
-fakeptda_pPTDAParent        dd      0
-fakeptda_pPTDASelf          dd      offset FLAT:fakeptda_start
-fakeptda_pPTDAFirstChild    dd      0
-fakeptda_pPTDAExecChild     dd      offset FLAT:fakeptda_start
-fakeptda_dummy              db  123 dup (0)
-fakeptda_environ            dw      1   ; 1 is the hardcoded HOB of the kKrnlLibtst.exe's environment.
-fakeptda_ptdasem            db  20  dup (0) ; PTDA semaphore - Intra-Process serialisation mutex KSEM (sg244640).
-fakeptda_handle             dw      2   ; 2 is the hardcoded HPTDA of the current process.
-fakeptda_module             dw      1   ; 1 is the hardcoded HMTE of the current executable module.
-fakeptda_pBeginLIBPATH      dd      0   ; BEGINLIBPATH not implemented.
-                            dd      0   ; ENDLIBPATH not implemented.
-
-
-; TCB - just needs some dummy data for reading and writing to the TCBFailErr.
-fakeTCB                     db 220h dup (0CCh)
-
-DATA16 ENDS
-
-
-CODE16 SEGMENT
-
-
-; Scans strings until empy-string is reached.
-; input:  bx:di
-; uses:   nearly all (save bp)
-; return: cx size - CF clear
-;         ax error- CF set
-fakef_FuStrLenZ PROC FAR
-    push    2                           ; required by all 16-bit far procedures.
-    push    2                           ; dummy code.
-    push    2                           ; dummy code.
-    push    2                           ; dummy code.
-    push    es
-
-    mov     dx, di                      ; save di pointer.
-    cmp     bx, 7                       ; check if NULL ptr.
-    jle     ffslz_badselector
-
-    mov     es, bx                      ; es:di -> string
-    mov     cx, di
-    not     cx                          ; maximum length is to segment end.
-    xor     ax, ax                      ; test against zero (scasb uses al to cmp with).
-
-ffslz_loop:
-    repnz scasb
-    jnz     ffslz_no_term               ; jump if cx = 0
-    dec     cx                          ; check if next is NULL too
-    scasb
-    jnz     ffslz_loop
-
-ffslz_retok:
-    mov     cx, di
-    sub     cx, dx                      ; cx <- size (end ptr - start ptr)
-    pop     es
-    add     sp, 8
-    clc
-    db      66h
-    retf
-
-ffslz_badselector:
-    mov     ax, ERROR_INVALID_SELECTOR
-    jmp     ffslz_reterr
-
-;ffslz_invalidptr:
-;    mov     ax, ERROR_INVALID_ACCESS
-;    jmp     ffslz_reterr
-
-ffslz_no_term:
-    mov     ax, ERROR_TERMINATOR_NOT_FOUND
-ffslz_reterr:
-    pop     es
-    add     sp, 8
-    stc
-    db      66h
-    retf
-fakef_FuStrLenZ ENDP
-
-
-;
-; Stringlength - Fake
-; input:  bx:di
-; uses:   nearly all (save bp)
-; return: cx size - CF clear
-;         ax error- CF set
-fakef_FuStrLen PROC FAR
-    push    2                           ; required by all 16-bit far procedures.
-    push    2                           ; dummy code.
-    push    2                           ; dummy code.
-    push    2                           ; dummy code.
-    push    es
-
-    mov     dx, di                      ; save di pointer.
-    cmp     bx, 7                       ; check if NULL ptr.
-    jle     ffslz_badselector
-
-    mov     es, bx                      ; es:di -> string
-    mov     cx, di
-    not     cx                          ; maximum length is to segment end.
-    xor     ax, ax                      ; test against zero (scasb uses al to cmp with).
-
-    repnz scasb
-    jnz     ffslz_no_term               ; jump if cx = 0
-
-ffslz_retok:
-    mov     cx, di
-    sub     cx, dx                      ; cx <- size (end ptr - start ptr)
-    pop     es
-    add     sp, 8
-    clc
-    db      66h
-    retf
-
-ffslz_badselector:
-    mov     ax, ERROR_INVALID_SELECTOR
-    jmp     ffslz_reterr
-
-;ffslz_invalidptr:
-;    mov     ax, ERROR_INVALID_ACCESS
-;    jmp     ffslz_reterr
-
-ffslz_no_term:
-    mov     ax, ERROR_TERMINATOR_NOT_FOUND
-ffslz_reterr:
-    pop     es
-    add     sp, 8
-    stc
-    db      66h
-    retf
-fakef_FuStrLen ENDP
-
-
-;memcpy
-;input:  bx:si pointer to source
-;        es:di pointer to target
-;        cx    count of bytes to copy
-;uses:   nearly all (save bp), es, ds
-;return: success CF clear
-;        failure CF set
-fakef_FuBuff PROC FAR
-    push    2                           ; required by all 16-bit far procedures.
-    push    2                           ; dummy code.
-    push    2                           ; dummy code.
-    push    2                           ; dummy code.
-    push    es
-
-    cmp     bx, 7                       ; check if NULL ptr.
-    jle     ffslz_badselector
-    mov     ax, es
-    cmp     bx, 7                       ; check if NULL ptr.
-    jle     ffslz_badselector
-
-    mov     ds, bx                      ; ds:si -> string
-    mov     ax, di
-    not     ax
-    cmp     ax, cx                      ; crosses segment boundrary...
-    jb      ffslz_invalidptr
-    mov     ax, si
-    not     ax
-    cmp     ax, cx                      ; crosses segment boundrary...
-    jb      ffslz_invalidptr
-
-;    movzx   esi, si
-;    movzx   edi, di
-;    movzx   ecx, cx
-;    db      66h                         ; force it use extended registers.
-    rep movsb
-
-ffslz_retok:
-    xor     ax, ax
-    mov     cx, di
-    sub     cx, dx                      ; cx <- size (end ptr - start ptr)
-    pop     es
-    add     sp, 8
-    clc
-    db      66h
-    retf
-
-ffslz_badselector:
-    mov     ax, ERROR_INVALID_SELECTOR
-    jmp     ffslz_reterr
-
-ffslz_invalidptr:
-    int     3
-    mov     ax, ERROR_INVALID_ACCESS
-    jmp     ffslz_reterr
-
-ffslz_no_term:
-    mov     ax, ERROR_TERMINATOR_NOT_FOUND
-ffslz_reterr:
-    pop     es
-    add     sp, 8
-    stc
-    db      66h
-    retf
-fakef_FuBuff ENDP
-
-
-;;
-; RASRST faker.
-; @status   stupid stub.
-fakeRASRST proc near
-    mov     ax, ds
-    mov     ax, ds
-    mov     ax, ds
-    mov     ax, ds
-    int     3
-fakeRASRST endp
-
-
-;;
-; dh_SendEvent faker.
-; @status   stupid stub.
-fakedh_SendEvent proc near
-    mov     ax, ds
-    mov     ax, ds
-    mov     ax, ds
-    mov     ax, ds
-    int     3
-fakedh_SendEvent endp
-
-
-;;
-; POST_SIGNAL faker
-fakeh_POST_SIGNAL proc near
-    ; dummy prolog.
-    mov     ax, ds
-    mov     ax, ds
-    mov     ax, ds
-    mov     ax, ds
-    int     3
-fakeh_POST_SIGNAL endp
-
-
-CODE16 ends
-
-
-
-CODE32 segment
-;;
-; Faker of which simply clears the loader semaphore.
-; @cproto    none! (void _Optlink   faketkStartProcess(void))
-; @returns
-; @param
-; @uses
-; @equiv
-; @time
-; @sketch
-; @status
-; @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-; @remark
-faketkStartProcess PROC NEAR
-    push    ebp
-    mov     ebp, esp
-
-    push    ebx
-    push    ecx
-
-    call    _fakeLDRClearSem@0
-
-    pop     ecx
-    pop     ebx
-
-    xor     eax, eax
-    leave
-    ret
-faketkStartProcess ENDP
-
-
-;;
-; Fake g_tkExecPgm implementation.
-; @proto     none. (void _Optlink fakeg_tkExecPgm(void);)
-; @returns   same as tkExecPgm: eax, edx and carry flag
-; @param     ax     Exec flag
-;            ds:dx  Filename address. (String)
-;            es:bx  Environment address. (String)
-;            di:si  Argument address. (String)
-; @uses      all - bp
-; @sketch    Copy the filename and arguments into a buffer we
-;            may modify later if this is a UNIX shellscript or
-;            a PE-file started by pe.exe.
-; @status    completely implemented.
-; @author    knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-;
-;
-fakeg_tkExecPgm PROC NEAR
-    push    ebp
-    mov     ebp, esp
-
-    ;
-    ; Call C worker
-    ;
-    sub     esp, 10h
-    movzx   eax, ax
-    mov     [esp + 00h], eax            ; ExecFlag DWORD
-
-    mov     ax, es
-    SelToFlat
-    mov     [esp + 08h], eax            ; Environment ptr.
-    mov     ecx, eax
-
-    mov     ax, ds
-    mov     bx, dx
-    SelToFlat
-    mov     [esp + 0ch], eax            ; Filename ptr
-
-    mov     ax, di
-    mov     bx, si
-    SelToFlat
-    mov     [esp + 04h], eax            ; Argument ptr
-    mov     edx, eax
-
-    mov     eax, [esp + 00h]            ; ExecFlag DWORD in eax
-
-    mov     bx, seg FLAT:DATA32
-    mov     ds, bx                      ; Make ds flat
-    mov     es, bx                      ; Make es flat
-
-    call    tkExecPgmWorker             ;(ULONG flags, arg,    env,   prog)
-    add     esp, 10                     ;       eax,   edx,    ecx,
-                                        ;     ebp+8, ebp+c, ebp+10, ebp+14
-                                        ;     esp+0, esp+4, esp+08, esp+0c
-    or      eax, eax
-    jnz     ftkep_ret
-    call    faketkStartProcess          ; If succesfully so far. call start process.
-    jmp     ftkep_ret2                  ; <Currently no parameters are implemented.>
-
-ftkep_ret:
-    push    eax
-    call    _fakeLDRClearSem@0          ; clear the semaphore.
-    pop     eax
-
-ftkep_ret2:
-    leave
-    ret
-fakeg_tkExecPgm ENDP
-
-
-;;
-; Calls the fakeg_tkExecPgm procedure.
-; @cproto   ULONG _Optlink  CalltkExecPgm(
-;                               ULONG   execFlags,
-;                               PCSZ    pArg,
-;                               PCSZ    pEnv,
-;                               PCSZ    pExecName);
-; @returns
-; @param    eax (ebp +08h)  execFlags
-; @param    edx (ebp +0ch)  pArg
-; @param    ecx (ebp +10h)  pEnv
-; @param    ebp + 14h       pExecName
-; @uses     eax, ecx, edx
-; @status   completely implemented.
-; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-; @remark
-CalltkExecPgm PROC NEAR
-    push    ebp
-    mov     ebp, esp
-    push    ebx
-    push    edi
-    push    esi
-    push    es
-    push    ds
-
-    ; Save parameters
-    mov     [ebp+08h], eax
-
-    ;
-    ; create input for fakeg_tkExecPgm
-    ;
-    mov     eax, edx
-    xor     edi, edi
-    xor     esi, esi
-    or      eax, eax
-    jz      ctkep1
-    FlatToSel
-    mov     di, ax
-    mov     esi, ebx                    ; di:si -> arguments
-ctkep1:
-
-    mov     eax, [ebp + 14h]
-    xor     edx, edx
-    mov     ds, dx
-    or      eax, eax
-    jz      ctkep2
-    FlatToSel
-    mov     ds, ax
-    mov     edx, ebx                    ; ds:dx -> executable filename
-ctkep2:
-
-    mov     eax, ecx
-    xor     ebx, ebx
-    mov     es, bx
-    or      eax, eax
-    jz      ctkep3
-    FlatToSel
-    mov     es, ax
-    mov     eax, ebx                    ; es:bx -> environment.
-ctkep3:
-
-    mov     eax, [ebp+08h]              ; ax = exec flags.
-
-    call    far ptr FLAT:fakeg_tkExecPgm
-
-    ;
-    ; Restore and return.
-    ;
-    pop     ds
-    pop     es
-    pop     esi
-    pop     edi
-    pop     ebx
-    leave
-    ret
-CalltkExecPgm ENDP
-
-
-;;
-; Gets the selector for the CODE16 segment.
-; @cproto   USHORT  _Optlink GetSelectorCODE16(void)
-; @returns  Selector for the CODE16 segment.
-; @uses     eax
-; @status   completely implemented.
-; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-GetSelectorCODE16 PROC NEAR
-    xor     eax, eax
-    mov     ax, seg CODE16
-    ret
-GetSelectorCODE16 ENDP
-
-
-;;
-; Gets the selector for the DATA16 segment.
-; @cproto   USHORT  _Optlink GetSelectorDATA16(void)
-; @returns  Selector for the DATA16 segment.
-; @uses     eax
-; @status   completely implemented.
-; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-GetSelectorDATA16 PROC NEAR
-    xor     eax, eax
-    mov     ax, seg DATA16
-    ret
-GetSelectorDATA16 ENDP
-
-
-;;
-; Gets the selector for the CODE32 segment.
-; @cproto   USHORT  _Optlink GetSelectorCODE32(void)
-; @returns  Selector for the CODE32 segment.
-; @uses     eax
-; @status   completely implemented.
-; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-GetSelectorCODE32 PROC NEAR
-    xor     eax, eax
-    mov     ax, seg FLAT:CODE32
-    ret
-GetSelectorCODE32 ENDP
-
-;;
-; Gets the selector for the DATA32 segment.
-; @cproto   USHORT  _Optlink GetSelectorDATA32(void)
-; @returns  Selector for the DATA32 segment.
-; @uses     eax
-; @status   completely implemented.
-; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-GetSelectorDATA32 PROC NEAR
-    xor     eax, eax
-    mov     ax, seg FLAT:DATA32
-    ret
-GetSelectorDATA32 ENDP
-
-
-;;
-; Wrapper for fakeldrOpenPath.
-; @cproto       ULONG LDRCALL   fakeldrOpenPath(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful, ULONG lLibPath);
-; @returns      Return of the current fakeldrOpenPath
-; @param        pachFilename  Pointer to modulename. Not zero terminated!
-; @param        cchFilename   Modulename length.
-; @param        plv           Loader local variables? (Struct from KERNEL.SDF)
-; @param        pful          Pointer to flags which are passed on to ldrOpen.
-; @param        lLibPath      New parameter in build 14053.
-;                             ldrGetMte calls with 1
-;                             ldrOpenNewExe calls with 3
-;                             This is compared to the initial libpath index.
-;                                 The libpath index is:
-;                                     BEGINLIBPATH    1
-;                                     LIBPATH         2
-;                                     ENDLIBPATH      3
-;                                 The initial libpath index is either 1 or 2.
-;                             - ignored -
-; @uses         ecx, eax, edx
-; @sketch
-; @status
-; @author       knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-; @remark
-_fakeldrOpenPath@20 PROC NEAR
-    ASSUME ds:FLAT
-    ; dummy prolog.
-    push    ebp
-    mov     ebp, esp
-    sub     esp, 10h
-    add     esp, 10h
-    pop     ebp
-    ; real code
-    cmp     FLAT:DATA16:_options.ulBuild, 14053
-    jge     new
-    jmp     near ptr FLAT:CODE32:_fakeldrOpenPath_old@16
-new:
-    jmp     near ptr FLAT:CODE32:_fakeldrOpenPath_new@20
-_fakeldrOpenPath@20 ENDP
-
-
-
-;;
-; This is called at kernel entry.
-; @cproto   none
-; @returns  nothing
-; @param    none
-; @uses     nothing
-; @status   stub.
-; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-fakeKMEnterKmodeSEF proc near
-    ; dummy prolog.
-    push    ebp
-    mov     ebp, esp
-    sub     esp, 10h
-    leave
-    ret
-fakeKMEnterKmodeSEF endp
-
-
-;;
-; This is called at kernel exit.
-; @cproto   none
-; @returns  nothing
-; @param    none
-; @uses     nothing
-; @status   stub.
-; @author   knut st. osmundsen (knut.stange.osmundsen@mynd.no)
-fakeKMExitKmodeSEF8 proc near
-    ; dummy prolog.
-    push    ebp
-    mov     ebp, esp
-    sub     esp, 10h
-    leave
-    ret
-fakeKMExitKmodeSEF8 endp
-
-CODE32 ends
-
-end _exestart
Index: trunk/src/win32k/kKrnlLib/testcase/tstInit.asm
===================================================================
--- trunk/src/win32k/kKrnlLib/testcase/tstInit.asm	(revision 8210)
+++ 	(revision )
@@ -1,141 +1,0 @@
-; $Id: tstInit.asm,v 1.1 2002-03-30 17:05:47 bird Exp $
-;
-; Thunks to call stratgy entry points with init packets.
-;
-; Copyright (c) 2000-2001 knut st. osmundsen (kosmunds@csc.com)
-;
-; Project Odin Software License can be found in LICENSE.TXT
-;
-    .386
-
-;
-; Include files
-;
-    include devsegdf.inc
-    include os2.inc
-
-
-;
-; Exported symbols
-;
-    public  InitkKrnlHlp
-    public  InitkKrnlLib
-
-
-;
-; extrns
-;
-    extrn   _strategyAsm0:PROC
-    extrn   _strategyAsm1:PROC
-
-CODE32 SEGMENT
-;;
-; Initiates the kKrnlHlp device driver.
-; @cproto    ULONG _Optlink InitkKrnlHlp(PVOID pvPacket);
-; @returns
-; @param     (ss:)eax    pvPacket
-;                   This parameter is pointer to a stack object which haven't
-;                   had SSToDS() applied. This is done in this way because it
-;                   lightens the job to make a far 16 bits pointer of it.
-; @uses      eax, ecx, edx
-; @sketch
-; @status
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark
-InitkKrnlHlp PROC NEAR
-    ASSUME ds:FLAT, es:NOTHING, ss:NOTHING
-    push    ebx
-    push    ds
-    push    es
-    ;
-    ; Make 16:16 ptr to packet pointed to by ss:eax
-    ;
-    mov     bx, ss
-    mov     es, bx
-    mov     bx, ax
-
-    ;
-    ; Set ds to DATA16
-    ;
-    mov     ax, seg DATA16
-    mov     ds, ax
-
-    ;
-    ; Call stratgy entry point.
-    ;
-    jmp far ptr CODE16:Thunk16_kKrnlHlp
-Thunk32_kKrnlHlp::
-    movzx   eax, ax                     ; Cast USHORT to ULONG.
-
-    pop     es
-    pop     ds
-    pop     ebx
-    ret
-InitkKrnlHlp ENDP
-CODE32 ENDS
-
-CODE16 SEGMENT
-    ; Call strategy entry point for kKrnlHlp.
-Thunk16_kKrnlHlp::
-    call    far ptr CODE16:_strategyAsm0
-    jmp far ptr FLAT:Thunk32_kKrnlHlp
-CODE16 ENDS
-
-
-
-CODE32 SEGMENT
-;;
-; Initiates the kKrnlLib device driver.
-; @cproto    ULONG _Optlink InitkKrnlLib(PVOID pvPacket);
-; @returns
-; @param     (ss:)eax    pvPacket
-;                   This parameter is pointer to a stack object which haven't
-;                   had SSToDS() applied. This is done in this way because it
-;                   lightens the job to make a far 16 bits pointer of it.
-; @uses      eax, ecx, edx
-; @sketch
-; @status
-; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
-; @remark
-InitkKrnlLib PROC NEAR
-    ASSUME ds:FLAT, es:NOTHING, ss:NOTHING
-    push    ebx
-    push    ds
-    push    es
-    ;
-    ; Make 16:16 ptr to packet pointed to by ss:eax
-    ;
-    mov     bx, ss
-    mov     es, bx
-    mov     bx, ax
-
-    ;
-    ; Set ds to DATA16
-    ;
-    mov     ax, seg DATA16
-    mov     ds, ax
-
-    ;
-    ; Call stratgy entry point.
-    ;
-    jmp far ptr CODE16:Thunk16_InitkKrnlLib
-Thunk32_InitkKrnlLib::
-    movzx   eax, ax                     ; Cast USHORT to ULONG.
-
-    pop     es
-    pop     ds
-    pop     ebx
-    ret
-InitkKrnlLib ENDP
-CODE32 ENDS
-
-CODE16 SEGMENT
-    ; Call strategy entry point for kKrnlLib.
-Thunk16_InitkKrnlLib::
-    call    far ptr CODE16:_strategyAsm1
-    jmp far ptr FLAT:Thunk32_InitkKrnlLib
-
-CODE16 ENDS
-
-
-END
Index: trunk/src/win32k/kKrnlLib/testcase/tstkKrnlLib.c
===================================================================
--- trunk/src/win32k/kKrnlLib/testcase/tstkKrnlLib.c	(revision 8210)
+++ 	(revision )
@@ -1,892 +1,0 @@
-/* $Id: tstkKrnlLib.c,v 1.2 2002-04-01 12:44:11 bird Exp $
- *
- * kKrnlLib test module.
- *
- * Copyright (c) 2000-2001 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- *
- * Project Odin Software License can be found in LICENSE.TXT
- *
- */
-
-/*******************************************************************************
-*   Defined Constants And Macros                                               *
-*******************************************************************************/
-
-#define SEL_FLATMASK        0x01fff0000
-#define SEL_FLAT_SHIFT      0x0d
-#define SEL_LDT_RPL3        0x07
-
-#define SelToFlat(sel, off) \
-    (PVOID)( (((unsigned)(sel) << SEL_FLAT_SHIFT) & SEL_FLAT_MASK) + (unsigned)(off))
-
-#define FlatToSel(flataddr) \
-    (PVOID)( ( (((unsigned)(flataddr) << 3) & 0xfff80000) | (SEL_LDT_RPL3 << 16) ) | ((unsigned)(flataddr) & 0xffff) )
-
-#define assert(expr) ((expr) ? (void)0 : __interrupt(3))
-
-#define DWORD   ULONG
-#define WORD    USHORT
-
-/*******************************************************************************
-*   Internal Functions                                                         *
-*******************************************************************************/
-#define INCL_BASE
-#define INCL_SSTODS
-#define FOR_EXEHDR 1
-#include <os2.h>
-#include <exe386.h>
-#include <newexe.h>
-
-#include "devSegDf.h"                   /* kKrnlLib segment definitions. */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdarg.h>
-
-#include "options.h"
-#include "dev1632.h"
-#include "dev32.h"
-#include "devcmd.h"
-#define INCL_OS2KRNL_ALL
-#include "os2krnl.h"
-
-#define INCL_KKL_ALL
-#include "kKrnlLib.h"
-
-#include "ProbKrnl.h"
-#include "krnlPrivate.h"
-#include "testcase.h"
-
-#include <stdlib.h>
-
-
-
-
-/** @design kKrnlLib Ring-3 Testing
- * I'll try to make it possible to test parts or all the kKrnlLib code in ring-3.
- * To archive this the interface against the kernel has to be faked/emulated.
- * More precisely:
- *      - DevHelps.
- *      - Worker routines for imported kernel functions. (calltab.asm jumps to them.)
- *      - 16-bit stack 1Kb.
- *      - Strategy calls.
- *      - Fake module loadings (= testcases).
- *      - ?
- *
- * Some of the initstuff has to be omitted, at least in the start. The first
- * goal is to be able to test _ldrOpenPath and _ldrOpen.
- *
- *
- * @subsection  Device Helper Routines
- *
- * These I think we'll implemented by providing the kernel interface, a far 16:16
- * pointer to a dh-router. Our router will in most cases thunk back to 32-bit
- * code and implementet the required devhelp routines in pure C code.
- *
- * These are the needed routines:
- *      - DevHelp_VirtToLin   - ok
- *      - DevHelp_VMAlloc     - ok
- *      - DevHelp_VMFree      - ok
- *      - DevHelp_GetDOSVar   - ok
- *      - DevHelp_VMLock
- *      - DevHelp_VMUnLock  ?
- *      - DevHelp_VMSetMem  ?
- *      - DevHelp_Yield     ?
- *
- *
- * @subsection  Worker routines for imported kernel functions
- *
- * Create worker routines for the imported kernel functions. Calltab will be
- * set up to jump to them. This is done in d32init.c, in stead of using
- * the importtab.
- *
- * Some of these workers will be parts of testcases. For example g_tkExecPgm
- * and _LDRQAppType.
- *
- * Only the imported functions are implemented on demand. Initially these
- * functions will be provided:
- *      - ldrOpen
- *      - ldrRead
- *      - ldrClose
- *      - ldrOpenPath
- *      - SftFileSize
- *
- *
- * @subsection  16-bit stack
- *
- * To make this test real the stack has to be 16-bit and _very_ small (1KB).
- * TKSSBase have to be implemented by the DevHelp_GetDOSVar DosTable2 stuff.
- * The stack will be thunked to 16-bit by a thunking procedure called from
- * main. This procedure thunks the stack (quite easy, we're in tiled memory!),
- * set the value of TKSSBase, calls a C function which does all the rest of
- * the testing. When taht function returns, the stack will be thunked back
- * to 32-bit, TKSSBase will be zeroed, and the procedure returns to main.
- *
- *
- * @subsection  Straegy routine calls (not implemented)
- *
- * We'll call the strategy entry points with init request packets. The initiation
- * will require a replacement for DosDevIOCtl (16-bit) which calls the
- * kKrnlHlp strategy routine. We'll also have to provide fakes for kernel probing,
- * verifing and overloading in d32init.c.
- *
- *
- * @subsection  Order of events
- *
- * This is the order this testing environment currently works:
- *      1) init devhelp subsystem
- *      2) init workers
- *      3) thunk stack
- *      4) Fake 16-bit init. Set TKSSBase, FlatDS, FlatCS, DevHelp pointer....
- *      5) Call R0Init32().
- *         (d32init.c is modified a bit to setup the calltab correctly.)
- *      6) Start testing...
- *      7) Testing finished - thunk stack back to 32-bit.
- */
-
-
-/*******************************************************************************
-*   Structures and Typedefs                                                    *
-*******************************************************************************/
-#if !defined(QS_MTE) || defined(QS_MODVER)
-   /* From OS/2 Toolkit v4.5 (BSEDOS.H) */
-
-   /* Global Record structure
-    * Holds all global system information. Placed first in user buffer
-    */
-   typedef struct qsGrec_s {  /* qsGrec */
-           ULONG         cThrds;
-           ULONG         c32SSem;
-           ULONG         cMFTNodes;
-   }qsGrec_t;
-
-   /*
-    *      System wide MTE information
-    *      ________________________________
-    *      |       pNextRec                |----|
-    *      |-------------------------------|    |
-    *      |       hmte                    |    |
-    *      |-------------------------------|    |
-    *      |       ctImpMod                |    |
-    *      |-------------------------------|    |
-    *      |       ctObj                   |    |
-    *      |-------------------------------|    |
-    *      |       pObjInfo                |----|----------|
-    *      |-------------------------------|    |          |
-    *      |       pName                   |----|----|     |
-    *      |-------------------------------|    |    |     |
-    *      |       imported module handles |    |    |     |
-    *      |          .                    |    |    |     |
-    *      |          .                    |    |    |     |
-    *      |          .                    |    |    |     |
-    *      |-------------------------------| <--|----|     |
-    *      |       "pathname"              |    |          |
-    *      |-------------------------------| <--|----------|
-    *      |       Object records          |    |
-    *      |       (if requested)          |    |
-    *      |_______________________________|    |
-    *                                      <-----
-    *      NOTE that if the level bit is set to QS_MTE, the base Lib record will be followed
-    *      by a series of object records (qsLObj_t); one for each object of the
-    *      module.
-    */
-
-   typedef struct qsLObjrec_s {  /* qsLOrec */
-           ULONG         oaddr;  /* object address */
-           ULONG         osize;  /* object size */
-           ULONG         oflags; /* object flags */
-   } qsLObjrec_t;
-
-   typedef struct qsLrec_s {     /* qsLrec */
-           void  FAR        *pNextRec;      /* pointer to next record in buffer */
-           USHORT           hmte;           /* handle for this mte */
-           USHORT           fFlat;          /* true if 32 bit module */
-           ULONG            ctImpMod;       /* # of imported modules in table */
-           ULONG            ctObj;          /* # of objects in module (mte_objcnt)*/
-           qsLObjrec_t FAR  *pObjInfo;      /* pointer to per object info if any */
-           UCHAR     FAR    *pName;         /* -> name string following struc */
-   } qsLrec_t;
-
-
-
-   /* Pointer Record Structure
-    *      This structure is the first in the user buffer.
-    *      It contains pointers to heads of record types that are loaded
-    *      into the buffer.
-    */
-
-   typedef struct qsPtrRec_s {   /* qsPRec */
-           qsGrec_t        *pGlobalRec;
-           void            *pProcRec;      /* ptr to head of process records */
-           void            *p16SemRec;     /* ptr to head of 16 bit sem recds */
-           void            *p32SemRec;     /* ptr to head of 32 bit sem recds */
-           void            *pMemRec;       /* ptr to head of shared mem recs */
-           qsLrec_t        *pLibRec;       /* ptr to head of mte records */
-           void            *pShrMemRec;    /* ptr to head of shared mem records */
-           void            *pFSRec;        /* ptr to head of file sys records */
-   } qsPtrRec_t;
-
-#endif
-
-
-/*******************************************************************************
-*   Global Variables                                                           *
-*******************************************************************************/
-extern BOOL     fInited;                /* malloc.c */
-int             iTestcaseNo;
-int             cObjectsFake = 14;
-OTE             aKrnlOTE[24];
-
-
-/*******************************************************************************
-*   External Functions                                                         *
-*******************************************************************************/
-#ifndef QS_MTE
-   /* from OS/2 Toolkit v4.5 */
-
-   APIRET APIENTRY DosQuerySysState(ULONG EntityList, ULONG EntityLevel, PID pid,
-                                    TID tid, PVOID pDataBuf, ULONG cbBuf);
-    #define QS_MTE         0x0004
-#endif
-
-
-/*******************************************************************************
-*   Internal Functions                                                         *
-*******************************************************************************/
-void    syntax(void);
-int     kernelInit(int iTest, int argc, char **argv);
-void    workersinit(void);
-void    initRPInit(RP32INIT *pRpInit, char *pszInitArgs);
-int     tests(int iTest, int argc, char **argv);
-int     TestCase1(int argc, char **argv);
-int     TestCase2(void);
-int     CompareOptions(struct kKLOptions *pOpt, ULONG fExpKernel, ULONG ulExpKernelBuild, USHORT usExpVerMajor, USHORT usExpVerMinor);
-int     TestCaseExeLoad2(void);
-int     WritekKrnlLibDll(void);
-
-
-/**
- * Main function. Arguments _currently_ unused.
- */
-int main(int argc, char **argv)
-{
-    int         rc;
-
-    /*
-     * Init devhelp subsystems.
-     */
-    dhinit();
-
-    /*
-     * Parse arguments.
-     * (printf don't work before dhinit is called...)
-     */
-    if (argc < 2 || (iTestcaseNo = atoi(argv[1])) <= 0)
-    {
-        syntax();
-        printf("syntax error\n");
-        return -1;
-    }
-
-    /*
-     * Init workers if necessary.
-     */
-    workersinit();
-
-    /*
-     * Init Kernel
-     */
-    if (!kernelInit(iTestcaseNo, argc, argv))
-        return -2;
-
-    /*
-     * Thunk Stack to 16-bits.
-     *
-     * IMPORTANT! From now on SSToDS have to be used when making pointers
-     *            to stack objects.
-     */
-    ThunkStack32To16();
-
-    rc = tests(iTestcaseNo, argc, argv);
-
-    /*
-     * Thunk Stack back to 32-bits.
-     */
-    ThunkStack16To32();
-
-
-    /*
-     * To avoid a sfree error message we'll set fInited (heap init flag) to false.
-     */
-    fInited = FALSE;
-    return rc;
-}
-
-
-/**
- * Prints syntax information.
- * @status  partially implemented.
- * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-void    syntax(void)
-{
-    printf(
-           "kKrnlLibTst.exe v%d.%d.%d - Ring 3 testing of kKrnlLib.sys\n"
-           "syntax: kKrnlLibTst.exe <testcase number> [optional arguments]\n",
-           0,0,4
-           );
-}
-
-
-/**
- * test case 1: Load the specified kernel
- * other cases: Load running kernel.
- * @returns Success indicator. (true/false)
- * @param   iTest   Testcase number.
- * @param   argc    main argc
- * @param   argv    main argv
- * @status  completely implemented.
- * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-int     kernelInit(int iTest, int argc, char **argv)
-{
-    static char     achBuffer[1024*256];
-    char            szError[256];
-    HMODULE         hmod = NULLHANDLE;
-    int             rc;
-    char            szName[CCHMAXPATH];
-    char *          pszSrcName;
-    char *          pszTmp;
-    ULONG           ulAction;
-    HFILE           hFile;
-    struct e32_exe* pe32 = (struct e32_exe*)(void*)&achBuffer[0];
-    qsPtrRec_t *    pPtrRec = (qsPtrRec_t*)(void*)&achBuffer[0];
-    qsLrec_t *      pLrec;
-    int             i;
-    FILESTATUS3     fsts3;
-
-    /*
-     * If not testcase 1, use the running kernel.
-     */
-    if (iTest != 1)
-    {
-        ULONG   ulBootDrv = 3;
-        pszSrcName = "c:\\os2krnl";
-        DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, SSToDS(&ulBootDrv), sizeof(ulBootDrv));
-        pszSrcName[0] = (char)(ulBootDrv + 'a' - 1);
-    }
-    else
-    {
-        if (argc < 3)
-        {
-            printf("Missing parameter!\n");
-            return FALSE;
-        }
-        pszSrcName = argv[2];
-    }
-
-    /*
-     * Make a temporary copy of the kernel.
-     */
-    if (DosScanEnv("TMP", &pszTmp) != NO_ERROR || pszTmp == NULL)
-    {
-        printf("Environment variable TMP is not set.\n");
-        return FALSE;
-    }
-    strcpy(szName, pszTmp);
-    if (szName[strlen(pszTmp) - 1] != '\\' && szName[strlen(pszTmp) - 1] != '/')
-        strcat(szName, "\\");
-    strcat(szName, "os2krnl");
-    rc = DosCopy(pszSrcName, szName, DCPY_EXISTING);
-    if (rc != NO_ERROR)
-    {
-        printf("Failed to copy %s to %s.\n", pszSrcName, szName);
-        return FALSE;
-    }
-    if (DosQueryPathInfo(szName, FIL_STANDARD, &fsts3, sizeof(fsts3)) != NO_ERROR
-        ||  !(fsts3.attrFile = FILE_ARCHIVED)
-        ||  DosSetPathInfo(szName, FIL_STANDARD, &fsts3, sizeof(fsts3), 0) != NO_ERROR
-        )
-    {
-        printf("Failed to set attributes for %s.\n", szName);
-        return FALSE;
-    }
-
-    /*
-     * Patch the kernel.
-     *      Remove the entrypoint.
-     */
-    ulAction = 0;
-    rc = DosOpen(szName, &hFile, &ulAction, 0, FILE_NORMAL,
-                 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
-                 OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
-                 NULL);
-    if (rc != NO_ERROR)
-    {
-        printf("Failed to open temporary kernel file. rc = %d\n", rc);
-        return FALSE;
-    }
-    rc = DosRead(hFile, &achBuffer[0], 0x200, &ulAction);
-    if (rc != NO_ERROR)
-    {
-        DosClose(hFile);
-        printf("Failed to read LX header from temporary kernel file.\n");
-        return FALSE;
-    }
-    pe32 = (struct e32_exe*)(void*)&achBuffer[*(unsigned long*)(void*)&achBuffer[0x3c]];
-    if (*(PUSHORT)pe32->e32_magic != E32MAGIC)
-    {
-        DosClose(hFile);
-        printf("Failed to read LX header from temporary kernel file (2).\n");
-        return FALSE;
-    }
-    pe32->e32_eip = 0;
-    pe32->e32_startobj = 0;
-    pe32->e32_mflags &= ~(E32LIBTERM | E32LIBINIT);
-    if ((rc = DosSetFilePtr(hFile, *(unsigned long*)(void*)&achBuffer[0x3c], FILE_BEGIN, &ulAction)) != NO_ERROR
-        || (rc = DosWrite(hFile, pe32, sizeof(struct e32_exe), &ulAction)) != NO_ERROR)
-    {
-        DosClose(hFile);
-        printf("Failed to write patched LX header to temporary kernel file.\n");
-        return FALSE;
-    }
-    DosClose(hFile);
-
-    /*
-     * Load the module.
-     */
-    rc = DosLoadModule(szError, sizeof(szError), szName, SSToDS(&hmod));
-    if (rc != NO_ERROR && (rc != ERROR_INVALID_PARAMETER && hmod == NULLHANDLE))
-    {
-        printf("Failed to load OS/2 kernel image %s.");
-        return FALSE;
-    }
-
-    /*
-     * Get object information.
-     */
-    rc = DosQuerySysState(QS_MTE, QS_MTE, 0L, 0L, pPtrRec, sizeof(achBuffer));
-    if (rc != NO_ERROR)
-    {
-        printf("DosQuerySysState failed with rc=%d.\n", rc);
-        return FALSE;
-    }
-
-    pLrec = pPtrRec->pLibRec;
-    while (pLrec != NULL)
-    {
-        /*
-         * Bug detected in OS/2 FP13. Probably a problem which occurs
-         * in _LDRSysMteInfo when qsCheckCache is calle before writing
-         * object info. The result is that the cache flushed and the
-         * attempt of updating the qsLrec_t next and object pointer is
-         * not done. This used to work earlier and on Aurora AFAIK.
-         *
-         * The fix for this problem is to check if the pObjInfo is NULL
-         * while the number of objects isn't 0 and correct this. pNextRec
-         * will also be NULL at this time. This will be have to corrected
-         * before we exit the loop or moves to the next record.
-         * There is also a nasty alignment of the object info... Hope
-         * I got it right. (This aligment seems new to FP13.)
-         */
-        if (pLrec->pObjInfo == NULL /*&& pLrec->pNextRec == NULL*/ && pLrec->ctObj > 0)
-            {
-            pLrec->pObjInfo = (qsLObjrec_t*)(void*)(
-                (char*)(void*)pLrec
-                + ((sizeof(qsLrec_t)                            /* size of the lib record */
-                   + pLrec->ctImpMod * sizeof(short)            /* size of the array of imported modules */
-                   + strlen((char*)(void*)pLrec->pName) + 1     /* size of the filename */
-                   + 3) & ~3));                                 /* the size is align on 4 bytes boundrary */
-            pLrec->pNextRec = (qsLrec_t*)(void*)((char*)(void*)pLrec->pObjInfo
-                                                 + sizeof(qsLObjrec_t) * pLrec->ctObj);
-            }
-        if (pLrec->hmte == hmod)
-            break;
-
-        /*
-         * Next record
-         */
-        pLrec = (qsLrec_t*)pLrec->pNextRec;
-    }
-
-    if (pLrec == NULL)
-    {
-        printf("DosQuerySysState(os2krnl): not found\n");
-        return FALSE;
-    }
-    if (pLrec->pObjInfo == NULL)
-    {
-        printf("DosQuerySysState(os2krnl): no object info\n");
-        return FALSE;
-    }
-
-    /*
-     * Fill the aKrnlOTE array.
-     */
-    for (i = 0; i < pLrec->ctObj; i++)
-    {
-        aKrnlOTE[i].ote_size    = pLrec->pObjInfo[i].osize;
-        aKrnlOTE[i].ote_base    = pLrec->pObjInfo[i].oaddr;
-        aKrnlOTE[i].ote_flags   = pLrec->pObjInfo[i].oflags;
-        aKrnlOTE[i].ote_pagemap = i > 0 ? aKrnlOTE[i-1].ote_pagemap + aKrnlOTE[i-1].ote_mapsize : 0;
-        aKrnlOTE[i].ote_mapsize = (pLrec->pObjInfo[i].osize + 0x0FFF) / 0x1000;
-        aKrnlOTE[i].ote_sel     = (USHORT)FlatToSel(pLrec->pObjInfo[i].oaddr);
-        aKrnlOTE[i].ote_hob     = 0;
-    }
-    cObjectsFake = pLrec->ctObj;
-
-    return TRUE;
-}
-
-
-/**
- * Initiates a init reqest packet.
- * @param   pRpInit         Pointer to request packet to init.
- * @param   pszInitArgs     Pointer to init arguments.
- * @status  completely implemented.
- * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-void initRPInit(RP32INIT *pRpInit, char *pszInitArgs)
-{
-    /* kKrnlHlp */
-    memset(pRpInit, 0, sizeof(RP32INIT));
-    pRpInit->rph.Len  = sizeof(RP32INIT);
-    pRpInit->rph.Cmd  = CMDInit;
-    pRpInit->DevHlpEP = getDHRouterFarPtr();
-    pRpInit->InitArgs = (PSZ)FlatToSel(pszInitArgs);
-}
-
-
-/**
- * Testcase fan-out.
- * @returns Testcase return value.
- *          -2 if testcase not found.
- * @param   iTest   Testcase number.
- * @param   argc    main argc
- * @param   argv    main argv
- * @status  completely implemented.
- * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-int tests(int iTest, int argc, char **argv)
-{
-    int     rc;
-
-    printf("-------------------------------- Testcase %d:\n", iTest);
-    switch (iTest)
-    {
-        case 1:     rc = TestCase1(argc, argv);   break;
-        case 2:     rc = TestCase2();   break;
-
-        default:
-            printf("testcase no. %d is not found\n", iTest);
-            rc = -2;
-    }
-    printf("result %d -----------------------------------\n", rc);
-
-    KNOREF(argc);
-    KNOREF(argv);
-    return rc;
-}
-
-
-
-/**
- * Test case 1.
- * Checks that default initiation works fine for a given kernel.
- *
- * Syntax:  win32ktst.exe 1 <os2krnl> <majorver> <minorver> <build> <kerneltype: S|U|4> <buildtype: A|H|R> [rev] [os2krnl.sym]
- *
- * @sketch  Create init packet with no arguments.
- *          Initiate kKrnlHlp
- *          Create init packet with no arguments.
- *          Initiate kKrnlLib
- * @returns 0 on success.
- *          1 on failure.
- * @status  completely implemented.
- * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-int TestCase1(int argc, char **argv)
-{
-    static char szInitArgs[CCHMAXPATH + 10];
-    int         rc = 1;
-    RP32INIT    rpinit;
-
-    /* verify argument count */
-    if (argc < 8 || argc > 10)
-    {
-        printf("Invalid parameter count for testcase 1.\n");
-        return ERROR_INVALID_PARAMETER;
-    }
-
-    /* init fake variabels */
-    _usFakeVerMajor = (USHORT)atoi(argv[3]);
-    _usFakeVerMinor = (USHORT)atoi(argv[4]);
-
-    /* make init string */
-    strcpy(szInitArgs, "-w3");
-    if (argc >= 9 && argv[argc-1][1] != '\0')
-        strcat(strcat(szInitArgs, " -S:"), argv[argc-1]);
-
-    /* kKrnlHlp */
-    initRPInit(SSToDS(&rpinit), szInitArgs);
-    rc = InitkKrnlHlp(&rpinit);              /* no SSToDS! */
-    printf("InitkKrnlHlp returned status=0x%04x\n", rpinit.rph.Status);
-    if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
-    {
-        /* kKrnlLib */
-        initRPInit(SSToDS(&rpinit), szInitArgs);
-        rc = InitkKrnlLib(&rpinit);       /* no SSToDS! */
-        printf("InitkKrnlLib returned status=0x%04x\n", rpinit.rph.Status);
-        if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
-        {
-            struct kKLOptions opt = DEFAULT_OPTION_ASSIGMENTS;
-            ULONG   fExpKernel = 0;
-            if (argv[6][0] == 'S')  fExpKernel |= KF_SMP;
-            if (argv[6][0] == '4')  fExpKernel |= KF_W4;
-            if (argv[6][0] == 'U')  fExpKernel |= KF_UNI;
-            if (argv[7][0] == 'A')  fExpKernel |= KF_ALLSTRICT;
-            if (argv[7][0] == 'H')  fExpKernel |= KF_HALFSTRICT;
-
-            if (argc >= 9 && argv[8][1] == '\0')
-                switch (argv[8][0])
-                {
-                    case '\0': break;
-                    default:
-                    fExpKernel |= (argv[8][0] - (argv[8][0] >= 'a' ? 'a'-1 : 'A'-1)) << KF_REV_SHIFT;
-                }
-            rc = CompareOptions(SSToDS(&opt), fExpKernel, atoi(argv[5]), (USHORT)atoi(argv[3]), (USHORT)atoi(argv[4]));
-        }
-        else
-            printf("!failed!\n");
-    }
-    else
-        printf("!failed!\n");
-
-    return rc;
-}
-
-/**
- * Test case 2.
- * Checks that all parameters are read correctly (1).
- *
- * @sketch  Create init packet with no arguments.
- *          Initiate kKrnlHlp
- *          Create init packet with no arguments.
- *          Initiate kKrnlLib
- * @returns 0 on success.
- *          1 on failure.
- * @status  completely implemented.
- * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-int TestCase2(void)
-{
-    int         rc = 1;
-    RP32INIT    rpinit;
-    char *      pszInitArgs = "-C1 -L:E -Verbose -Elf:Yes -Pe:Mixed -Script:Yes -W4 -Heap:512000 -ResHeap:0256000 -HeapMax:4096000 -ResHeapMax:0x100000";
-
-    options.fLogging = TRUE;
-
-    /* kKrnlHlp */
-    initRPInit(SSToDS(&rpinit), pszInitArgs);
-    rc = InitkKrnlHlp(&rpinit);              /* no SSToDS! */
-    printf("InitkKrnlHlp returned status=0x%04x\n", rpinit.rph.Status);
-    if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
-    {
-        /* kKrnlLib */
-        initRPInit(SSToDS(&rpinit), pszInitArgs);
-        rc = InitkKrnlLib(&rpinit);       /* no SSToDS! */
-        printf("InitkKrnlLib returned status=0x%04x\n", rpinit.rph.Status);
-        if ((rpinit.rph.Status & (STDON | STERR)) == STDON)
-        {
-            struct kKLOptions opt = DEFAULT_OPTION_ASSIGMENTS;
-            opt.cbSwpHeapInit   = 512000;
-            opt.cbSwpHeapMax    = 4096000;
-            opt.cbResHeapInit   = 0256000;
-            opt.cbResHeapMax    = 0x100000;
-            opt.fQuiet          = FALSE;
-            opt.fLogging        = TRUE;
-            opt.usCom           = OUTPUT_COM1;
-
-            rc = CompareOptions(SSToDS(&opt), -1, -1, (USHORT)-1, (USHORT)-1);
-            if (rc == NO_ERROR)
-            {
-                rc = WritekKrnlLibDll();
-            }
-        }
-        else
-            printf("!failed!\n");
-    }
-    else
-        printf("!failed!\n");
-
-    return rc;
-}
-
-
-
-int WritekKrnlLibDll(void)
-{
-    ULONG   ulAction;
-    int     rc;
-    HFILE   hFile = NULLHANDLE;
-
-    /*
-     * Open the file.
-     */
-    rc = DosOpen("kKrnlLib.Dll", SSToDS(&hFile), SSToDS(&ulAction), 0, FILE_NORMAL,
-                 OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS,
-                 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYREAD | OPEN_ACCESS_WRITEONLY,
-                 NULL);
-    if (rc == NO_ERROR)
-    {
-        static struct e32_exe   exehdr;
-        static struct o32_obj   aObjTab[24];
-        struct o32_map          page;
-        int                     i;
-        int                     j;
-        ULONG                   ulWritten;
-        ULONG                   ulPos;
-        ULONG                   ulNULL = 0;
-
-
-        /* make exehdr */
-        memset(&exehdr, 0, sizeof(exehdr));
-        exehdr.e32_magic[0] = E32MAGIC1;
-        exehdr.e32_magic[1] = E32MAGIC2;
-        exehdr.e32_cpu      = E32CPU486;
-        exehdr.e32_os       = NE_OS2;
-        exehdr.e32_mflags   = E32MODDLL | E32PMW;
-        exehdr.e32_mpages   = 0;
-        for (i = 0; i < KKL_SwapMTE.smte_objcnt; i++)
-            exehdr.e32_mpages += (KKL_SwapMTE.smte_objtab[i].ote_size + 0xfff) >> 12;
-        exehdr.e32_startobj = 2;
-        exehdr.e32_eip      = 0;
-        exehdr.e32_pagesize = 0x1000;
-        exehdr.e32_fixupsize= exehdr.e32_mpages * sizeof(unsigned long)
-                            + 4;
-        exehdr.e32_ldrsize  = KKL_SwapMTE.smte_objcnt * sizeof(struct o32_obj)
-                            + exehdr.e32_mpages * sizeof(struct o32_map)
-                            + &KKL_ResNameTabEND[0] - (char*)KKL_SwapMTE.smte_restab
-                            + exehdr.e32_mpages * sizeof(unsigned long)
-                            + 4;
-        exehdr.e32_objtab   = sizeof(exehdr);
-        exehdr.e32_objcnt   = KKL_SwapMTE.smte_objcnt;
-        exehdr.e32_objmap   = exehdr.e32_objtab + exehdr.e32_objcnt * sizeof(struct o32_obj);
-        exehdr.e32_restab   = exehdr.e32_objmap + exehdr.e32_mpages * sizeof(struct o32_map);
-        exehdr.e32_enttab   = exehdr.e32_restab + &KKL_ResNameTabEND[0] - (char*)KKL_SwapMTE.smte_restab;
-        exehdr.e32_fpagetab = exehdr.e32_enttab + &KKL_EntryTabEND[0] - (char*)KKL_SwapMTE.smte_enttab;
-        exehdr.e32_frectab  = exehdr.e32_fpagetab+exehdr.e32_mpages * sizeof(unsigned long);
-        exehdr.e32_datapage = exehdr.e32_frectab + 4;
-        exehdr.e32_nrestab  = 0;
-        exehdr.e32_cbnrestab= 0;
-
-        /* make object table */
-        memcpy(&aObjTab[0], KKL_SwapMTE.smte_objtab, KKL_SwapMTE.smte_objcnt * sizeof(struct o32_obj));
-        for (i = 0, j = 1; i < KKL_SwapMTE.smte_objcnt; i++)
-        {
-            aObjTab[i].o32_reserved = 0;
-            aObjTab[i].o32_pagemap = j;
-            j += aObjTab[i].o32_mapsize = (aObjTab[i].o32_size + 0xfff) >> 12;
-            printf("obj %02d: base=%08x size=%08x page=%08x pages=%08x\n",
-                   i, aObjTab[i].o32_base, aObjTab[i].o32_size, aObjTab[i].o32_pagemap, aObjTab[i].o32_mapsize);
-        }
-
-        /* write the header stuff */
-        DosWrite(hFile, &exehdr, sizeof(exehdr), SSToDS(&ulWritten));
-        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_objtab);
-        DosWrite(hFile, &aObjTab[0], exehdr.e32_objcnt * sizeof(struct o32_obj), SSToDS(&ulWritten));
-        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_objmap);
-        for (i = 0, page.o32_pagedataoffset = 0; i < KKL_SwapMTE.smte_objcnt; i++)
-        {
-            for (j = 0; j < aObjTab[i].o32_mapsize;j++, page.o32_pagedataoffset += 0x1000)
-            {
-                page.o32_pageflags = VALID;
-                page.o32_pagesize = 0x1000;
-                DosWrite(hFile, SSToDS(&page), sizeof(struct o32_map), SSToDS(&ulWritten));
-            }
-        }
-        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_restab);
-        DosWrite(hFile, &KKL_ResNameTab[0], &KKL_ResNameTabEND[0] - (char*)KKL_SwapMTE.smte_restab, SSToDS(&ulWritten));
-        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_enttab);
-        DosWrite(hFile, &KKL_EntryTab[0], &KKL_EntryTabEND[0] - (char*)KKL_SwapMTE.smte_enttab, SSToDS(&ulWritten));
-        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_fpagetab);
-        for (i = 0, page.o32_pagedataoffset = 0; i < KKL_SwapMTE.smte_objcnt; i++)
-        {
-            for (j = 0; j < aObjTab[i].o32_mapsize;j++, page.o32_pagedataoffset += 0x1000)
-                DosWrite(hFile, SSToDS(&ulNULL), sizeof(ulNULL), SSToDS(&ulWritten));
-        }
-        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_frectab);
-        DosWrite(hFile, SSToDS(&ulNULL), sizeof(ulNULL), SSToDS(&ulWritten));
-
-        /* Write data pages. */
-        assert(!DosSetFilePtr(hFile, 0, FILE_CURRENT, SSToDS(&ulPos)) && ulPos == exehdr.e32_datapage);
-        for (i = 0; i < KKL_SwapMTE.smte_objcnt; i++)
-            for (j = 0; j < aObjTab[i].o32_mapsize; j++)
-            {
-                static char achPage[0x1000];
-                char    *pchData = (char*)aObjTab[i].o32_base + j * 0x1000;
-                int k;
-                if (aObjTab[i].o32_flags & (OBJINVALID | OBJIOPL))
-                    memset(achPage[0], 0x1000, 0);
-                else
-                    for (k = 0; k < 0x1000; k++, pchData++)
-                        achPage[k] = *pchData;
-                DosWrite(hFile, &achPage[0], 0x1000, SSToDS(&ulWritten));
-            }
-
-        /*
-         * Close file - We're finished in a way.
-         */
-        DosClose(hFile);
-    }
-
-    return 0;
-}
-
-/**
- * Compares the options with the option struct passed in.
- * @returns 0 on success.
- *          number of mismatches on error.
- * @param   pOpt                Expected option struct.
- * @param   fExpKernel          Expected stuff.
- * @param   ulExpKernelBuild    Expected stuff.
- * @param   usExpVerMajor       Expected stuff.
- * @param   usExpVerMinor       Expected stuff.
- * @status  completely implemented.
- * @author  knut st. osmundsen (knut.stange.osmundsen@mynd.no)
- */
-int CompareOptions(struct kKLOptions *pOpt, ULONG fExpKernel, ULONG ulExpKernelBuild,
-                   USHORT usExpVerMajor, USHORT usExpVerMinor)
-{
-    int rc = 0;
-    /*
-     *  Check that the option struct is correct.
-     */
-    if (options.fQuiet != pOpt->fQuiet)
-        printf("fQuiet = %d - should be %d\n", options.fQuiet, pOpt->fQuiet, rc++);
-    if (options.usCom != pOpt->usCom)
-        printf("usCom = %d - should be %d\n", options.usCom, pOpt->usCom, rc++);
-    if (options.fLogging != pOpt->fLogging)
-        printf("fLogging = %d - should be %d\n", options.fLogging, pOpt->fLogging, rc++);
-    if (ulExpKernelBuild != ~0UL)
-    {
-        if (fKernel != fExpKernel)
-            printf("fKernel = %x - should be %x\n", fKernel, fExpKernel, rc++);
-        if (ulKernelBuild != ulExpKernelBuild)
-            printf("ulBuild = %d - should be %d\n", ulKernelBuild, ulExpKernelBuild, rc++);
-        if (usVerMajor != usExpVerMajor)
-            printf("usVerMajor = %d - should be %d\n", usVerMajor, usExpVerMajor, rc++);
-        if (usVerMinor != usExpVerMinor)
-            printf("usVerMinor = %d - should be %d\n", usVerMinor, usExpVerMinor, rc++);
-    }
-    if (options.cbSwpHeapInit != pOpt->cbSwpHeapInit)
-        printf("cbSwpHeapInit = %d - should be %d\n", options.cbSwpHeapInit, pOpt->cbSwpHeapInit, rc++);
-    if (options.cbSwpHeapMax != pOpt->cbSwpHeapMax)
-        printf("cbSwpHeapMax = %d - should be %d\n", options.cbSwpHeapMax, pOpt->cbSwpHeapMax, rc++);
-    if (options.cbResHeapInit != pOpt->cbResHeapInit)
-        printf("cbResHeapInit = %d - should be %d\n", options.cbResHeapInit, pOpt->cbResHeapInit, rc++);
-    if (options.cbResHeapMax != pOpt->cbResHeapMax)
-        printf("cbResHeapMax = %d - should be %d\n", options.cbResHeapMax, pOpt->cbResHeapMax, rc++);
-
-    return rc;
-}
