I don't understand why my code triggers a page fault with the write and present bits set.
I am following
James Molloy's tutorial. The fault occurs when I am initializing paging. The problem seems to be when the function
create_heap makes a call to
orderedArray_place:
Code:
heap_t *create_heap ( u32int start, u32int end, u32int max, u8int supervisor, u8int readonly )
{
//
heap_t *heap = ( heap_t * ) kmalloc( sizeof( heap_t ) );
...
// Initialize the index
heap -> index = orderedArray_place( ( void * ) start, HEAP_INDEX_SIZE, &header_t_less_than ); // <---
...
create_heap is called by
initialise_paging as follows:
Code:
// Initialise the kernel heap.
kheap = create_heap( KHEAP_START, KHEAP_START + KHEAP_INITIAL_SIZE, 0xCFFFF000, 0, 0 );
And the values of the constants are:
Code:
#define KHEAP_START 0xC0000000 // arbitrary
#define KHEAP_INITIAL_SIZE 0x100000 // arbitrary
#define HEAP_INDEX_SIZE 0x20000 // arbitrary
The fault appears when a call to
memset in
orderedArray_place tries to write zeros to the given location...
Code:
// Create an ordered array (uses given start location)
ordered_array_t orderedArray_place ( void *address, u32int max_size, lessthan_predicate_t less_than )
{
ordered_array_t a;
a.array = ( type_t * ) address;
memset( ( u32int * ) address, 0, max_size * sizeof( type_t ) ); // fill with zeros <---
...
I.e. during a write to the range KHEAP_START to (KHEAP_START + HEAP_INDEX_SIZE * sizeof( type_t )). What is preventing me from writing here?
My full code is
here. The relevant files (I think) are
kernelHeap,
orderedArray, and
paging.
By the way,
type_t is declared as follows:
Code:
typedef void* type_t;