This commit is contained in:
2025-03-31 14:55:24 +08:00
parent 613e0f7f61
commit c5ead42ade
207 changed files with 10338 additions and 108 deletions

View File

@@ -0,0 +1,10 @@
namespace HybridCLR
{
public enum HomologousImageMode
{
Consistent, // AOT dll需要跟主工程精确一致即为裁剪后的AO dll
SuperSet, // AOT dll不需要跟主工程精确一致但必须包含裁剪后的AOT dll的所有元数据即为裁剪后dll的超集。推荐使用原始aot dll
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f0351553ad90e74aa586746b5965ded
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,14 @@
{
"name": "HybridCLR.Runtime",
"rootNamespace": "",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 13ba8ce62aa80c74598530029cb2d649
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
namespace HybridCLR
{
public enum LoadImageErrorCode
{
OK = 0,
BAD_IMAGE, // dll 不合法
NOT_IMPLEMENT, // 不支持的元数据特性
AOT_ASSEMBLY_NOT_FIND, // 对应的AOT assembly未找到
HOMOLOGOUS_ONLY_SUPPORT_AOT_ASSEMBLY, // 不能给解释器assembly补充元数据
HOMOLOGOUS_ASSEMBLY_HAS_LOADED, // 已经补充过了,不能再次补充
INVALID_HOMOLOGOUS_MODE, // 非法HomologousImageMode
};
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2c7d5b71981fba643b4c21ed01bcb675
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HybridCLR
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class ReversePInvokeWrapperGenerationAttribute : Attribute
{
public int ReserveWrapperCount { get; }
public ReversePInvokeWrapperGenerationAttribute(int reserveWrapperCount)
{
ReserveWrapperCount = reserveWrapperCount;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f99dd22d9d81b2540b4663b3bcdf0a79
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace HybridCLR
{
public static class RuntimeApi
{
/// <summary>
/// 加载补充元数据assembly
/// </summary>
/// <param name="dllBytes"></param>
/// <returns></returns>
/// <exception cref="NotSupportedException"></exception>
#if UNITY_EDITOR
public static unsafe LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes, HomologousImageMode mode)
{
return LoadImageErrorCode.OK;
}
#else
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes, HomologousImageMode mode);
#endif
/// <summary>
/// 获取解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
/// </summary>
/// <returns></returns>
public static int GetInterpreterThreadObjectStackSize()
{
return GetRuntimeOption(RuntimeOptionId.InterpreterThreadObjectStackSize);
}
/// <summary>
/// 设置解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
/// </summary>
/// <param name="size"></param>
public static void SetInterpreterThreadObjectStackSize(int size)
{
SetRuntimeOption(RuntimeOptionId.InterpreterThreadObjectStackSize, size);
}
/// <summary>
/// 获取解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
/// </summary>
/// <returns></returns>
public static int GetInterpreterThreadFrameStackSize()
{
return GetRuntimeOption(RuntimeOptionId.InterpreterThreadFrameStackSize);
}
/// <summary>
/// 设置解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
/// </summary>
/// <param name="size"></param>
public static void SetInterpreterThreadFrameStackSize(int size)
{
SetRuntimeOption(RuntimeOptionId.InterpreterThreadFrameStackSize, size);
}
#if UNITY_EDITOR
private static readonly Dictionary<RuntimeOptionId, int> s_runtimeOptions = new Dictionary<RuntimeOptionId, int>();
public static void SetRuntimeOption(RuntimeOptionId optionId, int value)
{
s_runtimeOptions[optionId] = value;
}
#else
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern void SetRuntimeOption(RuntimeOptionId optionId, int value);
#endif
#if UNITY_EDITOR
public static int GetRuntimeOption(RuntimeOptionId optionId)
{
if (s_runtimeOptions.TryGetValue(optionId, out var value))
{
return value;
}
return 0;
}
#else
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern int GetRuntimeOption(RuntimeOptionId optionId);
#endif
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0d58bdc22b6d6b54ab6791baf16a0a3d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,9 @@
namespace HybridCLR
{
public enum RuntimeOptionId
{
InterpreterThreadObjectStackSize = 1,
InterpreterThreadFrameStackSize = 2,
ThreadExceptionFlowSize = 3,
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 64be598b47302644a96013c74d945653
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: