]>
git.ipfire.org Git - thirdparty/bash.git/blob - unwind_prot.h
1 /* unwind_prot.h - Macros and functions for hacking unwind protection. */
3 /* Copyright (C) 1993-2023 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bash is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
21 #if !defined (_UNWIND_PROT_H)
22 #define _UNWIND_PROT_H
24 /* Generic function type void (*) (void *) for all unwind cleanups. A
25 cleanup function does not return a value and takes a single generic
26 pointer argument. This type works fine for arbitrary pointers; if a
27 cleanup function needs to take an int argument, it's passed through
28 a cast to intptr_t, an integer type that's safe to convert to and
30 typedef void sh_uwfunc_t (void *);
32 extern void uwp_init (void);
34 /* Run a function without interrupts. */
35 extern void begin_unwind_frame (char *);
36 extern void discard_unwind_frame (char *);
37 extern void run_unwind_frame (char *);
38 extern void add_unwind_protect (sh_uwfunc_t
*, void *);
39 extern void remove_unwind_protect (void);
40 extern void run_unwind_protects (void);
41 extern void clear_unwind_protect_list (int);
42 extern int have_unwind_protects (void);
43 extern int unwind_protect_tag_on_stack (const char *);
45 /* Define for people who like their code to look a certain way. */
46 #define end_unwind_frame()
48 /* How to protect a variable. */
49 #define unwind_protect_var(X) unwind_protect_mem ((char *)&(X), sizeof (X))
51 extern void unwind_protect_mem (char *, int);
53 /* Backwards compatibility */
54 #define unwind_protect_int unwind_protect_var
55 #define unwind_protect_short unwind_protect_var
56 #define unwind_protect_string unwind_protect_var
57 #define unwind_protect_pointer unwind_protect_var
58 #define unwind_protect_jmp_buf unwind_protect_var
60 #endif /* _UNWIND_PROT_H */