Re: Doubt on segmentation fault



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.
.



Relevant Pages

  • Re: Doubt on segmentation fault
    ... Here how kernel is creating ... generates a segmentation fault. ... The address is not "absent", ... The startup code running before mainmay well have used that stack ...
    (comp.os.linux.development.system)
  • Doubt on segmentation fault
    ... This process fails due to SIGSEGV. ... Here how kernel is creating ... generates a segmentation fault. ...
    (comp.os.linux.development.system)
  • Re: [Bugme-new] [Bug 15005] New: Segmentation fault when shutting down
    ... Segmentation fault when shutting down ... Currently compiled newest kernel 2.6.32.3 for Atom based netbook (datacask ... : commit bb6eddf7676e1c1f3e637aa93c5224488d99036f upstream. ... So we may well have the same regression in 2.6.33-rcX. ...
    (Linux-Kernel)
  • year 9223372034708485227 problem
    ... Segmentation fault ... I'm not sure if it is kernel problem... ... still there after reboot? ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: [SLE] PHP and Apache2 re visited
    ... >if i try to run any php program in a Web browser all i get is the save file box popping up in Mozilla or the what do you want me to do with this box in Konqurer ... >Linux user No: 256242 ... Segmentation fault ... I'll pull back to an earlier kernel and see what gives. ...
    (SuSE)