diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Architecture.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Architecture.cs index a59a9a5868e89..ec9641fffb75a 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Architecture.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Architecture.cs @@ -3,16 +3,52 @@ namespace System.Runtime.InteropServices { + /// + /// Indicates the processor architecture. + /// public enum Architecture { + /// + /// An Intel-based 32-bit processor architecture. + /// X86, + /// + /// An Intel-based 64-bit processor architecture. + /// X64, + /// + /// A 32-bit ARM processor architecture. + /// + /// + /// This value indicates ARMv7 base instructions, VFPv3 floating point support and registers, and Thumb2 compact instruction set. + /// Arm, + /// + /// A 64-bit ARM processor architecture. + /// Arm64, + /// + /// The WebAssembly platform. + /// Wasm, + /// + /// A S390x platform architecture. + /// S390x, + /// + /// A LoongArch64 processor architecture. + /// LoongArch64, + /// + /// A 32-bit ARMv6 processor architecture. + /// + /// + /// This value indicates ARMv6 base instructions, VFPv2 floating point support and registers, hard-float ABI, and no compact instruction set. + /// Armv6, + /// + /// A PowerPC 64-bit (little-endian) processor architecture. + /// Ppc64le, } } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ArrayMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ArrayMarshaller.cs index 3803812953ca7..ec73d0debec29 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ArrayMarshaller.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/ArrayMarshaller.cs @@ -22,6 +22,12 @@ namespace System.Runtime.InteropServices.Marshalling public static unsafe class ArrayMarshaller where TUnmanagedElement : unmanaged { + /// + /// Allocates memory for the unmanaged representation of the array. + /// + /// The managed array + /// The unmanaged element count + /// The unmanaged pointer to the allocated memory public static TUnmanagedElement* AllocateContainerForUnmanagedElements(T[]? managed, out int numElements) { if (managed is null) @@ -37,12 +43,29 @@ public static unsafe class ArrayMarshaller return (TUnmanagedElement*)Marshal.AllocCoTaskMem(spaceToAllocate); } + /// + /// Gets a source for the managed elements in the array. + /// + /// The managed array + /// The containing the managed elements to marshal public static ReadOnlySpan GetManagedValuesSource(T[]? managed) => managed; + /// + /// Gets a destination for the unmanaged elements in the array. + /// + /// The unmanaged allocation + /// The unmanaged element count + /// The of unmanaged elements public static Span GetUnmanagedValuesDestination(TUnmanagedElement* unmanaged, int numElements) => new Span(unmanaged, numElements); + /// + /// Allocates memory for the managed representation of the array. + /// + /// The unmanaged array + /// The unmanaged element count + /// The managed array public static T[]? AllocateContainerForManagedElements(TUnmanagedElement* unmanaged, int numElements) { if (unmanaged is null) @@ -51,17 +74,41 @@ public static Span GetUnmanagedValuesDestination(TUnmanagedEl return new T[numElements]; } + /// + /// Gets a destination for the managed elements in the array. + /// + /// The managed array + /// The of managed elements public static Span GetManagedValuesDestination(T[]? managed) => managed; + /// + /// Gets a source for the unmanaged elements in the array. + /// + /// The unmanaged array + /// The unmanaged element count + /// The containing the unmanaged elements to marshal public static ReadOnlySpan GetUnmanagedValuesSource(TUnmanagedElement* unmanagedValue, int numElements) => new ReadOnlySpan(unmanagedValue, numElements); + /// + /// Frees memory for the unmanaged array. + /// + /// Unmanaged array public static void Free(TUnmanagedElement* unmanaged) => Marshal.FreeCoTaskMem((IntPtr)unmanaged); + /// + /// Marshaller for marshalling a array from managed to unmanaged. + /// public ref struct ManagedToUnmanagedIn { + /// + /// Requested caller-allocated buffer size. + /// + /// + /// Represents a potential optimization for the marshaller. + /// // We'll keep the buffer size at a maximum of 200 bytes to avoid overflowing the stack. public static int BufferSize { get; } = 0x200 / sizeof(TUnmanagedElement); @@ -134,6 +181,11 @@ public void Free() NativeMemory.Free(_allocatedMemory); } + /// + /// Gets a pinnable reference to the managed array. + /// + /// The managed array. + /// The reference that can be pinned and directly passed to unmanaged code. public static ref T GetPinnableReference(T[]? array) { if (array is null) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/PointerArrayMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/PointerArrayMarshaller.cs index bbfc3baffc423..115abfb92896c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/PointerArrayMarshaller.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/PointerArrayMarshaller.cs @@ -23,6 +23,12 @@ public static unsafe class PointerArrayMarshaller where T : unmanaged where TUnmanagedElement : unmanaged { + /// + /// Allocates memory for the unmanaged representation of the array. + /// + /// The managed array to marshal + /// The unmanaged element count + /// The unmanaged pointer to the allocated memory public static TUnmanagedElement* AllocateContainerForUnmanagedElements(T*[]? managed, out int numElements) { if (managed is null) @@ -38,12 +44,29 @@ public static unsafe class PointerArrayMarshaller return (TUnmanagedElement*)Marshal.AllocCoTaskMem(spaceToAllocate); } + /// + /// Gets a source for the managed elements in the array. + /// + /// The managed array + /// The containing the managed elements to marshal public static ReadOnlySpan GetManagedValuesSource(T*[]? managed) => Unsafe.As(managed); + /// + /// Gets a destination for the unmanaged elements in the array. + /// + /// The unmanaged allocation + /// The unmanaged element count + /// The of unmanaged elements public static Span GetUnmanagedValuesDestination(TUnmanagedElement* unmanaged, int numElements) => new Span(unmanaged, numElements); + /// + /// Allocates memory for the managed representation of the array. + /// + /// The unmanaged array + /// The unmanaged element count + /// The managed array public static T*[]? AllocateContainerForManagedElements(TUnmanagedElement* unmanaged, int numElements) { if (unmanaged is null) @@ -52,17 +75,42 @@ public static Span GetUnmanagedValuesDestination(TUnmanagedEl return new T*[numElements]; } + /// + /// Gets a destination for the managed elements in the array. + /// + /// The managed array + /// The of managed elements public static Span GetManagedValuesDestination(T*[]? managed) => Unsafe.As(managed); + /// + /// Gets a source for the unmanaged elements in the array. + /// + /// The unmanaged array + /// The unmanaged element count + /// The containing the unmanaged elements to marshal public static ReadOnlySpan GetUnmanagedValuesSource(TUnmanagedElement* unmanagedValue, int numElements) => new ReadOnlySpan(unmanagedValue, numElements); + /// + /// Frees memory for the unmanaged array. + /// + /// Unmanaged array public static void Free(TUnmanagedElement* unmanaged) => Marshal.FreeCoTaskMem((IntPtr)unmanaged); + /// + /// Marshaller for marshalling a array from managed to unmanaged. + /// public ref struct ManagedToUnmanagedIn { + /// + /// Requested caller-allocated buffer size. + /// + /// + /// Represents a potential optimization for the marshaller. + /// + // We'll keep the buffer size at a maximum of 200 bytes to avoid overflowing the stack. public static int BufferSize => 0x200 / sizeof(TUnmanagedElement); private T*[]? _managedArray; @@ -134,6 +182,11 @@ public void Free() NativeMemory.Free(_allocatedMemory); } + /// + /// Gets a pinnable reference to the managed array. + /// + /// The managed array. + /// The reference that can be pinned and directly passed to unmanaged code. public static ref byte GetPinnableReference(T*[]? array) { if (array is null) diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SpanMarshaller.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SpanMarshaller.cs index bccaef9203e6d..49bfd1a728e08 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SpanMarshaller.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshalling/SpanMarshaller.cs @@ -180,6 +180,11 @@ public void Free() NativeMemory.Free(_allocatedMemory); } + /// + /// Gets a pinnable reference to the managed span. + /// + /// The managed span. + /// A reference that can be pinned and directly passed to unmanaged code. public static ref T GetPinnableReference(Span managed) { return ref MemoryMarshal.GetReference(managed); diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StringMarshalling.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StringMarshalling.cs index d073ee08227c3..503b4e4cf149d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StringMarshalling.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/StringMarshalling.cs @@ -20,8 +20,17 @@ namespace System.Runtime.InteropServices #endif enum StringMarshalling { + /// + /// Indicates the user is suppling a specific marshaller in . + /// Custom = 0, - Utf8, // UTF-8 - Utf16, // UTF-16, machine-endian + /// + /// Use the platform-provided UTF-8 marshaller. + /// + Utf8, + /// + /// Use the platform-provided UTF-16 marshaller. + /// + Utf16, } }