static void ark_get (FILE *ark, const char *ark_name, const char *key) { if (0 != fseek (ark, -11, SEEK_END)) sys_panic (ark_name); long catalog_size; fscanf (ark, "%ld", &catalog_size); // XXX check errors if (catalog_size <= 0) panic ("Bad or empty arkfile"); if (0 != fseek (ark, -11 - catalog_size, SEEK_END)) sys_panic (ark_name); long offset = 0; for (;;) { long size; fscanf (ark, "%ld ", &size); // XXX check errors char key2[1024]; if (!fgets (key2, sizeof key2, ark)) panic ("Key not found"); size_t L = strlen (key2); if (0 < L) key2[L-1] = '\0'; // strip trailing newline if (0 == strcmp (key, key2)) { blast (ark, ark_name, offset, size); return; } offset += size; } }
void assert_fail(const char* file, int line, const char* msg) { (void) console_printf(CPOS(23, 0), 0xC000, "PANIC: %s:%d: assertion '%s' failed\n", file, line, msg); sys_panic(NULL); spinloop: goto spinloop; // should never get here }
static void pwd (void) { char *filename = getcwd (NULL, 0); if (!filename) sys_panic (NULL); must_printf ("%s\n", filename); free (filename); }
/* * Bind capabilities for the known file. */ void bind_cap(char *path, task_t task) { const struct cap_map *map; cap_t cap = 0; int error; /* * Set capabilities to the known applications. */ map = &cap_table[0]; while (map->c_path != NULL) { if (!strncmp(path, map->c_path, PATH_MAX)) { cap = map->c_capset; break; } map++; } if (cap != 0) { DPRINTF(("exec: set capability:%08x to %s\n", cap, path)); error = task_setcap(task, cap); if (error) sys_panic("exec: no SETPCAP capability"); } }
before(); call(void initPrimitiveClasses(...)) { struct benchtime_s bt; u8_t t1, t2, t3; u4_t a, b; u4_t totalmem = 1024 * 1024; benchmem = jxmalloc(totalmem MEMTYPE_PROFILING); bench_empty(&bt); bench_empty(&bt); BMPRINT("empty"); bench_store(&bt); bench_store(&bt); BMPRINT("store/hot"); bench_store1(&bt); bench_store1(&bt); BMPRINT("store1/hot"); FLUSHCACHE; bench_store1(&bt); BMPRINT("store1/cold"); bench_load1(&bt); bench_load1(&bt); BMPRINT("load1/hot"); FLUSHCACHE; bench_load1(&bt); BMPRINT("load1/cold"); sys_panic("END OF BENCHMARK"); }
void __dassert(const char *file, int line, const char *exp) { char buf[128]; sprintf(buf, "assertion \"%s\" failed: file \"%s\", line %d\n", exp, file, line); sys_panic(buf); /* NOTREACHED */ }
int main (int argc, char **argv) { if (3 != argc) panic ("usage: ark-get arkfile key"); FILE *f = fopen (argv[1], "rb"); if (!f) sys_panic (argv[1]); ark_get (f, argv[1], argv[2]); fclose (f); return 0; }
static void blast (FILE *ark, const char *ark_name, long start, long size) { if (0 != fseek (ark, start, SEEK_SET)) sys_panic (ark_name); while (0 < size--) { int c = getc (ark); if (EOF == c) panic ("Premature EOF or I/O error"); putc (c, stdout); } }
void panic(const char *fmt, ...) { char buf[LINE_MAX]; va_list args; va_start(args, fmt); vsprintf(buf, fmt, args); sys_panic(buf); va_end(args); }
void assert_memory(MemoryProxy * x) { u4_t flags = getObjFlags(x); if ((flags & FORWARD_MASK) == GC_FORWARD) return; /* forwarding pointer. do not check */ if ((flags & FLAGS_MASK) != OBJFLAGS_MEMORY) { printf("FLAGS: obj=%p flags=%x flagword=%x\n", x, flags & FLAGS_MASK, flags); sys_panic("no mem flags"); } //if (((struct MemoryProxy_s*)(x))->dz==NULL) sys_panic("no dzmem"); }
void cpuManager_assertInterruptEnabled(ObjectDesc * self) { #ifdef KERNEL ASSERT((getEFlags() & 0x00000200) != 0); #else sigset_t set, oldset; sigemptyset(&set); sigprocmask(SIG_BLOCK, &set, &oldset); if (sigismember(&oldset, SIGALRM)) sys_panic("INTERRUPTS ARE *NOT* ENABLED"); #endif }
void device_register(struct device *dev, const char *name, int flags) { size_t len; void *private = NULL; assert(dev->driver != NULL); /* Check the length of name. */ len = strnlen(name, MAXDEVNAME); if (len == 0 || len >= MAXDEVNAME) return; sched_lock(); /* Check if specified name is already used. */ if (device_lookup(name) != NULL) sys_panic("duplicate device"); /* * Allocate a device and device private data. */ if (dev->driver->devsz != 0) { if ((private = malloc(dev->driver->devsz)) == NULL) sys_panic("devsz"); memset(private, 0, dev->driver->devsz); } strlcpy(dev->name, name, len + 1); dev->flags = flags; dev->active = 1; dev->refcnt = 1; dev->offset = 0; dev->private_data = private; dev->next = device_list; dev->max_io_size = UINT_MAX; device_list = dev; sched_unlock(); }
void gc_compacting_gc(DomainDesc * domain) { #ifdef VERBOSE_GC printf("GARBAGE COLLECTOR started for domain %p (%s)\n", domain, domain->domainName); #endif printf("COMPACTING HEAP %p - %p (%p)\n", GCM_COMPACTING(domain).heap, GCM_COMPACTING(domain).heapTop, GCM_COMPACTING(domain).heapBorder); #if 0 #ifdef KERNEL DISABLE_IRQ; #else #ifdef DEBUG { sigset_t set, oldset; sigemptyset(&set); sigprocmask(SIG_BLOCK, &set, &oldset); if (!sigismember(&oldset, SIGALRM)) sys_panic("signal must be blocked during GC"); } #endif /*DEBUG*/ #endif #endif #ifdef PROFILE_GC pgcNewRun(domain); #endif PGCB(GC); /* * Init */ #ifdef CHECK_HEAPUSAGE # ifdef DBG_GC /* check whether heap is consistent */ printf("Checking Heap..."); if (gc_checkHeap(domain, JNI_FALSE) == JNI_TRUE) printf("OK\n"); else printf("FAILED\n"); # else gc_checkHeap(domain, JNI_FALSE); # endif #endif /*CHECK_HEAPUSAGE */ freezeThreads(domain); IF_DBG_GC( { printf(" Test map...\n"); walkStacks(domain, NULL); // FIXME } );
static void register_process(void) { struct msg m; object_t obj; int error; error = object_lookup("!proc", &obj); if (error) sys_panic("pow: no proc found"); m.hdr.code = PS_REGISTER; msg_send(obj, &m, sizeof(m)); }
void panic(const char* format, ...) { va_list val; va_start(val, format); char buf[160]; memcpy(buf, "PANIC: ", 7); int len = vsnprintf(&buf[7], sizeof(buf) - 7, format, val) + 7; va_end(val); if (len > 0 && buf[len - 1] != '\n') { strcpy(buf + len - (len == (int) sizeof(buf) - 1), "\n"); } (void) console_printf(CPOS(23, 0), 0xC000, "%s", buf); sys_panic(NULL); spinloop: goto spinloop; // should never get here }
void cpuManager_join(ObjectDesc * self, CPUStateProxy * cpuStateProxy) { /*ThreadDesc *cpuState = cpuStateProxy->cpuState; */ ThreadDesc *cpuState = cpuState2thread(cpuStateProxy); #ifdef KERNEL ASSERTTHREAD(cpuState); DISABLE_IRQ; while (cpuState->state != STATE_ZOMBIE) { threadyield(); } RESTORE_IRQ; #else sys_panic("cpuManager_join should not be called"); #endif }
static void pow_init(void) { task_t self; /* * Set default power actions */ pmact.pwrbtn = PWR_OFF; pmact.slpbtn = PWR_SUSPEND; pmact.lcdclose = PWR_SUSPEND; pmact.lowbatt = PWR_OFF; /* * Connect to the pm driver to get all power events. */ if (device_open("pm", 0, &pmdev) != 0) { /* * Bad config... */ sys_panic("pow: no pm driver"); } self = task_self(); device_ioctl(pmdev, PMIOC_CONNECT, &self); /* * Setup exception to receive signals from pm driver. */ exception_setup(exception_handler); /* * Start power thread. */ if (run_thread(power_thread)) sys_panic("pow_init"); }
OT_INTERRUPT void platform_usernmi_isr(void) { static const ot_u8 error_code[] = {0, 11, 2, 7}; /// 11 - segmentation fault (Veelite error) /// 2 - unknown error (Oscillator error) /// 7 - vacant memory access (flash error) /// 10 - bus error (hw bus problem, usually USB timeout) ot_u8 sysuniv_reg; sysuniv_reg = (ot_u8)SYS->UNIV; SYS->UNIV = 0; // Clear all User NMI flags if (sysuniv_reg != 0) { sysuniv_reg >>= 1; sys_panic( error_code[sysuniv_reg] ); }
static void shutdown_server(const char *name) { struct msg m; object_t obj; int error; DPRINTF(("pow: shutdown %s\n", name)); error = object_lookup((char *)name, &obj); if (error != 0) return; m.hdr.code = STD_SHUTDOWN; error = msg_send(obj, &m, sizeof(m)); if (error) sys_panic("pow: shutdown error"); }
jint cpuManager_waitUntilBlocked(ObjectDesc * self, CPUStateProxy * cpuStateProxy) { /* ThreadDesc *cpuState = cpuStateProxy->cpuState; */ ThreadDesc *cpuState = cpuState2thread(cpuStateProxy); #ifdef KERNEL ASSERTTHREAD(cpuState); DISABLE_IRQ; while (cpuState->state != STATE_BLOCKEDUSER) { threadyield(); } /*printf("Thread %p is now BLOCKED\n", cpuState); */ RESTORE_IRQ; #else sys_panic("waituntilblocked should not be called"); #endif }
// only done once per app run void sim_init() { // try and improve our performance a bit setpriority(PRIO_PROCESS, 0, -20); scall("mlockall", mlockall(MCL_CURRENT | MCL_FUTURE)); // check that new polarity scheme didn't break anything assert(WREG_O3_RST == WREG_O3_RST_GOOD); assert(WREG_O2_IDLE == WREG_O2_IDLE_GOOD); assert(WREG_O2_ENA == WREG_O2_ENA_GOOD); assert(WREG_O2_ARM == WREG_O2_ARM_GOOD); bus_init(); pru_start(); bus_pru_gpio_init(); if (!background_mode) { tty = open("/dev/tty", O_RDONLY | O_NONBLOCK); if (tty < 0) sys_panic("open tty"); } }
void APIC_error_interrupt(void) // called from "error_apic" { unsigned long v, v1; v = apic_read(APIC_ESR); apic_write(APIC_ESR, 0); v1 = apic_read(APIC_ESR); ack_APIC_irq(); /* Here is what the APIC error bits mean: 0: Send CS error 1: Receive CS error 2: Send accept error 3: Receive accept error 4: Reserved 5: Send illegal vector 6: Received illegal vector 7: Illegal register address */ printf("APIC error: %02lx(%02lx): \"", v, v1); if (v1 & 0x01) printf("Send CS error"); if (v1 & 0x02) printf("Receive CS error"); if (v1 & 0x04) printf("Send accept error"); if (v1 & 0x08) printf("Receive accept error"); if (v1 & 0x10) printf("Reserved"); if (v1 & 0x20) printf("Send illegal vector"); if (v1 & 0x40) printf("Received illegal vector"); if (v1 & 0x80) printf("Illegal register addres"); printf("\" on CPU%d\n", get_processor_id()); sys_panic("APIC error on CPU%d\n", get_processor_id()); }
/* * device_create - create new device object. * * A device object is created by the device driver to provide * I/O services to applications. Returns device ID on * success, or 0 on failure. */ struct device * device_create(struct driver *drv, const char *name, int flags) { struct device *dev; size_t len; assert(drv != NULL); /* Check the length of name. */ len = strnlen(name, MAXDEVNAME); if (len == 0 || len >= MAXDEVNAME) return NULL; /* * Allocate a device structure. */ if ((dev = malloc(sizeof(*dev))) == NULL) sys_panic("device_create"); dev->driver = drv; device_register(dev, name, flags); return dev; }
/* * Wait until specified server starts. */ static void wait_server(const char *name, object_t *pobj) { int i, error = 0; /* Give chance to run other servers. */ thread_yield(); /* * Wait for server loading. timeout is 1 sec. */ for (i = 0; i < 100; i++) { error = object_lookup((char *)name, pobj); if (error == 0) break; /* Wait 10msec */ timer_sleep(10, 0); thread_yield(); } if (error) sys_panic("pow: server not found"); }
void data_setpath(char *name) { unzFile zip; char *n; if (str_zipext(name)) { /* path has .zip extension */ n = str_slash(str_dup(name)); zip = unzOpen(n); if (!zip) { free(n); sys_panic("(data) can not open data"); } else { path.zip = zip; path.name = n; } } else { /* path has no .zip extension. it should be a directory */ /* FIXME check that it is a valid directory */ path.zip = NULL; path.name = str_dup(name); } }
unique_t alarm_unique(alarm_t a) { if (!a->unique) { sys_panic(("REAL:unique not installed")) ; } return a->unique ; }
static void ipIRQfunc(unsigned int irq) { sys_panic("this should never be called"); }
static void must_rename (const char *from_filename, const char *to_filename) { if (rename (from_filename, to_filename) < 0) sys_panic (NULL); /* TODO: improve on NULL */ }
struct MemoryProxy_s *gc_impl_shallowCopyMemory(u4_t * dst, struct MemoryProxy_s *srcObj) { sys_panic("shallow"); }
MemoryProxyHandle allocReadOnlyMemory(ObjectDesc * self, jint start, jint size) { sys_panic("createRO"); }