Well, I finally hacked my way through this. There are so many errors and omissions and inconsistencies in the IBM documentation that it was very difficult. (I don't intend to litigate the previous statement here. If anyone seriously is interested in the documentation shortcomings please contact me offline.)
HERE is the sample program that SHOULD be in the IBM documentation. If anyone
would like to pick this up and put it somewhere more searchable please feel
free. It is released to the public domain.
*PROCESS RENT,RLD
MVSFREE TITLE 'Charles Mills Consulting MVS FREEMAIN'
MVSFREE CSECT
DATA LOCTR ,
DC C'Copyright 2025 Charles Mills Consulting, LLC'
* Released to the public domain April 23, 2025
CODE LOCTR ,
SYSSTATE ARCHLVL=6,OSREL=ZOSV2R4
* Note requires GOFF option, which in turn requires LIST(133)
* AMODE, RMODE and ENTRY FREEMAIN all supplied by EDCXPRLG
* FREEMAIN: FREEMAIN MVS-allocated storage
* extern "OS_DOWNSTACK" void FREEMAIN(const void *address,
* unsigned int size, unsigned int subpool = 0);
* extern "OS_DOWNSTACK" for C++
* #pragma linkage(FREEMAIN, OS_DOWNSTACK) for C
* Not every combination of features has been tested but in theory
* the following is all supported:
* Length = 0 (free subpool) or not = 0 (ordinary FREEMAIN)
* Address = 0 (free subpool) or not = 0 (ordinary FREEMAIN)
* EDCXPRLG establishes RMODE and AMODE, saves registers, sets R4
* saves the parms in the DSA, and updates the stack pointer
* Also generates ENTRY FREEMAIN
* Do *NOT* specify a DSASIZE less than 80. Bizarre LE problems result
MVSFREE EDCXPRLG DSASIZE=80,PARMWRDS=3,BASEREG=NONE, +
ENTNAME=FREEMAIN
* Parameters are respectively in R1 and pointed to by R2 and R3
USING LE_RentStor,R4 Our DSA (untested)
* Load parameters from register pointers
L R0,0(,R2) Get length
L R3,0(,R3) Get subpool
FREEMAIN RU,A=(1),LV=(0),SP=(R3)
* Return success (no return from FREEMAIN RU if error; instead ABENDs)
* And C function is declared void, so it does not really matter
* EDCXEPLG restores registers 4 to 15 and returns on the restored R7
LHI R3,0 Set RC = 0
EDCXEPLG ,
* ====================================================================
* ====================================================================
DATA LOCTR
LTORG ,
LE_RentStor DSECT ,
* LE-compliant reentrant storage
* Reentrant storage could go here
LE_RentStorLen EQU *-LE_RentStor
IAZYREG , Standard register equates
END
Charles
