[llvmlinux] Can alloca() be used in the kernel instead of VLAIS or VLA?

Behan Webster behanw at converseincode.com
Mon Feb 2 20:22:52 UTC 2015


On 02/02/15 15:04, David Woodhouse wrote:
> On Mon, 2015-02-02 at 20:28 +0100, Behan Webster wrote:
>>> The real reason we don't use alloca() in the kernel is because the
>>> kernel has very limited stack space.
>> That makes sense.
>>
>> Though for a similarly sized piece of memory you would allocate as an
>> automatic variable, wouldn't alloca then also be okay?
> You might possibly think that. It might even seem logical.
>
> But alloc() screams "HAHA I AM ALLOCATING VARIABLY-SIZED STUFF ON THE
> STACK. LOOK AT ME. WHAT BOUNDS ARE THERE ON THE SIZE OF THIS OBJECT?" in
> a way that VLAIS does not.
LOL!

> So if you're "fixing" the VLAIS, sometimes you might get prodded to fix
> it *differently* rather than just changing it to alloca().
That makes sense.

We certainly haven't used alloca so far in our efforts. For small things
we've used automatic variables (for things which are guaranteed to
always be small) and for larger things kmalloc.

Behan

-- 
Behan Webster
behanw at converseincode.com



More information about the LLVMLinux mailing list