Re: Fastcode CompareMem B&V 1.1
- From: "Aleksandr Sharahov" <alsha-on-mail333.com>
- Date: Sat, 30 Apr 2005 16:30:28 +0400
Hi Dennis,
Here is validation function you ask.
--
regards
Aleksandr
function Validate0: boolean;
const
ValidateNo : Cardinal = 0; //Change me!
const
delta= 31;
function InternalValidate(q1, q2: pchar; len: integer): boolean;
var
ofs1, ofs2, maxlen, i: integer;
adr1, adr2: pchar;
label
BreakInternalValidation;
begin;
Result:=false;
adr1:=nil;
adr2:=nil;
try
maxlen:=len+delta;
while len<=maxlen do begin; //Test all sizes in [len..len+delta]
for ofs1:=0 to delta do begin; //Test all addresses in
[q1..q1+delta]
adr1:=q1+ofs1;
i:=len;
while i>0 do begin; //Fill buffer q1
dec(i); adr1[i]:=chr(i);
end;
for ofs2:=0 to delta do begin; //Test all addresses in
[q2..q2+delta]
adr2:=q2+ofs2;
i:=len;
while i>0 do begin; //Fill buffer q2
dec(i); adr2[i]:=chr(i);
end;
Result:=CompareMemFunction(adr1, adr2, len);
if not Result then goto BreakInternalValidation;
end;
end;
inc(len);
end;
BreakInternalValidation:
except
Result:=false;
end;
if not Result then ErrorTrap(ValidateNo, adr1, adr2, len);
end;
const
page= 4*1024;
function InternalTrigger(var p: pchar; var flags: dword): pchar;
var
oldflags: dword;
firstcall: boolean;
begin;
firstcall:=(flags and PAGE_NOACCESS)<>0;
if firstcall then GetMem(p,4*page);
//Protect/unprotect the 1st page
Result:=pchar(integer(p) and -page) + 1*page;
VirtualProtect(Result,1,flags,@oldflags);
//Protect/unprotect the 3th page
Result:=pchar(integer(p) and -page) + 3*page;
VirtualProtect(Result,1,flags,@flags);
//Return address of 2nd (unprotected) page
Result:=pchar(integer(p) and -page) + 2*page;
if not firstcall then FreeMem(p);
end;
const
lengths: array[0..3] of integer = (0, 32, 64, 256);
var
p1, p2, q1, q2: pchar;
f1, f2: dword;
i, len, ofs: integer;
begin;
//Get two unprotected pages with protected borders
f1:=PAGE_NOACCESS; q1:=InternalTrigger(p1, f1);
f2:=PAGE_NOACCESS; q2:=InternalTrigger(p2, f2);
//Test various lengths and offsets
Result:=true;
for i:=Low(lengths) to High(lengths) do begin;
len:=lengths[i];
ofs:=page-2*delta-len;
if ofs>=0 then begin;
if not InternalValidate(q1, q2, len)
or not InternalValidate(q1, q2+ofs, len)
or not InternalValidate(q1+ofs, q2, len)
or not InternalValidate(q1+ofs, q2+ofs, len)
then begin;
Result:=false;
break;
end;
end;
end;
//Free memory
InternalTrigger(p1, f1);
InternalTrigger(p2, f2);
end;
.
- Follow-Ups:
- Re: Fastcode CompareMem B&V 1.1
- From: Aleksandr Sharahov
- Re: Fastcode CompareMem B&V 1.1
- References:
- Fastcode CompareMem B&V 1.1
- From: Dennis
- Fastcode CompareMem B&V 1.1
- Prev by Date: Re: Fastcode MM Rule
- Next by Date: String Functions
- Previous by thread: Fastcode CompareMem B&V 1.1
- Next by thread: Re: Fastcode CompareMem B&V 1.1
- Index(es):
Relevant Pages
|