commit | 6cd2ea5511a4f25af1de30201810b771c54ff4d5 | [log] [tgz] |
---|---|---|
author | Gaby Baghdadi <[email protected]> | Thu May 19 21:14:48 2022 |
committer | GitHub Enterprise <[email protected]> | Thu May 19 21:14:48 2022 |
tree | dcc149c6269e3c8c479359f083764c6ee83e550e | |
parent | 5101c86abbfef0c2352fbbad077e8dcc316a063c [diff] |
refactor roanon_mmap() & memory alloc/free checks & logging (#77) memory logging and fix mmap() leak plus some cleanups - implement optional logging of memory allocs & frees - refactor roanon_mmap() by moving its mmap() call to platform-zos.cc where it is now tracked for correct memory release, otherwise that mmap() caused a memory leak - add more checking and reporting when allocating and freeing memory - remove lock from ~__Cache(), since the function is called only during exit-time - return MAP_FAILED from anon_mmap rather than nullptr, as that's what's expected from mmap(). Co-authored-by: Igor Todorovski <[email protected]>
ZOSLIB is a z/OS C/C++ library. It is an extended implementation of the z/OS LE C Runtime Library.
ZOSLIB implements the following:
ZOSLIB is supported on the following z/OS operating systems with z/OSĀ® UNIX System Services enabled:
z/OS V2R3 with the following PTFs installed:
UI61308
UI61375
UI61747
z/OS V2R4 with the following PTFs installed:
UI64830
UI64837
UI64839
UI64940
UI65567
ZOSLIB is supported on the following hardware:
Clone the ZOSLIB source code using Git into the newly created zoslib directory:
$ git clone git@github.com:ibmruntimes/zoslib.git zoslib
After obtaining the source, cd
to the zoslib
directory and create a build directory to hold your build files:
$ cd zoslib $ mkdir mybuilddir && cd mybuilddir
Next, we will configure our build with CMake.
Make sure to export the CC
and CXX
environment variables to point to the supported C/C++ build compiler, or pass in the CMake options -DCMAKE_C_COMPILER and -DCMAKE_CXX_COMPILER.
From the directory mybuilddir
, enter the following CMake command (here, ..
refers to the ZOSLIB source directory)
$ cmake ..
By default CMake will configure your build as a Debug build. You can configure your build as a Release build with the -DCMAKE_BUILD_TYPE=Release
option.
CMake will detect your development environment, perform a series of tests, and generate the files required for building ZOSLIB.
By default, CMake will generate Makefiles. If you prefer to use Ninja, you can specify -GNinja as an option to CMake.
After CMake has finished with the configuration, start the build from mybuilddir
using CMake:
$ cmake --build .
After ZOSLIB has finished building, install it from mybuilddir
:
$ cmake --build . --target install
Once we have ZOSLIB built and installed, let's attempt to build our first ZOSLIB C++ application. The application will generate a series of random numbers, leveraging the getentropy
C API in ZOSLIB.
random.cc
containing the following contents:// random.cc // Include zos.h ZOSLIB header #include <zos.h> #include <stdio.h> // Initialize ZOSLIB class __init_zoslib __nodezoslib; int main(int argc, char** argv) { printf("ZOSLIB version: %s\n", __zoslib_version); if (argc < 1) { printf("An argument specifying the number of random " " numbers is required\n"); return 1; } int num = atoi(argv[1]); if (num < 0) { printf("The argument should be positive (>0)\n"); return 2; } printf("Generating %d random values\n", num); char buffer[10]; for (int i = 0; i < num; i++) { printf("Random index: %d\n", i); // Call ZOSLIB getentropy C API if (!getentropy(buffer, 10)) { for (int j = 0; j < 10; j++) printf("%2X ", buffer[j]); printf("\n"); } } return 0; }
This example will first include the main ZOSLIB header file, zos.h
, which subsequently includes all of the ZOSLIB header files. Alternatively, we could have just included zos-base.h
, since the prototype for getentropy
is defined in zos-base.h
.
__init_zoslib
class: __init_zoslib zoslib_init;
. This initializes the Enhanced ASCII runtime environment, among other things. If your application is C only, you can make use of the init_zoslib
function instead.In the main
function, we make use of two ZOSLIB definitions, __zoslib_version
to obtain the ZOSLIB version, and getentropy
to generate a list of random values.
xlclang++ -I path/to/zoslib/include -L path/to/mybuilddir/lib -lzoslib random.cc -o random
./random 2
You should get an output similar to the following:
ZOSLIB version: v1.1.0 Generating 2 random values Random index: 0 BC DE CF DE 7 E3 58 3A 4F 22 Random index: 1 5B 30 5A 9C C4 70 94 A6 B6 E5
The ZOSLIB API documentation is available here.
ZOSLIB is available under the Apache 2.0 license. See the LICENSE file for details
Licensed Materials - Property of IBM ZOSLIB (C) Copyright IBM Corp. 2020. All Rights Reserved. US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.