Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 11, 2025

The SDK was P/Invoking into System.Native (via libSystem.Native), a private implementation detail of the runtime. This caused breakage in .NET 7 on arm64 when the runtime changed the native function signature (dotnet/runtime#72308).

Changes

  • Removed src/Cli/dotnet/StatInterop.cs - contained DllImport declarations for SystemNative_LStat and associated structs (FileStatus, Permissions, FileStatusFlags)

The file had no references in the codebase and was not being used. Originally intended for checking file ownership in SudoEnvironmentDirectoryOverride.cs, but that code path was never implemented.

Original prompt

This section details on the original issue you should resolve

<issue_title>Don't DllImport System.Native libraries</issue_title>
<issue_description>### Describe the bug
Today we are p/invoking into the System.Native library in dotnet/runtime to use the lstat function:

[DllImport("libSystem.Native", EntryPoint = "SystemNative_LStat", SetLastError = true)]
internal static extern int LStat(string path, out FileStatus output);

This isn't recommended because this library is a private implementation detail of the runtime. We should find another way to implement the required functionality here.

One possibility is to add the necessary APIs to .NET to read the current owner of a file:

private static bool TempHomeIsOnlyRootWritable(string path)
{
if (StatInterop.LStat(path, out StatInterop.FileStatus fileStat) != 0)
{
return false;
}
return IsOwnedByRoot(fileStat) && GroupCannotWrite(fileStat) &&
OtherUserCannotWrite(fileStat);
}
private static bool OtherUserCannotWrite(StatInterop.FileStatus fileStat)
{
return (fileStat.Mode & (int) StatInterop.Permissions.S_IWOTH) == 0;
}
private static bool GroupCannotWrite(StatInterop.FileStatus fileStat)
{
return (fileStat.Mode & (int) StatInterop.Permissions.S_IWGRP) == 0;
}
private static bool IsOwnedByRoot(StatInterop.FileStatus fileStat)
{
return fileStat.Uid == 0;
}

.NET 7 added APIs to check the file's mode, but this code also needs to check the file's owner.

To Reproduce

This is the root cause of dotnet/runtime#72308. In .NET 7 the runtime changed the signature of this native function and broke the SDK on arm64.
</issue_description>

<agent_instructions>Remove the entire StatInterop.cs file as we do not think it is used or needed.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: marcpopMSFT <[email protected]>
Copy link
Member

@marcpopMSFT marcpopMSFT left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No testing done as we're just removing a file we don't think is used and would expect it to fail to build/run if still in use.

Copilot finished reviewing on behalf of marcpopMSFT November 13, 2025 21:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes an unused file that contained P/Invoke declarations to a private runtime library, preventing potential future breakage. The SDK was incorrectly depending on System.Native (via libSystem.Native), which is a private implementation detail of the runtime and caused breaking changes in .NET 7 on arm64.

  • Removed src/Cli/dotnet/StatInterop.cs containing unused DllImport declarations for SystemNative_LStat and associated structs

@marcpopMSFT marcpopMSFT requested a review from MiYanni November 13, 2025 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don't DllImport System.Native libraries

2 participants