1
/* libunwind - a platform-independent unwind library
2
Copyright (C) 2003 Hewlett-Packard Co
3
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5
This file is part of libunwind.
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:
15
The above copyright notice and this permission notice shall be
16
included in all copies or substantial portions of the Software.
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. */
26
#ifndef unwind_internal_h
27
#define unwind_internal_h
29
#define UNW_LOCAL_ONLY
33
#include <libunwind.h>
38
/* The version of the _Unwind_*() interface implemented by this code. */
41
typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
42
(int, _Unwind_Action, unsigned long, struct _Unwind_Exception *,
43
struct _Unwind_Context *);
45
struct _Unwind_Context {
47
int end_of_stack; /* set to 1 if the end of stack was reached */
50
/* This must be a macro because unw_getcontext() must be invoked from
51
the callee, even if optimization (and hence inlining) is turned
52
off. The macro arguments MUST NOT have any side-effects. */
53
#define _Unwind_InitContext(context, uc) \
54
((context)->end_of_stack = 0, \
55
((unw_getcontext (uc) < 0 || unw_init_local (&(context)->cursor, uc) < 0) \
58
static inline _Unwind_Reason_Code ALWAYS_INLINE
59
_Unwind_Phase2 (struct _Unwind_Exception *exception_object,
60
struct _Unwind_Context *context)
62
_Unwind_Stop_Fn stop = (_Unwind_Stop_Fn) exception_object->private_1;
63
unsigned long exception_class = exception_object->exception_class;
64
void *stop_parameter = (void *) exception_object->private_2;
65
_Unwind_Personality_Fn personality;
66
_Unwind_Reason_Code reason;
67
_Unwind_Action actions;
72
actions = _UA_CLEANUP_PHASE;
74
actions |= _UA_FORCE_UNWIND;
78
ret = unw_step (&context->cursor);
83
actions |= _UA_END_OF_STACK;
84
context->end_of_stack = 1;
87
return _URC_FATAL_PHASE2_ERROR;
92
reason = (*stop) (_U_VERSION, actions, exception_class,
93
exception_object, context, stop_parameter);
94
if (reason != _URC_NO_REASON)
95
/* Stop function may return _URC_FATAL_PHASE2_ERROR if
96
it's unable to handle end-of-stack condition or
97
_URC_FATAL_PHASE2_ERROR if something is wrong. Not
98
that it matters: the resulting state is indeterminate
99
anyhow so we must return _URC_FATAL_PHASE2_ERROR... */
100
return _URC_FATAL_PHASE2_ERROR;
103
if (context->end_of_stack
104
|| unw_get_proc_info (&context->cursor, &pi) < 0)
105
return _URC_FATAL_PHASE2_ERROR;
107
personality = (_Unwind_Personality_Fn) pi.handler;
112
if (unw_get_reg (&context->cursor, UNW_REG_IP, &ip) < 0)
113
return _URC_FATAL_PHASE2_ERROR;
115
if ((unsigned long) stop_parameter == ip)
116
actions |= _UA_HANDLER_FRAME;
119
reason = (*personality) (_U_VERSION, actions, exception_class,
120
exception_object, context);
121
if (reason != _URC_CONTINUE_UNWIND)
123
if (reason == _URC_INSTALL_CONTEXT)
125
/* we may regain control via _Unwind_Resume() */
126
unw_resume (&context->cursor);
130
return _URC_FATAL_PHASE2_ERROR;
132
if (actions & _UA_HANDLER_FRAME)
133
/* The personality routine for the handler-frame changed
134
it's mind; that's a no-no... */
138
return _URC_FATAL_PHASE2_ERROR; /* shouldn't be reached */
141
#endif /* unwind_internal_h */