Lines Matching refs:code
10 do such @dfn{non-local exits} using the @code{setjmp} and @code{longjmp}
38 their associated cleanup code entirely. Alternatively, you could use a
49 @code{setjmp}. This function saves information about the execution
50 environment in which the call to @code{setjmp} appears in an object of
51 type @code{jmp_buf}. Execution of the program continues normally after
52 the call to @code{setjmp}, but if an exit is later made to this return
53 point by calling @code{longjmp} with the corresponding @w{@code{jmp_buf}}
54 object, control is transferred back to the point where @code{setjmp} was
55 called. The return value from @code{setjmp} is used to distinguish
57 @code{longjmp}, so calls to @code{setjmp} usually appear in an @samp{if}
66 The function @code{abort_to_main_loop} causes an immediate transfer of
70 The flow of control inside the @code{main} function may appear a little
72 @code{setjmp}. A normal call to @code{setjmp} returns zero, so the
74 @code{abort_to_main_loop} is called somewhere within the execution of
75 @code{do_command}, then it actually appears as if the @emph{same} call
76 to @code{setjmp} in @code{main} were returning a second time with a value
77 of @code{-1}.
80 So, the general pattern for using @code{setjmp} looks something like:
101 Objects of type @code{jmp_buf} hold the state information to
102 be restored by a non-local exit. The contents of a @code{jmp_buf}
112 When called normally, @code{setjmp} stores information about the
114 @code{longjmp} is later used to perform a non-local exit to this
115 @var{state}, @code{setjmp} returns a nonzero value.
135 @var{state}, and continues execution from the call to @code{setjmp} that
136 established that return point. Returning from @code{setjmp} by means of
137 @code{longjmp} returns the @var{value} argument that was passed to
138 @code{longjmp}, rather than @code{0}. (But if @var{value} is given as
139 @code{0}, @code{setjmp} returns @code{1}).
143 @code{setjmp} and @code{longjmp}. Most of these restrictions are
148 The @code{setjmp} function is actually a macro without an actual
150 its address. In addition, calls to @code{setjmp} are safe in only the
172 that called @code{setjmp} to establish them. If you @code{longjmp} to
176 You should use a nonzero @var{value} argument to @code{longjmp}. While
177 @code{longjmp} refuses to pass back a zero argument as the return value
178 from @code{setjmp}, this is intended as a safety net against accidental
182 whatever values they had at the time @code{longjmp} was called. The
184 function containing the @code{setjmp} call that have been changed since
185 the call to @code{setjmp} are indeterminate, unless you have declared
186 them @code{volatile}.
191 In BSD Unix systems, @code{setjmp} and @code{longjmp} also save and
193 the POSIX.1 standard requires @code{setjmp} and @code{longjmp} not to
195 functions (@code{sigsetjmp} and @code{siglongjmp}) to get the BSD
198 The behavior of @code{setjmp} and @code{longjmp} in @theglibc{} is
209 This is similar to @code{jmp_buf}, except that it can also store state
220 This is similar to @code{setjmp}. If @var{savesigs} is nonzero, the set
222 @code{siglongjmp} is later performed with this @var{state}.
229 This is similar to @code{longjmp} except for the type of its @var{state}
230 argument. If the @code{sigsetjmp} call that set this @var{state} used a
231 nonzero @var{savesigs} flag, @code{siglongjmp} also restores the set of
247 Similar to the @code{jmp_buf} and @code{sigjmp_buf} types used for the
248 variables to contain the state of the @code{longjmp} functions the
258 The @code{ucontext_t} type is defined as a structure with at least the
261 @table @code
275 @code{mcontext_t} type is also defined in this header but the definition
291 The @code{getcontext} function initializes the variable pointed to by
295 @code{getcontext} call just returned.
299 @code{uc_stack} field of @var{ucp}, or it may instead be in
300 architecture-specific subfields of the @code{uc_mcontext} field.
302 The function returns @code{0} if successful. Otherwise it returns
303 @code{-1} and sets @code{errno} accordingly.
306 The @code{getcontext} function is similar to @code{setjmp} but it does
307 not provide an indication of whether @code{getcontext} is returning for
312 @code{volatile}.
315 be modified using the @code{makecontext} function. The latter is normally
323 The @var{ucp} parameter passed to @code{makecontext} shall be
324 initialized by a call to @code{getcontext}. The context will be
326 calling the function @code{func} which gets @var{argc} integer arguments
328 @var{argc} parameter in the call to @code{makecontext}.
330 Before the call to this function the @code{uc_stack} and @code{uc_link}
332 @code{uc_stack} element describes the stack which is used for this
336 The @code{uc_link} element of the object pointed to by @var{ucp} should
338 returns or it should be a null pointer. See @code{setcontext} for more
344 allowed to contain code which is executed or not. Data segments and
346 programs would fail. Examples for such code include the calling
354 that the @code{uc_stack} element must be used but the values stored in
355 the elements of the @code{stack_t} value are unclear. @Theglibc{}
356 and most other Unix implementations require the @code{ss_sp} value of
357 the @code{uc_stack} element to point to the base of the memory region
359 @code{ss_size}. There are implementations out there which require
360 @code{ss_sp} to be set to the value the stack pointer will have (which
362 difference makes the @code{makecontext} function hard to use and it
377 The @code{setcontext} function restores the context described by
381 If the context was created by @code{getcontext} execution resumes with
383 @code{getcontext} call just returned.
385 If the context was modified with a call to @code{makecontext} execution
386 continues with the function passed to @code{makecontext} which gets the
388 resumed in the context which was referenced by the @code{uc_link}
389 element of the context structure passed to @code{makecontext} at the
390 time of the call. If @code{uc_link} was a null pointer the application
391 terminates normally with an exit status value of @code{EXIT_SUCCESS}
395 other source then the behaviour of @code{setcontext} is unspecified.
401 The @code{setcontext} function does not return unless an error occurred
402 in which case it returns @code{-1}.
405 The @code{setcontext} function simply replaces the current context with
416 The @code{swapcontext} function is similar to @code{setcontext} but
419 @code{getcontext}. The saved context would resume after the call to
420 @code{swapcontext}.
425 If @code{swapcontext} succeeds the function does not return unless the
427 @code{makecontext}. The return value in this case is @code{0}. If the
428 function fails it returns @code{-1} and sets @code{errno} accordingly.
434 replacement for @code{setjmp} and @code{longjmp}. The context contains
466 require a lot of code) to leave the function with an error value which
472 Something which is harder to implement with @code{setjmp} and
473 @code{longjmp} is to switch temporarily to a different execution path
482 to call every once in a while @code{swapcontext} to continue running a
485 @code{setcontext} if the signal was delivered during code that was not
488 are executed is a safer approach. Since @code{swapcontext} is saving the
490 in the code. Execution will always resume where it was left.