09-15-2005
A solution involving portable C eludes me! I naturally rejected the idea of having change() locate its return address on the stack and alter it to step over the i=10 statement. The precise location of the return address and even whether to increment it or decrement it and certainly by how much can vary from system to system. There is really no guarantee that the return address will be stored on the stack or even that there is a stack. I admit that I don't know of any currently marketed unix systems without a stack or that move the PC backwards. But I also don't know of any standard prohibiting them. These days we are in transistion from 32 bit to 64 bit architectures. Most versions of unix currently support executables in either architecture. So the change() function would need to detect the length of the return address as well.
But the other problem that I see with this involves agressive optimization. There is no indication that i is accessible to change() or is otherwise aliased or volatile. So there is no reason that the compiler writer could not legally choose to emit code that operates like...
i=10;
change();
printf("%d",i);
Whether or not that would happen would probably depend on the optimization level selected and the compiler used, and whether or not the resulting executable is intended to interact with a symbolic debugger.
So if you have a portable solution, I would love to see it!
9 More Discussions You Might Find Interesting
1. Programming
I'm now designing a server application which can serve large number of clients' request. I've a question to ask, that is, main process will block when invoke the "accept" function, if a client request comes, main process should be separated into 2 processes by invoking "fork" function, the parent... (4 Replies)
Discussion started by: acqy
4 Replies
2. UNIX for Advanced & Expert Users
well, my internet brakes down every day because of my server, i don't have troubles with RAM or anything i think... that problem started since i am running an unrealircd server...
well, my internet brakes down and when i try to access the inside ip from the server on http port 80, it says that:... (2 Replies)
Discussion started by: AiRkO
2 Replies
3. UNIX for Advanced & Expert Users
Hi, all,
The following commands could compute the 10 most frequent bigrams from a input sequence which is in a file infile.
I would like to know whether there is somebody who can use only two unix commands to do the same work.
--------------------
tr " " "\012*" <infile >out1
tail +2... (3 Replies)
Discussion started by: vicky20000
3 Replies
4. UNIX for Advanced & Expert Users
Hi!
My unix os version is OSF1 CP1 V4.0 878 alpha.
It startup normally but it restarts within 5 sec.
I would like to know how to solve .
Please reply to me.
Thanks .
akzin (2 Replies)
Discussion started by: akzin
2 Replies
5. IP Networking
I have a Red Hat linux server X on a x.x.0.0 network. This machine also has to communicate with another server Y on a network called y.y.0.0
Server X has two network interfaces.
eth0 is configured on the x.x.0.0 network and has a default gateway on the x.x.0.0 network.
In order to... (4 Replies)
Discussion started by: soliberus
4 Replies
6. UNIX for Advanced & Expert Users
I have a file process.txt
I wanted to just grab data in "process" column.
Name process process_id status
Adminserver adminserver 22669 Running
Browser Engine browserengine ... (7 Replies)
Discussion started by: soemac
7 Replies
7. Shell Programming and Scripting
Take a look on this code:
#!/bin/sh
currentpath=`pwd`
if ; then
#Normal user
if ; then
"$currentpath"/.cleaner
else
./runit
fi
else
#Root user
if ; then
rm -r /some
fi
mkdir /some
cd /home/
echo "`ls --group-directories-first -1`" > /some/allusers
cat /some/allusers | sed 's/... (17 Replies)
Discussion started by: hakermania
17 Replies
8. Shell Programming and Scripting
Hi all,
I have a file.....
I want to print 2nd column arranged according to order of first column, present in second file.....
So, the output should be:
I am using following code:
awk 'NR==FNR{a=$2;next}{print a?a:"ABSENT\t"}' file1 file2
But, it seems that the... (3 Replies)
Discussion started by: CAch
3 Replies
9. Shell Programming and Scripting
Hello,
I would really appreciate some help into approaching this problem:
- i have a random txt file with x lines and y rows following this pattern:
ex:
ip1 | user1 | command
ip2 | user2 | command
ip3 | user3 | command
- i need to telnet/ssh into these ip's, login with... (7 Replies)
Discussion started by: catalinstk
7 Replies
LEARN ABOUT LINUX
pthread_attr_setstackaddr
PTHREAD_ATTR_SETSTACKADDR(3) Linux Programmer's Manual PTHREAD_ATTR_SETSTACKADDR(3)
NAME
pthread_attr_setstackaddr, pthread_attr_getstackaddr - set/get stack address attribute in thread attributes object
SYNOPSIS
#include <pthread.h>
int pthread_attr_setstackaddr(pthread_attr_t *attr, void *stackaddr);
int pthread_attr_getstackaddr(pthread_attr_t *attr, void **stackaddr);
Compile and link with -pthread.
DESCRIPTION
These functions are obsolete: do not use them. Use pthread_attr_setstack(3) and pthread_attr_getstack(3) instead.
The pthread_attr_setstackaddr() function sets the stack address attribute of the thread attributes object referred to by attr to the value
specified in stackaddr. This attribute specifies the location of the stack that should be used by a thread that is created using the
thread attributes object attr.
stackaddr should point to a buffer of at least PTHREAD_STACK_MIN bytes that was allocated by the caller. The pages of the allocated buffer
should be both readable and writable.
The pthread_attr_getstackaddr() function returns the stack address attribute of the thread attributes object referred to by attr in the
buffer pointed to by stackaddr.
RETURN VALUE
On success, these functions return 0; on error, they return a nonzero error number.
ERRORS
No errors are defined (but applications should nevertheless handle a possible error return).
VERSIONS
These functions are provided by glibc since version 2.1.
CONFORMING TO
POSIX.1-2001 specifies these functions but marks them as obsolete. POSIX.1-2008 removes the specification of these functions.
NOTES
Do not use these functions! They cannot be portably used, since they provide no way of specifying the direction of growth or the range of
the stack. For example, on architectures with a stack that grows downwards, stackaddr specifies the next address past the highest address
of the allocated stack area. However, on architectures with a stack that grows upwards, stackaddr specifies the lowest address in the
allocated stack area. By contrast, the stackaddr used by pthread_attr_setstack(3) and pthread_attr_getstack(3), is always a pointer to the
lowest address in the allocated stack area (and the stacksize argument specifies the range of the stack).
SEE ALSO
pthread_attr_init(3), pthread_attr_setstack(3), pthread_attr_setstacksize(3), pthread_create(3), pthreads(7)
COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
Linux 2008-10-24 PTHREAD_ATTR_SETSTACKADDR(3)