![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| segmentation fault | rockgal | High Level Programming | 8 | 12-05-2006 09:16 AM |
| Segmentation Fault | compbug | UNIX for Dummies Questions & Answers | 3 | 04-21-2006 07:43 AM |
| segmentation fault | wojtyla | High Level Programming | 3 | 02-19-2005 11:53 AM |
| Segmentation fault | jshaulis | AIX | 1 | 06-01-2004 01:16 PM |
| segmentation fault | omran | High Level Programming | 2 | 08-01-2003 05:19 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#8
|
|||
|
|||
|
Unfortunately the libraries in use may confuse the issue for you.
This code: Code:
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void handlesegfault(int sig) {
printf("Segv detected..exiting.\n");
exit(1);
}
int main(void) {
int y = 0;
char x[12];
signal(SIGSEGV,handlesegfault);
while (1) {
bzero(x,(y++));
printf("%s at %d\n",x,y);
}
}
|
| Forum Sponsor | ||
|
|
|
#9
|
|||
|
|||
|
Hi ramen_noodle,
It is a very interesting example. I didn't know this type of glibc "protection". Is there any way to disable this behavior?? perhaps a gcc parameter? Thanks a lot! |
|
#10
|
|||
|
|||
|
Hi
Is there a minimum size of the stack in a C program?
If I have only one variable (type int) in a function, what will be the size of the stack? I know that it depends on the implementation but, is there an standard size? Thanks!!! |
|
#11
|
|||
|
|||
|
The stack frame is one page minimum. the pagesize command is found on a lot of machines, try it. If you do not have it you'll have to run something like this:
Code:
#include <unistd.h>
int main()
{
printf("%d\n", getpagesize() );
return 0;
}
|
|
#12
|
|||
|
|||
|
Hi
Thank you very much!! you know a lot of Linux programming!
Do you think that my problem may be because of the size of the stack?? My problem is in the first post of this thread, and the question is "Why 2 bytes are not enough to get a segmentation fault message ?? " Thanks again! |
|
#13
|
|||
|
|||
|
In your case SIGSEGV is caused by a stack overflow. The size of each stack frame varies by OS since it is allocated by the processor at runtime. It is not the same as the system pagesize. Max size of a stack frame is determined by the number of bits taken up by the displacement field. On AIX the stu/stwu instruction pushes a frame onto the stack which has 16 (signed) bits allocated giving a max size of 32K. Generate assembly code listing of your C program and figure out which instruction is used to allocate a frame on the stack. If it uses mnemonics like SP (stack pointer) then it might be easy to decode else compiler generated assembly is confusing. Read more about it here
|
|
#14
|
|||
|
|||
|
You can also get stack frame size from cc -s myfile.c by address subtraction.
And one some systems the minimum stack frame is one page - you can actually allocate stackframes for pthreads, if you're willing to suffer through it, as well as set the size of the stack and the address of the stack. eg., pthread_attr_setstacksize(), pthread_attr_setstackaddr(), pthread_attr_getstackaddr().... glibc backtrace() with some programming examples to print the stack frame in C using glibc: Stack Backtracing Inside Your Program |
|||
| Google The UNIX and Linux Forums |