#include "Disassembler.h"
#include "Interpreter.h"
+#include <string.h> /* for memcpy */
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+
/* --------------------------------------------------------------------------
* The bytecode interpreter
memcpy(arguments, Sp, sizeof(W_) * stk_offset);
#endif
+ // Restore the Haskell thread's current value of errno
+ errno = cap->r.rCurrentTSO->saved_errno;
+
// There are a bunch of non-ptr words on the stack (the
// ccall args, the ccall fun address and space for the
// result), which we need to cover with an info table
marshall_fn ( (void*)(cap->r.rCurrentTSO->sp + ret_dyn_size) );
#else
// Threaded RTS:
- // We already made a malloced copy of the arguments above.
+ // We already made a copy of the arguments above.
marshall_fn ( arguments );
#endif
LOAD_STACK_POINTERS;
Sp += ret_dyn_size;
+ // Save the Haskell thread's current value of errno
+ cap->r.rCurrentTSO->saved_errno = errno;
+
#ifdef RTS_SUPPORTS_THREADS
// Threaded RTS:
// Copy the "arguments", which might include a return value,