2014-07-29 Ed Smith-Rowland <3dw4rd@verizon.net>
[official-gcc.git] / libcilkrts / runtime / jmpbuf.h
blob60573f3a5fa7b71b5f00e44c6d72787f98d41a1c
1 /* jmpbuf.h -*-C++-*-
3 *************************************************************************
5 * @copyright
6 * Copyright (C) 2009-2013, Intel Corporation
7 * All rights reserved.
8 *
9 * @copyright
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
14 * * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 * * Neither the name of Intel Corporation nor the names of its
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * @copyright
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
32 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
33 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
35 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 **************************************************************************/
39 /**
40 * @file jmpbuf.h
42 * @brief Macros and functions to access the _JUMP_BUFFER initialized by a
43 * call to CILK_SETJMP before a cilk_spawn or cilk_sync. The definition of
44 * CILK_SETJMP and CILK_LONGJMP are OS dependent and in abi.h
48 #ifndef INCLUDED_JMPBUF_DOT_H
49 #define INCLUDED_JMPBUF_DOT_H
51 #include <cilk/common.h>
52 #include <internal/abi.h>
53 #include <stddef.h>
54 #include <setjmp.h>
56 #if 0 /* defined CILK_USE_C_SETJMP && defined JB_RSP */
57 # define JMPBUF_SP(ctx) (ctx)[0].__jmpbuf[JB_RSP]
58 # define JMPBUF_FP(ctx) (ctx)[0].__jmpbuf[JB_RBP]
59 # define JMPBUF_PC(ctx) (ctx)[0].__jmpbuf[JB_PC]
60 #elif 0 /* defined CILK_USE_C_SETJMP && defined JB_SP */
61 # define JMPBUF_SP(ctx) (ctx)[0].__jmpbuf[JB_SP]
62 # define JMPBUF_FP(ctx) (ctx)[0].__jmpbuf[JB_BP]
63 # define JMPBUF_PC(ctx) (ctx)[0].__jmpbuf[JB_PC]
64 #elif defined _WIN64
65 # define JMPBUF_SP(ctx) ((_JUMP_BUFFER*)(&(ctx)))->Rsp
66 # define JMPBUF_FP(ctx) ((_JUMP_BUFFER*)(&(ctx)))->Rbp
67 # define JMPBUF_PC(ctx) ((_JUMP_BUFFER*)(&(ctx)))->Rip
68 #elif defined _WIN32
69 /** Fetch stack pointer from a __cilkrts_stack_frame */
70 # define JMPBUF_SP(ctx) (ctx).Esp
71 /** Fetch frame pointer from a __cilkrts_stack_frame */
72 # define JMPBUF_FP(ctx) (ctx).Ebp
73 /** Fetch program counter from a __cilkrts_stack_frame */
74 # define JMPBUF_PC(ctx) (ctx).Eip
75 #else /* defined __GNUC__ || defined __ICC */
76 /* word 0 is frame address
77 * word 1 is resume address
78 * word 2 is stack address */
79 # define JMPBUF_FP(ctx) (ctx)[0]
80 # define JMPBUF_PC(ctx) (ctx)[1]
81 # define JMPBUF_SP(ctx) (ctx)[2]
82 #endif
84 /**
85 * @brief Get frame pointer from jump buffer in__cilkrts_stack_frame.
87 #define FP(SF) JMPBUF_FP((SF)->ctx)
89 /**
90 * @brief Get program counter from jump buffer in__cilkrts_stack_frame.
92 #define PC(SF) JMPBUF_PC((SF)->ctx)
94 /**
95 * @brief Get stack pointer from jump buffer in__cilkrts_stack_frame.
97 #define SP(SF) JMPBUF_SP((SF)->ctx)
100 __CILKRTS_BEGIN_EXTERN_C
103 * Fetch the stack pointer from a __cilkrts_stack_frame. The jmpbuf was
104 * initialized before a cilk_spawn or cilk_sync.
106 * @param sf __cilkrts_stack_frame containing the jmpbuf.
108 * @return the stack pointer from the ctx.
110 inline char *__cilkrts_get_sp(__cilkrts_stack_frame *sf)
112 return (char *)SP(sf);
116 * Calculate the frame size from __cilkrts_stack_frame. The jmpbuf was
117 * initialized before a cilk_spawn or cilk_sync.
119 * @warning Returning an arbitrary value on Windows!
121 * @param sf __cilkrts_stack_frame containing the jmpbuf.
123 * @return the stack pointer from the ctx.
125 inline ptrdiff_t __cilkrts_get_frame_size(__cilkrts_stack_frame *sf)
127 #ifdef _WIN32
128 if (0 == SP(sf))
129 return 256; // Arbitrary!
130 #endif
131 return (ptrdiff_t)FP(sf) - (ptrdiff_t)SP(sf);
134 __CILKRTS_END_EXTERN_C
136 #endif // ! defined(INCLUDED_JMPBUF_DOT_H)