Path: utzoo!attcan!uunet!aplcen!samsung!shadooby!mailrus!purdue!bu-cs!dartvax!eleazar.dartmouth.edu!ari From: ari@eleazar.dartmouth.edu (Ari Halberstadt) Newsgroups: comp.sys.mac.programmer Subject: Re: Why link with '-ad 4' ? Message-ID: <17662@dartvax.Dartmouth.EDU> Date: 4 Dec 89 03:37:26 GMT References: <9162@hoptoad.uucp> Sender: news@dartvax.Dartmouth.EDU Reply-To: ari@eleazar.dartmouth.edu (Ari Halberstadt) Organization: Dartmouth College, Hanover, NH Lines: 35 Here's a question for you folks out on NetLand. I'm trying to figure out, with a reasonable degree of success, if the refCon field of a window contains a valid handle. This must be determined by a driver, which is separate from the the program which actually created the window. The tests currently performed are: Boolean ValidHandle(Handle hndl) { hndl = (Handle) GetWRefCon(window); /* copied here for brevity */ if (! hndl) return(false); if ((long) hndl & 1L) /* check for odd address */ return(false); if (GetHandleSize(hndl) != expected_size) return(false); } Actually, I've got three questions. 1. Is it ok to check for odd adresses on a 680x0? I assume Apple wouldn't write NewHandle to create something on an odd adress, since access times are slower. 2. I would like to check that the handle is within a reasonable area of memory, i.e., within the application heap. However, since the application may have several heap zones, what is the correct way to check this? Is it sufficient to use ApplicZone and GetApplLimit? 3. Any more ideas for useful checks? I've already got a special long int stuck at the head of the place where the correct handle would point to, and I've thought of making sure the handle is below RomBase. -- Ari Halberstadt '91, "Long live succinct signatures" ari@eleazar.dartmouth.edu Disclaimer: "Live Free or Die"