| 1 | ; $Id: mytkStartProcess.asm,v 1.4 2001-02-23 02:57:55 bird Exp $ | 
|---|
| 2 | ; | 
|---|
| 3 | ; tkStartProcess overloader. Needed to clear the loader semaphore | 
|---|
| 4 | ; when a process is being started syncronously. | 
|---|
| 5 | ; | 
|---|
| 6 | ; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no) | 
|---|
| 7 | ; | 
|---|
| 8 | ; Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 9 | ; | 
|---|
| 10 |  | 
|---|
| 11 | .386p | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 | ; | 
|---|
| 15 | ;   Include files | 
|---|
| 16 | ; | 
|---|
| 17 | include devsegdf.inc | 
|---|
| 18 |  | 
|---|
| 19 | ; | 
|---|
| 20 | ;   Imported Functions and variables. | 
|---|
| 21 | ; | 
|---|
| 22 |  | 
|---|
| 23 | ; | 
|---|
| 24 | ; LDR semaphore | 
|---|
| 25 | ; | 
|---|
| 26 | extrn pLdrSem:DWORD | 
|---|
| 27 | extrn _LDRClearSem@0:PROC | 
|---|
| 28 | extrn _KSEMQueryMutex@8:PROC | 
|---|
| 29 |  | 
|---|
| 30 | ; | 
|---|
| 31 | ; Loader State | 
|---|
| 32 | ; | 
|---|
| 33 | extrn ulLDRState:DWORD | 
|---|
| 34 |  | 
|---|
| 35 | ; | 
|---|
| 36 | ; mytkExecPgm stuff. | 
|---|
| 37 | ; | 
|---|
| 38 | extrn fTkExecPgm:BYTE | 
|---|
| 39 |  | 
|---|
| 40 | ; | 
|---|
| 41 | ; Pointer to current executable module. | 
|---|
| 42 | ; | 
|---|
| 43 | extrn pExeModule:DWORD | 
|---|
| 44 |  | 
|---|
| 45 | ; | 
|---|
| 46 | ; TKSSBase (32-bit) | 
|---|
| 47 | ; | 
|---|
| 48 | extrn pulTKSSBase32:DWORD | 
|---|
| 49 |  | 
|---|
| 50 | ; | 
|---|
| 51 | ; Calltable entry for tkStartProcess | 
|---|
| 52 | ; | 
|---|
| 53 | extrn _tkStartProcess:PROC | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | ; | 
|---|
| 57 | ;   Exported symbols | 
|---|
| 58 | ; | 
|---|
| 59 | public _mytkStartProcess | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 | CODE32 SEGMENT | 
|---|
| 63 |  | 
|---|
| 64 | ;; | 
|---|
| 65 | ; Overloads tkStartProcess. If the loader semahore is taken by us we'll release it. | 
|---|
| 66 | ; @returns | 
|---|
| 67 | ; @param | 
|---|
| 68 | ; @uses      eax, ecx, edx | 
|---|
| 69 | ; @sketch | 
|---|
| 70 | ; @status | 
|---|
| 71 | ; @author    knut st. osmundsen (knut.stange.osmundsen@pmsc.no) | 
|---|
| 72 | ; @remark | 
|---|
| 73 | _mytkStartProcess PROC NEAR | 
|---|
| 74 | ASSUME DS:FLAT, ES:NOTHING, SS:NOTHING | 
|---|
| 75 |  | 
|---|
| 76 | ; | 
|---|
| 77 | ; Check if the loader semphore is take by us. | 
|---|
| 78 | ; Clear it (and other vars) if it is. | 
|---|
| 79 | ; | 
|---|
| 80 | push    eax | 
|---|
| 81 | push    ecx | 
|---|
| 82 | push    edx | 
|---|
| 83 |  | 
|---|
| 84 | push    0                           ; Usage count variable. | 
|---|
| 85 | mov     eax, pulTKSSBase32          ; Get TKSSBase | 
|---|
| 86 | mov     eax, [eax] | 
|---|
| 87 | add     eax, esp                    ; Added TKSSBase to the usage count pointer | 
|---|
| 88 | push    eax                         ; Push address of usage count pointer. | 
|---|
| 89 | push    pLdrSem                     ; Push pointer to loader semaphore ( = handle). | 
|---|
| 90 | call    _KSEMQueryMutex@8 | 
|---|
| 91 | or      eax, eax                    ; Check return code. (1 = our / free; 0 = not our but take) | 
|---|
| 92 | pop     eax                         ; Pops usage count. | 
|---|
| 93 | jz      mtksp_ret                   ; jmp if not taken by us (rc=FALSE). | 
|---|
| 94 | or      eax, eax                    ; Check usage count. | 
|---|
| 95 | jz      mtksp_ret                   ; jmp if 0 (=free). | 
|---|
| 96 | mov     ulLDRState, 0               ; Clears loaderstate. (LDRSTATE_UNKNOWN) | 
|---|
| 97 | mov     pExeModule, 0               ; Sets the exemodule pointer to NULL. | 
|---|
| 98 | mov     fTkExecPgm, 0               ; Marks global data invalid. | 
|---|
| 99 | cmp     eax, 2                      ; If usage count > 1 then issue a release. (should not happen here) | 
|---|
| 100 | jl      mtksp_ret                   ; jmp if usage count < 2. (tkStartProcess or tkExecPgm will free the last usage). | 
|---|
| 101 | call    _LDRClearSem@0 | 
|---|
| 102 |  | 
|---|
| 103 | mtksp_ret: | 
|---|
| 104 | pop     edx | 
|---|
| 105 | pop     ecx | 
|---|
| 106 | pop     eax | 
|---|
| 107 | jmp     _tkStartProcess | 
|---|
| 108 | _mytkStartProcess ENDP | 
|---|
| 109 |  | 
|---|
| 110 | CODE32 ENDS | 
|---|
| 111 | END | 
|---|