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

PSAPI_VERSION support #1789

Open
ldm0 opened this issue Jan 2, 2024 · 6 comments
Open

PSAPI_VERSION support #1789

ldm0 opened this issue Jan 2, 2024 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@ldm0
Copy link

ldm0 commented Jan 2, 2024

Suggestion

For win32 api like GetModuleInformation, GetPerformanceInfo, there is a PSAPI_VERSION flag to conveniently redirecting them to Kernel32.dll. But there is no such equivalent in windows crate, which makes it hard for downstream users to remove Psapi.dll's usage without forking every dependency. Normally crates won't call kernel32 apis directly(e.g. K32GetModuleInformation) for old Windows Version support(or the authors are not aware of that). It would be awesome to have a feature flag or cfg for kernel32 api redirection just like what PSAPI_VERSION does.

@ldm0 ldm0 added the enhancement New feature or request label Jan 2, 2024
@kennykerr
Copy link
Contributor

kennykerr commented Jan 2, 2024

I believe this was to support versions of Windows older than Windows 7, so these could safely be replaced with the kernel32 versions in metadata. Will transfer for consideration.

@kennykerr kennykerr transferred this issue from microsoft/windows-rs Jan 2, 2024
@riverar
Copy link
Collaborator

riverar commented Jan 2, 2024

Do we need to do anything here? windows and win32metadata contain both variants.

[DllImport("KERNEL32.dll", ExactSpelling = true, PreserveSig = false)]
[Documentation("https://learn.microsoft.com/windows/win32/api/psapi/nf-psapi-getmoduleinformation")]
public unsafe static extern BOOL K32GetModuleInformation([In] HANDLE hProcess, [In] HMODULE hModule, [Out] MODULEINFO* lpmodinfo, [In] uint cb);


[DllImport("PSAPI.dll", ExactSpelling = true, PreserveSig = false, SetLastError = true)]
[SupportedOSPlatform("windows5.1.2600")]
[Documentation("https://learn.microsoft.com/windows/win32/api/psapi/nf-psapi-getmoduleinformation")]
public unsafe static extern BOOL GetModuleInformation([In] HANDLE hProcess, [In] HMODULE hModule, [Out] MODULEINFO* lpmodinfo, [In] uint cb);

https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/ProcessStatus/fn.K32GetModuleInformation.html
https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/System/ProcessStatus/fn.GetModuleInformation.html

@kennykerr
Copy link
Contributor

I don't have a strong opinion. One option would be to update the metadata for GetModuleInformation to point to kernel32 and use the K32GetModuleInformation entry point.

@ldm0
Copy link
Author

ldm0 commented Jan 3, 2024

One option would be to update the metadata for GetModuleInformation to point to kernel32 and use the K32GetModuleInformation entry point.

Worth noting that this change would make apps rely on win32metadata unusable on Windows XP & WIndows Vista. Since K32GetModuleInformation couldn't be found in kernel32.dll on such platofrms.

Providing a features flag for such direction might be better in terms of compatibility.

@ldm0
Copy link
Author

ldm0 commented Jan 3, 2024

BTW, it's vague that whether win32metadata supports WIndows XP / Windows Vista / Windows Server 2003. I tried but couldn't find a list of supported OSes. :-(

@mikebattista
Copy link
Contributor

We exposed both variants in #920. A feature flag in the projection seems reasonable. Do you have everything you need in the metadata to do that?

@mikebattista mikebattista self-assigned this Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants