m_debuginfo: Suppress warning about not handling entry_value ops
[valgrind.git] / include / pub_tool_libcsetjmp.h
blob6b278d285ba2866a183482032f18c2c655121107
2 /*--------------------------------------------------------------------*/
3 /*--- A minimal setjmp/longjmp facility. pub_tool_libcsetjmp.h ---*/
4 /*--------------------------------------------------------------------*/
6 /*
7 This file is part of Valgrind, a dynamic binary instrumentation
8 framework.
10 Copyright (C) 2010-2017 Mozilla Foundation
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 This program is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, see <http://www.gnu.org/licenses/>.
25 The GNU General Public License is contained in the file COPYING.
28 /* Contributed by Julian Seward <jseward@acm.org> */
30 #ifndef __PUB_TOOL_LIBCSETJMP_H
31 #define __PUB_TOOL_LIBCSETJMP_H
33 #include "pub_tool_basics.h" // UWord
35 //--------------------------------------------------------------------
36 // PURPOSE: Provides a minimal setjmp/longjmp facility, that saves/
37 // restores integer registers, but not necessarily anything more.
38 //--------------------------------------------------------------------
41 /* This provides an extremely minimal setjmp/longjmp facility, in
42 which only the host's integer registers are saved/restored. Or at
43 least, that is the minimal guaranteed functionality.
45 Until Apr 2011 we used __builtin_setjmp and __builtin_longjmp, but
46 it appears that that is not always correctly implemented. See
47 https://bugs.kde.org/show_bug.cgi?id=259977. So this module wraps
48 those functions up and facilitates replacing them with our own
49 implementations where necessary.
52 /* --- !!! --- EXTERNAL HEADERS start --- !!! --- */
53 #include <setjmp.h>
54 /* --- !!! --- EXTERNAL HEADERS end --- !!! --- */
57 /* Don't use jmp_buf, __builtin_setjmp or __builtin_longjmp directly.
58 They don't always work reliably. Instead use these macros, which
59 provide the opportunity to supply alternative implementations as
60 necessary.
62 Note that the abstraction is done with macros (ick) rather than
63 functions and typedefs, since wrapping __builtin_setjmp up in a
64 second function (eg, VG_(minimal_setjmp)) doesn't seem to work for
65 whatever reason -- returns via a VG_(minimal_longjmp) go wrong.
67 VG_MINIMAL_SETJMP stores the current integer register state in the
68 supplied argument, and returns zero. VG_MINIMAL_LONGJMP resumes
69 with the previously saved state, and returns a nonzero, word-sized
70 value. The caller must test all bits of the value in order to make
71 a zero/non-zero determination.
74 #if defined(VGP_ppc32_linux)
76 #define VG_MINIMAL_JMP_BUF(_name) UInt _name [32+1+1]
77 __attribute__((returns_twice))
78 UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
79 __attribute__((noreturn))
80 void VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));
83 #elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)
85 #define VG_MINIMAL_JMP_BUF(_name) ULong _name [32+1+1]
86 __attribute__((returns_twice))
87 UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
88 __attribute__((noreturn))
89 void VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));
92 #elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin) || \
93 defined(VGP_amd64_solaris) || defined(VGP_amd64_freebsd)
95 #define VG_MINIMAL_JMP_BUF(_name) ULong _name [16+1]
96 __attribute__((returns_twice))
97 UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
98 __attribute__((noreturn))
99 void VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));
102 #elif defined(VGP_x86_linux) || defined(VGP_x86_darwin) || \
103 defined(VGP_x86_solaris) || defined(VGP_x86_freebsd)
105 #define VG_MINIMAL_JMP_BUF(_name) UInt _name [8+1]
106 __attribute__((returns_twice))
107 __attribute__((regparm(1))) // this is critical; don't delete
108 UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
109 __attribute__((noreturn))
110 __attribute__((regparm(1))) // ditto
111 void VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));
113 #elif defined(VGP_mips32_linux) || defined(VGP_nanomips_linux)
115 #define VG_MINIMAL_JMP_BUF(_name) ULong _name [104 / sizeof(ULong)]
116 __attribute__((returns_twice))
117 UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
118 __attribute__((noreturn))
119 void VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));
121 #elif defined(VGP_mips64_linux)
123 #define VG_MINIMAL_JMP_BUF(_name) ULong _name [168 / sizeof(ULong)]
124 __attribute__((returns_twice))
125 UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
126 __attribute__((noreturn))
127 void VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));
129 #else
131 /* The default implementation. */
132 #define VG_MINIMAL_JMP_BUF(_name) jmp_buf _name
133 #define VG_MINIMAL_SETJMP(_env) ((UWord)(__builtin_setjmp((_env))))
134 #define VG_MINIMAL_LONGJMP(_env) __builtin_longjmp((_env),1)
136 #endif
138 #endif // __PUB_TOOL_LIBCSETJMP_H
140 /*--------------------------------------------------------------------*/
141 /*--- end pub_tool_libcsetjmp.h ---*/
142 /*--------------------------------------------------------------------*/