Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2002-05

Stack verifying ...

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Michail A.Baikov

Advice to me, how to check stack routine in procedures and functions. How to test correct stack work in procedures and functions? If stack is corrupted in any procedure, program returned to crash address. How to test and prevent it?

Thanks.

Reply by email

Ingmar Tulva
to Michail A.Baikov

Never met stack problems with FPC. Are you sure you cannot use smaller local variables? If you need realy huge locals, try allocating them in heap.

BTW, doesn't FPC's stack grow as needed?

------

Ingmar

------

"Salamanders can survive up to six hours outside a fire if regularly fed pepper" (Scamander 1927).

Reply by email

Michail A.Baikov
to Ingmar Tulva

Maybe you don't understand me ...

Simple example:

Procedure a1;
begin
call_external_function_in_dll;
end;

there need verify stack after returns from dll. I know about impossible this situation (control returning to any memory address), but ... ;-) I think only test SPtr value ...

Earlier message 27 lines
----- Original Message ----- From: "Ingmar Tulva" To: Sent: Monday, May 06, 2002 8:25 PM Subject: Re: [fpc-devel]Stack verifying ... > Never met stack problems with FPC. Are you sure you cannot use smaller > local variables? If you need realy huge locals, try allocating them in > heap. > > BTW, doesn't FPC's stack grow as needed? > > ------ > > Ingmar > > ------ > > "Salamanders can survive up to six hours outside a fire if regularly fed > pepper" (Scamander 1927). > > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel >

Reply by email

Ingmar Tulva
to Michail A.Baikov

On Mon, 6 May 2002, Michail A.Baikov wrote:

}Maybe you don't understand me ...

I really didn't, sorry. Not sure if I do understand now but let's try:

{$asmmode Intel}
function CorruptsStack : Boolean;
 const { "Locals" are typed constants because they must not be in stack. }
   JBuf : Jmp_buf = ();
   ESP_Before : DWord = 0;
   ESP_After : DWord = 0;
 begin
   if SetJump(JBuf)=0 then begin
     asm
       mov [ESP_Before],ESP
     end;
     call_something_suspicious;
     asm
       mov [ESP_After],ESP
     end;
     if ESP_BeforeESP_After then LongJump(JBuf,1);
       { in fact, if ESP_After>ESP_Before, we are still in trouble }
   end
   else Exit(True);
   Result:=False;
 end;

This is probably not exactly what you need but it should help if I got you right.

------

Ingmar

------

"Salamanders can survive up to six hours outside a fire if regularly fed pepper" (Scamander 1927).

Reply by email