1 / 9

C++ Exception Handling for IA-64 Unix

C++ Exception Handling for IA-64 Unix . By Priti Shrivastav. C++ EH Overview. C++ EH uses static model to avoid runtime overhead for functions with try/throw/catch statements. Destructor thunks are separate functions.

reuel
Download Presentation

C++ Exception Handling for IA-64 Unix

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. C++ Exception Handling for IA-64 Unix By Priti Shrivastav Intel Confidential

  2. C++ EH Overview • C++ EH uses static model to avoid runtime overhead for functions with try/throw/catch statements. • Destructor thunks are separate functions. • Try and Catch blocks are generated inline within the function’s body. • Three tables are generated by the compiler backend for each routine and for each catch routine. • Function Table • Try region Table ( C++ EH tables ) • Unwind descriptors table Intel Confidential

  3. Compiler and C++ EH Runtime • Catch blocks stay mainline code. • They need to be separate entry points. • Runtime will allocate exception objects on the regular heap. • At start-up runtime will pre-allocate enough space to process one out-of-memory exception. • Runtime allocates the object on heap before branching to catch block. Runtime will pass in r8 the destructor thunk which frees the object to catch. Catch will call the destructor thunk before leaving the catch block. If the object to catch is passed by value, two copies of the objects will be allocated by the runtime and the destructor thunk will have to know to free both. Intel Confidential

  4. Function,Try Region and Unwind Tables • Runtime function table is created for every executable image. • A function table entry is created for every function. • typedef struct _RUNTIME_FUNCTION { ULONGLONG BeginAddress; ULONGLONG EndAddress; ULONGLONG UnwindInfo; // unwind information block } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION; Intel Confidential

  5. Function,Try Region and Unwind Tables (Continued) • The unwindinfo field points to a structure which contains the unwind information for the function • The Unwind table • typedef struct_UNWIND_INFO{ USHORT version; USHORT Flags; // try/except or try/finally indicator UINT DataLength; // length of the unwind descriptors UCHAR Descriptors[]; // unwind descriptors PEXCEPTION_ROUTINE ExceptionHandler; // personality routine TRY_REGION_TABLE TryRegionInfo; // Try Region Table CLEANUP_TABLE ObjectCleanupInfo; // Object Cleanup Table } UNWIND_INFO, *PUNWIND_INFO; Intel Confidential

  6. Function,Try Region and Unwind Tables (Continued) • The TryRegionInfopoints to the try region table whose entries define the try regions in the function. • The table is used by the C++ exception handler to determine the active regions in the function at the time of exception. • The entries for nested scopes are PC-mapped and are ordered from inner to outer scopes. • The try region table • typedef struct _TRY_REGION_TABLE{ UINT NumberOfTryEntries; struct { UINT BeginAddress; // begin of a try region UINT EndAddress; // next bundle after the end of try UINT CatchHandlerInfo; // catch address table } TryRegionTableEntry[ ]; } TRY_REGION_TABLE, *PTRY_REGION_TABLE; Intel Confidential

  7. Function,Try Region and Unwind Tables (Continued) • The ObjectCleanupInfopoints to the object cleanup table whose entries define the cleanup action required in the function. • The table is used by the C++ exception handler to determine the active cleanup regions in the function at the time of exception. • The entries for nested scopes are PC-mapped and are in reverse order of creation. • The object cleanup table • typedef struct _OBJ_CLEANUP_TABLE{ UINT NumberOfCleanupEntries; struct { UINT BeginAddress; // begin of a cleanup region UINT EndAddress; // next bundle after the end of region UINT CleanupFunctionAddress; // destructor ’s address } ObjectCleanupEntry[ ]; } CLEANUP_TABLE, *PCLEAUP_TABLE; Intel Confidential

  8. Unwind support in EM compiler • Unwind descriptor region header records are created for prolog,body and epilog regions • Descriptors for updating special and preserved registers in prolog regions are generated. • Unwind mechanism handles shrink-wrap regions • In case of multiple prologs, either a matching epilog region header record for each prolog is created or epilog region header records specify the number of prolog regions to pop. • Each region header record specifies region length which helps determine which are the active regions for a given IP. • All the spill code for saving the preserved registers must be in the prolog region. For this post-pass scheduling must be prevented for the prolog. • Previous sp value is saved in a stacked register for variable size frames. Intel Confidential

  9. IA-64 Unwind Scheme Call unwind (target sp, target bsp, target IP) Unwind to the previous call frame Lookup Funtion Table Entry Unwinder Process descriptors to set the call frame (sp,bsp) Unwinder No Yes Resume execution at the target IP Personality Routine Cleanup the objects Target Frame? Intel Confidential

More Related