<< Back to Writing Codezero Applications
Pagers manipulate the address space of their children using privileged address space manipulation functions.
Address spaces are created, cleared and destroyed by l4_thread_control system call during thread creation. However, the modification of existing address spaces are done by the l4_map and l4_unmap system calls.
Below are the code snippets for typical address space manipulation operations by pagers.
Below is the Microkernel's architecture-specific structure for describing a page fault:
/* Kernel's data about the fault */ typedef struct fault_kdata { u32 faulty_pc; /* In DABT: Aborting PC, In PABT: Same as FAR */ u32 fsr; /* In DABT: DFSR, In PABT: IFSR */ u32 far; /* In DABT: DFAR, in PABT: IFAR */ pte_t pte; /* Faulty page table entry */ } __attribute__ ((__packed__)) fault_kdata_t;
Below is the code snippet taken from a pager during the handling of a page fault from a task:
... /* Map the new page to faulting task */ l4_map((void *)page_to_phys(page), (void *)page_align(fault->address), 1, (reason & VM_READ) ? MAP_USR_RO : MAP_USR_RW, fault->task->tid); dprintf("%s: Mapped 0x%x as writable to tid %d.\n", __TASKNAME__, page_align(fault->address), fault->task->tid); return 0; }
Below is the code snippet taken from a pager during the unmapping of a virtual memory address range from a client task:
/* Destroys a single vma from a task and unmaps its range from task space */ int vma_destroy_single(struct tcb *task, struct vm_area *vma) { int ret; /* Release all object links */ if ((ret = vma_drop_merge_delete_all(vma)) < 0) return ret; /* * Unmap the whole vma address range. Note that this * may return -1 if the area was already faulted, which * means the area was unmapped before being touched. */ l4_unmap((void *)__pfn_to_addr(vma->pfn_start), vma->pfn_end - vma->pfn_start, task->tid); /* Unlink and delete vma */ list_remove(&vma->list); kfree(vma); return 0; }