Fixes #609 - Add thread attribute constants from processthreadsapi.h
This commit is contained in:
Родитель
3033ee4e93
Коммит
f2c101e0be
|
@ -1,5 +1,3 @@
|
|||
--file
|
||||
<PartitionDir>\main.cpp
|
||||
--output
|
||||
<GeneratedSourceDir>\<PartitionName>.cs
|
||||
--include-directory
|
||||
|
|
|
@ -7,3 +7,33 @@
|
|||
|
||||
#include <winnt.h>
|
||||
#include <avrt.h>
|
||||
|
||||
#define MakeProcThreadAttributeConst(value) \
|
||||
const DWORD __forceconst__##value = value;
|
||||
|
||||
#undef ProcThreadAttributeValue
|
||||
#define ProcThreadAttributeValue(Number, Thread, Input, Additive) \
|
||||
(((DWORD)(Number) & PROC_THREAD_ATTRIBUTE_NUMBER) | \
|
||||
((Thread != FALSE) ? PROC_THREAD_ATTRIBUTE_THREAD : 0) | \
|
||||
((Input != FALSE) ? PROC_THREAD_ATTRIBUTE_INPUT : 0) | \
|
||||
((Additive != FALSE) ? PROC_THREAD_ATTRIBUTE_ADDITIVE : 0))
|
||||
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_PARENT_PROCESS)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_HANDLE_LIST)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_GROUP_AFFINITY)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_PREFERRED_NODE)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_IDEAL_PROCESSOR)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_UMS_THREAD)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_MITIGATION_POLICY)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_SECURITY_CAPABILITIES)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_PROTECTION_LEVEL)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_MACHINE_TYPE)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_ENABLE_OPTIONAL_XSTATE_FEATURES)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_WIN32K_FILTER)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_JOB_LIST)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_CHILD_PROCESS_POLICY)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_ALL_APPLICATION_PACKAGES_POLICY)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_DESKTOP_APP_POLICY)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_MITIGATION_AUDIT_POLICY)
|
||||
MakeProcThreadAttributeConst(PROC_THREAD_ATTRIBUTE_COMPONENT_FILTER)
|
||||
|
|
|
@ -22,5 +22,6 @@ SignalObjectAndWait
|
|||
<IncludeRoot>/um/threadpoolapiset.h
|
||||
<IncludeRoot>/um/threadpoollegacyapiset.h
|
||||
<IncludeRoot>/um/wow64apiset.h
|
||||
<PartitionDir>/main.cpp
|
||||
--namespace
|
||||
Windows.Win32.System.Threading
|
||||
|
|
|
@ -43,6 +43,5 @@ ID2D1Factory
|
|||
<IncludeRoot>/winrt/winstring.h
|
||||
<IncludeRoot>/um/sharewindowcommandsourceinterop.h
|
||||
<IncludeRoot>/um/IMessageDispatcher.h
|
||||
<PartitionDir>\main.cpp
|
||||
--namespace
|
||||
Windows.Win32.System.WinRT
|
||||
|
|
|
@ -242,6 +242,7 @@ LPTHREAD_START_ROUTINE=Windows.Win32.System.Threading
|
|||
OUTPUT_DEBUG_STRING_INFO=Windows.Win32.System.Diagnostics.Debug
|
||||
OVERLAPPED_ENTRY=Windows.Win32.System.IO
|
||||
OVERLAPPED=Windows.Win32.System.IO
|
||||
PROC_THREAD_ATTRIBUTE_NUM=Windows.Win32.System.Threading
|
||||
READ_DIRECTORY_NOTIFY_INFORMATION_CLASS=Windows.Win32.Storage.FileSystem
|
||||
RIP_INFO=Windows.Win32.System.Diagnostics.Debug
|
||||
SECURITY_ATTRIBUTES=Windows.Win32.Security
|
||||
|
|
|
@ -32,6 +32,7 @@ CF_HYDRATION_POLICY_MODIFIER=ushort
|
|||
CF_HYDRATION_POLICY_PRIMARY=ushort
|
||||
CF_POPULATION_POLICY_MODIFIER=ushort
|
||||
CF_POPULATION_POLICY_PRIMARY=ushort
|
||||
PROC_THREAD_ATTRIBUTE_NUM=uint
|
||||
--exclude
|
||||
_TREEITEM
|
||||
_IMAGELIST
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:321e49aea41fcd7d01fbd66a6107b247e62e890f1e65b80978b808db5e8ce8a2
|
||||
size 15610880
|
||||
oid sha256:2daf7a4bd5fa86bf055ee8b795e36a25a6c86821d540768c5e0959ceb601e372
|
||||
size 15611904
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace ClangSharpSourceToWinmd
|
|||
|
||||
private const string InteropNamespace = "Windows.Win32.Interop";
|
||||
private const string ScannedSuffix = "__scanned__";
|
||||
private const string RemovePrefix = "__remove__";
|
||||
|
||||
private const string SystemAssemblyName = "netstandard";
|
||||
private const string Win32InteropAssemblyName = "Windows.Win32.Interop";
|
||||
|
@ -210,6 +211,21 @@ namespace ClangSharpSourceToWinmd
|
|||
return this.diagnostics.AsReadOnly();
|
||||
}
|
||||
|
||||
private static string FixFinalName(string name)
|
||||
{
|
||||
if (name.StartsWith(RemovePrefix))
|
||||
{
|
||||
name = name.Substring(RemovePrefix.Length);
|
||||
}
|
||||
|
||||
if (name.EndsWith(ScannedSuffix))
|
||||
{
|
||||
name = name.Substring(0, name.Length - ScannedSuffix.Length);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
private static byte[] ConvertKeyToByteArray(string key)
|
||||
{
|
||||
byte[] ret = new byte[key.Length / 2];
|
||||
|
@ -1097,10 +1113,7 @@ namespace ClangSharpSourceToWinmd
|
|||
continue;
|
||||
}
|
||||
|
||||
if (name.EndsWith(ScannedSuffix))
|
||||
{
|
||||
name = name.Substring(0, name.Length - ScannedSuffix.Length);
|
||||
}
|
||||
name = FixFinalName(name);
|
||||
|
||||
if (name.StartsWith("CLSID_"))
|
||||
{
|
||||
|
@ -1546,7 +1559,7 @@ namespace ClangSharpSourceToWinmd
|
|||
|
||||
this.EncodeTypeSymbol(type, signatureEncoder);
|
||||
|
||||
var memberName = member.Identifier.Text;
|
||||
var memberName = FixFinalName(member.Identifier.Text);
|
||||
if (string.IsNullOrEmpty(memberName))
|
||||
{
|
||||
throw new InvalidOperationException($"Enum {node.Identifier.Text} has a member with no name.");
|
||||
|
|
|
@ -149,11 +149,14 @@ namespace ClangSharpSourceToWinmd
|
|||
|
||||
public override SyntaxNode VisitFieldDeclaration(FieldDeclarationSyntax node)
|
||||
{
|
||||
const string ForceConstPrefix = "__forceconst__";
|
||||
|
||||
string localName = node.Declaration.Variables.First().Identifier.ValueText;
|
||||
|
||||
// If it's a constant, ignore it if it's already part of an enum
|
||||
if (node.Modifiers.ToString() == "public const")
|
||||
{
|
||||
string name = node.Declaration.Variables.First().Identifier.ValueText;
|
||||
if (this.enumMemberNames.Contains(name))
|
||||
if (this.enumMemberNames.Contains(localName))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -170,46 +173,66 @@ namespace ClangSharpSourceToWinmd
|
|||
newType = "string";
|
||||
}
|
||||
|
||||
// Turn public static readonly Guids into string constants with an attribute
|
||||
// to signal language projections to turn them into Guid constants. Guid constants
|
||||
// aren't allowed in metadata, requiring us to surface them this way
|
||||
if (node.Modifiers.ToString() == "public static readonly" && node.Declaration.Type.ToString() == "Guid")
|
||||
if (node.Modifiers.ToString() == "public static readonly")
|
||||
{
|
||||
var varInitializer = node.Declaration.Variables.First().Initializer;
|
||||
if (varInitializer.Value is ObjectCreationExpressionSyntax objCreationSyntax)
|
||||
// Turn public static readonly Guids into string constants with an attribute
|
||||
// to signal language projections to turn them into Guid constants. Guid constants
|
||||
// aren't allowed in metadata, requiring us to surface them this way
|
||||
if (node.Declaration.Type.ToString() == "Guid")
|
||||
{
|
||||
node = node.RemoveNode(varInitializer, SyntaxRemoveOptions.KeepExteriorTrivia | SyntaxRemoveOptions.KeepEndOfLine);
|
||||
|
||||
var args = objCreationSyntax.ArgumentList.Arguments;
|
||||
if (args.Count == 11)
|
||||
var varInitializer = node.Declaration.Variables.First().Initializer;
|
||||
if (varInitializer.Value is ObjectCreationExpressionSyntax objCreationSyntax)
|
||||
{
|
||||
var allArgs = $"(uint){args}";
|
||||
node = node.RemoveNode(varInitializer, SyntaxRemoveOptions.KeepExteriorTrivia | SyntaxRemoveOptions.KeepEndOfLine);
|
||||
|
||||
string argsFormatted = $"({allArgs})";
|
||||
var attrsList =
|
||||
SyntaxFactory.AttributeList(
|
||||
SyntaxFactory.SingletonSeparatedList<AttributeSyntax>(
|
||||
SyntaxFactory.Attribute(
|
||||
SyntaxFactory.ParseName("Windows.Win32.Interop.Guid"),
|
||||
SyntaxFactory.ParseAttributeArgumentList(argsFormatted))));
|
||||
|
||||
node = node.AddAttributeLists(attrsList).WithLeadingTrivia(node.GetLeadingTrivia());
|
||||
}
|
||||
else if (objCreationSyntax.ArgumentList.Arguments.Count == 1)
|
||||
{
|
||||
var textValue = EncodeHelpers.RemoveQuotes(objCreationSyntax.ArgumentList.Arguments[0].ToString());
|
||||
|
||||
// If this is an invalid format, remove the node
|
||||
if (!Guid.TryParse(textValue, out var guidVal))
|
||||
var args = objCreationSyntax.ArgumentList.Arguments;
|
||||
if (args.Count == 11)
|
||||
{
|
||||
return null;
|
||||
var allArgs = $"(uint){args}";
|
||||
|
||||
string argsFormatted = $"({allArgs})";
|
||||
var attrsList =
|
||||
SyntaxFactory.AttributeList(
|
||||
SyntaxFactory.SingletonSeparatedList<AttributeSyntax>(
|
||||
SyntaxFactory.Attribute(
|
||||
SyntaxFactory.ParseName("Windows.Win32.Interop.Guid"),
|
||||
SyntaxFactory.ParseAttributeArgumentList(argsFormatted))));
|
||||
|
||||
node = node.AddAttributeLists(attrsList).WithLeadingTrivia(node.GetLeadingTrivia());
|
||||
}
|
||||
else if (objCreationSyntax.ArgumentList.Arguments.Count == 1)
|
||||
{
|
||||
var textValue = EncodeHelpers.RemoveQuotes(objCreationSyntax.ArgumentList.Arguments[0].ToString());
|
||||
|
||||
node = node.AddAttributeLists(EncodeHelpers.ConvertGuidToAttributeList(guidVal).WithLeadingTrivia(node.GetLeadingTrivia()));
|
||||
// If this is an invalid format, remove the node
|
||||
if (!Guid.TryParse(textValue, out var guidVal))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
node = node.AddAttributeLists(EncodeHelpers.ConvertGuidToAttributeList(guidVal).WithLeadingTrivia(node.GetLeadingTrivia()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return node;
|
||||
return node;
|
||||
}
|
||||
// Some constants get scraped as public static readonly.
|
||||
// If we see the prefix, force it to be a const
|
||||
else if (localName.StartsWith(ForceConstPrefix))
|
||||
{
|
||||
var newModifiers =
|
||||
SyntaxFactory.TokenList(
|
||||
SyntaxFactory.Token(SyntaxKind.PublicKeyword).WithTrailingTrivia(SyntaxFactory.Space),
|
||||
SyntaxFactory.Token(SyntaxKind.ConstKeyword).WithTrailingTrivia(SyntaxFactory.Space));
|
||||
|
||||
node = node.WithModifiers(newModifiers).WithLeadingTrivia(node.GetLeadingTrivia());
|
||||
|
||||
var variable = node.Declaration.Variables.First();
|
||||
variable = variable.WithIdentifier(SyntaxFactory.ParseToken(localName.Substring(ForceConstPrefix.Length)));
|
||||
node = node.WithDeclaration(node.Declaration.WithVariables(SyntaxFactory.SingletonSeparatedList(variable)));
|
||||
|
||||
return node;
|
||||
}
|
||||
}
|
||||
|
||||
node = (FieldDeclarationSyntax)base.VisitFieldDeclaration(node);
|
||||
|
|
|
@ -135,6 +135,7 @@ namespace MetadataTasks
|
|||
foreach (var traverseLine in RspReader.GetSettingsValues(settingsFile, "--traverse"))
|
||||
{
|
||||
var fixedLine = traverseLine.Replace("<IncludeRoot>", this.sdkIncRoot);
|
||||
fixedLine = fixedLine.Replace("<PartitionDir>", Path.GetDirectoryName(this.FullPath));
|
||||
files.Add(fixedLine);
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче