[U-Boot] [PATCH] Prevent malloc with size 0

Graeme Russ
2012-10-16T22:41:38Z

Hi Wolfgang,

On Tue, Oct 16, 2012 at 9:43 PM, Wolfgang Denk <wd@denx.de> wrote:
> Dear Marek Vasut,
>
> In message <201210160831.20759.marex@denx.de> you wrote:
>>
>> > In short, returning non-NULL from malloc(0) and expecting a CPU exception
>> > when it is de-referenced is not going to fly.
>
> We should not expect to have support for any exceptions for any kind
> of illegal accesses. In general, behaviours is undetermined.
>
>> > [1] Apparently the way do do it is to reserve the entire first 4kB page and
>> > mark it as 'not-present' so any access causes a page-fault.
>>
>> Ok, I don't mean to reopen this can of worms again ... but what're we going to
>> do about this patch?
>
> NAK it.

That was my thought

> It is perfectly valid on most systems to dereference a pointer to
> address 0 (which in almost all cases looks the same as a NULL
> pointer).

In an OS environment, it is valid to dereference _physical_ address 0
but not _virtual_ address 0. To achieve this, you need to configure
the MMU accordingly. For x86, this means enabling paging and
configuring the physical/virtual address map...

> I object against patches that will make access to this data impossible
> (or even more complicated than it is now).

Exactly - way too complicated for the (questionable) benefit it provides.

Regards,

Graeme