nhc98-1.{00,01} produce crashing programs

Fergus Henderson fjh at cs.mu.oz.au
Sun Jan 7 17:26:53 EST 2001

On 04-Jan-2001, Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> wrote:
> foreign export dynamic is harder. It must wrap a Haskell function
> (closure) in a C function pointer. It is not possible to do this
> portably in C: function pointers are normally only pointers to elements
> of the finite set of (toplevel) functions. It should allocate a
> block of unmovable memory on the heap (perhaps using malloc), attach
> an equivalent of StablePtr of the function to it on a known offset
> (to be able to free it later using freeHaskellFunPtr), write there a
> constructed machine code which has this stable pointer hardcoded in
> its body and applies it to parameters passed from C, and return the
> pointer to the block as a function pointer.

You forgot to flush the instruction cache.
That is needed on some architectures.
It also tends to be very bad for performance.

On some systems that I've used (some version of DEC Ultrix, if I recall
correctly), you had to be super-user to flush the instruction cache.

Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  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 FFI mailing list