Hi Alex,
I had a similar need for an underlying Win32 function
(IsBadReadPtr and it's bretheren). I ended up poaching
some ideas from the MoreIsBetter stack backtrace code.
I bet there's another more [efficient, elegant,
effective, etc] way to accomplish this, but hey, it
seems to work.
cheers, Brendan Creane
Boolean
memIsValid(vm_address_t addr, size_t numOfBytes)
{
vm_address_t dstPtr =
(vm_address_t)malloc(numOfBytes);
mach_port_t thisTask = mach_task_self();
vm_size_t sizeRead = numOfBytes;
int err;
err = vm_read_overwrite(thisTask, addr,
numOfBytes, dstPtr, &sizeRead);
if (err == noErr && sizeRead != numOfBytes)
err = -1;
return (err == noErr);
}
> Hi All,
> On the PC (Visual Studio), there is a call for
> testing valid memory
> AfxIsValidAddress( ) - "Tests any memory address to
> ensure that it is
> contained entirely within the program's memory
> space." This function
> also takes a read/write parameter. Is there a
> similar function on
> MacOSX/Xcode?
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/darwin-dev/email@hidden
This email sent to email@hidden