Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

jumps.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1990 Microsoft Corporation 00004 00005 Module Name: 00006 00007 jumps.c 00008 00009 Abstract: 00010 00011 This module implements the C runtime library functions for set jump and 00012 long jump that are compatible with structured exception handling. 00013 00014 Author: 00015 00016 David N. Cutler (davec) 15-Sep-1990 00017 00018 Environment: 00019 00020 Any mode. 00021 00022 Revision History: 00023 00024 Tom Wood 23-Aug-1994 00025 Add stack limit parameters to RtlVirtualUnwind. 00026 00027 --*/ 00028 00029 #include "ntrtlp.h" 00030 #include "setjmp.h" 00031 00032 VOID 00033 longjmp ( 00034 IN jmp_buf JumpBuffer, 00035 IN int ReturnValue 00036 ) 00037 00038 /*++ 00039 00040 Routine Description: 00041 00042 This function executes a long jump operation by virtually unwinding to 00043 the caller of the corresponding call to set jump and then calling unwind 00044 to transfer control to the jump target. 00045 00046 Arguments: 00047 00048 00049 JumpBuffer - Supplies the address of a jump buffer that contains the 00050 virtual frame pointer and target address. 00051 00052 N.B. This is an array of double to force quadword alignment. 00053 00054 ReturnValue - Supplies the value that is to be returned to the caller 00055 of set jump. 00056 00057 Return Value: 00058 00059 None. 00060 00061 --*/ 00062 00063 { 00064 00065 PULONG JumpArray; 00066 00067 // 00068 // If the specified return value is zero, then set it to one. 00069 // 00070 00071 if (ReturnValue == 0) { 00072 ReturnValue = 1; 00073 } 00074 00075 // 00076 // Unwind to the caller of set jump and return the specified value. 00077 // There is no return from unwind. 00078 // 00079 00080 JumpArray = (PULONG)&JumpBuffer[0]; 00081 RtlUnwind((PVOID)JumpArray[0], 00082 (PVOID)JumpArray[1], 00083 NULL, 00084 (PVOID)ReturnValue); 00085 } 00086 00087 int 00088 setjmp ( 00089 IN jmp_buf JumpBuffer 00090 ) 00091 00092 /*++ 00093 00094 Routine Description: 00095 00096 This function performs a set jump operation by capturing the current 00097 context, virtualy unwinding to the caller of set jump, and returns zero 00098 to the caller. 00099 00100 Arguments: 00101 00102 JumpBuffer - Supplies the address of a jump buffer to store the virtual 00103 frame pointer and target address of the caller. 00104 00105 N.B. This is an array of double to force quadword alignment. 00106 00107 Return Value: 00108 00109 A value of zero is returned. 00110 00111 --*/ 00112 00113 { 00114 00115 CONTEXT ContextRecord; 00116 ULONG EstablisherFrame; 00117 PRUNTIME_FUNCTION FunctionEntry; 00118 BOOLEAN InFunction; 00119 PULONG JumpArray; 00120 ULONG NextPc; 00121 00122 // 00123 // Capture the current context, virtually unwind to the caller of set 00124 // jump, and return zero to the caller. 00125 // 00126 00127 JumpArray = (PULONG)&JumpBuffer[0]; 00128 RtlCaptureContext(&ContextRecord); 00129 NextPc = ContextRecord.Lr - 4; 00130 FunctionEntry = RtlLookupFunctionEntry(NextPc); 00131 NextPc = RtlVirtualUnwind(NextPc, 00132 FunctionEntry, 00133 &ContextRecord, 00134 &InFunction, 00135 &EstablisherFrame, 00136 NULL, 00137 0, 00138 0xffffffff); 00139 00140 JumpArray[1] = NextPc + 4; 00141 FunctionEntry = RtlLookupFunctionEntry(NextPc); 00142 NextPc = RtlVirtualUnwind(NextPc, 00143 FunctionEntry, 00144 &ContextRecord, 00145 &InFunction, 00146 &EstablisherFrame, 00147 NULL, 00148 0, 00149 0xffffffff); 00150 00151 JumpArray[0] = EstablisherFrame; 00152 return 0; 00153 }

Generated on Sat May 15 19:40:32 2004 for test by doxygen 1.3.7