98 lines · 1.8 KB · Text
RawDownload
.TH SETJMP 2.SH NAMEsetjmp, longjmp, notejmp \- non-local goto.SH SYNOPSIS.B #include <u.h>.br.B #include <libc.h>.PP.ta \w'\fLvoid 'u.Bint	setjmp(jmp_buf env).PP.Bvoid	longjmp(jmp_buf env, int val).PP.Bvoid	notejmp(void *uregs, jmp_buf env, int val).SH DESCRIPTIONThese routines are useful for dealing with errorsand interrupts encountered ina low-level subroutine of a program..PP.I Setjmpsaves its stack environment in.I envfor later use by.IR longjmp .It returns value 0..PP.I Longjmprestores the environment saved by the last call of.IR setjmp .It then causes execution tocontinue as if the call of.I setjmphad just returned with value.IR val .The invoker of.I setjmpmust not itself have returned in the interim.All accessible data have values as of the time.I longjmpwas called..PP.I Notejmpis the same as.I longjmpexcept that it is to be called from within a note handler (see.IR notify (2)).The.I uregsargument should be the first argument passed to the note handler..PP.I Setjmpand.I longjmpcan also be used to switch stacks.Several macros are defined in.B /$objtype/include/u.hthat can be used to build.B jmp_bufsby hand.  The following code establishes a.B jmp_buf.i labelthat may be called by.I longjmpto begin execution in a function.BR fwith 1024 bytes of stack:.IP.EX#include <u.h>#include <libc.h> jmp_buf label;#define NSTACK 1024char stack[NSTACK]; voidsetlabel(void){	label[JMPBUFPC] = ((ulong)f+JMPBUFDPC);	/* -2 leaves room for old pc and new pc in frame */	label[JMPBUFSP] =	        (ulong)(&stack[NSTACK-2*sizeof(ulong*)]);}.EE.SH SOURCE.B /sys/src/libc/$objtype/setjmp.s.br.B /sys/src/libc/$objtype/notejmp.c.SH SEE ALSO.IR notify (2).SH BUGS.PP.I Notejmpcannot recover from an address trap or bus error (page fault) on the 680x0architectures.