~ubuntu-branches/ubuntu/utopic/libunwind/utopic-proposed

« back to all changes in this revision

Viewing changes to src/unwind/unwind-internal.h

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Delahaye
  • Date: 2005-04-22 11:12:14 UTC
  • mto: (4.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050422111214-0m74olipxly1ra8a
Tags: upstream-0.98.5
ImportĀ upstreamĀ versionĀ 0.98.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* libunwind - a platform-independent unwind library
 
2
   Copyright (C) 2003 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
#ifndef unwind_internal_h
 
27
#define unwind_internal_h
 
28
 
 
29
#define UNW_LOCAL_ONLY
 
30
 
 
31
#include <unwind.h>
 
32
#include <stdlib.h>
 
33
#include <libunwind.h>
 
34
 
 
35
#include "internal.h"
 
36
#include "tdep.h"
 
37
 
 
38
/* The version of the _Unwind_*() interface implemented by this code.  */
 
39
#define _U_VERSION      1
 
40
 
 
41
typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
 
42
        (int, _Unwind_Action, unsigned long, struct _Unwind_Exception *,
 
43
         struct _Unwind_Context *);
 
44
 
 
45
struct _Unwind_Context {
 
46
  unw_cursor_t cursor;
 
47
  int end_of_stack;     /* set to 1 if the end of stack was reached */
 
48
};
 
49
 
 
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) \
 
56
    ? -1 : 0))
 
57
 
 
58
static inline _Unwind_Reason_Code ALWAYS_INLINE
 
59
_Unwind_Phase2 (struct _Unwind_Exception *exception_object,
 
60
                struct _Unwind_Context *context)
 
61
{
 
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;
 
68
  unw_proc_info_t pi;
 
69
  unw_word_t ip;
 
70
  int ret;
 
71
 
 
72
  actions = _UA_CLEANUP_PHASE;
 
73
  if (stop)
 
74
    actions |= _UA_FORCE_UNWIND;
 
75
 
 
76
  while (1)
 
77
    {
 
78
      ret = unw_step (&context->cursor);
 
79
      if (ret <= 0)
 
80
        {
 
81
          if (ret == 0)
 
82
            {
 
83
              actions |= _UA_END_OF_STACK;
 
84
              context->end_of_stack = 1;
 
85
            }
 
86
          else
 
87
            return _URC_FATAL_PHASE2_ERROR;
 
88
        }
 
89
 
 
90
      if (stop)
 
91
        {
 
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;
 
101
        }
 
102
 
 
103
      if (context->end_of_stack
 
104
          || unw_get_proc_info (&context->cursor, &pi) < 0)
 
105
        return _URC_FATAL_PHASE2_ERROR;
 
106
 
 
107
      personality = (_Unwind_Personality_Fn) pi.handler;
 
108
      if (personality)
 
109
        {
 
110
          if (!stop)
 
111
            {
 
112
              if (unw_get_reg (&context->cursor, UNW_REG_IP, &ip) < 0)
 
113
                return _URC_FATAL_PHASE2_ERROR;
 
114
 
 
115
              if ((unsigned long) stop_parameter == ip)
 
116
                actions |= _UA_HANDLER_FRAME;
 
117
            }
 
118
 
 
119
          reason = (*personality) (_U_VERSION, actions, exception_class,
 
120
                                   exception_object, context);
 
121
          if (reason != _URC_CONTINUE_UNWIND)
 
122
            {
 
123
              if (reason == _URC_INSTALL_CONTEXT)
 
124
                {
 
125
                  /* we may regain control via _Unwind_Resume() */
 
126
                  unw_resume (&context->cursor);
 
127
                  abort ();
 
128
                }
 
129
              else
 
130
                return _URC_FATAL_PHASE2_ERROR;
 
131
            }
 
132
          if (actions & _UA_HANDLER_FRAME)
 
133
            /* The personality routine for the handler-frame changed
 
134
               it's mind; that's a no-no... */
 
135
            abort ();
 
136
        }
 
137
    }
 
138
  return _URC_FATAL_PHASE2_ERROR;       /* shouldn't be reached */
 
139
}
 
140
 
 
141
#endif /* unwind_internal_h */