mirror of
https://github.com/tobast/libunwind-eh_elf.git
synced 2025-01-08 18:33:42 +01:00
(Logical change 1.135)
This commit is contained in:
parent
1a7d4ee7ed
commit
ab0fdbbb4c
19 changed files with 1008 additions and 0 deletions
151
include/unwind.h
151
include/unwind.h
|
@ -0,0 +1,151 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#ifndef _UNWIND_H
|
||||
#define _UNWIND_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Minimal interface as per C++ ABI draft standard:
|
||||
|
||||
http://www.codesourcery.com/cxx-abi/abi-eh.html */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
_URC_NO_REASON = 0,
|
||||
_URC_FOREIGN_EXCEPTION_CAUGHT = 1,
|
||||
_URC_FATAL_PHASE2_ERROR = 2,
|
||||
_URC_FATAL_PHASE1_ERROR = 3,
|
||||
_URC_NORMAL_STOP = 4,
|
||||
_URC_END_OF_STACK = 5,
|
||||
_URC_HANDLER_FOUND = 6,
|
||||
_URC_INSTALL_CONTEXT = 7,
|
||||
_URC_CONTINUE_UNWIND = 8
|
||||
}
|
||||
_Unwind_Reason_Code;
|
||||
|
||||
typedef int _Unwind_Action;
|
||||
|
||||
#define _UA_SEARCH_PHASE 1
|
||||
#define _UA_CLEANUP_PHASE 2
|
||||
#define _UA_HANDLER_FRAME 4
|
||||
#define _UA_FORCE_UNWIND 8
|
||||
|
||||
struct _Unwind_Context; /* opaque data-structure */
|
||||
struct _Unwind_Exception; /* forward-declaration */
|
||||
|
||||
typedef void (*_Unwind_Exception_Cleanup_Fn) (_Unwind_Reason_Code,
|
||||
struct _Unwind_Exception *);
|
||||
|
||||
typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int, _Unwind_Action,
|
||||
unsigned long,
|
||||
struct _Unwind_Exception *,
|
||||
struct _Unwind_Context *,
|
||||
void *);
|
||||
|
||||
/* The C++ ABI requires exception_class, private_1, and private_2 to
|
||||
be of type uint64 and the entire structure to be
|
||||
double-word-aligned, but that seems a bit overly IA-64-specific.
|
||||
Using "unsigned long" instead should give us the desired effect on
|
||||
IA-64, while being more general. */
|
||||
struct _Unwind_Exception
|
||||
{
|
||||
unsigned long exception_class;
|
||||
_Unwind_Exception_Cleanup_Fn exception_cleanup;
|
||||
unsigned long private_1;
|
||||
unsigned long private_2;
|
||||
};
|
||||
|
||||
extern _Unwind_Reason_Code _Unwind_RaiseException (struct _Unwind_Exception *);
|
||||
extern _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *,
|
||||
_Unwind_Stop_Fn, void *);
|
||||
extern void _Unwind_Resume (struct _Unwind_Exception *);
|
||||
extern void _Unwind_DeleteException (struct _Unwind_Exception *);
|
||||
extern unsigned long _Unwind_GetGR (struct _Unwind_Context *, int);
|
||||
extern void _Unwind_SetGR (struct _Unwind_Context *, int, unsigned long);
|
||||
extern unsigned long _Unwind_GetIP (struct _Unwind_Context *);
|
||||
extern void _Unwind_SetIP (struct _Unwind_Context *, unsigned long);
|
||||
extern unsigned long _Unwind_GetLanguageSpecificData (struct _Unwind_Context*);
|
||||
extern unsigned long _Unwind_GetRegionStart (struct _Unwind_Context *);
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
|
||||
/* Callback for _Unwind_Backtrace(). The backtrace stops immediately
|
||||
if the callback returns any value other than _URC_NO_REASON. */
|
||||
typedef _Unwind_Reason_Code (*_Unwind_Trace_Fn) (struct _Unwind_Context *,
|
||||
void *);
|
||||
|
||||
/* See http://gcc.gnu.org/ml/gcc-patches/2001-09/msg00082.html for why
|
||||
_UA_END_OF_STACK exists. */
|
||||
# define _UA_END_OF_STACK 16
|
||||
|
||||
/* If the unwind was initiated due to a forced unwind, resume that
|
||||
operation, else re-raise the exception. This is used by
|
||||
__cxa_rethrow(). */
|
||||
extern _Unwind_Reason_Code
|
||||
_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *);
|
||||
|
||||
/* See http://gcc.gnu.org/ml/gcc-patches/2003-09/msg00154.html for why
|
||||
_Unwind_GetBSP() exists. */
|
||||
extern unsigned long _Unwind_GetBSP (struct _Unwind_Context *);
|
||||
|
||||
/* Return the "canonical frame address" for the given context.
|
||||
This is used by NPTL... */
|
||||
extern unsigned long _Unwind_GetCFA (struct _Unwind_Context *);
|
||||
|
||||
/* Return the base-address for data references. */
|
||||
extern unsigned long _Unwind_GetDataRelBase (struct _Unwind_Context *);
|
||||
|
||||
/* Return the base-address for text references. */
|
||||
extern unsigned long _Unwind_GetTextRelBase (struct _Unwind_Context *);
|
||||
|
||||
/* Call _Unwind_Trace_Fn once for each stack-frame, without doing any
|
||||
cleanup. The first frame for which the callback is invoked is the
|
||||
one for the caller of _Unwind_Backtrace(). _Unwind_Backtrace()
|
||||
returns _URC_END_OF_STACK when the backtrace stopped due to
|
||||
reaching the end of the call-chain or _URC_FATAL_PHASE1_ERROR if it
|
||||
stops for any other reason. */
|
||||
extern _Unwind_Reason_Code _Unwind_Backtrace (_Unwind_Trace_Fn, void *);
|
||||
|
||||
/* Find the start-address of the procedure containing the specified IP
|
||||
or NULL if it cannot be found (e.g., because the function has no
|
||||
unwind info). Note: there is not necessarily a one-to-one
|
||||
correspondence between source-level functions and procedures: some
|
||||
functions don't have unwind-info and others are split into multiple
|
||||
procedures. */
|
||||
extern void *_Unwind_FindEnclosingFunction (void *);
|
||||
|
||||
/* See also Linux Standard Base Spec:
|
||||
http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/libgcc-s.html */
|
||||
|
||||
#endif /* _GNU_SOURCE */
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* _UNWIND_H */
|
|
@ -0,0 +1,53 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
_Unwind_Reason_Code
|
||||
_Unwind_Backtrace (_Unwind_Trace_Fn trace, void *trace_parameter)
|
||||
{
|
||||
struct _Unwind_Context context;
|
||||
unw_context_t uc;
|
||||
int ret;
|
||||
|
||||
if (_Unwind_InitContext (&context, &uc) < 0)
|
||||
return _URC_FATAL_PHASE1_ERROR;
|
||||
|
||||
/* Phase 1 (search phase) */
|
||||
|
||||
while (1)
|
||||
{
|
||||
if ((ret = unw_step (&context.cursor)) <= 0)
|
||||
{
|
||||
if (ret == 0)
|
||||
return _URC_END_OF_STACK;
|
||||
else
|
||||
return _URC_FATAL_PHASE1_ERROR;
|
||||
}
|
||||
|
||||
if ((*trace) (&context, trace_parameter) != _URC_NO_REASON)
|
||||
return _URC_FATAL_PHASE1_ERROR;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
void
|
||||
_Unwind_DeleteException (struct _Unwind_Exception *exception_object)
|
||||
{
|
||||
_Unwind_Exception_Cleanup_Fn cleanup = exception_object->exception_cleanup;
|
||||
|
||||
if (cleanup)
|
||||
(*cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exception_object);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
void *
|
||||
_Unwind_FindEnclosingFunction (void *ip)
|
||||
{
|
||||
unw_proc_info_t pi;
|
||||
|
||||
if (unw_get_proc_info_by_ip (unw_local_addr_space, (unw_word_t) ip, &pi, 0)
|
||||
< 0)
|
||||
return NULL;
|
||||
|
||||
return (void *) pi.start_ip;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
_Unwind_Reason_Code
|
||||
_Unwind_ForcedUnwind (struct _Unwind_Exception *exception_object,
|
||||
_Unwind_Stop_Fn stop, void *stop_parameter)
|
||||
{
|
||||
struct _Unwind_Context context;
|
||||
unw_context_t uc;
|
||||
|
||||
/* We check "stop" here to tell the compiler's inliner that
|
||||
exception_object->private_1 isn't NULL when calling
|
||||
_Unwind_Phase2(). */
|
||||
if (!stop)
|
||||
return _URC_FATAL_PHASE2_ERROR;
|
||||
|
||||
if (_Unwind_InitContext (&context, &uc) < 0)
|
||||
return _URC_FATAL_PHASE2_ERROR;
|
||||
|
||||
exception_object->private_1 = (unsigned long) stop;
|
||||
exception_object->private_2 = (unsigned long) stop_parameter;
|
||||
|
||||
return _Unwind_Phase2 (exception_object, &context);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
unsigned long
|
||||
_Unwind_GetBSP (struct _Unwind_Context *context)
|
||||
{
|
||||
#ifdef UNW_TARGET_IA64
|
||||
unw_word_t val;
|
||||
|
||||
unw_get_reg (&context->cursor, UNW_IA64_BSP, &val);
|
||||
return val;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
unsigned long
|
||||
_Unwind_GetCFA (struct _Unwind_Context *context)
|
||||
{
|
||||
unw_word_t val;
|
||||
|
||||
unw_get_reg (&context->cursor, UNW_REG_SP, &val);
|
||||
return val;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
unsigned long
|
||||
_Unwind_GetDataRelBase (struct _Unwind_Context *context)
|
||||
{
|
||||
/* Not yet implemented. DWARF2-based exception-handling would need
|
||||
this, apparently. */
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
unsigned long
|
||||
_Unwind_GetGR (struct _Unwind_Context *context, int index)
|
||||
{
|
||||
unw_word_t val;
|
||||
|
||||
if (index == UNW_REG_SP && context->end_of_stack)
|
||||
/* _Unwind_ForcedUnwind() requires us to return a NULL
|
||||
stack-pointer after reaching the end of the stack. */
|
||||
return 0;
|
||||
|
||||
unw_get_reg (&context->cursor, index, &val);
|
||||
return val;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
unsigned long
|
||||
_Unwind_GetIP (struct _Unwind_Context *context)
|
||||
{
|
||||
unw_word_t val;
|
||||
|
||||
unw_get_reg (&context->cursor, UNW_REG_IP, &val);
|
||||
return val;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
unsigned long
|
||||
_Unwind_GetLanguageSpecificData (struct _Unwind_Context *context)
|
||||
{
|
||||
unw_proc_info_t pi;
|
||||
|
||||
pi.lsda = 0;
|
||||
unw_get_proc_info (&context->cursor, &pi);
|
||||
return pi.lsda;
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
unsigned long
|
||||
_Unwind_GetRegionStart (struct _Unwind_Context *context)
|
||||
{
|
||||
unw_proc_info_t pi;
|
||||
|
||||
pi.start_ip = 0;
|
||||
unw_get_proc_info (&context->cursor, &pi);
|
||||
return pi.start_ip;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
unsigned long
|
||||
_Unwind_GetTextRelBase (struct _Unwind_Context *context)
|
||||
{
|
||||
/* Not yet implemented. DWARF2-based exception-handling would need
|
||||
this, apparently. */
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
_Unwind_Reason_Code
|
||||
_Unwind_RaiseException (struct _Unwind_Exception *exception_object)
|
||||
{
|
||||
unsigned long exception_class = exception_object->exception_class;
|
||||
_Unwind_Personality_Fn personality;
|
||||
struct _Unwind_Context context;
|
||||
_Unwind_Reason_Code reason;
|
||||
unw_proc_info_t pi;
|
||||
unw_context_t uc;
|
||||
unw_word_t ip;
|
||||
int ret;
|
||||
|
||||
debug (1, "%s(exception_object=%p)\n", __FUNCTION__, exception_object);
|
||||
|
||||
if (_Unwind_InitContext (&context, &uc) < 0)
|
||||
return _URC_FATAL_PHASE1_ERROR;
|
||||
|
||||
/* Phase 1 (search phase) */
|
||||
|
||||
while (1)
|
||||
{
|
||||
if ((ret = unw_step (&context.cursor)) <= 0)
|
||||
{
|
||||
if (ret == 0)
|
||||
{
|
||||
debug (1, "%s: no handler found\n", __FUNCTION__);
|
||||
return _URC_END_OF_STACK;
|
||||
}
|
||||
else
|
||||
return _URC_FATAL_PHASE1_ERROR;
|
||||
}
|
||||
|
||||
if (unw_get_proc_info (&context.cursor, &pi) < 0)
|
||||
return _URC_FATAL_PHASE1_ERROR;
|
||||
|
||||
personality = (_Unwind_Personality_Fn) pi.handler;
|
||||
if (personality)
|
||||
{
|
||||
reason = (*personality) (_U_VERSION, _UA_SEARCH_PHASE,
|
||||
exception_class, exception_object,
|
||||
&context);
|
||||
if (reason != _URC_CONTINUE_UNWIND)
|
||||
{
|
||||
if (reason == _URC_HANDLER_FOUND)
|
||||
break;
|
||||
else
|
||||
{
|
||||
debug (1, "%s: personality returned %d\n",
|
||||
__FUNCTION__, reason);
|
||||
return _URC_FATAL_PHASE1_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Exceptions are associated with IP-ranges. If a given exception
|
||||
is handled at a particular IP, it will _always_ be handled at
|
||||
that IP. If this weren't true, we'd have to track the tuple
|
||||
(IP,SP,BSP) to uniquely identify the stack frame that's handling
|
||||
the exception. */
|
||||
if (unw_get_reg (&context.cursor, UNW_REG_IP, &ip) < 0)
|
||||
return _URC_FATAL_PHASE1_ERROR;
|
||||
exception_object->private_1 = 0; /* clear "stop" pointer */
|
||||
exception_object->private_2 = ip; /* save frame marker */
|
||||
|
||||
debug (1, "%s: found handler for IP=%lx; entering cleanup phase\n",
|
||||
__FUNCTION__, ip);
|
||||
|
||||
/* Reset the cursor to the first frame: */
|
||||
if (unw_init_local (&context.cursor, &uc) < 0)
|
||||
return _URC_FATAL_PHASE1_ERROR;
|
||||
|
||||
return _Unwind_Phase2 (exception_object, &context);
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
void
|
||||
_Unwind_Resume (struct _Unwind_Exception *exception_object)
|
||||
{
|
||||
struct _Unwind_Context context;
|
||||
unw_context_t uc;
|
||||
|
||||
if (_Unwind_InitContext (&context, &uc) < 0)
|
||||
abort ();
|
||||
|
||||
_Unwind_Phase2 (exception_object, &context);
|
||||
abort ();
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
_Unwind_Reason_Code
|
||||
_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exception_object)
|
||||
{
|
||||
struct _Unwind_Context context;
|
||||
unw_context_t uc;
|
||||
|
||||
if (exception_object->private_1)
|
||||
{
|
||||
if (_Unwind_InitContext (&context, &uc) < 0)
|
||||
return _URC_FATAL_PHASE2_ERROR;
|
||||
|
||||
return _Unwind_Phase2 (exception_object, &context);
|
||||
}
|
||||
else
|
||||
return _Unwind_RaiseException (exception_object);
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
void
|
||||
_Unwind_SetGR (struct _Unwind_Context *context, int index,
|
||||
unsigned long new_value)
|
||||
{
|
||||
unw_set_reg (&context->cursor, index, new_value);
|
||||
#ifdef UNW_TARGET_IA64
|
||||
if (index >= UNW_IA64_GR && index <= UNW_IA64_GR + 127)
|
||||
/* Clear the NaT bit. */
|
||||
unw_set_reg (&context->cursor, UNW_IA64_NAT + (index - UNW_IA64_GR), 0);
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#include "unwind-internal.h"
|
||||
|
||||
void
|
||||
_Unwind_SetIP (struct _Unwind_Context *context, unsigned long new_value)
|
||||
{
|
||||
unw_set_reg (&context->cursor, UNW_REG_IP, new_value);
|
||||
}
|
|
@ -0,0 +1,141 @@
|
|||
/* libunwind - a platform-independent unwind library
|
||||
Copyright (C) 2003 Hewlett-Packard Co
|
||||
Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
|
||||
|
||||
This file is part of libunwind.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
|
||||
#ifndef unwind_internal_h
|
||||
#define unwind_internal_h
|
||||
|
||||
#define UNW_LOCAL_ONLY
|
||||
|
||||
#include <unwind.h>
|
||||
#include <stdlib.h>
|
||||
#include <libunwind.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "tdep.h"
|
||||
|
||||
/* The version of the _Unwind_*() interface implemented by this code. */
|
||||
#define _U_VERSION 1
|
||||
|
||||
typedef _Unwind_Reason_Code (*_Unwind_Personality_Fn)
|
||||
(int, _Unwind_Action, unsigned long, struct _Unwind_Exception *,
|
||||
struct _Unwind_Context *);
|
||||
|
||||
struct _Unwind_Context {
|
||||
unw_cursor_t cursor;
|
||||
int end_of_stack; /* set to 1 if the end of stack was reached */
|
||||
};
|
||||
|
||||
/* This must be a macro because unw_getcontext() must be invoked from
|
||||
the callee, even if optimization (and hence inlining) is turned
|
||||
off. The macro arguments MUST NOT have any side-effects. */
|
||||
#define _Unwind_InitContext(context, uc) \
|
||||
((context)->end_of_stack = 0, \
|
||||
((unw_getcontext (uc) < 0 || unw_init_local (&(context)->cursor, uc) < 0) \
|
||||
? -1 : 0))
|
||||
|
||||
static inline _Unwind_Reason_Code ALWAYS_INLINE
|
||||
_Unwind_Phase2 (struct _Unwind_Exception *exception_object,
|
||||
struct _Unwind_Context *context)
|
||||
{
|
||||
_Unwind_Stop_Fn stop = (_Unwind_Stop_Fn) exception_object->private_1;
|
||||
unsigned long exception_class = exception_object->exception_class;
|
||||
void *stop_parameter = (void *) exception_object->private_2;
|
||||
_Unwind_Personality_Fn personality;
|
||||
_Unwind_Reason_Code reason;
|
||||
_Unwind_Action actions;
|
||||
unw_proc_info_t pi;
|
||||
unw_word_t ip;
|
||||
int ret;
|
||||
|
||||
actions = _UA_CLEANUP_PHASE;
|
||||
if (stop)
|
||||
actions |= _UA_FORCE_UNWIND;
|
||||
|
||||
while (1)
|
||||
{
|
||||
ret = unw_step (&context->cursor);
|
||||
if (ret <= 0)
|
||||
{
|
||||
if (ret == 0)
|
||||
{
|
||||
actions |= _UA_END_OF_STACK;
|
||||
context->end_of_stack = 1;
|
||||
}
|
||||
else
|
||||
return _URC_FATAL_PHASE2_ERROR;
|
||||
}
|
||||
|
||||
if (stop)
|
||||
{
|
||||
reason = (*stop) (_U_VERSION, actions, exception_class,
|
||||
exception_object, context, stop_parameter);
|
||||
if (reason != _URC_NO_REASON)
|
||||
/* Stop function may return _URC_FATAL_PHASE2_ERROR if
|
||||
it's unable to handle end-of-stack condition or
|
||||
_URC_FATAL_PHASE2_ERROR if something is wrong. Not
|
||||
that it matters: the resulting state is indeterminate
|
||||
anyhow so we must return _URC_FATAL_PHASE2_ERROR... */
|
||||
return _URC_FATAL_PHASE2_ERROR;
|
||||
}
|
||||
|
||||
if (context->end_of_stack
|
||||
|| unw_get_proc_info (&context->cursor, &pi) < 0)
|
||||
return _URC_FATAL_PHASE2_ERROR;
|
||||
|
||||
personality = (_Unwind_Personality_Fn) pi.handler;
|
||||
if (personality)
|
||||
{
|
||||
if (!stop)
|
||||
{
|
||||
if (unw_get_reg (&context->cursor, UNW_REG_IP, &ip) < 0)
|
||||
return _URC_FATAL_PHASE2_ERROR;
|
||||
|
||||
if ((unsigned long) stop_parameter == ip)
|
||||
actions |= _UA_HANDLER_FRAME;
|
||||
}
|
||||
|
||||
reason = (*personality) (_U_VERSION, actions, exception_class,
|
||||
exception_object, context);
|
||||
if (reason != _URC_CONTINUE_UNWIND)
|
||||
{
|
||||
if (reason == _URC_INSTALL_CONTEXT)
|
||||
{
|
||||
/* we may regain control via _Unwind_Resume() */
|
||||
unw_resume (&context->cursor);
|
||||
abort ();
|
||||
}
|
||||
else
|
||||
return _URC_FATAL_PHASE2_ERROR;
|
||||
}
|
||||
if (actions & _UA_HANDLER_FRAME)
|
||||
/* The personality routine for the handler-frame changed
|
||||
it's mind; that's a no-no... */
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
return _URC_FATAL_PHASE2_ERROR; /* shouldn't be reached */
|
||||
}
|
||||
|
||||
#endif /* unwind_internal_h */
|
Loading…
Reference in a new issue