X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/2dd575b95694c126013c912526093ff4915f3398..7839389a75b803b3f9e3c88a8f269c178497cdb2:/lcorernd.pas?ds=sidebyside diff --git a/lcorernd.pas b/lcorernd.pas index 643de3a..3a8ea0c 100644 --- a/lcorernd.pas +++ b/lcorernd.pas @@ -111,7 +111,7 @@ function randominteger(i:longint):longint; function randombits(b:integer):longint; {generate a version 4 random uuid} -function generate_uuid:string; +function generate_uuid:ansistring; {$ifndef nolcorernd} @@ -130,14 +130,39 @@ var implementation +{$include pgtypes.inc} + {$ifndef nolcorernd} uses - {$ifdef win32}windows,activex,{$endif} - {$ifdef unix}baseunix,unix,unixutil,{$endif} + {$ifdef mswindows}windows,activex,{$endif} + {$ifdef unix} + {$ifdef ver1_0} + linux, + {$else} + baseunix,unix,unixutil,sockets, + {$endif} + {$endif} fastmd5,sysutils; {$ifdef unix}{$include unixstuff.inc}{$endif} +procedure rdtsc(buf: pointer); +asm + {$ifdef cpux86} + mov ecx, buf + db $0f; db $31 {rdtsc} + mov [ecx], edx + mov [ecx+4], eax + {$endif} + + {$ifdef cpux64} + mov rcx, buf + rdtsc + mov [rcx], edx + mov [rcx+4], eax + {$endif} +end; + type {hashtype must be array of bytes} hashtype=tmd5; @@ -159,7 +184,7 @@ var pool:array[0..(pooldwords+seeddwords-1)] of wordtype; reseedcountdown:integer; -{$ifdef win32} +{$ifdef mswindows} function collect_seeding(var output;const bufsize:integer):integer; var l:packed record @@ -172,7 +197,6 @@ var cursor:tpoint; hs:theapstatus; end absolute output; - rdtsc_0,rdtsc_1:integer; begin result := 0; if (bufsize < sizeof(l)) then exit; @@ -188,15 +212,8 @@ begin queryperformancecounter(tlargeinteger(l.qpcbuf)); {RDTSC} - {$ifdef cpu386} - asm - db $0F; db $31 - mov rdtsc_0,eax - mov rdtsc_1,edx - end; - l.rdtscbuf[0] := rdtsc_0; - l.rdtscbuf[1] := rdtsc_1; - {$endif} + rdtsc(@l.rdtscbuf); + {GETSYSTEMTIME} getsystemtime(tsystemtime(l.systemtimebuf)); @@ -247,7 +264,6 @@ var tv:ttimeval; pid:integer; end absolute output; - rdtsc_0,rdtsc_1:integer; begin result := 0; @@ -274,15 +290,7 @@ begin move(wtmpcached,l.devrnd,sizeof(l.devrnd)); end; {get more randomness in case there's no /dev/random} - {$ifdef cpu386}{$ASMMODE intel} - asm - db $0F; db $31 - mov rdtsc_0,eax - mov rdtsc_1,edx - end; - l.rdtscbuf[0] := rdtsc_0; - l.rdtscbuf[1] := rdtsc_1; - {$endif} + rdtsc(@l.rdtscbuf); gettimeofday(l.tv); l.pid := getpid; @@ -396,12 +404,12 @@ begin end; const - ch:array[0..15] of char='0123456789abcdef'; + ch:array[0..15] of ansichar='0123456789abcdef'; -function generate_uuid:string; +function generate_uuid:ansistring; var buf:array[0..7] of word; -function inttohex(w:word):string; +function inttohex(w:word):ansistring; begin result := ch[w shr 12] + ch[(w shr 8) and $f] + ch[(w shr 4) and $f] + ch[w and $f]; end;