You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
@@ -38,6 +38,7 @@ using System.Security;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Text;
|
||||
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
#if !FULL_AOT_RUNTIME
|
||||
@@ -83,6 +84,9 @@ namespace System.Runtime.InteropServices
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
public extern static IntPtr AllocCoTaskMem (int cb);
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal extern static IntPtr AllocCoTaskMemSize (UIntPtr sizet);
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
[ReliabilityContractAttribute (Consistency.WillNotCorruptState, Cer.MayFail)]
|
||||
@@ -285,6 +289,12 @@ namespace System.Runtime.InteropServices
|
||||
FreeCoTaskMem (s);
|
||||
}
|
||||
|
||||
public static void ZeroFreeCoTaskMemUTF8 (IntPtr s)
|
||||
{
|
||||
ClearAnsi (s);
|
||||
FreeCoTaskMem (s);
|
||||
}
|
||||
|
||||
public static void ZeroFreeGlobalAllocAnsi (IntPtr s)
|
||||
{
|
||||
ClearAnsi (s);
|
||||
@@ -758,6 +768,16 @@ namespace System.Runtime.InteropServices
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
public extern static string PtrToStringAnsi (IntPtr ptr, int len);
|
||||
|
||||
public static string PtrToStringUTF8 (IntPtr ptr)
|
||||
{
|
||||
return PtrToStringAnsi (ptr);
|
||||
}
|
||||
|
||||
public static string PtrToStringUTF8 (IntPtr ptr, int byteLen)
|
||||
{
|
||||
return PtrToStringAnsi (ptr, byteLen);
|
||||
}
|
||||
|
||||
public static string PtrToStringAuto (IntPtr ptr)
|
||||
{
|
||||
return SystemDefaultCharSize == 2
|
||||
@@ -1053,23 +1073,9 @@ namespace System.Runtime.InteropServices
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
public extern static IntPtr StringToBSTR (string s);
|
||||
|
||||
//
|
||||
// I believe this is wrong, because in Mono and in P/Invoke
|
||||
// we treat "Ansi" conversions as UTF-8 conversions, while
|
||||
// this one does not do this
|
||||
//
|
||||
public static IntPtr StringToCoTaskMemAnsi (string s)
|
||||
{
|
||||
int length = s.Length + 1;
|
||||
IntPtr ctm = AllocCoTaskMem (length);
|
||||
|
||||
byte[] asBytes = new byte[length];
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
asBytes[i] = (byte)s[i];
|
||||
asBytes[s.Length] = 0;
|
||||
|
||||
copy_to_unmanaged (asBytes, 0, ctm, length);
|
||||
return ctm;
|
||||
return StringToAllocatedMemoryUTF8 (s);
|
||||
}
|
||||
|
||||
public static IntPtr StringToCoTaskMemAuto (string s)
|
||||
@@ -1094,6 +1100,29 @@ namespace System.Runtime.InteropServices
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
public extern static IntPtr StringToHGlobalAnsi (string s);
|
||||
|
||||
unsafe public static IntPtr StringToAllocatedMemoryUTF8(String s)
|
||||
{
|
||||
const int MAX_UTF8_CHAR_SIZE = 3;
|
||||
if (s == null)
|
||||
return IntPtr.Zero;
|
||||
|
||||
int nb = (s.Length + 1) * MAX_UTF8_CHAR_SIZE;
|
||||
|
||||
// Overflow checking
|
||||
if (nb < s.Length)
|
||||
throw new ArgumentOutOfRangeException("s");
|
||||
|
||||
IntPtr pMem = AllocCoTaskMemSize(new UIntPtr((uint)nb +1));
|
||||
|
||||
if (pMem == IntPtr.Zero)
|
||||
throw new OutOfMemoryException();
|
||||
|
||||
byte* pbMem = (byte*)pMem;
|
||||
int nbWritten = s.GetBytesFromEncoding(pbMem, nb, Encoding.UTF8);
|
||||
pbMem[nbWritten] = 0;
|
||||
return pMem;
|
||||
}
|
||||
|
||||
public static IntPtr StringToHGlobalAuto (string s)
|
||||
{
|
||||
return SystemDefaultCharSize == 2
|
||||
@@ -1426,10 +1455,10 @@ namespace System.Runtime.InteropServices
|
||||
const int COR_E_TARGET = unchecked ((int)0x80131603L);
|
||||
const int COR_E_TARGETINVOCATION = unchecked ((int)0x80131604L);
|
||||
const int COR_E_TARGETPARAMCOUNT = unchecked ((int)0x8002000EL);
|
||||
const int COR_E_THREADABORTED = unchecked ((int)0x80131530L);
|
||||
//const int COR_E_THREADABORTED = unchecked ((int)0x80131530L);
|
||||
const int COR_E_THREADINTERRUPTED = unchecked ((int)0x80131519L);
|
||||
const int COR_E_THREADSTATE = unchecked ((int)0x80131520L);
|
||||
const int COR_E_THREADSTOP = unchecked ((int)0x80131521L);
|
||||
//const int COR_E_THREADSTOP = unchecked ((int)0x80131521L);
|
||||
const int COR_E_TYPEINITIALIZATION = unchecked ((int)0x80131534L);
|
||||
const int COR_E_VERIFICATION = unchecked ((int)0x8013150DL);
|
||||
//const int COR_E_WEAKREFERENCE = unchecked ((int)?);
|
||||
@@ -1722,5 +1751,45 @@ namespace System.Runtime.InteropServices
|
||||
internal static void SetLastWin32Error (int error)
|
||||
{
|
||||
}
|
||||
|
||||
#if FEATURE_COMINTEROP || MONO_COM
|
||||
// Copied from referencesource/mscorlib/system/runtime/interopservices/marshal.cs
|
||||
//====================================================================
|
||||
// return the raw IUnknown* for a COM Object not related to current
|
||||
// context
|
||||
// Does not call AddRef
|
||||
//====================================================================
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal static extern IntPtr /* IUnknown* */ GetRawIUnknownForComObjectNoAddRef(Object o);
|
||||
|
||||
// Copied from referencesource/mscorlib/system/runtime/interopservices/marshal.cs
|
||||
//====================================================================
|
||||
// Converts the CLR exception to an HRESULT. This function also sets
|
||||
// up an IErrorInfo for the exception.
|
||||
// This function is only used in WinRT and converts ObjectDisposedException
|
||||
// to RO_E_CLOSED
|
||||
//====================================================================
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal static extern int GetHRForException_WinRT(Exception e);
|
||||
|
||||
// Copied from referencesource/mscorlib/system/runtime/interopservices/marshal.cs
|
||||
//========================================================================
|
||||
// Create activation factory and wraps it with a unique RCW
|
||||
//========================================================================
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
internal static extern object GetNativeActivationFactory(Type type);
|
||||
#else
|
||||
internal static IntPtr /* IUnknown* */ GetRawIUnknownForComObjectNoAddRef(Object o) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
internal static int GetHRForException_WinRT(Exception e) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
internal static object GetNativeActivationFactory(Type type) {
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user