Example #1
0
File: misc.c Project: att/ast
//
// Builtin `shift`.
//
int b_shift(int n, char *argv[], Shbltin_t *context) {
    char *arg;
    Shell_t *shp = context->shp;
    while ((n = optget(argv, sh_optshift))) {
        switch (n) {
            case ':': {
                errormsg(SH_DICT, 2, "%s", opt_info.arg);
                break;
            }
            case '?': {
                errormsg(SH_DICT, ERROR_usage(0), "%s", opt_info.arg);
                return 2;
            }
            default: { break; }
        }
    }

    if (error_info.errors) {
        errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
        __builtin_unreachable();
    }

    argv += opt_info.index;
    n = ((arg = *argv) ? (int)sh_arith(shp, arg) : 1);
    if (n < 0 || shp->st.dolc < n) {
        errormsg(SH_DICT, ERROR_exit(1), e_number, arg);
        __builtin_unreachable();
    } else {
        shp->st.dolv += n;
        shp->st.dolc -= n;
    }
    return 0;
}
Example #2
0
File: misc.c Project: att/ast
//
// Builtin `wait`.
//
int b_wait(int n, char *argv[], Shbltin_t *context) {
    Shell_t *shp = context->shp;
    while ((n = optget(argv, sh_optwait))) {
        switch (n) {
            case ':': {
                errormsg(SH_DICT, 2, "%s", opt_info.arg);
                break;
            }
            case '?': {
                errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg);
                __builtin_unreachable();
            }
            default: { break; }
        }
    }

    if (error_info.errors) {
        errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
        __builtin_unreachable();
    }

    argv += opt_info.index;
    job_bwait(argv);
    return shp->exitval;
}
Example #3
0
File: misc.c Project: att/ast
int b_let(int argc, char *argv[], Shbltin_t *context) {
    int r;
    char *arg;
    Shell_t *shp = context->shp;
    UNUSED(argc);

    while ((r = optget(argv, sh_optlet))) {
        switch (r) {
            case ':': {
                errormsg(SH_DICT, 2, "%s", opt_info.arg);
                break;
            }
            case '?': {
                errormsg(SH_DICT, ERROR_usage(2), "%s", opt_info.arg);
                __builtin_unreachable();
            }
            default: { break; }
        }
    }

    argv += opt_info.index;
    if (error_info.errors || !*argv) {
        errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
        __builtin_unreachable();
    }
    while ((arg = *argv++)) r = !sh_arith(shp, arg);
    return r;
}
Example #4
0
int
Fgenerate_new_buffer_name (void)
{
  char number[2];
  int i = foo ();
  if (i < 0)
    __builtin_unreachable ();
  if (i >= 2)
    __builtin_unreachable ();
  return sprintf (number, "%d", i); /* { dg-bogus "writing" } */
}
Example #5
0
/* { dg-options "-O2" } */
void
g (int a, int b, int c, int d)
{
  if (d)
    {
      ((void)
       (!(a && b && c) ? __builtin_unreachable (), 0 : 0));
    }
  ((void)
   (!(a && b && c) ? __builtin_unreachable (), 0 : 0));
}
Example #6
0
int
bar (int x, long *y)
{
  if (x)
    {
      fn (y[0]);
      v = 1;
      __builtin_unreachable ();
    }
  v = 1;
  __builtin_unreachable ();
}
Example #7
0
static int md5(lua_State *L) {
	size_t len;
	const char *input = lua_tolstring(L, 1, &len);
	if (input == NULL) {
		lua_pushstring(L, "first argument: should be the input string");
		lua_error(L);
		__builtin_unreachable();
	}

	unsigned char digest[MD5_DIGEST_LEN];
	char output[MD5_STRLEN];

	struct md5_ctx ctx;
	md5_begin(&ctx);
	md5_hash(input, len, &ctx);
	md5_end(digest, &ctx);

	// fill the digest bytewise in the output string
	int i;
	for (i = 0; i < MD5_DIGEST_LEN; i++) {
		sprintf(output + 2*i, "%02x", digest[i]);
	}

	lua_pushstring(L, output);
	return 1;
}
Example #8
0
// where should this go...
extern "C" void abort() {
    static void (*libc_abort)() = (void (*)())dlsym(RTLD_NEXT, "abort");

    // In case something calls abort down the line:
    static bool recursive = false;
    if (!recursive) {
        recursive = true;

        fprintf(stderr, "Someone called abort!\n");

        // If we call abort(), things may be seriously wrong.  Set an alarm() to
        // try to handle cases that we would just hang.
        // (Ex if we abort() from a static constructor, and _printStackTrace uses
        // that object, _printStackTrace will hang waiting for the first construction
        // to finish.)
        alarm(1);
        try {
            _printStacktrace();
        } catch (ExcInfo) {
            fprintf(stderr, "error printing stack trace during abort()");
        }

        // Cancel the alarm.
        // This is helpful for when running in a debugger, since the debugger will catch the
        // abort and let you investigate, but the alarm will still come back to kill the program.
        alarm(0);
    }

    libc_abort();
    __builtin_unreachable();
}
Example #9
0
/*
 Loads registers using values in pcb
 @param Process ID
 @param PID
 @return Returns 0 if successful

 */
void load_process_state(pcb* pcb_p)
{
	asm("MOV r0, %0"::"r"(pcb_p->R0):);
	asm("MOV r1, %0"::"r"(pcb_p->R1):);
	asm("MOV r2, %0"::"r"(pcb_p->R2):);
	asm("MOV r3, %0"::"r"(pcb_p->R3):);
	asm("MOV r4, %0"::"r"(pcb_p->R4):);
	asm("MOV r5, %0"::"r"(pcb_p->R5):);
	asm("MOV r6, %0"::"r"(pcb_p->R6):);
	asm("MOV r7, %0"::"r"(pcb_p->R7):);
	asm("MOV r8, %0"::"r"(pcb_p->R8):);
	asm("MOV r9, %0"::"r"(pcb_p->R9):);
	asm("MOV r10, %0"::"r"(pcb_p->R10):);
	//asm("MOV r11, %0"::"r"(11):);
	asm("MOV r12, %0"::"r"(pcb_p->R12):);

	asm("MOV r13, %0"::"r"(pcb_p->R13):);

	asm("MOV r14, %0"::"r"(pcb_p->R14):);
//assert(1==11);

	asm("MOV r15, %0"::"r"(pcb_p->R15):);

	__builtin_unreachable();
}
Example #10
0
void abort(void)
{
	// TODO: Add proper kernel panic.
	printf("\nPANIC!!!!!!!!!!!!!! Abort all stations!\n");
	while ( 1 ) { }
	__builtin_unreachable();
}
Example #11
0
    static inline const char *string_for_property_type(PropertyType type) {
        switch (type) {
            case PropertyType::String:
                return "string";
            case PropertyType::Int:
                return "int";
            case PropertyType::Bool:
                return "bool";
            case PropertyType::Date:
                return "date";
            case PropertyType::Data:
                return "data";
            case PropertyType::Double:
                return "double";
            case PropertyType::Float:
                return "float";
            case PropertyType::Any:
                return "any";
            case PropertyType::Object:
                return "object";
            case PropertyType::Array:
                return "array";
#if __GNUC__
            default:
                __builtin_unreachable();
#endif
        }
    }
Example #12
0
void exit(int status) {
  pthread_mutex_lock(&exit_mutex);
  if (_exit_func) (*_exit_func)();
  _fini();
  syscall_exit(status);
  __builtin_unreachable();
}
Example #13
0
void _start(void)
{
	/* Copy data segment */
	memcpy(&_sdata, &_sidata, &_edata - &_sdata);

	/* Zero BSS segment */
	bzero(&_sbss, &_ebss - &_sbss);

	/* We don't have CCM-SRAM, but why limit ourselves */
	/* bzero(&_sfast, &_efast - &_sfast); */

	/* FPU interrupt handling: lazy save of FP state */
	FPU->FPCCR |= FPU_FPCCR_ASPEN_Msk | FPU_FPCCR_LSPEN_Msk;

	/* Default NaN mode (don't propagate; just make NaN) and 
	 * flush-to-zero handling for subnormals
	 */
	FPU->FPDSCR |= FPU_FPDSCR_DN_Msk | FPU_FPDSCR_FZ_Msk;

	/* Enable the FPU in the coprocessor state register; CP10/11 */
	SCB->CPACR |= 0x00f00000;

	/* Invoke main. */
	asm ("bl	main");
	__builtin_unreachable();
}
Example #14
0
void abort(void)
{
	// TODO: Proper kernel panic
	printf("Kernel Panic: abort()\n");
	while(1) {}
	__builtin_unreachable();
}
Example #15
0
static long sys_exit(int status)
{
  const std::string msg = "Service exited with status " + std::to_string(status) + "\n";
  OS::print(msg.data(), msg.size());
  __arch_poweroff();
  __builtin_unreachable();
}
Example #16
0
void _exit(int status) {
  kprintf("%s",std::string(LINEWIDTH, '=').c_str());
  kprint("\n");
  SYSINFO("service exited with status %i", status);
  default_exit();
  __builtin_unreachable();
}
Example #17
0
void panic_epilogue(const char* why)
{
  // Call custom on panic handler (if present).
  if (panic_handler != nullptr) {
    // Avoid recursion if the panic handler results in panic
    auto final_action = panic_handler;
    panic_handler = nullptr;
    final_action(why);
  }

#if defined(ARCH_x86)
  SMP::global_lock();
  // Signal End-Of-Transmission
  kprint("\x04");
  SMP::global_unlock();

#else
#warning "panic() handler not implemented for selected arch"
#endif

  switch (OS::panic_action())
  {
  case OS::Panic_action::halt:
    while (1) OS::halt();
  case OS::Panic_action::shutdown:
    extern void __arch_poweroff();
    __arch_poweroff();
  case OS::Panic_action::reboot:
  default:
    OS::reboot();
  }

  __builtin_unreachable();
}
Example #18
0
File: misc.c Project: att/ast
int b_eval(int argc, char *argv[], Shbltin_t *context) {
    int r;
    Shell_t *shp = context->shp;
    UNUSED(argc);

    while ((r = optget(argv, sh_opteval))) {
        switch (r) {
            case ':': {
                errormsg(SH_DICT, 2, "%s", opt_info.arg);
                break;
            }
            case '?': {
                errormsg(SH_DICT, ERROR_usage(0), "%s", opt_info.arg);
                return 2;
            }
            default: { break; }
        }
    }

    if (error_info.errors) {
        errormsg(SH_DICT, ERROR_usage(2), "%s", optusage(NULL));
        __builtin_unreachable();
    }
    argv += opt_info.index;
    if (*argv && **argv) {
        sh_offstate(shp, SH_MONITOR);
        sh_eval(shp, sh_sfeval((const char **)argv), 0);
    }
    return shp->exitval;
}
Example #19
0
/**
 * Handle fatal errors
 *
 * @v fmt	Error message format string
 * @v ...	Arguments
 */
void die ( const char *fmt, ... ) {
	EFI_BOOT_SERVICES *bs;
	EFI_RUNTIME_SERVICES *rs;
	va_list args;

	/* Print message */
	va_start ( args, fmt );
	vprintf ( fmt, args );
	va_end ( args );

	/* Reboot or exit as applicable */
	if ( efi_systab ) {

		/* Exit */
		bs = efi_systab->BootServices;
		bs->Exit ( efi_image_handle, EFI_LOAD_ERROR, 0, NULL );
		printf ( "Failed to exit\n" );
		rs = efi_systab->RuntimeServices;
		rs->ResetSystem ( EfiResetWarm, 0, 0, NULL );
		printf ( "Failed to reboot\n" );

	} else {

		/* Wait for keypress */
		printf ( "Press a key to reboot..." );
		getchar();
		printf ( "\n" );

		/* Reboot system */
		reboot();
	}

	/* Should be impossible to reach this */
	__builtin_unreachable();
}
Example #20
0
/*
 * xabort_errno - print a message to stderr, and exit the process.
 * Calling abort() in libc might result other syscalls being called
 * by libc.
 *
 * If error_code is not zero, it is also printed.
 */
void
xabort_errno(int error_code, const char *msg)
{
	static const char main_msg[] = " libsyscall_intercept error\n";

	if (msg != NULL) {
		/* not using libc - inline strlen */
		size_t len = 0;
		while (msg[len] != '\0')
			++len;
		syscall_no_intercept(SYS_write, 2, msg, len);
	}

	if (error_code != 0) {
		char buf[0x10];
		size_t len = 1;
		char *c = buf + sizeof(buf) - 1;

		/* not using libc - inline sprintf */
		do {
			*c-- = error_code % 10;
			++len;
			error_code /= 10;
		} while (error_code != 0);
		*c = ' ';

		syscall_no_intercept(SYS_write, 2, c, len);
	}

	syscall_no_intercept(SYS_write, 2, main_msg, sizeof(main_msg) - 1);
	syscall_no_intercept(SYS_exit_group, 1);

	__builtin_unreachable();
}
Example #21
0
 void N::deleteChildren(N *node) {
     if (N::isLeaf(node)) {
         return;
     }
     switch (node->getType()) {
         case NTypes::N4: {
             auto n = static_cast<N4 *>(node);
             n->deleteChildren();
             return;
         }
         case NTypes::N16: {
             auto n = static_cast<N16 *>(node);
             n->deleteChildren();
             return;
         }
         case NTypes::N48: {
             auto n = static_cast<N48 *>(node);
             n->deleteChildren();
             return;
         }
         case NTypes::N256: {
             auto n = static_cast<N256 *>(node);
             n->deleteChildren();
             return;
         }
     }
     assert(false);
     __builtin_unreachable();
 }
Example #22
0
int pr13910_foo(int x) {
  if (x == 1)
    return 0;
  else
    return x;
  __builtin_unreachable(); // expected no warning
}
Example #23
0
	void __cxa_throw(void *except, __cxa_info_type info, void (*dest)(void *))
	{
		auto rethrow = (void (*)(void*, __cxa_info_type, void(*)(void*)))dlsym(RTLD_NEXT, "__cxa_throw");
		luw_backtrace();
		rethrow(except, info, dest);
		__builtin_unreachable(); // rethrow is noreturn
	}
Example #24
0
File: abort.c Project: shmoe/echos
void abort(void)
{
	// TODO: Add proper kernel panic.
	printf("Popcorn Panic [abort()]: abandon ship!\n");
	while ( 1 ) { }
	__builtin_unreachable();
}
Example #25
0
loadExecReboot(int r0, int r1, int r2, uint32_t hiId, uint32_t loId)
{
	const size_t pathLen = 64;
	wchar_t path[pathLen];
	size_t read;
	P9File f;

	p9FileInit(f);
	swprintf(path, pathLen, L"sdmc:/" FIRM_PATH_FMT, hiId, loId);
	p9Open(f, path, 1);
	p9Read(f, &read, (void *)FIRM_ADDR, FIRM_SIZE);
	p9Close(f);

	p9FileInit(f);
	swprintf(path, pathLen, L"sdmc:/" FIRM_PATCH_PATH_FMT, hiId, loId);
	p9Open(f, path, 1);
	p9Read(f, &read, (void *)PATCH_ADDR, PATCH_SIZE);
	p9Close(f);

	while (p9RecvPxi() != 0x44846);
	svcKernelSetState(SVC_KERNEL_STATE_INIT, hiId, loId,
		SVC_KERNEL_STATE_TITLE_COMPAT);

	if (loId != TID_CTR_NATIVE_FIRM && loId != TID_KTR_NATIVE_FIRM)
		nandSector = 0;

	svcBackdoor((void *)execReboot);
	__builtin_unreachable();
}
Example #26
0
__attribute__((__noreturn__)) void abort(void)
{
	// TODO: add proper kernel panic
	printf("Kernel Panic: aborting!\n");
	while (1) { }
	__builtin_unreachable();
}
Example #27
0
void kernel_main() {
  // enter user mode the first time somewhat manually:
  scheduler_run(0);
  --cpu.nested_isr;
  asm volatile ( "jmp isr_to_usermode" );
  __builtin_unreachable();
}
Example #28
0
static int osrandom_rand_bytes(unsigned char *buffer, int size) {
    int len;
    int res;

    switch(getentropy_works) {
#if defined(__APPLE__)
    case CRYPTOGRAPHY_OSRANDOM_GETENTROPY_FALLBACK:
        return dev_urandom_read(buffer, size);
#endif
    case CRYPTOGRAPHY_OSRANDOM_GETENTROPY_WORKS:
        while (size > 0) {
            /* OpenBSD and macOS restrict maximum buffer size to 256. */
            len = size > 256 ? 256 : size;
            res = getentropy(buffer, (size_t)len);
            if (res < 0) {
                ERR_Cryptography_OSRandom_error(
                    CRYPTOGRAPHY_OSRANDOM_F_RAND_BYTES,
                    CRYPTOGRAPHY_OSRANDOM_R_GETENTROPY_FAILED,
                    __FILE__, __LINE__
                );
                return 0;
            }
            buffer += len;
            size -= len;
        }
        return 1;
    }
    __builtin_unreachable();
}
Example #29
0
static size_t
find_next_power_of_two(size_t number)
{
#if HAVE_BUILTIN_CLZLL
    static const int size_bits = (int)sizeof(number) * CHAR_BIT;

    if (sizeof(size_t) == sizeof(unsigned int)) {
        return 1U << (size_bits - __builtin_clz((unsigned int)number));
    } else if (sizeof(size_t) == sizeof(unsigned long)) {
        return 1UL << (size_bits - __builtin_clzl((unsigned long)number));
    } else if (sizeof(size_t) == sizeof(unsigned long long)) {
        return 1ULL << (size_bits - __builtin_clzll((unsigned long long)number));
    } else {
        __builtin_unreachable();
    }
#else
    number--;
    number |= number >> 1;
    number |= number >> 2;
    number |= number >> 4;
    number |= number >> 8;
    number |= number >> 16;
    return number + 1;
#endif
}
Example #30
0
static void check_bootloader(void) {
    BootloaderKind kind = get_bootloaderKind();

    switch (kind) {
    case BLK_v1_0_0:
    case BLK_v1_0_1:
    case BLK_v1_0_2:
    case BLK_v1_0_3:
    case BLK_v1_0_3_elf:
    case BLK_v1_0_3_sig:
    case BLK_v1_0_4:
#ifndef DEBUG_ON
        update_bootloader();
#endif
        return;
    case BLK_UNKNOWN:
#ifndef DEBUG_ON
        unknown_bootloader();
#endif
        return;
    case BLK_v2_0_0:
    case BLK_v1_1_0:
        return;
    }

#ifdef DEBUG_ON
    __builtin_unreachable();
#else
    unknown_bootloader();
#endif
}