From 12cae0948a42a79a62c2e38f84955ea5a94fd1de Mon Sep 17 00:00:00 2001 From: Yanyan Jiang Date: Wed, 4 Mar 2020 15:51:55 +0800 Subject: [PATCH 1/4] x86-qemu: remove unused irq_stack in cpu-local struct --- am/src/x86/qemu/x86-qemu.h | 1 - 1 file changed, 1 deletion(-) diff --git a/am/src/x86/qemu/x86-qemu.h b/am/src/x86/qemu/x86-qemu.h index 4b39a25a..28d2937d 100644 --- a/am/src/x86/qemu/x86-qemu.h +++ b/am/src/x86/qemu/x86-qemu.h @@ -51,7 +51,6 @@ struct cpu_local { TSS32 tss; #endif struct kernel_stack stack; - struct kernel_stack irq_stack; }; #if __x86_64__ From 853cdee5085764b0e66915551cddac85e926b1f2 Mon Sep 17 00:00:00 2001 From: Zihao Yu Date: Sun, 15 Mar 2020 16:00:25 +0800 Subject: [PATCH 2/4] native,platform: fix wrong assert --- am/src/native/platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/am/src/native/platform.c b/am/src/native/platform.c index bae0a253..302a2930 100644 --- a/am/src/native/platform.c +++ b/am/src/native/platform.c @@ -66,7 +66,7 @@ static void init_platform() { pmem = mmap(PMEM_START, PMEM_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_SHARED | MAP_FIXED, pmem_fd, 0); - assert(_heap.start != (void *)-1); + assert(pmem != (void *)-1); // allocate private per-cpu structure thiscpu = mmap(NULL, sizeof(*thiscpu), PROT_READ | PROT_WRITE, From 803669810082421b873a286aff78d1b91f9e58a8 Mon Sep 17 00:00:00 2001 From: Zihao Yu Date: Sun, 15 Mar 2020 17:04:41 +0800 Subject: [PATCH 3/4] native,platform: use memfd_create() instead of shm_open() * memfd_create() is automatically released by the kernel, and it does not create any files on the filesystem --- am/src/native/platform.c | 16 +++++----------- am/src/native/platform.h | 4 ++-- am/src/native/vme.c | 6 +++--- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/am/src/native/platform.c b/am/src/native/platform.c index 302a2930..710b09ed 100644 --- a/am/src/native/platform.c +++ b/am/src/native/platform.c @@ -1,6 +1,6 @@ +#define _GNU_SOURCE #include #include -#include #include #include #include "platform.h" @@ -10,7 +10,6 @@ #define PMEM_START (void *)0x3000000 // for nanos-lite with vme disabled #define PMEM_SIZE (128 * 1024 * 1024) // 128MB static int pmem_fd = 0; -static char pmem_shm_file[] = "/native-pmem-XXXXXX"; static void *pmem = NULL; static ucontext_t uc_example = {}; static int sys_pgsz; @@ -57,10 +56,8 @@ int main(const char *args); static void init_platform() __attribute__((constructor)); static void init_platform() { - // create shared memory object and set up mapping to simulate the physical memory - assert(access("/", W_OK) != 0); - assert(mkstemp(pmem_shm_file) < 0); - pmem_fd = shm_open(pmem_shm_file, O_RDWR | O_CREAT | O_EXCL, 0700); + // create memory object and set up mapping to simulate the physical memory + pmem_fd = memfd_create("pmem", 0); assert(pmem_fd != -1); assert(0 == ftruncate(pmem_fd, PMEM_SIZE)); @@ -159,16 +156,13 @@ static void init_platform() { } void __am_exit_platform(int code) { - int ret = shm_unlink(pmem_shm_file); - printf("Unlink pmem_shm_file %s\n", (ret == 0 ? "successfully" : "fail")); - // let Linux clean up other resource extern int __am_mpe_init; if (__am_mpe_init && _ncpu() > 1) kill(0, SIGKILL); exit(code); } -void __am_shm_mmap(void *va, void *pa, int prot) { +void __am_pmem_map(void *va, void *pa, int prot) { // translate AM prot to mmap prot int mmap_prot = PROT_NONE; // we do not support executable bit, so mark @@ -180,7 +174,7 @@ void __am_shm_mmap(void *va, void *pa, int prot) { assert(ret != (void *)-1); } -void __am_shm_munmap(void *va) { +void __am_pmem_unmap(void *va) { int ret = munmap(va, __am_pgsize); assert(ret == 0); } diff --git a/am/src/native/platform.h b/am/src/native/platform.h index d6692179..03b1eda7 100644 --- a/am/src/native/platform.h +++ b/am/src/native/platform.h @@ -11,8 +11,8 @@ void __am_get_example_uc(_Context *r); void __am_get_intr_sigmask(sigset_t *s); int __am_is_sigmask_sti(sigset_t *s); void __am_init_timer_irq(); -void __am_shm_mmap(void *va, void *pa, int prot); -void __am_shm_munmap(void *va); +void __am_pmem_map(void *va, void *pa, int prot); +void __am_pmem_unmap(void *va); // per-cpu structure typedef struct { diff --git a/am/src/native/vme.c b/am/src/native/vme.c index 656e3104..11dca889 100644 --- a/am/src/native/vme.c +++ b/am/src/native/vme.c @@ -46,7 +46,7 @@ void __am_switch(_Context *c) { // munmap all mappings list_foreach(pp, thiscpu->vm_head) { if (pp->is_mapped) { - __am_shm_munmap(pp->va); + __am_pmem_unmap(pp->va); pp->is_mapped = false; } } @@ -56,7 +56,7 @@ void __am_switch(_Context *c) { // mmap all mappings list_foreach(pp, head) { assert(IN_RANGE(pp->va, USER_SPACE)); - __am_shm_mmap(pp->va, pp->pa, pp->prot); + __am_pmem_map(pp->va, pp->pa, pp->prot); pp->is_mapped = true; } } @@ -90,7 +90,7 @@ void _map(_AddressSpace *as, void *va, void *pa, int prot) { if (vm_head == thiscpu->vm_head) { // enforce the map immediately - __am_shm_mmap(pp->va, pp->pa, pp->prot); + __am_pmem_map(pp->va, pp->pa, pp->prot); pp->is_mapped = true; } } From e548ff32512082a5be4cb893d59d91f3142fc4f7 Mon Sep 17 00:00:00 2001 From: Zihao Yu Date: Sun, 15 Mar 2020 17:41:56 +0800 Subject: [PATCH 4/4] am,arch,native: add rule for gdb --- am/arch/native.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/am/arch/native.mk b/am/arch/native.mk index 46732ac3..a8b0d2f1 100644 --- a/am/arch/native.mk +++ b/am/arch/native.mk @@ -18,3 +18,6 @@ image: run: $(BINARY) + +gdb: + gdb -ex "handle SIGUSR1 SIGSEGV noprint nostop" $(BINARY)