// Copyright (C) 2026 SharpEmu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later namespace SharpEmu.HLE.Host; /// /// Raw host thread and native-TLS primitives for the execution engine. Guest /// code must run on threads the CLR did not create (no managed frames below /// guest frames), so thread creation takes a native entry point and is not /// expressible with managed threads. /// public interface IHostThreading { /// Allocates a native TLS slot; returns on failure. uint AllocateTlsSlot(); bool FreeTlsSlot(uint slot); bool SetTlsValue(uint slot, nint value); nint GetTlsValue(uint slot); uint CurrentThreadId { get; } bool TrySetCurrentThreadAffinity(nuint affinityMask); /// /// Asks the OS for ~1 ms timed-wait granularity for the life of the process /// (idempotent; best-effort). No-op on platforms whose default is already fine. /// void RequestTimerResolution(); /// /// Creates a raw OS thread executing native code at with /// of reserved (not committed) stack. /// Returns the thread handle, or 0 on failure. /// nint CreateNativeThread(nint entry, nint parameter, nuint stackReserveBytes, out uint threadId); /// Waits for the thread to exit; true when it did within the timeout. bool WaitForThreadExit(nint threadHandle, uint timeoutMilliseconds); void CloseThreadHandle(nint threadHandle); /// /// Suspends the thread, snapshots its general-purpose registers, and resumes it — /// one indivisible operation (diagnostics only). The caller must not pass the /// current thread. Returns false if the thread cannot be opened or suspended. /// bool TryCaptureThreadRegisters(uint threadId, out HostCapturedRegisters registers); }