Subject: Re: segmentation fault on fclose?
To: None <current-users@NetBSD.ORG>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: current-users
Date: 09/06/1994 10:18:41
>> I would consider that segmentation fault to be a debugging aid.
> [...]

> So, now that I'm bothering you gurus... why does *this* fail?

> #include <stdio.h>
> main()
> {
> char    buf[512 * 1024];
> }

> Is this some kernel size limitation?

Essentially, yes.  The thing is, the kernel has to have some way to
tell the difference between stack growth and wild pointers.

Normally, the stack is grown automatically by the kernel noticing a
memory fault just below the current stack limit, and growing the stack
to encompass the referred-to location.  But obviously there has to be a
limit, or wild pointer references could easily lead to the kernel
trying to make the stack enormous.  The price of this is that when a
program tries to grow the stack by a big step all at once, a
sufficiently big such step will be beyond the limit.  Half a meg seems
to be "sufficiently big" for your kernel.

> This same code (mSQL) is trying to use a 'buf[512 * 1024' and this is
> causing a segmentation fault.
> Is there anyway to fix this? (i.e. config file option)

Not that I know of.  You could probably make it one with comparatively
little work - or at least, it probably could be so made; whether _you_
can do it or not I can't say. :-)

But first, I'd recommend seriously thinking about whether you need to
allocate that much memory on the stack.  Do you really need a half-meg
array to be auto?  If not, consider declaring it static, which will
move it to data or bss, and avoid the stack growth problems you're

					der Mouse