You've already forked linux-packaging-mono
Imported Upstream version 4.8.0.309
Former-commit-id: 5f9c6ae75f295e057a7d2971f3a6df4656fa8850
This commit is contained in:
parent
ee1447783b
commit
94b2861243
@@ -31,7 +31,7 @@ using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Mono {
|
||||
|
||||
#if MOBILE
|
||||
#if MOBILE || XAMMAC_4_5
|
||||
public
|
||||
#endif
|
||||
static class Runtime
|
||||
@@ -40,16 +40,31 @@ namespace Mono {
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
private static extern void mono_runtime_install_handlers ();
|
||||
|
||||
static internal void InstallSignalHandlers ()
|
||||
#if MOBILE || XAMMAC_4_5
|
||||
public
|
||||
#else
|
||||
internal
|
||||
#endif
|
||||
static void InstallSignalHandlers ()
|
||||
{
|
||||
mono_runtime_install_handlers ();
|
||||
}
|
||||
|
||||
#if MOBILE || XAMMAC_4_5
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
static extern void mono_runtime_cleanup_handlers ();
|
||||
|
||||
public static void RemoveSignalHandlers ()
|
||||
{
|
||||
mono_runtime_cleanup_handlers ();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Should not be removed intended for external use
|
||||
// Safe to be called using reflection
|
||||
// Format is undefined only for use as a string for reporting
|
||||
[MethodImplAttribute (MethodImplOptions.InternalCall)]
|
||||
#if MOBILE
|
||||
#if MOBILE || XAMMAC_4_5
|
||||
public
|
||||
#else
|
||||
internal
|
||||
|
||||
274
mcs/class/corlib/Mono/RuntimeHandles.cs
Normal file
274
mcs/class/corlib/Mono/RuntimeHandles.cs
Normal file
@@ -0,0 +1,274 @@
|
||||
//
|
||||
// Wrapper handles for Mono Runtime internal structs
|
||||
//
|
||||
// Authors:
|
||||
// Aleksey Kliger <aleksey@xamarin.com>
|
||||
// Rodrigo Kumpera <kumpera@xamarin.com>
|
||||
//
|
||||
// Copyright 2016 Dot net foundation.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Mono {
|
||||
|
||||
internal struct RuntimeClassHandle {
|
||||
unsafe RuntimeStructs.MonoClass* value;
|
||||
|
||||
internal unsafe RuntimeClassHandle (RuntimeStructs.MonoClass* value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
internal unsafe RuntimeClassHandle (IntPtr ptr) {
|
||||
this.value = (RuntimeStructs.MonoClass*) ptr;
|
||||
}
|
||||
|
||||
internal unsafe RuntimeStructs.MonoClass* Value {
|
||||
get { return value; }
|
||||
}
|
||||
|
||||
public override bool Equals (object obj)
|
||||
{
|
||||
if (obj == null || GetType () != obj.GetType ())
|
||||
return false;
|
||||
|
||||
unsafe { return value == ((RuntimeClassHandle)obj).Value; }
|
||||
}
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
unsafe { return ((IntPtr)value).GetHashCode (); }
|
||||
}
|
||||
|
||||
public bool Equals (RuntimeClassHandle handle)
|
||||
{
|
||||
unsafe { return value == handle.Value; }
|
||||
}
|
||||
|
||||
public static bool operator == (RuntimeClassHandle left, Object right)
|
||||
{
|
||||
return (right != null) && (right is RuntimeClassHandle) && left.Equals ((RuntimeClassHandle)right);
|
||||
}
|
||||
|
||||
public static bool operator != (RuntimeClassHandle left, Object right)
|
||||
{
|
||||
return (right == null) || !(right is RuntimeClassHandle) || !left.Equals ((RuntimeClassHandle)right);
|
||||
}
|
||||
|
||||
public static bool operator == (Object left, RuntimeClassHandle right)
|
||||
{
|
||||
return (left != null) && (left is RuntimeClassHandle) && ((RuntimeClassHandle)left).Equals (right);
|
||||
}
|
||||
|
||||
public static bool operator != (Object left, RuntimeClassHandle right)
|
||||
{
|
||||
return (left == null) || !(left is RuntimeClassHandle) || !((RuntimeClassHandle)left).Equals (right);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
internal unsafe extern static IntPtr GetTypeFromClass (RuntimeStructs.MonoClass *klass);
|
||||
|
||||
internal RuntimeTypeHandle GetTypeHandle ()
|
||||
{
|
||||
unsafe { return new RuntimeTypeHandle (GetTypeFromClass (value)); }
|
||||
}
|
||||
}
|
||||
|
||||
internal struct RuntimeRemoteClassHandle {
|
||||
unsafe RuntimeStructs.RemoteClass* value;
|
||||
|
||||
internal unsafe RuntimeRemoteClassHandle (RuntimeStructs.RemoteClass* value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
internal RuntimeClassHandle ProxyClass {
|
||||
get {
|
||||
unsafe {
|
||||
return new RuntimeClassHandle (value->proxy_class);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal struct RuntimeGenericParamInfoHandle {
|
||||
unsafe RuntimeStructs.GenericParamInfo* value;
|
||||
|
||||
internal unsafe RuntimeGenericParamInfoHandle (RuntimeStructs.GenericParamInfo* value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
internal unsafe RuntimeGenericParamInfoHandle (IntPtr ptr)
|
||||
{
|
||||
this.value = (RuntimeStructs.GenericParamInfo*) ptr;
|
||||
}
|
||||
|
||||
|
||||
internal Type[] Constraints { get { return GetConstraints (); } }
|
||||
|
||||
internal GenericParameterAttributes Attributes {
|
||||
get {
|
||||
unsafe {
|
||||
return (GenericParameterAttributes) value->flags;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Type[] GetConstraints () {
|
||||
int n = GetConstraintsCount ();
|
||||
var a = new Type[n];
|
||||
for (int i = 0; i < n; i++) {
|
||||
unsafe {
|
||||
RuntimeClassHandle c = new RuntimeClassHandle (value->constraints[i]);
|
||||
a[i] = Type.GetTypeFromHandle (c.GetTypeHandle ());
|
||||
}
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
int GetConstraintsCount () {
|
||||
int i = 0;
|
||||
unsafe {
|
||||
RuntimeStructs.MonoClass** p = value->constraints;
|
||||
while (p != null && *p != null) {
|
||||
p++; i++;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
internal struct RuntimeEventHandle {
|
||||
IntPtr value;
|
||||
|
||||
internal RuntimeEventHandle (IntPtr v)
|
||||
{
|
||||
value = v;
|
||||
}
|
||||
|
||||
public IntPtr Value {
|
||||
get {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals (object obj)
|
||||
{
|
||||
if (obj == null || GetType () != obj.GetType ())
|
||||
return false;
|
||||
|
||||
return value == ((RuntimeEventHandle)obj).Value;
|
||||
}
|
||||
|
||||
public bool Equals (RuntimeEventHandle handle)
|
||||
{
|
||||
return value == handle.Value;
|
||||
}
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
return value.GetHashCode ();
|
||||
}
|
||||
|
||||
public static bool operator == (RuntimeEventHandle left, RuntimeEventHandle right)
|
||||
{
|
||||
return left.Equals (right);
|
||||
}
|
||||
|
||||
public static bool operator != (RuntimeEventHandle left, RuntimeEventHandle right)
|
||||
{
|
||||
return !left.Equals (right);
|
||||
}
|
||||
}
|
||||
|
||||
internal struct RuntimePropertyHandle {
|
||||
IntPtr value;
|
||||
|
||||
internal RuntimePropertyHandle (IntPtr v)
|
||||
{
|
||||
value = v;
|
||||
}
|
||||
|
||||
public IntPtr Value {
|
||||
get {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals (object obj)
|
||||
{
|
||||
if (obj == null || GetType () != obj.GetType ())
|
||||
return false;
|
||||
|
||||
return value == ((RuntimePropertyHandle)obj).Value;
|
||||
}
|
||||
|
||||
public bool Equals (RuntimePropertyHandle handle)
|
||||
{
|
||||
return value == handle.Value;
|
||||
}
|
||||
|
||||
public override int GetHashCode ()
|
||||
{
|
||||
return value.GetHashCode ();
|
||||
}
|
||||
|
||||
public static bool operator == (RuntimePropertyHandle left, RuntimePropertyHandle right)
|
||||
{
|
||||
return left.Equals (right);
|
||||
}
|
||||
|
||||
public static bool operator != (RuntimePropertyHandle left, RuntimePropertyHandle right)
|
||||
{
|
||||
return !left.Equals (right);
|
||||
}
|
||||
}
|
||||
|
||||
internal struct RuntimeGPtrArrayHandle {
|
||||
unsafe RuntimeStructs.GPtrArray* value;
|
||||
|
||||
internal unsafe RuntimeGPtrArrayHandle (RuntimeStructs.GPtrArray* value)
|
||||
{
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
internal unsafe RuntimeGPtrArrayHandle (IntPtr ptr)
|
||||
{
|
||||
this.value = (RuntimeStructs.GPtrArray*) ptr;
|
||||
}
|
||||
|
||||
internal int Length {
|
||||
get {
|
||||
unsafe {
|
||||
return value->len;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr this[int i] => Lookup (i);
|
||||
|
||||
internal IntPtr Lookup (int i)
|
||||
{
|
||||
if (i >= 0 && i < Length) {
|
||||
unsafe {
|
||||
return value->data[i];
|
||||
}
|
||||
} else
|
||||
throw new IndexOutOfRangeException ();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.InternalCall)]
|
||||
unsafe extern static void GPtrArrayFree (RuntimeStructs.GPtrArray* value);
|
||||
|
||||
internal static void DestroyAndFree (ref RuntimeGPtrArrayHandle h) {
|
||||
unsafe {
|
||||
GPtrArrayFree (h.value);
|
||||
h.value = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
65
mcs/class/corlib/Mono/RuntimeMarshal.cs
Normal file
65
mcs/class/corlib/Mono/RuntimeMarshal.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Mono {
|
||||
internal static class RuntimeMarshal {
|
||||
internal static string PtrToUtf8String (IntPtr ptr)
|
||||
{
|
||||
unsafe {
|
||||
return new String ((sbyte*)ptr);
|
||||
}
|
||||
}
|
||||
|
||||
internal static SafeStringMarshal MarshalString (string str)
|
||||
{
|
||||
return new SafeStringMarshal (str);
|
||||
}
|
||||
|
||||
static int DecodeBlobSize (IntPtr in_ptr, out IntPtr out_ptr)
|
||||
{
|
||||
uint size;
|
||||
unsafe {
|
||||
byte *ptr = (byte*)in_ptr;
|
||||
|
||||
if ((*ptr & 0x80) == 0) {
|
||||
size = (uint)(ptr [0] & 0x7f);
|
||||
ptr++;
|
||||
} else if ((*ptr & 0x40) == 0){
|
||||
size = (uint)(((ptr [0] & 0x3f) << 8) + ptr [1]);
|
||||
ptr += 2;
|
||||
} else {
|
||||
size = (uint)(((ptr [0] & 0x1f) << 24) +
|
||||
(ptr [1] << 16) +
|
||||
(ptr [2] << 8) +
|
||||
ptr [3]);
|
||||
ptr += 4;
|
||||
}
|
||||
out_ptr = (IntPtr)ptr;
|
||||
}
|
||||
|
||||
return (int)size;
|
||||
}
|
||||
|
||||
internal static byte[] DecodeBlobArray (IntPtr ptr)
|
||||
{
|
||||
IntPtr out_ptr;
|
||||
int size = DecodeBlobSize (ptr, out out_ptr);
|
||||
byte[] res = new byte [size];
|
||||
Marshal.Copy (out_ptr, res, 0, size);
|
||||
return res;
|
||||
}
|
||||
|
||||
internal static int AsciHexDigitValue (int c)
|
||||
{
|
||||
if (c >= '0' && c <= '9')
|
||||
return c - '0';
|
||||
if (c >= 'a' && c <= 'f')
|
||||
return c - 'a' + 10;
|
||||
return c - 'A' + 10;
|
||||
}
|
||||
|
||||
[MethodImpl (MethodImplOptions.InternalCall)]
|
||||
internal static extern void FreeAssemblyName (ref MonoAssemblyName name);
|
||||
}
|
||||
}
|
||||
83
mcs/class/corlib/Mono/RuntimeStructs.cs
Normal file
83
mcs/class/corlib/Mono/RuntimeStructs.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// Mono runtime native structs surfaced to managed code.
|
||||
//
|
||||
// Authors:
|
||||
// Aleksey Kliger <aleksey@xamarin.com>
|
||||
// Rodrigo Kumpera <kumpera@xamarin.com>
|
||||
//
|
||||
// Copyright 2016 Dot net foundation.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
#pragma warning disable 169
|
||||
|
||||
namespace Mono {
|
||||
//
|
||||
// Managed representations of mono runtime types
|
||||
//
|
||||
internal static class RuntimeStructs {
|
||||
// class-internals.h MonoRemoteClass
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
internal unsafe struct RemoteClass {
|
||||
internal IntPtr default_vtable;
|
||||
internal IntPtr xdomain_vtable;
|
||||
internal MonoClass* proxy_class;
|
||||
internal IntPtr proxy_class_name;
|
||||
internal uint interface_count;
|
||||
// FIXME: How to represent variable-length array struct member?
|
||||
// MonoClass* interfaces [];
|
||||
}
|
||||
|
||||
internal struct MonoClass {
|
||||
}
|
||||
|
||||
// class-internals.h MonoGenericParamInfo
|
||||
internal unsafe struct GenericParamInfo {
|
||||
internal MonoClass* pklass;
|
||||
internal IntPtr name;
|
||||
internal ushort flags;
|
||||
internal uint token;
|
||||
internal MonoClass** constraints; /* NULL terminated */
|
||||
}
|
||||
|
||||
// glib.h GPtrArray
|
||||
internal unsafe struct GPtrArray {
|
||||
internal IntPtr* data;
|
||||
internal int len;
|
||||
}
|
||||
|
||||
// handle.h HandleStackMark
|
||||
struct HandleStackMark {
|
||||
int size;
|
||||
IntPtr chunk;
|
||||
}
|
||||
|
||||
// mono-error.h MonoError
|
||||
struct MonoError {
|
||||
ushort error_code;
|
||||
ushort hidden_0;
|
||||
IntPtr hidden_1, hidden_2, hidden_3, hidden_4, hidden_5, hidden_6, hidden_7, hidden_8;
|
||||
IntPtr hidden_11, hidden_12, hidden_13, hidden_14, hidden_15, hidden_16, hidden_17, hidden_18;
|
||||
}
|
||||
}
|
||||
|
||||
//Maps to metadata-internals.h:: MonoAssemblyName
|
||||
internal unsafe struct MonoAssemblyName
|
||||
{
|
||||
const int MONO_PUBLIC_KEY_TOKEN_LENGTH = 17;
|
||||
|
||||
internal IntPtr name;
|
||||
internal IntPtr culture;
|
||||
internal IntPtr hash_value;
|
||||
internal IntPtr public_key;
|
||||
internal fixed byte public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
|
||||
internal uint hash_alg;
|
||||
internal uint hash_len;
|
||||
internal uint flags;
|
||||
internal ushort major, minor, build, revision;
|
||||
internal ushort arch;
|
||||
}
|
||||
}
|
||||
38
mcs/class/corlib/Mono/SafeGPtrArrayHandle.cs
Normal file
38
mcs/class/corlib/Mono/SafeGPtrArrayHandle.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// Safe handle class for Mono.RuntimeGPtrArrayHandle
|
||||
//
|
||||
// Authors:
|
||||
// Aleksey Kliger <aleksey@xamarin.com>
|
||||
// Rodrigo Kumpera <kumpera@xamarin.com>
|
||||
//
|
||||
// Copyright 2016 Dot net foundation.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Mono {
|
||||
internal struct SafeGPtrArrayHandle : IDisposable {
|
||||
RuntimeGPtrArrayHandle handle;
|
||||
|
||||
internal SafeGPtrArrayHandle (IntPtr ptr)
|
||||
{
|
||||
handle = new RuntimeGPtrArrayHandle (ptr);
|
||||
}
|
||||
|
||||
public void Dispose () {
|
||||
RuntimeGPtrArrayHandle.DestroyAndFree (ref handle);
|
||||
}
|
||||
|
||||
internal int Length {
|
||||
get {
|
||||
return handle.Length;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr this[int i] => handle[i];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
46
mcs/class/corlib/Mono/SafeStringMarshal.cs
Normal file
46
mcs/class/corlib/Mono/SafeStringMarshal.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// Safe wrapper for a string and its UTF8 encoding
|
||||
//
|
||||
// Authors:
|
||||
// Aleksey Kliger <aleksey@xamarin.com>
|
||||
// Rodrigo Kumpera <kumpera@xamarin.com>
|
||||
//
|
||||
// Copyright 2016 Dot net foundation.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Mono {
|
||||
internal struct SafeStringMarshal : IDisposable {
|
||||
readonly string str;
|
||||
IntPtr marshaled_string;
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
public extern static IntPtr StringToUtf8 (string str);
|
||||
|
||||
[MethodImplAttribute(MethodImplOptions.InternalCall)]
|
||||
public extern static void GFree (IntPtr ptr);
|
||||
|
||||
public SafeStringMarshal (string str) {
|
||||
this.str = str;
|
||||
this.marshaled_string = IntPtr.Zero;
|
||||
}
|
||||
|
||||
public IntPtr Value {
|
||||
get {
|
||||
if (marshaled_string == IntPtr.Zero && str != null)
|
||||
marshaled_string = StringToUtf8 (str);
|
||||
return marshaled_string;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose () {
|
||||
if (marshaled_string != IntPtr.Zero) {
|
||||
GFree (marshaled_string);
|
||||
marshaled_string = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user