- 
                Notifications
    You must be signed in to change notification settings 
- Fork 114
Description
Actual behavior
Declaring an instance of the struct PROCESS_BASIC_INFORMATION and passing it to NtQueryInformationProcess results in either a read/write memory error or incorrect values ending up in the struct. The issue seems to be the PEB[] PebBaseAddress declaration.
While the struct has the correct sizeof compared to when it is read from memory even the unrelated struct fields (like UniqueProcessId) have the wrong values when passed to ntqueryinformationprocess. I was confused that VS internal seemed to use the call without issue, but then realized they are actually declaring their own instance of the class: https://github.com/microsoft/vs-extension-testing/blob/b78ac2a63a471cc0a56b45af0a1d7b2473288202/src/Microsoft.VisualStudio.Extensibility.Testing.Xunit.Shared/Harness/VisualStudioInstance.cs#L273-L281
Here is the generated version
internal partial struct PROCESS_BASIC_INFORMATION
		{
			internal winmdroot.Foundation.NTSTATUS ExitStatus;
			internal winmdroot.System.Threading.PEB[] PebBaseAddress;
			internal nuint AffinityMask;
			internal int BasePriority;
			internal nuint UniqueProcessId;
			internal nuint InheritedFromUniqueProcessId;
		}changing winmdroot.System.Threading.PEB[] to IntPtr fixes it.
Expected behavior
Calling NtQueryInformationProcess with it to not throw an exception and have the right data values.
Repro steps
- NativeMethods.txtcontent:
NtQueryInformationProcess
- Any of your own code that should be shared?
nuint nreturnLength = 0;
PROCESS_BASIC_INFORMATION pbi = default;
PInvoke.NtQueryInformationProcess(handle, PROCESSINFOCLASS.ProcessBasicInformation, &pbi, (uint)Marshal.SizeOf<PROCESS_BASIC_INFORMATION>(), ref returnLength);Context
- CsWin32 version: [e.g. 0.4.422-beta]
- Win32Metadata version (if explicitly set by project):
- Target Framework: [e.g. netstandard2.0]
- LangVersion(if explicitly set by project): [e.g.- 9]