3 *************************************************************************
5 * Copyright (C) 2009-2016, Intel Corporation
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
32 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
35 * *********************************************************************
37 * PLEASE NOTE: This file is a downstream copy of a file mainitained in
38 * a repository at cilkplus.org. Changes made to this file that are not
39 * submitted through the contribution process detailed at
40 * http://www.cilkplus.org/submit-cilk-contribution will be lost the next
41 * time that a new version is released. Changes only submitted to the
42 * GNU compiler collection or posted to the git repository at
43 * https://bitbucket.org/intelcilkruntime/intel-cilk-runtime.git are
46 * We welcome your contributions to this open source project. Thank you
47 * for your assistance in helping us improve Cilk Plus.
48 **************************************************************************/
53 * @brief Macros and functions to access the _JUMP_BUFFER initialized by a
54 * call to CILK_SETJMP before a cilk_spawn or cilk_sync. The definition of
55 * CILK_SETJMP and CILK_LONGJMP are OS dependent and in abi.h
59 #ifndef INCLUDED_JMPBUF_DOT_H
60 #define INCLUDED_JMPBUF_DOT_H
62 #include <cilk/common.h>
63 #include <internal/abi.h>
67 #if 0 /* defined CILK_USE_C_SETJMP && defined JB_RSP */
68 # define JMPBUF_SP(ctx) (ctx)[0].__jmpbuf[JB_RSP]
69 # define JMPBUF_FP(ctx) (ctx)[0].__jmpbuf[JB_RBP]
70 # define JMPBUF_PC(ctx) (ctx)[0].__jmpbuf[JB_PC]
71 #elif 0 /* defined CILK_USE_C_SETJMP && defined JB_SP */
72 # define JMPBUF_SP(ctx) (ctx)[0].__jmpbuf[JB_SP]
73 # define JMPBUF_FP(ctx) (ctx)[0].__jmpbuf[JB_BP]
74 # define JMPBUF_PC(ctx) (ctx)[0].__jmpbuf[JB_PC]
76 # define JMPBUF_SP(ctx) ((_JUMP_BUFFER*)(&(ctx)))->Rsp
77 # define JMPBUF_FP(ctx) ((_JUMP_BUFFER*)(&(ctx)))->Rbp
78 # define JMPBUF_PC(ctx) ((_JUMP_BUFFER*)(&(ctx)))->Rip
80 /** Fetch stack pointer from a __cilkrts_stack_frame */
81 # define JMPBUF_SP(ctx) (ctx).Esp
82 /** Fetch frame pointer from a __cilkrts_stack_frame */
83 # define JMPBUF_FP(ctx) (ctx).Ebp
84 /** Fetch program counter from a __cilkrts_stack_frame */
85 # define JMPBUF_PC(ctx) (ctx).Eip
86 #else /* defined __GNUC__ || defined __ICC */
87 /* word 0 is frame address
88 * word 1 is resume address
89 * word 2 is stack address */
90 # define JMPBUF_FP(ctx) (ctx)[0]
91 # define JMPBUF_PC(ctx) (ctx)[1]
92 # define JMPBUF_SP(ctx) (ctx)[2]
96 * @brief Get frame pointer from jump buffer in__cilkrts_stack_frame.
98 #define FP(SF) JMPBUF_FP((SF)->ctx)
101 * @brief Get program counter from jump buffer in__cilkrts_stack_frame.
103 #define PC(SF) JMPBUF_PC((SF)->ctx)
106 * @brief Get stack pointer from jump buffer in__cilkrts_stack_frame.
108 #define SP(SF) JMPBUF_SP((SF)->ctx)
111 __CILKRTS_BEGIN_EXTERN_C
114 * Fetch the stack pointer from a __cilkrts_stack_frame. The jmpbuf was
115 * initialized before a cilk_spawn or cilk_sync.
117 * @param sf __cilkrts_stack_frame containing the jmpbuf.
119 * @return the stack pointer from the ctx.
121 inline char *__cilkrts_get_sp(__cilkrts_stack_frame
*sf
)
123 return (char *)SP(sf
);
127 * Calculate the frame size from __cilkrts_stack_frame. The jmpbuf was
128 * initialized before a cilk_spawn or cilk_sync.
130 * @warning Returning an arbitrary value on Windows!
132 * @param sf __cilkrts_stack_frame containing the jmpbuf.
134 * @return the stack pointer from the ctx.
136 inline ptrdiff_t __cilkrts_get_frame_size(__cilkrts_stack_frame
*sf
)
140 return 256; // Arbitrary!
142 return (ptrdiff_t)FP(sf
) - (ptrdiff_t)SP(sf
);
145 __CILKRTS_END_EXTERN_C
147 #endif // ! defined(INCLUDED_JMPBUF_DOT_H)