I'm trying to do hot-swapping of code (you could call it "runtime
static linking"). You load some libraries in the form of .o or .so
files, and some of my objects have pointers to static variables in
these libraries. Now I want to reload the new version of the .o file
into memory, and patch these pointers to a new address. The
previously-loaded libraries also need to be patched, which I already
kind-of know how to do using libbfd
stack can be patched using DWARF debug info, I think, though that's
purely theoretical for me at this point; In any case, I wanted to know
how I could patch the allocated objects; which of course requires me
at the very least to be able to iterate through them.
Some introspection on the types of the allocated objects will be
necessary. So two questions come to mind: 1. Is bdwgc using itself
internally, or will every object reachable by
GC_apply_to_each_object() belong to the user? ? (I'm guessing the
former is true) 2. Is there any way of segmenting blocks by anything
other than size (say, by type :-) )? (I'm guessing no)
Finally - is there any way of having two distinct allocators working
simultaneously? Actually I would like to be able to allocate
executable memory, without having all memory be executable. But I see
myself using separate allocators for other purposes, if it were
Thank you :-)
Post by Bruce Hoult
There's no exposed API for this, no. There are of course internal ways for
the GC to do this, which may change from release to release of the GC --
although they're pretty stable at this point.
The GC allocates memory in blocks of generally 4 kB. Each block is divided
into objects of the same size (allocated size .. may be a little more than
was asked for in GC_malloc, generally the next multiple of 16 bytes or so).
Each block keeps a list of free objects in the block, and mark bits for the
You can iterate through all blocks using the internal
GC_apply_to_all_blocks() function, or through all objects with the
GC_apply_to_each_object() function. It would be your job to make sure the
object is not on the free list, and/or is reachable if that is important to
you. The object was reachable AT THE LAST GC (or at least mark phase) if the
mark bit is set, and it's not on the free list. Objects may have become
unreachable since the last GC.
What are you really trying to do?
Post by Bruno Loff
I am using the bdwgc library for maintaining various allocated objects
I would like to know: is there a mechanism for iterating over every
chunk that was allocated via gc_malloc?
Thank you for your time,
bdwgc mailing list
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.