1/* Dynamic loading of the libgcc unwinder. Generic version.
2 Copyright (C) 2021-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19#ifndef _UNWIND_LINK_H
20#define _UNWIND_LINK_H
21
22#include <unwind.h>
23#include <unwind-arch.h>
24
25#if !UNWIND_LINK_FRAME_ADJUSTMENT
26static inline void *
27unwind_arch_adjustment (void *prev, void *addr)
28{
29 return addr;
30}
31#endif
32
33#ifdef SHARED
34# include <sysdep.h>
35# include <unwind-resume.h>
36
37# if UNWIND_LINK_FRAME_STATE_FOR
38struct frame_state;
39# endif
40
41struct unwind_link
42{
43 __typeof (_Unwind_Backtrace) *ptr__Unwind_Backtrace;
44 __typeof (_Unwind_ForcedUnwind) *ptr__Unwind_ForcedUnwind;
45 __typeof (_Unwind_GetCFA) *ptr__Unwind_GetCFA;
46# if UNWIND_LINK_GETIP
47 __typeof (_Unwind_GetIP) *ptr__Unwind_GetIP;
48# endif
49 __typeof (_Unwind_Resume) *ptr__Unwind_Resume;
50#if UNWIND_LINK_FRAME_STATE_FOR
51 struct frame_state *(*ptr___frame_state_for) (void *, struct frame_state *);
52#endif
53 _Unwind_Reason_Code (*ptr_personality) PERSONALITY_PROTO;
54 UNWIND_LINK_EXTRA_FIELDS
55};
56
57/* Return a pointer to the implementation, or NULL on failure. */
58struct unwind_link *__libc_unwind_link_get (void);
59libc_hidden_proto (__libc_unwind_link_get)
60
61/* UNWIND_LINK_PTR returns the stored function pointer NAME from the
62 cached unwind link OBJ (which was previously returned by
63 __libc_unwind_link_get). */
64# ifdef PTR_DEMANGLE
65# define UNWIND_LINK_PTR(obj, name, ...) \
66 ({ \
67 __typeof ((obj)->ptr_##name) __unwind_fptr = (obj)->ptr_##name; \
68 PTR_DEMANGLE (__unwind_fptr); \
69 __unwind_fptr; \
70 })
71# else /* !PTR_DEMANGLE */
72# define UNWIND_LINK_PTR(obj, name, ...) ((obj)->ptr_##name)
73# endif
74
75/* Called from fork, in the new subprocess. */
76void __libc_unwind_link_after_fork (void);
77
78/* Called from __libc_freeres. */
79void __libc_unwind_link_freeres (void) attribute_hidden;
80
81#else /* !SHARED */
82
83/* Dummy implementation so that the code can be shared with the SHARED
84 version. */
85struct unwind_link;
86static inline struct unwind_link *
87__libc_unwind_link_get (void)
88{
89 /* Return something that is not a null pointer, so that error checks
90 succeed. */
91 return (struct unwind_link *) 1;
92}
93
94/* Directly call the static implementation. */
95# define UNWIND_LINK_PTR(obj, name, ...) \
96 ((void) (obj), &name)
97
98static inline void
99__libc_unwind_link_after_fork (void)
100{
101 /* No need to clean up if the unwinder is statically linked. */
102}
103
104#endif /* !SHARED */
105
106#endif /* _UNWIND_LINK_H */
107

source code of glibc/sysdeps/generic/unwind-link.h