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

Add RtlGetVersion(OSVERSIONINFOEX) overload #509

Merged
merged 2 commits into from
Jul 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CodeGeneration/OfferFriendlyOverloadsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public Task<SyntaxList<MemberDeclarationSyntax>> GenerateAsync(TransformationCon
.WithMembers(SyntaxFactory.List<MemberDeclarationSyntax>());
var methodsWithNativePointers =
from method in type.Members.OfType<MethodDeclarationSyntax>()
where !method.AttributeLists.SelectMany(al => al.Attributes).Any(att => att.Name is SimpleNameSyntax sn && sn.Identifier.ValueText == "NoFriendlyOverloads")
where WhereIsPointerParameter(method.ParameterList.Parameters).Any() || method.ReturnType is PointerTypeSyntax
select method;

Expand Down
17 changes: 17 additions & 0 deletions src/CodeGenerationAttributes/NoFriendlyOverloadsAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright © .NET Foundation and Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

namespace PInvoke
{
using System;
using System.Diagnostics;

/// <summary>
/// Decorated on a method to suppress automatic generation of friendly overloads.
/// </summary>
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
public sealed class NoFriendlyOverloadsAttribute : Attribute
{
}
}
16 changes: 12 additions & 4 deletions src/NTDll/NTDll.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,17 @@ namespace PInvoke
/// </content>
public static partial class NTDll
{
// This is where you define methods that assist in calling P/Invoke methods.
// For example, if a P/Invoke method requires allocating unmanaged memory
// and freeing it up after the call, a helper method in this file would
// make "P/Invoking" for most callers much easier and is a welcome addition.
/// <inheritdoc cref="RtlGetVersion(Kernel32.OSVERSIONINFO*)"/>
[NoFriendlyOverloads]
public static unsafe NTSTATUS RtlGetVersion(Kernel32.OSVERSIONINFOEX* versionInformation) => RtlGetVersion((Kernel32.OSVERSIONINFO*)versionInformation);

/// <inheritdoc cref="RtlGetVersion(ref Kernel32.OSVERSIONINFO)"/>
public static unsafe NTSTATUS RtlGetVersion(ref Kernel32.OSVERSIONINFOEX versionInformation)
{
fixed (Kernel32.OSVERSIONINFOEX* versionInformationLocal = &versionInformation)
{
return RtlGetVersion(versionInformationLocal);
}
}
}
}
2 changes: 1 addition & 1 deletion src/NTDll/NTDll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static unsafe extern NTSTATUS NtQueryInformationProcess(
/// The <see cref="RtlGetVersion(Kernel32.OSVERSIONINFO*)"/> routine returns version information about the currently running operating system.
/// </summary>
/// <param name="versionInformation">
/// A <see cref="Kernel32.OSVERSIONINFO"/> structure that contains the version information about the currently running operating system.
/// A pointer to an <see cref="Kernel32.OSVERSIONINFO"/> or <see cref="Kernel32.OSVERSIONINFOEX"/> structure that contains the version information about the currently running operating system.
/// </param>
/// <returns>
/// <see cref="RtlGetVersion(Kernel32.OSVERSIONINFO*)"/> returns <see cref="NTSTATUS.Code.STATUS_SUCCESS"/>.
Expand Down
8 changes: 5 additions & 3 deletions src/NTDll/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ PInvoke.NTDll.PROCESS_BASIC_INFORMATION.Reserved2a -> void*
PInvoke.NTDll.PROCESS_BASIC_INFORMATION.Reserved2b -> void*
PInvoke.NTDll.PROCESS_BASIC_INFORMATION.Reserved3 -> void*
PInvoke.NTDll.PROCESS_BASIC_INFORMATION.UniqueProcessId -> void*
static extern PInvoke.NTDll.NtQueryInformationProcess(PInvoke.Kernel32.SafeObjectHandle ProcessHandle, PInvoke.NTDll.PROCESSINFOCLASS ProcessInformationClass, void* ProcessInformation, int ProcessInformationLength, out int ReturnLength) -> PInvoke.NTSTATUS
static extern PInvoke.NTDll.RtlGetVersion(PInvoke.Kernel32.OSVERSIONINFO* versionInformation) -> PInvoke.NTSTATUS
static PInvoke.NTDll.NtQueryInformationProcess(PInvoke.Kernel32.SafeObjectHandle ProcessHandle, PInvoke.NTDll.PROCESSINFOCLASS ProcessInformationClass, System.IntPtr ProcessInformation, int ProcessInformationLength, out int ReturnLength) -> PInvoke.NTSTATUS
static PInvoke.NTDll.RtlGetVersion(ref PInvoke.Kernel32.OSVERSIONINFO versionInformation) -> PInvoke.NTSTATUS
static PInvoke.NTDll.RtlGetVersion(PInvoke.Kernel32.OSVERSIONINFOEX* versionInformation) -> PInvoke.NTSTATUS
static PInvoke.NTDll.RtlGetVersion(System.IntPtr versionInformation) -> PInvoke.NTSTATUS
static PInvoke.NTDll.RtlGetVersion(ref PInvoke.Kernel32.OSVERSIONINFO versionInformation) -> PInvoke.NTSTATUS
static PInvoke.NTDll.RtlGetVersion(ref PInvoke.Kernel32.OSVERSIONINFOEX versionInformation) -> PInvoke.NTSTATUS
static extern PInvoke.NTDll.NtQueryInformationProcess(PInvoke.Kernel32.SafeObjectHandle ProcessHandle, PInvoke.NTDll.PROCESSINFOCLASS ProcessInformationClass, void* ProcessInformation, int ProcessInformationLength, out int ReturnLength) -> PInvoke.NTSTATUS
static extern PInvoke.NTDll.RtlGetVersion(PInvoke.Kernel32.OSVERSIONINFO* versionInformation) -> PInvoke.NTSTATUS