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

Last change on this file since 10366 was 6288, checked in by bird, 24 years ago

New fakers.

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