Metal C environment

Some of the functions require that an environment be created before they are called. You can create the environment by using a new function, __cinit(). This function will set up the appropriate control blocks and return an environment token to the caller. The caller must then ensure that GPR 12 contains this token when calling Metal C functions that require an environment. When the environment is no longer needed, a new function, __cterm(), can be used to perform cleanup, freeing all resources that had been obtained by using the token.

An environment created by __cinit() can be used in both AMODE 31 and AMODE 64. In conjunction with this, the Metal C run time maintains both a below-the-bar heap and an above-the-bar heap for each environment. Calls to __malloc31() always affect the below-the-bar heap. Calls made in AMODE 31 to all other functions that obtain storage will affect the below-the-bar heap; calls made in AMODE 64 affect the above-the-bar heap.

The storage key for all storage obtained on behalf of the environment is the psw key of the caller. The caller needs to ensure that the environment is always used with the same or compatible key.

Metal C environments are intended to be used serially by a single dispatchable unit of work. If you need to share environments between multiple dispatchable units, you must make sure that the use of each environment is serialized.