The system scope initialization and termination functions

The __tpf_module_init and __tpf_module_initRC initialization functions and the __tpf_module_term and __tpf_module_termRC termination functions define the system scope initializer.

The __tpf_module_initRC initialization function and the __tpf_module_termRC termination function have return codes.

Use the following prototype to specify the system scope initialization and termination functions in your C language programs:
void __tpf_module_init(void);
void __tpf_module_term(void);
int __tpf_module_initRC(void);
int __tpf_module_termRC(void);
Use the following prototype to specify the system scope initialization and termination functions in your C++ language programs:
extern "C" void __tpf_module_init(void);
extern "C" void __tpf_module_term(void);
extern "C" int __tpf_module_initRC(void);
extern "C" int __tpf_module_termRC(void);

The z/TPF system view of writable data is modified when a CSO is initialized by using the system scope initializer functions. On return from the__tpf_module_init function, the writable data in the CSO is copied to the z/TPF system view of the CSO. The MOVEC system macro updates the writable data in the SVM, which includes the initialized and uninitialized static data sections. To view the contents, use the binary tool readelf

The __tpf_module_term can be used to free up the resources obtained by using the __tpf_module_init function. Before the CSO is removed from memory, the __tpf_module_term function runs a unique process that corresponds to the system scope initialization by handling the termination clean up, such as the release of any system heap storage that was acquired. The __tpf_module_term function runs only if the system scope initialization and termination is successful.

If the system scope initialization is not successful, the __tpf_module_term function is not run and the system heap storage that was acquired can be lost. In this case, the z/TPF system issues an OLDR5270E message and the CSO is removed from memory. If the z/TPF system requires a restart or a catastrophic error occurs, the __tpf_module_term function does not run and data that was filed can be lost. Use z/TPF globals when filing data.

Table 1 contains the return conditions, the descriptions of return codes, and the z/TPF system actions. Use the information in this table as a guide when you code the system initializer.

Table 1. The z/TPF system handles different return codes from initializer functions
Return condition Description of return code z/TPF system action
No return code from the __tpf_module_init initialization function The __tpf_module_init initialization function does not send a return code. The z/TPF system assumes that the initializer is completed successfully and processing continues. The z/TPF system copies the writable static from the ECB virtual memory (EVM) to the system virtual memory (SVM).
Return code 0 from the __tpf_module_initRC initialization function The initializer is completed successfully. The z/TPF system assumes that the initializer is completed successfully and processing continues. The z/TPF system copies the writable static from the ECB virtual memory (EVM) to the system virtual memory (SVM).
Return code 1 from the __tpf_module_initRC initialization function The initializer cannot be run now, and the program is marked as unusable. However, the first system call was not marked as complete, so the next call to the program tries to run the initializer again. This return code is valid only for initializer but not for terminator, and is used when a program with an initializer is called too early in restart processing. If the initializer returns 1 when the initializer is run for a program in a loadset that is being activated, treat 1 the same as -1. The loadset activation is terminated. The z/TPF system takes one of the following actions:
  • If the initializer was invoked because of the first call to a base version of a program, the initializer is invoked again on the next call because the program is in the same state. The program receives the return code from the function that the program called. No messages are displayed by the z/TPF system.
  • If the initializer was invoked because the program was in a loadset that was activated, the loadset activation fails. An error message is displayed from E-type loader activate processing.
Return code -1 from the __tpf_module_initRC initialization function An error occurs. The initializer is not completed successfully, and the program is marked as unusable. The z/TPF system takes one of the following actions:
  • If the initializer was invoked because of the first call to a base version of a program, the program is unusable. No messages are displayed by the z/TPF system. Subsequent calls to the program cause a 064804 dump.
  • If the initializer was invoked because the program was in a loadset that was activated, the loadset activation fails. An error message is displayed from E-type loader activate processing.
ECB exits from a constructor None. The z/TPF system takes one of the following actions:
  • If the initializer was invoked because of the first call to a base version of a program, the program is unusable. Exit processing displays a 00006E dump. Subsequent calls to the program cause a 064804 dump.
  • If the initializer was invoked because the program was in a loadset that was activated, the loadset activation fails. An error message is displayed from E-type loader activate processing.

For more information about the binary tool readelf, see the GNU website.