|
From: | Paolo Bonzini |
Subject: | [Qemu-devel] Re: [PATCH] Permit zero-sized qemu_malloc() & friends |
Date: | Sun, 06 Dec 2009 17:23:03 +0100 |
User-agent: | Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4pre) Gecko/20090922 Fedora/3.0-3.9.b4.fc12 Lightning/1.0pre Thunderbird/3.0b4 |
On 12/06/2009 01:02 PM, malc wrote:
On Sun, 6 Dec 2009, Paolo Bonzini wrote:On 12/06/2009 11:22 AM, malc wrote:Here, i believe, you are inventing artificial restrictions on how malloc behaves, i don't see anything that prevents the implementor from setting aside a range of addresses with 31st bit set as an indicator of "zero" allocations, and then happily giving it to the user of malloc and consumming it in free.But it has to make it a valid address anyway. If a zero-sized read treats it as invalid (SIGSEGV, EFAULT, whatever), malloc has failed to return a valid address and is not obeying its specification.Once again - standard doesn't speak about "valid addresses".
For that matter, POSIX doesn't mention EFAULT at all, and doesn't include detecting "valid addresses" among the things that read can do before returning 0. So if an OS extends POSIX with EFAULT, it had better provide a malloc that is consistent with whatever definition of "valid address" EFAULT uses. While if it doesn't provide EFAULT, read should return 0 for the OS to be conforming to POSIX, and the whole discussion is moot.
Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |