Author Topic: Wierd stack corruption... on loop counter ?  (Read 3391 times)

K_F

  • Member
  • *****
  • Posts: 1404
  • Anybody out there?
Wierd stack corruption... on loop counter ?
« on: August 20, 2015, 09:07:53 PM »
Hi Ramon...
I'm having a weird problem here...
System = Win7 Pro, Service Pack = 1..something!

The data is written to the file OK, but the data counter (ECX [or EDX]) is being corrupted on the stack therefore the loop hangs.
EBX is fine.
I use the RegVal macro as quick look at registers, so don't think it's this as it's always worked fine.
FillBuffer - fills the array with zeros

It's in this code, as nothing else is happening at this point, so we're looking at a couple scenarios..
WinAPI, or WriteTextLine is corrupting the stack ?


Finally how does on set your stacksize in EC ?

Thanks
Van
Code: [Select]
;--- WRITE THE DATA ---
invoke SendMessage, GRP_DATA.h_lst_Data, LB_GETCOUNT, 0, 0
.if eax != LB_ERR
.if eax > 0
mov ecx, eax
xor ebx, ebx
@@:
RegVal ecx
RegVal ebx
push ecx
push ebx
Invoke FillBuffer, Addr s_BigBuff,512,0
Invoke SendMessage, GRP_DATA.h_lst_Data, LB_GETTEXT, ebx, Addr s_BigBuff
.if eax != LB_ERR
Invoke WriteTextLine, hFile, Addr s_BigBuff
.endif

pop ebx
pop ecx
inc ebx
dec ecx
cmp ecx, 0
jbe @F
jmp @B
@@:
.endif
.endif


Macro Used:
RegVal MACRO reg:REQ
push reg         
invoke FillBuffer, ADDR DebugSz, 256, 0
pop reg
push reg
invoke dwtoa, reg, ADDR DebugSz
invoke MessageBox, GlobWnd, ADDR DebugSz,TextAddr("REG VAL"), MB_OK
pop reg
ENDM
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

K_F

  • Member
  • *****
  • Posts: 1404
  • Anybody out there?
Re: Wierd stack corruption... on loop counter ?
« Reply #1 on: August 20, 2015, 11:26:03 PM »
Hang on a bit... I think I might be me.. :shock:
don't tell anybody... :t
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

K_F

  • Member
  • *****
  • Posts: 1404
  • Anybody out there?
Re: Wierd stack corruption... on loop counter ?
« Reply #2 on: August 21, 2015, 02:12:33 AM »
Resolved.. it.
After every instruction, I placed a RegVal ecx macro.. and it

- Corrupted on FillBuffer, commented this out..
- Even corrupted on MemFill..
- Then corrupted on SendMessage.. commented this out
- Corrupted on Write line.... ??

WTF...Now I'm beginning to freak out.

Closed EC restarted and changed my FillBuffer proc and manually implemented epilogues and prologues.

Worked on Fillbuffer.. then SendMessage then Writeline... Farrrk!! So got rid of all the RegVals and now all is fine.
It's not the closing/restarting of EC as I've done this at least 50x while looking for this solution...

.. and the solution is... I don't know... it just works so my hands are off
 :badgrin:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

jj2007

  • Member
  • *****
  • Posts: 8776
  • Assembler is fun ;-)
    • MasmBasic
Re: Wierd stack corruption... on loop counter ?
« Reply #3 on: August 21, 2015, 05:33:35 AM »
Resolved.. it.
After every instruction, I placed a RegVal ecx macro.. and it

- Corrupted on FillBuffer, commented this out..
- Even corrupted on MemFill..
- Then corrupted on SendMessage.. commented this out
- Corrupted on Write line.... ??

What is this RegVal macro supposed to do, and where did you get it?

rsala

  • Moderator
  • Member
  • *****
  • Posts: 274
    • Easy Code
Re: Wierd stack corruption... on loop counter ?
« Reply #4 on: August 21, 2015, 07:37:18 AM »
Hi Van,

Glad you could solve the problem!


jj2007:

Good question!
EC coder

K_F

  • Member
  • *****
  • Posts: 1404
  • Anybody out there?
Re: Wierd stack corruption... on loop counter ?
« Reply #5 on: August 21, 2015, 08:15:22 AM »
What is this RegVal macro supposed to do, and where did you get it?
Just a quickie/speed debugging macro I made up, to display a register value of interest.
It's in the code section on the first post.

RegVal MACRO reg:REQ
   push    reg         
   invoke   FillBuffer, ADDR DebugSz, 256, 0
   pop      reg
   push   reg
   invoke   dwtoa, reg, ADDR DebugSz
   invoke   MessageBox, GlobWnd, ADDR DebugSz,TextAddr("REG VAL"), MB_OK
   pop      reg
ENDM
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

jj2007

  • Member
  • *****
  • Posts: 8776
  • Assembler is fun ;-)
    • MasmBasic
Re: Wierd stack corruption... on loop counter ?
« Reply #6 on: August 21, 2015, 11:16:35 AM »
From what I see, RegVal ecx will trash eax and edx but otherwise it should be OK.

K_F

  • Member
  • *****
  • Posts: 1404
  • Anybody out there?
Re: Wierd stack corruption... on loop counter ?
« Reply #7 on: August 21, 2015, 04:10:27 PM »
EDX.. thanks I've overlooked this... :icon14:
'Sire, Sire!... the peasants are Revolting !!!'
'Yes, they are.. aren't they....'

rsala

  • Moderator
  • Member
  • *****
  • Posts: 274
    • Easy Code
Re: Wierd stack corruption... on loop counter ?
« Reply #8 on: August 21, 2015, 04:42:15 PM »
 :t
EC coder