示例#1
0
static _Unwind_Reason_Code unwind_phase2_forced(struct _Unwind_Exception* exception_object, 
												_Unwind_Stop_Fn stop, void* stop_parameter)
{
	// walk each frame until we reach where search phase said to stop
	_Unwind_FunctionContext_t c = __Unwind_SjLj_GetTopOfFunctionStack();
	while ( true ) {

		// get next frame (skip over first which is _Unwind_RaiseException)
		if ( c == NULL ) {
			DEBUG_PRINT_UNWINDING("unwind_phase2(ex_ojb=%p): unw_step() reached bottom => _URC_END_OF_STACK\n", exception_object); 
			return _URC_END_OF_STACK;
		}
				
		// call stop function at each frame
		_Unwind_Action action = (_Unwind_Action)(_UA_FORCE_UNWIND|_UA_CLEANUP_PHASE);
		_Unwind_Reason_Code stopResult = (*stop)(1, action, 
						exception_object->exception_class, exception_object, 
						(struct _Unwind_Context*)c, stop_parameter);
		DEBUG_PRINT_UNWINDING("unwind_phase2_forced(ex_ojb=%p): stop function returned %d\n", exception_object, stopResult);
		if ( stopResult != _URC_NO_REASON ) {
			DEBUG_PRINT_UNWINDING("unwind_phase2_forced(ex_ojb=%p): stopped by stop function\n", exception_object);
			return _URC_FATAL_PHASE2_ERROR;
		}
		
		// if there is a personality routine, tell it we are unwinding
		if ( c->personality != NULL ) {
			__personality_routine p = (__personality_routine)c->personality;
			DEBUG_PRINT_UNWINDING("unwind_phase2_forced(ex_ojb=%p): calling personality function %p\n", exception_object, p);
			_Unwind_Reason_Code personalityResult = (*p)(1, action, 
						exception_object->exception_class, exception_object, 
						(struct _Unwind_Context*)c);
			switch ( personalityResult ) {
				case _URC_CONTINUE_UNWIND:
					DEBUG_PRINT_UNWINDING("unwind_phase2_forced(ex_ojb=%p): personality returned _URC_CONTINUE_UNWIND\n", exception_object);
					// destructors called, continue unwinding
					break;
				case _URC_INSTALL_CONTEXT:
					DEBUG_PRINT_UNWINDING("unwind_phase2_forced(ex_ojb=%p): personality returned _URC_INSTALL_CONTEXT\n", exception_object);
					// we may get control back if landing pad calls _Unwind_Resume()
					__Unwind_SjLj_SetTopOfFunctionStack(c);
					__builtin_longjmp(c->jbuf, 1);
					break;
				default:
					// something went wrong
					DEBUG_PRINT_UNWINDING("unwind_phase2_forced(ex_ojb=%p): personality returned %d, _URC_FATAL_PHASE2_ERROR\n", 
						exception_object, personalityResult);
					return _URC_FATAL_PHASE2_ERROR;
			}
		}
		c = c->prev;
	}

	// call stop function one last time and tell it we've reached the end of the stack
	DEBUG_PRINT_UNWINDING("unwind_phase2_forced(ex_ojb=%p): calling stop function with _UA_END_OF_STACK\n", exception_object);
	_Unwind_Action lastAction = (_Unwind_Action)(_UA_FORCE_UNWIND|_UA_CLEANUP_PHASE|_UA_END_OF_STACK);
	(*stop)(1, lastAction, exception_object->exception_class, exception_object, (struct _Unwind_Context*)c, stop_parameter);
	
	// clean up phase did not resume at the frame that the search phase said it would
	return _URC_FATAL_PHASE2_ERROR;
}
示例#2
0
 static void
jmp_check(Jmp_buf *J, int jv)
{
	if (J)
		J->err = jv;
		__builtin_longjmp(J->jb, 1);
	}
示例#3
0
static
void scan_all_valid_memory_catcher ( Int sigNo, Addr addr )
{
   if (0)
      VG_(printf)("OUCH! sig=%d addr=%#lx\n", sigNo, addr);
   if (sigNo == VKI_SIGSEGV || sigNo == VKI_SIGBUS)
      __builtin_longjmp(memscan_jmpbuf, 1);
}
示例#4
0
static _Unwind_Reason_Code unwind_phase2(struct _Unwind_Exception* exception_object)
{
	DEBUG_PRINT_UNWINDING("unwind_phase2(ex_ojb=%p)\n", exception_object); 
	
	// walk each frame until we reach where search phase said to stop
	_Unwind_FunctionContext_t c = __Unwind_SjLj_GetTopOfFunctionStack();
	while ( true ) {
		DEBUG_PRINT_UNWINDING("unwind_phase2s(ex_ojb=%p): function-context=%p\n", exception_object, c); 

		// check for no more frames
		if ( c == NULL ) {
			DEBUG_PRINT_UNWINDING("unwind_phase2(ex_ojb=%p): unw_step() reached bottom => _URC_END_OF_STACK\n", exception_object); 
			return _URC_END_OF_STACK;
		}
		
		// if there is a personality routine, tell it we are unwinding
		if ( c->personality != NULL ) {
			_Unwind_Action action = _UA_CLEANUP_PHASE;
			if ( (uintptr_t)c == exception_object->private_2 )
				action = (_Unwind_Action)(_UA_CLEANUP_PHASE|_UA_HANDLER_FRAME); // tell personality this was the frame it marked in phase 1
			_Unwind_Reason_Code personalityResult = (*c->personality)(1, action, 
						exception_object->exception_class, exception_object, 
						(struct _Unwind_Context*)c);
			switch ( personalityResult ) {
				case _URC_CONTINUE_UNWIND:
					// continue unwinding
					DEBUG_PRINT_UNWINDING("unwind_phase2(ex_ojb=%p): _URC_CONTINUE_UNWIND\n", exception_object);
					if ( (uintptr_t)c == exception_object->private_2 ) {
						// phase 1 said we would stop at this frame, but we did not...
						ABORT("during phase1 personality function said it would stop here, but now if phase2 it did not stop here");
					}
					break;
				case _URC_INSTALL_CONTEXT:
					DEBUG_PRINT_UNWINDING("unwind_phase2(ex_ojb=%p): _URC_INSTALL_CONTEXT, will resume at landing pad %p\n", exception_object, c->jbuf[1]);
					// personality routine says to transfer control to landing pad
					// we may get control back if landing pad calls _Unwind_Resume()
					__Unwind_SjLj_SetTopOfFunctionStack(c);
					__builtin_longjmp(c->jbuf, 1);
					// unw_resume() only returns if there was an error
					return _URC_FATAL_PHASE2_ERROR;
				default:
					// something went wrong
					DEBUG_MESSAGE("personality function returned unknown result %d", personalityResult);
					return _URC_FATAL_PHASE2_ERROR;
			}
		}
		c = c->prev;
	}

	// clean up phase did not resume at the frame that the search phase said it would
	return _URC_FATAL_PHASE2_ERROR;
}
示例#5
0
void error(const char *fmt, ...) {
    va_list va;
    va_start(va, fmt);
    gui_debug_printf("Error (%08x): ", arm.reg[15]);
    gui_debug_vprintf(fmt, va);
    gui_debug_printf("\n");
    va_end(va);
    debugger(DBG_EXCEPTION, 0);
    cpu_events |= EVENT_RESET;
    #ifndef NO_SETJMP
        __builtin_longjmp(restart_after_exception, 1);
    #else
        assert(false);
    #endif
}
示例#6
0
文件: _eh.C 项目: BillTheBest/k42
void
__sjthrow()
{
    struct eh_context *eh = (*get_eh_context)();
    void ***dhc = &eh->dynamic_handler_chain;
    void * __jmpbuf ;
    void (*func)(void *, int);
    void *arg;
    void ***cleanup = (void***)&(*dhc)[1];

    if (cleanup[0])
    {
	double store[200];
	void **buf = (void**)store;
	buf[1] = 0;
	buf[0] = (*dhc);
	if (! __builtin_setjmp(&buf[2]))
	{
	    *dhc = buf;
	    while (cleanup[0])
	    {
		func = (void(*)(void*, int))cleanup[0][1];
		arg = (void*)cleanup[0][2];
		cleanup[0] = (void **)cleanup[0][0];
		(*func)(arg, 2);
	    }
	    *dhc = (void **)buf[0];
	}
	else
	{
	    __terminate();
	}
    }
    if (! eh->info || (*dhc)[0] == 0)
	__terminate();
    __jmpbuf  = &(*dhc)[2];
    *dhc = (void**)(*dhc)[0];
    __builtin_longjmp(__jmpbuf , 1);
}
示例#7
0
static
void vg_scan_all_valid_memory_sighandler ( Int sigNo )
{
   __builtin_longjmp(memscan_jmpbuf, 1);
}
示例#8
0
文件: setjmp-4.c 项目: 0day-ci/gcc
void raise0(void)
{
  __builtin_longjmp (buf, 1);
}
示例#9
0
文件: builtins.c 项目: Pear0/clang
// CHECK-LABEL: define void @test_builtin_longjmp
void test_builtin_longjmp(void **buffer) {
  // CHECK: [[BITCAST:%.*]] = bitcast
  // CHECK-NEXT: call void @llvm.eh.sjlj.longjmp(i8* [[BITCAST]])
  __builtin_longjmp(buffer, 1);
  // CHECK-NEXT: unreachable
}
示例#10
0
文件: setjmp-2.c 项目: 0day-ci/gcc
static void segv_handler(int seg)
{
   __builtin_longjmp(segv_jmpbuf, 1);
}
void jumpaway(int *ptr) {
  __builtin_longjmp(ptr,1);
}
示例#12
0
static void segv_handler(Int seg)
{
   __builtin_longjmp(segv_jmpbuf, 1);
   VG_(core_panic)("longjmp failed");
}
示例#13
0
static void VG_(oursignalhandler) ( Int sigNo )
{
   Int           ret;
   vki_ksigset_t block_procmask;
   vki_ksigset_t saved_procmask;

   if (VG_(clo_trace_signals)) {
      VG_(start_msg)(Vg_DebugMsg);
      VG_(add_to_msg)("signal %d arrived ... ", sigNo );
   }
   vg_assert(sigNo >= 1 && sigNo < VKI_KNSIG);

   /* Sanity check.  Ensure we're really running on the signal stack
      we asked for. */
   if ( !(
            ((Char*)(&(VG_(sigstack)[0])) <= (Char*)(&ret))
            &&
            ((Char*)(&ret) < (Char*)(&(VG_(sigstack)[10000])))
         )
        ) {
     VG_(message)(Vg_DebugMsg, "FATAL: signal delivered on the wrong stack?!");
     VG_(message)(Vg_DebugMsg, "A possible workaround follows.  Please tell me");
     VG_(message)(Vg_DebugMsg, "([email protected]) if the suggested workaround doesn't help.");
     VG_(unimplemented)
        ("support for progs compiled with -p/-pg; rebuild your prog without -p/-pg");
   }

   vg_assert((Char*)(&(VG_(sigstack)[0])) <= (Char*)(&ret));
   vg_assert((Char*)(&ret) < (Char*)(&(VG_(sigstack)[10000])));

   if (sigNo == VKI_SIGABRT && VG_(sighandler)[sigNo] == NULL) {
      /* We get here if SIGABRT is delivered and the client hasn't
         asked to catch it.  The aim is to exit in a controlled
         manner. */
      if (VG_(clo_trace_signals)) {
         VG_(add_to_msg)("catching SIGABRT");
         VG_(end_msg)();
      }
      VG_(ksignal)(VKI_SIGABRT, VKI_SIG_DFL);
      VG_(interrupt_reason) = VG_Y_EXIT;
      VG_(longjmpd_on_signal) = VKI_SIGABRT;
      __builtin_longjmp(VG_(toploop_jmpbuf),1);
   }

   /* Block all host signals. */
   VG_(ksigfillset)(&block_procmask);
   ret = VG_(ksigprocmask)(VKI_SIG_SETMASK, &block_procmask, &saved_procmask);
   vg_assert(ret == 0);

   if (VG_(sighandler)[sigNo] == NULL) {
      if (VG_(clo_trace_signals)) {
         VG_(add_to_msg)("unexpected!");
         VG_(end_msg)();
      }
      VG_(panic)("vg_oursignalhandler: unexpected signal");
   }

   /* Decide what to do with it. */
   if (VG_(sigpending)[sigNo] == VG_SIGRUNNING) {
       /* Already running; ignore it. */
      if (VG_(clo_trace_signals)) {
         VG_(add_to_msg)("already running; discarded" );
         VG_(end_msg)();
      }
   }
   else
   if (VG_(sigpending)[sigNo] != VG_SIGRUNNING && 
       VG_(sigpending)[sigNo] != VG_SIGIDLE) {
      /* Not running and not idle == pending; ignore it. */
      if (VG_(clo_trace_signals)) {
         VG_(add_to_msg)("already pending; discarded" );
         VG_(end_msg)();
      }
   } 
   else {
      /* Ok, we'd better deliver it to the client, one way or another. */
      vg_assert(VG_(sigpending)[sigNo] == VG_SIGIDLE);

      if (VG_(syscall_depth) == 0) {
         /* The usual case; delivering a signal to the client, and the
            client is not currently in a syscall.  Queue it up for
            delivery at some point in the future. */
         VG_(sigpending)[sigNo] = VG_(sighandler)[sigNo];
         if (VG_(clo_trace_signals)) {
            VG_(add_to_msg)("queued" );
            VG_(end_msg)();
         }
      } else {
         /* The nasty case, which was causing kmail to freeze up: the
            client is (presumably blocked) in a syscall.  We have to
            deliver the signal right now, because it may be that
            running the sighandler is the only way that the syscall
            will be able to return.  In which case, if we don't do
            that, the client will deadlock. */
         if (VG_(clo_trace_signals)) {
            VG_(add_to_msg)("delivering immediately" );
            VG_(end_msg)();
         }
         /* Note that this runs with all host signals blocked. */
         VG_(sigpending)[sigNo] = VG_(sighandler)[sigNo];
         vg_deliver_signal_immediately(sigNo);
         VG_(sigpending)[sigNo] = VG_SIGIDLE;
         /* VG_(printf)("resuming at %p\n", VG_(baseBlock)[VGOFF_(m_eip)]); */
      }
   }

   /* We've finished messing with the queue, so re-enable host signals. */
   ret = VG_(ksigprocmask)(VKI_SIG_SETMASK, &saved_procmask, NULL);

   vg_assert(ret == 0);
   if (sigNo == VKI_SIGSEGV || sigNo == VKI_SIGBUS 
       || sigNo == VKI_SIGFPE || sigNo == VKI_SIGILL) {
      /* Can't continue; must longjmp and thus enter the sighandler
         immediately. */
      VG_(longjmpd_on_signal) = sigNo;
      __builtin_longjmp(VG_(toploop_jmpbuf),1);
   }
}
示例#14
0
static
void SIGSEGV_handler(int signum)
{
   __builtin_longjmp(myjmpbuf, 1);
}
示例#15
0
static void handler_sigill ( Int x ) { __builtin_longjmp(env_sigill,1); }
示例#16
0
sub2 (void)
{
  __builtin_longjmp (buf, 1);
}
示例#17
0
void
_gnat_builtin_longjmp (void *ptr, int flag ATTRIBUTE_UNUSED)
{
   __builtin_longjmp (ptr, 1);
}
示例#18
0
__chk_fail (void)
{
  if (chk_fail_allowed)
    __builtin_longjmp (chk_fail_buf, 1);
  abort ();
}
示例#19
0
__attribute__((noinline, noclone)) void
baz (void)
{
  __builtin_longjmp (&jmp_buf, 1);
}
示例#20
0
static void handler_unsup_insn ( Int x ) { __builtin_longjmp(env_unsup_insn,1); }
示例#21
0
void
__sjthrow ()
{
  struct eh_context *eh = (*get_eh_context) ();
  void ***dhc = &eh->dynamic_handler_chain;
  void *jmpbuf;
  void (*func)(void *, int);
  void *arg;
  void ***cleanup;

  /* The cleanup chain is one word into the buffer.  Get the cleanup
     chain.  */
  cleanup = (void***)&(*dhc)[1];

  /* If there are any cleanups in the chain, run them now.  */
  if (cleanup[0])
    {
      double store[200];
      void **buf = (void**)store;
      buf[1] = 0;
      buf[0] = (*dhc);

      /* try { */
#ifdef DONT_USE_BUILTIN_SETJMP
      if (! setjmp (&buf[2]))
#else
      if (! __builtin_setjmp (&buf[2]))
#endif
	{
	  *dhc = buf;
	  while (cleanup[0])
	    {
	      func = (void(*)(void*, int))cleanup[0][1];
	      arg = (void*)cleanup[0][2];

	      /* Update this before running the cleanup.  */
	      cleanup[0] = (void **)cleanup[0][0];

	      (*func)(arg, 2);
	    }
	  *dhc = buf[0];
	}
      /* catch (...) */
      else
	{
	  __terminate ();	}
    }
  
  /* We must call terminate if we try and rethrow an exception, when
     there is no exception currently active and when there are no
     handlers left.  */
  if (! eh->info || (*dhc)[0] == 0)
    __terminate ();
    
  /* Find the jmpbuf associated with the top element of the dynamic
     handler chain.  The jumpbuf starts two words into the buffer.  */
  jmpbuf = &(*dhc)[2];

  /* Then we pop the top element off the dynamic handler chain.  */
  *dhc = (void**)(*dhc)[0];

  /* And then we jump to the handler.  */

#ifdef DONT_USE_BUILTIN_SETJMP
  longjmp (jmpbuf, 1);
#else
  __builtin_longjmp (jmpbuf, 1);
#endif


}