theseus-os / Theseus

Theseus is a modern OS written from scratch in Rust that explores 𝐢𝐧𝐭𝐫𝐚𝐥𝐢𝐧𝐠𝐮𝐚𝐥 𝐝𝐞𝐬𝐢𝐠𝐧: closing the semantic gap between compiler and hardware by maximally leveraging the power of language safety and affine types. Theseus aims to shift OS responsibilities like resource management into the compiler.
https://www.theseus-os.com/
MIT License
2.87k stars 172 forks source link

Frame Allocator can create duplicate free regions during initialization #1105

Closed Ramla-I closed 3 weeks ago

Ramla-I commented 1 month ago

The current code catches the mistake and reports an error. The duplicate region is created due to a bug in the check_and_add_free_region function. After returning from a recursive call, the original area's end frame should be updated to not include the region that was just added to the free list.

I believe there is an unspoken assumption that the list of reserved regions will be in ascending order, but that is not always the case.

In the screenshots below, the original code adds the region 0x2098000..=0x1FFDE000 twice.

Screenshot_w_bug Screenshot_w_fix