提交 1bb8082e 创建 作者: Frans Kaashoek's avatar Frans Kaashoek

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

...@@ -76,6 +76,7 @@ ULIB := $(addprefix $(O)/, $(ULIB)) ...@@ -76,6 +76,7 @@ ULIB := $(addprefix $(O)/, $(ULIB))
UPROGS= \ UPROGS= \
_cat \ _cat \
_echo \
_init \ _init \
_forkexectree \ _forkexectree \
_forkexecbench \ _forkexecbench \
...@@ -85,7 +86,8 @@ UPROGS= \ ...@@ -85,7 +86,8 @@ UPROGS= \
_maptest \ _maptest \
_sh \ _sh \
_thrtest \ _thrtest \
_halt _halt \
_usertests
UPROGS := $(addprefix $(O)/, $(UPROGS)) UPROGS := $(addprefix $(O)/, $(UPROGS))
all: $(O)/kernel all: $(O)/kernel
...@@ -125,7 +127,7 @@ xv6memfs.img: bootblock kernelmemfs ...@@ -125,7 +127,7 @@ xv6memfs.img: bootblock kernelmemfs
$(O)/_%: $(O)/%.o $(ULIB) $(O)/_%: $(O)/%.o $(ULIB)
@echo " LD $@" @echo " LD $@"
$(Q)$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^ $(Q)$(LD) $(LDFLAGS) -N -e main -Ttext 0x100000 -o $@ $^
$(O)/mkfs: mkfs.c fs.h $(O)/mkfs: mkfs.c fs.h
gcc -m32 -Werror -Wall -o $@ mkfs.c gcc -m32 -Werror -Wall -o $@ mkfs.c
......
...@@ -206,10 +206,11 @@ init32e: ...@@ -206,10 +206,11 @@ init32e:
movl %eax, %cr3 movl %eax, %cr3
# Enable IA-32e mode by setting IA32_EFER.LME = 1. # Enable IA-32e mode by setting IA32_EFER.LME = 1.
# Also turn on IA32_EFER.SCE (syscall enable). # Also turn on IA32_EFER.SCE (syscall enable) and
# IA32_EFER.NXE (no-execute enable).
movl $0xc0000080, %ecx movl $0xc0000080, %ecx
rdmsr rdmsr
orl $0x101, %eax orl $((1<<8)|(1<<0)|(1<<11)), %eax
wrmsr wrmsr
# Enable paging by setting CR0.PG = 1. # Enable paging by setting CR0.PG = 1.
......
...@@ -94,7 +94,7 @@ snprintf(char *buf, u32 n, char *fmt, ...) ...@@ -94,7 +94,7 @@ snprintf(char *buf, u32 n, char *fmt, ...)
va_end(ap); va_end(ap);
} }
void static void
__cprintf(const char *fmt, ...) __cprintf(const char *fmt, ...)
{ {
va_list ap; va_list ap;
...@@ -124,9 +124,9 @@ cprintf(const char *fmt, ...) ...@@ -124,9 +124,9 @@ cprintf(const char *fmt, ...)
void void
puts(const char *s) puts(const char *s)
{ {
uint8 *p, *ep; u8 *p, *ep;
p = (uint8*)s; p = (u8*)s;
ep = p+strlen(s); ep = p+strlen(s);
for (; p < ep; p++) for (; p < ep; p++)
...@@ -192,16 +192,19 @@ kerneltrap(struct trapframe *tf) ...@@ -192,16 +192,19 @@ kerneltrap(struct trapframe *tf)
; ;
} }
void __noret__ void
panic(const char *s) panic(const char *fmt, ...)
{ {
extern void sys_halt(); extern void sys_halt();
va_list ap;
cli(); cli();
acquire(&cons.lock); acquire(&cons.lock);
__cprintf("cpu%d: panic: ", mycpu()->id); __cprintf("cpu%d: panic: ", mycpu()->id);
__cprintf(s); va_start(ap, fmt);
vprintfmt(writecons, 0, fmt, ap);
va_end(ap);
__cprintf("\n"); __cprintf("\n");
stacktrace(); stacktrace();
......
...@@ -27,9 +27,9 @@ ...@@ -27,9 +27,9 @@
#define CRANGE_CHECKING 0 #define CRANGE_CHECKING 0
#define MINNLEVEL 10 #define MINNLEVEL 10
#define MARKED(x) (((uintptr) (x)) & 0x1) #define MARKED(x) (((uptr) (x)) & 0x1)
#define RANGE_MARK(x) ((struct clist_range *) (((uintptr) (x)) | 0x1)) #define RANGE_MARK(x) ((struct clist_range *) (((uptr) (x)) | 0x1))
#define RANGE_WOMARK(x) ((struct clist_range *) (((uintptr) (x)) & ~0x1)) #define RANGE_WOMARK(x) ((struct clist_range *) (((uptr) (x)) & ~0x1))
enum { crange_debug = 0 }; enum { crange_debug = 0 };
......
...@@ -83,34 +83,28 @@ updatepages(pme_t *pml4, void *begin, void *end, int perm) ...@@ -83,34 +83,28 @@ updatepages(pme_t *pml4, void *begin, void *end, int perm)
} }
} }
static void // Map from 0 to 128Gbytes starting at KBASE.
pgmap(void *va, void *last, paddr pa) void
initpg(char* (*alloc)(void))
{ {
pme_t *pdp; extern char end[];
pme_t *pd; void *va = (void*)KBASE;
pme_t *sp; paddr pa = 0;
for (;;) { while (va < (void*)(KBASE+(128ull<<30))) {
pdp = descend(kpml4, va, 0, 1, 3); pme_t *pdp = descend(kpml4, va, 0, 1, 3);
pd = descend(pdp, va, 0, 1, 2); pme_t *pd = descend(pdp, va, 0, 1, 2);
sp = &pd[PX(1,va)]; pme_t *sp = &pd[PX(1,va)];
*sp = pa | PTE_W | PTE_P | PTE_PS; u64 flags = PTE_W | PTE_P | PTE_PS;
if(va == last) // Set NX for non-code pages
break; if (va >= (void*) end)
flags |= PTE_NX;
*sp = pa | flags;
va += PGSIZE*512; va += PGSIZE*512;
pa += PGSIZE*512; pa += PGSIZE*512;
} }
} }
// set up a page table to get off the ground
void
initpg(char* (*alloc)(void))
{
// Map first 4GB to KBASE
pgmap((void *) (KBASE+(1ull<<30)), (void *) (KBASE+(128ull<<30)), (1ull<<30));
// boot.S maps first 1GB to KBASE and gets us running with kpml4
}
// Set up kernel part of a page table. // Set up kernel part of a page table.
pml4e_t* pml4e_t*
setupkvm(void) setupkvm(void)
......
...@@ -31,7 +31,7 @@ static struct kmem slabmem[][NCPU] = { ...@@ -31,7 +31,7 @@ static struct kmem slabmem[][NCPU] = {
extern char end[]; // first address after kernel loaded from ELF file extern char end[]; // first address after kernel loaded from ELF file
char *newend; char *newend;
enum { kalloc_memset = 0 }; enum { kalloc_memset = 1 };
static int kinited __mpalign__; static int kinited __mpalign__;
...@@ -128,11 +128,15 @@ kfree_pool(struct kmem *m, char *v) ...@@ -128,11 +128,15 @@ kfree_pool(struct kmem *m, char *v)
{ {
struct run *r; struct run *r;
if((uptr)v % PGSIZE || v < end || memsize(v) == -1ull) if ((uptr)v % PGSIZE)
panic("kfree_pool"); panic("kfree_pool: misaligned %p", v);
if (v < end)
panic("kfree_pool: less than end %p", v);
if (memsize(v) == -1ull)
panic("kfree_pool: unknown region %p", v);
// Fill with junk to catch dangling refs. // Fill with junk to catch dangling refs.
if (kinited && kalloc_memset) if (kinited && kalloc_memset && m->size <= 16384)
memset(v, 1, m->size); memset(v, 1, m->size);
acquire(&m->lock); acquire(&m->lock);
...@@ -151,9 +155,9 @@ kmemprint(void) ...@@ -151,9 +155,9 @@ kmemprint(void)
cprintf("free pages: [ "); cprintf("free pages: [ ");
for (u32 i = 0; i < NCPU; i++) for (u32 i = 0; i < NCPU; i++)
if (i == mycpu()->id) if (i == mycpu()->id)
cprintf("<%d> ", kmems[i].nfree); cprintf("<%lu> ", kmems[i].nfree);
else else
cprintf("%d ", kmems[i].nfree); cprintf("%lu ", kmems[i].nfree);
cprintf("]\n"); cprintf("]\n");
} }
...@@ -184,7 +188,7 @@ kmemalloc(struct kmem *km) ...@@ -184,7 +188,7 @@ kmemalloc(struct kmem *km)
mtlabel(mtrace_label_block, r, m->size, "kalloc", sizeof("kalloc")); mtlabel(mtrace_label_block, r, m->size, "kalloc", sizeof("kalloc"));
if (kalloc_memset) if (kalloc_memset && m->size <= 16384)
memset(r, 2, m->size); memset(r, 2, m->size);
return (char*)r; return (char*)r;
} }
...@@ -408,7 +412,7 @@ kmalign(void **p, int align, u64 size) ...@@ -408,7 +412,7 @@ kmalign(void **p, int align, u64 size)
{ {
void *mem = kmalloc(size + (align-1) + sizeof(void*)); void *mem = kmalloc(size + (align-1) + sizeof(void*));
char *amem = ((char*)mem) + sizeof(void*); char *amem = ((char*)mem) + sizeof(void*);
amem += align - ((uintptr)amem & (align - 1)); amem += align - ((uptr)amem & (align - 1));
((void**)amem)[-1] = mem; ((void**)amem)[-1] = mem;
*p = amem; *p = amem;
return 0; return 0;
......
...@@ -44,8 +44,9 @@ void cv_wakeup(struct condvar *cv); ...@@ -44,8 +44,9 @@ void cv_wakeup(struct condvar *cv);
void cv_tick(void); void cv_tick(void);
// console.c // console.c
void cprintf(const char*, ...); void cprintf(const char*, ...) __attribute__((format(printf, 1, 2)));
void panic(const char*) __noret__; void panic(const char*, ...)
__noret__ __attribute__((format(printf, 1, 2)));
void kerneltrap(struct trapframe *tf) __noret__; void kerneltrap(struct trapframe *tf) __noret__;
void snprintf(char *buf, u32 n, char *fmt, ...); void snprintf(char *buf, u32 n, char *fmt, ...);
void consoleintr(int(*)(void)); void consoleintr(int(*)(void));
......
...@@ -26,5 +26,7 @@ SECTIONS ...@@ -26,5 +26,7 @@ SECTIONS
.bss : { .bss : {
*(.bss) *(.bss)
} }
/* 2MByte align, because we set NX on 2MByte super pages. */
. = ALIGN(0x200000);
PROVIDE(end = .); PROVIDE(end = .);
} }
...@@ -148,7 +148,7 @@ cpunum(void) ...@@ -148,7 +148,7 @@ cpunum(void)
static int n __mpalign__; static int n __mpalign__;
if(n == 0) { if(n == 0) {
n++; n++;
cprintf("cpu called from %lx with interrupts enabled\n", cprintf("cpu called from %p with interrupts enabled\n",
__builtin_return_address(0)); __builtin_return_address(0));
} }
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "multiboot.h" #include "multiboot.h"
#include "kernel.h" #include "kernel.h"
#include "cpu.h" #include "cpu.h"
#include "e820.h" #include "amd64.h"
extern void initpic(void); extern void initpic(void);
extern void initioapic(void); extern void initioapic(void);
...@@ -115,6 +115,7 @@ cmain(u64 mbmagic, u64 mbaddr) ...@@ -115,6 +115,7 @@ cmain(u64 mbmagic, u64 mbaddr)
inituser(); // first user process inituser(); // first user process
bootothers(); // start other processors bootothers(); // start other processors
kpml4[0] = 0; // don't need 1 GB identity mapping anymore kpml4[0] = 0; // don't need 1 GB identity mapping anymore
lcr3(rcr3());
scheduler(); scheduler();
panic("Unreachable"); panic("Unreachable");
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#define PTE_PS 0x080 // Page Size #define PTE_PS 0x080 // Page Size
#define PTE_MBZ 0x180 // Bits must be zero #define PTE_MBZ 0x180 // Bits must be zero
#define PTE_COW 0x800 // copy-on-write #define PTE_COW 0x800 // copy-on-write
#define PTE_NX 0x8000000000000000ull // No-execute enable
#define PGROUNDUP(sz) (((sz)+PGSIZE-1) & ~(PGSIZE-1)) #define PGROUNDUP(sz) (((sz)+PGSIZE-1) & ~(PGSIZE-1))
#define PGROUNDDOWN(a) ((__typeof__(a))((((uptr)(a)) & ~(PGSIZE-1)))) #define PGROUNDDOWN(a) ((__typeof__(a))((((uptr)(a)) & ~(PGSIZE-1))))
...@@ -123,5 +124,5 @@ struct taskstate ...@@ -123,5 +124,5 @@ struct taskstate
// and type bits. // and type bits.
#define INTDESC(cs, rip, bits) (struct intdesc){ \ #define INTDESC(cs, rip, bits) (struct intdesc){ \
(rip)&0xffff, (cs), 0, bits, ((rip)>>16)&0xffff, \ (rip)&0xffff, (cs), 0, bits, ((rip)>>16)&0xffff, \
(uint64)(rip)>>32, 0, \ (u64)(rip)>>32, 0, \
} }
typedef struct Mbdata Mbdata; typedef struct Mbdata Mbdata;
struct Mbdata struct Mbdata
{ {
uint32 flags; u32 flags;
uint32 mem_lower; // flag 0 u32 mem_lower; // flag 0
uint32 mem_upper; // flag 0 u32 mem_upper; // flag 0
uint32 boot_device; // flag 1 u32 boot_device; // flag 1
uint32 cmdline; // flag 2 u32 cmdline; // flag 2
uint32 mods_count; // flag 3 u32 mods_count; // flag 3
uint32 mods_addr; u32 mods_addr;
uint32 syms[4]; // flag 4, 5 u32 syms[4]; // flag 4, 5
uint32 mmap_length; // flag 6 u32 mmap_length; // flag 6
uint32 mmap_addr; u32 mmap_addr;
uint32 drives_length; // flag 7 u32 drives_length; // flag 7
uint32 drives_addr; u32 drives_addr;
uint32 config_table; // flag 8 u32 config_table; // flag 8
uint32 boot_loader_name; // flag 9 u32 boot_loader_name; // flag 9
uint32 apm_table; // flag 10 u32 apm_table; // flag 10
uint32 vbe_control_info; // flag 11 u32 vbe_control_info; // flag 11
uint32 vbe_mode_info; u32 vbe_mode_info;
uint32 vbe_mode; u32 vbe_mode;
uint32 vbe_interface_seg; u32 vbe_interface_seg;
uint32 vbe_interface_off; u32 vbe_interface_off;
uint32 vbe_interface_len; u32 vbe_interface_len;
}; };
typedef struct Mbmem Mbmem; typedef struct Mbmem Mbmem;
struct Mbmem struct Mbmem
{ {
uint64 base; u64 base;
uint64 length; u64 length;
uint32 type; u32 type;
}; };
typedef struct Mbmod Mbmod; typedef struct Mbmod Mbmod;
struct Mbmod struct Mbmod
{ {
uint32 start; u32 start;
uint32 end; u32 end;
uint32 name; u32 name;
};
typedef struct Page Page;
struct Page
{
Page *next; // only valid when page is on free list
}; };
...@@ -111,7 +111,7 @@ pci_attach_match(u32 key1, u32 key2, ...@@ -111,7 +111,7 @@ pci_attach_match(u32 key1, u32 key2,
return r; return r;
if (r < 0) if (r < 0)
cprintf("pci_attach_match: attaching " cprintf("pci_attach_match: attaching "
"%x.%x (%p): e\n", "%x.%x (%p): %d\n",
key1, key2, list[i].attachfn, r); key1, key2, list[i].attachfn, r);
} }
} }
......
...@@ -437,7 +437,7 @@ growproc(int n) ...@@ -437,7 +437,7 @@ growproc(int n)
// is there space for newstart..newstart+newn? // is there space for newstart..newstart+newn?
if(vmap_lookup(m, newstart, newn) != 0){ if(vmap_lookup(m, newstart, newn) != 0){
cprintf("growproc: not enough room in address space; brk %d n %d\n", cprintf("growproc: not enough room in address space; brk %lx n %d\n",
myproc()->brk, n); myproc()->brk, n);
return -1; return -1;
} }
...@@ -446,7 +446,7 @@ growproc(int n) ...@@ -446,7 +446,7 @@ growproc(int n)
// vma? we can't allow that, since then a future sbrk() // vma? we can't allow that, since then a future sbrk()
// would start to use the next region (e.g. the stack). // would start to use the next region (e.g. the stack).
if(vmap_lookup(m, PGROUNDUP(newstart+newn), 1) != 0){ if(vmap_lookup(m, PGROUNDUP(newstart+newn), 1) != 0){
cprintf("growproc: would abut next vma; brk %d n %d\n", cprintf("growproc: would abut next vma; brk %lx n %d\n",
myproc()->brk, n); myproc()->brk, n);
return -1; return -1;
} }
...@@ -530,7 +530,7 @@ void *procdump(void *vk, void *v, void *arg) ...@@ -530,7 +530,7 @@ void *procdump(void *vk, void *v, void *arg)
if(p->state == SLEEPING){ if(p->state == SLEEPING){
getcallerpcs((void*)p->context->rbp, pc); getcallerpcs((void*)p->context->rbp, pc);
for(int i=0; i<10 && pc[i] != 0; i++) for(int i=0; i<10 && pc[i] != 0; i++)
cprintf(" %p\n", pc[i]); cprintf(" %lx\n", pc[i]);
} }
return 0; return 0;
} }
......
...@@ -46,8 +46,8 @@ struct proc { ...@@ -46,8 +46,8 @@ struct proc {
struct file *ofile[NOFILE]; // Open files struct file *ofile[NOFILE]; // Open files
struct inode *cwd; // Current directory struct inode *cwd; // Current directory
char name[16]; // Process name (debugging) char name[16]; // Process name (debugging)
unsigned long long tsc; u64 tsc;
unsigned long long curcycles; u64 curcycles;
unsigned cpuid; unsigned cpuid;
struct spinlock lock; struct spinlock lock;
SLIST_HEAD(childlist, proc) childq; SLIST_HEAD(childlist, proc) childq;
......
...@@ -25,7 +25,7 @@ tryacquire(struct spinlock *lk) ...@@ -25,7 +25,7 @@ tryacquire(struct spinlock *lk)
#if SPINLOCK_DEBUG #if SPINLOCK_DEBUG
if(holding(lk)) { if(holding(lk)) {
cprintf("%lx\n", __builtin_return_address(0)); cprintf("%p\n", __builtin_return_address(0));
panic("acquire"); panic("acquire");
} }
#endif #endif
...@@ -56,7 +56,7 @@ acquire(struct spinlock *lk) ...@@ -56,7 +56,7 @@ acquire(struct spinlock *lk)
#if SPINLOCK_DEBUG #if SPINLOCK_DEBUG
if(holding(lk)) { if(holding(lk)) {
cprintf("%lx\n", __builtin_return_address(0)); cprintf("%p\n", __builtin_return_address(0));
panic("acquire"); panic("acquire");
} }
#endif #endif
......
...@@ -131,7 +131,7 @@ trap(struct trapframe *tf) ...@@ -131,7 +131,7 @@ trap(struct trapframe *tf)
} }
// In user space, assume process misbehaved. // In user space, assume process misbehaved.
cprintf("pid %d %s: trap %d err %d on cpu %d " cprintf("pid %d %s: trap %lu err %d on cpu %d "
"rip 0x%lx rsp 0x%lx addr 0x%lx--kill proc\n", "rip 0x%lx rsp 0x%lx addr 0x%lx--kill proc\n",
myproc()->pid, myproc()->name, tf->trapno, tf->err, myproc()->pid, myproc()->name, tf->trapno, tf->err,
mycpu()->id, tf->rip, tf->rsp, rcr2()); mycpu()->id, tf->rip, tf->rsp, rcr2());
...@@ -163,8 +163,8 @@ trap(struct trapframe *tf) ...@@ -163,8 +163,8 @@ trap(struct trapframe *tf)
void void
inittrap(void) inittrap(void)
{ {
uint64 entry; u64 entry;
uint32 bits; u32 bits;
int i; int i;
bits = INT_P | SEG_INTR64; // present, interrupt gate bits = INT_P | SEG_INTR64; // present, interrupt gate
......
...@@ -52,6 +52,7 @@ trapcommon: ...@@ -52,6 +52,7 @@ trapcommon:
// XXX(sbw) we should do something with fs, gs, gs.base // XXX(sbw) we should do something with fs, gs, gs.base
movq %rsp, %rdi // first argument to trap movq %rsp, %rdi // first argument to trap
xor %rbp, %rbp
call trap call trap
// Fall through to trapret // Fall through to trapret
......
typedef unsigned short uint16; typedef unsigned char u8;
typedef unsigned int uint32; typedef char s8;
typedef long int64; typedef unsigned short u16;
typedef unsigned long uint64; typedef short s16;
typedef unsigned char uint8; typedef unsigned int u32;
typedef uint64 uintptr; typedef int s32;
typedef unsigned long u64;
typedef long s64;
typedef u64 uptr;
typedef uptr paddr;
typedef uint8 u8; // Page Map Entry (refers to any entry in any level)
typedef char s8; typedef u64 pme_t;
typedef uint16 u16; typedef pme_t pml4e_t;
typedef short s16;
typedef uint32 u32;
typedef int s32;
typedef int64 s64;
typedef uint64 u64;
typedef uint64 uptr;
typedef uptr paddr;
typedef u64 pme_t; // Page Map Entry (refers to any entry in any level)
typedef pme_t pml4e_t;
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "fcntl.h" #include "fcntl.h"
#include "syscall.h" #include "syscall.h"
#include "traps.h" #include "traps.h"
#include "mtrace.h"
char buf[2048]; char buf[2048];
char name[3]; char name[3];
...@@ -663,7 +662,7 @@ concreate(void) ...@@ -663,7 +662,7 @@ concreate(void)
int i, pid, n, fd; int i, pid, n, fd;
char fa[40]; char fa[40];
struct { struct {
ushort inum; u16 inum;
char name[14]; char name[14];
} de; } de;
...@@ -1240,7 +1239,7 @@ sbrktest(void) ...@@ -1240,7 +1239,7 @@ sbrktest(void)
{ {
int fds[2], pid, pids[32], ppid; int fds[2], pid, pids[32], ppid;
char *a, *b, *c, *lastaddr, *oldbrk, *p, scratch; char *a, *b, *c, *lastaddr, *oldbrk, *p, scratch;
uint amt; uptr amt;
printf(stdout, "sbrk test\n"); printf(stdout, "sbrk test\n");
oldbrk = sbrk(0); oldbrk = sbrk(0);
...@@ -1275,7 +1274,7 @@ sbrktest(void) ...@@ -1275,7 +1274,7 @@ sbrktest(void)
// can one allocate the full 640K? // can one allocate the full 640K?
// less a stack page and an empty page at the top. // less a stack page and an empty page at the top.
a = sbrk(0); a = sbrk(0);
amt = (632 * 1024) - (uint)a; amt = (632 * 1024) - (uptr)a;
p = sbrk(amt); p = sbrk(amt);
if(p != a){ if(p != a){
printf(stdout, "sbrk test failed 632K test, p %x a %x\n", p, a); printf(stdout, "sbrk test failed 632K test, p %x a %x\n", p, a);
...@@ -1351,7 +1350,7 @@ sbrktest(void) ...@@ -1351,7 +1350,7 @@ sbrktest(void)
for(i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){ for(i = 0; i < sizeof(pids)/sizeof(pids[0]); i++){
if((pids[i] = fork(0)) == 0){ if((pids[i] = fork(0)) == 0){
// allocate the full 632K // allocate the full 632K
sbrk((632 * 1024) - (uint)sbrk(0)); sbrk((632 * 1024) - (uptr)sbrk(0));
write(fds[1], "x", 1); write(fds[1], "x", 1);
// sit around until killed // sit around until killed
for(;;) sleep(1000); for(;;) sleep(1000);
...@@ -1380,31 +1379,22 @@ sbrktest(void) ...@@ -1380,31 +1379,22 @@ sbrktest(void)
} }
void void
validateint(int *p)
{
int res;
__asm("mov %%esp, %%ebx\n\t"
"mov %3, %%esp\n\t"
"int %2\n\t"
"mov %%ebx, %%esp" :
"=a" (res) :
"a" (SYS_sleep), "n" (T_SYSCALL), "c" (p) :
"ebx");
}
void
validatetest(void) validatetest(void)
{ {
int hi, pid; int pid;
uint p; uptr lo, hi, p;
printf(stdout, "validate test\n"); printf(stdout, "validate test\n");
hi = 1100*1024; // Do 16 pages below the bottom of userspace and 16 pages above,
// which should be code pages and read-only
lo = (1024*1024) - 16*4096;
hi = (1024*1024) + 16*4096;
for(p = 0; p <= (uint)hi; p += 4096){ for(p = lo; p <= hi; p += 4096){
if((pid = fork(0)) == 0){ if((pid = fork(0)) == 0){
// try to crash the kernel by passing in a badly placed integer // try to crash the kernel by passing in a badly placed integer
validateint((int*)p); if (pipe((int*)p) == 0)
printf(stdout, "validatetest failed (pipe succeeded)\n");
exit(); exit();
} }
sleep(0); sleep(0);
...@@ -1444,9 +1434,8 @@ bsstest(void) ...@@ -1444,9 +1434,8 @@ bsstest(void)
void void
bigargtest(void) bigargtest(void)
{ {
int pid, ppid; int pid;
ppid = getpid();
pid = fork(0); pid = fork(0);
if(pid == 0){ if(pid == 0){
char *args[32+1]; char *args[32+1];
...@@ -1548,8 +1537,6 @@ main(int argc, char *argv[]) ...@@ -1548,8 +1537,6 @@ main(int argc, char *argv[])
{ {
printf(1, "usertests starting\n"); printf(1, "usertests starting\n");
mtrace_enable_set(1, "xv6-forktest");
if(open("usertests.ran", 0) >= 0){ if(open("usertests.ran", 0) >= 0){
printf(1, "already ran user tests -- rebuild fs.img\n"); printf(1, "already ran user tests -- rebuild fs.img\n");
exit(); exit();
...@@ -1569,7 +1556,7 @@ main(int argc, char *argv[]) ...@@ -1569,7 +1556,7 @@ main(int argc, char *argv[])
writetest1(); writetest1();
createtest(); createtest();
mem(); // mem();
pipe1(); pipe1();
preempt(); preempt();
exitwait(); exitwait();
......
...@@ -217,7 +217,8 @@ pagefault(struct vmap *vmap, uptr va, u32 err) ...@@ -217,7 +217,8 @@ pagefault(struct vmap *vmap, uptr va, u32 err)
m = pagefault_ondemand(vmap, va, err, m); m = pagefault_ondemand(vmap, va, err, m);
if (vm_debug) if (vm_debug)
cprintf("pagefault: err 0x%x va 0x%x type %d ref %d pid %d\n", err, va, m->va_type, m->n->ref, myproc()->pid); cprintf("pagefault: err 0x%x va 0x%lx type %d ref %lu pid %d\n",
err, va, m->va_type, m->n->ref, myproc()->pid);
if (m->va_type == COW && (err & FEC_WR)) { if (m->va_type == COW && (err & FEC_WR)) {
if (pagefault_wcow(vmap, va, pte, m, npg) < 0) { if (pagefault_wcow(vmap, va, pte, m, npg) < 0) {
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论