2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
12 // TODO: Figure out why this fails with Memory Sanitizer.
15 // Basic test for _Unwind_ForcedUnwind.
16 // See libcxxabi/test/forced_unwind* tests too.
26 #include <sys/types.h>
33 _Unwind_Reason_Code
stop(int version
, _Unwind_Action actions
,
34 _Unwind_Exception_Class exceptionClass
,
35 _Unwind_Exception
*exceptionObject
,
36 struct _Unwind_Context
*context
,
37 void *stop_parameter
) {
39 assert((actions
& _UA_FORCE_UNWIND
) != 0);
41 assert(exceptionObject
== &ex
);
42 assert(stop_parameter
== &foo
);
44 Dl_info info
= {0, 0, 0, 0};
46 // Unwind util the main is reached, above frames depend on the platform and
48 if (dladdr(reinterpret_cast<void *>(_Unwind_GetIP(context
)), &info
) &&
49 info
.dli_sname
&& !strcmp("main", info
.dli_sname
)) {
52 return _URC_NO_REASON
;
55 __attribute__((noinline
)) void foo() {
57 // Arm EHABI defines struct _Unwind_Control_Block as exception
58 // object. Ensure struct _Unwind_Exception* work there too,
59 // because _Unwind_Exception in this case is just an alias.
60 struct _Unwind_Exception
*e
= &ex
;
61 #if defined(_LIBUNWIND_ARM_EHABI)
62 // Create a mock exception object.
63 memset(e
, '\0', sizeof(*e
));
64 strcpy(reinterpret_cast<char *>(&e
->exception_class
), "CLNGUNW");
66 _Unwind_ForcedUnwind(e
, stop
, (void *)&foo
);