summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Safar <marek.safar@gmail.com>2019-01-31 07:57:39 +0100
committerJan Kotas <jkotas@microsoft.com>2019-01-30 22:57:39 -0800
commit10ba67ac50a2152464981db11f2a893b87f8deee (patch)
treeb2a9b8340d5be730fdb8cdc060a4cd952c136c45
parente369d43e6630774ef73a18821488819fe5f1a596 (diff)
downloadcoreclr-10ba67ac50a2152464981db11f2a893b87f8deee.tar.gz
coreclr-10ba67ac50a2152464981db11f2a893b87f8deee.tar.bz2
coreclr-10ba67ac50a2152464981db11f2a893b87f8deee.zip
Add managed implementation of GetSystemMaxDBCSCharSize (#22290)
-rw-r--r--src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCPInfo.cs5
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs2
-rw-r--r--src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs10
-rw-r--r--src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs6
-rw-r--r--src/vm/ecalllist.h1
-rw-r--r--src/vm/marshalnative.cpp9
-rw-r--r--src/vm/marshalnative.h2
7 files changed, 14 insertions, 21 deletions
diff --git a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCPInfo.cs b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCPInfo.cs
index 1665119420..8d523e41e9 100644
--- a/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCPInfo.cs
+++ b/src/System.Private.CoreLib/shared/Interop/Windows/Kernel32/Interop.GetCPInfo.cs
@@ -2,14 +2,13 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System.IO;
-using System.Text;
using System.Runtime.InteropServices;
internal partial class Interop
{
internal partial class Kernel32
{
+ [StructLayout(LayoutKind.Sequential)]
internal unsafe struct CPINFO
{
internal int MaxCharSize;
@@ -19,6 +18,6 @@ internal partial class Interop
}
[DllImport(Libraries.Kernel32)]
- internal static extern unsafe int GetCPInfo(uint codePage, CPINFO* lpCpInfo);
+ internal static extern unsafe Interop.BOOL GetCPInfo(uint codePage, CPINFO* lpCpInfo);
}
}
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs
index 32c7e632c7..1f049bd795 100644
--- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Unix.cs
@@ -9,6 +9,8 @@ namespace System.Runtime.InteropServices
{
public static partial class Marshal
{
+ private static int GetSystemMaxDBCSCharSize() => 3;
+
private static bool IsWin32Atom(IntPtr ptr) => false;
internal static unsafe int StringToAnsiString(string s, byte* buffer, int bufferLength, bool bestFit = false, bool throwOnUnmappableChar = false)
diff --git a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs
index 2750243855..5a44e497fe 100644
--- a/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs
+++ b/src/System.Private.CoreLib/shared/System/Runtime/InteropServices/Marshal.Windows.cs
@@ -8,6 +8,16 @@ namespace System.Runtime.InteropServices
{
public static partial class Marshal
{
+ private static unsafe int GetSystemMaxDBCSCharSize()
+ {
+ Interop.Kernel32.CPINFO cpInfo = default;
+
+ if (Interop.Kernel32.GetCPInfo(Interop.Kernel32.CP_ACP, &cpInfo) == Interop.BOOL.FALSE)
+ return 2;
+
+ return cpInfo.MaxCharSize;
+ }
+
// Win32 has the concept of Atoms, where a pointer can either be a pointer
// or an int. If it's less than 64K, this is guaranteed to NOT be a
// pointer since the bottom 64K bytes are reserved in a process' page table.
diff --git a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
index d6b4d41452..8bbfd87ccb 100644
--- a/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
+++ b/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.CoreCLR.cs
@@ -39,12 +39,6 @@ namespace System.Runtime.InteropServices
private const int LMEM_FIXED = 0;
private const int LMEM_MOVEABLE = 2;
- /// <summary>
- /// Helper method to retrieve the system's maximum DBCS character size.
- /// </summary>
- [MethodImpl(MethodImplOptions.InternalCall)]
- private static extern int GetSystemMaxDBCSCharSize();
-
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern int SizeOfHelper(Type t, bool throwIfNotMarshalable);
diff --git a/src/vm/ecalllist.h b/src/vm/ecalllist.h
index fb182e33a3..bef2de9674 100644
--- a/src/vm/ecalllist.h
+++ b/src/vm/ecalllist.h
@@ -805,7 +805,6 @@ FCFuncStart(gInteropMarshalFuncs)
FCFuncElement("GetLastWin32Error", MarshalNative::GetLastWin32Error)
FCFuncElement("SetLastWin32Error", MarshalNative::SetLastWin32Error)
FCFuncElement("SizeOfHelper", MarshalNative::SizeOfClass)
- FCFuncElement("GetSystemMaxDBCSCharSize", MarshalNative::GetSystemMaxDBCSCharSize)
FCFuncElement("StructureToPtr", MarshalNative::StructureToPtr)
FCFuncElement("PtrToStructureHelper", MarshalNative::PtrToStructureHelper)
FCFuncElement("DestroyStructure", MarshalNative::DestroyStructure)
diff --git a/src/vm/marshalnative.cpp b/src/vm/marshalnative.cpp
index 908a7b3b04..3419e3fb15 100644
--- a/src/vm/marshalnative.cpp
+++ b/src/vm/marshalnative.cpp
@@ -481,15 +481,6 @@ FCIMPL3(LPVOID, MarshalNative::GetManagedThunkForUnmanagedMethodPtr, LPVOID pfnM
}
FCIMPLEND
-
-FCIMPL0(UINT32, MarshalNative::GetSystemMaxDBCSCharSize)
-{
- FCALL_CONTRACT;
-
- return GetMaxDBCSCharByteSize();
-}
-FCIMPLEND
-
/************************************************************************
* PInvoke.GetLastWin32Error
*/
diff --git a/src/vm/marshalnative.h b/src/vm/marshalnative.h
index 8f3168820a..064cd61f83 100644
--- a/src/vm/marshalnative.h
+++ b/src/vm/marshalnative.h
@@ -68,8 +68,6 @@ public:
static FCDECL3(LPVOID, GetUnmanagedThunkForManagedMethodPtr, LPVOID pfnMethodToWrap, PCCOR_SIGNATURE pbSignature, ULONG cbSignature);
static FCDECL3(LPVOID, GetManagedThunkForUnmanagedMethodPtr, LPVOID pfnMethodToWrap, PCCOR_SIGNATURE pbSignature, ULONG cbSignature);
- static FCDECL0(UINT32, GetSystemMaxDBCSCharSize);
-
static FCDECL2(LPVOID, GCHandleInternalAlloc, Object *obj, int type);
static FCDECL1(VOID, GCHandleInternalFree, OBJECTHANDLE handle);
static FCDECL1(LPVOID, GCHandleInternalGet, OBJECTHANDLE handle);