File: pub_tool_libcsetjmp.h

package info (click to toggle)
valgrind 1:3.14.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 156,980 kB
  • sloc: ansic: 728,128; exp: 26,134; xml: 22,268; cpp: 7,638; asm: 7,312; makefile: 6,102; perl: 5,910; sh: 5,717
file content (144 lines) | stat: -rw-r--r-- 5,308 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

/*--------------------------------------------------------------------*/
/*--- A minimal setjmp/longjmp facility.     pub_tool_libcsetjmp.h ---*/
/*--------------------------------------------------------------------*/

/*
   This file is part of Valgrind, a dynamic binary instrumentation
   framework.

   Copyright (C) 2010-2017 Mozilla Inc

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307, USA.

   The GNU General Public License is contained in the file COPYING.
*/

/* Contributed by Julian Seward <jseward@acm.org> */

#ifndef __PUB_TOOL_LIBCSETJMP_H
#define __PUB_TOOL_LIBCSETJMP_H

#include "pub_tool_basics.h"   // UWord

//--------------------------------------------------------------------
// PURPOSE: Provides a minimal setjmp/longjmp facility, that saves/
// restores integer registers, but not necessarily anything more.
//--------------------------------------------------------------------


/* This provides an extremely minimal setjmp/longjmp facility, in
   which only the host's integer registers are saved/restored.  Or at
   least, that is the minimal guaranteed functionality.

   Until Apr 2011 we used __builtin_setjmp and __builtin_longjmp, but
   it appears that that is not always correctly implemented.  See
   https://bugs.kde.org/show_bug.cgi?id=259977.  So this module wraps
   those functions up and facilitates replacing them with our own
   implementations where necessary.
*/

/* --- !!! --- EXTERNAL HEADERS start --- !!! --- */
#include <setjmp.h>
/* --- !!! --- EXTERNAL HEADERS end --- !!! --- */


/* Don't use jmp_buf, __builtin_setjmp or __builtin_longjmp directly.
   They don't always work reliably.  Instead use these macros, which
   provide the opportunity to supply alternative implementations as
   necessary.

   Note that the abstraction is done with macros (ick) rather than
   functions and typedefs, since wrapping __builtin_setjmp up in a
   second function (eg, VG_(minimal_setjmp)) doesn't seem to work for
   whatever reason -- returns via a VG_(minimal_longjmp) go wrong.

   VG_MINIMAL_SETJMP stores the current integer register state in the
   supplied argument, and returns zero.  VG_MINIMAL_LONGJMP resumes
   with the previously saved state, and returns a nonzero, word-sized
   value.  The caller must test all bits of the value in order to make
   a zero/non-zero determination.
*/

#if defined(VGP_ppc32_linux)

#define VG_MINIMAL_JMP_BUF(_name)        UInt _name [32+1+1]
__attribute__((returns_twice))
UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
__attribute__((noreturn))
void  VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));


#elif defined(VGP_ppc64be_linux) || defined(VGP_ppc64le_linux)

#define VG_MINIMAL_JMP_BUF(_name)        ULong _name [32+1+1]
__attribute__((returns_twice))
UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
__attribute__((noreturn))
void  VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));


#elif defined(VGP_amd64_linux) || defined(VGP_amd64_darwin) || \
      defined(VGP_amd64_solaris)

#define VG_MINIMAL_JMP_BUF(_name)        ULong _name [16+1]
__attribute__((returns_twice))
UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
__attribute__((noreturn))
void  VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));


#elif defined(VGP_x86_linux) || defined(VGP_x86_darwin) || \
      defined(VGP_x86_solaris)

#define VG_MINIMAL_JMP_BUF(_name)        UInt _name [8+1]
__attribute__((returns_twice))
__attribute__((regparm(1))) // this is critical; don't delete
UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
__attribute__((noreturn))
__attribute__((regparm(1))) // ditto
void  VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));

#elif defined(VGP_mips32_linux)

#define VG_MINIMAL_JMP_BUF(_name)        ULong _name [104 / sizeof(ULong)]
__attribute__((returns_twice))
UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
__attribute__((noreturn))
void  VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));

#elif defined(VGP_mips64_linux)

#define VG_MINIMAL_JMP_BUF(_name)        ULong _name [168 / sizeof(ULong)]
__attribute__((returns_twice))
UWord VG_MINIMAL_SETJMP(VG_MINIMAL_JMP_BUF(_env));
__attribute__((noreturn))
void  VG_MINIMAL_LONGJMP(VG_MINIMAL_JMP_BUF(_env));

#else

/* The default implementation. */
#define VG_MINIMAL_JMP_BUF(_name) jmp_buf _name
#define VG_MINIMAL_SETJMP(_env)   ((UWord)(__builtin_setjmp((_env))))
#define VG_MINIMAL_LONGJMP(_env)  __builtin_longjmp((_env),1)

#endif

#endif   // __PUB_TOOL_LIBCSETJMP_H

/*--------------------------------------------------------------------*/
/*--- end                                    pub_tool_libcsetjmp.h ---*/
/*--------------------------------------------------------------------*/