Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

setjmp(2) [plan9 man page]

SETJMP(2)							System Calls Manual							 SETJMP(2)

NAME
setjmp, longjmp, notejmp - non-local goto SYNOPSIS
#include <u.h> #include <libc.h> int setjmp(jmp_buf env) void longjmp(jmp_buf env, int val) void notejmp(void *uregs, jump_buf env, int val) DESCRIPTION
These routines are useful for dealing with errors and interrupts encountered in a low-level subroutine of a program. Setjmp saves its stack environment in env for later use by longjmp. It returns value 0. Longjmp restores the environment saved by the last call of setjmp. It then causes execution to continue as if the call of setjmp had just returned with value val. The invoker of setjmp must not itself have returned in the interim. All accessible data have values as of the time longjmp was called. Notejmp is the same as longjmp except that it is to be called from within a note handler (see notify(2)). The uregs argument should be the first argument passed to the note handler. Setjmp and longjmp can also be used to switch stacks. Defined in </$objtype/u.h> are several macros that can be used to build jmp_bufs by hand. The following code establishes a jmp_buf that may be called by longjmp to begin execution in a function f with 1024 bytes of stack: #include <u.h> #include <libc.h> jmp_buf label; #define NSTACK 1024 char stack[NSTACK]; void setlabel(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*)]); } SOURCE
/sys/src/libc/$objtype/setjmp.s /sys/src/libc/$objtype/notejmp.c SEE ALSO
notify(2) BUGS
Notejmp cannot recover from an address trap or bus error (page fault) on the 680x0 architectures. SETJMP(2)

Check Out this Related Man Page

SETJMP(3)						     Library Functions Manual							 SETJMP(3)

NAME
setjmp, longjmp - non-local goto SYNOPSIS
#include <setjmp.h> setjmp(env) jmp_buf env; longjmp(env, val) jmp_buf env; _setjmp(env) jmp_buf env; _longjmp(env, val) jmp_buf env; DESCRIPTION
These routines are useful for dealing with errors and interrupts encountered in a low-level subroutine of a program. Setjmp saves its stack environment in env for later use by longjmp. It returns value 0. Longjmp restores the environment saved by the last call of setjmp. It then returns in such a way that execution continues as if the call of setjmp had just returned the value val to the function that invoked setjmp, which must not itself have returned in the interim. All accessible data have values as of the time longjmp was called. Setjmp and longjmp save and restore the signal mask sigmask(2), while _setjmp and _longjmp manipulate only the C stack and registers. ERRORS
If the contents of the jmp_buf are corrupted, or correspond to an environment that has already returned, longjmp calls the routine longjm- perror. If longjmperror returns the program is aborted. The default version of longjmperror prints the message ``longjmp botch'' to stan- dard error and returns. User programs wishing to exit more gracefully can write their own versions of longjmperror. SEE ALSO
sigvec(2), sigstack(2), signal(3) NOTES (PDP-11) On the PDP-11, longjmperror is called as _ljerr. This difference stems from the limited name size of the PDP-11 that requires all external names to be unique within the first seven characters. However, <setjmp.h> automatically translates longjmperror to ljerror and should be included before any definition longjmperror. The PDP-11 implementation also contains a subtle bug that occurs when a routine containing a setjmp has register variables. The bug some- times causes those variables to be given invalid values when a longjmp is made back to the routine. Register variables should therefore be avoided in routines containing setjmps. And finally, _longjmp may sometimes die fatally. Sorry. 4th Berkeley Distribution January 9, 1986 SETJMP(3)
Man Page