The kext gave each process's context a number once, counting up from 1, and
never again. A number is the top 24 bits of the context's 64-bit object ids
(RGFX_CONTEXT_OBJ_ID_SHIFT) and of its doorbell page's bind, so the 2^24th open
of a boot carried ids past 64 bits, onto other contexts' ids.
Numbers now run below 2^24, in turn from where the last was taken, wrapping
past the last to 1 and skipping those held. A number is held from its open
until both the device has answered its close OK (no framebuffer started, or a
late answer, counts as well; a refused close keeps it) and its user client is
freed, so no call of the client's, and no create it posted behind its close,
can reach the device once another process takes the number. Where every number
is held, or the 2048 the kext keeps, the open is refused with
kIOReturnNoResources, as when no unit of GPU addresses is free: the bundle
answers that process no Metal device, and a later open takes a number once one
is given back. A live number is never given out twice.
context_numbers_test pins it near the top: the last numbers below 2^24, the
wrap to 1 past those held, a number reused only after both holds drop, and
every number held refused with nothing changed.