Re: Doubt on segmentation fault
- From: Josef Moellers <josef.moellers@xxxxxxxxxxxxxx>
- Date: Fri, 31 Jul 2009 10:06:19 +0200
deepak wrote:
Hi,
This is my sample program.
main()
{
char *a;
int i;
for (i=0; i<5; i++) {
a[i] = i;
}
return 0;
}
This process fails due to SIGSEGV. Here how kernel is creating
segmentation fault.
I'm thinking like cpu will look into tlb for finding address of 'a'
and since it's absent will look into page-table where page-table finds
that it's not an address belonging to this process, it
generates a segmentation fault.
Please correct if my understanding is wrong.
The address is not "absent", it's just ... sort of ... unspecified: as you have not initialized "a", it will have whatever value was there before. If you're unlucky, it might be a valid data address and your program will happily over-write soem other data. If you're lucky, the address will either be an invalid address (i.e. not withing a virtual address range allocated to your process) or it will be the address of a read-only segment, e.g. a code segment. In that case, you'll get a SIGSEGV.
For the rest: you're right.
--
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html
.
- Follow-Ups:
- Re: Doubt on segmentation fault
- From: Rainer Weikusat
- Re: Doubt on segmentation fault
- References:
- Doubt on segmentation fault
- From: deepak
- Doubt on segmentation fault
- Prev by Date: Doubt on segmentation fault
- Next by Date: Re: Doubt on segmentation fault
- Previous by thread: Doubt on segmentation fault
- Next by thread: Re: Doubt on segmentation fault
- Index(es):
Relevant Pages
|