egametang/ET · critical · NotSupportedException

Unsupported runtime

Error message

Unsupported runtime

What it means

Thrown in HookUtils' static constructor (non-OSX build) when typeof(Environment).GetProperty("SystemPageSize") returns null. The hooking subsystem needs the system page size to compute page-aligned addresses for mprotect/VirtualProtect calls. SystemPageSize was added in .NET Framework 4.0 / Mono 2.x; if the runtime is too old or stripped, the property is absent and hooking cannot proceed.

Source

Thrown at Packages/cn.etetet.hybridclr/Scripts/Editor/Share/3rds/UnityHook/HookUtils.cs:23

using System.Runtime.InteropServices;
using System.Text;
using UnityEngine;

namespace MonoHook
{
    public static unsafe class HookUtils
    {
        [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        delegate void DelegateFlushICache(void* code, int size); // delegate * unmanaged[Cdecl] <void, byte, uint> native_flush_cache_fun_ptr; // unsupported at C# 8.0

        static DelegateFlushICache flush_icache;
        private static readonly long _Pagesize;
        
        static HookUtils()
        {
            PropertyInfo p_SystemPageSize = typeof(Environment).GetProperty("SystemPageSize");
            if (p_SystemPageSize == null)
                throw new NotSupportedException("Unsupported runtime");
            _Pagesize = (int)p_SystemPageSize.GetValue(null, new object[0]);
            SetupFlushICacheFunc();
        }

        public static void MemCpy(void* pDst, void* pSrc, int len)
        {
            byte* pDst_ = (byte*)pDst;
            byte* pSrc_ = (byte*)pSrc;

            for (int i = 0; i < len; i++)
                *pDst_++ = *pSrc_++;
        }

        public static void MemCpy_Jit(void* pDst, byte[] src)
        {
            fixed (void* p = &src[0])
            {
                MemCpy(pDst, p, src.Length);

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Upgrade Unity to a version that ships a Mono runtime with Environment.SystemPageSize (most Unity 2018+ versions have it).
  2. If you cannot upgrade, fork HookUtils to obtain the page size via an alternative: P/Invoke sysconf(_SC_PAGESIZE) on POSIX or GetSystemInfo on Windows.
  3. Verify that the Mono runtime is not corrupted or stripped — reinstall Unity if necessary.
  4. Disable the method-hooking feature if it is optional for your workflow and you cannot resolve the runtime issue.

Example fix

// before
PropertyInfo p = typeof(Environment).GetProperty("SystemPageSize");
if (p == null) throw new NotSupportedException("Unsupported runtime");
_Pagesize = (int)p.GetValue(null);

// after — fallback to sysconf on POSIX
PropertyInfo p = typeof(Environment).GetProperty("SystemPageSize");
if (p != null)
    _Pagesize = (int)p.GetValue(null);
else
    _Pagesize = sysconf(_SC_PAGESIZE); // P/Invoke fallback
Defensive patterns

Strategy: validation

Validate before calling

// Check runtime compatibility before triggering the static constructor
PropertyInfo prop = typeof(Environment).GetProperty("SystemPageSize");
if (prop == null)
{
    Debug.LogError("This runtime does not support Environment.SystemPageSize. " +
        "Method hooking requires .NET Framework 4.0+ or Mono 2.x+. Upgrade Unity or Mono.");
    return;
}

Type guard

static bool IsRuntimeSupported()
{
    return typeof(Environment).GetProperty("SystemPageSize") != null;
}

Try / catch

try
{
    // Trigger static constructor by accessing any HookUtils member
    HookUtils.SetAddrFlagsToRWX(ptr, size);
}
catch (NotSupportedException ex) when (ex.Message == "Unsupported runtime")
{
    Debug.LogError("HookUtils requires a runtime with Environment.SystemPageSize. " +
        "Upgrade Unity or provide a patched HookUtils with a sysconf fallback.");
}

Prevention

When it happens

Trigger: The static constructor runs the first time any HookUtils member is accessed. If the current Mono or .NET runtime does not expose Environment.SystemPageSize, the constructor throws NotSupportedException, preventing the entire hooking subsystem from initializing.

Common situations: Running on a very old or custom Mono runtime bundled with an older Unity version; running on a stripped IL2CPP runtime where reflection on System.Environment is limited; an exotic platform whose runtime lacks the property; Unity version downgrade to one with an older Mono.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/fddb31feef6cce3d. Report an issue: GitHub.