Subject: Re: alloca in the kernel
To: Alfred Perlstein <>
From: Jaromir Dolecek <>
List: tech-kern
Date: 01/06/2002 13:09:17
Alfred Perlstein wrote:
> * Lennart Augustsson <> [020105 20:04] wrote:
> > alloca() is nasty, let's avoid it in the kernel.
> I've always assumed that alloca() gets its backing store from the
> stack, you definetly don't want to encourage allocating large things
> on the stack in the kernel, right?

Yes, exactly.

The bit in macppc machdep.c could theoretically easily be replaced
with malloc(9)/free(9). However, note it's initppc() function, and
thus the virtual system might not be initialized yet enough to use
malloc/free. In this case, alloca() there seems to be a fairly
clever way to allocate needed temporary storage. Since the (maximum)
ofmap length is not known in advance, it seems to be necessary
to allocate the (stack) memory on run-time. Is there an upper bound
of mmu.translations length? The code should at least check that
ofmaplen is smaller than size of kernel stack at that point.

Jaromir Dolecek <>
-=  Those who would give up liberty for a little temporary safety deserve  =-
-=  neither liberty nor safety, and will lose both.  -- Benjamin Franklin  =-