Lighweight memory pool

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Lighweight memory pool

ソリューションへジャンプ
1,514件の閲覧回数
vines
Contributor III

Hi All,

This might seem basic to everyone. But what can cause the problem LWMEM_POOL_INVALID? Eg memory not enough in heap, stack, etc. I hope I don't get a reply "read the manual". I did, I guess my comprehension is not that good (sorry). Anyway, I will appreciate it if you could explain this.

Thanks.

0 件の賞賛
返信
1 解決策
1,180件の閲覧回数
Martin_
NXP Employee
NXP Employee

Hi vines,

The source code for this can be found in:

${MQX_ROOT}\mqx\source\kernel\lwmem.c

LWMEM_POOL_INVALID is returned from _lwmem_alloc_ functions() or from _lwmem_test(). Condition looks like this:

if (mem_pool_ptr->VALID != LWMEM_POOL_VALID)

    {

        _task_set_error(MQX_LWMEM_POOL_INVALID);

        return (NULL);

    } /* Endif */

So the VALID bit in the LWMEM_POOL_STRUCT is not correct. You don't indicate which function would cause this. (during allocation, either from the system pool or from a private pool ? or is this during runtime call to lwmem_test() ?)

If this occurs in runtime, in order to debug this, you can put data watchpoint to the address of the pool_ptr->VALID. CPU would enter debug mode upon a CPU write access to this address. This is important note - only if CPU store instruction writes to this address. As there exist more crossbar switch master ports on Kinetis (like usb controller, DMA) it is also possible, that one of these masters writes data to the address of pool_ptr->VALID. For example, you schedule a usb transaction, for which you have allocated statically an application buffer of size 100 bytes, but the usb will receive 200 bytes. As it is 100 bytes off it is overwriting some other memory.

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,181件の閲覧回数
Martin_
NXP Employee
NXP Employee

Hi vines,

The source code for this can be found in:

${MQX_ROOT}\mqx\source\kernel\lwmem.c

LWMEM_POOL_INVALID is returned from _lwmem_alloc_ functions() or from _lwmem_test(). Condition looks like this:

if (mem_pool_ptr->VALID != LWMEM_POOL_VALID)

    {

        _task_set_error(MQX_LWMEM_POOL_INVALID);

        return (NULL);

    } /* Endif */

So the VALID bit in the LWMEM_POOL_STRUCT is not correct. You don't indicate which function would cause this. (during allocation, either from the system pool or from a private pool ? or is this during runtime call to lwmem_test() ?)

If this occurs in runtime, in order to debug this, you can put data watchpoint to the address of the pool_ptr->VALID. CPU would enter debug mode upon a CPU write access to this address. This is important note - only if CPU store instruction writes to this address. As there exist more crossbar switch master ports on Kinetis (like usb controller, DMA) it is also possible, that one of these masters writes data to the address of pool_ptr->VALID. For example, you schedule a usb transaction, for which you have allocated statically an application buffer of size 100 bytes, but the usb will receive 200 bytes. As it is 100 bytes off it is overwriting some other memory.

0 件の賞賛
返信
1,180件の閲覧回数
vines
Contributor III

Thanks Martin.

Just for info

The problem was I forgot to remove a free() function where as the malloc was already remove. Thus it is trying to free up memory to a space that is not even allocated.

0 件の賞賛
返信