Page 1 of 1

Page Fault when printf using newlib in user mode

Posted: Sat Nov 15, 2025 10:55 pm
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);
}

Re: Page Fault when printf using newlib in user mode

Posted: Sun Nov 16, 2025 12:36 am
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.

Re: Page Fault when printf using newlib in user mode

Posted: Sun Nov 30, 2025 12:06 pm
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.