. map text (kernel's and processes') in readonly

. 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.
This commit is contained in:
Ben Gras 2008-12-18 15:35:22 +00:00
parent f0000078c3
commit 3121eec6bd
6 changed files with 25 additions and 14 deletions

View File

@ -426,9 +426,7 @@ PRIVATE PUBLIC phys_bytes alloc_pages(int pages, int memflags)
#define ALLOCRETURNCHECK \ #define ALLOCRETURNCHECK \
availbytes(&avail2, &chunks2); \ availbytes(&avail2, &chunks2); \
vm_assert(avail1 - bytes == avail2); \ vm_assert(avail1 - bytes == avail2); \
vm_assert(chunks1 == chunks2 || chunks1-1 == chunks2); \ vm_assert(chunks1 == chunks2 || chunks1-1 == chunks2);
if(verbosealloc) \
printf("memory: 0x%lx bytes in %d chunks\n", avail2, chunks2);
#else #else
#define ALLOCRETURNCHECK #define ALLOCRETURNCHECK
#endif #endif
@ -495,9 +493,7 @@ PRIVATE PUBLIC void free_pages(phys_bytes pageno, int npages)
#define FREERETURNCHECK \ #define FREERETURNCHECK \
availbytes(&avail2, &chunks2); \ availbytes(&avail2, &chunks2); \
vm_assert(avail1 + origsize == avail2); \ vm_assert(avail1 + origsize == avail2); \
vm_assert(chunks1 == chunks2 || chunks1+1 == chunks2 || chunks1-1 == chunks2); \ vm_assert(chunks1 == chunks2 || chunks1+1 == chunks2 || chunks1-1 == chunks2);
if(verbosealloc) \
printf("memory: 0x%lx bytes in %d chunks\n", avail2, chunks2);
#else #else
#define FREERETURNCHECK #define FREERETURNCHECK
#endif #endif

View File

@ -361,7 +361,7 @@ PUBLIC int proc_new(struct vmproc *vmp,
vmp->vm_offset = vstart; vmp->vm_offset = vstart;
/* page mapping flags for code */ /* page mapping flags for code */
#define TEXTFLAGS (PTF_PRESENT | PTF_USER | PTF_WRITE) #define TEXTFLAGS (PTF_PRESENT | PTF_USER)
SANITYCHECK(SCL_DETAIL); SANITYCHECK(SCL_DETAIL);
if(text_bytes > 0) { if(text_bytes > 0) {
if(!map_page_region(vmp, vstart, 0, text_bytes, if(!map_page_region(vmp, vstart, 0, text_bytes,

View File

@ -20,8 +20,6 @@ u32_t data1[200];
EXTERN long vm_sanitychecklevel; EXTERN long vm_sanitychecklevel;
#endif #endif
int verbosealloc;
#define VMP_SYSTEM _NR_PROCS #define VMP_SYSTEM _NR_PROCS
/* vm operation mode state and values */ /* vm operation mode state and values */

View File

@ -781,12 +781,12 @@ PUBLIC int pt_mapkernel(pt_t *pt)
/* Map in text. flags: don't write, supervisor only */ /* Map in text. flags: don't write, supervisor only */
if((r=pt_writemap(pt, KERNEL_TEXT, KERNEL_TEXT, KERNEL_TEXT_LEN, 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; return r;
/* Map in data. flags: read-write, supervisor only */ /* Map in data. flags: read-write, supervisor only */
if((r=pt_writemap(pt, KERNEL_DATA, KERNEL_DATA, KERNEL_DATA_LEN, 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 r;
return OK; return OK;

View File

@ -247,6 +247,23 @@ PRIVATE void vm_init(void)
*/ */
kernel_top_bytes = find_kernel_top(); 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. */ /* Give these processes their own page table. */
for (ip = &image[0]; ip < &image[NR_BOOT_PROCS]; ip++) { for (ip = &image[0]; ip < &image[NR_BOOT_PROCS]; ip++) {
int s; int s;

View File

@ -12,7 +12,7 @@
#define ABS2CLICK(a) ((a) >> CLICK_SHIFT) #define ABS2CLICK(a) ((a) >> CLICK_SHIFT)
/* Compile in asserts and custom sanity checks at all? */ /* Compile in asserts and custom sanity checks at all? */
#define SANITYCHECKS 0 #define SANITYCHECKS 1
#define VMSTATS 1 #define VMSTATS 1
/* If so, this level: */ /* If so, this level: */