Executing Programs: Page Fault if cleaning up

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
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Executing Programs: Page Fault if cleaning up

Post by pcmattman »

Hi everyone,

I've been having some trouble as of late in my hobby kernel when running programs from my shell.

Some background first: I use reference counting for mapped pages, and whenever a process dies the kernel goes through its page directory and frees any unused pages (ie, ref count = 0). This works great for userspace processes and means the program doesn't have to keep track of memory.

However, I get stuck whenever I try to clean up after kernel threads have finished running. At the moment I only clean up their stacks, but somehow this causes running a program from my shell (or using execve in the kernel) to page fault. From my backtrace I find that it's faulting from memcpy - len=4096, i=30xx, dest=0x---f1000.

I think it must be something to do with the stack getting trashed when I clean up the kernel thread space, as without cleaning up kernel threads when they die I end up having no problems whatsoever.

If anyone can provide any ideas as to why this might happen and how to avoid it, that'd be great. I can provide code if you need it (I can't in this post as I don't have it at the moment).

Thanks!

EDIT: Just thought I'd mention, the programs I run for my tests in this case are objdump, nasm, and ld (all with -v as an argument) each running natively under my OS. The shell is my own, written from scratch. However, execve even in the kernel space (not from a shell) fails in the same way, so I'm led to believe that it must be something else.
Post Reply