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

Rafael/additional ihv metadata #2043

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions generation/WinSDK/autoTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -1599,6 +1599,7 @@
"Name": "PROCESSTRACE_HANDLE",
"ValueType": "ulong",
"CloseApi": "CloseTrace",
"InvalidHandleValues": [ -1 ],
"NativeTypedef": false
},
{
Expand Down Expand Up @@ -2759,6 +2760,7 @@
"Name": "REGHANDLE",
"ValueType": "long",
"CloseApi": "EventUnregister",
"InvalidHandleValues": [ 0 ],
"NativeTypedef": true
},
{
Expand All @@ -2771,12 +2773,14 @@
"Name": "PDH_HLOG",
"ValueType": "DECLARE_HANDLE",
"CloseApi": "PdhCloseLog",
"InvalidHandleValues": [ -1, 0 ],
"NativeTypedef": true
},
{
"Name": "PDH_HQUERY",
"ValueType": "DECLARE_HANDLE",
"CloseApi": "PdhCloseQuery",
"InvalidHandleValues": [ -1, 0 ],
"NativeTypedef": true
},
{
Expand All @@ -2789,6 +2793,7 @@
"Name": "PRINTER_HANDLE",
"ValueType": "void*",
"CloseApi": "ClosePrinter",
"InvalidHandleValues": [ -1, 0 ],
"NativeTypedef": false
},
{
Expand Down
36 changes: 36 additions & 0 deletions tests/Windows.Win32.Tests/RaiiFreeAttributeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using ICSharpCode.Decompiler.TypeSystem;
using MetadataUtils;
using Xunit;

namespace Windows.Win32.Tests
{

public class RaiiFreeAttributeTests
{
[Fact]
public void AllRaiiTypesHaveInvalidHandleValueAttribute()
{
var typeSystem = DecompilerUtils.LoadDecompilerTypeSystem(TestCommon.TestUtils.Win32WinmdPath);
var excludedTypes = new HashSet<string>
{
"Windows.Win32.Foundation.BSTR", // Not a handle type
"Windows.Win32.System.WinRT.HSTRING", // Has no invalid handle value
"Windows.Win32.System.Threading.LPPROC_THREAD_ATTRIBUTE_LIST", // Not a handle type
};

var structsMissingMetadata = typeSystem.MainModule.TypeDefinitions
.Where(type => type.Kind == TypeKind.Struct)
.Where(type => type.GetAttributes().Any(attr => attr.AttributeType.Name == "RAIIFreeAttribute"))
.Where(type => !type.GetAttributes().Any(attr => attr.AttributeType.Name == "InvalidHandleValueAttribute"))
.Where(type => !excludedTypes.Contains(type.FullName))
.Select(type => type.FullName);

Assert.True(!structsMissingMetadata.Any(),
$"RAII structs missing InvalidHandleValue attribute:{Environment.NewLine}" +
string.Join(Environment.NewLine, structsMissingMetadata.Select(structName => $"- {structName}")));
}
}
}
4 changes: 4 additions & 0 deletions tests/Windows.Win32.Tests/Windows.Win32.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Remove="C:\Sources\win32metadata\images/windows.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ICSharpCode.Decompiler" Version="7.2.1.6856" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
Expand Down