IBM Metal C

Compiler

Writable Static Area - WSA

The writable static area is used for data items in reentrant C or C++ programs. C code is naturally reentrant if it contains no data in the Writable Static Area. The modifiable writable static part of the program contains:

Reentrant programs are structured to allow multiple users to share a single copy of an executable module or to use an executable module repeatedly without reloading. C and C++ achieve reentrancy by splitting programs into two parts, which are maintained in separate areas of memory.

Constructed Reentrancy for Metal-C Programs

RENT mode support

The RENT option supports constructed reentrancy for C programs with writable static and external variables. This makes Metal C programs with writable static and external variables reentrant.

Runtime RENT support is accomplished by additional calls generated for the function "main" between the prolog/epilog code and the function code. The RENT environment initialization and termination routines are called to establish and terminate the dynamically allocated WSA storage.

For the AMODE 31 "main" function, CCNZINIT and CCNZTERM are the called CCNZQINIand CCNZQTRM are called.

Here's how constructed reentrancy is managed for a Metal-C program:

Sample C Code - M_WSA class

Below are snippets from the exampleExample 11, Pseudorandom Number Generator (PRNG), the using Mersenne Twister. The static data are highlighted.

 
#define N 624
#define M 397
#define MATRIX_A 0x9908b0dfUL
#define UPPER_MASK 0x80000000UL 
#define LOWER_MASK 0x7fffffffUL 

static unsigned long mt[N]; 
static int mti = N + 1; 


unsigned long genrand_int32(void)
{
    unsigned long y;
static unsigned long mag01[2] = {0x0UL, MATRIX_A};

	
	
    
}

After compiling the Metal-C program, the generated assembler code will have a text class such as the one shown below:

 
MAIN#C   CSECT ,
M_WSA     CATTR RMODE(ANY),PART(MAIN#S),NOTEXECUTABLE,ALIGN(3)  
$STATIC  DS    0D
         DC    (2512)X'00' 
         ORG   $STATIC+8
         DC    XL8'000000009908B0DF' mag01[0,1] = 0x00000000,0x9908b0df 
         ORG   $STATIC
         DC    XL4'00000271' mti = 625 
         ORG   ,
         EJECT
@@STATICD@@ DSECT
         DS    XL2512
         ORG   @@STATICD@@
@27mti   DS    F
         ORG   @@STATICD@@+16
@31mt    DS    XL2496        mt[N] = 2496 bytes 
         ORG   @@STATICD@@+8
@41mag01 DS    XL8
         END   ,(5694A01   ,1D00,15018)                                                                    
    

The static data in this program are:

There also appears to be 4 unused bytes at offset 8.

Retrieving the WSA from an Assembler Program

I wanted to see if it was possible to retrieve the WSA from a Metal-C program from an Assemlber interface. The idea being that an Assembler program calling a Metal-C program would first call this program passing it the name of Metal-C program. This would obviate the need to call CCNZINIT and CCNZTERM. The calling program would be given the address of the WSA which it could then pass to the Metal-C program in GPR 0. The program below shows how this might be possible.

References

  1. z/OS Metal C Programming Guide and Reference
  2. z/OS XL C/C++ Language Reference
  3. z/OS XL C/C++ Programming Guide/li>
  4. z/OS Version 2 Release 3 MVS Program Management - Advanced Facilities
  5. What is New in Enterprise PL/I 4.1 and z/OS XL C/C++ V1R12 IBM Corporation August 2, 2010

All references copyright© IBM Corporation.