sewardj | 6c591e1 | 2011-04-11 16:17:51 +0000 | [diff] [blame^] | 1 | |
| 2 | /*--------------------------------------------------------------------*/ |
| 3 | /*--- A minimal setjmp/longjmp facility. pub_tool_libcsetjmp.h ---*/ |
| 4 | /*--------------------------------------------------------------------*/ |
| 5 | |
| 6 | /* |
| 7 | This file is part of Valgrind, a dynamic binary instrumentation |
| 8 | framework. |
| 9 | |
| 10 | Copyright (C) 2010-2010 Mozilla Inc |
| 11 | |
| 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. |
| 16 | |
| 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. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 25 | 02111-1307, USA. |
| 26 | |
| 27 | The GNU General Public License is contained in the file COPYING. |
| 28 | */ |
| 29 | |
| 30 | /* Contributed by Julian Seward <jseward@acm.org> */ |
| 31 | |
| 32 | #ifndef __PUB_TOOL_LIBCSETJMP_H |
| 33 | #define __PUB_TOOL_LIBCSETJMP_H |
| 34 | |
| 35 | //-------------------------------------------------------------------- |
| 36 | // PURPOSE: Provides a minimal setjmp/longjmp facility, that saves/ |
| 37 | // restores integer registers, but not necessarily anything more. |
| 38 | //-------------------------------------------------------------------- |
| 39 | |
| 40 | |
| 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. |
| 44 | |
| 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. |
| 50 | */ |
| 51 | |
| 52 | /* --- !!! --- EXTERNAL HEADERS start --- !!! --- */ |
| 53 | #include <setjmp.h> |
| 54 | /* --- !!! --- EXTERNAL HEADERS end --- !!! --- */ |
| 55 | |
| 56 | |
| 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. |
| 61 | |
| 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. |
| 66 | */ |
| 67 | #define VG_MINIMAL_JMP_BUF jmp_buf |
| 68 | #define VG_MINIMAL_SETJMP(_env) __builtin_setjmp((_env)) |
| 69 | #define VG_MINIMAL_LONGJMP(_env) __builtin_longjmp((_env),1) |
| 70 | |
| 71 | |
| 72 | #endif // __PUB_TOOL_LIBCSETJMP_H |
| 73 | |
| 74 | /*--------------------------------------------------------------------*/ |
| 75 | /*--- end pub_tool_libcsetjmp.h ---*/ |
| 76 | /*--------------------------------------------------------------------*/ |