My kernels VFS code is page faulting on attempting to call the handler for reading the /dev/null device. It is defined as a function pointer to the read_null function in device_null_create(). The page fault occurs immediately when read_null is called from the vfs_node_t object held in the filesystem tree. The cause of this is an invalid pointer to 0xF000FF53, which is a garbage address (at least, I believe it is; my kernel at this point had only allocated to about 0x2F4000 of usable memory, as it is a lower half kernel).
My question is: What's causing my kernel to call that address instead of the proper address of my function?
Single-stepping in gdb has revealed little (or maybe it's because I don't use gdb often), and everything seems ("seems") okay until read_null is called. I have posted some relevant sources and output as well, and attempted to narrow it down to related and suspected functions.
main.c
Code: Select all
vfs_mount("/dev/null", device_null_create());
vfs_print_tree_node(vfs_tree->root,0);
printf("Reading from /dev/null\n");
vfs_node_t *null = kopen("/dev/null", 0);
printf("null returns:%d\n",read_vfs(null,0,0,0));
Code: Select all
uint32_t read_vfs(vfs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer)
{
if (node->read) {
printf("read_vfs: node->read = 0x%X\n",node->read);
uint32_t ret = node->read(node, offset, size, buffer);
return ret;
} else {
return 0;
}
}
Code: Select all
uint32_t read_null(vfs_node_t *node, uint32_t offset, uint32_t size, uint8_t *buffer) {
return 0;
}
...
vfs_node_t *device_null_create()
{
vfs_node_t * fnode = malloc(sizeof(vfs_node_t));
memset(fnode, 0x00, sizeof(vfs_node_t));
fnode->inode = 0;
strcpy(fnode->name, "null");
fnode->uid = 0;
fnode->gid = 0;
fnode->flags = VFS_CHARDEVICE;
fnode->read = read_null;
fnode->write = write_null;
fnode->open = open_null;
fnode->close = close_null;
fnode->readdir = NULL;
fnode->finddir = NULL;
return fnode;
}
Code: Select all
[x86]:Loading x86 components...
[CPU]:GDT Setup
[CPU]:IDT Setup
[IRQ]:Registered irq handler for 32 (IRQ0) at 0x10BD10
[IRQ]:Registered irq handler for 14 at 0x109EF0
[MEM]:Initialising and populating memory...
[MEM]:Marked 0x2F4000 (3096576) frames as dirty
[MEM]:Allocating Kernel Reserved Area...
[MEM]:Creating heap...!
[MEM]:Done allocating initial memory!
[x86]:Done starting hardware!
[KERN]:CoreLibs initialising...
[KERN]:Running Debug Kernel! Some things might not work properly!
[IO]:Verifiying timer / interrupts (waiting 10 ticks)
[KERN]:Finished initialising CoreLibs!
[VIDEO]:BGA unsupported, setting terminal as output
[VFS]:Starting VFS...
sbrk: allocating 1 pages to cover 0x1000 bytes
[root] -> (empty)
[VFS]:Mounting devices...
[VFS]:Searching for dev
[VFS]:Did not find dev, making it.
[VFS]:Searching for null
[VFS]:Did not find null, making it.
[root] -> (empty)
dev -> (empty)
null -> 0x2f4091 (null)
Reading from /dev/null
read_vfs: node->read = 0xF000FF53
[PF]:Page fault!
[PF]:Addr:0xF000FF53. present 1 rw 0 us 0 res 0 id 0
[SYS]:Encountered interrupt 14 (Page Fault)!
[KERN]:Halting!
Registers:
| eax 0x22; ebx 0x0; ecx 0xF000FF53; edx 0x0
| ??? 0x104AB8; ebp 0x104B08; err 0x0; efl 0x202
| usp 0x105E31; eip 0x104B08; esi 0x0; edi 0x0
| cs 0x8; ds 0x10; es 0x10; fs 0x10
| gs 0x10
Thanks,
Lionel