public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [x86] Access off the bottom of stack causes a segfault?
@ 2003-10-14 18:31 Chris Lattner
  2003-10-14 18:37 ` Davide Libenzi
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Chris Lattner @ 2003-10-14 18:31 UTC (permalink / raw)
  To: linux-kernel


My compiler is generating accesses off the bottom of the stack (address
below %esp).  Is there some funny kernel interaction that I should be
aware of with this?  I'm periodically getting segfaults.

Example:

int main() {
   int test[4000];
...
   return 0;
}

Generated code:
        .intel_syntax
...
main:
        mov DWORD PTR [%ESP - 16004], %EBP    # Save EBP to stack
        mov %EBP, %ESP                        # Set up EBP
        sub %ESP, 16004                       # Finally adjust ESP
        lea %EAX, DWORD PTR [%EBP - 16000]    # Get the address of the array
...
        mov %EAX, 0                           # Setup return value
        mov %ESP, %EBP                        # restore ESP
        mov %EBP, DWORD PTR [%ESP - 16004]    # Restore EBP from stack
        ret

This seems like perfectly valid X86 code (though unconventional), but it
is causing segfaults pretty consistently (on the first instruction).
Does the linux kernel assume that page faults will be above the stack
pointer if the stack needs to be expanded?

Thanks,

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2003-10-17 23:55 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-14 18:31 [x86] Access off the bottom of stack causes a segfault? Chris Lattner
2003-10-14 18:37 ` Davide Libenzi
2003-10-14 19:00   ` Chris Lattner
2003-10-14 18:45     ` Davide Libenzi
2003-10-14 19:28     ` Richard B. Johnson
2003-10-14 19:48       ` Chris Lattner
2003-10-17 23:55         ` Jamie Lokier
2003-10-14 20:47     ` Mikael Pettersson
2003-10-14 18:42 ` Brian Gerst
2003-10-14 18:49 ` Chris Lattner
2003-10-14 18:42   ` Petr Vandrovec
2003-10-14 19:02     ` Chris Lattner
2003-10-14 19:18 ` Richard B. Johnson
2003-10-14 20:43   ` H. Peter Anvin
2003-10-17  0:23 ` Eric W. Biederman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox