Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions HashLib/src/Utils/HlpArmHwCapProvider.pas
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ TArmHwCapProvider = class sealed
strict private
class var
FGetAuxVal: TGetAuxValFunc;
FResolved: Boolean;

strict private
class procedure ResolveOnce(); static;
private
class procedure ResolveDynamicImports(); static;

public
class function GetHwCap(): UInt64; static;
Expand All @@ -110,10 +109,9 @@ TArmHwCapProvider = class sealed
strict private
class var
FElfAuxInfo: TElfAuxInfoFunc;
FResolved: Boolean;

strict private
class procedure ResolveOnce(); static;
private
class procedure ResolveDynamicImports(); static;

public
class function GetHwCap(): UInt64; static;
Expand All @@ -139,15 +137,11 @@ implementation

{$IF DEFINED(HASHLIB_LINUX) OR DEFINED(HASHLIB_ANDROID)}

class procedure TArmHwCapProvider.ResolveOnce();
class procedure TArmHwCapProvider.ResolveDynamicImports();
var
LHandle: Pointer;
begin
if FResolved then
Exit;

FGetAuxVal := nil;
FResolved := True;

LHandle := dlopen(nil, RTLD_NOW);
if LHandle = nil then
Expand All @@ -163,7 +157,6 @@ class procedure TArmHwCapProvider.ResolveOnce();

class function TArmHwCapProvider.GetHwCap(): UInt64;
begin
ResolveOnce();
if System.Assigned(FGetAuxVal) then
Result := FGetAuxVal(AT_HWCAP)
else
Expand All @@ -172,7 +165,6 @@ class function TArmHwCapProvider.GetHwCap(): UInt64;

class function TArmHwCapProvider.GetHwCap2(): UInt64;
begin
ResolveOnce();
if System.Assigned(FGetAuxVal) then
Result := FGetAuxVal(AT_HWCAP2)
else
Expand All @@ -185,15 +177,11 @@ class function TArmHwCapProvider.GetHwCap2(): UInt64;

{$IF DEFINED(HASHLIB_BSD)}

class procedure TArmHwCapProvider.ResolveOnce();
class procedure TArmHwCapProvider.ResolveDynamicImports();
var
LHandle: Pointer;
begin
if FResolved then
Exit;

FElfAuxInfo := nil;
FResolved := True;

LHandle := dlopen(nil, RTLD_NOW);
if LHandle = nil then
Expand All @@ -216,7 +204,6 @@ class function TArmHwCapProvider.GetHwCap(): UInt64;
var
LValue: UInt64;
begin
ResolveOnce();
if System.Assigned(FElfAuxInfo) then
begin
LValue := 0;
Expand All @@ -233,7 +220,6 @@ class function TArmHwCapProvider.GetHwCap2(): UInt64;
var
LValue: UInt64;
begin
ResolveOnce();
if System.Assigned(FElfAuxInfo) then
begin
LValue := 0;
Expand All @@ -259,6 +245,11 @@ class function TArmHwCapProvider.HasProcessorFeature(AFeature: UInt32): Boolean;

{$IFEND} // HASHLIB_MSWINDOWS

{$IF DEFINED(HASHLIB_LINUX) OR DEFINED(HASHLIB_ANDROID) OR DEFINED(HASHLIB_BSD)}
initialization
TArmHwCapProvider.ResolveDynamicImports;
{$IFEND}

{$IFEND} // HASHLIB_ARM

end.
16 changes: 6 additions & 10 deletions HashLib/src/Utils/HlpDarwinSysCtl.pas
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ TDarwinSysCtl = class sealed
strict private
class var
FSysCtlByName: TSysCtlByNameFunc;
FResolved: Boolean;

strict private
class procedure ResolveOnce(); static;
private
class procedure ResolveDynamicImports(); static;

/// <summary>
/// Queries a single sysctl key. Returns True if the key exists and
Expand Down Expand Up @@ -63,15 +62,11 @@ implementation

{ TDarwinSysCtl }

class procedure TDarwinSysCtl.ResolveOnce();
class procedure TDarwinSysCtl.ResolveDynamicImports();
var
LHandle: Pointer;
begin
if FResolved then
Exit;

FSysCtlByName := nil;
FResolved := True;

LHandle := dlopen(nil, RTLD_NOW);
if LHandle = nil then
Expand Down Expand Up @@ -107,8 +102,6 @@ class function TDarwinSysCtl.QueryKey(const AName: PAnsiChar): Boolean;
class function TDarwinSysCtl.HasFeature(const AModernName: PAnsiChar;
const ALegacyName: PAnsiChar): Boolean;
begin
ResolveOnce();

if not System.Assigned(FSysCtlByName) then
begin
Result := False;
Expand All @@ -123,6 +116,9 @@ class function TDarwinSysCtl.HasFeature(const AModernName: PAnsiChar;
Result := QueryKey(ALegacyName);
end;

initialization
TDarwinSysCtl.ResolveDynamicImports;

{$IFEND} // HASHLIB_MACOS OR HASHLIB_IOS
{$IFEND} // HASHLIB_ARM

Expand Down
Loading