Re: Doubt on segmentation fault
- From: Rainer Weikusat <rweikusat@xxxxxxxxxxx>
- Date: Fri, 31 Jul 2009 13:20:27 +0200
Josef Moellers <josef.moellers@xxxxxxxxxxxxxx> writes:
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.
In this particular case, assuming the object is really allocated on
the stack, the value should always be zero. Otherwise, whatever the
last user of the corresponding page might have written to it would
become available to an unrelated process.
.
- Follow-Ups:
- Re: Doubt on segmentation fault
- From: Josef Moellers
- Re: Doubt on segmentation fault
- From: Måns Rullgård
- Re: Doubt on segmentation fault
- References:
- Doubt on segmentation fault
- From: deepak
- Re: Doubt on segmentation fault
- From: Josef Moellers
- Doubt on segmentation fault
- Prev by Date: Re: Doubt on segmentation fault
- Next by Date: Re: Doubt on segmentation fault
- Previous by thread: Re: Doubt on segmentation fault
- Next by thread: Re: Doubt on segmentation fault
- Index(es):
Relevant Pages
|