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 // Basic test for _Unwind_ForcedUnwind.
13 // See libcxxabi/test/forced_unwind* tests too.
22 #include <sys/types.h>
29 _Unwind_Reason_Code
stop(int version
, _Unwind_Action actions
,
30 uint64_t exceptionClass
,
31 _Unwind_Exception
*exceptionObject
,
32 struct _Unwind_Context
*context
,
33 void *stop_parameter
) {
35 assert((actions
& _UA_FORCE_UNWIND
) != 0);
37 assert(exceptionObject
== &ex
);
38 assert(stop_parameter
== &foo
);
40 Dl_info info
= {0, 0, 0, 0};
42 // Unwind util the main is reached, above frames depend on the platform and
44 if (dladdr(reinterpret_cast<void *>(_Unwind_GetIP(context
)), &info
) &&
45 info
.dli_sname
&& !strcmp("main", info
.dli_sname
)) {
48 return _URC_NO_REASON
;
51 __attribute__((noinline
)) void foo() {
53 // Arm EHABI defines struct _Unwind_Control_Block as exception
54 // object. Ensure struct _Unwind_Exception* work there too,
55 // because _Unwind_Exception in this case is just an alias.
56 struct _Unwind_Exception
*e
= &ex
;
57 #if defined(_LIBUNWIND_ARM_EHABI)
58 // Create a mock exception object.
59 memset(e
, '\0', sizeof(*e
));
60 e
->exception_class
= 0x434C4E47554E5700; // CLNGUNW\0
62 _Unwind_ForcedUnwind(e
, stop
, (void *)&foo
);