In article <Pine.LNX.3.96.990521100207.12723B-100
...@deadlock.et.tudelft.nl>,
Joris van Rantwijk <jo
...@deadlock.et.tudelft.nl> wrote:
>Kernel 2.2.7 still has the same problem.
As has been mentioned by others: it's not a problem, it's a feature.
Linux will refuse to extend the stack beyond the stack pointer. Using
memory under the stack pointer is not considered acceptable, so you
should never do something like this (pseudocode):
*(esp-128) = val;
esp -= 128;
because it just sets you up for bugs when a signal comes in and trashes
what you had on the stack.
"enter" is a special, and very ugly x86 instruction that does exactly
the above. It so happens that we _could_ allow it, but as others have
mentioned, using "enter" in the first place is just stupid anyway, so
there really isn't any reason to allow that kind of braindamage.
>I did some more tests and found out that in my case (2.2.7 on i486) the
>problem only occurs when reserving more than 28 bytes of local storage
>(ESP gets decremented by more than 32).
Indeed. Linux allows a small amount of slop underneath the stack
pointer, because "pusha" has the same problem, and for "pusha" there is
no good alternative way of doing the same thing.
>I think this may be related to the following code from the kernel
>linux/arch/i386/fault.c (line 124) :
> /*
> * accessing the stack below %esp is always a bug.
> * The "+ 32" is there due to some instructions (like
> * pusha) doing post-decrement on the stack and that
> * doesn't show up until later..
> */
> if (address + 32 < regs->esp)
> goto bad_area;
Exactly. The comment pretty much says it all.
>The enter seems to check page availability for the entire stack region it
>claims
No. I think "enter" claims page availability for just the last byte it
claims, not the whole region.
> (which is odd since it only needs to access the upper 4 bytes,
>but then again the intel docs do say that it checks the SS limit for the
>entire region).
"enter" is just basically a horrible crock, and should not be used in
any case. It's slower than the (much more natural) alternatives, and
generally just doesn't have any redeeming features at all.
>My guess is that Linux simply doesn't support the ENTER insn (I think GCC
>doesn't use it).
Sure, you can use it, but you can't depend on Linux being nice to you
and extending the stack automatically. If you extend the stack by hand
before using enter, you can then use it if you want (another way of
saying "if you really know what you're doing, Linux lets you shoot
yourself in the head if you want to"). The example could be something
like this:
/* allocate 32kB of stack space */
subl $32768,%esp
movl $0,0(%esp)
addl $32768,%esp
/* now you can use enter to your hearts content */
enter 256,0
but it's not as if I really see the reason for doing something like the
above ;)
Linus