[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-dev] Malloc hooks
From: |
Taavo Raykoff |
Subject: |
[avr-libc-dev] Malloc hooks |
Date: |
Mon, 21 Jan 2019 16:03:22 -0500 |
The avr-libc malloc and friends such as realloc and free are implemented in a
way that is not re-entrant.
When using FreeRTOS, any application code can be pre-empted and needs to be
thread-safe. FreeRTOS does have its own allocators independent of avr-libc,
and one allocator which wraps avr-libc in what is effectively a critical
section.
However this does not solve the problem of legacy library code which use
avr-libc directly, such as
Arduino String library
avr-lib’s strdup() and possibly others
Other libraries
When pre-empted, the allocator structures (freelist, etc) can be corrupted
resulting in hard-to-find bugs.
I think a good solution to this would be to provide entry/exit hooks on the
malloc and friends implementations, that can optionally be implemented to
ensure that the avr-libc implementation is in a section that will prevent
pre-emption. This can easily be done using weak linker symbols, that can be
ignored by existing code, but provide a hook for the entry/exit handlers.
This is one approach:
https://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html
<https://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html>
I’d like to submit a patch for this and get included upstream…
Taavo.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [avr-libc-dev] Malloc hooks,
Taavo Raykoff <=