Implement Marshal.SetLastWin32Error
authorFilip Navara <navara@emclient.com>
Wed, 18 Sep 2019 16:06:49 +0000 (18:06 +0200)
committerMarek Safar <marek.safar@gmail.com>
Thu, 19 Sep 2019 07:59:49 +0000 (09:59 +0200)
Commit migrated from https://github.com/mono/mono/commit/85056b086f950799b79a8f999e9a3edd406b0785

src/mono/mono/metadata/icall-def-netcore.h
src/mono/mono/metadata/icall-def.h
src/mono/mono/metadata/marshal.c
src/mono/mono/metadata/marshal.h
src/mono/netcore/System.Private.CoreLib/src/System.Runtime.InteropServices/Marshal.cs

index 0373349..f1df804 100644 (file)
@@ -362,6 +362,7 @@ HANDLES(MARSHAL_19, "PtrToStringUni(intptr,int)", ves_icall_System_Runtime_Inter
 HANDLES(MARSHAL_20, "PtrToStructureInternal", ves_icall_System_Runtime_InteropServices_Marshal_PtrToStructureInternal, void, 3, (gconstpointer, MonoObject, MonoBoolean))
 HANDLES(MARSHAL_43, "ReAllocCoTaskMem", ves_icall_System_Runtime_InteropServices_Marshal_ReAllocCoTaskMem, gpointer, 2, (gpointer, int))
 HANDLES(MARSHAL_23, "ReAllocHGlobal", ves_icall_System_Runtime_InteropServices_Marshal_ReAllocHGlobal, gpointer, 2, (gpointer, gsize))
+NOHANDLES(ICALL(MARSHAL_29a, "SetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_SetLastWin32Error))
 HANDLES(MARSHAL_30, "SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf, guint32, 1, (MonoReflectionType))
 HANDLES(MARSHAL_31, "SizeOfHelper", ves_icall_System_Runtime_InteropServices_Marshal_SizeOfHelper, guint32, 2, (MonoReflectionType, MonoBoolean))
 HANDLES(MARSHAL_32, "StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi, char_ptr, 2, (const_gunichar2_ptr, int))
index 63a5a09..039b3d9 100644 (file)
@@ -805,6 +805,7 @@ HANDLES(MARSHAL_49, "ReleaseComObjectInternal", ves_icall_System_Runtime_Interop
 #if !defined (DISABLE_COM) || defined (HOST_WIN32)
 NOHANDLES(ICALL(MARSHAL_29, "ReleaseInternal", ves_icall_System_Runtime_InteropServices_Marshal_ReleaseInternal))
 #endif
+NOHANDLES(ICALL(MARSHAL_29a, "SetLastWin32Error", ves_icall_System_Runtime_InteropServices_Marshal_SetLastWin32Error))
 HANDLES(MARSHAL_30, "SizeOf", ves_icall_System_Runtime_InteropServices_Marshal_SizeOf, guint32, 1, (MonoReflectionType))
 HANDLES(MARSHAL_31, "SizeOfHelper", ves_icall_System_Runtime_InteropServices_Marshal_SizeOfHelper, guint32, 2, (MonoReflectionType, MonoBoolean))
 HANDLES(MARSHAL_32, "StringToHGlobalAnsi", ves_icall_System_Runtime_InteropServices_Marshal_StringToHGlobalAnsi, char_ptr, 2, (const_gunichar2_ptr, int))
index b4e320b..c38034c 100644 (file)
@@ -5177,6 +5177,12 @@ ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error (void)
        return GPOINTER_TO_INT (mono_native_tls_get_value (last_error_tls_id));
 }
 
+void
+ves_icall_System_Runtime_InteropServices_Marshal_SetLastWin32Error (guint32 err)
+{
+       mono_native_tls_set_value (last_error_tls_id, GINT_TO_POINTER (err));
+}
+
 guint32 
 ves_icall_System_Runtime_InteropServices_Marshal_SizeOf (MonoReflectionTypeHandle rtype, MonoError *error)
 {
index e556c52..f19be39 100644 (file)
@@ -601,6 +601,10 @@ guint32
 ves_icall_System_Runtime_InteropServices_Marshal_GetLastWin32Error (void);
 
 ICALL_EXPORT
+void
+ves_icall_System_Runtime_InteropServices_Marshal_SetLastWin32Error (guint32 err);
+
+ICALL_EXPORT
 mono_bstr
 ves_icall_System_Runtime_InteropServices_Marshal_BufferToBSTR (const gunichar2 *ptr, int len);
 
index 68ce920..33bf49d 100644 (file)
@@ -64,10 +64,8 @@ namespace System.Runtime.InteropServices
                        //return !type.IsValueType || RuntimeTypeHandle.HasReferences (type as RuntimeType);
                }
 
-               // TODO: Should be called from Windows only code
-               internal static void SetLastWin32Error (int error)
-               {
-               }
+               [MethodImplAttribute(MethodImplOptions.InternalCall)]
+               internal static extern void SetLastWin32Error (int error);
 
                static Exception GetExceptionForHRInternal (int errorCode, IntPtr errorInfo)
                {