runtime: iOS (and other Apple platforms): the BCL has P/Invokes to libraries and/or functions that don't exist

Description

There are several DllImports in the BCL for iOS (and the other Apple platforms) that contain references to native functions that don’t exist. It’s highly preferable to not have any P/Invokes to native functions that don’t exist, because it allows the AOT compiler to generate more efficient code. It also makes other performance improvements possible.

  • System.Diagnostics.Process.dl

    • P/Invoke to SystemNative_ConfigureTerminalForChildProcess in libSystem.Native.dylib, but libSystem.Native.dylib doesn’t provide that function. Tracked in #47910
  • System.Net.Quic.dll

    • MsQuicOpen Library: libmsquic.dylib
  • System.Reflection.Metadata.dll

    • ReadFile Library: kernel32.dll
  • System.Security.Cryptography.Algorithms.dll, System.Security.Cryptography.OpenSsl.dll and System.Security.Cryptography.X509Certificates.dll

    • Numerous references to functions in libSystem.Security.Cryptography.Native.Apple.dylib of the form AppleCryptoNative_* or CryptoNative_*. Tracked in #47910
  • System.Private.CoreLib.dll

    • Numerous references to functions in libSystem.Globalization.Native.dylib of the form GlobalizationNative_*. I believe this is because of pending work (issue #?)
    • Two functions from libhostpolicy.dylib(corehost_resolve_component_dependencies and corehost_set_error_writer). This has also been reported in #38543.

This is from the microsoft.netcore.app.runtime.ios-arm64 pack (6.0.0-alpha.1.21063.13).

Full output from custom tool I wrote: https://gist.github.com/rolfbjarne/b9a6f16d2a6697c0d8dfc46c39160404

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 15 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Just means that the relevant Interop.cs is being included in the iOS build when it doesn’t need to.

Actually it’s worse because in some cases the Interop code is called on the managed side and fails in very unpredictable fashion. This was one reported instance on Discord:

Unhandled Exception:
System.EntryPointNotFoundException: AppleCryptoNative_SecKeychainItemCopyKeychain
   at Interop.AppleCrypto.SecKeychainItemCopyKeychain(IntPtr item)
   at System.Security.Cryptography.Apple.SafeTemporaryKeychainHandle.UntrackItem(IntPtr keychainItem)
   at System.Security.Cryptography.Apple.SafeKeychainItemHandle.ReleaseHandle()
   at System.Runtime.InteropServices.SafeHandle.InternalRelease(Boolean disposeOrFinalizeOperation)
   at System.Runtime.InteropServices.SafeHandle.Dispose(Boolean disposing)
   at System.Runtime.InteropServices.SafeHandle.Finalize()