2023-09-17 20:58:18 +08:00
|
|
|
using System;
|
2022-09-22 08:56:07 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Reflection;
|
2023-10-09 22:24:35 +08:00
|
|
|
using System.Runtime.CompilerServices;
|
2022-09-22 08:56:07 +08:00
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
namespace HybridCLR
|
|
|
|
{
|
|
|
|
public static class RuntimeApi
|
|
|
|
{
|
2023-10-09 22:24:35 +08:00
|
|
|
#if UNITY_EDITOR
|
|
|
|
private static int s_interpreterThreadObjectStackSize = 128 * 1024;
|
|
|
|
private static int s_interpreterThreadFrameStackSize = 2 * 1024;
|
2022-09-22 08:56:07 +08:00
|
|
|
#endif
|
|
|
|
|
2022-10-08 12:35:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 加载补充元数据assembly
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="dllBytes"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
/// <exception cref="NotSupportedException"></exception>
|
2023-10-09 22:24:35 +08:00
|
|
|
#if UNITY_EDITOR
|
2022-10-26 11:28:49 +08:00
|
|
|
public static unsafe LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes, HomologousImageMode mode)
|
2022-09-28 21:48:09 +08:00
|
|
|
{
|
2022-10-08 12:35:34 +08:00
|
|
|
return LoadImageErrorCode.OK;
|
2023-07-03 22:52:56 +08:00
|
|
|
}
|
|
|
|
#else
|
2023-10-09 22:24:35 +08:00
|
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
|
|
|
public static extern LoadImageErrorCode LoadMetadataForAOTAssembly(byte[] dllBytes, HomologousImageMode mode);
|
2023-07-03 22:52:56 +08:00
|
|
|
#endif
|
2022-11-05 22:22:39 +08:00
|
|
|
|
2022-10-08 12:35:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 获取解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
2023-07-03 22:52:56 +08:00
|
|
|
#if UNITY_EDITOR
|
|
|
|
public static int GetInterpreterThreadObjectStackSize()
|
|
|
|
{
|
2023-10-09 22:24:35 +08:00
|
|
|
return s_interpreterThreadObjectStackSize;
|
2023-07-03 22:52:56 +08:00
|
|
|
}
|
|
|
|
#else
|
2023-10-09 22:24:35 +08:00
|
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
2022-09-22 08:56:07 +08:00
|
|
|
public static extern int GetInterpreterThreadObjectStackSize();
|
2023-07-03 22:52:56 +08:00
|
|
|
#endif
|
2023-10-09 22:24:35 +08:00
|
|
|
|
2022-10-08 12:35:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 设置解释器线程栈的最大StackObject个数(size*8 为最终占用的内存大小)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size"></param>
|
2023-07-03 22:52:56 +08:00
|
|
|
#if UNITY_EDITOR
|
|
|
|
public static void SetInterpreterThreadObjectStackSize(int size)
|
|
|
|
{
|
2023-10-09 22:24:35 +08:00
|
|
|
s_interpreterThreadObjectStackSize = size;
|
2023-07-03 22:52:56 +08:00
|
|
|
}
|
2023-07-07 21:38:38 +08:00
|
|
|
#else
|
2023-10-09 22:24:35 +08:00
|
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
2022-09-22 08:56:07 +08:00
|
|
|
public static extern void SetInterpreterThreadObjectStackSize(int size);
|
2023-07-03 22:52:56 +08:00
|
|
|
#endif
|
2022-10-08 12:35:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 获取解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
|
|
|
|
/// </summary>
|
|
|
|
/// <returns></returns>
|
2023-07-03 22:52:56 +08:00
|
|
|
#if UNITY_EDITOR
|
|
|
|
public static int GetInterpreterThreadFrameStackSize()
|
|
|
|
{
|
2023-10-09 22:24:35 +08:00
|
|
|
return s_interpreterThreadFrameStackSize;
|
2023-07-03 22:52:56 +08:00
|
|
|
}
|
|
|
|
#else
|
2023-10-09 22:24:35 +08:00
|
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
2022-09-22 08:56:07 +08:00
|
|
|
public static extern int GetInterpreterThreadFrameStackSize();
|
2023-07-03 22:52:56 +08:00
|
|
|
#endif
|
|
|
|
|
2022-10-08 12:35:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 设置解释器线程函数帧数量(sizeof(InterpreterFrame)*size 为最终占用的内存大小)
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size"></param>
|
2023-07-03 22:52:56 +08:00
|
|
|
#if UNITY_EDITOR
|
|
|
|
public static void SetInterpreterThreadFrameStackSize(int size)
|
|
|
|
{
|
2023-10-09 22:24:35 +08:00
|
|
|
s_interpreterThreadFrameStackSize = size;
|
2023-07-03 22:52:56 +08:00
|
|
|
}
|
2023-07-07 21:38:38 +08:00
|
|
|
#else
|
2023-10-09 22:24:35 +08:00
|
|
|
[MethodImpl(MethodImplOptions.InternalCall)]
|
2022-09-22 08:56:07 +08:00
|
|
|
public static extern void SetInterpreterThreadFrameStackSize(int size);
|
2023-07-03 22:52:56 +08:00
|
|
|
#endif
|
2022-09-22 08:56:07 +08:00
|
|
|
}
|
|
|
|
}
|