LibSR:Bad luck mode

From Maths
Jump to: navigation, search

Overview

The idea of "bad luck mode" is to help find bugs which may not show themselves due purely to luck. For example, malloc calls return memory that is usually aligned to 4096 bytes, this is luck, as a result, anything requiring say 16 byte alignment appears to work, but there's actually no reason for it to.

By building in bad luck mode you can have the allocators deliberately allocate stuff on "unlucky" boundaries, for example, odd byte boundaries if no alignment is specified. This'll cause failures if alignment is used where it was only okay before by luck. There is a performance cost of course! Processors like aligned things, that's why we do it!

Memory

  • LIBSR_BAD_LUCK_ODD_ALIGN_UNALIGNED_ALLOCATIONS - any memory allocations without an explicit alignment will be odd byte aligned.

To do

  • Allow unaligned allocations to be even byte aligned only. So addresses divisible by 2 not 4.
  • I used a trick before where I'd allocate double the space required and add an offset to give an annoying alignment, then subtract it later when passing to free. If only some things have "bad luck" I may (will) need to record the actual pointer to give back to free; as this method will no longer work.
    • It may also not be needed.... maybe.