aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata/testwinlibthrow/veh.cpp
blob: ed7015a06418092ee691b13bb77bd405e6f0225a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//go:build ignore

#include <windows.h>

extern "C" __declspec(dllexport)
void RaiseExcept(void)
{
    try
    {
        RaiseException(42, 0, 0, 0);
    }
    catch (...)
    {
    }
}

extern "C" __declspec(dllexport)
void RaiseNoExcept(void)
{
    RaiseException(42, 0, 0, 0);
}

static DWORD WINAPI ThreadRaiser(void* Context)
{
    if (Context)
        RaiseExcept();
    else
        RaiseNoExcept();
    return 0;
}

static void ThreadRaiseXxx(int except)
{
    static int dummy;
    HANDLE thread = CreateThread(0, 0, ThreadRaiser, except ? &dummy : 0, 0, 0);
    if (0 != thread)
    {
        WaitForSingleObject(thread, INFINITE);
        CloseHandle(thread);
    }
}

extern "C" __declspec(dllexport)
void ThreadRaiseExcept(void)
{
    ThreadRaiseXxx(1);
}

extern "C" __declspec(dllexport)
void ThreadRaiseNoExcept(void)
{
    ThreadRaiseXxx(0);
}