Ref, NonNullRef, and Leak() in NeKernel.

Ref, NonNullRef, and Leak()

In NeKernel, Ref is a minimal value container for holding T instances without overhead, ideal for scheduler hot paths where copies kill perf.

  • Ref: Wraps a T by value (construct from T or *T* via deref). Provides -> and * for access; always truthy if constructed.
  • Ref::Leak() / TryLeak(): Returns inner T& for raw access/chaining (e.g., ref.Leak()->Leak()). No RAII post-leak, caller owns the ref. Use for explicit escapes; assumes valid inner state.

Example:

Ref<USER_PROCESS> proc = GetProc(pid);  // Wraps USER_PROCESS value
USER_PROCESS& raw = proc.Leak();        // Expose for manual use (e.g., Status = kRunning)

NonNullRef: Strict wrapper around Ref—rejects nulls at ctor via MUST_PASS; forbids default/null ctors. Enforces non-null chains.

Ties to MP scheduler: Enables leak-free handoffs (e.g., TheCurrentProcess().Leak().ProcessId) without alloc/copy tax.

SOFTWARE: ne_kernel


AUTHOR: Amlal El Mahrouss

Amlal.