8.3 Run-Time Generated Code

Code generated at run time is important for applications that include:

To maintain stack traceability and to support exception handling for code that is generated at run time, procedure descriptors must be provided for that code. Such procedure descriptors must describe correctly the characteristics of the code and the environment within which that code executes.

Before run-time generated code can be executed, the following system library function must be called to activate its corresponding procedure descriptors:

RtlAddFunctionTable( FunctionTable, EntryCount )

Arguments

FunctionTable  

Specifies the address of an array of procedure descriptors, where each element is of type RUNTIME_FUNCTION.

EntryCount  

Specifies the number of procedure descriptors in the array.

Function value

Success  

TRUE (=1) indicates the function completed successfully; FALSE (=0) indicates the function did not finish successfully.

Remarks

A function table must not be modified in any way while the table is active; if any changes are required, the table must be deactivated (using RtlDeleteFunctionTable(), see below), modified, and then reactivated using RtlAddFunctionTable().

Note that active dynamic procedure descriptors are included in the searches performed by RtlLookupFunctionEntry() or RtlLookupDirectFunctionEntry().

When procedure information is no longer valid or the code will not be executed again, the following system library function should be called to deactivate the procedure descriptor information:

RtlDeleteFunctionTable( FunctionTable )

Arguments

FunctionTable  

Specifies the address of an array of procedure descriptors that was passed in a previous call to RtlAddFunctionTable().

Function Value

Success  

TRUE (=1) indicates the function completed successfully; FALSE (=0) indicates the function did not complete successfully.

Steps for Run-Time Generation of Code

The following steps show how run-time code should be constructed and destroyed:

  1. Allocate memory for the code and procedure descriptor(s).

  2. Write the code and procedure descriptor(s) to memory.

  3. Call RtlAddFunctionTable() to activate the function table.

    Note   The execution environment may analyze a function table when it is made active and cache certain summary information to facilitate later searching. For example, a table that is sorted in increasing order by its BeginAddress field might be later searched using a binary rather than a linear search.

  4. Invoke an IMB (instruction memory barrier) operation as required by the Alpha architecture.

  5. Execute the code.

  6. Call RtlDeleteFunctionTable() to deactivate the function table.

  7. Deallocate the memory containing the code and procedure descriptor(s).