Page 1 of 1

Page fault from JamesM's kernel heap tutorial

Posted: Thu Sep 24, 2009 2:10 pm
by CD1212
Ive been sortof re-writing JamesM's tutorials, just to gain some understanding of how paging and the heap works, anyway in my create heap function I always get a page fault exception on the line 'heap->index = temp;'. I could have placed the array in the same line but I wanted to check it wasnt the kPlace_OrderedArray function that was causing the problems. I cant really understand whats wrong.

Code: Select all

struct kHeap *heap = (struct kHeap*)kMalloc(sizeof(struct kHeap));
	
	// Check its page aligned
	ASSERT(start % 0x1000 == 0);
	ASSERT(end % 0x1000 == 0);
	
	struct kOrderedArray temp = kPlace_OrderedArray((void*)start, HEAP_INDEX_SIZE, &kHeap_HeaderLessThan);
	
	heap->index = temp;
	
	start += sizeof(kType) * HEAP_INDEX_SIZE;
Any help would be greatly appreciated!

Would it matter that I didnt typedef the kOrderedArray struct? EDIT: No it doesnt

Re: Page fault from JamesM's kernel heap tutorial

Posted: Thu Sep 24, 2009 2:59 pm
by Creature
There's little I can say about this as it's only a small section of your code. I can however point you to the fact that you're copying the array here:

Code: Select all

struct kOrderedArray temp = kPlace_OrderedArray((void*)start, HEAP_INDEX_SIZE, &kHeap_HeaderLessThan);

// I'm presuming heap->index isn't a pointer, so that means 'temp' will be entirely copied into 'heap->index'.   
heap->index = temp;
Which is probably not the problem, but it might speed up things a little to just use a pointer to begin with or something.

You should also know that JamesM's 'OrderedArray' can actually simply be replaced by a simple (possibly doubly) linked list which lists heap headers from small to large and that 'Footer' is pretty much obsolete (except for easy of use, but you could just give every header a Previous member or something).

JamesM also said multiple times that he's probably least proud of his heap tutorial. He started a new series of tutorials (a while ago, now, I think) which can be found here. You can find the heap in Source -> Browse -> trunk -> src.

Hope this was of some help to you.

Re: Page fault from JamesM's kernel heap tutorial

Posted: Fri Sep 25, 2009 9:02 am
by CD1212
Ahh, thats fantastic, thanks Creature!

Btw the way JamesM, your tutorials have been amazingly helpful! :D

EDIT: Out of interest, is there any documentation to go with the sources in the repository?

Re: Page fault from JamesM's kernel heap tutorial

Posted: Fri Sep 25, 2009 12:15 pm
by Creature
CD1212 wrote:EDIT: Out of interest, is there any documentation to go with the sources in the repository?
I'm not sure but I don't think so. AFAIK JamesM was going to write a new series of tutorials (using that page as SVN). He apparently wanted to get all the source code first and then write the actual tutorials.

Re: Page fault from JamesM's kernel heap tutorial

Posted: Sun Oct 11, 2009 4:35 pm
by djsilence
what emulator do you use? see, JamesM tutorials works for example on bochs and give some errors on vmware... it is strange, but working of tutorials depends on emulator you use.