C Exception Handling for IA64 Unix By Priti
C++ Exception Handling for IA-64 Unix By Priti Shrivastav intel 2/26/2021 R Microcomputer Software Labs Intel Confidential 1
C++ EH Overview u u 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 2/26/2021 R Microcomputer Software Labs Intel Confidential 2
Compiler and C++ EH Runtime u Catch blocks stay mainline code. – They need to be separate entry points. – Runtime will allocate exception objects on the regular heap. v v 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 r 8 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 2/26/2021 R Microcomputer Software Labs Intel Confidential 3
Function, Try Region and Unwind Tables u Runtime function table is created for every executable image. – A function table entry is created for every function. v typedef struct _RUNTIME_FUNCTION { ULONG Begin. Address; ULONG End. Address; ULONG Unwind. Info; // unwind information block } RUNTIME_FUNCTION, *PRUNTIME_FUNCTION; intel 2/26/2021 R Microcomputer Software Labs Intel Confidential 4
Function, Try Region and Unwind Tables (Continued) u The unwindinfo field points to a structure which contains the unwind information for the function – The Unwind table v typedef struct _UNWIND_INFO { USHORT version; USHORT Flags; // try/except or try/finally indicator UINT Data. Length; // length of the unwind descriptors UCHAR Descriptors[]; // unwind descriptors PEXCEPTION_ROUTINE Exception. Handler; // personality routine TRY_REGION_TABLE Try. Region. Info; // Try Region Table CLEANUP_TABLE Object. Cleanup. Info; // Object Cleanup Table } UNWIND_INFO, *PUNWIND_INFO; intel 2/26/2021 R Microcomputer Software Labs Intel Confidential 5
Function, Try Region and Unwind Tables (Continued) u The Try. Region. Info points 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 v typedef struct _TRY_REGION_TABLE { UINT Number. Of. Try. Entries; struct { UINT Begin. Address; UINT End. Address; UINT Catch. Handler. Info; } Try. Region. Table. Entry[ ]; // begin of a try region // next bundle after the end of try // catch address table } TRY_REGION_TABLE, *PTRY_REGION_TABLE; intel 2/26/2021 R Microcomputer Software Labs Intel Confidential 6
Function, Try Region and Unwind Tables (Continued) u The Object. Cleanup. Info points 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 v typedef struct _OBJ_CLEANUP_TABLE { UINT Number. Of. Cleanup. Entries; struct { UINT Begin. Address; // begin of a cleanup region UINT End. Address; // next bundle after the end of region UINT Cleanup. Function. Address; // destructor ’s address } Object. Cleanup. Entry[ ]; } CLEANUP_TABLE, *PCLEAUP_TABLE; intel 2/26/2021 R Microcomputer Software Labs Intel Confidential 7
Unwind support in EM compiler u u u 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 2/26/2021 R Microcomputer Software Labs Intel Confidential 8
IA-64 Unwind Scheme Call unwind (target sp, target bsp, target IP) Lookup Funtion Table Entry Unwinder Personality Routine Process descriptors to set the call frame (sp, bsp) Cleanup the objects intel 2/26/2021 Unwind to the previous call frame Unwinder No Target Frame? Yes Resume execution at the target IP R Microcomputer Software Labs Intel Confidential 9
- Slides: 9