Page Fault when printf using newlib in user mode

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
atomtables
Posts: 14
Joined: Fri Nov 08, 2024 5:08 pm
Libera.chat IRC: atomtables

Page Fault when printf using newlib in user mode

Post by atomtables »

Hi. I'm trying to use a printf in newlib, with rudimentary sbrk and write syscall support in my kernel. However, before it even gets to running the syscall, a page error gets thrown at the address of

Code: Select all

/newlib/libc/stdio/puts.c:88 (discriminator 1)
(CR2=00000034) because of what seems like a null pointer.

This doesn't seem to happen because of any code I wrote (at least from what I can glance obviously) because from what I've been able to glance people don't have errors until the syscall has finished running. If someone could help it would be great.

Kernel (not fully committed but the up-to-date working syscalls are in the src/primary/kernel/syscalls folder) https://github.com/atomtables/AstatineOS

newlib: https://github.com/atomtables/newlib_astatine

test program:

Code: Select all

#include <stdio.h>

void main() {
    printf("Hello, World!\n");
    while(1);
}
User avatar
iansjack
Member
Member
Posts: 4908
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Page Fault when printf using newlib in user mode

Post by iansjack »

Have you run it under gdb to determine the call sequence leading to the fault? That should at least tell you the variable containing the null pointer and you can place a watch on that variable to see how it gets set.
atomtables
Posts: 14
Joined: Fri Nov 08, 2024 5:08 pm
Libera.chat IRC: atomtables

Re: Page Fault when printf using newlib in user mode

Post by atomtables »

Thanks for the help! What ended up being the problem was something along the lines that the libc I used to compile gcc wasn't playing nice with newlib, and there were a lot of problems. After a simple recompilation (making sure that gcc targets newlib instead of my stubbed libc), it works now.
Post Reply