Re: gmalloc prevents a "Bus error"
Re: gmalloc prevents a "Bus error"
- Subject: Re: gmalloc prevents a "Bus error"
- From: Brad Oliver <email@hidden>
- Date: Tue, 4 Oct 2005 00:52:22 -0700
On Oct 3, 2005, at 8:42 PM, email@hidden wrote:
Could someone explain to me in simple terms how turning on the most
aggressive memory checking could make the error disappear
altogether? Sorry if this is a bit elementary.
gmalloc works by putting a "guard page" at the beginning and end of
each memory allocation and marking it as neither readable or
writable. When your app hits this memory, you get caught.
The secret to the magic is that it implements this using virtual
memory pages, which are 4096 bytes in size. This has two
implications. One: all your memory allocations are now at least 4096
bytes in size, rounded up to the nearest 4k boundary. Two: the guard
page will work very effectively for one end of the memory allocation,
not so much for the other. You can't detect an off-by-one error on
both sides of the memory block since only one of them will directly
abut a VM guard page.
What this means is that it's possible that you're still overwriting
memory with gmalloc, but you're doing it off the end of the block
that isn't immediately bounded by a VM guard page. As I recall,
gmalloc has a provision to change the block boundaries to align to
the start (to detect buffer underflows) or the end of the blocks (for
overflows), so you might want to change that setting and try running
your app again.
There may be other esoteric reasons why gmalloc "helps" your app; I
don't know exactly how the implementation works.
--
Brad Oliver
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden