I apologize if this is a weird problem and if this is a little too broad, but I’m experiencing serious issues with my OS’s memory allocator, which is liballoc
.
When I’m working with my EXT2 driver, liballoc is responsible for allocating all of the structures that the driver uses, most notable fsNode_t
and a few ext2-specific structures. However, if I allocate too much, it doesn’t matter if the memory is freed, liballoc causes a page fault in the code at a different address depending on where the problem occurs.
Link to the ext2 driver here. As of writing the current problem will happen in the ext2_finddir
function, at the very last part where it allocates a VFS node to return.
liballoc can be found here.
liballoc requires a few wrapper functions to properly work, which could be a source of trouble but I don’t think so, as with debug output liballoc crashes when it’s trying to figure out where to allocate to. The wrapper functions can be found here
Another part about my OS is that liballoc isn’t enabled until later in the boot process (terrible, I know), and some definitely buggy code is used before it’s enabled. Link to that weird code here.
Here is the debug output of when the fault happens (NOTE: the =====
stuff is what my kernel panic handler prints, meaning that’s when the panic happens):
liballoc: 108141 PREFIX(malloc)( 160 ): CASE 4.2: returning 820D0
liballoc: 108141 PREFIX(malloc)( 4128 ): CASE 4.1: returning 821A0
liballoc: 108141 PREFIX(malloc)( 4128 ): CASE 4.1: returning 821A0
liballoc: 108141 PREFIX(malloc)( 4128 ): CASE 4.1: returning 831E0
liballoc: 108141 PREFIX(malloc)( 41 ): CASE 4.1: returning 84210
liballoc: 108202 PREFIX(free)( 84200 ): OK
liballoc: 108141 PREFIX(malloc)( 48 ): CASE 4.1: returning 84210
liballoc: 108202 PREFIX(free)( 82190 ): OK
liballoc: 108202 PREFIX(free)( 820C0 ): OK
liballoc: 108141 PREFIX(malloc)( 4128 ): CASE 4.2: returning 821A0
liballoc: 108141 PREFIX(malloc)( 228 ): ===========================================================
You can see in the above that the panic happens during memory allocation, or when liballoc is determining the case to use for allocation. (no wrapper functions have been called, they are only used once or twice to allocate some pages)
I thought the fault might be with liballoc, so I wrote some test code to allocate a large amount of memory (~120KB) and some more after that in increments, and then free it all, but that usually passes. However, it appears the ext2 driver leaves liballoc in some sort of corrupted state, where all tests fail (not just the large allocation) only if ext2 initializes.
The full GitHub repo is available here, if anyone wants to look: link
I honestly have exhausted what I can do, so I thought I’d ask for help. Thank you! Please let me know if I need to clarify, and I will happily do so.