Compare commits

...

10 Commits

Author SHA1 Message Date
Michael Lee 83a632b1b2 Fixing provisioning of gdbinit 2014-09-25 01:38:07 -05:00
Michael Lee 4376508c63 Ignoring .vagrant directory 2014-09-24 07:35:35 -05:00
Michael Lee 051f910f4d Adding Vagrantfile 2014-09-24 07:25:02 -05:00
Michael Lee 6e0d8f2ef6 Readying for CS 450 xv6 assignment 2013-06-25 19:46:06 -05:00
Michael Lee 0ae596828b Updating Makefile to work with Macports tools 2013-05-28 20:39:02 -05:00
Stephen Tu ff2783442e Correct a security bug in copyuvm()
copyuvm() should not allow new copied pages to inherit more
permissions than the original pages.
2013-03-04 16:16:54 -05:00
Cam Tenny 241c068066 Prevent extra rebuild of fs.img by keeping intermediate object files. 2012-10-24 18:52:40 -04:00
Frans Kaashoek c440b5cd97 Use static assert instead of _LP64 (thanks Eddie!) 2012-09-10 21:58:18 -04:00
Frans Kaashoek cf57e525c1 Remove -m32 flag from native gcc compiler
But check that mkfs.c is building with LP64
2012-09-07 17:39:04 -04:00
Robert Morris 2ae8392a5c make the book happy 2012-08-28 14:41:08 -04:00
10 changed files with 124 additions and 15 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ kernel
kernelmemfs
mkfs
.gdbinit
.vagrant

View File

@ -28,11 +28,7 @@ OBJS = \
vectors.o\
vm.o\
# Cross-compiling (e.g., on Mac OS X)
#TOOLPREFIX = i386-jos-elf-
# Using native tools (e.g., on X86 Linux)
#TOOLPREFIX =
TOOLPREFIX =
# Try to infer the correct TOOLPREFIX if not set
ifndef TOOLPREFIX
@ -51,7 +47,7 @@ TOOLPREFIX := $(shell if i386-jos-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/d
endif
# If the makefile can't find QEMU, specify its path here
#QEMU =
QEMU = qemu-system-i386
# Try to infer the correct QEMU
ifndef QEMU
@ -146,7 +142,13 @@ _forktest: forktest.o $(ULIB)
$(OBJDUMP) -S _forktest > forktest.asm
mkfs: mkfs.c fs.h
gcc -m32 -Werror -Wall -o mkfs mkfs.c
gcc -Werror -Wall -o mkfs mkfs.c
# Prevent deletion of intermediate files, e.g. cat.o, after first build, so
# that disk image changes after first build are persistent until clean. More
# details:
# http://www.gnu.org/software/make/manual/html_node/Chained-Rules.html
.PRECIOUS: %.o
UPROGS=\
_cat\
@ -164,6 +166,8 @@ UPROGS=\
_usertests\
_wc\
_zombie\
_bigtest\
#_getcount\
fs.img: mkfs README $(UPROGS)
./mkfs fs.img README $(UPROGS)
@ -200,9 +204,9 @@ QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
then echo "-gdb tcp::$(GDBPORT)"; \
else echo "-s -p $(GDBPORT)"; fi)
ifndef CPUS
CPUS := 2
CPUS := 1
endif
QEMUOPTS = -hdb fs.img xv6.img -smp $(CPUS) -m 512 $(QEMUEXTRA)
QEMUOPTS = -hdb fs.img xv6.img -smp $(CPUS) -m 512 $(QEMUEXTRA) -snapshot
qemu: fs.img xv6.img
$(QEMU) -serial mon:stdio $(QEMUOPTS)

21
Vagrantfile vendored Normal file
View File

@ -0,0 +1,21 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty64"
# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
end
config.vm.provision :shell, path: "vagrantprov.sh"
end

51
bigtest.c Normal file
View File

@ -0,0 +1,51 @@
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"
int
main()
{
char buf[512];
int fd, i, sectors;
fd = open("big.file", O_CREATE | O_WRONLY);
if(fd < 0){
printf(2, "big: cannot open big.file for writing\n");
exit();
}
sectors = 0;
while(1){
*(int*)buf = sectors;
int cc = write(fd, buf, sizeof(buf));
if(cc <= 0)
break;
sectors++;
if (sectors % 100 == 0)
printf(2, ".");
}
printf(1, "\nwrote %d sectors\n", sectors);
close(fd);
fd = open("big.file", O_RDONLY);
if(fd < 0){
printf(2, "big: cannot re-open big.file for reading\n");
exit();
}
for(i = 0; i < sectors; i++){
int cc = read(fd, buf, sizeof(buf));
if(cc <= 0){
printf(2, "big: read error at sector %d\n", i);
exit();
}
if(*(int*)buf != i){
printf(2, "big: read the wrong data (%d) for sector %d\n",
*(int*)buf, i);
exit();
}
}
exit();
}

19
getcount.c Normal file
View File

@ -0,0 +1,19 @@
#include "types.h"
#include "user.h"
#include "syscall.h"
int
main(int argc, char *argv[])
{
printf(1, "initial fork count %d\n", getcount(SYS_fork));
if (fork() == 0) {
printf(1, "child fork count %d\n", getcount(SYS_fork));
printf(1, "child write count %d\n", getcount(SYS_write));
} else {
wait();
printf(1, "parent fork count %d\n", getcount(SYS_fork));
printf(1, "parent write count %d\n", getcount(SYS_write));
}
printf(1, "wait count %d\n", getcount(SYS_wait));
exit();
}

4
ide.c
View File

@ -134,11 +134,11 @@ iderw(struct buf *b)
if(b->dev != 0 && !havedisk1)
panic("iderw: ide disk 1 not present");
acquire(&idelock); //DOC: acquire-lock
acquire(&idelock); //DOC:acquire-lock
// Append b to idequeue.
b->qnext = 0;
for(pp=&idequeue; *pp; pp=&(*pp)->qnext) //DOC: insert-queue
for(pp=&idequeue; *pp; pp=&(*pp)->qnext) //DOC:insert-queue
;
*pp = b;

9
mkfs.c
View File

@ -11,10 +11,12 @@
#include "stat.h"
#include "param.h"
int nblocks = 985;
#define static_assert(a, b) do { switch (0) case 0: case (a): ; } while (0)
int nblocks = 25000;
int nlog = LOGSIZE;
int ninodes = 200;
int size = 1024;
int size = 25045;
int fsfd;
struct superblock sb;
@ -64,6 +66,9 @@ main(int argc, char *argv[])
char buf[512];
struct dinode din;
static_assert(sizeof(int) == 4, "Integers must be 4 bytes!");
if(argc < 2){
fprintf(stderr, "Usage: mkfs fs.img files...\n");
exit(1);

1
mmu.h
View File

@ -142,6 +142,7 @@ struct segdesc {
// Address in page table or page directory entry
#define PTE_ADDR(pte) ((uint)(pte) & ~0xFFF)
#define PTE_FLAGS(pte) ((uint)(pte) & 0xFFF)
#ifndef __ASSEMBLER__
typedef uint pte_t;

6
vagrantprov.sh Executable file
View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
apt-get update
apt-get install -y qemu-system-x86
apt-get install -y gdb
echo "set auto-load safe-path /" > /home/vagrant/.gdbinit

5
vm.c
View File

@ -311,7 +311,7 @@ copyuvm(pde_t *pgdir, uint sz)
{
pde_t *d;
pte_t *pte;
uint pa, i;
uint pa, i, flags;
char *mem;
if((d = setupkvm()) == 0)
@ -322,10 +322,11 @@ copyuvm(pde_t *pgdir, uint sz)
if(!(*pte & PTE_P))
panic("copyuvm: page not present");
pa = PTE_ADDR(*pte);
flags = PTE_FLAGS(*pte);
if((mem = kalloc()) == 0)
goto bad;
memmove(mem, (char*)p2v(pa), PGSIZE);
if(mappages(d, (void*)i, PGSIZE, v2p(mem), PTE_W|PTE_U) < 0)
if(mappages(d, (void*)i, PGSIZE, v2p(mem), flags) < 0)
goto bad;
}
return d;