It is currently Thu Jun 20, 2013 1:14 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Safe procedure calling
PostPosted: Tue Sep 13, 2011 7:18 am 
Offline
Addict
Addict

Joined: Sun Aug 08, 2004 5:21 am
Posts: 1109
Location: Netherlands
Currently there's a stack problem with CallFunctionFast.
Here's a safe approach that can call both Procedure and ProcedureC style procedures.
Code:
; ** CallFnSafe code **

Procedure CallFnSafe_addr_()
  !mov eax, CallFnFast_start
  ProcedureReturn
  !CallFnFast_start:
  !push ebp
  !mov ebp, esp
  !and esp, 0xfffffff0
  !sub esp, 32
  !mov ecx, 28
  !CallFnFast_loop:
  !mov eax, [ebp + ecx + 12]
  !mov [esp + ecx], eax
  !sub ecx, 4
  !jnc CallFnFast_loop
  !call dword [ebp + 8]
  !mov esp, ebp
  !pop ebp
  !ret
EndProcedure

PrototypeC CallFnSafe_proto(*Function, Arg1 = 0, Arg2 = 0, Arg3 = 0, Arg4 = 0, Arg5 = 0, Arg6 = 0, Arg7 = 0, Arg8 = 0)
Global CallFnSafe.CallFnSafe_proto = CallFnSafe_addr_()

; ** end of CallFnSafe code **


; test the code

Procedure MyProcedure(n)
  Debug n
EndProcedure

ProcedureC MyCProcedure(n)
  Debug n
EndProcedure

CallFnSafe(@MyProcedure(), 1)
CallFnSafe(@MyCProcedure(), 2)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye