Similarly to the way we save errno across context switches and
suspendThread/resumeThread, we must save and restore the Win32 error
code via GetLastError()/SetLastError(). Fixes #896.
#ifdef DIST
StgTSODistInfo dist;
#endif
#ifdef DIST
StgTSODistInfo dist;
#endif
+#ifdef mingw32_HOST_OS
+ StgWord32 saved_winerror;
+#endif
/* The thread stack... */
StgWord32 stack_size; /* stack size in *words* */
/* The thread stack... */
StgWord32 stack_size; /* stack size in *words* */
prev_what_next = t->what_next;
errno = t->saved_errno;
prev_what_next = t->what_next;
errno = t->saved_errno;
+#if mingw32_HOST_OS
+ SetLastError(t->saved_winerror);
+#endif
+
cap->in_haskell = rtsTrue;
dirtyTSO(t);
cap->in_haskell = rtsTrue;
dirtyTSO(t);
// XXX: possibly bogus for SMP because this thread might already
// be running again, see code below.
t->saved_errno = errno;
// XXX: possibly bogus for SMP because this thread might already
// be running again, see code below.
t->saved_errno = errno;
+#if mingw32_HOST_OS
+ // Similarly for Windows error code
+ SetLastError(t->saved_winerror);
+#endif
#if defined(THREADED_RTS)
// If ret is ThreadBlocked, and this Task is bound to the TSO that
#if defined(THREADED_RTS)
// If ret is ThreadBlocked, and this Task is bound to the TSO that
suspendThread (StgRegTable *reg)
{
Capability *cap;
suspendThread (StgRegTable *reg)
{
Capability *cap;
- int saved_errno = errno;
+#if mingw32_HOST_OS
+ StgWord32 saved_winerror;
+#endif
+
+ saved_errno = errno;
+#if mingw32_HOST_OS
+ saved_winerror = GetLastError();
+#endif
/* assume that *reg is a pointer to the StgRegTable part of a Capability.
*/
/* assume that *reg is a pointer to the StgRegTable part of a Capability.
*/
#endif
errno = saved_errno;
#endif
errno = saved_errno;
+#if mingw32_HOST_OS
+ SetLastError(saved_winerror);
+#endif
{
StgTSO *tso;
Capability *cap;
{
StgTSO *tso;
Capability *cap;
- int saved_errno = errno;
+ int saved_errno;
+#if mingw32_HOST_OS
+ StgWord32 saved_winerror;
+#endif
+
+ saved_errno = errno;
+#if mingw32_HOST_OS
+ saved_winerror = GetLastError();
+#endif
cap = task->cap;
// Wait for permission to re-enter the RTS with the result.
cap = task->cap;
// Wait for permission to re-enter the RTS with the result.
cap->r.rCurrentTSO = tso;
cap->in_haskell = rtsTrue;
errno = saved_errno;
cap->r.rCurrentTSO = tso;
cap->in_haskell = rtsTrue;
errno = saved_errno;
+#if mingw32_HOST_OS
+ SetLastError(saved_winerror);
+#endif
/* We might have GC'd, mark the TSO dirty again */
dirtyTSO(tso);
/* We might have GC'd, mark the TSO dirty again */
dirtyTSO(tso);