2004-10-05 13:25:32

by Andrei A. Voropaev

[permalink] [raw]
Subject: PROBLEM: large auto variables cause segfault under 2.6

Declaring very large auto variables cause segfaults in the program under
2.6 kernel.

Take a look at this program.

int main( int argc, char **argv )
{
unsigned char bRet = 0;

char tst[67123456];


const char* pcSupportedParams = "d:t:lV:C:cP:h";

printf("pcSupportedParams = %s\n");
return 0;
}

When compiled it produces segfault under kernel 2.6.8.1. The problem is
with that large array. Under 2.4 kernel the program gets its memory
region automatically extended to accomodate for large auto variables.
Under 2.6 it gets segment violation signal.


2004-10-05 13:41:17

by Arjan van de Ven

[permalink] [raw]
Subject: Re: PROBLEM: large auto variables cause segfault under 2.6

On Tue, 2004-10-05 at 15:27, Andrei A. Voropaev wrote:
> Declaring very large auto variables cause segfaults in the program under
> 2.6 kernel.
>
> Take a look at this program.
>
> int main( int argc, char **argv )
> {
> unsigned char bRet = 0;
>
> char tst[67123456];
>
you have a stack variable that is several orders of magnitude bigger
than the rlimit you have set for the stack I suspect. Try increasing the
stack rlimit...


Attachments:
signature.asc (189.00 B)
This is a digitally signed message part

2004-10-05 13:45:57

by Andrei A. Voropaev

[permalink] [raw]
Subject: Re: PROBLEM: large auto variables cause segfault under 2.6

On Tue, Oct 05, 2004 at 03:40:52PM +0200, Arjan van de Ven wrote:
> On Tue, 2004-10-05 at 15:27, Andrei A. Voropaev wrote:
> > Declaring very large auto variables cause segfaults in the program under
> > 2.6 kernel.
> >
> > Take a look at this program.
> >
> > int main( int argc, char **argv )
> > {
> > unsigned char bRet = 0;
> >
> > char tst[67123456];
> >
> you have a stack variable that is several orders of magnitude bigger
> than the rlimit you have set for the stack I suspect. Try increasing the
> stack rlimit...
>

Yep. I was just going to write "excuse me" letter. Looks like under new
kernel the kernel stack is limited to 8M while under 2.4 kernel it is
unlimited. So setrusage should help us.

Sorry for distractions.

Andrei


2004-10-07 15:10:39

by Tonnerre

[permalink] [raw]
Subject: Re: PROBLEM: large auto variables cause segfault under 2.6

Salut,

On Tue, Oct 05, 2004 at 03:27:41PM +0200, Andrei A. Voropaev wrote:
> int main( int argc, char **argv )
> {
> unsigned char bRet = 0;
>
> char tst[67123456];
>
>
> const char* pcSupportedParams = "d:t:lV:C:cP:h";
>
> printf("pcSupportedParams = %s\n");
> return 0;
> }

It might also crash because your printf is printing something odd.

Tonnerre


Attachments:
(No filename) (414.00 B)
signature.asc (189.00 B)
Digital signature
Download all attachments