提交 28a306e9 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

Merge branch 'scale-amd64' of git+ssh://amsterdam.csail.mit.edu/home/am0/6.828/xv6 into scale-amd64

...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "mtrace.h" #include "mtrace.h"
#include "pthread.h" #include "pthread.h"
#include <sys/mman.h>
static int cpu; static int cpu;
static pthread_barrier_t bar; static pthread_barrier_t bar;
enum { ncore = 8 }; enum { ncore = 8 };
...@@ -27,11 +29,11 @@ vmsharing(void* arg) ...@@ -27,11 +29,11 @@ vmsharing(void* arg)
u64 i = (u64) arg; u64 i = (u64) arg;
volatile char *p = (char*)(0x40000UL + i * 4096); volatile char *p = (char*)(0x40000UL + i * 4096);
if (map((void *) p, 4096) < 0) if (mmap((void *) p, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) < 0)
die("map failed"); die("mmap failed");
if (unmap((void *) p, 4096) < 0) if (munmap((void *) p, 4096) < 0)
die("unmap failed"); die("munmap failed");
return 0; return 0;
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "mtrace.h" #include "mtrace.h"
#include "pthread.h" #include "pthread.h"
#include <sys/mman.h>
enum { readaccess = 1 }; enum { readaccess = 1 };
enum { verbose = 0 }; enum { verbose = 0 };
enum { npg = 1 }; enum { npg = 1 };
...@@ -33,7 +35,8 @@ thr(void *arg) ...@@ -33,7 +35,8 @@ thr(void *arg)
fprintf(1, "%d: %d ops\n", tid, i); fprintf(1, "%d: %d ops\n", tid, i);
volatile char *p = (char*) (0x100000000UL + tid * npg * 0x100000); volatile char *p = (char*) (0x100000000UL + tid * npg * 0x100000);
if (map((void *) p, npg * 4096) < 0) { if (mmap((void *) p, npg * 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED) {
fprintf(1, "%d: map failed\n", tid); fprintf(1, "%d: map failed\n", tid);
exit(); exit();
} }
...@@ -43,7 +46,7 @@ thr(void *arg) ...@@ -43,7 +46,7 @@ thr(void *arg)
p[j] = '\0'; p[j] = '\0';
} }
if (unmap((void *) p, npg * 4096) < 0) { if (munmap((void *) p, npg * 4096) < 0) {
fprintf(1, "%d: unmap failed\n", tid); fprintf(1, "%d: unmap failed\n", tid);
exit(); exit();
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "uspinlock.h" #include "uspinlock.h"
#include "pthread.h" #include "pthread.h"
#include <sys/mman.h>
static volatile char *p; static volatile char *p;
static struct uspinlock l; static struct uspinlock l;
static volatile int state; static volatile int state;
...@@ -50,7 +52,8 @@ int ...@@ -50,7 +52,8 @@ int
main(void) main(void)
{ {
p = (char *) 0x80000; p = (char *) 0x80000;
if (map((void *) p, 8192) < 0) { if (mmap((void *) p, 8192, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) < 0) {
fprintf(1, "map failed\n"); fprintf(1, "map failed\n");
exit(); exit();
} }
...@@ -73,7 +76,7 @@ main(void) ...@@ -73,7 +76,7 @@ main(void)
fprintf(1, "shm ok\n"); fprintf(1, "shm ok\n");
if (unmap((void *) p, 8192) < 0) { if (munmap((void *) p, 8192) < 0) {
fprintf(1, "unmap failed\n"); fprintf(1, "unmap failed\n");
exit(); exit();
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "traps.h" #include "traps.h"
#include "pthread.h" #include "pthread.h"
#include <sys/mman.h>
char buf[2048]; char buf[2048];
char name[3]; char name[3];
const char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 }; const char *echoargv[] = { "echo", "ALL", "TESTS", "PASSED", 0 };
...@@ -1712,24 +1714,26 @@ unmappedtest(void) ...@@ -1712,24 +1714,26 @@ unmappedtest(void)
printf("unmappedtest\n"); printf("unmappedtest\n");
for (int i = 1; i <= 8; i++) { for (int i = 1; i <= 8; i++) {
int r = map((void*)off, i*4096); void *p = mmap((void*)off, i*4096, PROT_READ|PROT_WRITE,
if (r < 0) MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED)
die("unmappedtest: map failed"); die("unmappedtest: map failed");
off += (i*2*4096); off += (i*2*4096);
} }
for (int i = 8; i >= 1; i--) { for (int i = 8; i >= 1; i--) {
long r = map(0, i*4096); void *p = mmap(0, i*4096, PROT_READ|PROT_WRITE,
if (r < 0) MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED)
die("unmappedtest: map failed"); die("unmappedtest: map failed");
r = unmap((void*)r, i*4096); int r = munmap(p, i*4096);
if (r < 0) if (r < 0)
die("unmappedtest: unmap failed"); die("unmappedtest: unmap failed");
} }
off = 0x1000; off = 0x1000;
for (int i = 1; i <= 8; i++) { for (int i = 1; i <= 8; i++) {
int r = unmap((void*)off, i*4096); int r = munmap((void*)off, i*4096);
if (r < 0) if (r < 0)
die("unmappedtest: unmap failed"); die("unmappedtest: unmap failed");
off += (i*2*4096); off += (i*2*4096);
......
...@@ -26,6 +26,7 @@ struct cpu { ...@@ -26,6 +26,7 @@ struct cpu {
struct cpu *cpu; struct cpu *cpu;
struct proc *proc; // The currently-running process. struct proc *proc; // The currently-running process.
struct kmem *kmem; // The per-core memory table struct kmem *kmem; // The per-core memory table
u64 syscallno; // Temporary used by sysentry
} __mpalign__; } __mpalign__;
extern struct cpu cpus[NCPU]; extern struct cpu cpus[NCPU];
......
...@@ -26,4 +26,4 @@ void threadhelper(void (*fn)(void *), void *arg); ...@@ -26,4 +26,4 @@ void threadhelper(void (*fn)(void *), void *arg);
struct trapframe; struct trapframe;
void trap(struct trapframe *tf); void trap(struct trapframe *tf);
void sysentry(void); void sysentry(void);
u64 sysentry_c(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num); u64 sysentry_c(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 num);
...@@ -217,7 +217,7 @@ int fetchint64(uptr, u64*); ...@@ -217,7 +217,7 @@ int fetchint64(uptr, u64*);
int fetchstr(char*, const char*, u64); int fetchstr(char*, const char*, u64);
int fetchmem(void*, const void*, u64); int fetchmem(void*, const void*, u64);
int putmem(void*, const void*, u64); int putmem(void*, const void*, u64);
u64 syscall(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num); u64 syscall(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 num);
// string.c // string.c
extern "C" int memcmp(const void*, const void*, size_t); extern "C" int memcmp(const void*, const void*, size_t);
......
...@@ -64,12 +64,18 @@ static inline void mtresume(struct proc *p) ...@@ -64,12 +64,18 @@ static inline void mtresume(struct proc *p)
#define mtrec() mtrace_call_set(1, ~0ull) #define mtrec() mtrace_call_set(1, ~0ull)
#define mtign() mtrace_call_set(0, ~0ull) #define mtign() mtrace_call_set(0, ~0ull)
static inline void mtreadavar(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
static inline void mtwriteavar(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
class mt_ascope class mt_ascope
{ {
char name[64]; char name[64];
bool active; bool active;
public: public:
explicit mt_ascope(const char *fmt, ...) explicit mt_ascope(const char *fmt, ...)
__attribute__((format(printf, 2, 3)))
{ {
va_list ap; va_list ap;
...@@ -96,6 +102,7 @@ public: ...@@ -96,6 +102,7 @@ public:
{ {
vsnprintf(name, sizeof(name) - 1, fmt, ap); vsnprintf(name, sizeof(name) - 1, fmt, ap);
mtrace_ascope_register(0, name); mtrace_ascope_register(0, name);
mtwriteavar("kstack:%p", myproc()->kstack);
active = true; active = true;
} }
......
...@@ -175,7 +175,7 @@ futexwait(futexkey_t key, u64 val, u64 timer) ...@@ -175,7 +175,7 @@ futexwait(futexkey_t key, u64 val, u64 timer)
futexaddr* fa; futexaddr* fa;
mtreadavar("futex:ns:%lx", key); mtreadavar("futex:ns:%p", key);
{ {
scoped_gc_epoch gc; scoped_gc_epoch gc;
again: again:
...@@ -190,7 +190,7 @@ futexwait(futexkey_t key, u64 val, u64 timer) ...@@ -190,7 +190,7 @@ futexwait(futexkey_t key, u64 val, u64 timer)
fa->dec(); fa->dec();
goto again; goto again;
} }
mtwriteavar("futex:ns:%lx", key); mtwriteavar("futex:ns:%p", key);
fa->inserted_ = true; fa->inserted_ = true;
} else { } else {
if (!fa->tryinc()) { if (!fa->tryinc()) {
...@@ -199,7 +199,7 @@ futexwait(futexkey_t key, u64 val, u64 timer) ...@@ -199,7 +199,7 @@ futexwait(futexkey_t key, u64 val, u64 timer)
} }
} }
assert(fa->key_ == key); assert(fa->key_ == key);
mtwriteavar("futex:%lx.%p", key, fa); mtwriteavar("futex:%p.%p", key, fa);
acquire(&myproc()->futex_lock); acquire(&myproc()->futex_lock);
auto cleanup = scoped_cleanup([&fa](){ auto cleanup = scoped_cleanup([&fa](){
...@@ -237,7 +237,7 @@ futexwake(futexkey_t key, u64 nwake) ...@@ -237,7 +237,7 @@ futexwake(futexkey_t key, u64 nwake)
if (nwake == 0) if (nwake == 0)
return -1; return -1;
mtreadavar("futex:ns:%lx", key); mtreadavar("futex:ns:%p", key);
{ {
scoped_gc_epoch gc; scoped_gc_epoch gc;
fa = nsfutex->lookup(key); fa = nsfutex->lookup(key);
...@@ -248,7 +248,7 @@ futexwake(futexkey_t key, u64 nwake) ...@@ -248,7 +248,7 @@ futexwake(futexkey_t key, u64 nwake)
auto cleanup = scoped_cleanup([&fa](){ auto cleanup = scoped_cleanup([&fa](){
fa->dec(); fa->dec();
}); });
mtwriteavar("futex:%lx.%p", key, fa); mtwriteavar("futex:%p.%p", key, fa);
fa->nspid_->enumerate([&nwoke, &nwake](u32 pid, proc* p) { fa->nspid_->enumerate([&nwoke, &nwake](u32 pid, proc* p) {
acquire(&p->futex_lock); acquire(&p->futex_lock);
......
...@@ -79,14 +79,12 @@ argcheckptr(const void *p, int size) ...@@ -79,14 +79,12 @@ argcheckptr(const void *p, int size)
return 0; return 0;
} }
extern u64 (*syscalls[])(u64, u64, u64, u64, u64); extern u64 (*syscalls[])(u64, u64, u64, u64, u64, u64);
extern const int nsyscalls; extern const int nsyscalls;
u64 u64
syscall(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num) syscall(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 num)
{ {
mt_ascope ascope("syscall(%lx,%lx,%lx,%lx,%lx,%lx)", num, a0, a1, a2, a3, a4);
for (;;) { for (;;) {
#if EXCEPTIONS #if EXCEPTIONS
try { try {
...@@ -94,7 +92,7 @@ syscall(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num) ...@@ -94,7 +92,7 @@ syscall(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num)
if(num < nsyscalls && syscalls[num]) { if(num < nsyscalls && syscalls[num]) {
mtstart(syscalls[num], myproc()); mtstart(syscalls[num], myproc());
mtrec(); mtrec();
u64 r = syscalls[num](a0, a1, a2, a3, a4); u64 r = syscalls[num](a0, a1, a2, a3, a4, a5);
mtstop(myproc()); mtstop(myproc());
mtign(); mtign();
return r; return r;
......
...@@ -299,7 +299,6 @@ sys_openat(int dirfd, const char *path, int omode) ...@@ -299,7 +299,6 @@ sys_openat(int dirfd, const char *path, int omode)
// Reads the dirfd FD, dirfd's inode, the inodes of all files in // Reads the dirfd FD, dirfd's inode, the inodes of all files in
// path; writes the returned FD // path; writes the returned FD
mt_ascope ascope("%s(%d,%s,%d)", __func__, dirfd, path, omode); mt_ascope ascope("%s(%d,%s,%d)", __func__, dirfd, path, omode);
mtwriteavar("thread:%x", myproc()->pid);
mtreadavar("inode:%x.%x", cwd->dev, cwd->inum); mtreadavar("inode:%x.%x", cwd->dev, cwd->inum);
if(omode & O_CREATE){ if(omode & O_CREATE){
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include "kmtrace.hh" #include "kmtrace.hh"
#include "futex.h" #include "futex.h"
#include <uk/mman.h>
//SYSCALL //SYSCALL
int int
sys_fork(int flags) sys_fork(int flags)
...@@ -98,42 +100,64 @@ sys_uptime(void) ...@@ -98,42 +100,64 @@ sys_uptime(void)
} }
//SYSCALL //SYSCALL
int void *
sys_map(userptr<void> addr, size_t len) sys_mmap(userptr<void> addr, size_t len, int prot, int flags, int fd,
off_t offset)
{ {
ANON_REGION(__func__, &perfgroup); ANON_REGION(__func__, &perfgroup);
mt_ascope ascope("%s(%p,%lu,%#x,%#x,%d,%#lx)",
__func__, addr.unsafe_get(), len, prot, flags, fd, offset);
if (!(prot & (PROT_READ | PROT_WRITE))) {
cprintf("not implemented: !(prot & (PROT_READ | PROT_WRITE))\n");
return MAP_FAILED;
}
if (flags & MAP_SHARED) {
cprintf("not implemented: (flags & MAP_SHARED)\n");
return MAP_FAILED;
}
if (!(flags & MAP_ANONYMOUS)) {
cprintf("not implemented: !(flags & MAP_ANONYMOUS)\n");
return MAP_FAILED;
}
uptr start = PGROUNDDOWN(addr);
uptr end = PGROUNDUP(addr + len);
if ((flags & MAP_FIXED) && start != addr)
return MAP_FAILED;
#if MTRACE #if MTRACE
mt_ascope ascope("%s(%p,%lx)", __func__, addr, len); if (addr != 0) {
mtwriteavar("thread:%x", myproc()->pid); for (uptr i = start / PGSIZE; i < end / PGSIZE; i++)
for (uptr i = PGROUNDDOWN(addr); i < PGROUNDUP(addr + len); i += PGSIZE) mtwriteavar("pte:%p.%#lx", myproc()->vmap, i);
mtwriteavar("page:%016x", i); }
#endif #endif
vmnode *vmn = new vmnode(PGROUNDUP(len) / PGSIZE); vmnode *vmn = new vmnode((end - start) / PGSIZE);
if (vmn == 0) if (vmn == 0)
return -1; return MAP_FAILED;
long r = myproc()->vmap->insert(vmn, PGROUNDDOWN(addr), 1); uptr r = myproc()->vmap->insert(vmn, start, 1);
if (r < 0) { if (r < 0) {
delete vmn; delete vmn;
return -1; return MAP_FAILED;
} }
return r; return (void*)r;
} }
//SYSCALL //SYSCALL
int int
sys_unmap(userptr<void> addr, size_t len) sys_munmap(userptr<void> addr, size_t len)
{ {
ANON_REGION(__func__, &perfgroup); ANON_REGION(__func__, &perfgroup);
#if MTRACE #if MTRACE
mt_ascope ascope("%s(%p,%lx)", __func__, addr, len); mt_ascope ascope("%s(%p,%#lx)", __func__, addr.unsafe_get(), len);
mtwriteavar("thread:%x", myproc()->pid); for (uptr i = addr / PGSIZE; i < PGROUNDUP(addr + len) / PGSIZE; i++)
for (uptr i = PGROUNDDOWN(addr); i < PGROUNDUP(addr + len); i += PGSIZE) mtwriteavar("pte:%p.%#lx", myproc()->vmap, i);
mtwriteavar("page:%016x", i);
#endif #endif
uptr align_addr = PGROUNDDOWN(addr); uptr align_addr = PGROUNDDOWN(addr);
...@@ -179,7 +203,6 @@ sys_futex(const u64* addr, int op, u64 val, u64 timer) ...@@ -179,7 +203,6 @@ sys_futex(const u64* addr, int op, u64 val, u64 timer)
return -1; return -1;
mt_ascope ascope("%s(%p,%d,%lu,%lu)", __func__, addr, op, val, timer); mt_ascope ascope("%s(%p,%d,%lu,%lu)", __func__, addr, op, val, timer);
mtwriteavar("thread:%x", myproc()->pid);
switch(op) { switch(op) {
case FUTEX_WAIT: case FUTEX_WAIT:
......
...@@ -20,7 +20,7 @@ struct intdesc idt[256] __attribute__((aligned(16))); ...@@ -20,7 +20,7 @@ struct intdesc idt[256] __attribute__((aligned(16)));
extern u64 trapentry[]; extern u64 trapentry[];
u64 u64
sysentry_c(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num) sysentry_c(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5, u64 num)
{ {
sti(); sti();
...@@ -31,7 +31,7 @@ sysentry_c(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num) ...@@ -31,7 +31,7 @@ sysentry_c(u64 a0, u64 a1, u64 a2, u64 a3, u64 a4, u64 num)
trapframe *tf = (trapframe*) (myproc()->kstack + KSTACKSIZE - sizeof(*tf)); trapframe *tf = (trapframe*) (myproc()->kstack + KSTACKSIZE - sizeof(*tf));
myproc()->tf = tf; myproc()->tf = tf;
u64 r = syscall(a0, a1, a2, a3, a4, num); u64 r = syscall(a0, a1, a2, a3, a4, a5, num);
if(myproc()->killed) { if(myproc()->killed) {
mtstart(trap, myproc()); mtstart(trap, myproc());
......
...@@ -18,6 +18,21 @@ ...@@ -18,6 +18,21 @@
#define TRAP(x) _TRAP(x, NOEC) #define TRAP(x) _TRAP(x, NOEC)
#define TRAPCODE(x) _TRAP(x, EC) #define TRAPCODE(x) _TRAP(x, EC)
/* Calling convention:
*
* Syscall #: %rax
* Arguments: %rdi, %rsi, %rdx, %r10 (*), %r8, %r9
* Return RIP: %rcx (from syscall instruction)
* RFLAGS: %r11 (from syscall instruction)
*
* None of the above registers are preserved across function calls in
* the AMD64 ABI. This means user space doesn't need to save any
* registers across a syscall and we're free to clobber them.
*
* (*) This argument register differs from the regular AMD64 ABI.
* Normally, the fourth argument is in %rcx, but this is clobbered by
* syscall. %r10 is cheap to use because it is caller-save.
*/
.code64 .code64
.globl sysentry .globl sysentry
.align 8 .align 8
...@@ -25,23 +40,21 @@ sysentry: ...@@ -25,23 +40,21 @@ sysentry:
// can syscall/sysret be used safely in the presence of NMIs? // can syscall/sysret be used safely in the presence of NMIs?
// we are executing with cpl=0 but without a valid stack. // we are executing with cpl=0 but without a valid stack.
// blow away %r9: syscalls can take at most 5 args
swapgs swapgs
movq %gs:8, %r9 // myproc() movq %rax, %gs:24 // save %rax so we can use it
movq %gs:8, %rax // myproc()
movq %ss:PROC_KSTACK_OFFSET(%r9), %r9 movq %ss:PROC_KSTACK_OFFSET(%rax), %rax
addq $(KSTACKSIZE-TRAPFRAME_SIZE), %r9 addq $(KSTACKSIZE-TRAPFRAME_SIZE), %rax
// syscall number: %rax
// function arguments: %rdi, %rsi, %rdx, %rcx, %r8, %r9 (killed)
// save all registers we're not allowed to clobber
// skip padding3, ds // skip padding3, ds
movq %r15, %ss:0x10(%r9) movq %r15, %ss:0x10(%rax)
movq %r14, %ss:0x18(%r9) movq %r14, %ss:0x18(%rax)
movq %r13, %ss:0x20(%r9) movq %r13, %ss:0x20(%rax)
movq %r12, %ss:0x28(%r9) movq %r12, %ss:0x28(%rax)
movq %rbp, %ss:0x30(%r9) movq %rbp, %ss:0x30(%rax)
movq %rbx, %ss:0x38(%r9) movq %rbx, %ss:0x38(%rax)
// skip r11 (0x40) // skip r11 (0x40)
// skip r10 (0x48) // skip r10 (0x48)
// skip r9 (0x50) // skip r9 (0x50)
...@@ -53,20 +66,21 @@ sysentry: ...@@ -53,20 +66,21 @@ sysentry:
// skip rdi (0x80) // skip rdi (0x80)
// skip trapno (0x88) // skip trapno (0x88)
// skip err, padding2 (0x90) // skip err, padding2 (0x90)
movq %rcx, %ss:0x98(%r9) // rip saved by syscall movq %rcx, %ss:0x98(%rax) // rip saved by syscall
// skip cs, padding (0xa0) // skip cs, padding (0xa0)
movq %r11, %ss:0xa8(%r9) // eflags saved by syscall movq %r11, %ss:0xa8(%rax) // eflags saved by syscall
movq %rsp, %ss:0xb0(%r9) movq %rsp, %ss:0xb0(%rax)
movw $KDSEG, %cx movw $KDSEG, %cx
movw %cx, %ds movw %cx, %ds
movw %cx, %es movw %cx, %es
movq %r9, %rsp movq %rax, %rsp
movq %r10, %rcx // saved by usys.S movq %r10, %rcx // saved by usys.S
movq %rax, %r9 // syscall# from usys.S pushq %gs:24 // syscall# saved from %rax
call sysentry_c call sysentry_c
popq %r11
// return using SYSRET // return using SYSRET
cli cli
......
...@@ -130,7 +130,7 @@ vmnode::loadpg(off_t off) ...@@ -130,7 +130,7 @@ vmnode::loadpg(off_t off)
{ {
#ifdef MTRACE #ifdef MTRACE
mtreadavar("inode:%x.%x", ip->dev, ip->inum); mtreadavar("inode:%x.%x", ip->dev, ip->inum);
mtwriteavar("vmnode:%016x", this); mtwriteavar("vmnode:%p", this);
#endif #endif
assert(off <= sz); assert(off <= sz);
...@@ -627,7 +627,7 @@ vmap::pagefault(uptr va, u32 err) ...@@ -627,7 +627,7 @@ vmap::pagefault(uptr va, u32 err)
*pte = v2p(m->n->page[npg]) | PTE_P | PTE_U | PTE_W; *pte = v2p(m->n->page[npg]) | PTE_P | PTE_U | PTE_W;
} }
mtreadavar("vmnode:%016x", m->n); mtreadavar("vmnode:%p", m->n);
return 1; return 1;
} }
...@@ -636,9 +636,8 @@ int ...@@ -636,9 +636,8 @@ int
pagefault(vmap *vmap, uptr va, u32 err) pagefault(vmap *vmap, uptr va, u32 err)
{ {
#if MTRACE #if MTRACE
mt_ascope ascope("%s(%p)", __func__, va); mt_ascope ascope("%s(%#lx)", __func__, va);
mtwriteavar("thread:%x", myproc()->pid); mtwriteavar("pte:%p.%#lx", vmap, va / PGSIZE);
mtwriteavar("page:%p.%016x", vmap, PGROUNDDOWN(va));
#endif #endif
for (;;) { for (;;) {
...@@ -679,7 +678,7 @@ vmap::pagelookup(uptr va) ...@@ -679,7 +678,7 @@ vmap::pagelookup(uptr va)
throw_bad_alloc(); throw_bad_alloc();
char* kptr = (char*)(m->n->page[npg]); char* kptr = (char*)(m->n->page[npg]);
mtreadavar("vmnode:%016x", m->n); mtreadavar("vmnode:%p", m->n);
return &kptr[va & (PGSIZE-1)]; return &kptr[va & (PGSIZE-1)];
} }
...@@ -687,9 +686,8 @@ void* ...@@ -687,9 +686,8 @@ void*
pagelookup(vmap* vmap, uptr va) pagelookup(vmap* vmap, uptr va)
{ {
#if MTRACE #if MTRACE
mt_ascope ascope("%s(%p)", __func__, va); mt_ascope ascope("%s(%#lx)", __func__, va);
mtwriteavar("thread:%x", myproc()->pid); mtwriteavar("pte:%p.%#lx", vmap, va / PGSIZE);
mtwriteavar("page:%p.%016x", vmap, PGROUNDDOWN(va));
#endif #endif
for (;;) { for (;;) {
......
...@@ -208,6 +208,8 @@ vprintfmt(void (*putch)(int, void*), void *putdat, ...@@ -208,6 +208,8 @@ vprintfmt(void (*putch)(int, void*), void *putdat,
case 'o': case 'o':
num = getuint (ap, lflag); num = getuint (ap, lflag);
base = 8; base = 8;
if (altflag && num)
putch ('0', putdat);
goto number; goto number;
// pointer // pointer
...@@ -223,6 +225,10 @@ vprintfmt(void (*putch)(int, void*), void *putdat, ...@@ -223,6 +225,10 @@ vprintfmt(void (*putch)(int, void*), void *putdat,
case 'x': case 'x':
num = getuint (ap, lflag); num = getuint (ap, lflag);
base = 16; base = 16;
if (altflag && num) {
putch ('0', putdat);
putch ('x', putdat);
}
number: number:
printnum (putch, putdat, num, base, MAX(width, 0), padc); printnum (putch, putdat, num, base, MAX(width, 0), padc);
break; break;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "lib.h" #include "lib.h"
#include "percpu.hh" #include "percpu.hh"
#include <sys/mman.h>
#define WQCHUNKSZ 8192 #define WQCHUNKSZ 8192
#define WQBLOCKSZ 128 #define WQBLOCKSZ 128
static_assert(WQCHUNKSZ%WQBLOCKSZ == 0, "Bad sizes"); static_assert(WQCHUNKSZ%WQBLOCKSZ == 0, "Bad sizes");
...@@ -17,11 +19,11 @@ percpu<wqblock*> block; ...@@ -17,11 +19,11 @@ percpu<wqblock*> block;
static bool static bool
refill(void) refill(void)
{ {
long r = map(0, WQCHUNKSZ); void *r = mmap(0, WQCHUNKSZ, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
if (r < 0) if (r == MAP_FAILED)
return false; return false;
for (uptr p = r; p < r+WQCHUNKSZ; p += WQBLOCKSZ) { for (char *p = (char*)r; p < (char*)r+WQCHUNKSZ; p += WQBLOCKSZ) {
wqblock* n = (wqblock*)p; wqblock* n = (wqblock*)p;
n->next = *block; n->next = *block;
*block = n; *block = n;
......
#pragma once
#include <uk/mman.h>
// User/kernel shared mmap definitions
#pragma once
#define PROT_NONE 0x0
#define PROT_READ 0x1
#define PROT_WRITE 0x2
#define PROT_EXEC 0x4
#define MAP_SHARED 0x1
#define MAP_PRIVATE 0x2
#define MAP_FIXED 0x4
#define MAP_ANONYMOUS 0x8
#define MAP_FAILED ((void*)-1)
...@@ -34,13 +34,13 @@ def main(): ...@@ -34,13 +34,13 @@ def main():
", ".join(syscall.kargs)) ", ".join(syscall.kargs))
print print
print "u64 (*syscalls[])(u64, u64, u64, u64, u64) = {" print "u64 (*syscalls[])(u64, u64, u64, u64, u64, u64) = {"
bynum = dict((s.num, s) for s in syscalls) bynum = dict((s.num, s) for s in syscalls)
for num in range(max(bynum.keys()) + 1): for num in range(max(bynum.keys()) + 1):
if num not in bynum: if num not in bynum:
print " nullptr," print " nullptr,"
else: else:
print " (u64(*)(u64,u64,u64,u64,u64))%s," % bynum[num].kname print " (u64(*)(u64,u64,u64,u64,u64,u64))%s," % bynum[num].kname
print "};" print "};"
print print
print "extern const int nsyscalls = %d;" % (max(bynum.keys()) + 1) print "extern const int nsyscalls = %d;" % (max(bynum.keys()) + 1)
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论