Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinXP Compatibility for PdhUtil#PdhLookupPerfNameByIndex #1052

Merged
merged 1 commit into from
Jan 8, 2019

Conversation

dbwiddis
Copy link
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
Member

Thank you - looks sane.

@matthiasblaesing matthiasblaesing merged commit 076ae4b into java-native-access:master Jan 8, 2019
@dbwiddis
Copy link
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