summaryrefslogtreecommitdiff
path: root/vm.c
diff options
context:
space:
mode:
authorRobert Morris <[email protected]>2010-09-20 06:00:22 -0400
committerRobert Morris <[email protected]>2010-09-20 06:00:22 -0400
commita9183883b88bfccd1c6a62e27621b2c892d50b67 (patch)
tree5cae8d40cf5e91ea52d7aeb281e3baf5828c45e0 /vm.c
parent26d11ee8dc60fed78c8b34d15670eb6640d92129 (diff)
downloadxv6-labs-a9183883b88bfccd1c6a62e27621b2c892d50b67.tar.gz
xv6-labs-a9183883b88bfccd1c6a62e27621b2c892d50b67.tar.bz2
xv6-labs-a9183883b88bfccd1c6a62e27621b2c892d50b67.zip
map kernel instructions r/o
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/vm.c b/vm.c
index c57fa53..cd6b255 100644
--- a/vm.c
+++ b/vm.c
@@ -125,6 +125,9 @@ pde_t*
setupkvm(void)
{
pde_t *pgdir;
+ extern char etext[];
+ char *rwstart = PGROUNDDOWN(etext) - PGSIZE;
+ uint rwlen = (uint)rwstart - 0x100000;
// Allocate page directory
if(!(pgdir = (pde_t *) kalloc()))
@@ -132,8 +135,10 @@ setupkvm(void)
memset(pgdir, 0, PGSIZE);
if(// Map IO space from 640K to 1Mbyte
!mappages(pgdir, (void *)USERTOP, 0x60000, USERTOP, PTE_W) ||
- // Map kernel and free memory pool
- !mappages(pgdir, (void *)0x100000, PHYSTOP-0x100000, 0x100000, PTE_W) ||
+ // Map kernel instructions
+ !mappages(pgdir, (void *)0x100000, rwlen, 0x100000, 0) ||
+ // Map kernel data and free memory pool
+ !mappages(pgdir, rwstart, PHYSTOP-(uint)rwstart, (uint)rwstart, PTE_W) ||
// Map devices such as ioapic, lapic, ...
!mappages(pgdir, (void *)0xFE000000, 0x2000000, 0xFE000000, PTE_W))
return 0;