473,803 Members | 4,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

stack

jt
hello everyone..

int fun()
{
/* anything */
}
int main(void)
{
fun();
}

in this program, when the control is transferred to function fun()..
the return address is pushed to the stack..
Is it possible to access this value..??
Aug 3 '08
62 2879
"Chris Torek" <no****@torek.n etwrote in message
news:g7******** @news3.newsguy. com...
In article
<38************ *************** *******@v1g2000 pra.googlegroup s.com>
jt <ka**********@g mail.comwrote:
>>hello everyone..

int fun()
{
/* anything */
}
int main(void)
{
fun();
}

in this program, when the control is transferred to function fun()..
the return address is pushed to the stack..

Actually, it is put in the register "lr" (PPC), "ra" (MIPS), "%o7"
(SPARC), or 14 (IBM S/390; spelled %r14 in GNU assembler). As
others have noted, if fun() is expanded in line, there is no control
transfer at all. But on the VAX and PDP-11, it is indeed placed
on the (hardware) stack.
You left out x86-32. A little-used processor, I know...

--
Bartc

Aug 4 '08 #11
"jt" <ka**********@g mail.comwrote in message
news:38******** *************** ***********@v1g 2000pra.googleg roups.com...
hello everyone..

int fun()
{
/* anything */
}
int main(void)
{
fun();
}

in this program, when the control is transferred to function fun()..
the return address is pushed to the stack..
Is it possible to access this value..??
We've had a lot of "not in standard C" responses now.. what use are they?

Your compiler may have the intrinsic function _ReturnAddress( ) (and/or
_AddressOfRetur nAddress() ) available
You can also try to access 'the address of the last argument + its size' as
though it was a pointer-sized thing but that's less stable and very
implementation dependand

Aug 4 '08 #12
Harold Aptroot wrote:
"jt" <ka**********@g mail.comwrote in message
news:38******** *************** ***********@v1g 2000pra.googleg roups.com...
>hello everyone..

int fun()
{
/* anything */
}
int main(void)
{
fun();
}

in this program, when the control is transferred to function fun()..
the return address is pushed to the stack..
Is it possible to access this value..??

We've had a lot of "not in standard C" responses now.. what use are
they?
If they manage to redirect the OP to a more suitable forum, then IMO,
they served their purpose.
Your compiler may have the intrinsic function _ReturnAddress( ) (and/or
_AddressOfRetur nAddress() ) available
Which compiler has the latter function (just curious)?
You can also try to access 'the address of the last argument + its
size' as though it was a pointer-sized thing but that's less stable
and very implementation dependand
This is probably the worst method (if once could call it that) that I've
seen so far.

The return address is a feature of the *implementation * , which in the
vast majority of cases uses features of the underlying processor to
accomplish this. Thus for a robust solution to the OP's problem, one
needs to determine the details of the implementation and the underlying
hardware.

Aug 4 '08 #13
jacob navia schrieb:
Of course it is. Most viruses do.
But we will not tell you how.
No. Most viruses don't. Many worms do.

Regards,
Johannes

--
"Wer etwas kritisiert muss es noch lange nicht selber besser können. Es
reicht zu wissen, daß andere es besser können und andere es auch
besser machen um einen Vergleich zu bringen." - Wolfgang Gerber
in de.sci.electron ics <47************ ***********@new s.freenet.de>
Aug 4 '08 #14
Is it possible to access this value..??
No.
Aug 4 '08 #15
"santosh" <sa*********@gm ail.comwrote in message
news:g7******** **@registered.m otzarella.org.. .
Harold Aptroot wrote:
>"jt" <ka**********@g mail.comwrote in message
news:38******** *************** ***********@v1g 2000pra.googleg roups.com...
>>hello everyone..

int fun()
{
/* anything */
}
int main(void)
{
fun();
}

in this program, when the control is transferred to function fun()..
the return address is pushed to the stack..
Is it possible to access this value..??

We've had a lot of "not in standard C" responses now.. what use are
they?

If they manage to redirect the OP to a more suitable forum, then IMO,
they served their purpose.
And the OP still wouldn't know anything
Which is great, because most people in clc are just here to flame people who
ask questions that in their opinion don't belong there - without answering
them first.
>
>Your compiler may have the intrinsic function _ReturnAddress( ) (and/or
_AddressOfRetu rnAddress() ) available

Which compiler has the latter function (just curious)?
Some versions of MSVC
>You can also try to access 'the address of the last argument + its
size' as though it was a pointer-sized thing but that's less stable
and very implementation dependand

This is probably the worst method (if once could call it that) that I've
seen so far.
It's very bad
I've seen it work though, and that's all that really matters (most virusses
are platform specific anyway)

The return address is a feature of the *implementation * , which in the
vast majority of cases uses features of the underlying processor to
accomplish this. Thus for a robust solution to the OP's problem, one
needs to determine the details of the implementation and the underlying
hardware.
Or just assume it'll be the most common implementation and let the OP
complain when that assumption turns out to be false?

An other solution that will not sit well with C-purists but should work:
inline assembly!

Aug 4 '08 #16
"MisterE" <Mi*****@nimga. comwrote in message
news:48******** *************** @news.optusnet. com.au...
>
>Is it possible to access this value..??

No.
Of course it is
The OP did not request a standard compliant way to do it after all

Aug 4 '08 #17
Harold Aptroot wrote:
"santosh" <sa*********@gm ail.comwrote in message
news:g7******** **@registered.m otzarella.org.. .
>Harold Aptroot wrote:
>>"jt" <ka**********@g mail.comwrote in message
news:38******* *************** ************@v1 g2000pra.google groups.com...
>>>hello everyone..

int fun()
{
/* anything */
}
int main(void)
{
fun();
}

in this program, when the control is transferred to function fun()..
the return address is pushed to the stack..
Is it possible to access this value..??

We've had a lot of "not in standard C" responses now.. what use are
they?

If they manage to redirect the OP to a more suitable forum, then IMO,
they served their purpose.

And the OP still wouldn't know anything
The O.P. has learned that his problem cannot be solved
with unaided C. The O.P. has also been directed to a place
where he might learn more.

Look at it this way: When you conduct a Google search you
do not receive information about the subject you searched for.
Rather, you receive a whole bunch of pointers to other places
that might provide information. Since Google gives the searcher
only links but no actual data, do you consider Google useless?
Which is great, because most people in clc are just here to flame people
who ask questions that in their opinion don't belong there - without
answering them first.
I think not. There are some who visit this newsgroup for
nothing more (it seems) than the sheer joy of polluting; they
have found their way into my killfile. But my killfile for this
group has only (checks) four entries, so I take issue with your
use of "most" and suggest "some" as an alternative.
[...]
An other solution that will not sit well with C-purists but should work:
inline assembly!
Still better would be inline COBOL, which at least has
a "C" in it.

--
Eric Sosman
es*****@ieee-dot-org.invalid
Aug 4 '08 #18
"Harold Aptroot" <ha************ @gmail.comwrite s:
"santosh" <sa*********@gm ail.comwrote in message
news:g7******** **@registered.m otzarella.org.. .
>Harold Aptroot wrote:
[...]
>>We've had a lot of "not in standard C" responses now.. what use are
they?

If they manage to redirect the OP to a more suitable forum, then IMO,
they served their purpose.

And the OP still wouldn't know anything
[...]

Nonsense. The OP has already gotten the best answer we can give him
with regard to the C language, that it provides no portable way to get
the return address. He's far more likely to get a *useful* answer
that will help him do what he wants to do by posting to a more
suitable forum.

As for the multiplicity of answers saying essentially the same thing,
that's a consequence of the fact that Usenet is asynchronous; several
people post answers before seeing the others. There's no easy
solution to this in an unmoderated newsgroup. (I note that
comp.lang.c.mod erated has even more of a problem with multiple similar
answers than comp.lang.c does, because of long latency and the
moderator's choice not to reject duplicate answers.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Aug 4 '08 #19
jt wrote:
>
int fun() {
/* anything */
}
int main(void) {
fun();
}

in this program, when the control is transferred to function fun()..
the return address is pushed to the stack..
Is it possible to access this value..??
In a machine that can execute the standard C language, there is no
need for a stack. This makes it hard to access a return address
(of unknown form) stored in a non-existant stack.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
Aug 4 '08 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
7745
by: Andrew | last post by:
Last night I was reading about implementing my own stack. The example given pushes items on and off the stack at the start and end of each procedure (ie. in a std module). What's not so clear is how this would work with class objects. In this case do you have to push the object on the stack at the start of every public procedure etc. in the class and pop it off at the end? I can't see how else you can know which object is active - or...
14
30102
by: Kevin Grigorenko | last post by:
Hello, I couldn't find an obvious answer to this in the FAQ. My basic question, is: Is there any difference in allocating on the heap versus the stack? If heap or stack implementation is not part of the standard, then just disregard this question. Here's some questions I'm confused about, and if you can add anything else, please do so! Is the stack limited for each program?
4
2624
by: Chris Mabee | last post by:
Hello all, and Merry Christmas, I'm having a problem understanding an example of an array based implementation of a stack in a textbook of mine. The code in question is written below. The syntax is directly as in the book, except for where I added the comments at the lines I wanted to refer to or to skip sections of code. template <class Element_Type> class Stack {
4
3631
by: anonymous | last post by:
Thanks your reply. The article I read is from www.hakin9.org/en/attachments/stackoverflow_en.pdf. And you're right. I don't know it very clearly. And that's why I want to understand it; for it's useful to help me to solve some basic problem which I may not perceive before. I appreciate your help, sincerely.
8
2100
by: LedZep | last post by:
What up everyone, I have to write a program that uses a stack to determine whether a string is a palindrome (a string that is spelled identically backward and forward). The program has to ignore spaces, case sensitivity and punctuation. I need three text boxes. The first will be for input of the string. The second will display the string when the "check" button is clicked and the result of the analysis (string is a palindrome or is...
4
2150
by: alisaee | last post by:
plz check what i have made wrong what is requierd her is to creat class queue and class stack and run the push,pop operation . #include<iostream.h> #include<conio.h> #include<stdio.h> class stack { public:
16
4451
by: sarathy | last post by:
Hi all, I need a few clarifications regarding memory allocaion in C++. I apologize for the lengthy explanation. 1. In C++, Objects are allocated in heap. What does heap refer to? Is it an area in RAM/Memory or does it refer to a data structure being used for storing objects. 2. In C++, functions and its local variables go in stack. If local variables that are primitives go in stack, it is OK. But what
24
6592
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means the stack pointer should go upwards when there are "push" operations, and stack pointer should go downards when there are "pop" operations?? If this is the case, the address should go upwards (increasing) or downards (decreasing) then? i.e....
1
4223
by: alfie27 | last post by:
I currently have a working program that is a stack that stores integers. Now i have to convert it to store strings instead of integers. I have been working on this for hours and just keep getting errors of all kinds. I have decided to start from scratch. Any suggestions someone can give me would be greatly appreciated!! Here is the current code: #include <iostream> using std::cout; using std::cin; #include <cstring> using std::strcpy;
11
1788
by: tom | last post by:
Hi! Im new to Python and doing exercise found from internet. It is supposed to evaluate expression given with postfix operator using Stack() class. class Stack: def __init__(self): self.items = def push(self, item): self.items.append(item)
0
9699
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10309
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10068
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4274
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.