How do I get the upper and lower limits to the global data area in C?
I am making a garbage collector to develop an appreciation for how they work.
I can process registers as well as he开发者_高级运维ap 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?
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.
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.
精彩评论