home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!mcsun!chsun!bernina!bernina!neeri
- From: neeri@iis.ethz.ch (Matthias Neeracher)
- Subject: Re: Verifying valid handles, how to?
- In-Reply-To: gwatts@fnalo.fnal.gov's message of Fri, 22 Jan 1993 07:55:20 GMT
- Message-ID: <NEERI.93Jan22190934@iis.ethz.ch>
- Sender: news@bernina.ethz.ch (USENET News System)
- Organization: Integrated Systems Laboratory, ETH, Zurich
- References: <1993Jan22.015520.1@fnalo.fnal.gov>
- Date: Fri, 22 Jan 1993 18:09:34 GMT
- Lines: 52
-
- In article <1993Jan22.015520.1@fnalo.fnal.gov>, gwatts@fnalo.fnal.gov writes:
- > At any rate, I was thinking. I've got only indirect objects in my project.
- > This means every object is a handle, right? Well, why not, in the debug
- > version of the message dispatcher (oopDebug library) put a little code that
- > will check the object is infact allocated as a handle?
- > I checked out the routine in msg.c (in the oops Libraries folder), and
- > the handle is stored in register a1. I don't know, however, how to check
- > if it is a valid handle without causing an error (bus or otherwise) of
- > somesort. Especially if it is a random number! Anyone know? Is there
- > some memory manager routine, given a suspected handle, will tell me this?
-
- Here you go. This code is not guaranteed to work 100% of the time, but I doubt
- you will get it to produce an address error for any normal memory setup (One
- exception I can think of are macs with a memory upgrade that makes the ROM
- appear in the middle of the application heap).
-
- /* Heuristic to determine whether a given address is a Handle */
- /* Based on the articles of Lloyd Lim and Matthew T Russotto in the UMPG */
- /* This code may be redistributed without any restrictions */
-
- Boolean RealHandle(void * addr)
- {
- THz sysZone;
- THz applZone;
- THz heapZone;
-
- addr = StripAddress(addr);
- if (addr && !((long) addr & 1)) {
- sysZone = SystemZone();
- applZone = ApplicZone();
- if (addr >= (Ptr) &sysZone->heapData &&
- addr < (Ptr) sysZone->bkLim ||
- addr >= (Ptr) &applZone->heapData &&
- addr < (Ptr) applZone->bkLim
- )
- if (*(long *)addr && !(*(long *)addr & 1)) {
- heapZone = HandleZone(addr);
- if (!MemError())
- if (heapZone == sysZone || heapZone == applZone)
- return true;
- }
- }
-
- return false;
- }
-
- Matthias
-
- -----
- Matthias Neeracher neeri@iis.ethz.ch
- `We say "gestalt" when things combine to act in ways we can't explain'
- -- Marvin Minsky, _The Society Of Mind_
-