[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: failed to protect memory on Solaris
From: |
David Chisnall |
Subject: |
Re: failed to protect memory on Solaris |
Date: |
Tue, 15 Jun 2010 10:27:51 +0100 |
On 15 Jun 2010, at 01:02, Riccardo Mottola wrote:
> mprotect() wants a page-aligned address on Solaris.
> - valloc instead of malloc, valloc just one page
> - mprotect exactly that page, not size
> - before freeing, make the page writable again.
I went through this code with Riccardo last night. On other platforms, it's
likely that this was the cause of some subtle bugs.
Due to limitations of the hardware, mprotect() only works at the page
granularity. Solaris, helpfully, tells you that you're doing something wrong
if you try to protect memory allocations smaller than a page. Other operating
systems don't; the mprotect() call will silently protect the entire page.
Other bits of this page may have been allocated to other variables with malloc,
or they may subsequently be allocated (because malloc on most platforms expects
to be able to write to memory that it has requested from the kernel but not
given to the user, marking a page read-only when not all of it is allocated may
cause malloc() to crash for no apparent reason).
I think that we use mmap() to get exactly one page on other platforms. This
fix now gets exactly one page on platforms where mmap() is not available.
David
-- Sent from my Apple II