aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/generic
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/generic')
-rw-r--r--sysdeps/generic/not-cancel.h10
-rw-r--r--sysdeps/generic/unwind-dw2.c93
-rw-r--r--sysdeps/generic/unwind.inc309
3 files changed, 378 insertions, 34 deletions
diff --git a/sysdeps/generic/not-cancel.h b/sysdeps/generic/not-cancel.h
index b87c160..2bea378 100644
--- a/sysdeps/generic/not-cancel.h
+++ b/sysdeps/generic/not-cancel.h
@@ -19,8 +19,12 @@
02111-1307 USA. */
/* By default we have none. Map the name to the normal functions. */
-#define open_not_cancel(name, flags, mode...) \
- __libc_open (name, flags, ##mode)
+#define open_not_cancel(name, flags, mode) \
+ __libc_open (name, flags, mode)
+#define open_not_cancel_2(name, flags) \
+ __libc_open (name, flags)
+#define close_not_cancel(fd) \
+ __close (fd)
#define close_not_cancel_no_status(fd) \
(void) __close (fd)
#define read_not_cancel(fd, buf, n) \
@@ -29,3 +33,5 @@
__write (fd, buf, n)
#define writev_not_cancel_no_status(fd, iov, n) \
(void) __writev (fd, iov, n)
+# define waitpid_not_cancel(pid, stat_loc, options) \
+ __waitpid (pid, stat_loc, options)
diff --git a/sysdeps/generic/unwind-dw2.c b/sysdeps/generic/unwind-dw2.c
index 8e17546..89f9d59 100644
--- a/sysdeps/generic/unwind-dw2.c
+++ b/sysdeps/generic/unwind-dw2.c
@@ -72,10 +72,8 @@ struct _Unwind_Context
_Unwind_Word args_size;
};
-#ifndef _LIBC
/* Byte size of every register managed by these routines. */
static unsigned char dwarf_reg_size_table[DWARF_FRAME_REGISTERS];
-#endif
/* The result of interpreting the frame unwind info for a frame.
@@ -184,7 +182,7 @@ _Unwind_GetGR (struct _Unwind_Context *context, int index)
_Unwind_Word
_Unwind_GetCFA (struct _Unwind_Context *context)
{
- return (_Unwind_Word) context->cfa;
+ return (_Unwind_Ptr) context->cfa;
}
/* Overwrite the saved value for register REG in CONTEXT with VAL. */
@@ -323,7 +321,7 @@ extract_cie_info (struct dwarf_cie *cie, struct _Unwind_Context *context,
return ret ? ret : p;
}
-#ifndef _LIBC
+
/* Decode a DW_OP stack program. Return the top of stack. Push INITIAL
onto the stack to start. */
@@ -713,7 +711,7 @@ execute_stack_op (const unsigned char *op_ptr, const unsigned char *op_end,
/* Most things push a result value. */
if ((size_t) stack_elt >= sizeof(stack)/sizeof(*stack))
abort ();
- stack[++stack_elt] = result;
+ stack[stack_elt++] = result;
no_push:;
}
@@ -723,7 +721,7 @@ execute_stack_op (const unsigned char *op_ptr, const unsigned char *op_end,
abort ();
return stack[stack_elt];
}
-#endif
+
/* Decode DWARF 2 call frame information. Takes pointers the
instruction sequence to decode, current register information and
@@ -863,17 +861,17 @@ execute_cfa_program (const unsigned char *insn_ptr,
break;
case DW_CFA_def_cfa_expression:
- insn_ptr = read_uleb128 (insn_ptr, &utmp);
fs->cfa_exp = insn_ptr;
fs->cfa_how = CFA_EXP;
+ insn_ptr = read_uleb128 (insn_ptr, &utmp);
insn_ptr += utmp;
break;
case DW_CFA_expression:
insn_ptr = read_uleb128 (insn_ptr, &reg);
- insn_ptr = read_uleb128 (insn_ptr, &utmp);
fs->regs.reg[reg].how = REG_SAVED_EXP;
fs->regs.reg[reg].loc.exp = insn_ptr;
+ insn_ptr = read_uleb128 (insn_ptr, &utmp);
insn_ptr += utmp;
break;
@@ -1061,8 +1059,6 @@ __frame_state_for (void *pc_target, struct frame_state *state_in)
return state_in;
}
-#ifndef _LIBC
-
static void
uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs)
{
@@ -1070,34 +1066,48 @@ uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs)
void *cfa;
long i;
+#ifdef EH_RETURN_STACKADJ_RTX
+ /* Special handling here: Many machines do not use a frame pointer,
+ and track the CFA only through offsets from the stack pointer from
+ one frame to the next. In this case, the stack pointer is never
+ stored, so it has no saved address in the context. What we do
+ have is the CFA from the previous stack frame.
+
+ In very special situations (such as unwind info for signal return),
+ there may be location expressions that use the stack pointer as well.
+
+ Do this conditionally for one frame. This allows the unwind info
+ for one frame to save a copy of the stack pointer from the previous
+ frame, and be able to use much easier CFA mechanisms to do it.
+ Always zap the saved stack pointer value for the next frame; carrying
+ the value over from one frame to another doesn't make sense. */
+
+ _Unwind_Word tmp_sp;
+
+ if (!orig_context.reg[__builtin_dwarf_sp_column ()])
+ {
+ tmp_sp = (_Unwind_Ptr) context->cfa;
+ orig_context.reg[__builtin_dwarf_sp_column ()] = &tmp_sp;
+ }
+ context->reg[__builtin_dwarf_sp_column ()] = NULL;
+#endif
+
/* Compute this frame's CFA. */
switch (fs->cfa_how)
{
case CFA_REG_OFFSET:
- /* Special handling here: Many machines do not use a frame pointer,
- and track the CFA only through offsets from the stack pointer from
- one frame to the next. In this case, the stack pointer is never
- stored, so it has no saved address in the context. What we do
- have is the CFA from the previous stack frame. */
- if (context->reg[fs->cfa_reg] == NULL)
- cfa = context->cfa;
- else
- cfa = (void *) (_Unwind_Ptr) _Unwind_GetGR (context, fs->cfa_reg);
+ cfa = (void *) (_Unwind_Ptr) _Unwind_GetGR (&orig_context, fs->cfa_reg);
cfa += fs->cfa_offset;
break;
case CFA_EXP:
- /* ??? No way of knowing what register number is the stack pointer
- to do the same sort of handling as above. Assume that if the
- CFA calculation is so complicated as to require a stack program
- that this will not be a problem. */
{
const unsigned char *exp = fs->cfa_exp;
_Unwind_Word len;
exp = read_uleb128 (exp, &len);
cfa = (void *) (_Unwind_Ptr)
- execute_stack_op (exp, exp + len, context, 0);
+ execute_stack_op (exp, exp + len, &orig_context, 0);
break;
}
@@ -1112,12 +1122,15 @@ uw_update_context_1 (struct _Unwind_Context *context, _Unwind_FrameState *fs)
{
case REG_UNSAVED:
break;
+
case REG_SAVED_OFFSET:
context->reg[i] = cfa + fs->regs.reg[i].loc.offset;
break;
+
case REG_SAVED_REG:
context->reg[i] = orig_context.reg[fs->regs.reg[i].loc.reg];
break;
+
case REG_SAVED_EXP:
{
const unsigned char *exp = fs->regs.reg[i].loc.exp;
@@ -1169,6 +1182,7 @@ uw_init_context_1 (struct _Unwind_Context *context,
{
void *ra = __builtin_extract_return_addr (__builtin_return_address (0));
_Unwind_FrameState fs;
+ _Unwind_Word sp_slot;
memset (context, 0, sizeof (struct _Unwind_Context));
context->ra = ra;
@@ -1177,9 +1191,10 @@ uw_init_context_1 (struct _Unwind_Context *context,
abort ();
/* Force the frame state to use the known cfa value. */
- context->cfa = outer_cfa;
+ sp_slot = (_Unwind_Ptr) outer_cfa;
+ context->reg[__builtin_dwarf_sp_column ()] = &sp_slot;
fs.cfa_how = CFA_REG_OFFSET;
- fs.cfa_reg = 0;
+ fs.cfa_reg = __builtin_dwarf_sp_column ();
fs.cfa_offset = 0;
uw_update_context_1 (context, &fs);
@@ -1236,11 +1251,26 @@ uw_install_context_1 (struct _Unwind_Context *current,
memcpy (c, t, dwarf_reg_size_table[i]);
}
- /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
- if (STACK_GROWS_DOWNWARD)
- return target->cfa - current->cfa + target->args_size;
- else
- return current->cfa - target->cfa - target->args_size;
+#ifdef EH_RETURN_STACKADJ_RTX
+ {
+ void *target_cfa;
+
+ /* If the last frame records a saved stack pointer, use it. */
+ if (target->reg[__builtin_dwarf_sp_column ()])
+ target_cfa = (void *)(_Unwind_Ptr)
+ _Unwind_GetGR (target, __builtin_dwarf_sp_column ());
+ else
+ target_cfa = target->cfa;
+
+ /* We adjust SP by the difference between CURRENT and TARGET's CFA. */
+ if (STACK_GROWS_DOWNWARD)
+ return target_cfa - current->cfa + target->args_size;
+ else
+ return current->cfa - target_cfa - target->args_size;
+ }
+#else
+ return 0;
+#endif
}
static inline _Unwind_Ptr
@@ -1252,5 +1282,4 @@ uw_identify_context (struct _Unwind_Context *context)
#include "unwind.inc"
-#endif /* _LIBC */
#endif /* !USING_SJLJ_EXCEPTIONS */
diff --git a/sysdeps/generic/unwind.inc b/sysdeps/generic/unwind.inc
new file mode 100644
index 0000000..7ec65e9
--- /dev/null
+++ b/sysdeps/generic/unwind.inc
@@ -0,0 +1,309 @@
+/* Exception handling and frame unwind runtime interface routines. -*- C -*-
+ Copyright (C) 2001 Free Software Foundation, Inc.
+
+ This file is part of GCC.
+
+ GCC is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GCC is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
+ License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GCC; see the file COPYING. If not, write to the Free
+ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
+
+/* This is derived from the C++ ABI for IA-64. Where we diverge
+ for cross-architecture compatibility are noted with "@@@".
+ This file is included from unwind-dw2.c or unwind-ia64.c. */
+
+/* Subroutine of _Unwind_RaiseException also invoked from _Unwind_Resume.
+
+ Unwind the stack calling the personality routine to find both the
+ exception handler and intermediary cleanup code. We'll only locate
+ the first such frame here. Cleanup code will call back into
+ _Unwind_Resume and we'll continue Phase 2 there. */
+
+static _Unwind_Reason_Code
+_Unwind_RaiseException_Phase2(struct _Unwind_Exception *exc,
+ struct _Unwind_Context *context)
+{
+ _Unwind_Reason_Code code;
+
+ while (1)
+ {
+ _Unwind_FrameState fs;
+ int match_handler;
+
+ code = uw_frame_state_for (context, &fs);
+
+ /* Identify when we've reached the designated handler context. */
+ match_handler = (uw_identify_context (context) == exc->private_2
+ ? _UA_HANDLER_FRAME : 0);
+
+ if (code != _URC_NO_REASON)
+ /* Some error encountered. Usually the unwinder doesn't
+ diagnose these and merely crashes. */
+ return _URC_FATAL_PHASE2_ERROR;
+
+ /* Unwind successful. Run the personality routine, if any. */
+ if (fs.personality)
+ {
+ code = (*fs.personality) (1, _UA_CLEANUP_PHASE | match_handler,
+ exc->exception_class, exc, context);
+ if (code == _URC_INSTALL_CONTEXT)
+ break;
+ if (code != _URC_CONTINUE_UNWIND)
+ return _URC_FATAL_PHASE2_ERROR;
+ }
+
+ /* Don't let us unwind past the handler context. */
+ if (match_handler)
+ abort ();
+
+ uw_update_context (context, &fs);
+ }
+
+ return code;
+}
+
+/* Raise an exception, passing along the given exception object. */
+#ifndef _LIBC
+_Unwind_Reason_Code
+_Unwind_RaiseException(struct _Unwind_Exception *exc)
+{
+ struct _Unwind_Context this_context, cur_context;
+ _Unwind_Reason_Code code;
+
+ /* Set up this_context to describe the current stack frame. */
+ uw_init_context (&this_context);
+ cur_context = this_context;
+
+ /* Phase 1: Search. Unwind the stack, calling the personality routine
+ with the _UA_SEARCH_PHASE flag set. Do not modify the stack yet. */
+ while (1)
+ {
+ _Unwind_FrameState fs;
+
+ /* Set up fs to describe the FDE for the caller of cur_context. The
+ first time through the loop, that means __cxa_throw. */
+ code = uw_frame_state_for (&cur_context, &fs);
+
+ if (code == _URC_END_OF_STACK)
+ /* Hit end of stack with no handler found. */
+ return _URC_END_OF_STACK;
+
+ if (code != _URC_NO_REASON)
+ /* Some error encountered. Ususally the unwinder doesn't
+ diagnose these and merely crashes. */
+ return _URC_FATAL_PHASE1_ERROR;
+
+ /* Unwind successful. Run the personality routine, if any. */
+ if (fs.personality)
+ {
+ code = (*fs.personality) (1, _UA_SEARCH_PHASE, exc->exception_class,
+ exc, &cur_context);
+ if (code == _URC_HANDLER_FOUND)
+ break;
+ else if (code != _URC_CONTINUE_UNWIND)
+ return _URC_FATAL_PHASE1_ERROR;
+ }
+
+ /* Update cur_context to describe the same frame as fs. */
+ uw_update_context (&cur_context, &fs);
+ }
+
+ /* Indicate to _Unwind_Resume and associated subroutines that this
+ is not a forced unwind. Further, note where we found a handler. */
+ exc->private_1 = 0;
+ exc->private_2 = uw_identify_context (&cur_context);
+
+ cur_context = this_context;
+ code = _Unwind_RaiseException_Phase2 (exc, &cur_context);
+ if (code != _URC_INSTALL_CONTEXT)
+ return code;
+
+ uw_install_context (&this_context, &cur_context);
+}
+#endif
+
+
+/* Subroutine of _Unwind_ForcedUnwind also invoked from _Unwind_Resume. */
+
+static _Unwind_Reason_Code
+_Unwind_ForcedUnwind_Phase2(struct _Unwind_Exception *exc,
+ struct _Unwind_Context *context)
+{
+ _Unwind_Stop_Fn stop = (_Unwind_Stop_Fn) (_Unwind_Ptr) exc->private_1;
+ void *stop_argument = (void *) (_Unwind_Ptr) exc->private_2;
+ _Unwind_Reason_Code code, stop_code;
+
+ while (1)
+ {
+ _Unwind_FrameState fs;
+ int action;
+
+ /* Set up fs to describe the FDE for the caller of cur_context. */
+ code = uw_frame_state_for (context, &fs);
+ if (code != _URC_NO_REASON && code != _URC_END_OF_STACK)
+ return _URC_FATAL_PHASE2_ERROR;
+
+ /* Unwind successful. */
+ action = _UA_FORCE_UNWIND | _UA_CLEANUP_PHASE;
+ if (code == _URC_END_OF_STACK)
+ action |= _UA_END_OF_STACK;
+ stop_code = (*stop) (1, action, exc->exception_class, exc,
+ context, stop_argument);
+ if (stop_code != _URC_NO_REASON)
+ return _URC_FATAL_PHASE2_ERROR;
+
+ /* Stop didn't want to do anything. Invoke the personality
+ handler, if applicable, to run cleanups. */
+ if (code == _URC_END_OF_STACK)
+ break;
+
+ if (fs.personality)
+ {
+ code = (*fs.personality) (1, _UA_FORCE_UNWIND | _UA_CLEANUP_PHASE,
+ exc->exception_class, exc, context);
+ if (code == _URC_INSTALL_CONTEXT)
+ break;
+ if (code != _URC_CONTINUE_UNWIND)
+ return _URC_FATAL_PHASE2_ERROR;
+ }
+
+ /* Update cur_context to describe the same frame as fs. */
+ uw_update_context (context, &fs);
+ }
+
+ return code;
+}
+
+
+/* Raise an exception for forced unwinding. */
+#ifndef _LIBC
+_Unwind_Reason_Code
+_Unwind_ForcedUnwind (struct _Unwind_Exception *exc,
+ _Unwind_Stop_Fn stop, void * stop_argument)
+{
+ struct _Unwind_Context this_context, cur_context;
+ _Unwind_Reason_Code code;
+
+ uw_init_context (&this_context);
+ cur_context = this_context;
+
+ exc->private_1 = (_Unwind_Ptr) stop;
+ exc->private_2 = (_Unwind_Ptr) stop_argument;
+
+ code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
+ if (code != _URC_INSTALL_CONTEXT)
+ return code;
+
+ uw_install_context (&this_context, &cur_context);
+}
+#endif
+
+
+/* Resume propagation of an existing exception. This is used after
+ e.g. executing cleanup code, and not to implement rethrowing. */
+
+void
+_Unwind_Resume (struct _Unwind_Exception *exc)
+{
+ struct _Unwind_Context this_context, cur_context;
+ _Unwind_Reason_Code code;
+
+ uw_init_context (&this_context);
+ cur_context = this_context;
+
+ /* Choose between continuing to process _Unwind_RaiseException
+ or _Unwind_ForcedUnwind. */
+ if (exc->private_1 == 0)
+ code = _Unwind_RaiseException_Phase2 (exc, &cur_context);
+ else
+ code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
+
+ if (code != _URC_INSTALL_CONTEXT)
+ abort ();
+
+ uw_install_context (&this_context, &cur_context);
+}
+
+
+/* Resume propagation of an FORCE_UNWIND exception, or to rethrow
+ a normal exception that was handled. */
+#ifndef _LIBC
+_Unwind_Reason_Code
+_Unwind_Resume_or_Rethrow (struct _Unwind_Exception *exc)
+{
+ struct _Unwind_Context this_context, cur_context;
+ _Unwind_Reason_Code code;
+
+ /* Choose between continuing to process _Unwind_RaiseException
+ or _Unwind_ForcedUnwind. */
+ if (exc->private_1 == 0)
+ return _Unwind_RaiseException (exc);
+
+ uw_init_context (&this_context);
+ cur_context = this_context;
+
+ code = _Unwind_ForcedUnwind_Phase2 (exc, &cur_context);
+
+ if (code != _URC_INSTALL_CONTEXT)
+ abort ();
+
+ uw_install_context (&this_context, &cur_context);
+}
+#endif
+
+
+/* A convenience function that calls the exception_cleanup field. */
+#ifndef _LIBC
+void
+_Unwind_DeleteException (struct _Unwind_Exception *exc)
+{
+ if (exc->exception_cleanup)
+ (*exc->exception_cleanup) (_URC_FOREIGN_EXCEPTION_CAUGHT, exc);
+}
+#endif
+
+
+/* Perform stack backtrace through unwind data. */
+#ifndef _LIBC
+_Unwind_Reason_Code
+_Unwind_Backtrace(_Unwind_Trace_Fn trace, void * trace_argument)
+{
+ struct _Unwind_Context context;
+ _Unwind_Reason_Code code;
+
+ uw_init_context (&context);
+
+ while (1)
+ {
+ _Unwind_FrameState fs;
+
+ /* Set up fs to describe the FDE for the caller of context. */
+ code = uw_frame_state_for (&context, &fs);
+ if (code != _URC_NO_REASON && code != _URC_END_OF_STACK)
+ return _URC_FATAL_PHASE1_ERROR;
+
+ /* Call trace function. */
+ if ((*trace) (&context, trace_argument) != _URC_NO_REASON)
+ return _URC_FATAL_PHASE1_ERROR;
+
+ /* We're done at end of stack. */
+ if (code == _URC_END_OF_STACK)
+ break;
+
+ /* Update context to describe the same frame as fs. */
+ uw_update_context (&context, &fs);
+ }
+
+ return code;
+}
+#endif