<?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>MQX Software SolutionsのトピックRe: lwmem error ?</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/lwmem-error/m-p/732017#M17674</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so I finally found the root cause. It's not lwmem, but task.c in conjunction with lwmem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's a little mind twisting, so I try to explain the patch attached:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When _task_destroy_internal() tries to apply it's garbage collection, it searches for all memory blocks&amp;nbsp;using the own task ID.&lt;/P&gt;&lt;P&gt;Using _mem_get_next_block_internal(), _task_destroy_internal() tries to find mem blocks allocated by the own task, where _mem_free() hadn't been already applied by the task itself,&amp;nbsp;as it should have.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When&amp;nbsp;it finds blocks using our own task ID,&amp;nbsp;but not&amp;nbsp;belonging to our task, things become really&amp;nbsp;bad.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And this can happen due to task prios and the way TASK IDs are getting re-used again.&lt;/P&gt;&lt;P&gt;When&amp;nbsp;&lt;SPAN&gt;_task_destroy_internal()&lt;SPAN&gt;&amp;nbsp; marks&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;the task ID&amp;nbsp;as free to use again, there are up to three memory blocks left which are still&amp;nbsp;marked as property to this task ID. When we now release&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;TASK_CREATE_LWSEM, a high prio task might already be waiting for this semaphore to become ready. Hence it creates a task using that exact Task ID again. If this newly created dynamic task has a higher prio too, and terminates, it will detect all memory blocks of this task ID as garbage&amp;nbsp;mem. But it falsely&amp;nbsp;found and&amp;nbsp;frees the three memory blocks of the old lower prio task.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;I hope this is fixed in task.c with the patch attached.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;cheers,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp; Martin&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 03 Nov 2017 13:02:06 GMT</pubDate>
    <dc:creator>m_bach</dc:creator>
    <dc:date>2017-11-03T13:02:06Z</dc:date>
    <item>
      <title>lwmem error ?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/lwmem-error/m-p/732016#M17673</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi There,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for some time now, I'm searching a bug which is really hard to find. Anyway, I reduced everything to a very small example code which crashes after several seconds.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The Scenario is described as:&lt;/P&gt;&lt;P&gt;- main1() and main2() are auto created tasks, started by MQX init&lt;/P&gt;&lt;P&gt;- both are just loops which are creating dynamic tasks dynamic1() and dynamic2()&lt;/P&gt;&lt;P&gt;- I'm&amp;nbsp;using Kinetis K64-120 MHz, 256KB SRAM&lt;/P&gt;&lt;P&gt;- MQX Version is 4.2.0.2, so this should be fixed already:&amp;nbsp;&lt;A href="https://community.nxp.com/thread/328044"&gt;Bug Report: Memory pool corruption in _lwmem_alloc_align_internal&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sometimes, _lwmem_test()&amp;nbsp;reports Error 7 before everything hangs, which is&amp;nbsp;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;MQX_CORRUPT_STORAGE_POOL_FREE_LIST,&amp;nbsp;b&lt;/SPAN&gt;&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;ut more likely my system hangs before this is reported...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; color: #51626f;"&gt;main.c&amp;nbsp;and main.h is attached.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; color: #51626f;"&gt;If I&amp;nbsp;enabled MQX_USE_MEM instead of MQX_USE_LWMEM, the problem is gone, which makes me think there is an lwmem problem. On the other hand, the problem is also gone&amp;nbsp;when enabling&lt;/SPAN&gt;&lt;SPAN style="background-color: #ffffff; color: #51626f;"&gt;&amp;nbsp;_time_delay(1) at the end of&amp;nbsp;main2() and staying with lwmem.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This&amp;nbsp; seems very related to my Problem:&amp;nbsp;&lt;A href="https://community.nxp.com/thread/395885"&gt;stuck in _lwmem_get_next_block_internal()&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When the error&amp;nbsp;condition occurs,&amp;nbsp;_task_destroy_internal calls _lwmem_get_next_block_internal(), and than&lt;SPAN&gt;_lwmem_get_next_block_internal()&amp;nbsp;&lt;/SPAN&gt;crashes when trying to skip free blocks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Martin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Oct 2017 15:03:48 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/lwmem-error/m-p/732016#M17673</guid>
      <dc:creator>m_bach</dc:creator>
      <dc:date>2017-10-30T15:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: lwmem error ?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/lwmem-error/m-p/732017#M17674</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so I finally found the root cause. It's not lwmem, but task.c in conjunction with lwmem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's a little mind twisting, so I try to explain the patch attached:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When _task_destroy_internal() tries to apply it's garbage collection, it searches for all memory blocks&amp;nbsp;using the own task ID.&lt;/P&gt;&lt;P&gt;Using _mem_get_next_block_internal(), _task_destroy_internal() tries to find mem blocks allocated by the own task, where _mem_free() hadn't been already applied by the task itself,&amp;nbsp;as it should have.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When&amp;nbsp;it finds blocks using our own task ID,&amp;nbsp;but not&amp;nbsp;belonging to our task, things become really&amp;nbsp;bad.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And this can happen due to task prios and the way TASK IDs are getting re-used again.&lt;/P&gt;&lt;P&gt;When&amp;nbsp;&lt;SPAN&gt;_task_destroy_internal()&lt;SPAN&gt;&amp;nbsp; marks&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;the task ID&amp;nbsp;as free to use again, there are up to three memory blocks left which are still&amp;nbsp;marked as property to this task ID. When we now release&amp;nbsp;&lt;SPAN&gt;&lt;SPAN&gt;TASK_CREATE_LWSEM, a high prio task might already be waiting for this semaphore to become ready. Hence it creates a task using that exact Task ID again. If this newly created dynamic task has a higher prio too, and terminates, it will detect all memory blocks of this task ID as garbage&amp;nbsp;mem. But it falsely&amp;nbsp;found and&amp;nbsp;frees the three memory blocks of the old lower prio task.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;I hope this is fixed in task.c with the patch attached.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;cheers,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;&amp;nbsp; Martin&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Nov 2017 13:02:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/lwmem-error/m-p/732017#M17674</guid>
      <dc:creator>m_bach</dc:creator>
      <dc:date>2017-11-03T13:02:06Z</dc:date>
    </item>
  </channel>
</rss>

