XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESystem

【Rust】XFE系统,基于Rust和汇编

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Runtime.InteropServices;
namespace XFESystem.NativeKernel;

public static unsafe partial class Kernel
{
    static uint _runtimeReports;
    static int _runtimeNextStage;
    static bool _runtimeReportInvalid;
    [UnmanagedCallersOnly(EntryPoint = "xfe_runtime_probe_report")]
    public static void RuntimeProbeReport(int stage, long value)
    {
        Serial.Write("XFE_DOTNET_PROBE_REPORT stage="); Serial.Number((ulong)(uint)stage);
        Serial.Write(" value="); Serial.Number((ulong)value); Serial.Line("");
        if (stage == _runtimeNextStage && stage >= 1 && stage <= 6 &&
            (stage == 1 ? value > 0 : value == 1))
        {
            _runtimeReports |= 1u << (stage - 1);
            _runtimeNextStage++;
        }
        else _runtimeReportInvalid = true;
    }

#if XFE_DOTNET_RUNTIME
    [DllImport("xfe_native", EntryPoint = "xfe_kernel_run_runtime")]
    static extern int RunRuntime();
    static partial void OnKernelReady()
    {
        _runtimeReports = 0; _runtimeReportInvalid = false; _runtimeNextStage = 1;
        Serial.Line("XFE_DOTNET_RUNTIME_START");
        int status = RunRuntime();
        Serial.Write("XFE_DOTNET_RUNTIME_RETURN status="); Serial.Number((ulong)(uint)status); Serial.Line("");
        if (status != 0 || _runtimeReportInvalid || _runtimeReports != 63) Fail("DOTNET_PROBE_INCOMPLETE");
        Serial.Line("XFE_DOTNET_RUNTIME_PROBE_OK GC CWT weak finalizer workers Monitor TLS compacting mutator roots join EH");
    }
#endif
}