By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

High address of stack in C

P: 26
First of all I would like to mention that this is required as a part of project that I am making.

What I want to do is identify the objects made up at runtime in C for a conservative garbage collector.

Here I want to search the stack for all the pointer values.
So I can find one end by simply declaring a variable and finding the address of it.

The problem comes in finding the other end of stack.

How can I know its value.

I guess it would be saying as finding the sp pointer just before my program starts its execution in the cpu.

Please help...
Nov 7 '10 #1

✓ answered by Oralloy

nk28,

I think you're talking about SIGSEGV - segmentation violation.

From recollection, there are lots of problems with catching this signal. On some systems it may be impossible. Check your documentation very carefully.

The other thing you might attempt is to look into the complier's documentation and find the global variable that is supposed to have that value. Most compilers have it, the trick is finding the documentation on the default C-language start-up sequence.

All that said, Banfa has the right of it. Nothing in the specification states that there has to be a stack of any sort. We just assume a stack, because it's the common implementation mechanism.

That said, you also have to know if the stack is contiguous - in the old IBM 360/370/390 architecture, the stack was a series of threaded frames in memory. Not only that, but they were statically allocated, if at all possible.

Good luck!

Share this Question
Share on Google+
5 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
I guess I am stuck at how you know there are no references to an allocation left in the program so that your garbage collector knows it's safe to delete the allocation.

In C++ you can use a managed pointer but I don't know how to to that in C.
Nov 7 '10 #2

P: 26
Is it possible that I take a pointer and increment its value till it exceeds stack boundary and I get some error ??
Nov 7 '10 #3

Banfa
Expert Mod 5K+
P: 8,916
Yes you could do that, of course the error you get might be a segmentation fault.

Your question lacks the detail to answer since the C standard does not even mandate that there should be a stack. Therefore all stacks are platform defined and finding the end of a stack would have to be a platform defined operation.

However you have not mentioned the platform.

Also you seem to be assuming that there is only 1 stack. Are you not running in a multi-threaded environment?
Nov 7 '10 #4

P: 26
yeah ... sorry for that....

I am working on linux platform and yes for the time being I am assuming a single stack and not associated with a multithreading environment....

Is there a particular error like SIGBUS that I can check for
???
Nov 8 '10 #5

Oralloy
Expert 100+
P: 983
nk28,

I think you're talking about SIGSEGV - segmentation violation.

From recollection, there are lots of problems with catching this signal. On some systems it may be impossible. Check your documentation very carefully.

The other thing you might attempt is to look into the complier's documentation and find the global variable that is supposed to have that value. Most compilers have it, the trick is finding the documentation on the default C-language start-up sequence.

All that said, Banfa has the right of it. Nothing in the specification states that there has to be a stack of any sort. We just assume a stack, because it's the common implementation mechanism.

That said, you also have to know if the stack is contiguous - in the old IBM 360/370/390 architecture, the stack was a series of threaded frames in memory. Not only that, but they were statically allocated, if at all possible.

Good luck!
Nov 8 '10 #6

Post your reply

Sign in to post your reply or Sign up for a free account.