Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


struct vm_area_struct * vma;
unsigned long address;
unsigned long page;
int write, si_code;
int fault;
...

/* get the address */
address = read_cr2();
...

Table 4-1: Meaning of Page Fault Error Codes on IA-32

Bit Set (1) Not set (0)

0 No page present in RAM Protection fault (insufficient access permission)

1 Read access Write access

2 Privileged kernel mode User mode

Once a large number of variables have been declared for subsequent use, the kernel stores the address of
the location that triggered the fault inaddress.^18

arch/i386/mm/fault.c
tsk = current;

si_code = SEGV_MAPERR;

/*
* We fault-in kernel-space virtual memory on-demand. The
* ’reference’ page table is init_mm.pgd.
*
* NOTE! We MUST NOT take any locks for this case. We may
* be in an interrupt or a critical region, and should
* only copy the information from the master page table,
* nothing more.
*
* This verifies that the fault happens in kernel space
* (error_code & 4) == 0, and that the fault was not a
* protection error (error_code & 9) == 0.
*/
if (unlikely(address >= TASK_SIZE)) {
if (!(error_code & 0x0000000d) && vmalloc_fault(address) >= 0)
return;
/*
* Don’t take the mm semaphore here. If we fixup a prefetch
* fault we could otherwise deadlock.

(^18) On IA-32 processors, the address is held in registerCR2, whose contents are copied toaddressbyread_cr2. The processor-
specific details are of no interest.

Free download pdf