提交 39024ea6 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

c++ for lwip

上级 abfb55e2
...@@ -126,6 +126,7 @@ $(O)/kernel: $(O) $(O)/boot.o $(OBJS) ...@@ -126,6 +126,7 @@ $(O)/kernel: $(O) $(O)/boot.o $(OBJS)
$(O): $(O):
$(Q)mkdir $(O) $(Q)mkdir $(O)
$(Q)mkdir $(O)/net
$(O)/%.o: %.c $(O)/%.o: %.c
@echo " CC $@" @echo " CC $@"
......
...@@ -24,8 +24,7 @@ ...@@ -24,8 +24,7 @@
#include "types.h" #include "types.h"
#include "kernel.hh" #include "kernel.hh"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "buf.hh" #include "buf.hh"
#include "cpputil.hh" #include "cpputil.hh"
#include "ns.hh" #include "ns.hh"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "amd64.h" #include "amd64.h"
#include "mmu.h" #include "mmu.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "kernel.hh" #include "kernel.hh"
......
#pragma once
#include "queue.h" #include "queue.h"
struct condvar { struct condvar {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "kernel.hh" #include "kernel.hh"
#include "spinlock.h" #include "spinlock.h"
#include "fs.h" #include "fs.h"
#include "condvar.hh" #include "condvar.h"
#include "file.hh" #include "file.hh"
#include "amd64.h" #include "amd64.h"
#include "queue.h" #include "queue.h"
...@@ -122,6 +122,19 @@ cprintf(const char *fmt, ...) ...@@ -122,6 +122,19 @@ cprintf(const char *fmt, ...)
} }
void void
vcprintf(const char *fmt, va_list ap)
{
int locking = cons.locking;
if(locking)
acquire(&cons.lock);
vprintfmt(writecons, 0, fmt, ap);
if(locking)
release(&cons.lock);
}
void
puts(const char *s) puts(const char *s)
{ {
u8 *p, *ep; u8 *p, *ep;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "kernel.hh" #include "kernel.hh"
#include "mmu.h" #include "mmu.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "cpu.hh" #include "cpu.hh"
......
#include "types.h" #include "types.h"
#include "mmu.h" #include "mmu.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "kernel.hh" #include "kernel.hh"
......
#include "types.h" #include "types.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "kernel.hh" #include "kernel.hh"
#include "fs.h" #include "fs.h"
#include "file.hh" #include "file.hh"
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "mmu.h" #include "mmu.h"
#include "kernel.hh" #include "kernel.hh"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "fs.h" #include "fs.h"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "mmu.h" #include "mmu.h"
#include "amd64.h" #include "amd64.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "cpu.hh" #include "cpu.hh"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "spinlock.h" #include "spinlock.h"
#include "kalloc.h" #include "kalloc.h"
#include "queue.h" #include "queue.h"
#include "condvar.hh" #include "condvar.h"
#include "proc.hh" #include "proc.hh"
#include "vm.hh" #include "vm.hh"
#include <stddef.h> #include <stddef.h>
......
...@@ -2,6 +2,8 @@ extern "C" { ...@@ -2,6 +2,8 @@ extern "C" {
#include "kern_c.h" #include "kern_c.h"
} }
#include <stdarg.h>
#define KBASE 0xFFFFFF0000000000ull #define KBASE 0xFFFFFF0000000000ull
#define KSHARED 0xFFFFF00000000000ull #define KSHARED 0xFFFFF00000000000ull
#define USERTOP 0x0000800000000000ull #define USERTOP 0x0000800000000000ull
...@@ -48,6 +50,7 @@ void cv_tick(void); ...@@ -48,6 +50,7 @@ void cv_tick(void);
// console.c // console.c
void cprintf(const char*, ...) __attribute__((format(printf, 1, 2))); void cprintf(const char*, ...) __attribute__((format(printf, 1, 2)));
void vcprintf(const char *fmt, va_list ap);
void panic(const char*, ...) void panic(const char*, ...)
__noret__ __attribute__((format(printf, 1, 2))); __noret__ __attribute__((format(printf, 1, 2)));
void kerneltrap(struct trapframe *tf) __noret__; void kerneltrap(struct trapframe *tf) __noret__;
...@@ -221,10 +224,10 @@ void syscall(void); ...@@ -221,10 +224,10 @@ void syscall(void);
// string.c // string.c
int memcmp(const void*, const void*, u32); int memcmp(const void*, const void*, u32);
void* memmove(void*, const void*, u32); void* memmove(void*, const void*, u32);
void* memset(void*, int, u32); extern "C" void* memset(void*, int, u32);
void* memcpy(void*, const void *, u32); extern "C" void* memcpy(void*, const void *, u32);
char* safestrcpy(char*, const char*, u32); char* safestrcpy(char*, const char*, u32);
extern "C" unsigned int strlen(const char*); extern "C" unsigned int strlen(const char*);
int strncmp(const char*, const char*, u32); int strncmp(const char*, const char*, u32);
char* strncpy(char*, const char*, u32); char* strncpy(char*, const char*, u32);
int strcmp(const char *p, const char *q); int strcmp(const char *p, const char *q);
......
#include "types.h" #include "types.h"
#include "kernel.hh" #include "kernel.hh"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "cpu.hh" #include "cpu.hh"
#include "proc.hh" #include "proc.hh"
#include "fs.h" #include "fs.h"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "kernel.hh" #include "kernel.hh"
#include "spinlock.h" #include "spinlock.h"
#include "queue.h" #include "queue.h"
#include "condvar.hh" #include "condvar.h"
#include "proc.hh" #include "proc.hh"
#include "amd64.h" #include "amd64.h"
#include "traps.h" #include "traps.h"
......
...@@ -13,20 +13,16 @@ extern "C" { ...@@ -13,20 +13,16 @@ extern "C" {
#include "types.h" #include "types.h"
#include "kernel.hh" #include "kernel.hh"
#include "queue.h" #include "queue.h"
#ifndef LWIP
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#endif
#include "proc.hh" #include "proc.hh"
#include "fs.h" #include "fs.h"
#include "file.hh" #include "file.hh"
#include "net.hh" #include "net.hh"
#ifdef LWIP #ifdef LWIP
extern "C" {
err_t if_init(struct netif *netif); err_t if_init(struct netif *netif);
void if_input(struct netif *netif, void *buf, u16 len); void if_input(struct netif *netif, void *buf, u16 len);
}
#endif #endif
void void
......
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
#include <types.h> #include <types.h>
void cprintf(const char*, ...) __attribute__((format(printf, 1, 2))); void lwip_cprintf(const char*, ...) __attribute__((format(printf, 1, 2)));
void panic(const char*, ...) void lwip_panic(const char*, ...) __noret__ __attribute__((format(printf, 1, 2)));
__noret__ __attribute__((format(printf, 1, 2)));
typedef u32 u32_t; typedef u32 u32_t;
typedef s32 s32_t; typedef s32 s32_t;
...@@ -34,8 +33,8 @@ typedef uptr mem_ptr_t; ...@@ -34,8 +33,8 @@ typedef uptr mem_ptr_t;
#define U32_F "u" #define U32_F "u"
#define X32_F "x" #define X32_F "x"
#define LWIP_PLATFORM_DIAG(x) cprintf x #define LWIP_PLATFORM_DIAG(x) lwip_cprintf x
#define LWIP_PLATFORM_ASSERT(x) panic(x) #define LWIP_PLATFORM_ASSERT(x) lwip_panic(x)
#ifndef BYTE_ORDER #ifndef BYTE_ORDER
#define BYTE_ORDER LITTLE_ENDIAN #define BYTE_ORDER LITTLE_ENDIAN
......
extern "C" {
#include "lwip/stats.h" #include "lwip/stats.h"
#include "netif/etharp.h" #include "netif/etharp.h"
#include "kernel.h" }
#include "kernel.hh"
/** /**
* In this function, the hardware should be initialized. * In this function, the hardware should be initialized.
...@@ -52,7 +55,7 @@ low_level_output(struct netif *netif, struct pbuf *p) ...@@ -52,7 +55,7 @@ low_level_output(struct netif *netif, struct pbuf *p)
u8 *buf; u8 *buf;
size = 0; size = 0;
buf = netalloc(); buf = (u8*) netalloc();
if (buf == NULL) { if (buf == NULL) {
cprintf("low_level_output: netalloc failed\n"); cprintf("low_level_output: netalloc failed\n");
return ERR_MEM; return ERR_MEM;
...@@ -122,7 +125,7 @@ low_level_input(struct netif *netif, void *buf, u16_t len) ...@@ -122,7 +125,7 @@ low_level_input(struct netif *netif, void *buf, u16_t len)
int bytes = q->len; int bytes = q->len;
if (bytes > (len - copied)) if (bytes > (len - copied))
bytes = len - copied; bytes = len - copied;
memmove(q->payload, buf + copied, bytes); memmove(q->payload, (char*) buf + copied, bytes);
copied += bytes; copied += bytes;
} }
...@@ -160,7 +163,7 @@ if_input(struct netif *netif, void *buf, u16 len) ...@@ -160,7 +163,7 @@ if_input(struct netif *netif, void *buf, u16 len)
/* no packet could be read, silently ignore this */ /* no packet could be read, silently ignore this */
if (p == NULL) return; if (p == NULL) return;
/* points to packet payload, which starts with an Ethernet header */ /* points to packet payload, which starts with an Ethernet header */
ethhdr = p->payload; ethhdr = (eth_hdr*) p->payload;
switch (htons(ethhdr->type)) { switch (htons(ethhdr->type)) {
/* IP or ARP packet? */ /* IP or ARP packet? */
...@@ -175,7 +178,7 @@ if_input(struct netif *netif, void *buf, u16 len) ...@@ -175,7 +178,7 @@ if_input(struct netif *netif, void *buf, u16 len)
if (VERBOSE) if (VERBOSE)
cprintf("if_input: unknown type %04x\n", htons(ethhdr->type)); cprintf("if_input: unknown type %04x\n", htons(ethhdr->type));
pbuf_free(p); pbuf_free(p);
p = NULL; p = 0;
break; break;
} }
} }
......
extern "C" {
#include "lwip/sys.h" #include "lwip/sys.h"
#include "arch/sys_arch.h" #include "arch/sys_arch.h"
}
#include "queue.h" #include "queue.h"
#include "kernel.h" #include "kernel.hh"
#include "proc.h" #include "proc.hh"
#include "cpu.h" #include "cpu.hh"
#define DIE panic(__func__) #define DIE panic(__func__)
...@@ -192,7 +194,7 @@ struct lwip_thread { ...@@ -192,7 +194,7 @@ struct lwip_thread {
static void static void
lwip_thread(void *x) lwip_thread(void *x)
{ {
struct lwip_thread *lt = x; struct lwip_thread *lt = (struct lwip_thread*) x;
lwip_core_lock(); lwip_core_lock();
lt->thread(lt->arg); lt->thread(lt->arg);
lwip_core_unlock(); lwip_core_unlock();
...@@ -206,9 +208,9 @@ sys_thread_new(const char *name, lwip_thread_fn thread, void *arg, ...@@ -206,9 +208,9 @@ sys_thread_new(const char *name, lwip_thread_fn thread, void *arg,
struct lwip_thread *lt; struct lwip_thread *lt;
struct proc *p; struct proc *p;
lt = kmalloc(sizeof(*lt)); lt = (struct lwip_thread*) kmalloc(sizeof(*lt));
if (lt == NULL) if (lt == NULL)
return NULL; return 0;
lt->thread = thread; lt->thread = thread;
lt->arg = arg; lt->arg = arg;
...@@ -259,3 +261,25 @@ lwip_core_init(void) ...@@ -259,3 +261,25 @@ lwip_core_init(void)
{ {
initlock(&lwprot.lk, "lwIP lwprot", 1); initlock(&lwprot.lk, "lwIP lwprot", 1);
} }
void
lwip_panic(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vcprintf(fmt, ap);
va_end(ap);
panic("LWIP panic");
}
void
lwip_cprintf(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vcprintf(fmt, ap);
va_end(ap);
}
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "mmu.h" #include "mmu.h"
#include "kernel.hh" #include "kernel.hh"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "fs.h" #include "fs.h"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "mmu.h" #include "mmu.h"
#include "amd64.h" #include "amd64.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "cpu.hh" #include "cpu.hh"
...@@ -427,13 +427,13 @@ growproc(int n) ...@@ -427,13 +427,13 @@ growproc(int n)
vma *e = m->lookup(newstart, 1); vma *e = m->lookup(newstart, 1);
if(e == 0) if(e == 0)
break; break;
if(e->va_end >= newstart + newn){ if(e->vma_end >= newstart + newn){
newstart += newn; newstart += newn;
newn = 0; newn = 0;
break; break;
} }
newn -= e->va_end - newstart; newn -= e->vma_end - newstart;
newstart = e->va_end; newstart = e->vma_end;
} }
gc_end_epoch(); gc_end_epoch();
......
#include "types.h" #include "types.h"
#include "kernel.hh" #include "kernel.hh"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "fs.h" #include "fs.h"
#include "file.hh" #include "file.hh"
#include "prof.hh" #include "prof.hh"
......
#include "types.h" #include "types.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "fs.h" #include "fs.h"
#include "kernel.hh" #include "kernel.hh"
#include "stat.h" #include "stat.h"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "mmu.h" #include "mmu.h"
#include "amd64.h" #include "amd64.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "cpu.hh" #include "cpu.hh"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "bits.hh" #include "bits.hh"
#include "spinlock.h" #include "spinlock.h"
#include "mtrace.h" #include "mtrace.h"
#include "condvar.hh" #include "condvar.h"
#include "fs.h" #include "fs.h"
#include "file.hh" #include "file.hh"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "mmu.h" #include "mmu.h"
#include "kernel.hh" #include "kernel.hh"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "amd64.h" #include "amd64.h"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "mmu.h" #include "mmu.h"
#include "kernel.hh" #include "kernel.hh"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "fs.h" #include "fs.h"
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "kernel.hh" #include "kernel.hh"
#include "mmu.h" #include "mmu.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "queue.h" #include "queue.h"
#include "proc.hh" #include "proc.hh"
#include "cpu.hh" #include "cpu.hh"
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "traps.h" #include "traps.h"
#include "queue.h" #include "queue.h"
#include "spinlock.h" #include "spinlock.h"
#include "condvar.hh" #include "condvar.h"
#include "proc.hh" #include "proc.hh"
#include "kmtrace.hh" #include "kmtrace.hh"
#include "bits.hh" #include "bits.hh"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "spinlock.h" #include "spinlock.h"
#include "kalloc.h" #include "kalloc.h"
#include "queue.h" #include "queue.h"
#include "condvar.hh" #include "condvar.h"
#include "proc.hh" #include "proc.hh"
#include "vm.hh" #include "vm.hh"
#include "gc.hh" #include "gc.hh"
...@@ -120,7 +120,7 @@ vmnode::load(inode *iparg, u64 offarg, u64 szarg) ...@@ -120,7 +120,7 @@ vmnode::load(inode *iparg, u64 offarg, u64 szarg)
*/ */
vma::vma() vma::vma()
: rcu_freed("vma"), va_start(0), va_end(0), va_type(PRIVATE), n(0) : rcu_freed("vma"), vma_start(0), vma_end(0), va_type(PRIVATE), n(0)
{ {
snprintf(lockname, sizeof(lockname), "vma:%p", this); snprintf(lockname, sizeof(lockname), "vma:%p", this);
initlock(&lock, lockname, LOCKSTAT_VM); initlock(&lock, lockname, LOCKSTAT_VM);
...@@ -210,15 +210,15 @@ vmap::copy(int share) ...@@ -210,15 +210,15 @@ vmap::copy(int share)
if (ne == 0) if (ne == 0)
goto err; goto err;
ne->va_start = e->va_start; ne->vma_start = e->vma_start;
ne->va_end = e->va_end; ne->vma_end = e->vma_end;
if (share) { if (share) {
ne->n = e->n; ne->n = e->n;
ne->va_type = COW; ne->va_type = COW;
scoped_acquire sae(&e->lock); scoped_acquire sae(&e->lock);
e->va_type = COW; e->va_type = COW;
updatepages(pml4, (void *) (e->va_start), (void *) (e->va_end), PTE_COW); updatepages(pml4, (void *) (e->vma_start), (void *) (e->vma_end), PTE_COW);
} else { } else {
ne->n = e->n->copy(); ne->n = e->n->copy();
ne->va_type = e->va_type; ne->va_type = e->va_type;
...@@ -228,7 +228,7 @@ vmap::copy(int share) ...@@ -228,7 +228,7 @@ vmap::copy(int share)
goto err; goto err;
ne->n->ref++; ne->n->ref++;
nm->cr.add(ne->va_start, ne->va_end - ne->va_start, (void *) ne); nm->cr.add(ne->vma_start, ne->vma_end - ne->vma_start, (void *) ne);
} }
if (share) if (share)
...@@ -256,9 +256,9 @@ vmap::lookup(uptr start, uptr len) ...@@ -256,9 +256,9 @@ vmap::lookup(uptr start, uptr len)
range *r = cr.search(start, len); range *r = cr.search(start, len);
if (r != 0) { if (r != 0) {
vma *e = (struct vma *) (r->value); vma *e = (struct vma *) (r->value);
if (e->va_end <= e->va_start) if (e->vma_end <= e->vma_start)
panic("malformed va"); panic("malformed va");
if (e->va_start < start+len && e->va_end > start) if (e->vma_start < start+len && e->vma_end > start)
return e; return e;
} }
...@@ -266,12 +266,12 @@ vmap::lookup(uptr start, uptr len) ...@@ -266,12 +266,12 @@ vmap::lookup(uptr start, uptr len)
} }
int int
vmap::insert(vmnode *n, uptr va_start) vmap::insert(vmnode *n, uptr vma_start)
{ {
scoped_acquire sa(&lock); scoped_acquire sa(&lock);
u64 len = n->npages * PGSIZE; u64 len = n->npages * PGSIZE;
if (lookup(va_start, len)) { if (lookup(vma_start, len)) {
cprintf("vmap_insert: overlap\n"); cprintf("vmap_insert: overlap\n");
return -1; return -1;
} }
...@@ -280,28 +280,28 @@ vmap::insert(vmnode *n, uptr va_start) ...@@ -280,28 +280,28 @@ vmap::insert(vmnode *n, uptr va_start)
if (e == 0) if (e == 0)
return -1; return -1;
e->va_start = va_start; e->vma_start = vma_start;
e->va_end = va_start + len; e->vma_end = vma_start + len;
e->n = n; e->n = n;
n->ref++; n->ref++;
cr.add(e->va_start, len, (void *) e); cr.add(e->vma_start, len, (void *) e);
return 0; return 0;
} }
int int
vmap::remove(uptr va_start, uptr len) vmap::remove(uptr vma_start, uptr len)
{ {
scoped_acquire sa(&lock); scoped_acquire sa(&lock);
uptr va_end = va_start + len; uptr vma_end = vma_start + len;
struct range *r = cr.search(va_start, len); struct range *r = cr.search(vma_start, len);
if (r == 0) if (r == 0)
panic("no vma?"); panic("no vma?");
struct vma *e = (struct vma *) r->value; struct vma *e = (struct vma *) r->value;
if (e->va_start != va_start || e->va_end != va_end) { if (e->vma_start != vma_start || e->vma_end != vma_end) {
cprintf("vmap_remove: partial unmap unsupported\n"); cprintf("vmap_remove: partial unmap unsupported\n");
return -1; return -1;
} }
cr.del(va_start, len); cr.del(vma_start, len);
gc_delayed(e); gc_delayed(e);
return 0; return 0;
} }
...@@ -341,7 +341,7 @@ vmap::pagefault_wcow(uptr va, pme_t *pte, vma *m, u64 npg) ...@@ -341,7 +341,7 @@ vmap::pagefault_wcow(uptr va, pme_t *pte, vma *m, u64 npg)
m->va_type = PRIVATE; m->va_type = PRIVATE;
m->n = c; m->n = c;
// Update the hardware page tables to reflect the change to the vma // Update the hardware page tables to reflect the change to the vma
updatepages(pml4, (void *) m->va_start, (void *) m->va_end, 0); updatepages(pml4, (void *) m->vma_start, (void *) m->vma_end, 0);
pte = walkpgdir(pml4, (const void *)va, 0); pte = walkpgdir(pml4, (const void *)va, 0);
*pte = v2p(m->n->page[npg]) | PTE_P | PTE_U | PTE_W; *pte = v2p(m->n->page[npg]) | PTE_P | PTE_U | PTE_W;
// drop my ref to vmnode // drop my ref to vmnode
...@@ -364,7 +364,7 @@ vmap::pagefault(uptr va, u32 err) ...@@ -364,7 +364,7 @@ vmap::pagefault(uptr va, u32 err)
return -1; return -1;
acquire(&m->lock); acquire(&m->lock);
u64 npg = (PGROUNDDOWN(va) - m->va_start) / PGSIZE; u64 npg = (PGROUNDDOWN(va) - m->vma_start) / PGSIZE;
if (m->n && m->n->type == ONDEMAND && m->n->page[npg] == 0) if (m->n && m->n->type == ONDEMAND && m->n->page[npg] == 0)
m = pagefault_ondemand(va, err, m); m = pagefault_ondemand(va, err, m);
...@@ -412,7 +412,7 @@ vmap::copyout(uptr va, void *p, u64 len) ...@@ -412,7 +412,7 @@ vmap::copyout(uptr va, void *p, u64 len)
return -1; return -1;
acquire(&vma->lock); acquire(&vma->lock);
uptr pn = (va0 - vma->va_start) / PGSIZE; uptr pn = (va0 - vma->vma_start) / PGSIZE;
char *p0 = vma->n->page[pn]; char *p0 = vma->n->page[pn];
if(p0 == 0) if(p0 == 0)
panic("copyout: missing page"); panic("copyout: missing page");
......
...@@ -31,8 +31,8 @@ struct vmnode { ...@@ -31,8 +31,8 @@ struct vmnode {
enum vmatype { PRIVATE, COW }; enum vmatype { PRIVATE, COW };
struct vma : public rcu_freed { struct vma : public rcu_freed {
uptr va_start; // start of mapping uptr vma_start; // start of mapping
uptr va_end; // one past the last byte uptr vma_end; // one past the last byte
enum vmatype va_type; enum vmatype va_type;
struct vmnode *n; struct vmnode *n;
struct spinlock lock; // serialize fault/unmap struct spinlock lock; // serialize fault/unmap
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论