aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata/testwinlibthrow
diff options
context:
space:
mode:
authorqmuntal <quimmuntal@gmail.com>2022-10-14 17:30:45 +0200
committerGopher Robot <gobot@golang.org>2022-10-19 20:21:26 +0000
commit6fe3ccd74c4bf53552da3d9f59463a8a291f59db (patch)
treec386d044d7a85df2ed856a812e2fb7ba140a3469 /src/runtime/testdata/testwinlibthrow
parent4a164a44de3c67da878403504d948dfbd4fc6f7d (diff)
downloadgo-6fe3ccd74c4bf53552da3d9f59463a8a291f59db.tar.xz
runtime: ignore exceptions from non-Go threads on windows arm/arm64
If there is no current G while handling an exception it means the exception was originated in a non-Go thread. The best we can do is ignore the exception and let it flow through other vectored and structured error handlers. I've removed badsignal2 from sigtramp because we can't really know if the signal is bad or not, it might be handled later in the chain. Fixes #50877 Updates #56082 Change-Id: Ica159eb843629986d1fb5482f0b59a9c1ed91698 Reviewed-on: https://go-review.googlesource.com/c/go/+/442896 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Auto-Submit: Michael Pratt <mpratt@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Michael Pratt <mpratt@google.com> Run-TryBot: Quim Muntal <quimmuntal@gmail.com> Reviewed-by: David Chase <drchase@google.com>
Diffstat (limited to 'src/runtime/testdata/testwinlibthrow')
-rw-r--r--src/runtime/testdata/testwinlibthrow/main.go23
-rw-r--r--src/runtime/testdata/testwinlibthrow/veh.cpp53
2 files changed, 76 insertions, 0 deletions
diff --git a/src/runtime/testdata/testwinlibthrow/main.go b/src/runtime/testdata/testwinlibthrow/main.go
new file mode 100644
index 0000000000..50c483f401
--- /dev/null
+++ b/src/runtime/testdata/testwinlibthrow/main.go
@@ -0,0 +1,23 @@
+package main
+
+import (
+ "os"
+ "syscall"
+)
+
+func main() {
+ dll := syscall.MustLoadDLL("veh.dll")
+ RaiseExcept := dll.MustFindProc("RaiseExcept")
+ RaiseNoExcept := dll.MustFindProc("RaiseNoExcept")
+ ThreadRaiseExcept := dll.MustFindProc("ThreadRaiseExcept")
+ ThreadRaiseNoExcept := dll.MustFindProc("ThreadRaiseNoExcept")
+
+ thread := len(os.Args) > 1 && os.Args[1] == "thread"
+ if !thread {
+ RaiseExcept.Call()
+ RaiseNoExcept.Call()
+ } else {
+ ThreadRaiseExcept.Call()
+ ThreadRaiseNoExcept.Call()
+ }
+}
diff --git a/src/runtime/testdata/testwinlibthrow/veh.cpp b/src/runtime/testdata/testwinlibthrow/veh.cpp
new file mode 100644
index 0000000000..ed7015a064
--- /dev/null
+++ b/src/runtime/testdata/testwinlibthrow/veh.cpp
@@ -0,0 +1,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);
+}