stdlib: Fix stdbit.h with -Wconversion for clang
[glibc.git] / sysdeps / generic / unwind-link.h
blob0b57208fde1815ab0cc744a6e200c8eb94afbad3
1 /* Dynamic loading of the libgcc unwinder. Generic version.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
19 #ifndef _UNWIND_LINK_H
20 #define _UNWIND_LINK_H
22 #include <unwind.h>
23 #include <unwind-arch.h>
25 #if !UNWIND_LINK_FRAME_ADJUSTMENT
26 static inline void *
27 unwind_arch_adjustment (void *prev, void *addr)
29 return addr;
31 #endif
33 #ifdef SHARED
34 # include <pointer_guard.h>
35 # include <unwind-resume.h>
37 # if UNWIND_LINK_FRAME_STATE_FOR
38 struct frame_state;
39 # endif
41 struct unwind_link
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
57 /* Return a pointer to the implementation, or NULL on failure. */
58 struct unwind_link *__libc_unwind_link_get (void);
59 libc_hidden_proto (__libc_unwind_link_get)
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 # define UNWIND_LINK_PTR(obj, name, ...) \
65 ({ \
66 __typeof ((obj)->ptr_##name) __unwind_fptr = (obj)->ptr_##name; \
67 PTR_DEMANGLE (__unwind_fptr); \
68 __unwind_fptr; \
71 /* Called from fork, in the new subprocess. */
72 void __libc_unwind_link_after_fork (void);
74 /* Called from __libc_freeres. */
75 void __libc_unwind_link_freeres (void) attribute_hidden;
77 #else /* !SHARED */
79 /* Dummy implementation so that the code can be shared with the SHARED
80 version. */
81 struct unwind_link;
82 static inline struct unwind_link *
83 __libc_unwind_link_get (void)
85 /* Return something that is not a null pointer, so that error checks
86 succeed. */
87 return (struct unwind_link *) 1;
90 /* Directly call the static implementation. */
91 # define UNWIND_LINK_PTR(obj, name, ...) \
92 ((void) (obj), &name)
94 static inline void
95 __libc_unwind_link_after_fork (void)
97 /* No need to clean up if the unwinder is statically linked. */
100 #endif /* !SHARED */
102 #endif /* _UNWIND_LINK_H */