1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-08 03:27:04 +09:00

Clarify P/Invoke shims guidance for OOB assemblies (#63470)

* Clarify P/Invoke shims guidance for OOB assemblies

The discussion in PR #63421 clarified that System.Native shims for UNIX
APIs aren't appropriate for assemblies that don't ship as part of the
Microsoft.NETCore.App framework.

Updating the interop guidelines to capture that clarification.

* Update docs/coding-guidelines/interop-guidelines.md

Co-authored-by: Stephen Toub <stoub@microsoft.com>

Co-authored-by: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
Matt Kotsenas 2022-01-07 12:31:55 -08:00 committed by GitHub
parent 568364ac91
commit 83c97613a3
Signed by: github
GPG key ID: 4AEE18F83AFDEB23

View file

@ -180,6 +180,8 @@ This leaves us with a situation where we can't write portable P/Invoke declarati
To address this, we're moving to a model where all UNIX interop from dotnet/runtime starts with a P/Invoke to a C++ lib written specifically for dotnet/runtime. These libs -- System.*.Native.so (aka "shims") -- are intended to be very thin layers over underlying platform libraries. Generally, they are not there to add any significant abstraction, but to create a stable ABI such that the same IL assembly can work across UNIX flavors.
The System.Native shims are a private implementation detail of the Microsoft.NETCore.App shared framework and are intended only for use by code inside of the shared framework. Calling into the shims from external to Microsoft.NETCore.App has similar risks to using private reflection, with no guarantees from version to version or even patch to patch of stable exports. Assemblies that ship outside of the shared framework (e.g. Microsoft.Extensions.*) must not directly access the shims.
Guidelines for shim C++ API:
- Keep them as "thin"/1:1 as possible.