Page 1 of 1

Missing Page Directory & Segfault in User Process

Posted: Mon Nov 30, 2015 8:01 am
by 0fb1d8
Hello,
I have recently been encountering a rather bizarre bug in my OS Arcrascent while testing some user applications. All of my UNIX syscalls, at least as I have tested them, are working fine and my I/O also seems to be OK. But whenever I try to execute malloc(), free(), or pretty much any C dynamic memory-allocating function in a user application, my paging manager keeps saying that it is "missing page directory while mapping ... -> ..." in the sbrk() syscall, and attempts to set a new page directory. And when I try to write to any of these dynamically allocated memory regions, I simply get a Page Fault (#PF) in the application, leading to its automatic termination by my process manager. I have verified that I am setting all of the read, write, global, and user permissions for the pages I newly map for the user application.

What might be the problem here? Has anyone encountered an issue similar to this?

P.S. This is the code for the application, btw.

Code: Select all

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

int main() {
	char* mem = (char*)malloc(10);
	for (int i = 0; i < 10; ++i)
		mem[i] = i;
	return 0;
}
Thanks.

Re: Missing Page Directory & Segfault in User Process

Posted: Tue Dec 01, 2015 4:25 pm
by iansjack
I think you need to look at the code for your implementation of malloc() rather than the application that calls it.

Re: Missing Page Directory & Segfault in User Process

Posted: Wed Dec 02, 2015 1:42 am
by Combuster
Simple debugger task:
perform an "info tab" at the start of malloc()
perform an "info tab" at the end of malloc()
find the differences
check if the return value of malloc() is within these differences.

Re: Missing Page Directory & Segfault in User Process

Posted: Thu Dec 03, 2015 6:40 am
by 0fb1d8
Thank you all for your kind responses.
However, the application is being linked against Newlib, and my implementation of malloc() in the kernel is pretty much irrelevant. I believe there may be a compatibility issue between Newlib's implementation of malloc() and Arcrascent's memory manager infrastructure. GDB debugging neither is possible here, as the application is being run in the context of my operating system, which is not capable of running GDB due to the very bug that I'm trying to fix right now.

Are there any other ideas?

Thanks.

Re: Missing Page Directory & Segfault in User Process

Posted: Fri Dec 04, 2015 1:45 am
by iansjack
Although you are using Newlib you still have to provide some memory information/management to the library functions. Check your implementation of sbrk().

As for debugging, run the OS under a virtual machine such as qemu. You then have access to gdb and all it's debugging tools.

Re: Missing Page Directory & Segfault in User Process

Posted: Fri Dec 04, 2015 4:57 am
by Combuster
I was referring to Bochs' integrated debugger, which allows you to debug the entire machine state regardless of the guest OS.