-
Notifications
You must be signed in to change notification settings - Fork 3k
The implementation of __real__malloc_r #7250
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
Comments
ARM Internal Ref: MBOTRIAGE-777 |
There should be definition of the real malloc otherwise would not link. Look at |
@0xc0170 |
Does this help: https://docs.mbed.com/docs/mbed-os-handbook/en/5.2/advanced/runtime_stats/#heap-stats ? What does it report? |
@0xc0170 |
So where the max heap size is set? Should be some code similar as below in startup_stm32XB.S to set the heap size? But I can't find it in the startup file. Or there should be somewhere tell the libc about heap size. As expect it should be in the pre_main() function. But for GCC I can't find it in pre_main(). I'm using the GCC(GNU) toolchain.
|
See https://os.mbed.com/docs/latest/reference/memory.html Heap size is dynamic, limit is how much RAM is left (not yet true for IAR, as you are working with GCC - it is there). You can also review |
@0xc0170 |
@0xc0170 Firstly, the malloc() and _sbrk() are not one to one. For example, when we call malloc(2) firstly, then _sbrk(32) and _sbrk(2656) will be called. The next calling of malloc(xxx) depends on the size xxx wanted to allocate. If the size xxx is much less than 2656, then _sbrk() won't be called after the calling of malloc(xxx). If the size is bigger than 2656, then the second malloc() will call _sbrk(4096) to get more memory. This should be the behavior of malloc, don't know why, but looks like also reasonable. Then let's analysis why we get that error when we call malloc(4096) on stm32F103RB. As we know the stm32f103RB just has 20K of small RAM. As we see in heap_stats above the heap size is 5760. When we call malloc(4096), then _sbrk(4120) and _sbrk(2664) will be called. Since 4120+2664 is bigger than 5760 the malloc() executes failed and returns NULL. So the Nucleo_rtos_basic example in online compiler is not working for stm32f103rb. In this example, |
+1 for the analasis. What you are seeing is paging that sbrk does. See this issue #5386. This was reported earlier, and so far no solution. I would assume this is a duplicate, and we close it favor of 5386 where we link this report as well. |
@0xc0170 OK, let me close it. Thanks for all above support! |
Description
Dear experts,
When I run the example project
Nucleo_rtos_basic
on stm32f103 I get an error. The functionthread.start(print_thread)
goes to call the functionmalloc
, thenmalloc
will callmalloc_wrapper()
because of linker flag-Wl,--wrap,_malloc_r
. Finally__real__malloc_r()
will be called. But there is no definition of__real__malloc_r()
. Somalloc
will return NULL and assert the mbed error. My question is where is the implementation of__real__malloc_r
? It doesn't look like a standard lib function.Issue request type
[X] Question
[ ] Enhancement
[ ] Bug
The text was updated successfully, but these errors were encountered: