C stack

Simon Marlow simonmar@microsoft.com
Fri, 15 Dec 2000 02:13:11 -0800


> Hi,
> 
> I'm trying to write an interface for a C library that
> uses a Boehm type garbage collector. So, I need to get
> the address of the bottom of the C stack. In a C
> application this would look something like:
>   main()
>   {
>     int bottomOfStack;
>   }
> Where "&bottomOfStack" would be the thing I need. So,
> I'd want some function like:
>   bottomOfStack :: IO Addr
> 
> Would it be possible at all to make an interface to
> a C library that uses Boehm's garbage collection ?
> What Boehm's algorithm does is traverse the C stack
> at each garbage collect marking all accessible
> nodes and then sweeping all unmarked nodes. Would
> this cause problems with the C code generated by
> ghc ?

I don't forsee any problems with the C stack - the stack pointer stays
static during execution of Haskell code, and only moves when we do a C
call or return to the RTS.

Don't forget to tell the GC to traverse the Haskell heap too - GHC keeps
this in mmapped address space.  See fptools/ghc/rts/MBlock.c for the
details.

Cheers,
	Simon