source: trunk/src/win32k/test/fakea.asm@ 5220

Last change on this file since 5220 was 5207, checked in by bird, 25 years ago

Added kernelmode enter & exit faker functions.

File size: 14.7 KB
Line 
1; $Id: fakea.asm,v 1.4 2001-02-20 05:05:23 bird Exp $
2;
3; Fake assembly imports.
4;
5; Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
6;
7; Project Odin Software License can be found in LICENSE.TXT
8;
9
10 .386
11
12;
13; Defined Constants And Macros
14;
15 INCL_BASE EQU 1
16
17;
18; Include files
19;
20 include devsegdf.inc
21 include devhlp.inc
22 include os2.inc
23 include options.inc
24
25
26;
27; Exported symbols
28;
29 public fakepTCBCur
30 public fakepPTDACur
31 public fakeptda_start
32 public fakeptda_environ
33 public fakeptda_handle
34 public fakeptda_module
35 public fakeptda_ptdasem
36 public fakeptda_pBeginLIBPATH
37 public fakef_FuStrLenZ
38 public fakef_FuStrLen
39 public fakef_FuBuff
40 public fakeg_tkExecPgm
41 public faketkStartProcess
42 public CalltkExecPgm
43 public _fakeldrOpenPath@20
44 public fakeKMEnterKmodeSEF
45 public fakeKMExitKmodeSEF8
46
47
48;
49; Imported Functions and Variables.
50;
51 extrn tkExecPgmWorker:PROC ; fake.c
52 extrn _fakeLDRClearSem@0:PROC ; fake.c
53 extrn _fakeKSEMRequestMutex@8:PROC ; fake.c
54 extrn _fakeldrOpenPath_old@16:PROC ; fake.c
55 extrn _fakeldrOpenPath_new@20:PROC ; fake.c
56 extrn _options:options ; d16globl.c
57
58
59DATA16 SEGMENT
60; Fake data in 16-bit segment.
61fakepTCBCur dd offset FLAT:fakeTCB
62fakepPTDACur dd offset FLAT:fakeptda_start
63
64; PTDA - Only use environ and ExecChild.
65fakeptda_start LABEL DWORD
66fakeptda_pPTDAParent dd 0
67fakeptda_pPTDASelf dd offset FLAT:fakeptda_start
68fakeptda_pPTDAFirstChild dd 0
69fakeptda_pPTDAExecChild dd offset FLAT:fakeptda_start
70fakeptda_dummy db 123 dup (0)
71fakeptda_environ dw 1 ; 1 is the hardcoded HOB of the win32ktst.exe's environment.
72fakeptda_ptdasem db 20 dup (0) ; PTDA semaphore - Intra-Process serialisation mutex KSEM (sg244640).
73fakeptda_handle dw 2 ; 2 is the hardcoded HPTDA of the current process.
74fakeptda_module dw 1 ; 1 is the hardcoded HMTE of the current executable module.
75fakeptda_pBeginLIBPATH dd 0 ; BEGINLIBPATH not implemented.
76 dd 0 ; ENDLIBPATH not implemented.
77
78
79; TCB - just needs some dummy data for reading and writing to the TCBFailErr.
80fakeTCB db 220h dup (0CCh)
81
82DATA16 ENDS
83
84
85CODE16 SEGMENT
86
87
88; Scans strings until empy-string is reached.
89; input: bx:di
90; uses: nearly all (save bp)
91; return: cx size - CF clear
92; ax error- CF set
93fakef_FuStrLenZ PROC FAR
94 push 2 ; required by all 16-bit far procedures.
95 push 2 ; dummy code.
96 push 2 ; dummy code.
97 push 2 ; dummy code.
98 push es
99
100 mov dx, di ; save di pointer.
101 cmp bx, 7 ; check if NULL ptr.
102 jle ffslz_badselector
103
104 mov es, bx ; es:di -> string
105 mov cx, di
106 not cx ; maximum length is to segment end.
107 xor ax, ax ; test against zero (scasb uses al to cmp with).
108
109ffslz_loop:
110 repnz scasb
111 jnz ffslz_no_term ; jump if cx = 0
112 dec cx ; check if next is NULL too
113 scasb
114 jnz ffslz_loop
115
116ffslz_retok:
117 mov cx, di
118 sub cx, dx ; cx <- size (end ptr - start ptr)
119 pop es
120 add sp, 8
121 clc
122 db 66h
123 retf
124
125ffslz_badselector:
126 mov ax, ERROR_INVALID_SELECTOR
127 jmp ffslz_reterr
128
129;ffslz_invalidptr:
130; mov ax, ERROR_INVALID_ACCESS
131; jmp ffslz_reterr
132
133ffslz_no_term:
134 mov ax, ERROR_TERMINATOR_NOT_FOUND
135ffslz_reterr:
136 pop es
137 add sp, 8
138 stc
139 db 66h
140 retf
141fakef_FuStrLenZ ENDP
142
143
144;
145; Stringlength - Fake
146; input: bx:di
147; uses: nearly all (save bp)
148; return: cx size - CF clear
149; ax error- CF set
150fakef_FuStrLen PROC FAR
151 push 2 ; required by all 16-bit far procedures.
152 push 2 ; dummy code.
153 push 2 ; dummy code.
154 push 2 ; dummy code.
155 push es
156
157 mov dx, di ; save di pointer.
158 cmp bx, 7 ; check if NULL ptr.
159 jle ffslz_badselector
160
161 mov es, bx ; es:di -> string
162 mov cx, di
163 not cx ; maximum length is to segment end.
164 xor ax, ax ; test against zero (scasb uses al to cmp with).
165
166 repnz scasb
167 jnz ffslz_no_term ; jump if cx = 0
168
169ffslz_retok:
170 mov cx, di
171 sub cx, dx ; cx <- size (end ptr - start ptr)
172 pop es
173 add sp, 8
174 clc
175 db 66h
176 retf
177
178ffslz_badselector:
179 mov ax, ERROR_INVALID_SELECTOR
180 jmp ffslz_reterr
181
182;ffslz_invalidptr:
183; mov ax, ERROR_INVALID_ACCESS
184; jmp ffslz_reterr
185
186ffslz_no_term:
187 mov ax, ERROR_TERMINATOR_NOT_FOUND
188ffslz_reterr:
189 pop es
190 add sp, 8
191 stc
192 db 66h
193 retf
194fakef_FuStrLen ENDP
195
196
197;memcpy
198;input: bx:si pointer to source
199; es:di pointer to target
200; cx count of bytes to copy
201;uses: nearly all (save bp), es, ds
202;return: success CF clear
203; failure CF set
204fakef_FuBuff PROC FAR
205 push 2 ; required by all 16-bit far procedures.
206 push 2 ; dummy code.
207 push 2 ; dummy code.
208 push 2 ; dummy code.
209 push es
210
211 cmp bx, 7 ; check if NULL ptr.
212 jle ffslz_badselector
213 mov ax, es
214 cmp bx, 7 ; check if NULL ptr.
215 jle ffslz_badselector
216
217 mov ds, bx ; ds:si -> string
218 mov ax, di
219 not ax
220 cmp ax, cx ; crosses segment boundrary...
221 jb ffslz_invalidptr
222 mov ax, si
223 not ax
224 cmp ax, cx ; crosses segment boundrary...
225 jb ffslz_invalidptr
226
227; movzx esi, si
228; movzx edi, di
229; movzx ecx, cx
230; db 66h ; force it use extended registers.
231 rep movsb
232
233ffslz_retok:
234 xor ax, ax
235 mov cx, di
236 sub cx, dx ; cx <- size (end ptr - start ptr)
237 pop es
238 add sp, 8
239 clc
240 db 66h
241 retf
242
243ffslz_badselector:
244 mov ax, ERROR_INVALID_SELECTOR
245 jmp ffslz_reterr
246
247ffslz_invalidptr:
248 int 3
249 mov ax, ERROR_INVALID_ACCESS
250 jmp ffslz_reterr
251
252ffslz_no_term:
253 mov ax, ERROR_TERMINATOR_NOT_FOUND
254ffslz_reterr:
255 pop es
256 add sp, 8
257 stc
258 db 66h
259 retf
260fakef_FuBuff ENDP
261
262
263
264
265CODE16 ENDS
266
267
268
269CODE32 SEGMENT
270;;
271; Faker of which simply clears the loader semaphore.
272; @cproto none! (void _Optlink faketkStartProcess(void))
273; @returns
274; @param
275; @uses
276; @equiv
277; @time
278; @sketch
279; @status
280; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
281; @remark
282faketkStartProcess PROC NEAR
283 push ebp
284 mov ebp, esp
285
286 push ebx
287 push ecx
288
289 call _fakeLDRClearSem@0
290
291 pop ecx
292 pop ebx
293
294 xor eax, eax
295 leave
296 ret
297faketkStartProcess ENDP
298
299
300;;
301; Fake g_tkExecPgm implementation.
302; @proto none. (void _Optlink fakeg_tkExecPgm(void);)
303; @returns same as tkExecPgm: eax, edx and carry flag
304; @param ax Exec flag
305; ds:dx Filename address. (String)
306; es:bx Environment address. (String)
307; di:si Argument address. (String)
308; @uses all - bp
309; @sketch Copy the filename and arguments into a buffer we
310; may modify later if this is a UNIX shellscript or
311; a PE-file started by pe.exe.
312; @status completely implemented.
313; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
314;
315;
316fakeg_tkExecPgm PROC NEAR
317 push ebp
318 mov ebp, esp
319
320 ;
321 ; Call C worker
322 ;
323 sub esp, 10h
324 movzx eax, ax
325 mov [esp + 00h], eax ; ExecFlag DWORD
326
327 mov ax, es
328 SelToFlat
329 mov [esp + 08h], eax ; Environment ptr.
330 mov ecx, eax
331
332 mov ax, ds
333 mov bx, dx
334 SelToFlat
335 mov [esp + 0ch], eax ; Filename ptr
336
337 mov ax, di
338 mov bx, si
339 SelToFlat
340 mov [esp + 04h], eax ; Argument ptr
341 mov edx, eax
342
343 mov eax, [esp + 00h] ; ExecFlag DWORD in eax
344
345 mov bx, seg FLAT:DATA32
346 mov ds, bx ; Make ds flat
347 mov es, bx ; Make es flat
348
349 call tkExecPgmWorker ;(ULONG flags, arg, env, prog)
350 add esp, 10 ; eax, edx, ecx,
351 ; ebp+8, ebp+c, ebp+10, ebp+14
352 ; esp+0, esp+4, esp+08, esp+0c
353 or eax, eax
354 jnz ftkep_ret
355 call faketkStartProcess ; If succesfully so far. call start process.
356 jmp ftkep_ret2 ; <Currently no parameters are implemented.>
357
358ftkep_ret:
359 push eax
360 call _fakeLDRClearSem@0 ; clear the semaphore.
361 pop eax
362
363ftkep_ret2:
364 leave
365 ret
366fakeg_tkExecPgm ENDP
367
368
369;;
370; Calls the fakeg_tkExecPgm procedure.
371; @cproto ULONG _Optlink CalltkExecPgm(
372; ULONG execFlags,
373; PCSZ pArg,
374; PCSZ pEnv,
375; PCSZ pExecName);
376; @returns
377; @param eax (ebp +08h) execFlags
378; @param edx (ebp +0ch) pArg
379; @param ecx (ebp +10h) pEnv
380; @param ebp + 14h pExecName
381; @uses eax, ecx, edx
382; @status completely implemented.
383; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
384; @remark
385CalltkExecPgm PROC NEAR
386 push ebp
387 mov ebp, esp
388 push ebx
389 push edi
390 push esi
391 push es
392 push ds
393
394 ; Save parameters
395 mov [ebp+08h], eax
396
397 ;
398 ; create input for fakeg_tkExecPgm
399 ;
400 mov eax, edx
401 xor edi, edi
402 xor esi, esi
403 or eax, eax
404 jz ctkep1
405 FlatToSel
406 mov di, ax
407 mov esi, ebx ; di:si -> arguments
408ctkep1:
409
410 mov eax, [ebp + 14h]
411 xor edx, edx
412 mov ds, dx
413 or eax, eax
414 jz ctkep2
415 FlatToSel
416 mov ds, ax
417 mov edx, ebx ; ds:dx -> executable filename
418ctkep2:
419
420 mov eax, ecx
421 xor ebx, ebx
422 mov es, bx
423 or eax, eax
424 jz ctkep3
425 FlatToSel
426 mov es, ax
427 mov eax, ebx ; es:bx -> environment.
428ctkep3:
429
430 mov eax, [ebp+08h] ; ax = exec flags.
431
432 call far ptr FLAT:fakeg_tkExecPgm
433
434 ;
435 ; Restore and return.
436 ;
437 pop ds
438 pop es
439 pop esi
440 pop edi
441 pop ebx
442 leave
443 ret
444CalltkExecPgm ENDP
445
446
447;;
448; Gets the selector for the CODE16 segment.
449; @cproto USHORT _Optlink GetSelectorCODE16(void)
450; @returns Selector for the CODE16 segment.
451; @uses eax
452; @status completely implemented.
453; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
454GetSelectorCODE16 PROC NEAR
455 xor eax, eax
456 mov ax, seg CODE16
457 ret
458GetSelectorCODE16 ENDP
459
460
461;;
462; Gets the selector for the DATA16 segment.
463; @cproto USHORT _Optlink GetSelectorDATA16(void)
464; @returns Selector for the DATA16 segment.
465; @uses eax
466; @status completely implemented.
467; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
468GetSelectorDATA16 PROC NEAR
469 xor eax, eax
470 mov ax, seg DATA16
471 ret
472GetSelectorDATA16 ENDP
473
474
475;;
476; Gets the selector for the CODE32 segment.
477; @cproto USHORT _Optlink GetSelectorCODE32(void)
478; @returns Selector for the CODE32 segment.
479; @uses eax
480; @status completely implemented.
481; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
482GetSelectorCODE32 PROC NEAR
483 xor eax, eax
484 mov ax, seg FLAT:CODE32
485 ret
486GetSelectorCODE32 ENDP
487
488;;
489; Gets the selector for the DATA32 segment.
490; @cproto USHORT _Optlink GetSelectorDATA32(void)
491; @returns Selector for the DATA32 segment.
492; @uses eax
493; @status completely implemented.
494; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
495GetSelectorDATA32 PROC NEAR
496 xor eax, eax
497 mov ax, seg FLAT:DATA32
498 ret
499GetSelectorDATA32 ENDP
500
501
502;;
503; Wrapper for fakeldrOpenPath.
504; @cproto ULONG LDRCALL fakeldrOpenPath(PCHAR pachFilename, USHORT cchFilename, ldrlv_t *plv, PULONG pful, ULONG lLibPath);
505; @returns Return of the current fakeldrOpenPath
506; @param pachFilename Pointer to modulename. Not zero terminated!
507; @param cchFilename Modulename length.
508; @param plv Loader local variables? (Struct from KERNEL.SDF)
509; @param pful Pointer to flags which are passed on to ldrOpen.
510; @param lLibPath New parameter in build 14053.
511; ldrGetMte calls with 1
512; ldrOpenNewExe calls with 3
513; This is compared to the initial libpath index.
514; The libpath index is:
515; BEGINLIBPATH 1
516; LIBPATH 2
517; ENDLIBPATH 3
518; The initial libpath index is either 1 or 2.
519; - ignored -
520; @uses ecx, eax, edx
521; @sketch
522; @status
523; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
524; @remark
525_fakeldrOpenPath@20 PROC NEAR
526 ASSUME ds:FLAT
527 ; dummy prolog.
528 push ebp
529 mov ebp, esp
530 sub esp, 10h
531 add esp, 10h
532 pop ebp
533 ; real code
534 cmp FLAT:DATA16:_options.ulBuild, 14053
535 jge new
536 jmp near ptr FLAT:CODE32:_fakeldrOpenPath_old@16
537new:
538 jmp near ptr FLAT:CODE32:_fakeldrOpenPath_new@20
539_fakeldrOpenPath@20 ENDP
540
541
542
543;;
544; This is called at kernel entry.
545; @cproto none
546; @returns nothing
547; @param none
548; @uses nothing
549; @status stub.
550; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
551fakeKMEnterKmodeSEF proc near
552 ; dummy prolog.
553 push ebp
554 mov ebp, esp
555 sub esp, 10h
556 leave
557 ret
558fakeKMEnterKmodeSEF endp
559
560
561;;
562; This is called at kernel exit.
563; @cproto none
564; @returns nothing
565; @param none
566; @uses nothing
567; @status stub.
568; @author knut st. osmundsen (knut.stange.osmundsen@mynd.no)
569fakeKMExitKmodeSEF8 proc near
570 ; dummy prolog.
571 push ebp
572 mov ebp, esp
573 sub esp, 10h
574 leave
575 ret
576fakeKMExitKmodeSEF8 endp
577
578CODE32 ENDS
579
580END
Note: See TracBrowser for help on using the repository browser.