GDT Expand-down and up
- matias_beretta
- Member
- Posts: 101
- Joined: Mon Feb 26, 2007 3:39 pm
GDT Expand-down and up
GDT: What's the difference between expand-down and expand-up??
MatÃas Beretta
- matias_beretta
- Member
- Posts: 101
- Joined: Mon Feb 26, 2007 3:39 pm
- matias_beretta
- Member
- Posts: 101
- Joined: Mon Feb 26, 2007 3:39 pm
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
the difference is in what part of the segment is valid.
expand-up segments allow offsets from 0 to limit while expand-down segments allow from limit to 0xffffffff.
Even if you don't plan to expand your segments, it still makes sense to use expand-down segments for your stacks, as it gives you a stronger way to detect stack overflow (e.g. through the Stack Fault exception).
OS that relies on page faults and try to "guess" whether the program is just needing more stack or doing an invalid access may sometimes get fooled by allocation of a large array on the stack, e.g.
may work on some linux distros and (surprisingly?) crash on others.
Note, though, that using expand-down stack segment behaves weirdly in the usual C memory model (assuming DS.base == SS.base), requiring setup tricks and usually meaning that you traded stack-overflow protection against stack underflow protection...
expand-up segments allow offsets from 0 to limit while expand-down segments allow from limit to 0xffffffff.
Even if you don't plan to expand your segments, it still makes sense to use expand-down segments for your stacks, as it gives you a stronger way to detect stack overflow (e.g. through the Stack Fault exception).
OS that relies on page faults and try to "guess" whether the program is just needing more stack or doing an invalid access may sometimes get fooled by allocation of a large array on the stack, e.g.
Code: Select all
void f() {
char huge[1024*1024];
huge[1024*1024-1]='d';
}
Note, though, that using expand-down stack segment behaves weirdly in the usual C memory model (assuming DS.base == SS.base), requiring setup tricks and usually meaning that you traded stack-overflow protection against stack underflow protection...