-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cpu/atmega_common: wrappers for memory management function to avoid preemption #11998
cpu/atmega_common: wrappers for memory management function to avoid preemption #11998
Conversation
Memory management function like `malloc`, `calloc`, `realloc` and `free` must not be preempted when they operate on allocator structures. To avoid such a preemption, wrappers around these functions are used which simply disable all interrupts for the time of their execution.
14c8ded
to
d84f75b
Compare
is this related to #8619? |
Not really. PR #8619 implements the locking mechanism as used by |
OK, for testing I modified diff --git a/examples/hello-world/main.c b/examples/hello-world/main.c
index f51bf8c0a0..212e0f62f4 100644
--- a/examples/hello-world/main.c
+++ b/examples/hello-world/main.c
@@ -20,6 +20,7 @@
*/
#include <stdio.h>
+#include <stdlib.h>
int main(void)
{
@@ -27,6 +28,14 @@ int main(void)
printf("You are running RIOT on a(n) %s board.\n", RIOT_BOARD);
printf("This board features a(n) %s MCU.\n", RIOT_MCU);
+ void *a = malloc(4);
+ printf("void *a = %p\n", a);
+ void *b = calloc(4, 4);
+ printf("void *b = %p\n", b);
+ a = realloc(a, 32);
+ printf("void *a = %p (after realloc)\n", a);
+ free(a);
+ free(b);
return 0;
} The console output was
So no regressions were introduced. Finally, I disassembled the symbol main and got the following output:
So every call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK. Thanks for this very elegant fix!
@maribu Thanks for reviewing, testing and merging. |
Contribution description
This PR is an aproach to fix the problem described in #10842.
Memory management function like
malloc
,calloc
,realloc
andfree
must not be preempted when they operate on allocator structures. To avoid such a preemption, wrappers around these functions are used which simply disable all interrupts for the time of their execution.This approach produces 78 additional bytes of code.
Testing procedure
Flash and run
tests/malloc
.Issues/PRs references
Fixes #10842