[CSE]  Advanced Operating Systems 
COMP9242 2011/S2 
CRICOS Provider
Number: 00098G

PRINTER Printer-Friendly Version

M3: A pager

Use your memory manager from M2 to write a simple pager.

Current Implementation

The current implementation simply maps in a page for any address a user process faults on. This means that pages can be mapped in for NULL and user processes can execute code in non-readable segments. Additionally, the executables themselves are mapped in with untracked frames. Finally, the current malloc implementation uses a static array - it must be changed to use virtual memory (see libs/sel4/libsos/src/sys_morecore.c).

The Milestone

In this milestone you will:
  • Implement a simple pager to map virtual memory addresses to frame table entries.
  • Design your user level address space layout and permissions - including the stack, heap and other sections.
  • Change the current user malloc implementation to use virtual memory, not a static array (just allow it to fault in memory)
  • Modify the bootstrap ELF-loading code to use your pager mapping functions, not the frame table directly

Design alternatives

Probably the main thing that you should consider here is the layout of your processes address space. Some things you will want to consider is where you place various parts of memory such as the stack, heap and code segments. You may also have some other regions in your process address space, one of these is the IPC Buffer.

You should also think about if you want to make different ranges of the address space have different permissions, eg: you may want to make code read-only to prevent bugs, or have a guard page at the end of your stack to prevent overflow.


The main demonstration here will be to show a user process running with a high stack pointer (> 0x2000000). You should also demonstrate a user process using malloc() from a heap.

#define NPAGES 128

/* called from pt_test */
static void
do_pt_test( char *buf )
    int i;

    /* set */
    for(i = 0; i < NPAGES; i += 4)
	buf[i * 1024] = i;

    /* check */
    for(i = 0; i < NPAGES; i += 4)
	assert(buf[i*1024] == i);

static void
pt_test( void )
    /* need a decent sized stack */
    char buf1[NPAGES * 1024], *buf2 = NULL;

    /* check the stack is above phys mem */
    assert((void *) buf1 > (void *) 0x2000000);

    /* stack test */

    /* heap test */
    buf2 = malloc(NPAGES * 1024);

You should also be able to explain to the tutor how your code works and any design decisions you took.

Last modified: 09 Aug 2011.