You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Chapter 3 onward there is a bug in the Page Allocator that rears it's ugly head when you try to allocate more pages than are possible. Since for i in 0..num_pages - pages is not using checked_sub You can underflow num_pages and end up iterating way past the end of allocable memory, this will likely result in heap corruption for any allocation greater than the number of pages remaining in the heap. This is particularly troublesome because it is in an unsafe block.
Additionally, for i in 0..num_pages - pages should be for i in 0..=num_pages - pages so we can use the last page. While a minor grievance, I actually implemented this on a microcontroller that only had a single page of heap memory, which you couldn't allocate because the range doesn't include the last page in the heap... needless to say, this was detrimental to the usefulness of the allocator.
Chapter 3 onward there is a bug in the Page Allocator that rears it's ugly head when you try to allocate more pages than are possible. Since
for i in 0..num_pages - pages
is not usingchecked_sub
You can underflownum_pages
and end up iterating way past the end of allocable memory, this will likely result in heap corruption for any allocation greater than the number of pages remaining in the heap. This is particularly troublesome because it is in anunsafe
block.Additionally,
for i in 0..num_pages - pages
should befor i in 0..=num_pages - pages
so we can use the last page. While a minor grievance, I actually implemented this on a microcontroller that only had a single page of heap memory, which you couldn't allocate because the range doesn't include the last page in the heap... needless to say, this was detrimental to the usefulness of the allocator.https://github.com/sgmarz/osblog/blob/master/risc_v/chapters/ch3/src/page.rs#L137
The text was updated successfully, but these errors were encountered: