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

Commit ac67e48

Browse files
authored
Merge pull request #509 from dotnet/noFriendlyOverloadsAttribute
Add RtlGetVersion(OSVERSIONINFOEX) overload
2 parents 67506c8 + fdc5f72 commit ac67e48

File tree

5 files changed

+36
-8
lines changed

5 files changed

+36
-8
lines changed

src/CodeGeneration/OfferFriendlyOverloadsGenerator.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public Task<SyntaxList<MemberDeclarationSyntax>> GenerateAsync(TransformationCon
7171
.WithMembers(SyntaxFactory.List<MemberDeclarationSyntax>());
7272
var methodsWithNativePointers =
7373
from method in type.Members.OfType<MethodDeclarationSyntax>()
74+
where !method.AttributeLists.SelectMany(al => al.Attributes).Any(att => att.Name is SimpleNameSyntax sn && sn.Identifier.ValueText == "NoFriendlyOverloads")
7475
where WhereIsPointerParameter(method.ParameterList.Parameters).Any() || method.ReturnType is PointerTypeSyntax
7576
select method;
7677

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright © .NET Foundation and Contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace PInvoke
5+
{
6+
using System;
7+
using System.Diagnostics;
8+
9+
/// <summary>
10+
/// Decorated on a method to suppress automatic generation of friendly overloads.
11+
/// </summary>
12+
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
13+
[Conditional("CodeGeneration")]
14+
public sealed class NoFriendlyOverloadsAttribute : Attribute
15+
{
16+
}
17+
}

src/NTDll/NTDll.Helpers.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@ namespace PInvoke
99
/// </content>
1010
public static partial class NTDll
1111
{
12-
// This is where you define methods that assist in calling P/Invoke methods.
13-
// For example, if a P/Invoke method requires allocating unmanaged memory
14-
// and freeing it up after the call, a helper method in this file would
15-
// make "P/Invoking" for most callers much easier and is a welcome addition.
12+
/// <inheritdoc cref="RtlGetVersion(Kernel32.OSVERSIONINFO*)"/>
13+
[NoFriendlyOverloads]
14+
public static unsafe NTSTATUS RtlGetVersion(Kernel32.OSVERSIONINFOEX* versionInformation) => RtlGetVersion((Kernel32.OSVERSIONINFO*)versionInformation);
15+
16+
/// <inheritdoc cref="RtlGetVersion(ref Kernel32.OSVERSIONINFO)"/>
17+
public static unsafe NTSTATUS RtlGetVersion(ref Kernel32.OSVERSIONINFOEX versionInformation)
18+
{
19+
fixed (Kernel32.OSVERSIONINFOEX* versionInformationLocal = &versionInformation)
20+
{
21+
return RtlGetVersion(versionInformationLocal);
22+
}
23+
}
1624
}
1725
}

src/NTDll/NTDll.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public static unsafe extern NTSTATUS NtQueryInformationProcess(
107107
/// The <see cref="RtlGetVersion(Kernel32.OSVERSIONINFO*)"/> routine returns version information about the currently running operating system.
108108
/// </summary>
109109
/// <param name="versionInformation">
110-
/// A <see cref="Kernel32.OSVERSIONINFO"/> structure that contains the version information about the currently running operating system.
110+
/// 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.
111111
/// </param>
112112
/// <returns>
113113
/// <see cref="RtlGetVersion(Kernel32.OSVERSIONINFO*)"/> returns <see cref="NTSTATUS.Code.STATUS_SUCCESS"/>.

src/NTDll/PublicAPI.Unshipped.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ PInvoke.NTDll.PROCESS_BASIC_INFORMATION.Reserved2a -> void*
1313
PInvoke.NTDll.PROCESS_BASIC_INFORMATION.Reserved2b -> void*
1414
PInvoke.NTDll.PROCESS_BASIC_INFORMATION.Reserved3 -> void*
1515
PInvoke.NTDll.PROCESS_BASIC_INFORMATION.UniqueProcessId -> void*
16-
static extern PInvoke.NTDll.NtQueryInformationProcess(PInvoke.Kernel32.SafeObjectHandle ProcessHandle, PInvoke.NTDll.PROCESSINFOCLASS ProcessInformationClass, void* ProcessInformation, int ProcessInformationLength, out int ReturnLength) -> PInvoke.NTSTATUS
17-
static extern PInvoke.NTDll.RtlGetVersion(PInvoke.Kernel32.OSVERSIONINFO* versionInformation) -> PInvoke.NTSTATUS
1816
static PInvoke.NTDll.NtQueryInformationProcess(PInvoke.Kernel32.SafeObjectHandle ProcessHandle, PInvoke.NTDll.PROCESSINFOCLASS ProcessInformationClass, System.IntPtr ProcessInformation, int ProcessInformationLength, out int ReturnLength) -> PInvoke.NTSTATUS
19-
static PInvoke.NTDll.RtlGetVersion(ref PInvoke.Kernel32.OSVERSIONINFO versionInformation) -> PInvoke.NTSTATUS
17+
static PInvoke.NTDll.RtlGetVersion(PInvoke.Kernel32.OSVERSIONINFOEX* versionInformation) -> PInvoke.NTSTATUS
2018
static PInvoke.NTDll.RtlGetVersion(System.IntPtr versionInformation) -> PInvoke.NTSTATUS
19+
static PInvoke.NTDll.RtlGetVersion(ref PInvoke.Kernel32.OSVERSIONINFO versionInformation) -> PInvoke.NTSTATUS
20+
static PInvoke.NTDll.RtlGetVersion(ref PInvoke.Kernel32.OSVERSIONINFOEX versionInformation) -> PInvoke.NTSTATUS
21+
static extern PInvoke.NTDll.NtQueryInformationProcess(PInvoke.Kernel32.SafeObjectHandle ProcessHandle, PInvoke.NTDll.PROCESSINFOCLASS ProcessInformationClass, void* ProcessInformation, int ProcessInformationLength, out int ReturnLength) -> PInvoke.NTSTATUS
22+
static extern PInvoke.NTDll.RtlGetVersion(PInvoke.Kernel32.OSVERSIONINFO* versionInformation) -> PInvoke.NTSTATUS

0 commit comments

Comments
 (0)