views:

48

answers:

2

I am making a garbage collector to develop an appreciation for how they work.

I can process registers as well as heap and stack memory to find potential references to allocated blocks.

But processing the global data memory has eluded me.

Is there a way to get the upper and lower bounds of the global memory space in C (I'm using GCC on Intel OS-X if that helps)?

What other memory areas might I have missed?

+3  A: 

I can't give you a direct answer off-hand here, but I can tell you that the Boehm/Demers/Weiser conservative garbage collector will have code (and likely docs) to show you. This will be very platform dependent, however.

JUST MY correct OPINION
Thanks. It is a complex task from what I understand of the gcconfig.h and os_dep.c files.
philcolbourn
That's why I couldn't give you a direct answer off-hand. Finding your root set when you don't control the compiler and/or generated code is a non-trivial task.
JUST MY correct OPINION
+1  A: 

If I am understanding right you want to know if pointer p is pointing to the program global data area.

The solution is going to be platform dependent, also zero initialized data and statically initialized data is probably in different places. There is nothing in C that specifies that these zones have to exist at all let alone them being contiguous or not being in the same range as the heap or even in between functions.

You want to have a global symbol at the beginning and one at the end and use their reference to check the ranges. To do this you need to understand the linker.

Before doing that check that the C library doesn't export such data already even if it is only supposed to be for internal consumption.

jbcreix
Close. I want to scan the global data area for pointers to the heap. But I think you covered the issue. Thanks. ttmrichter pointed me to a popular GC (it seems) that has pages and pages of code to do what I want - although they do support a large number of platforms.
philcolbourn