One other twist I forgot to mention, I am working on Palm OS5.

Well, I have tried several techniques to test the pointer.  I coded up a
routine that looks at the chunk and examines several flags.  Warning:  If
anyone does this the Endianess is wrong (from a 68k perspective).  You need
to byte swap several values to make this work.  

This works locally, but I do receive false positives on occasion (as
expected) saying that the memory is good when it actually is not.  My test
is to store a pointer to an allocated chunk in a database and then soft
reset.  Interestingly, I can MemPtrSize() on the pointer and it returns the
size.  However, I know the pointer is invalid.

The next step is now to walk the free chunk list and see if my memory is
contained within a free chunk.  There is a Trap/OS call that returns the
Heap header pointer for a given pointer.  However, it seems that the heap
header has changed slightly from OS4 to OS5.  

I am trying to reverse engineer the Heap header structure now.  Has anyone
else looked at this on OS5?

Thanks,
rob
 

-----Original Message-----
From: Aaron Ardiri [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, January 30, 2003 5:09 PM
To: Palm Developer Forum
Subject: Re: Reliable invalid pointer check


> 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 have built a framework which has plugin modules - (www.drcompanion.com)
so, i can provide some assistance/guidance here :)

solution #1:
------------

struct
{
  void   *ptr;
  UInt32 ptrSize;
} ptrData;

get the developer to pass you a pointer to that structure instead :) no need
to do anything fancy, all data is stored (hope he set it
right) :P

solution #2:
------------

you cannot call MemPtrSize() on any pointer. you need to determine if it is
actually a dynamic pointer (allocated using MemPtrNew) or a static pointer
(MemHandleLock()). there is a way to do this, i dont recall it off hand,
but, once you determine if it is a handle or dynamic chunk, you can use:

MemPtrSize(ptr);
MemHandleSize(MemPtrRecoverHandle(ptr));

/me checks API references.. bbiab :)

>> MemPtrDataStorage

> 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?

need to know if it is a pointer of handle :)

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

try solution #1 - its safe, and, since you are developing the framework, you
can define the interface :) it'll still be a pointer, but, in this case, a
pointer to a pointer with a little extra info (size) :P

hope this helps.

---
Aaron Ardiri                           [EMAIL PROTECTED]
CEO - CTO                                              +46 70 656 1143
Mobile Wizardry                         http://www.mobilewizardry.com/


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

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

Reply via email to