Hello,
i have an problem that gives me headche
code thats causes the "invalid page fault" msg box
is:
dwVar1 and dwVar2 are DWORD vars


.while TRUE
mov eax,dwVar1 ; need to compare dwVar1 with dwVar2
.break .if eax>=dwVar2 ; <----- crash code.....
.......
...... ; other unimportant code in loop..
......
.endw

now every time the program comes to this part it causes IPF
message box, and it always says the same, same addres where fault occured, same content of registers etc
i also tryed to replace all those masm macros with pure asm (cmp, jne instuctions...) but the result is same - crashed
here is the error


CONTROLS is the name of my exe file

CONTROLS caused an invalid page fault in
module USER32.DLL at 017f:bff53ceb.
Registers:
EAX=00000000 CS=017f EIP=bff53ceb EFLGS=00010297
EBX=100030f1 SS=0187 ESP=0063fbe8 EBP=f063cb3f
ECX=bff53ce6 DS=0187 ESI=f063cb39 FS=119f
EDX=00016ce4 ES=0187 EDI=00020000 GS=0000
Bytes at CS:EIP:
66 0f b2 23 66 03 f4 66 83 ee 04 66 03 ec 66 83
Stack dump:
00000000 00000000 0063fbfe 8bfa111f 414d111f 0b1416b7 00010000 01110000 0ca00000 0ca00000 00010111 0b140000 7a640000 00000001 0000c3ad 000116b7


now i am not really good in this errors, but isnt this error occured inside user32.dll and thus its M$ fault and not mine?

but important Q to me is how to fix all this
btw this code is inside global hook callback function
Posted on 2002-07-20 17:15:13 by Mikky




.while TRUE
mov eax,dwVar1 ; need to compare dwVar1 with dwVar2
.break .if eax>=dwVar2 ; <----- crash code.....
.......
...... ; other unimportant code in loop..
......
.endw


now i am not really good in this errors, but isnt this error occured inside user32.dll and thus its M$ fault and not mine?


In this case it's your error. As you can see from the GPF output, EAX is 0h. So your dwVar1 is 0, too and your greater or equal comparsion wont catch. Maybe you should add some MessageBox:es with dwtoa function to show the values of dwVar1 and dwVar2 each loop.
Posted on 2002-07-20 17:48:54 by bazik
ahm.. i see ur point but that code should be like that becouse it needs to be 0 when first enters the loop...later in loop Var1 will be incremented

on the other hand, why is the problem to evaluate this, ok if eax=0 and if dwVar2 >0 then statement is FALSE and .break is not going to be executed... there is no reason to crash!?
Posted on 2002-07-20 19:03:46 by Mikky
I doubt you have the crash location correct.
Unless you're doing very fishy stuff, there's no way that
comparison could cause a page fault... and also, your
fault box says the crash is in user32, so it definitely
isn't in your comparison the fault lies.


"but isnt this error occured inside user32.dll and thus its M$ fault and not mine?"

Always assume you're the one that's wrong, it will be
true most of the time.

My guess is this is a classic case of "oops, I forgot to
preserve registers".
Posted on 2002-07-20 20:41:45 by f0dder
well actually cmp is not the one that causes error, its jmp instruction that comes after cmp if statment is true
what do u mean by fishy stuff and what registers should i save here, there is nothing that affects registers used by windows ?
Posted on 2002-07-21 19:05:27 by Mikky
fishy stuff means just that - "fishy stuff" ;).
Regs to preserve? If used, ebx+esi+edi+ebp+esp.

Find out which machine instruction that causes the fault..
trace with a debugger...
Posted on 2002-07-21 19:08:16 by f0dder