flipperdevices / flipperzero-firmware

Flipper Zero firmware source code
https://flipperzero.one
GNU General Public License v3.0
11.71k stars 2.59k forks source link

TLSF and the Temple of Corrupted Memory #3653

Open DrZlo13 opened 1 month ago

DrZlo13 commented 1 month ago

What's new

Verification

Checklist (For Reviewer)

github-actions[bot] commented 1 month ago

Compiled f7 firmware for commit d4b70a6a:

CookiePLMonster commented 4 weeks ago

Regarding the 8-byte alignment, GCC indeed appears to make that assumption, with or without -Os.

This code:

int32_t align_test_app(void* p) {
    UNUSED(p);
    FURI_LOG_I("TEST", "Hello world");
    FURI_LOG_I("TEST", "I'm align_test!");

    void* b = malloc(4);

    uintptr_t valB = (uintptr_t)b;
    return (valB & 7) == 0;
}

compiled into: image

So it's a very good idea to guarantee proper alignment, at least for malloc and realloc.

github-actions[bot] commented 2 weeks ago

PVS-Studio report for commit 7d50f4b5:

DrZlo13 commented 2 weeks ago

I disabled all dolphin animations and ran some tests:

tlsf

: free Free heap size: 141416 Total heap size: 185560 Minimum heap size: 137696 Maximum heap block: 140328 Aux pool total free: 2752 Aux pool max free block: 2644

: free Free heap size: 141304 Total heap size: 185560 Minimum heap size: 125768 Maximum heap block: 132512 Aux pool total free: 2752 Aux pool max free block: 2644

heap4

: free Free heap size: 146200 Total heap size: 185544 Minimum heap size: 142512 Maximum heap block: 145136 Pool free: 1464 Maximum pool block: 1348

: free Free heap size: 146136 Total heap size: 185544 Minimum heap size: 142440 Maximum heap block: 145296 Pool free: 1464 Maximum pool block: 1348

It looks like in the current version tlsf has no meaning except for the correct implementation of realloc.