提交 63f9d378 编写于 作者: Z Zihao Yu

Merge branch 'jyy-upstream' into 'master'

Jyy upstream

See merge request projectn/nexus-am!43
......@@ -19,3 +19,6 @@ image:
run:
$(BINARY)
gdb:
gdb -ex "handle SIGUSR1 SIGSEGV noprint nostop" $(BINARY)
#define _GNU_SOURCE
#include <sys/mman.h>
#include <sys/auxv.h>
#include <fcntl.h>
#include <elf.h>
#include <stdlib.h>
#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,16 +56,14 @@ 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));
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,
......@@ -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);
}
......
......@@ -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 {
......
......@@ -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;
}
}
......
......@@ -51,7 +51,6 @@ struct cpu_local {
TSS32 tss;
#endif
struct kernel_stack stack;
struct kernel_stack irq_stack;
};
#if __x86_64__
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册