473,413 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

High address of stack in C

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!

5 2520
weaknessforcats
9,208 Expert Mod 8TB
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
nk28
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
9,065 Expert Mod 8TB
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
nk28
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
988 Expert 512MB
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

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

Similar topics

6
by: Sayan | last post by:
How do I distinguish between a heap pointer and a stack pointer? I want the following to work: template<class T> bool isHeapPtr(T* p1,T* p2);//the function I want to write //... int a = 5;...
1
by: Chris Cranford | last post by:
I am in the process of implementing a stack machine virtual environment where each entry on the stack is a 32-bit value which then can reference to any memory pointer, numeric value, or alike. ...
12
by: johny smith | last post by:
I am trying to figure out a way to print the address of what called a certain function once inside the function. I am assuming that this information is on the stack somewhere. But can someone...
2
by: AshifToday | last post by:
Expression Evaluation in Post-Fix Notation Using Stack ===================== /* This program has been made by Ashif Zubair. Roll # 1468, B.Sc.(Hons.) in C.S. ALL RIGHTS ARE RESERVED TO ASHIF...
22
by: ypjofficial | last post by:
Hello All, While readling the C and C++ literature i came to know that the OS allocates separate protected memory space for each running program and the program do not interfare into one another's...
3
by: gary | last post by:
Hi, 1. About all C/C++ compilers, Does stack increase from high address to low address and heap grow increase from low to high? What on earth decides their increase direction, CPU architecture, OS...
26
by: bahadir.balban | last post by:
Hi, When you define varibles in the middle of your function call (C99), such as: if(i == 5) { int x = 5; int z = 2; }
5
by: Joel | last post by:
I would like to learn if there is any difference between the stack that MSIL uses for each method for executing instructions and the stack that it uses for storing Value types. Are they the same?...
30
by: asit | last post by:
We kno that data can be pushed onto the stack or popped 4m it. Can stack be traversed ??
1
by: S S | last post by:
Hi Can someone please tell me if I can load the shared library at the given address. I do not want it to get it loaded on its own random selected address (I want to provide that). My basic...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.