Dear fellow programming toilers,
is the following routine correct ?
I've tested it extensively, and it appears to work.
----- Cut
FUNCTION IsGoodReadPtr(CONST P: pointer): boolean;
{ -- Checks to see if P is readable.
-- Under DPMI, this means: can we obtain the value of P^ without causing a
-- GPF (Exception 0Dh) ?
-- In real mode, any pointer NIL is considered readable. }
{$IFDEF MSDOS}
BEGIN IsGoodReadPtr:=P NIL END;
{$ENDIF}
{$IFDEF DPMI}
ASSEMBLER;
ASM xor cl, cl { -- Function result := FALSE,
-- for the time being. }
{ -- First we test the selector part of P: }
mov bx, word ptr P+2 { -- Seg(P^) into BX. }
or bx, bx { -- BX = 0, i.e. was P of the form 0:ofs ? }
je @@EXIT { -- YES: not valid, so exit. }
{ -- The above two lines were added because older versions of VERR }
-- and LSL return nonsense when presented with a selector equal }
-- to zero. }
verr bx { -- Readable ? }
jnz @@EXIT { -- NO : exit, return FALSE. }
{ -- YES: on to the next test. }
{ -- Now the offset part of P comes under scrutiny:
-- is offset <= the selector's limit ? }
{ -- BX still holds the selector. }
lsl ax, bx { -- AX := limit. }
cmp ax, word ptr P { -- Limit >= Ofs(P^) ? }
jb @@EXIT { -- NO : P is invalid - exit. }
inc cl { -- YES: return TRUE. }
@@EXIT:
mov al, cl { -- Function result into AL. }
END;
{$ENDIF}
----- Cut
Some required information for those not familiar with Borland Pascal:
- Anything between "{" and the next "}" is a comment.
- Pointers are 32 bit animals, 16 bit offset, 16 bit segment, stored in
offset-segment order.
- Boolean function results are expected to be in AL.
- in C speak, "" == "!=", NIL == NULL, and "P^" == "*P".
According to the literature, LSL may fail. Can it also fail when VERR has
already given the selector a clean bill of health ?
Should the above routine be correct:
is a there a better/faster way (perhaps using DPMI functions 0202h and 0203h)
?
Should it not:
kindly show me the error of my ways.
On a related note: has anyone experienced problems with VERR and/or LSL ?
According to the Interrupt List, both instructions contain some truly bizarre
bugs.
Peter
... Alternate Subspace Molecular Inversion Refresh Layer:
... Valid settings are: Enabled and Disabled
--- EBO-BBS Diemen - NL
---------------
* Origin: EBO-BBS Diemen (http://www.worldonline.nl/~biginski) (2:280/901)
|