Re: [CHECKER] large stack variables (>=1K) in 2.4.4 and 2.4.4-ac8

dean gaudet
2001-05-25T15:45:38Z

On Fri, 25 May 2001, Andi Kleen wrote:

> On Fri, May 25, 2001 at 04:03:57PM +0200, Oliver Neukum wrote:
> > Is there a reason for the task structure to be at the bottom rather than the
> > top of these two pages ?
>
> This way you save one addition for every current access; which adds to
> quite a few KB over the complete kernel.

hrm, really?

i think it really depends on how you use current -- here's an alternative
usage which can fold the extra addition into the structure offset
calculations, and moves the task struct to the top of the stack.

not that this really solves anything, 'cause a stack underflow will just
trash something else rather than the task struct :)

-dean

% cat task.c
struct task {
int a;
int b;
};

#define current(p) (((struct task *)(((unsigned)p | 0x1fff)+1))-1)
int foo(void *p)
{
return current(p)->a + current(p)->b;
}
% gcc -O -c task.c
% objdump -dr task.o

task.o: file format elf32-i386

Disassembly of section .text:

00000000 <foo>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 55 08 mov 0x8(%ebp),%edx
6: 81 ca ff 1f 00 00 or $0x1fff,%edx
c: 8b 42 fd mov 0xfffffffd(%edx),%eax
f: 03 42 f9 add 0xfffffff9(%edx),%eax
12: c9 leave
13: c3 ret