{"action":"created","issue":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/7250","repository_url":"https://api.github.com/repos/ARMmbed/mbed-os","labels_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/7250/labels{/name}","comments_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/7250/comments","events_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/7250/events","html_url":"https://github.com/ARMmbed/mbed-os/issues/7250","id":333507425,"node_id":"MDU6SXNzdWUzMzM1MDc0MjU=","number":7250,"title":"The implementation of __real__malloc_r","user":{"login":"leibin2014","id":9861776,"node_id":"MDQ6VXNlcjk4NjE3NzY=","avatar_url":"https://avatars0.githubusercontent.com/u/9861776?v=4","gravatar_id":"","url":"https://api.github.com/users/leibin2014","html_url":"https://github.com/leibin2014","followers_url":"https://api.github.com/users/leibin2014/followers","following_url":"https://api.github.com/users/leibin2014/following{/other_user}","gists_url":"https://api.github.com/users/leibin2014/gists{/gist_id}","starred_url":"https://api.github.com/users/leibin2014/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leibin2014/subscriptions","organizations_url":"https://api.github.com/users/leibin2014/orgs","repos_url":"https://api.github.com/users/leibin2014/repos","events_url":"https://api.github.com/users/leibin2014/events{/privacy}","received_events_url":"https://api.github.com/users/leibin2014/received_events","type":"User","site_admin":false},"labels":[{"id":427713129,"node_id":"MDU6TGFiZWw0Mjc3MTMxMjk=","url":"https://api.github.com/repos/ARMmbed/mbed-os/labels/mirrored","name":"mirrored","color":"ededed","default":false},{"id":28847983,"node_id":"MDU6TGFiZWwyODg0Nzk4Mw==","url":"https://api.github.com/repos/ARMmbed/mbed-os/labels/type:%20question","name":"type: question","color":"cccccc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-06-19T03:33:04Z","updated_at":"2018-06-22T03:32:57Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"### Description\r\nDear experts,\r\nWhen I run the example project `Nucleo_rtos_basic` on stm32f103 I get an error. The function `thread.start(print_thread)` goes to call the function `malloc`, then `malloc` will call `malloc_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()` . So `malloc` 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.\r\n\r\n\r\n### Issue request type\r\n[X] Question\r\n[ ] Enhancement  \r\n[ ] Bug  \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/comments/399310477","html_url":"https://github.com/ARMmbed/mbed-os/issues/7250#issuecomment-399310477","issue_url":"https://api.github.com/repos/ARMmbed/mbed-os/issues/7250","id":399310477,"node_id":"MDEyOklzc3VlQ29tbWVudDM5OTMxMDQ3Nw==","user":{"login":"leibin2014","id":9861776,"node_id":"MDQ6VXNlcjk4NjE3NzY=","avatar_url":"https://avatars0.githubusercontent.com/u/9861776?v=4","gravatar_id":"","url":"https://api.github.com/users/leibin2014","html_url":"https://github.com/leibin2014","followers_url":"https://api.github.com/users/leibin2014/followers","following_url":"https://api.github.com/users/leibin2014/following{/other_user}","gists_url":"https://api.github.com/users/leibin2014/gists{/gist_id}","starred_url":"https://api.github.com/users/leibin2014/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leibin2014/subscriptions","organizations_url":"https://api.github.com/users/leibin2014/orgs","repos_url":"https://api.github.com/users/leibin2014/repos","events_url":"https://api.github.com/users/leibin2014/events{/privacy}","received_events_url":"https://api.github.com/users/leibin2014/received_events","type":"User","site_admin":false},"created_at":"2018-06-22T03:32:57Z","updated_at":"2018-06-22T03:32:57Z","author_association":"CONTRIBUTOR","body":"@0xc0170 \r\nI have got more clear picture about this problem.\r\nFirstly, 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.\r\nThen 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.\r\nSo the Nucleo_rtos_basic example in online compiler is not working for stm32f103rb. In this example, `thread.start(print_thread);` will call `_attr.stack_mem = new uint32_t[_attr.stack_size/sizeof(uint32_t)];`. Since the default value of `MBED_CONF_APP_THREAD_STACK_SIZE` is 4096, malloc(4096) will finally be called and return NULL then go into mbed error assert."}}
{"actor":{"display_login":"leibin2014"}}