]> Zhao Yanbai Git Server - minix.git/commitdiff
. map text (kernel's and processes') in readonly
authorBen Gras <ben@minix3.org>
Thu, 18 Dec 2008 15:35:22 +0000 (15:35 +0000)
committerBen Gras <ben@minix3.org>
Thu, 18 Dec 2008 15:35:22 +0000 (15:35 +0000)
 . map kernel in non-user
 . don't map in first pages of kernel code and data
   if possible

these first pages could actually be freed but as the
kernel isn't allowed to touch them either we can't reuse
them until VM has totally taken over page table management
and kernel doesn't rely on identity mapping any more.

servers/vm/alloc.c
servers/vm/exec.c
servers/vm/glo.h
servers/vm/i386/pagetable.c
servers/vm/main.c
servers/vm/vm.h

index fe97cf39ba06b1df391a57e669160829dec34c33..e28f4574d0f9996d60ef298b24bb05132d37ff3e 100644 (file)
@@ -426,9 +426,7 @@ PRIVATE PUBLIC phys_bytes alloc_pages(int pages, int memflags)
 #define ALLOCRETURNCHECK                       \
        availbytes(&avail2, &chunks2);          \
        vm_assert(avail1 - bytes == avail2);    \
-       vm_assert(chunks1 == chunks2 || chunks1-1 == chunks2);  \
-       if(verbosealloc)                                        \
-               printf("memory: 0x%lx bytes in %d chunks\n", avail2, chunks2);
+       vm_assert(chunks1 == chunks2 || chunks1-1 == chunks2);
 #else
 #define ALLOCRETURNCHECK
 #endif
@@ -493,11 +491,9 @@ PRIVATE PUBLIC void free_pages(phys_bytes pageno, int npages)
 
 #if SANITYCHECKS
 #define FREERETURNCHECK                                                                \
-       availbytes(&avail2, &chunks2);                                          \
-       vm_assert(avail1 + origsize  == avail2);                                \
-       vm_assert(chunks1 == chunks2 || chunks1+1 == chunks2 || chunks1-1 == chunks2);  \
-       if(verbosealloc)                                                        \
-               printf("memory: 0x%lx bytes in %d chunks\n", avail2, chunks2);
+       availbytes(&avail2, &chunks2);                                  \
+       vm_assert(avail1 + origsize  == avail2);                        \
+       vm_assert(chunks1 == chunks2 || chunks1+1 == chunks2 || chunks1-1 == chunks2);
 #else
 #define FREERETURNCHECK
 #endif
index 06d514b0469d168344d3aec31e515cf97300951c..e486f1befaa67098bf97facb6af94bc8069cba7e 100644 (file)
@@ -361,7 +361,7 @@ PUBLIC int proc_new(struct vmproc *vmp,
        vmp->vm_offset = vstart;
 
        /* page mapping flags for code */
-#define TEXTFLAGS (PTF_PRESENT | PTF_USER | PTF_WRITE)
+#define TEXTFLAGS (PTF_PRESENT | PTF_USER)
        SANITYCHECK(SCL_DETAIL);
        if(text_bytes > 0) {
                if(!map_page_region(vmp, vstart, 0, text_bytes,
index 2566830d80c112c7fac002981c3cde2b030efe12..065bee9c459bf1837466093c48cf2864e246adff 100644 (file)
@@ -20,8 +20,6 @@ u32_t data1[200];
 EXTERN long vm_sanitychecklevel;
 #endif
 
-int verbosealloc;
-
 #define VMP_SYSTEM     _NR_PROCS
 
 /* vm operation mode state and values */
index e80a5e313ac54b9bdfd3361baa5910bc862ce54a..bda5f5c4cfefb515fc7604d2bc2ffd001c46fc88 100644 (file)
@@ -781,12 +781,12 @@ PUBLIC int pt_mapkernel(pt_t *pt)
 
         /* Map in text. flags: don't write, supervisor only */
         if((r=pt_writemap(pt, KERNEL_TEXT, KERNEL_TEXT, KERNEL_TEXT_LEN,
-                 I386_VM_PRESENT | I386_VM_USER | I386_VM_WRITE, 0)) != OK)
+               I386_VM_PRESENT, 0)) != OK)
                return r;
  
         /* Map in data. flags: read-write, supervisor only */
         if((r=pt_writemap(pt, KERNEL_DATA, KERNEL_DATA, KERNEL_DATA_LEN,
-                I386_VM_PRESENT | I386_VM_USER | I386_VM_WRITE, 0)) != OK)
+               I386_VM_PRESENT|I386_VM_WRITE, 0)) != OK)
                return r;
 
        return OK;
index cec3b0fa2bf1a8031e008752637c81e8204d697f..624a5bb17dd8a504630b3d9fe12bb930ed37c7cf 100644 (file)
@@ -247,6 +247,23 @@ PRIVATE void vm_init(void)
         */
         kernel_top_bytes = find_kernel_top();
 
+       /* Can first kernel pages of code and data be (left) mapped out?
+        * If so, change the SYSTEM process' memory map to reflect this
+        * (future mappings of SYSTEM into other processes will not include
+        * first pages), and free the first pages.
+        */
+       if(vm_paged && sys_vmctl(SELF, VMCTL_NOPAGEZERO, 0) == OK) {
+               struct vmproc *vmp;
+               vmp = &vmproc[VMP_SYSTEM];
+               if(vmp->vm_arch.vm_seg[T].mem_len > 0) {
+#define DIFF CLICKSPERPAGE
+                       vmp->vm_arch.vm_seg[T].mem_phys += DIFF;
+                       vmp->vm_arch.vm_seg[T].mem_len -= DIFF;
+               }
+               vmp->vm_arch.vm_seg[D].mem_phys += DIFF;
+               vmp->vm_arch.vm_seg[D].mem_len -= DIFF;
+       }
+
        /* Give these processes their own page table. */
        for (ip = &image[0]; ip < &image[NR_BOOT_PROCS]; ip++) {
                int s;
index b305817b8f50f3806dfd247445a2299cd5c505c3..cdddf15395d6af598078fc05ea7031c0f807dafa 100644 (file)
@@ -12,7 +12,7 @@
 #define ABS2CLICK(a) ((a) >> CLICK_SHIFT)
 
 /* Compile in asserts and custom sanity checks at all? */
-#define SANITYCHECKS   0
+#define SANITYCHECKS   1
 #define VMSTATS                1
 
 /* If so, this level: */