Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Add NTDll.RtlGetVersion #498

Merged
merged 6 commits into from
Jul 12, 2020
Merged

Add NTDll.RtlGetVersion #498

merged 6 commits into from
Jul 12, 2020

Conversation

qmfrederik
Copy link
Contributor

No description provided.

@qmfrederik
Copy link
Contributor Author

Thanks, @vatsan-madhavan !

src/Kernel32/Kernel32+OSVERSIONINFO.cs Show resolved Hide resolved
src/NTDll/NTDll.cs Outdated Show resolved Hide resolved
{
var versionInfo = Kernel32.OSVERSIONINFO.Create();

Assert.Equal(NTSTATUS.Code.STATUS_SUCCESS, RtlGetVersion((Kernel32.OSVERSIONINFOEX*)&versionInfo).Value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether this is a case where helpers could come in handy. For e.g., in NtDll.Helpers.cs (see Kernel32.Helpers.cs for example), perhaps add a public overload RtlGetVersion(OSVERSIONINFO*) and "hide" this type of "reinterpret_cast" type casting in there (and let the users/callers of this API get a clean experience) ?

Another related thought - if you do add a helper, then would it make sense to use RtlGetVersion(OSVERSIONINFO) as the DllImport method, and RtlGetVersion(OSVERSIONINFOEX) as the helper? This would make the code for the helper itself a bit cleaner (the cast would read like (OSVERSIONINFO*)&osVersionInfoEx, which would guarantee that the pointer is within valid bounds and that this fact is statically verifiable) and would also follow the pattern in the OS itself (GetVersion and RtlGetVersion are defined in terms of LPOSVERSIONINFO, and when the dwOSVersionInfoSize indicates that the payload is actually an LPOSVERSIONINFOEX then additional fields are filled in and returned.)

Copy link
Collaborator

@AArnott AArnott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing!

src/Kernel32/Kernel32+OSVERSIONINFO.cs Show resolved Hide resolved
src/Kernel32/Kernel32+OSVERSIONINFO.cs Outdated Show resolved Hide resolved
src/Kernel32/Kernel32+OSVERSIONINFO.cs Outdated Show resolved Hide resolved
src/Kernel32/Kernel32+PLATFORM_ID.cs Outdated Show resolved Hide resolved
src/NTDll/NTDllExtensions.cs Outdated Show resolved Hide resolved
@qmfrederik
Copy link
Contributor Author

I think I addressed all comments for this PR, let me know if there's anything else you need from my side!

They required 32-bits to represent but were defined in a 16-bit enum.
Comment on lines 95 to 108
/// <summary>
/// AppServer mode is enabled.
/// </summary>
VER_SUITE_MULTIUSERTS = unchecked((short)0x00020000),

/// <summary>
/// Windows NT server is installed.
/// </summary>
VER_SERVER_NT = unchecked((short)0x80000000),

/// <summary>
/// Windows NT Workstation is installed.
/// </summary>
VER_WORKSTATION_NT = unchecked((short)0x40000000),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These enum values are all 0 because you're truncating the numbers you're providing to just 16 bits, and the last 16 bits are all zero. Clearly these could never be used in this enum which apparently is intentionally sized at 16 bits to fit the WORD size used in the methods that take this enum.
I've removed these new values.

@AArnott AArnott merged commit 9b2253f into dotnet:master Jul 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants