Opened 10 years ago

Closed 3 years ago

Last modified 2 years ago

#1820 closed bug (fixed)

Windows segfault-catching only works for the main thread

Reported by: simonmar Owned by:
Priority: lowest Milestone: 8.0.1
Component: Runtime System Version: 6.8.1
Keywords: Cc: simonmar
Operating System: Windows Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: derefnull(ghci), divbyzero(ghci)
Blocked By: Blocking:
Related Tickets: #6079 Differential Rev(s):
Wiki Page:

Description

On Windows, the RTS tries to catch segmentation faults and divide-by-zero exceptions using structured exception handling in rts/Main.c. Unfortunately this only works for the main thread, so if the exception occurs in another thread it won't be caught. GHCi runs all its computations in a separate thread, hence derefnull(ghci) and divbyzero(ghci) are failing.

Change History (21)

comment:1 Changed 10 years ago by igloo

Milestone: 6.8 branch6.8.3
Owner: set to igloo

comment:2 Changed 9 years ago by igloo

Milestone: 6.8.36.10.1

comment:3 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:4 Changed 9 years ago by igloo

Milestone: 6.10.16.10.2

comment:5 Changed 9 years ago by igloo

Milestone: 6.10.26.12.1

comment:6 Changed 8 years ago by igloo

See also the mingw GCC 4.4.0 announcement info on exceptions: http://sourceforge.net/project/shownotes.php?release_id=691876

comment:7 Changed 8 years ago by igloo

Milestone: 6.12.16.12 branch
Type of failure: None/Unknown

comment:8 Changed 8 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:9 Changed 8 years ago by igloo

Owner: igloo deleted

This program, with the seh_excn.* files in the GHC tree:

#include "seh_excn.h"

void g(int *p) {
    printf("1 Points to %d\n", *p);
    printf("2 Not %d\n", 5 / 0);
    printf("3 Points to %d\n", *p);
}

void h() {
    printf("1 Points to %d\n", 6);
    printf("2 Not %d\n", 5 / 0);
    printf("3 Points to %d\n", 7);
}

void f(int *p) {
    BEGIN_CATCH
    g(p);
    // h();
    END_CATCH
}

int main(void) {
    int p;
    p = 28;
    printf("Start\n");
    f(&p);
    printf("End\n");
}

doesn't work properly:

$ ./seh
Start
1 Points to 28

(note that we don't get a "divide by zero" message) whereas if you change it to call h rather than g then it does:

$ ./seh
Start
1 Points to 6
divide by zero

This is a problem because I think we want to do the exception handling in workerStart, where we need to pass the task argument on.

I've looked at using the simpler-looking AddVectoredExceptionHandler instead (which would mean we have to drop Win 2k support, I think), but I'm getting

C:\cygwin\tmp/ccYnOVfO.o:seh2.c:(.text+0xe3): undefined reference to `AddVectoredExceptionHandler'
C:\cygwin\tmp/ccYnOVfO.o:seh2.c:(.text+0xf6): undefined reference to `RemoveVectoredExceptionHandler'
collect2: ld returned 1 exit status

comment:10 Changed 7 years ago by igloo

Milestone: 6.12.36.14.1
Priority: normallow

comment:11 Changed 7 years ago by igloo

Milestone: 7.0.17.0.2

comment:12 Changed 7 years ago by igloo

Milestone: 7.0.27.2.1

comment:13 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:14 Changed 6 years ago by igloo

Milestone: 7.4.17.6.1
Priority: lowlowest

comment:15 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

comment:16 Changed 3 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:17 Changed 3 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:18 Changed 3 years ago by thoughtpolice

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:19 Changed 3 years ago by Phyx-

Cc: simonmar added
Resolution: fixed
Status: newclosed

comment:20 Changed 3 years ago by Phyx-

comment:21 Changed 2 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

Note: See TracTickets for help on using tickets.