Access context by index
Currently, wait handles store pointer to the context they are in. This
pointer is not protected with reference counting, as it is expected that
whenever a context is exited, references to it are cleaned thru
If a bug is present that violates this assumption, it is impossible to
guard against invalid pointer access and a hard to debug memory
Since the structure of contexts is a simple stack, let's reference them
by index instead of by pointer.
As a bonus, one pointer worth of memory is saved for every non-trivial wait handle.
The actual bugs will be fixed by the next 2 diffs that do:
- implement online cycle detection
- do enterContext() atomically and properly handle failure