diff options
| -rwxr-xr-x | arch/riscv64/conf/init | bin | 4008 -> 3960 bytes | |||
| -rw-r--r-- | arch/riscv64/conf/initrd | bin | 4608 -> 4608 bytes | |||
| -rw-r--r-- | arch/riscv64/kernel/smp.c | 2 | ||||
| -rw-r--r-- | arch/riscv64/kernel/vmem.c | 5 | ||||
| -rw-r--r-- | include/kmi/assert.h | 46 | ||||
| -rw-r--r-- | include/libfdt.h | 4 | ||||
| -rw-r--r-- | src/dmem.c | 4 | ||||
| -rw-r--r-- | src/elf.c | 2 | ||||
| -rw-r--r-- | src/initrd.c | 4 | ||||
| -rw-r--r-- | src/irq.c | 2 | ||||
| -rw-r--r-- | src/orphanage.c | 4 | ||||
| -rw-r--r-- | src/pmem.c | 8 | ||||
| -rw-r--r-- | src/proc.c | 2 | ||||
| -rw-r--r-- | src/regions.c | 4 | ||||
| -rw-r--r-- | src/tcb.c | 20 | ||||
| -rw-r--r-- | src/vmem.c | 10 |
16 files changed, 42 insertions, 75 deletions
diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init Binary files differindex 567ff43..5b06586 100755 --- a/arch/riscv64/conf/init +++ b/arch/riscv64/conf/init diff --git a/arch/riscv64/conf/initrd b/arch/riscv64/conf/initrd Binary files differindex e331c21..a792456 100644 --- a/arch/riscv64/conf/initrd +++ b/arch/riscv64/conf/initrd diff --git a/arch/riscv64/kernel/smp.c b/arch/riscv64/kernel/smp.c index a878b90..e48a216 100644 --- a/arch/riscv64/kernel/smp.c +++ b/arch/riscv64/kernel/smp.c @@ -86,7 +86,7 @@ void smp_bringup(struct vmem *b, void *fdt) if (r.value == SBI_HART_STARTED) { /* there should ever only be one started hart */ - catastrophic_assert(cpuid_to_hartid(0) == -1); + assert(cpuid_to_hartid(0) == -1); cpuid_to_hartid(0) = hartid; continue; } diff --git a/arch/riscv64/kernel/vmem.c b/arch/riscv64/kernel/vmem.c index 68869a3..b97082f 100644 --- a/arch/riscv64/kernel/vmem.c +++ b/arch/riscv64/kernel/vmem.c @@ -436,6 +436,7 @@ struct vmem *init_mapping() struct vmem *init_vmem(void *fdt) { UNUSED(fdt); + struct vmem *b = create_vmem(); __populate_dmap(b); /* update which memory branch to use */ @@ -597,7 +598,7 @@ void mark_rpc_invalid(struct tcb *t, vm_t top) struct vmem *b = t->arch.rpc_leaf; int top_idx = t->arch.rpc_idx; int bottom_idx = (top - RPC_STACK_BASE) / BASE_PAGE_SIZE; - catastrophic_assert(bottom_idx < top_idx); + assert(bottom_idx < top_idx); while (top_idx != bottom_idx) { pm_t *pte = (pm_t *)&b->leaf[top_idx]; @@ -614,7 +615,7 @@ void mark_rpc_valid(struct tcb *t, vm_t bottom) struct vmem *b = t->arch.rpc_leaf; int bottom_idx = t->arch.rpc_idx; int top_idx = (bottom - RPC_STACK_BASE) / BASE_PAGE_SIZE; - catastrophic_assert(bottom_idx < top_idx); + assert(bottom_idx < top_idx); while (top_idx != bottom_idx) { pm_t *pte = (pm_t *)&b->leaf[bottom_idx]; diff --git a/include/kmi/assert.h b/include/kmi/assert.h index 291f15f..3120edc 100644 --- a/include/kmi/assert.h +++ b/include/kmi/assert.h @@ -30,57 +30,17 @@ * * @param x Condition to check for. */ -#define catastrophic_assert(x) \ +#define assert(x) \ do { \ if (unlikely(!(x))) { \ - error("catastrophic assertion failed: " QUOTE(x) "\n"); \ + error("assertion failed: " QUOTE(x) "\n"); \ while (1) { \ } \ } \ } while (0); -/** - * The function cannot continue without this assertion, but doesn't necessarily - * mean that the kernel is borked. - * - * @warning Implicit return. - * - * @param x Condition to check for. - * @param r Return value on failed check. - */ -#define hard_assert(x, r) \ - { \ - if (unlikely(!(x))) { \ - warn("hard assertion failed: " QUOTE(x) "\n"); \ - return r; \ - } \ - } - -/** - * Unexpected case, but not likely to cause problems, likely a bug. - * - * @param x Condition to check for. - */ -#define soft_assert(x) \ - do { \ - if (unlikely(!(x))) { \ - info("soft assertion failed: " QUOTE(x) "\n"); \ - } \ - } while (0); #else -#define catastrophic_assert(x) -#define hard_assert(x, r) -#define soft_assert(x) +#define assert(x) #endif -/** - * Use when return value doesn't exist. - * - * Example: - * @code{.c} - * void func() { hard_assert(x, RETURN_VOID); } - * @endcode - */ -#define RETURN_VOID - #endif /* KMI_ASSERT_H */ diff --git a/include/libfdt.h b/include/libfdt.h index c1d6a4e..e9eb905 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -99,7 +99,7 @@ void __dbg_fdt(const void *fdt, int node_offset, int depth); static inline fdt64_t fdt_load_reg_addr(struct cell_info ci, const void *p, size_t i) { - catastrophic_assert(ci.addr_cells == 2 || ci.addr_cells == 1); + assert(ci.addr_cells == 2 || ci.addr_cells == 1); size_t offset = i * (ci.addr_cells + ci.size_cells) * sizeof(fdt32_t); char *addr = ((char *)p) + 0; return fdt_load_int_ptr(ci.addr_cells, addr + offset); @@ -116,7 +116,7 @@ static inline fdt64_t fdt_load_reg_addr(struct cell_info ci, const void *p, static inline fdt64_t fdt_load_reg_size(struct cell_info ci, const void *p, size_t i) { - hard_assert(ci.size_cells == 2 || ci.size_cells == 1, 0); + assert(ci.size_cells == 2 || ci.size_cells == 1); size_t offset = i * (ci.addr_cells + ci.size_cells) * sizeof(fdt32_t); char *addr = ((char *)p) + ci.addr_cells * sizeof(fdt32_t); return fdt_load_int_ptr(ci.size_cells, addr + offset); @@ -48,7 +48,7 @@ static struct mem_region_root *__select_region(pm_t addr) vm_t alloc_devmem(struct tcb *t, pm_t start, size_t bytes, vmflags_t flags) { - hard_assert(t && is_proc(t), ERR_INVAL); + assert(t && is_proc(t)); struct mem_region_root *region = __select_region(start); if (!region) @@ -69,7 +69,7 @@ vm_t alloc_devmem(struct tcb *t, pm_t start, size_t bytes, vmflags_t flags) stat_t free_devmem(struct tcb *t, vm_t start) { - hard_assert(t && is_proc(t), ERR_INVAL); + assert(t && is_proc(t)); pm_t addr = 0; stat_vpage(t->proc.vmem, start, &addr, NULL, NULL); @@ -46,7 +46,7 @@ static uint8_t __elf_to_uvflags(uint8_t elf_flags) static void __map_exec(struct tcb *t, vm_t bin, uint8_t ei_c, vm_t phstart, size_t phnum, size_t phsize) { - hard_assert(t && is_proc(t), RETURN_VOID); + assert(t && is_proc(t)); /** \todo take alignment into consideration? */ /** \todo take overlapping memory regions into account, probably mostly diff --git a/src/initrd.c b/src/initrd.c index 242e373..489d6f5 100644 --- a/src/initrd.c +++ b/src/initrd.c @@ -120,7 +120,7 @@ pm_t get_initrdtop(const void *fdt) void *initrd_end_ptr = (void *)fdt_getprop(fdt, chosen_offset, "linux,initrd-end", &len); - catastrophic_assert(initrd_end_ptr); + assert(initrd_end_ptr); return (pm_t)fdt_load_int_ptr(len / 4, initrd_end_ptr); } @@ -132,7 +132,7 @@ pm_t get_initrdbase(const void *fdt) void *initrd_base_ptr = (void *)fdt_getprop(fdt, chosen_offset, "linux,initrd-start", &len); - catastrophic_assert(initrd_base_ptr); + assert(initrd_base_ptr); return (pm_t)fdt_load_int_ptr(len / 4, initrd_base_ptr); } @@ -55,7 +55,7 @@ stat_t unregister_irq(struct tcb *t, irq_t id) void handle_irq() { irq_t id = get_irq(); - hard_assert(id < max_irq, RETURN_VOID); + assert(id < max_irq); id_t tid = irq_map[id]; diff --git a/src/orphanage.c b/src/orphanage.c index 9da6f8b..e613e8b 100644 --- a/src/orphanage.c +++ b/src/orphanage.c @@ -24,7 +24,7 @@ void orphanize(struct tcb *t) void unorphanize(struct tcb *t) { - catastrophic_assert(!is_rpc(t)); + assert(!is_rpc(t)); /* attach to init process */ struct tcb *init = get_tcb(1); @@ -43,7 +43,7 @@ void unorphanize(struct tcb *t) clear_bits(t->state, TCB_ORPHAN); - catastrophic_assert(init->callback); + assert(init->callback); set_args3(t, 0, SYS_USER_ORPHANED, t->tid); set_return(t, init->callback); t->callback = init->callback; @@ -564,7 +564,7 @@ static size_t build_reserved_map(size_t exists, struct avoid_region avoid[64], pm_t size = (pm_t)fdt_load_reg_size(ci, rmem_reg, 0); avoid[exists++] = (struct avoid_region){(pm_t)__va(base), size}; - catastrophic_assert(exists < 64); + assert(exists < 64); } return exists; @@ -636,10 +636,14 @@ void init_pmem(void *fdt, uintptr_t load_addr) info("found initrd at [%lx - %lx]\n", initrd_base, initrd_base + initrd_size); + assert(is_aligned(initrd_base, BASE_PAGE_SIZE)); + pm_t fdt_base = (pm_t)fdt; pm_t fdt_size = fdt_totalsize(fdt); info("found fdt at [%lx - %lx]\n", fdt_base, fdt_base + fdt_size); + assert(is_aligned(fdt_base, BASE_PAGE_SIZE)); + /* find probably most suitable contiguous region of ram for our physical * ram map */ @@ -661,7 +665,7 @@ void init_pmem(void *fdt, uintptr_t load_addr) pm_t pmap_base = select_base(ram_base, ram_size, probe_size, avoid_count, avoid); - catastrophic_assert(pmap_base); + assert(pmap_base); info("choosing to place pmem map at %lx\n", pmap_base); size_t actual_size = populate_pmap(ram_base, ram_size, pmap_base); @@ -18,6 +18,8 @@ #include <libfdt.h> +static vm_t entry; + stat_t prepare_proc(struct tcb *t, vm_t bin, vm_t interp) { vm_t entry = load_elf(t, bin, interp); diff --git a/src/regions.c b/src/regions.c index f098f4f..60cab23 100644 --- a/src/regions.c +++ b/src/regions.c @@ -664,7 +664,7 @@ stat_t clone_region(struct vmem *b, struct vmem *g, vm_t from, vm_t to, align_region(from, bytes, &from, &from_size); align_region(to, bytes, &to, &to_size); - catastrophic_assert(from_size == to_size); + assert(from_size == to_size); bytes = from_size; while (bytes) { @@ -694,7 +694,7 @@ stat_t copy_region(struct vmem *b, struct vmem *g, vm_t from, vm_t to, align_region(from, bytes, &from, &from_size); align_region(to, bytes, &to, &to_size); - catastrophic_assert(from_size == to_size); + assert(from_size == to_size); bytes = from_size; while (bytes) { @@ -47,7 +47,7 @@ void init_tcbs() * something smaller but this is fine for now. */ tcbs = (struct tcb **)alloc_page(MM_O1); num_tids = order_size(MM_O1) / sizeof(struct tcb *); - catastrophic_assert(is_powerof2(num_tids)); + assert(is_powerof2(num_tids)); memset(tcbs, 0, order_size(MM_O1)); } @@ -186,7 +186,7 @@ static stat_t __copy_proc(struct tcb *p, struct tcb *n) struct tcb *create_proc(struct tcb *p) { - hard_assert(tcbs, 0); + assert(tcbs); /* create a new thread outside the current process */ struct tcb *n = create_thread(NULL); @@ -207,7 +207,7 @@ struct tcb *create_proc(struct tcb *p) */ static stat_t __destroy_thread_data(struct tcb *t) { - catastrophic_assert(t->refcount == 0); + assert(t->refcount == 0); /* remove ourselves from the thread pool */ /** @todo this should be at the top of the function, and be wrapped in @@ -231,8 +231,8 @@ static stat_t __destroy_thread_data(struct tcb *t) stat_t destroy_thread(struct tcb *t) { - hard_assert(tcbs, ERR_NOINIT); - hard_assert(!is_proc(t), ERR_INVAL); + assert(tcbs); + assert(!is_proc(t)); /* mark us as zombies */ set_bits(t->state, TCB_ZOMBIE); @@ -265,8 +265,8 @@ stat_t destroy_thread(struct tcb *t) stat_t destroy_proc(struct tcb *p) { - hard_assert(tcbs, ERR_NOINIT); - hard_assert(is_proc(p), ERR_INVAL); + assert(tcbs); + assert(is_proc(p)); /** @todo currently we don't care who else is in the address space when * we start freeing stuff, one fairly simple way to deal with this is to @@ -291,7 +291,7 @@ void reference_proc(struct tcb *p) if (!p) return; - hard_assert(is_proc(p), RETURN_VOID); + assert(is_proc(p)); p->refcount++; } @@ -300,7 +300,7 @@ void unreference_proc(struct tcb *p) if (!p) return; - hard_assert(is_proc(p), RETURN_VOID); + assert(is_proc(p)); p->refcount--; if (zombie(p) && p->refcount == 0) { dbg("thread %ld is completely destroyed\n", (long)p->tid); @@ -342,7 +342,7 @@ void use_tcb(struct tcb *t) struct tcb *get_tcb(id_t tid) { - hard_assert(tcbs, 0); + assert(tcbs); if (tid <= 0) return NULL; @@ -40,7 +40,7 @@ static stat_t __copy_mapped_region(struct tcb *d, struct tcb *s, size_t size = end - start; vm_t v = alloc_fixed_region(&d->uvmem.region, start, size, &size, m->flags); - catastrophic_assert(v == start); + assert(v == start); /* note that we use uvmem.vmem instead of proc.vmem, this is just to * make sure that zombies don't eat our brains */ @@ -77,7 +77,7 @@ static stat_t __copy_shared_region(struct tcb *d, struct mem_region *m) vm_t v = alloc_fixed_region(&d->uvmem.region, start, size, &size, m->flags); - catastrophic_assert(v == start); + assert(v == start); stat_t res = clone_region(d->uvmem.vmem, s->uvmem.vmem, start, v, size, m->flags); if (res == OK) @@ -240,7 +240,7 @@ stat_t copy_uvmem(struct tcb *d, struct tcb *s) vm_t alloc_uvmem(struct tcb *t, size_t size, vmflags_t flags) { /* t exists and is the process tcb of the current process */ - hard_assert(t && is_proc(t), ERR_INVAL); + assert(t && is_proc(t)); const vm_t v = alloc_region(&t->uvmem.region, size, &size, flags); if (map_region(t->proc.vmem, v, size, max_order(), flags)) { @@ -254,7 +254,7 @@ vm_t alloc_uvmem(struct tcb *t, size_t size, vmflags_t flags) vm_t alloc_fixed_uvmem(struct tcb *t, vm_t start, size_t size, vmflags_t flags) { - hard_assert(t && is_proc(t), ERR_INVAL); + assert(t && is_proc(t)); const vm_t v = alloc_fixed_region(&t->uvmem.region, start, size, &size, flags); @@ -282,7 +282,7 @@ vm_t map_fixed_uvmem(struct tcb *t, pm_t start, size_t size, vmflags_t flags) /* free_shared_uvmem shouldn't be needed, likely to work with free_uvmem */ vm_t alloc_shared_uvmem(struct tcb *s, size_t size, vmflags_t flags) { - hard_assert(s && is_proc(s), ERR_INVAL); + assert(s && is_proc(s)); const vm_t v = alloc_region(&s->uvmem.region, size, &size, MR_SHARED | flags); /* use base pages to make clone more likely to succeed */ |
