Imported Upstream version 1.1
[platform/upstream/libunwind.git] / src / setjmp / setjmp.c
1 /* libunwind - a platform-independent unwind library
2    Copyright (C) 2003-2004 Hewlett-Packard Co
3         Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
4
5 This file is part of libunwind.
6
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  */
25
26 #include <libunwind.h>
27 #include <setjmp.h>
28
29 #include "jmpbuf.h"
30
31 /* Why use K&R syntax here?  setjmp() is often a macro and that
32    expands into a call to, say, __setjmp() and we need to define the
33    libunwind-version of setjmp() with the name of the actual function.
34    Using K&R syntax lets us keep the setjmp() macro while keeping the
35    syntax valid...  This trick works provided setjmp() doesn't do
36    anything other than a function call.  */
37
38 int
39 setjmp (env)
40      jmp_buf env;
41 {
42   void **wp = (void **) env;
43
44   /* this should work on most platforms, but may not be
45      performance-optimal; check the code! */
46   wp[JB_SP] = __builtin_frame_address (0);
47   wp[JB_RP] = (void *) __builtin_return_address (0);
48   return 0;
49 }