[demangler PATCH]: Revert and update generic lambda demangling
[official-gcc.git] / libcilkrts / runtime / jmpbuf.h
blob453d26913c4a741a2675b95395571e907fa82fa4
1 /* jmpbuf.h -*-C++-*-
3 *************************************************************************
5 * Copyright (C) 2009-2016, Intel Corporation
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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
17 * distribution.
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
44 * not tracked.
46 * We welcome your contributions to this open source project. Thank you
47 * for your assistance in helping us improve Cilk Plus.
48 **************************************************************************/
50 /**
51 * @file jmpbuf.h
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>
64 #include <stddef.h>
65 #include <setjmp.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]
75 #elif defined _WIN64
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
79 #elif defined _WIN32
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]
93 #endif
95 /**
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 * @brief Some architecture-dependent stack adjustment.
113 #if defined(__sparcv9) || (defined(__sparc__) && defined(__arch64__))
114 // Subtract SPARC V9 stack bias so the actual stack starts at the
115 // allocated area.
116 # define CILK_ADJUST_SP(SP) ((SP) - 2047)
117 # define CILK_UNADJUST_SP(SP) ((SP) + 2047)
118 #else
119 # define CILK_ADJUST_SP(SP) (SP)
120 # define CILK_UNADJUST_SP(SP) (SP)
121 #endif
123 __CILKRTS_BEGIN_EXTERN_C
126 * Fetch the stack pointer from a __cilkrts_stack_frame. The jmpbuf was
127 * initialized before a cilk_spawn or cilk_sync.
129 * @param sf __cilkrts_stack_frame containing the jmpbuf.
131 * @return the stack pointer from the ctx.
133 inline char *__cilkrts_get_sp(__cilkrts_stack_frame *sf)
135 return (char *)CILK_UNADJUST_SP(SP(sf));
139 * Calculate the frame size from __cilkrts_stack_frame. The jmpbuf was
140 * initialized before a cilk_spawn or cilk_sync.
142 * @warning Returning an arbitrary value on Windows!
144 * @param sf __cilkrts_stack_frame containing the jmpbuf.
146 * @return the stack pointer from the ctx.
148 inline ptrdiff_t __cilkrts_get_frame_size(__cilkrts_stack_frame *sf)
150 #ifdef _WIN32
151 if (0 == SP(sf))
152 return 256; // Arbitrary!
153 #endif
154 return (ptrdiff_t)FP(sf) - (ptrdiff_t)SP(sf);
157 __CILKRTS_END_EXTERN_C
159 #endif // ! defined(INCLUDED_JMPBUF_DOT_H)