From 8f18133fe0114e506ef89824f01a09b31b090e23 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Tue, 3 Jun 2025 21:25:24 -0700 Subject: [PATCH 1/3] Add more detail to GetFunctionPointerForDelegate docs --- xml/System.Runtime.InteropServices/Marshal.xml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/xml/System.Runtime.InteropServices/Marshal.xml b/xml/System.Runtime.InteropServices/Marshal.xml index 03afd30fd50..532ceb0a1ba 100644 --- a/xml/System.Runtime.InteropServices/Marshal.xml +++ b/xml/System.Runtime.InteropServices/Marshal.xml @@ -3946,10 +3946,15 @@ The code retrieves a reference to an instance of Microsoft Word successfully. Ho You must manually keep the delegate from being collected by the garbage collector from managed code. The garbage collector does not track references to unmanaged code. + This API is unsupported in environments that do not support dynamic entrypoint allocation, such as ProcessDynamicCodePolicy on Windows or WebAssembly. + + It is recommended to use function pointers and (xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute) instead. Function pointers are more efficient, easier to use correctly, and supported in all environments. + ]]> The parameter is a generic type definition. The parameter is . + Dynamic entrypoint allocation is not supported in the current environment. @@ -4014,11 +4019,15 @@ The code retrieves a reference to an instance of Microsoft Word successfully. Ho The delegate `d` is converted to a function pointer that can be passed to unmanaged code by using [the default platform calling convention](/dotnet/standard/native-interop/calling-conventions#platform-default-calling-convention). You can set the calling convention by applying the to the delegate. You must manually keep the delegate from being collected by the garbage collector from managed code. The garbage collector does not track references to unmanaged code. - + + This API is unsupported in environments that do not support dynamic entrypoint allocation, such as ProcessDynamicCodePolicy on Windows or WebAssembly. + + It is recommended to use function pointers and (xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute) instead. Function pointers are more efficient, easier to use correctly, and supported in all environments. ]]> The parameter is a generic type definition. The parameter is . + Dynamic entrypoint allocation is not supported in the current environment. From de735a8b6f16fca324c647537217353f67e82a7b Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Wed, 4 Jun 2025 21:00:50 -0700 Subject: [PATCH 2/3] Apply suggestions from code review --- xml/System.Runtime.InteropServices/Marshal.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xml/System.Runtime.InteropServices/Marshal.xml b/xml/System.Runtime.InteropServices/Marshal.xml index 532ceb0a1ba..c8c3637509b 100644 --- a/xml/System.Runtime.InteropServices/Marshal.xml +++ b/xml/System.Runtime.InteropServices/Marshal.xml @@ -3946,7 +3946,7 @@ The code retrieves a reference to an instance of Microsoft Word successfully. Ho You must manually keep the delegate from being collected by the garbage collector from managed code. The garbage collector does not track references to unmanaged code. - This API is unsupported in environments that do not support dynamic entrypoint allocation, such as ProcessDynamicCodePolicy on Windows or WebAssembly. + This API is unsupported in environments that do not support dynamic entrypoint allocation, such as `ProcessDynamicCodePolicy` on Windows, `execmem off` in SELinux, or WebAssembly. It is recommended to use function pointers and (xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute) instead. Function pointers are more efficient, easier to use correctly, and supported in all environments. @@ -4020,7 +4020,7 @@ The code retrieves a reference to an instance of Microsoft Word successfully. Ho You must manually keep the delegate from being collected by the garbage collector from managed code. The garbage collector does not track references to unmanaged code. - This API is unsupported in environments that do not support dynamic entrypoint allocation, such as ProcessDynamicCodePolicy on Windows or WebAssembly. + This API is unsupported in environments that do not support dynamic entrypoint allocation, such as `ProcessDynamicCodePolicy` on Windows, `execmem off` in SELinux, or WebAssembly. It is recommended to use function pointers and (xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute) instead. Function pointers are more efficient, easier to use correctly, and supported in all environments. ]]> From 66aa2db69c18d3270e70f98519b6fae90d1ab249 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 9 Jun 2025 17:05:32 -0700 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> --- xml/System.Runtime.InteropServices/Marshal.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/xml/System.Runtime.InteropServices/Marshal.xml b/xml/System.Runtime.InteropServices/Marshal.xml index c8c3637509b..9266fd7fc60 100644 --- a/xml/System.Runtime.InteropServices/Marshal.xml +++ b/xml/System.Runtime.InteropServices/Marshal.xml @@ -3946,9 +3946,9 @@ The code retrieves a reference to an instance of Microsoft Word successfully. Ho You must manually keep the delegate from being collected by the garbage collector from managed code. The garbage collector does not track references to unmanaged code. - This API is unsupported in environments that do not support dynamic entrypoint allocation, such as `ProcessDynamicCodePolicy` on Windows, `execmem off` in SELinux, or WebAssembly. + This API is unsupported in environments that don't support dynamic entry-point allocation, such as `ProcessDynamicCodePolicy` on Windows, `execmem off` in SELinux, and WebAssembly. - It is recommended to use function pointers and (xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute) instead. Function pointers are more efficient, easier to use correctly, and supported in all environments. + It is recommended to use function pointers and instead. Function pointers are more efficient, easier to use correctly, and supported in all environments. ]]> @@ -4020,9 +4020,9 @@ The code retrieves a reference to an instance of Microsoft Word successfully. Ho You must manually keep the delegate from being collected by the garbage collector from managed code. The garbage collector does not track references to unmanaged code. - This API is unsupported in environments that do not support dynamic entrypoint allocation, such as `ProcessDynamicCodePolicy` on Windows, `execmem off` in SELinux, or WebAssembly. + This API is unsupported in environments that don't support dynamic entry-point allocation, such as `ProcessDynamicCodePolicy` on Windows, `execmem off` in SELinux, and WebAssembly. - It is recommended to use function pointers and (xref:System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute) instead. Function pointers are more efficient, easier to use correctly, and supported in all environments. + It is recommended to use function pointers and instead. Function pointers are more efficient, easier to use correctly, and supported in all environments. ]]> The parameter is a generic type definition.