[PPL-devel] Re: Raising Prolog exceptions from C code (2nd attempt)

Fergus Henderson fjh at cs.mu.oz.au
Wed Jun 12 13:28:29 CEST 2002


On 12-Jun-2002, Daniel Diaz <Daniel.Diaz at univ-paris1.fr> wrote:
> Fergus Henderson wrote:
> > 
> > Using `-fomit-frame-pointer' (with or without -O2/-O3) is not sufficient
> > to guarantee that the generated code won't use the `ebp' register.
> > [...] I don't think it's a good idea to rely on third-party C libraries
> > not using ebp when they are compiled with -fomit-frame-pointer.
> > That would lead to code which might break when the third-party C library
> > is upgraded to the next version.
> 
> Not really because if this third-party uses ebp it will then save it at
> the entry and restore it at the exit. So the problem comes from foreign
> code using a frame pointer (i.e. ebp) and calling a GNU-Prolog library
> function expecting ebp contains a valid WAM register.

I understand that.  But IMHO the external interface that GNU-Prolog
presents to C code should not rely on ebp containing a valid WAM register.
Instead, GNU-Prolog should save ebp (to a global or thread-local variable)
before calling foreign code, and the routines in the external interface
presented to C code should restore ebp (from the global or thread-local
variable) before trying to access it.  Likewise for any other registers.

That's what we do in the Mercury implementation.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.



More information about the PPL-devel mailing list