
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

Simon Marlow wrote:
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.
But how do I get the address of the bottom of the stack ? It seems I can define a C main so I can get the bottom of the stack, but how do I make it call Haskell's main to start the application ?
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.
Ok, I will do that, it looks like a better idea than working with ForeignObj and finalizers. Jan
participants (2)
-
Jan Kort
-
Simon Marlow