supplierdeeply

malloc() and tasks

  • 4 Replies
  • 738 Views
*

Offline alvm

  • ***
  • 123
malloc() and tasks
« on: 17 / September / 2013, 05:57:03 »
Advertisements
Hi,

How I can get info about which task call malloc()? Is there mapping between tasks and a memory pool which they use through malloc()?

Thanks,
Alex.

*

Offline srsa_4c

  • ******
  • 3530
Re: malloc() and tasks
« Reply #1 on: 17 / September / 2013, 10:04:37 »
Is there mapping between tasks and a memory pool which they use through malloc()?
malloc() allocates from the same memory pool, regardless of which task issued the call (I hope I understood your question correctly).
Quote
How I can get info about which task call malloc()
Well, that isn't so easy. If the pointer returned by malloc() is stored in a static variable (i.e. it's located at a known address), then you could collect these variables and see where they point  :blink:.
Other method is to make cache hacks work, and replace the firmware's memory allocator function with a modified one that logs its callers somewhere.

Maybe someone else will give a better advice.

*

Offline alvm

  • ***
  • 123
Re: malloc() and tasks
« Reply #2 on: 17 / September / 2013, 10:19:56 »
Other method is to make cache hacks work, and replace the firmware's memory allocator function with a modified one that logs its callers somewhere.

Very interesting! thanks for advice!

Well, that isn't so easy. If the pointer returned by malloc() is stored in a static variable (i.e. it's located at a known address), then you could collect these variables and see where they point

drysh meminfo -t should be list of task but STDLIB_MALLOC_USE_LIST is not defined for fw :(

(for a810  meminfo -t  malloc memory info (per task))

*

Offline reyalp

  • ******
  • 11084
Re: malloc() and tasks
« Reply #3 on: 17 / September / 2013, 13:35:46 »
If you explain what you are trying to do, we might be able to offer better advice.

Modern cameras (including a810) copy DryOS kernel code to RAM. It looks like the actual malloc function is still in ROM, but the underlying functions are in RAM, so you could modify them quite easily using the same approach as the task hook used in recent cameras (e.g. sx160, elph130)
Don't forget what the H stands for.


*

Offline alvm

  • ***
  • 123
Re: malloc() and tasks
« Reply #4 on: 17 / September / 2013, 15:09:30 »
If you explain what you are trying to do, we might be able to offer better advice.

There is memory leakage when I run my small application based on chdk. I'm trying to find which task is a source of the problem. Task is from Canon fw, not from my application

Modern cameras (including a810) copy DryOS kernel code to RAM. It looks like the actual malloc function is still in ROM, but the underlying functions are in RAM, so you could modify them quite easily using the same approach as the task hook used in recent cameras (e.g. sx160, elph130)

Thanks for advice, I'll try to do this.
« Last Edit: 17 / September / 2013, 15:11:11 by alvm »

 

Related Topics