Missing Page Directory & Segfault in User Process

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
User avatar
0fb1d8
Member
Member
Posts: 27
Joined: Mon Nov 03, 2014 2:20 pm
Location: Seoul, South Korea
Contact:

Missing Page Directory & Segfault in User Process

Post 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.
Joonyoung Lee
Student at 한성과학고등학교(Hansung Science High School) & Ambitious OSDever
Arcrascent OS | Source <-- My OSDev Project
“One of my most productive days was throwing away 1000 lines of code.” - Ken Thompson
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Missing Page Directory & Segfault in User Process

Post by iansjack »

I think you need to look at the code for your implementation of malloc() rather than the application that calls it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Missing Page Directory & Segfault in User Process

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
0fb1d8
Member
Member
Posts: 27
Joined: Mon Nov 03, 2014 2:20 pm
Location: Seoul, South Korea
Contact:

Re: Missing Page Directory & Segfault in User Process

Post 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.
Joonyoung Lee
Student at 한성과학고등학교(Hansung Science High School) & Ambitious OSDever
Arcrascent OS | Source <-- My OSDev Project
“One of my most productive days was throwing away 1000 lines of code.” - Ken Thompson
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Missing Page Directory & Segfault in User Process

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Missing Page Directory & Segfault in User Process

Post by Combuster »

I was referring to Bochs' integrated debugger, which allows you to debug the entire machine state regardless of the guest OS.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply