1// Make sure we can throw exceptions from work items executed via
2// BindIoCompletionCallback.
3//
4// RUN: %clangxx_asan %s -o %t.exe
5// RUN: %run %t.exe 2>&1 | FileCheck %s
6
7#include <windows.h>
8#include <stdio.h>
9
10void ThrowAndCatch();
11
12__declspec(noinline)
13void Throw() {
14 fprintf(stderr, format: "Throw\n");
15// CHECK: Throw
16 throw 1;
17}
18
19void ThrowAndCatch() {
20 int local;
21 try {
22 Throw();
23 } catch(...) {
24 fprintf(stderr, format: "Catch\n");
25// CHECK: Catch
26 }
27}
28
29char buffer[65536];
30HANDLE done;
31OVERLAPPED ov;
32
33void CALLBACK completion_callback(DWORD error, DWORD bytesRead,
34 LPOVERLAPPED pov) {
35 ThrowAndCatch();
36 SetEvent(done);
37}
38
39int main(int argc, char **argv) {
40 done = CreateEvent(0, false, false, "job is done");
41 if (!done)
42 return 1;
43 HANDLE file = CreateFile(
44 argv[0], GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
45 OPEN_EXISTING,
46 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED,
47 NULL);
48 if (!file)
49 return 2;
50 if (!BindIoCompletionCallback(file, completion_callback, 0))
51 return 3;
52
53 if (!ReadFile(file, buffer, sizeof(buffer), NULL, &ov) &&
54 GetLastError() != ERROR_IO_PENDING)
55 return 4;
56
57 if (WAIT_OBJECT_0 != WaitForSingleObject(done, 10 * 1000))
58 return 5;
59 fprintf(stderr, format: "Done!\n");
60// CHECK: Done!
61}
62

source code of compiler-rt/test/asan/TestCases/Windows/bind_io_completion_callback.cpp