Skip to content

WinXP Compatibility for PdhUtil#PdhLookupPerfNameByIndex#1052

Merged
matthiasblaesing merged 1 commit intojava-native-access:masterfrom
dbwiddis:pdhutil-xp
Jan 8, 2019
Merged

WinXP Compatibility for PdhUtil#PdhLookupPerfNameByIndex#1052
matthiasblaesing merged 1 commit intojava-native-access:masterfrom
dbwiddis:pdhutil-xp

Conversation

@dbwiddis
Copy link
Copy Markdown
Contributor

@dbwiddis dbwiddis commented Jan 8, 2019

See discussion on JNA mailing list. WinXP requires non-null buffer and non-zero size for PdhLookupPerfNameByIndex. But we can't always set a too-small buffer for Vista+ as the returned size is not reliable without the null.

This method should bypass the error conditional (more quickly over time with branch prediction) on modern OS's but provide XP compatibility with a third call if required.

Other ways to address this:

  • Do a version check for Vista+ (see Add Windows Version Helper functions #1050) and save that boolean result, and use that for the conditional
  • Always set a big-enough buffer (PDH_MAX_COUNTER_NAME(1024) * Native.WCHAR_SIZE) on the first call.

@matthiasblaesing
Copy link
Copy Markdown
Member

Thank you - looks sane.

@matthiasblaesing matthiasblaesing merged commit 076ae4b into java-native-access:master Jan 8, 2019
@dbwiddis
Copy link
Copy Markdown
Contributor Author

dbwiddis commented Jan 8, 2019

Ugh, missed asking you to hold on this by a few hours. Doing more testing, discovered it doesn't quite fix the problem: the XP call that returns insufficient buffer isn't guaranteed to provide the new size... the docs give an either/or.

The function sets pcchNameBufferSize to either the required size or the size of the buffer that was used.

I need to wrap the XP fallback attempt in a loop that increases the buffer size until success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants