[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / libunwind / test / forceunwind.pass.cpp
blobe74aa3faa08032ca7c13fcf14d20ff1b6a0197f8
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
10 // REQUIRES: linux
12 // Basic test for _Unwind_ForcedUnwind.
13 // See libcxxabi/test/forced_unwind* tests too.
15 #include <assert.h>
16 #include <dlfcn.h>
17 #include <signal.h>
18 #include <stdint.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/types.h>
23 #include <unistd.h>
24 #include <unwind.h>
26 void foo();
27 _Unwind_Exception ex;
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) {
34 assert(version == 1);
35 assert((actions & _UA_FORCE_UNWIND) != 0);
36 (void)exceptionClass;
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
43 // architecture.
44 if (dladdr(reinterpret_cast<void *>(_Unwind_GetIP(context)), &info) &&
45 info.dli_sname && !strcmp("main", info.dli_sname)) {
46 _Exit(0);
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
61 #endif
62 _Unwind_ForcedUnwind(e, stop, (void *)&foo);
65 int main() {
66 foo();
67 return -2;