4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/** @file
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This file defines the macro setjmp, and declares the function longjmp
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync and the type jmp_buf, for bypassing the normal function call and return discipline.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync This program and the accompanying materials are licensed and made available under
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the terms and conditions of the BSD License that accompanies this distribution.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync The full text of the license may be found at
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync http://opensource.org/licenses/bsd-license.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync**/
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#ifndef _SETJMP_H
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#define _SETJMP_H
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#include <Library/BaseLib.h>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#include <sys/EfiCdefs.h>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/** jmp_buf is an array type suitable for holding the information needed to
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync restore a calling environment. The environment of a call to the setjmp
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync macro consists of information sufficient for a call to the longjmp function
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync to return execution to the correct block and invocation of that block, were
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync it called recursively. It does not include the state of the floating-point
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync status flags, of open files, or of any other component of the abstract
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync machine.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync**/
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsynctypedef BASE_LIBRARY_JUMP_BUFFER jmp_buf[1];
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/** The setjmp macro saves its calling environment in its jmp_buf argument for
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync later use by the longjmp function.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync The Standard does not specify whether setjmp is a macro or an identifier
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync declared with external linkage. If a macro definition is suppressed in
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync order to access an actual function, or a program defines an external
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync identifier with the name setjmp, the behavior is undefined by the Standard.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in,out] env A jmp_buf type object into which
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the current environment is stored.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return If the return is from a direct invocation, the setjmp macro
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync returns the value zero. If the return is from a call to the longjmp
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync function, the setjmp macro returns a nonzero value based upon the value
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync of the second argument to the longjmp function.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync**/
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#define setjmp(env) (INTN)SetJump((env))
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/** The longjmp function restores the environment saved by the most recent
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync invocation of the setjmp macro in the same invocation of the program with
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the corresponding jmp_buf argument. If there has been no such invocation,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync or if the function containing the invocation of the setjmp macro has
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync terminated execution in the interim, or if the invocation of the setjmp
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync macro was within the scope of an identifier with variably modified type and
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync execution has left that scope in the interim, the behavior is undefined.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] env The jump buffer containing the environment to be returned to.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param[in] val A non-zero value to be returned from setjmp.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return After longjmp is completed, program execution continues as if the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync corresponding invocation of the setjmp macro had just returned the value
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync specified by val. The longjmp function cannot cause the setjmp macro to
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync return the value 0; if val is 0, the setjmp macro returns the value 1.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync**/
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsyncextern void longjmp(jmp_buf env, int val);
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync#endif /* _SETJMP_H */