Page fault from JamesM's kernel heap tutorial

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
CD1212
Posts: 6
Joined: Tue May 19, 2009 5:59 am

Page fault from JamesM's kernel heap tutorial

Post 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
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Page fault from JamesM's kernel heap tutorial

Post 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.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
CD1212
Posts: 6
Joined: Tue May 19, 2009 5:59 am

Re: Page fault from JamesM's kernel heap tutorial

Post 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?
User avatar
Creature
Member
Member
Posts: 548
Joined: Sat Dec 27, 2008 2:34 pm
Location: Belgium

Re: Page fault from JamesM's kernel heap tutorial

Post 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.
When the chance of succeeding is 99%, there is still a 50% chance of that success happening.
User avatar
djsilence
Member
Member
Posts: 70
Joined: Wed Oct 01, 2008 11:18 am
Location: Ukraine, Kiev
Contact:

Re: Page fault from JamesM's kernel heap tutorial

Post 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.
Don't think a ****, but in ukrainian schools English is TOO BAD!
Post Reply