<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic __malloc_lock/unlock in Kinetis Design Studio</title>
    <link>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336485#M755</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why KDS::newlib::malloc() does not call __malloc_lock/unlock functions? Was locking support compiled out?&lt;/P&gt;&lt;P&gt;I can see malloc_r in the map file but no reference to locking functions.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Sergei&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Mar 2015 20:07:40 GMT</pubDate>
    <dc:creator>sergeisharonov</dc:creator>
    <dc:date>2015-03-20T20:07:40Z</dc:date>
    <item>
      <title>__malloc_lock/unlock</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336485#M755</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why KDS::newlib::malloc() does not call __malloc_lock/unlock functions? Was locking support compiled out?&lt;/P&gt;&lt;P&gt;I can see malloc_r in the map file but no reference to locking functions.&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Sergei&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Mar 2015 20:07:40 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336485#M755</guid>
      <dc:creator>sergeisharonov</dc:creator>
      <dc:date>2015-03-20T20:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: __malloc_lock/unlock</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336486#M756</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello Sergei,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;can you please upload your demo project to showcase your issue? thanks!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Zhang Jun&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Mar 2015 05:46:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336486#M756</guid>
      <dc:creator>ZhangJennie</dc:creator>
      <dc:date>2015-03-26T05:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: __malloc_lock/unlock</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336487#M757</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sergei,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, they are #define'd out in newlib-nano. The paragraph on malloc in newlib-nano below is from &lt;A href="https://developer.mbed.org/users/AdamGreen/notebook/newlib-nano/?compage=1#c8053"&gt;MBED&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;H2 style="margin-top: 1.4rem; margin-bottom: 1.4rem; font-size: 2.7rem; font-family: 'Trebuchet MS', sans-serif; color: #222222; background-color: #fdfdfd;"&gt;Synchronizing Heap Accesses (malloc/free)&lt;/H2&gt;&lt;P style="margin-bottom: 1.7rem; font-size: 14px; font-family: 'Helvetica Neue', Helvetica, Helvetica, Arial, sans-serif; color: #222222; background-color: #fdfdfd;"&gt;The memory allocation routines implementation in newlib-nano include references to &lt;STRONG&gt;MALLOC_LOCK&lt;/STRONG&gt; and &lt;STRONG&gt;MALLOC_UNLOCK&lt;/STRONG&gt; macros. In the standard newlib library, these macros would be weak references to &lt;CODE style="font-weight: bold; background: #ffff99;"&gt;__malloc_lock()&lt;/CODE&gt; and &lt;CODE style="font-weight: bold; background: #ffff99;"&gt;__malloc_unlock()&lt;/CODE&gt; routines. A project like gcc4mbed could then provide implementation of these routines to use a mutex to serialize access to the heap. &lt;STRONG style="text-decoration: underline;"&gt;However, in newlib-nano these macros are #define'ed to nothing so this isn't possible.&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="margin-bottom: 1.7rem; font-size: 14px; font-family: 'Helvetica Neue', Helvetica, Helvetica, Arial, sans-serif; color: #222222; background-color: #fdfdfd;"&gt;I hope this helps.&lt;/P&gt;&lt;P style="margin-bottom: 1.7rem; font-size: 14px; font-family: 'Helvetica Neue', Helvetica, Helvetica, Arial, sans-serif; color: #222222; background-color: #fdfdfd;"&gt;&lt;SPAN style="line-height: 1.5em;"&gt;Best regards,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 1.7rem; font-size: 14px; font-family: 'Helvetica Neue', Helvetica, Helvetica, Arial, sans-serif; color: #222222; background-color: #fdfdfd;"&gt;Martyn&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Mar 2015 16:19:27 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336487#M757</guid>
      <dc:creator>martynhunt</dc:creator>
      <dc:date>2015-03-26T16:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: __malloc_lock/unlock</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336488#M758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, looks like replies via Thunderbird make it through to the list but all text is stripped. Here we go again:&lt;/P&gt;&lt;P&gt;On 3/26/2015 11:19 AM, Martyn Hunt wrote: &lt;/P&gt;&lt;P&gt;&amp;gt; However, in newlib-nano these macros are #define'ed to nothing .... &lt;/P&gt;&lt;P&gt;Thought as much. Now, newlib makes malloc/free calls behind your back and we do not have any way to protect these hidden calls. &lt;/P&gt;&lt;P&gt;This makes newlib (as it exists in KDS) not safe to use in any multitasking environment. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only way I see to make it work is to override newlib's malloc/free with protected equivalents. That seems to work for me. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sergei&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Mar 2015 20:45:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336488#M758</guid>
      <dc:creator>sergeisharonov</dc:creator>
      <dc:date>2015-03-26T20:45:38Z</dc:date>
    </item>
    <item>
      <title>Re: __malloc_lock/unlock</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336489#M759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, looks like replies via Thunderbird make it through to the list but all text is stripped. Here we go again:&lt;/P&gt;&lt;P&gt;On 3/26/2015 12:46 AM, ZhangJennie wrote:&lt;/P&gt;&lt;P&gt; &amp;gt; can you please upload your demo project to showcase your issue? thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Do not have a demo project but here are 3 easy steps to reproduce:&lt;/P&gt;&lt;P&gt; 1. In KDS import hello_world_frdm22k demo project from KSDK_1.1.0/demos/hello_world/kds/frdmk22f&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; 2. Add calls to malloc/free somewhere in main(), e.g.:&lt;/P&gt;&lt;P&gt; &lt;EM&gt;.....&lt;BR /&gt; {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; void *p;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p = malloc(10);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(p)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; free(p);&lt;BR /&gt;&amp;nbsp; }&lt;/EM&gt;&lt;/P&gt;&lt;P&gt; ....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; 3. Check map file for presence of locking functions:&lt;/P&gt;&lt;P&gt; &lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; grep malloc_lock hello_world_frdmk22f.map&lt;/EM&gt;&lt;/P&gt;&lt;P&gt; Or use text editor if grep is not available.&lt;/P&gt;&lt;P&gt; You will see that locking functions are not there.&lt;/P&gt;&lt;P&gt; If I add my own locking functions using RTOS locking mechanics they will&lt;/P&gt;&lt;P&gt; not get called either.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; BTW, problem was solved by overriding library malloc/free with RTOS equivalents&lt;/P&gt;&lt;P&gt; instead of trying to protect them.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Regards,&lt;/P&gt;&lt;P&gt; Sergei&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Mar 2015 20:47:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336489#M759</guid>
      <dc:creator>sergeisharonov</dc:creator>
      <dc:date>2015-03-26T20:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: __malloc_lock/unlock</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336490#M760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Sergei,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you remove nanolibc from the linker options and simply link in libc, then you will find that malloc/free calls __malloc_lock/unlock. Hopefully this helps you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Martyn&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="remove_nanolibc.PNG.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/47982i89F9C57E1F9321B1/image-size/large?v=v2&amp;amp;px=999" role="button" title="remove_nanolibc.PNG.png" alt="remove_nanolibc.PNG.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="add_libc.PNG.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/48652i67926F9D8F852D17/image-size/large?v=v2&amp;amp;px=999" role="button" title="add_libc.PNG.png" alt="add_libc.PNG.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="malloc_lock_LIST.PNG.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/48913i276246A11E5FA63C/image-size/large?v=v2&amp;amp;px=999" role="button" title="malloc_lock_LIST.PNG.png" alt="malloc_lock_LIST.PNG.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Mar 2015 21:37:52 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336490#M760</guid>
      <dc:creator>martynhunt</dc:creator>
      <dc:date>2015-03-26T21:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: __malloc_lock/unlock</title>
      <link>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336491#M761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Martyn,&lt;/P&gt;&lt;P&gt;Thank you for looking into this. However, I believe full newlib is way too bloated for many embedded systems. For me, the better option was to override library malloc/free with FreeRTOS equivalents.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Sergei&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Mar 2015 17:10:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Design-Studio/malloc-lock-unlock/m-p/336491#M761</guid>
      <dc:creator>sergeisharonov</dc:creator>
      <dc:date>2015-03-30T17:10:47Z</dc:date>
    </item>
  </channel>
</rss>

