uJcontext: A drop-in replacement for the SYSV set/get/makecontext routines Orion Sky Lawlor, olawlor@acm.org, 2004/2/13 (Public Domain) SYSV Unix includes a few nice routines for manipulating the processor's "context" (registers, stack pointer, and program counter). These routines include: - getcontext: Save the processor's registers. - setcontext: Restore the processor's registers. - swapcontext: Save and restore registers (context switch). - makecontext: Set up a new function in an existing context. (See uJcontext.h or the man pages for details on these routines.) Many versions of Unix now include these routines; but some older versions of Unix, and Microsoft Windows, do not include these routines by default, which makes it difficult to write a user-level threads package. To run on older systems, I developed these versions of the SYSV context routines. Underneath, they call setjmp and longjmp, with a tiny bit of assembly to change the stack pointer. The routines have been used on several machines, including Windows, Linux on x86 and PowerPC, and seem to work and perform well. *All* the routine names, structure names, etc. come straight from the SYSV man pages; I've added "J" (for setjmp/longjmp) to the names so they will never conflict with the official versions. This code was originally developed to support Charm++ threads on IBM's Blue Gene machine.