Profiler / memory analyzer for macOS kext

Before starting to reinvent the wheel, I decided to make a few searches to see if some desired function was implemented somewhere. In general, I would like to analyze my macOS kext and look for any memory problems (memory leaked especially).

In particular, I want to find a code-based profiler (because the external profiler does not support kernel debugging modules), which is used as a shell for malloc / free.

1. on every malloc it record where you allocated the memory (file/line)
2. on every free, it remove this meta data (along with the memory itself). 
3. on tear-down, it scans for all left dynamic memory regions 
   and prints them out (along with their corresponding meta-data). 
   This analysis may be called when unloading the driver, which is the point 
   where all memory should be free.

Here's an implementation option using a doubly linked list, which, after requesting a request with some input size, the actual malloc is created for size + overhead, where the second part is designed to place links to the previous distribution and the next distribution, and the metadata itself (getting the file name using the macro FILE with a LINE macro and possibly more information), the return address is an offset from the actual distribution, so that the user can only process read data. overhead

In freewe use the input address - offsetas the actual input in free, since this is the original allocated memory, but before the release the item must be correctly removed from the linked list.

.

, , / .

, , GDB/LLDB, ( )...

P.S

driver verifier, , - ( )... macOS?

+4

Source: https://habr.com/ru/post/1687133/


All Articles