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

Commit f11ce88

Browse files
authored
Use aot friendly interop in System.Diagnostics.Process (#28329)
Fixes dotnet/corert#5593
1 parent dcdb83a commit f11ce88

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/Common/src/Interop/Windows/advapi32/Interop.CreateProcessWithLogon.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ internal static extern bool CreateProcessWithLogonW(
1616
string domain,
1717
IntPtr password,
1818
LogonFlags logonFlags,
19-
[MarshalAs(UnmanagedType.LPTStr)] string appName,
19+
string appName,
2020
StringBuilder cmdLine,
2121
int creationFlags,
2222
IntPtr environmentBlock,
23-
[MarshalAs(UnmanagedType.LPTStr)] string lpCurrentDirectory,
23+
string lpCurrentDirectory,
2424
Interop.Kernel32.STARTUPINFO lpStartupInfo,
25-
Interop.Kernel32.PROCESS_INFORMATION lpProcessInformation);
25+
[Out] Interop.Kernel32.PROCESS_INFORMATION lpProcessInformation);
2626

2727
[Flags]
2828
internal enum LogonFlags

src/Common/src/Interop/Windows/kernel32/Interop.CreateProcess.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ internal partial class Kernel32
1313
{
1414
[DllImport(Libraries.Kernel32, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false, EntryPoint = "CreateProcessW")]
1515
internal static extern bool CreateProcess(
16-
[MarshalAs(UnmanagedType.LPTStr)] string lpApplicationName,
16+
string lpApplicationName,
1717
StringBuilder lpCommandLine,
1818
ref SECURITY_ATTRIBUTES procSecAttrs,
1919
ref SECURITY_ATTRIBUTES threadSecAttrs,
2020
bool bInheritHandles,
2121
int dwCreationFlags,
2222
IntPtr lpEnvironment,
23-
[MarshalAs(UnmanagedType.LPTStr)] string lpCurrentDirectory,
23+
string lpCurrentDirectory,
2424
STARTUPINFO lpStartupInfo,
2525
[Out] PROCESS_INFORMATION lpProcessInformation
2626
);
2727

2828
[StructLayout(LayoutKind.Sequential)]
29-
internal class PROCESS_INFORMATION
29+
internal sealed class PROCESS_INFORMATION
3030
{
3131
internal IntPtr hProcess = IntPtr.Zero;
3232
internal IntPtr hThread = IntPtr.Zero;
@@ -35,7 +35,7 @@ internal class PROCESS_INFORMATION
3535
}
3636

3737
[StructLayout(LayoutKind.Sequential)]
38-
internal class STARTUPINFO : IDisposable
38+
internal sealed class STARTUPINFO : IDisposable
3939
{
4040
internal int cb;
4141
internal IntPtr lpReserved = IntPtr.Zero;
@@ -59,7 +59,7 @@ internal class STARTUPINFO : IDisposable
5959
internal
6060
STARTUPINFO()
6161
{
62-
cb = Marshal.SizeOf(this);
62+
cb = Marshal.SizeOf<STARTUPINFO>();
6363
}
6464

6565
public void Dispose()

src/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Windows.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ private static unsafe ProcessInfo[] GetProcessInfos(IntPtr dataPtr, Predicate<in
758758
// get the threads for current process
759759
processInfos[processInfo.ProcessId] = processInfo;
760760

761-
currentPtr = (IntPtr)((long)currentPtr + Marshal.SizeOf(pi));
761+
currentPtr = (IntPtr)((long)currentPtr + sizeof(SystemProcessInformation));
762762
int i = 0;
763763
while (i < pi.NumberOfThreads)
764764
{
@@ -774,7 +774,7 @@ private static unsafe ProcessInfo[] GetProcessInfos(IntPtr dataPtr, Predicate<in
774774
threadInfo._threadWaitReason = NtProcessManager.GetThreadWaitReason((int)ti.WaitReason);
775775

776776
processInfo._threadInfoList.Add(threadInfo);
777-
currentPtr = (IntPtr)((long)currentPtr + Marshal.SizeOf(ti));
777+
currentPtr = (IntPtr)((long)currentPtr + sizeof(SystemThreadInformation));
778778
i++;
779779
}
780780
}

0 commit comments

Comments
 (0)