This is a very interesting question, and I'm struck by the fact that nobody who really knows has responded yet. So, as I'm also not one of those, let me join the speculation:

Obviously, the first step is deciding whether simply *looking* at the byte of memory the pointer points to will cause a hardware exception. It must have an even address, and that address must be in memory that actually exists. The former is easy to check, the latter is probably possible, but I don't know how to find out what the range(s) of valid memory addresses on the device are. I believe there is no memory read protection on the 68000-based Palm devices, so it should be safe to actually look at the pointed-to memory once these two tests have passed. I believe the Palm OS heap format is documented somewhere, so it should be possible to examine memory at, before, and after the pointed-to byte and see if it appears to conform to the structure of a well-formed chunk. This can always give a false positive result (memory that accidentally resembles a valid chunk), so the real way to be sure is to trace through the Palm OS heaps and see if your pointer pops up as a member in good standing. This has potential performance implications...

Remember that, even if the 68000 hardware doesn't object to your looking at arbitrary memory, the Emulator will. Its warning messages can be suppressed by HostSetPreference(), q.v.

--Greg Lutz

At 12:52 PM 1/30/2003 -0500, Mauck, Robert wrote:

x-precedence:bulk

Bob,
Thanks for the response.
I am building a framework where an outside source (another coder) is passing
me a pointer. Right now, the only way I can check if the pointer is valid
is by calling MemPtrSize(). If the pointer is very weird (not a valid
chunk) the OS displays a fatal message and resets.

I would prefer to handle this error gracefully by returning an error code.
If there a way that MemPtrSize (or similar calls) can return as opposed to
display window then resetting?

In this case, I am not actually allocating the memory. I am just trying to
keep the users of the framework safe.

Thanks,
Rob mauck

-----Original Message-----
From: Robert McKenzie [mailto:[EMAIL PROTECTED]]


I would be very careful about relying on routines like PrvPtrCheck...

-----Original Message-----
From: Mauck, Robert


Hi,
I am trying to come up with a reliable invalid pointer check. I am assuming
that a valid pointer points to the beginning of a chunk (i.e. directly
allocated with MemPtrNew or MemHandleLock).

My first stab was to call MemPtrSize() on the pointer and compare the size
to what I expect. This works okay, except on really whacky pointers the
routine displays a Fatal error message and resets. I would like to
intercept the reset and handle the error myself.

I took a look at the OS4 source and there is a call PrvPtrCheck. That
routine returns a MemChunkHeaderPtr. I do not want the header but that
functionality without the error message is exactly what I am looking for.

Is there a call I can make to disable the error messages so that this call
will always return to me? Is there another technique I can use to verify
that my pointer is valid?

--
For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

Reply via email to