zoslib
z/OS C/C++ Library
Loading...
Searching...
No Matches
zos-base.h
Go to the documentation of this file.
1
2// Licensed Materials - Property of IBM
3// ZOSLIB
4// (C) Copyright IBM Corp. 2020. All Rights Reserved.
5// US Government Users Restricted Rights - Use, duplication
6// or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
8
9#ifndef ZOS_BASE_H_
10#define ZOS_BASE_H_
11
12#undef __ZOS_EXT
13#define __ZOS_EXT__ 1
14
15#if ' ' != 0x20
16#error EBCDIC codeset detected. ZOSLIB is compatible with the ASCII codeset only.
17#endif
18
19#include <_Nascii.h>
20#include <stdarg.h>
21#include <stdbool.h>
22#include <stdio.h>
23#include <sys/__getipc.h>
24#include <sys/ipc.h>
25#include <sys/shm.h>
26#include <sys/time.h>
27#include <sys/types.h>
28#include <sys/socket.h>
29#include <time.h>
30#include <unistd.h>
31
32#define __ZOS_CC
33
34#include "zos-macros.h"
35#include "zos-bpx.h"
36#include "zos-char-util.h"
37#include "zos-io.h"
38#include "zos-savstack.h"
39#include "zos-sys-info.h"
40#include "zos-tls.h"
41#include "zos-getentropy.h"
42
43#define IPC_CLEANUP_ENVAR_DEFAULT "__IPC_CLEANUP"
44#define RUNTIME_LIMIT_ENVAR_DEFAULT "__RUNTIMELIMIT"
45#define CCSID_GUESS_BUF_SIZE_DEFAULT "__CCSIDGUESSBUFSIZE"
46#define UNTAGGED_READ_MODE_DEFAULT "__UNTAGGED_READ_MODE"
47#define UNTAGGED_READ_MODE_CCSID1047_DEFAULT "__UNTAGGED_READ_MODE_CCSID1047"
48#define MEMORY_USAGE_LOG_FILE_ENVAR_DEFAULT "__MEMORY_USAGE_LOG_FILE"
49#define MEMORY_USAGE_LOG_LEVEL_ENVAR_DEFAULT "__MEMORY_USAGE_LOG_LEVEL"
50
57
58struct timespec;
59
60extern const char *__zoslib_version;
61
70
71#ifdef __cplusplus
72#include <bitset>
73extern "C" {
74#endif
75
80__Z_EXPORT char **__get_environ_np(void);
81
85__Z_EXPORT void __xfer_env(void);
86
92__Z_EXPORT void __cleanupipc(int others);
93
99__Z_EXPORT const char *getIFAUsageErrorString(unsigned long rc);
100
110__Z_EXPORT unsigned long long __registerProduct(const char *major_version,
111 const char *product_owner,
112 const char *feature_name,
113 const char *product_name,
114 const char *pid);
115
120__Z_EXPORT int gettid();
121
130
136
142
147
154__Z_EXPORT int backtrace(void **buffer, int size);
155
162__Z_EXPORT char **backtrace_symbols(void *const *buffer, int size);
163
170__Z_EXPORT void backtrace_symbols_fd(void *const *buffer, int size, int fd);
171
179__Z_EXPORT void __abend(int comp_code, unsigned reason_code, int flat_byte,
180 void *plist);
181
189__Z_EXPORT int strncasecmp_ignorecp(const char *a, const char *b, size_t n);
190
197__Z_EXPORT int strcasecmp_ignorecp(const char *a, const char *b);
198
209__Z_EXPORT int __getargcv(int *argc, char ***argv, pid_t pid);
210
219__Z_EXPORT int __getexepath(char *path, int pathlen, pid_t pid);
220
225__Z_EXPORT char **__getargv(void);
226
231__Z_EXPORT int __getargc(void);
232
238
245__Z_EXPORT void *__iterate_stack_and_get(void *dsaptr, __stack_info *si);
246
252__Z_EXPORT void *__dlcb_next(void *last);
253
261__Z_EXPORT int __dlcb_entry_name(char *buf, int size, void *dlcb);
262
268__Z_EXPORT void *__dlcb_entry_addr(void *dlcb);
269
280__Z_EXPORT int __dlcb_iterate(int (*cb)(char* name, void* addr, void* data),
281 void *data);
282
287__Z_EXPORT unsigned long __mach_absolute_time(void);
288
299__Z_EXPORT void *__zalloc(size_t len, size_t alignment);
300
313__Z_EXPORT void *anon_mmap(void *_, size_t len);
314
324__Z_EXPORT void *__zalloc_for_fd(size_t len, const char *filename, int fd,
325 off_t offset);
326
343__Z_EXPORT void *roanon_mmap(void *_, size_t len, int prot, int flags,
344 const char *filename, int fd, off_t offset);
351__Z_EXPORT int __zfree(void *addr, int len);
352
361__Z_EXPORT int anon_munmap(void *addr, size_t len);
362
370int __check_le_func(void *addr, char *funcname, size_t len);
371
383__Z_EXPORT int __cond_timed_wait(unsigned int secs, unsigned int nsecs,
384 unsigned int event_list, unsigned int *secs_rem,
385 unsigned int *nsecs_rem);
386
388
395__Z_EXPORT int __getentropy(void *buffer, size_t length);
396
401__Z_EXPORT char* __get_le_version(void);
402
406__Z_EXPORT void __build_version(void);
407
413__Z_EXPORT void __tcp_clear_to_close(int socket, unsigned int secs);
414
420__Z_EXPORT int get_ipcs_overview(IPCQPROC *info);
421
428__Z_EXPORT int __print_zoslib_help(FILE *fp, const char *title);
429
430typedef struct __cpu_relax_workarea {
431 void *sfaddr;
432 unsigned long t0;
434
437
439__Z_EXPORT int __testread(const void *location);
440__Z_EXPORT void __tb(void);
441
444
445#ifdef __cplusplus
449typedef struct __Z_EXPORT zoslib_config {
453 const char *IPC_CLEANUP_ENVAR = IPC_CLEANUP_ENVAR_DEFAULT;
457 const char *RUNTIME_LIMIT_ENVAR = RUNTIME_LIMIT_ENVAR_DEFAULT;
462 const char *CCSID_GUESS_BUF_SIZE_ENVAR = CCSID_GUESS_BUF_SIZE_DEFAULT;
466 const char *UNTAGGED_READ_MODE_ENVAR = UNTAGGED_READ_MODE_DEFAULT;
471 const char *UNTAGGED_READ_MODE_CCSID1047_ENVAR =
478 const char *MEMORY_USAGE_LOG_FILE_ENVAR = MEMORY_USAGE_LOG_FILE_ENVAR_DEFAULT;
483 const char *MEMORY_USAGE_LOG_LEVEL_ENVAR =
486
491__Z_EXPORT void init_zoslib(const zoslib_config_t config = {});
492
493#else
532
537__Z_EXPORT void init_zoslib(const zoslib_config_t config);
538
539#endif // __cplusplus
540
546
552__Z_EXPORT int __update_envar_settings(const char *envar);
553
558unsigned long __get_libvec_base(void);
559
566
571
577
583
589
595
596#ifdef __cplusplus
597}
598#endif
599
600#ifdef __cplusplus
602
603#include <exception>
604#include <map>
605#include <string>
606#include <unordered_map>
607
608inline bool operator==(const pthread_t &_a, const pthread_t &_b) {
609 return _a.__ == _b.__;
610}
611inline bool operator!=(const pthread_t &_a, const pthread_t &_b) {
612 return _a.__ != _b.__;
613}
614inline bool operator<=(const pthread_t &_a, const pthread_t &_b) {
615 return _a.__ <= _b.__;
616}
617inline bool operator>=(const pthread_t &_a, const pthread_t &_b) {
618 return _a.__ >= _b.__;
619}
620inline bool operator<(const pthread_t &_a, const pthread_t &_b) {
621 return _a.__ < _b.__;
622}
623inline bool operator>(const pthread_t &_a, const pthread_t &_b) {
624 return _a.__ > _b.__;
625}
626inline bool operator==(const pthread_t &_a, const int _b) {
627 return _a.__ == static_cast<unsigned long long>(_b);
628}
629inline bool operator!=(const pthread_t &_a, const int _b) {
630 return _a.__ != static_cast<unsigned long long>(_b);
631}
632
633struct zoslibEnvar {
634 std::string envarName;
635 std::string envarValue;
636
637 zoslibEnvar(std::string name, std::string value)
638 : envarName(name), envarValue(value) {}
639
640 bool operator<(const zoslibEnvar &t) const {
641 return std::tie(envarName, envarValue) <
642 std::tie(t.envarName, t.envarValue);
643 }
644};
645
646class __zinit {
647 int mode;
648 int cvstate;
649 std::terminate_handler _th;
650
651public:
652 zoslib_config_t config;
653 std::map<zoslibEnvar, std::string> envarHelpMap;
654
655public:
656 __zinit();
657 ~__zinit();
658
659 int initialize(const zoslib_config_t &config);
660 bool isValidZOSLIBEnvar(std::string envar);
661 int setEnvarHelpMap(void);
662 void populateLEFunctionPointers(void);
663
664 void __abort() { _th(); }
665
666private:
667 void del_instance();
668};
669
670struct __Z_EXPORT __init_zoslib {
671 __init_zoslib(const zoslib_config_t &config = {});
672};
673
680template <std::size_t N> __Z_EXPORT std::bitset<N>
681 __subtractOne(std::bitset<N> bs) {
682 // Flip bits from rightmost bit till and including the first 1:
683 for (int i=0; i<bs.size(); i++) {
684 if (bs[i]) {
685 bs[i] = 0b0;
686 break;
687 } else {
688 bs[i] = 0b1;
689 }
690 }
691 return bs;
692}
693
700template <std::size_t N> __Z_EXPORT std::bitset<N>
701 __addOne(std::bitset<N> bs) {
702 // Flip bits from rightmost bit till and including the first 0:
703 for (int i=0; i<bs.size(); i++) {
704 if (!bs[i]) {
705 bs[i] = 0b1;
706 break;
707 } else {
708 bs[i] = 0b0;
709 }
710 }
711 return bs;
712}
713
714__zinit* __get_instance();
715
716#endif // __cplusplus
717#endif // ZOS_BASE_H_
struct __ffile FILE
Definition stdio.h:16
Definition zos-base.h:430
void * sfaddr
Definition zos-base.h:431
unsigned long t0
Definition zos-base.h:432
Definition zos-base.h:62
void * prev_dsa
Definition zos-base.h:63
int * return_addr
Definition zos-base.h:66
char entry_name[256]
Definition zos-base.h:65
void * entry_point
Definition zos-base.h:64
int * stack_addr
Definition zos-base.h:68
int * entry_addr
Definition zos-base.h:67
Definition zos-base.h:497
const char * IPC_CLEANUP_ENVAR
Definition zos-base.h:501
const char * MEMORY_USAGE_LOG_FILE_ENVAR
Definition zos-base.h:525
const char * MEMORY_USAGE_LOG_LEVEL_ENVAR
Definition zos-base.h:530
const char * RUNTIME_LIMIT_ENVAR
Definition zos-base.h:505
const char * UNTAGGED_READ_MODE_ENVAR
Definition zos-base.h:514
const char * UNTAGGED_READ_MODE_CCSID1047_ENVAR
Definition zos-base.h:519
const char * CCSID_GUESS_BUF_SIZE_ENVAR
Definition zos-base.h:510
#define MEMORY_USAGE_LOG_LEVEL_ENVAR_DEFAULT
Definition zos-base.h:49
__Z_EXPORT void backtrace_symbols_fd(void *const *buffer, int size, int fd)
Definition zos.cc:446
struct __Z_EXPORT zoslib_config zoslib_config_t
__Z_EXPORT int __getentropy(void *buffer, size_t length)
Definition zos-getentropy.cc:74
COND_TIME_WAIT_CONSTANTS
Definition zos-base.h:387
@ CW_CONDVAR
Definition zos-base.h:387
@ CW_INTRPT
Definition zos-base.h:387
__Z_EXPORT char ** backtrace_symbols(void *const *buffer, int size)
Definition zos.cc:281
#define MEMORY_USAGE_LOG_FILE_ENVAR_DEFAULT
Definition zos-base.h:48
__Z_EXPORT int __zfree(void *addr, int len)
Definition zos.cc:1445
__Z_EXPORT int gettid()
Definition zos.cc:214
__Z_EXPORT void __tcp_clear_to_close(int socket, unsigned int secs)
Definition zos.cc:1790
__Z_EXPORT void * __iterate_stack_and_get(void *dsaptr, __stack_info *si)
Definition zos.cc:2343
__Z_EXPORT bool __doLogMemoryWarning()
Definition zos.cc:3063
__Z_EXPORT int __cond_timed_wait(unsigned int secs, unsigned int nsecs, unsigned int event_list, unsigned int *secs_rem, unsigned int *nsecs_rem)
Definition zos.cc:715
__Z_EXPORT pthread_t __getMainThreadSelf()
__Z_EXPORT int get_ipcs_overview(IPCQPROC *info)
Definition zos.cc:543
__Z_EXPORT int __dlcb_entry_name(char *buf, int size, void *dlcb)
Definition zos.cc:665
__Z_EXPORT int backtrace(void **buffer, int size)
Definition zos.cc:238
__Z_EXPORT void __cleanupipc(int others)
Definition zos.cc:547
__Z_EXPORT void init_zoslib(const zoslib_config_t config)
Definition zos.cc:2990
__Z_EXPORT int __testread(const void *location)
Definition zos.cc:1628
__Z_EXPORT int __getargcv(int *argc, char ***argv, pid_t pid)
Definition zos.cc:738
__Z_EXPORT int __getargc(void)
Definition zos.cc:881
notagread_t
Definition zos-base.h:51
@ __NO_TAG_READ_DEFAULT
Definition zos-base.h:52
@ __NO_TAG_READ_DEFAULT_WITHWARNING
Definition zos-base.h:53
@ __NO_TAG_READ_STRICT
Definition zos-base.h:55
@ __NO_TAG_READ_V6
Definition zos-base.h:54
const char * __zoslib_version
Definition zos.cc:117
__Z_EXPORT void * anon_mmap(void *_, size_t len)
Definition zos.cc:1440
__Z_EXPORT char * __get_le_version(void)
Definition zos.cc:1723
__Z_EXPORT void __display_backtrace(int fd)
Definition zos.cc:453
__Z_EXPORT void __abend(int comp_code, unsigned reason_code, int flat_byte, void *plist)
Definition zos.cc:459
__Z_EXPORT const char * getIFAUsageErrorString(unsigned long rc)
Definition zos.cc:2086
__Z_EXPORT int __getMainThreadId()
__Z_EXPORT void * roanon_mmap(void *_, size_t len, int prot, int flags, const char *filename, int fd, off_t offset)
Definition zos.cc:2197
unsigned long __get_libvec_base(void)
Definition zos.cc:2499
__Z_EXPORT void * __zalloc(size_t len, size_t alignment)
Definition zos.cc:1398
__Z_EXPORT unsigned long __mach_absolute_time(void)
Definition zos.cc:951
#define RUNTIME_LIMIT_ENVAR_DEFAULT
Definition zos-base.h:44
#define IPC_CLEANUP_ENVAR_DEFAULT
Definition zos-base.h:43
__Z_EXPORT int __update_envar_settings(const char *envar)
Definition zos.cc:2258
__Z_EXPORT void __tb(void)
Definition zos.cc:1699
__Z_EXPORT int anon_munmap(void *addr, size_t len)
Definition zos.cc:1456
__Z_EXPORT int __get_no_tag_ignore_ccsid1047()
Definition zos.cc:947
int __check_le_func(void *addr, char *funcname, size_t len)
Definition zos.cc:2995
__Z_EXPORT void * __dlcb_entry_addr(void *dlcb)
Definition zos.cc:677
__Z_EXPORT void __set_backtrace_on_abort(bool flag)
Definition zos.cc:711
__Z_EXPORT void __cpu_relax(__crwa_t *)
Definition zos.cc:1762
__Z_EXPORT notagread_t __get_no_tag_read_behaviour()
Definition zos.cc:935
__Z_EXPORT int __update_envar_names(zoslib_config_t *const config)
Definition zos.cc:2332
__Z_EXPORT int * __get_stack_start()
Definition zos.cc:2479
__Z_EXPORT bool __doLogMemoryAll()
Definition zos.cc:3061
__Z_EXPORT int __dlcb_iterate(int(*cb)(char *name, void *addr, void *data), void *data)
__Z_EXPORT int __print_zoslib_help(FILE *fp, const char *title)
Definition zos.cc:2203
__Z_EXPORT bool __doLogMemoryUsage()
Definition zos.cc:3055
__Z_EXPORT void * __dlcb_next(void *last)
Definition zos.cc:659
__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)
Definition zos.cc:2092
__Z_EXPORT void __mainTerminating()
Definition zos.cc:3067
__Z_EXPORT char * __getMemoryUsageLogFile()
Definition zos.cc:3059
#define UNTAGGED_READ_MODE_CCSID1047_DEFAULT
Definition zos-base.h:47
__Z_EXPORT void * __zalloc_for_fd(size_t len, const char *filename, int fd, off_t offset)
Definition zos.cc:2158
struct __cpu_relax_workarea __crwa_t
__Z_EXPORT void __build_version(void)
Definition zos.cc:1755
__Z_EXPORT char ** __getargv(void)
Definition zos.cc:863
#define CCSID_GUESS_BUF_SIZE_DEFAULT
Definition zos-base.h:45
__Z_EXPORT int __getexepath(char *path, int pathlen, pid_t pid)
Definition zos.cc:887
__Z_EXPORT void init_zoslib_config(zoslib_config_t *const config)
Definition zos.cc:2979
__Z_EXPORT int strcasecmp_ignorecp(const char *a, const char *b)
Definition zos.cc:496
#define UNTAGGED_READ_MODE_DEFAULT
Definition zos-base.h:46
__Z_EXPORT char ** __get_environ_np(void)
Definition zos.cc:145
__Z_EXPORT void __xfer_env(void)
Definition zos.cc:186
__Z_EXPORT int strncasecmp_ignorecp(const char *a, const char *b, size_t n)
Definition zos.cc:513
#define __Z_EXPORT
Definition zos-macros.h:13
__zinit * __get_instance()
Definition zos.cc:128