zoslib
z/OS C/C++ Library
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions | Variables
zos-base.h File Reference
#include <_Nascii.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <sys/__getipc.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <time.h>
#include <unistd.h>
#include "zos-macros.h"
#include "zos-bpx.h"
#include "zos-char-util.h"
#include "zos-io.h"
#include "zos-savstack.h"
#include "zos-sys-info.h"
#include "zos-tls.h"
#include "zos-getentropy.h"

Go to the source code of this file.

Classes

struct  __stack_info
 
struct  __cpu_relax_workarea
 
struct  zoslib_config
 

Macros

#define __ZOS_EXT__   1
 
#define __ZOS_CC
 
#define IPC_CLEANUP_ENVAR_DEFAULT   "__IPC_CLEANUP"
 
#define RUNTIME_LIMIT_ENVAR_DEFAULT   "__RUNTIMELIMIT"
 
#define CCSID_GUESS_BUF_SIZE_DEFAULT   "__CCSIDGUESSBUFSIZE"
 
#define UNTAGGED_READ_MODE_DEFAULT   "__UNTAGGED_READ_MODE"
 
#define UNTAGGED_READ_MODE_CCSID1047_DEFAULT   "__UNTAGGED_READ_MODE_CCSID1047"
 
#define MEMORY_USAGE_LOG_FILE_ENVAR_DEFAULT   "__MEMORY_USAGE_LOG_FILE"
 
#define MEMORY_USAGE_LOG_LEVEL_ENVAR_DEFAULT   "__MEMORY_USAGE_LOG_LEVEL"
 

Typedefs

typedef struct __stack_info __stack_info
 
typedef struct __cpu_relax_workarea __crwa_t
 
typedef struct __Z_EXPORT zoslib_config zoslib_config_t
 

Enumerations

enum  notagread_t { __NO_TAG_READ_DEFAULT = 0 , __NO_TAG_READ_DEFAULT_WITHWARNING = 1 , __NO_TAG_READ_V6 = 2 , __NO_TAG_READ_STRICT = 3 }
 
enum  COND_TIME_WAIT_CONSTANTS { CW_INTRPT = 1 , CW_CONDVAR = 32 }
 

Functions

__Z_EXPORT char ** __get_environ_np (void)
 
__Z_EXPORT void __xfer_env (void)
 
__Z_EXPORT void __cleanupipc (int others)
 
__Z_EXPORT const char * getIFAUsageErrorString (unsigned long rc)
 
__Z_EXPORT unsigned long long __registerProduct (const char *major_version, const char *product_owner, const char *feature_name, const char *product_name, const char *pid)
 
__Z_EXPORT int gettid ()
 
__Z_EXPORT int __getMainThreadId ()
 
__Z_EXPORT pthread_t __getMainThreadSelf ()
 
__Z_EXPORT void __display_backtrace (int fd)
 
__Z_EXPORT void __set_backtrace_on_abort (bool flag)
 
__Z_EXPORT int backtrace (void **buffer, int size)
 
__Z_EXPORT char ** backtrace_symbols (void *const *buffer, int size)
 
__Z_EXPORT void backtrace_symbols_fd (void *const *buffer, int size, int fd)
 
__Z_EXPORT void __abend (int comp_code, unsigned reason_code, int flat_byte, void *plist)
 
__Z_EXPORT int strncasecmp_ignorecp (const char *a, const char *b, size_t n)
 
__Z_EXPORT int strcasecmp_ignorecp (const char *a, const char *b)
 
__Z_EXPORT int __getargcv (int *argc, char ***argv, pid_t pid)
 
__Z_EXPORT int __getexepath (char *path, int pathlen, pid_t pid)
 
__Z_EXPORT char ** __getargv (void)
 
__Z_EXPORT int __getargc (void)
 
__Z_EXPORT int * __get_stack_start ()
 
__Z_EXPORT void * __iterate_stack_and_get (void *dsaptr, __stack_info *si)
 
__Z_EXPORT void * __dlcb_next (void *last)
 
__Z_EXPORT int __dlcb_entry_name (char *buf, int size, void *dlcb)
 
__Z_EXPORT void * __dlcb_entry_addr (void *dlcb)
 
__Z_EXPORT int __dlcb_iterate (int(*cb)(char *name, void *addr, void *data), void *data)
 
__Z_EXPORT unsigned long __mach_absolute_time (void)
 
__Z_EXPORT void * __zalloc (size_t len, size_t alignment)
 
__Z_EXPORT void * anon_mmap (void *_, size_t len)
 
__Z_EXPORT void * __zalloc_for_fd (size_t len, const char *filename, int fd, off_t offset)
 
__Z_EXPORT void * roanon_mmap (void *_, size_t len, int prot, int flags, const char *filename, int fd, off_t offset)
 
__Z_EXPORT int __zfree (void *addr, int len)
 
__Z_EXPORT int anon_munmap (void *addr, size_t len)
 
int __check_le_func (void *addr, char *funcname, size_t len)
 
__Z_EXPORT int __cond_timed_wait (unsigned int secs, unsigned int nsecs, unsigned int event_list, unsigned int *secs_rem, unsigned int *nsecs_rem)
 
__Z_EXPORT int __getentropy (void *buffer, size_t length)
 
__Z_EXPORT char * __get_le_version (void)
 
__Z_EXPORT void __build_version (void)
 
__Z_EXPORT void __tcp_clear_to_close (int socket, unsigned int secs)
 
__Z_EXPORT int get_ipcs_overview (IPCQPROC *info)
 
__Z_EXPORT int __print_zoslib_help (FILE *fp, const char *title)
 
__Z_EXPORT void __cpu_relax (__crwa_t *)
 
__Z_EXPORT int __testread (const void *location)
 
__Z_EXPORT void __tb (void)
 
__Z_EXPORT notagread_t __get_no_tag_read_behaviour ()
 
__Z_EXPORT int __get_no_tag_ignore_ccsid1047 ()
 
__Z_EXPORT void init_zoslib (const zoslib_config_t config)
 
__Z_EXPORT void init_zoslib_config (zoslib_config_t *const config)
 
__Z_EXPORT int __update_envar_settings (const char *envar)
 
unsigned long __get_libvec_base (void)
 
__Z_EXPORT int __update_envar_names (zoslib_config_t *const config)
 
__Z_EXPORT bool __doLogMemoryUsage ()
 
__Z_EXPORT char * __getMemoryUsageLogFile ()
 
__Z_EXPORT bool __doLogMemoryAll ()
 
__Z_EXPORT bool __doLogMemoryWarning ()
 
__Z_EXPORT void __mainTerminating ()
 

Variables

const char * __zoslib_version
 

Macro Definition Documentation

◆ __ZOS_CC

#define __ZOS_CC

◆ __ZOS_EXT__

#define __ZOS_EXT__   1

◆ CCSID_GUESS_BUF_SIZE_DEFAULT

#define CCSID_GUESS_BUF_SIZE_DEFAULT   "__CCSIDGUESSBUFSIZE"

◆ IPC_CLEANUP_ENVAR_DEFAULT

#define IPC_CLEANUP_ENVAR_DEFAULT   "__IPC_CLEANUP"

◆ MEMORY_USAGE_LOG_FILE_ENVAR_DEFAULT

#define MEMORY_USAGE_LOG_FILE_ENVAR_DEFAULT   "__MEMORY_USAGE_LOG_FILE"

◆ MEMORY_USAGE_LOG_LEVEL_ENVAR_DEFAULT

#define MEMORY_USAGE_LOG_LEVEL_ENVAR_DEFAULT   "__MEMORY_USAGE_LOG_LEVEL"

◆ RUNTIME_LIMIT_ENVAR_DEFAULT

#define RUNTIME_LIMIT_ENVAR_DEFAULT   "__RUNTIMELIMIT"

◆ UNTAGGED_READ_MODE_CCSID1047_DEFAULT

#define UNTAGGED_READ_MODE_CCSID1047_DEFAULT   "__UNTAGGED_READ_MODE_CCSID1047"

◆ UNTAGGED_READ_MODE_DEFAULT

#define UNTAGGED_READ_MODE_DEFAULT   "__UNTAGGED_READ_MODE"

Typedef Documentation

◆ __crwa_t

◆ __stack_info

typedef struct __stack_info __stack_info

◆ zoslib_config_t

Configuration for zoslib library

Enumeration Type Documentation

◆ COND_TIME_WAIT_CONSTANTS

Enumerator
CW_INTRPT 
CW_CONDVAR 

◆ notagread_t

Enumerator
__NO_TAG_READ_DEFAULT 
__NO_TAG_READ_DEFAULT_WITHWARNING 
__NO_TAG_READ_V6 
__NO_TAG_READ_STRICT 

Function Documentation

◆ __abend()

__Z_EXPORT void __abend ( int  comp_code,
unsigned  reason_code,
int  flat_byte,
void *  plist 
)

Generates an SVC 13 abend.

Parameters
[in]comp_codeCompletion code.
[in]reason_codeReason code.
[in]flat_byteFlat Byte.
[in]plistParameter list.

◆ __build_version()

__Z_EXPORT void __build_version ( void  )

Prints the build version of the library

◆ __check_le_func()

int __check_le_func ( void *  addr,
char *  funcname,
size_t  len 
)

Check if an LE function is present in the LE vector table

Parameters
[in]addraddress to LE function
[out]funcnamepointer to string that will hold the function name
[out]maxlength of string corresponding to funcname
Returns
returns 1 if successful, 0 if unsuccessful.

◆ __cleanupipc()

__Z_EXPORT void __cleanupipc ( int  others)

Remove IPC semaphores and shared memory.

Parameters
[in]othersnon-zero value indicates remove IPC not associated with current process.

◆ __cond_timed_wait()

__Z_EXPORT int __cond_timed_wait ( unsigned int  secs,
unsigned int  nsecs,
unsigned int  event_list,
unsigned int *  secs_rem,
unsigned int *  nsecs_rem 
)

Suspend the calling thread until any one of a set of events has occurred or until a specified amount of time has passed.

Parameters
[in]secsseconds to suspend
[in]nsecsnanoseconds to suspend
[in]event_listevents that will trigger thread to resume (CW_INTRPT or CW_CONDVAR)
[out]secs_remseconds remaining
[out]nsecs_remnanoseconds remaining
Returns
returns 0 if successful, -1 if unsuccessful.

◆ __cpu_relax()

__Z_EXPORT void __cpu_relax ( __crwa_t p)

TODO(itodorov) - zos: document these interfaces

◆ __display_backtrace()

__Z_EXPORT void __display_backtrace ( int  fd)

Print backtrace of stack to file descriptor.

Parameters
[in]fdfile descriptor.

◆ __dlcb_entry_addr()

__Z_EXPORT void * __dlcb_entry_addr ( void *  dlcb)

Get address of dlcb entry

Parameters
[in]dlcb- current dlcb
Returns
returns entry address of dlcb

◆ __dlcb_entry_name()

__Z_EXPORT int __dlcb_entry_name ( char *  buf,
int  size,
void *  dlcb 
)

Get entry name of given dlcb

Parameters
[out]buf- DLL name of given dlcb
[in]size- maximum number of bytes
[in]dlcb- current dlcb
Returns
[in] number of bytes written to buf

◆ __dlcb_iterate()

__Z_EXPORT int __dlcb_iterate ( int(*)(char *name, void *addr, void *data)  cb,
void *  data 
)

Walk through list of dlcb

Parameters
[in]cb- callback function for each dlcb, the callback will have the name, the address and data, which is a copy of whatever value was passed as the second argument, as input parameters
[in]data- pass to callback
Returns
returns whatever value was returned by the last call to callback, if no dlcb is found, return -1

◆ __dlcb_next()

__Z_EXPORT void * __dlcb_next ( void *  last)

Get next dlcb entry

Parameters
[in]last- previous dlcb entry
Returns
[in] returns next dlcb entry

◆ __doLogMemoryAll()

__Z_EXPORT bool __doLogMemoryAll ( )

Returns true if all messages from memory allocation and release are being displayed.

◆ __doLogMemoryUsage()

__Z_EXPORT bool __doLogMemoryUsage ( )

Returns true if logging of memory allocation and release is specified.

◆ __doLogMemoryWarning()

__Z_EXPORT bool __doLogMemoryWarning ( )

Returns true if only warnings from memory allocation and release are being displayed. Errors are always included if memory logging in on.

◆ __get_environ_np()

__Z_EXPORT char ** __get_environ_np ( void  )

Get the environ.

Returns
returns pointer to environment list

◆ __get_le_version()

__Z_EXPORT char * __get_le_version ( void  )

Return the LE version as a string in the format of "Product %d%s Version %d Release %d Modification %d"

◆ __get_libvec_base()

unsigned long __get_libvec_base ( void  )

Gets the LE libvec base address

Returns
libvec base address

◆ __get_no_tag_ignore_ccsid1047()

__Z_EXPORT int __get_no_tag_ignore_ccsid1047 ( )

◆ __get_no_tag_read_behaviour()

__Z_EXPORT notagread_t __get_no_tag_read_behaviour ( )

◆ __get_stack_start()

__Z_EXPORT int * __get_stack_start ( )

Get the stack start address for the current thread

Returns
returns the stack start address

◆ __getargc()

__Z_EXPORT int __getargc ( void  )

Get program argument count of the current process

Returns
returns count of process arguments

◆ __getargcv()

__Z_EXPORT int __getargcv ( int *  argc,
char ***  argv,
pid_t  pid 
)

Get program argument list of a given process id

Parameters
[out]argc- pointer to store count of the arguments
[out]argv- pointer to store an array of pointers that point to each argument
[in]pid- process id to obtain the argc and argv for
Note
Call free(argv) when done accessing argv.
Returns
On success, returns 0, or -1 on error.

◆ __getargv()

__Z_EXPORT char ** __getargv ( void  )

Get program argument list of the current process

Returns
returns an array of process arguments

◆ __getentropy()

__Z_EXPORT int __getentropy ( void *  buffer,
size_t  length 
)

Fill a buffer with random bytes

Parameters
[out]bufferto store random bytes to.
[in]numberof random bytes to generate.
Returns
On success, returns 0, or -1 on error.

◆ __getexepath()

__Z_EXPORT int __getexepath ( char *  path,
int  pathlen,
pid_t  pid 
)

Get the executable path of a given process id

Parameters
[out]path- pointer to the destination array to copy the null-terminated path to
[in]pathlen- length of the given array
[in]pid- process id to obtain the executable path for
Returns
On success, returns 0, or -1 on error.

◆ __getMainThreadId()

__Z_EXPORT int __getMainThreadId ( )

Get the main Thread ID. If a process is started with sh -c, main thread id is 0; if started with bash -c, main thread id is 2; if started directly from the shell, main thread id is 1.

Returns
returns the current thread id

◆ __getMainThreadSelf()

__Z_EXPORT pthread_t __getMainThreadSelf ( )

Get the pthread_self() for the main thread.

Returns
returns the current pthread_self() for main thread

◆ __getMemoryUsageLogFile()

__Z_EXPORT char * __getMemoryUsageLogFile ( )

Returns the file name, including "stdout" or "stderr", used to log memory allocation and release to.

◆ __iterate_stack_and_get()

__Z_EXPORT void * __iterate_stack_and_get ( void *  dsaptr,
__stack_info si 
)

Iterate to next stack dsa based on current dsa

Parameters
[in]dsaptr- current dsa entry
[out]si- stack information of next dsa
Returns
returns the next dsa entry in the chain or 0 if not found

◆ __mach_absolute_time()

__Z_EXPORT unsigned long __mach_absolute_time ( void  )

Obtain the mach absolute time

Returns
returns mach absolute time

◆ __mainTerminating()

__Z_EXPORT void __mainTerminating ( )

Tell zoslib that the main process is terminating, for its diagnostics.

◆ __print_zoslib_help()

__Z_EXPORT int __print_zoslib_help ( FILE fp,
const char *  title 
)

Prints zoslib help information to specified FILE pointer

Parameters
[in]FILEpointer to write to
[in]titleheader, specify NULL for default
Returns
On success, returns 0, or < 0 on error.

◆ __registerProduct()

__Z_EXPORT unsigned long long __registerProduct ( const char *  major_version,
const char *  product_owner,
const char *  feature_name,
const char *  product_name,
const char *  pid 
)

Registers product for SMF 89 Type 1 records using IFAUSAGE macro.

Parameters
[in]major_versionThe major version of Product (e.g. 14)
[in]product_ownerThe product owner (e.g. IBM)
[in]feature_nameThe feature name (e.g. Node.js)
[in]product_nameThe product name (e.g. Node.js for z/OS)
[in]pidThe Product ID (e.g. 5676-SDK)
Returns
returns 0 if successful, non-zero if unsuccessful.

◆ __set_backtrace_on_abort()

__Z_EXPORT void __set_backtrace_on_abort ( bool  flag)

Enable or disable abort() from calling display_backtrace(). Default is true.

◆ __tb()

__Z_EXPORT void __tb ( void  )

◆ __tcp_clear_to_close()

__Z_EXPORT void __tcp_clear_to_close ( int  socket,
unsigned int  secs 
)

Attempts to a close a socket for a period of time

Parameters
[in]socketsocket handle
[in]secsnumber of seconds to attempt the close

◆ __testread()

__Z_EXPORT int __testread ( const void *  location)

TODO(itodorov) - zos: document these interfaces

◆ __update_envar_names()

__Z_EXPORT int __update_envar_names ( zoslib_config_t *const  config)

Changes the names of one or more of the environment variables zoslib uses

Parameters
[in]zoslib_confit_tstructure that defines the new environment variable name(s)
Returns
0 for success, or -1 for failure

◆ __update_envar_settings()

__Z_EXPORT int __update_envar_settings ( const char *  envar)

Updates the zoslib global variables associated with the zoslib environment variables

Parameters
[in]envarenvironment variable to update, specify NULL to update all
Returns
0 for success, or -1 for failure

◆ __xfer_env()

__Z_EXPORT void __xfer_env ( void  )

Convert environment variables from EBCDIC to ASCII.

◆ __zalloc()

__Z_EXPORT void * __zalloc ( size_t  len,
size_t  alignment 
)

Allocate memory in 64-bit virtual storage when size is a megabyte multiple or above 2GB, or in 31-bit storage otherwise, and if none is available, attempt to allocate from 64-bit virtual storage.

Parameters
[in]lenlength in bytes of memory to allocate
[in]alignmentin bytes and applies only to 31-bit storage (64-bit storage is always megabyte-aligned)
Returns
pointer to the beginning of newly allocated memory, or 0 if unsuccessful

◆ __zalloc_for_fd()

__Z_EXPORT void * __zalloc_for_fd ( size_t  len,
const char *  filename,
int  fd,
off_t  offset 
)

Allocate memory (using __zalloc()) and read into it contents of given file

Parameters
[in]lenlength in bytes of memory to allocate
[in]filenamefilename to read
[in]fdfile descriptor
[in]offsetoffset in bytes into the file to read
Returns
pointer to the beginning of newly allocated memory, or 0 if unsuccessful

◆ __zfree()

__Z_EXPORT int __zfree ( void *  addr,
int  len 
)

Deallocate memory

Parameters
[in]addrstart address of memory
[in]lenlength in bytes
Returns
returns 0 if successful, -1 if unsuccessful

◆ anon_mmap()

__Z_EXPORT void * anon_mmap ( void *  _,
size_t  len 
)

Allocate memory in 64-bit virtual storage when size is a megabyte multiple or above 2GB, or in 31-bit storage (with PAGE_SIZE bytes alignment) otherwise, and if none is available, attempt to allocate from 64-bit virtual storage.

Parameters
[in]_ignored
[in]lenlength in bytes of memory to allocate
Returns
pointer to the beginning of newly allocated memory, or MAP_FAILED if unsuccessful
Deprecated:
This function will be removed once mmap is fully functional (e.g. MAP_ANONYMOUS is supported)

◆ anon_munmap()

__Z_EXPORT int anon_munmap ( void *  addr,
size_t  len 
)

Deallocate memory

Parameters
[in]addrstart address of memory
[in]lenlength in bytes
Returns
returns 0 if successful, -1 if unsuccessful
Deprecated:
This function will be removed once mmap is fully functional (e.g. MAP_ANONYMOUS is supported)

◆ backtrace()

__Z_EXPORT int backtrace ( void **  buffer,
int  size 
)

Generate a backtrace and store into *Buffer.

Parameters
[out]bufferAddress of location to store backtrace to.
[in]sizeMaximum number of bytes to store.
Returns
if successful, returns 0, otherwise -1

◆ backtrace_symbols()

__Z_EXPORT char ** backtrace_symbols ( void *const *  buffer,
int  size 
)

Generate a backtrace symbols and store into *Buffer.

Parameters
[out]bufferAddress of location to store backtrace to.
[in]sizeMaximum number of bytes to store.
Returns
if successful, an array of strings, otherwise returns NULL.

◆ backtrace_symbols_fd()

__Z_EXPORT void backtrace_symbols_fd ( void *const *  buffer,
int  size,
int  fd 
)

Generate a backtrace symbols and store into *Buffer.

Parameters
[out]bufferAddress of location to store backtrace to.
[in]sizeMaximum number of bytes to store.
[in]fdfile descriptor.

◆ get_ipcs_overview()

__Z_EXPORT int get_ipcs_overview ( IPCQPROC *  info)

Returns the overview structure of IPCQPROC

Parameters
[out]infoaddress of allocated IPCQPROC structure
Returns
On success, returns 0, or -1 on error.

◆ getIFAUsageErrorString()

__Z_EXPORT const char * getIFAUsageErrorString ( unsigned long  rc)

Retrieves error message from __registerProduct IFAUSAGE macro.

Parameters
[in]rcreturn code from __registerProduct.
Returns
returns error message as C character string.

◆ gettid()

__Z_EXPORT int gettid ( )

Get the Thread ID.

Returns
returns the current thread id

◆ init_zoslib()

__Z_EXPORT void init_zoslib ( const zoslib_config_t  config)

Initialize zoslib library

Parameters
[in]configstruct to configure zoslib.

◆ init_zoslib_config()

__Z_EXPORT void init_zoslib_config ( zoslib_config_t *const  config)

Initialize the struct used to configure zoslib with default values.

Parameters
[in]configstruct to configure zoslib.

◆ roanon_mmap()

__Z_EXPORT void * roanon_mmap ( void *  _,
size_t  len,
int  prot,
int  flags,
const char *  filename,
int  fd,
off_t  offset 
)

Allocate memory (using __zalloc()) and read into it contents of given file at the given offset.

Parameters
[in]_ignored
[in]lenlength in bytes of memory map
[in]protprotection bits
[in]flagsmmap flags
[in]filenamefilename to read
[in]fdfile descriptor
[in]offsetoffset in bytes into the file to read
Returns
pointer to the beginning of newly allocated memory, or MAP_FAILED if unsuccessful
Deprecated:
This function will be removed once mmap is fully functional (e.g. MAP_ANONYMOUS is supported), in which case mapped memory would need to be converted to ASCII if the file contains EBCDIC.

◆ strcasecmp_ignorecp()

__Z_EXPORT int strcasecmp_ignorecp ( const char *  a,
const char *  b 
)

String case comparision that ignores code page.

Parameters
[in]a- null-terminated character string.
[in]b- null-terminated character string.
Returns
if equal, returns 0, otherwise returns non-zero.

◆ strncasecmp_ignorecp()

__Z_EXPORT int strncasecmp_ignorecp ( const char *  a,
const char *  b,
size_t  n 
)

String case comparision that ignores code page.

Parameters
[in]a- Character String.
[in]b- Character String.
[in]n- Number of bytes to compare.
Returns
if equal, returns 0, otherwise returns non-zero.

Variable Documentation

◆ __zoslib_version

const char* __zoslib_version
extern