flat assembler
Message board for the users of flat assembler.

Index > IDE Development > fasmw.asm (missing POP)

Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

where is the "pop" ?

no problem with "esp" because "ret+endp" equal "mov esp,ebp / pop ebp"

but if VirtualAlloc fails,
the registers ebx, esi and edi are not restored properly.
Code:
;FASMW.ASM
;----------
proc   MainWindow hwnd,wmsg,wparam,lparam
  push    ebx esi edi
 ...
 ...
 cmp     [wmsg],FM_OPEN
      je      fmopen
      ...
 ...
fmopen:
  ...
 ...
load_file:
       invoke  CreateFile,\
       lparam],GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0
        cmp     eax,-1
      je      open_failed
 mov     ebx,eax
     invoke  GetFileSize,ebx,NULL
        inc     eax
 push    eax ;<-------- PUSH
      invoke  VirtualAlloc,0,eax,MEM_COMMIT,PAGE_READWRITE
        or      eax,eax
     jz      load_out_of_memory
  pop     ecx
 dec     ecx
 ...
 ...
load_out_of_memory:
      invoke  CloseHandle,ebx
open_failed:
 invoke  VirtualFree,[lparam],0,MEM_RELEASE
  jmp     failed
      ...
 ...
failed:      or      eax,-1
      jmp     finish
      ...
 ...
finish:      ; <--- here, esp != ebp ... esp == ebp-4
 pop     edi esi ebx 
        ret
endp
    
solution
Code:
proc  MainWindow hwnd,wmsg,wparam,lparam
  push    ebx esi edi
 ...
 ...
 push    eax ;<---------- PUSH
    invoke  VirtualAlloc,0,eax,MEM_COMMIT,PAGE_READWRITE
        or      eax,eax
     pop     ecx ;<---------- POP
     jz      load_out_of_memory
  dec     ecx
 ...
 ...
finish:      ; <--- now, esp == ebp
   pop     edi esi ebx 
        ret
    


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 01 Jul 2011, 23:21
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.