Jump to content
MartinKeane

getProcessAffinityMask failure handling in OTL

Recommended Posts

Posted (edited)

In OTL (3.0.7), OTLCommon.TOmniAffinity.GetMask calls DSiGetSystemAffinityMask, DSiGetProcessAffinityMask and DSiGetThreadAffinityMask which all call Winapi.windows.GetProcessAffinityMask, which can fail (I don't know under what conditions, but clients are reporting that it happens under Wine and also on at least one windows 10 system). If it fails, the var returns lpProcessAffinityMask and lpSystemAffinityMask are undefined. OTL release 1.40 made some changes to support 64 bit, and so I think in most places this behaviour won't show. However, for example OTLCommon.TOmniAffinity.GetCount has affMask := Mask; where affMask is a DWORD and mask is the NativeUInt property. An ERangeError won't be thrown unless:

  • 64 bit arch
  • range checking on
  • GetProcessAffinityMask throws
  • the second 64-bit param (lpProcessAffinityMask) value comes back as an invalid 32 bit value (I assume, under whatever conditions that trigger this issue, winapi doesn't change the stack val, so for example whatever was in that position happened to be an invalid 32 bit value)

 

So my suggestion is that anywhere getProcessAffinityMask is called (I think just 3 places), it is checked for failure and if so some reasonable value is returned, eg

if not GetProcessAffinityMask(GetCurrentProcess, Result, systemAffinityMask) then
    result := 1;

 

Edited by MartinKeane

Share this post


Link to post

Silent failure as you propose does not seem very useful to me. Surely better to use RaiseLastOSError in case an API call fails. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×