Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: API used to access process heap structure




On Sep 8, 2006, at 12:02 PM, email@hidden wrote:

Windows has an API to walk the heap associated with a process.
There is no POSIX API for UNIX as far as I know. So it will be
different for each UNIX variant. Darwin has a heap(1) utility which
clearly uses an API to get the information. You can see some of that by
looking at the output of nm. However, I have been unable to
find any published documentation about it. I am interested
for example in extracting information about the blocks on the
free list.

There is no published documentation on these interfaces, and they are not considered API.

Before we start talking about all this, though, it's important to understand
that under Darwin, malloc & friends are just wrappers around a plugin
interface that permits multiple instances of multiple allocators to co-exist.


In the common case, there's only one allocator, scalable_malloc, but quite
often there will be several instances of it (as you can see if you point Heap
at e.g. Safari).


If you look at <malloc/malloc.h> you will notice that in the malloc_zone_t
structure there is a pointer to a malloc_introspection_t structure, which is
defined further down.


In this structure are a number of useful function vectors.  One of these
is the enumerator.

Now, it's important to understand that in a utility, the enumerator comes
from the utility's copy of the system library, but if you have set up the reader
hook to read from another process' address space, you are looking at data
structures maintained by that process' copy, which may not be the same
(e.g. Rosetta, 32 vs. 64 bit, etc.).


This particular interface won't tell you what's on the freelist, I'm afraid,
and you will spend some time digging the zone_address parameter
up if you are introspecting another process (easy enough on your own
task). But it does largely parallel the Windows facility you described,
and if you look at the header it's well enough described that you can
work it out.


HTH

 = Mike

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.