home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.mac.programmer
- Path: sparky!uunet!munnari.oz.au!uniwa!cujo!ncrpda.curtin.edu.au!rocky.curtin.edu.au!user
- From: peter@cujo.curtin.edu.au (Peter N Lewis)
- Subject: Re: Verifying valid handles, how to?
- Message-ID: <peter-230193180216@rocky.curtin.edu.au>
- Followup-To: comp.sys.mac.programmer
- Lines: 44
- Sender: news@ncrpda.curtin.edu.au
- Nntp-Posting-Host: ncrpda.curtin.edu.au
- Organization: NCRPDA, Curtin University
- References: <1993Jan22.015520.1@fnalo.fnal.gov>
- Date: Sat, 23 Jan 1993 10:01:36 GMT
-
- In article <1993Jan22.015520.1@fnalo.fnal.gov>, gwatts@fnalo.fnal.gov
- wrote:
-
- > 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
-
- here's a random attempt at it. First check that the handle is even. Then
- check that it points to an area inside your heap or inside the system heap,
- then check that h^ is inside the heap as well, and finally that recover
- handle gives the right value.
-
- function InsideHeap (p: univ ptr; hz: THz): boolean;
- begin
- InsideHeap := (longInt(p) >= longInt(hz)) & (longInt(p) <
- longInt(hz^.bkLim));
- end;
-
- function ValidHandle (h: univ handle): boolean;
- var
- valid: boolean;
- begin
- valid := false;
- if BAND(h, 1) = 0 then begin
- if InsideHeap(h, ApplicZone) then begin
- valid := (BAND(h^, 1) = 0) & InsideHeap(h^, ApplicZone);
- end
- else if InsideHeap(h, SystemZone) then begin
- valid := (BAND(h^, 1) = 0) & InsideHeap(h^, SystemZone);
- end;
- end;
- if valid then begin
- valid := RecoverHandle(h^) = h;
- end;
- ValidHandle := valid;
- end;
-
- (Code tried and tested, but by no means guarenteed)
-
- That would seem to be a good start...
- Peter.
-
- _______________________________________________________________________
- Peter N Lewis <peter@cujo.curtin.edu.au> Ph: +61 9 368 2055
-