Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various enhancements for zopen tools #58

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
d95312c
zopen enhancements:
IgorTodorovskiIBM Apr 22, 2024
11eeb20
Add missing header netiniet
IgorTodorovskiIBM Jun 25, 2024
ebe82e0
Add support for getline, getdelim, sysconf, memset
IgorTodorovskiIBM Jun 26, 2024
b32dcd4
Add utimesat and PTHREAD_RWLOCK_INITIALIZER
IgorTodorovskiIBM Jun 27, 2024
7d497c6
Add readlink override to resolve PARMLIB variables like
IgorTodorovskiIBM Jul 11, 2024
8253dfe
Fix getdelim and readlink override
IgorTodorovskiIBM Jul 16, 2024
153ef5f
Fix typo
IgorTodorovskiIBM Jul 16, 2024
b7074a5
Fix getdelim again
IgorTodorovskiIBM Jul 16, 2024
b0cd547
Fix missing }
IgorTodorovskiIBM Jul 16, 2024
276feb4
Address comments
IgorTodorovskiIBM Jul 16, 2024
827486b
Address comments
IgorTodorovskiIBM Jul 16, 2024
4145cf9
Add __threading_support - needed for boost and clang 1.1 builds
IgorTodorovskiIBM Jul 19, 2024
040105d
Update memmem
IgorTodorovskiIBM Jul 22, 2024
8c0764d
Add strverscmp from musl c
IgorTodorovskiIBM Jul 23, 2024
504ba77
Fix readlink and mkostemp - after further testing with zopen tools
IgorTodorovskiIBM Jul 24, 2024
5a1b34b
Fix readlink and mkostemp - after further testing with zopen tools
IgorTodorovskiIBM Jul 24, 2024
b36a272
Add code for profiling instrumentation
IgorTodorovskiIBM Aug 19, 2024
325ed89
Fix typos
IgorTodorovskiIBM Aug 19, 2024
6f56563
Fix typos
IgorTodorovskiIBM Aug 20, 2024
63e621e
replace bzero with calloc (#68)
kishkulk Aug 20, 2024
c098335
revise json
IgorTodorovskiIBM Aug 20, 2024
b548649
Fix tid in instrumentation json
IgorTodorovskiIBM Aug 20, 2024
b1ae73f
Update zos-instrumentation.cc
IgorTodorovskiIBM Aug 20, 2024
51f5dd0
Resolve clang related build issues
IgorTodorovskiIBM Aug 21, 2024
d847fc3
Resolve clang related build issues
IgorTodorovskiIBM Aug 21, 2024
b87bc46
Change dsa to __dsa and use traceEvent objects to make ns the default…
IgorTodorovskiIBM Aug 21, 2024
7738105
Gzip the json file once completed
IgorTodorovskiIBM Aug 21, 2024
0756b23
Only activate __get_stack_start on non-quick startup
IgorTodorovskiIBM Aug 28, 2024
5d413b7
Propagate ZOSLIB_QUICK_STARTUP in cmake
IgorTodorovskiIBM Aug 28, 2024
659b1d5
Change the arch level to arch10 for clang (and arch14 only for zos-ge…
IgorTodorovskiIBM Aug 29, 2024
d2aed54
Add tracing for allocation
IgorTodorovskiIBM Sep 19, 2024
3a4cb7f
Add malloc/free overrides
IgorTodorovskiIBM Sep 19, 2024
9a69e8e
Add export to __readlink
IgorTodorovskiIBM Sep 23, 2024
4e8ca92
Update zos-v2r5-symbolfixes.h
IgorTodorovskiIBM Sep 24, 2024
2dc1f9b
Resolve issue when malloc/free are used as function pointers
IgorTodorovskiIBM Sep 24, 2024
ac3adb8
Add pthread_condattr_setclock to v2r5 symbol list
IgorTodorovskiIBM Oct 9, 2024
6c843ab
Add asprintf and vasprintf to v2r5 symbol list
IgorTodorovskiIBM Oct 9, 2024
ab0e6fa
Update unistd.h - use __asm
IgorTodorovskiIBM Nov 13, 2024
cdd2f75
Fix up product name & remove the c++ copied dir (#70)
perry-ca Nov 15, 2024
3a5c17f
Add dependant code for script command (#71)
sachintu47 Nov 26, 2024
bac1675
Add vasprintf and strcasestr - needed by htop
IgorTodorovskiIBM Jan 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ if(ZOSLIB_GENERIC)
ZOSLIB_GENERIC)
endif()

if(ZOSLIB_QUICK_STARTUP)
list(APPEND zoslib_defines
ZOSLIB_QUICK_STARTUP)
endif()


if(DEFINED ENV{BUILD_VERSION})
list(APPEND zoslib_defines BUILD_VERSION="$ENV{BUILD_VERSION}")
Expand Down Expand Up @@ -81,7 +86,7 @@ else()
list(APPEND zoslib_cflags
-fgnu-keywords
-m64
-march=arch14
-march=arch10
-mzos-target=zosv2r4
-fno-short-enums
-fzos-le-char-mode=ascii)
Expand Down
19 changes: 19 additions & 0 deletions include/c++/v1/__threading_support
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
///////////////////////////////////////////////////////////////////////////////
// Licensed Materials - Property of IBM
// ZOSLIB
// (C) Copyright IBM Corp. 2022. All Rights Reserved.
// US Government Users Restricted Rights - Use, duplication
// or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
///////////////////////////////////////////////////////////////////////////////

#ifndef ZOS_LIBCPP_THREADING_SUPPORT
#define ZOS_LIBCPP_THREADING_SUPPORT

//TODO(itodorov) - zos: workaround for nanosleep WoZ conflict, revisit
// once WoZ allow overriding or LE provides a nanosleep definition
#include <time.h>
#define nanosleep cpp_nanosleep
#include_next <__threading_support>
#undef nanosleep

#endif
19 changes: 19 additions & 0 deletions include/netinet/in_systm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
///////////////////////////////////////////////////////////////////////////////
// Licensed Materials - Property of IBM
// ZOSLIB
// (C) Copyright IBM Corp. 2024. All Rights Reserved.
// US Government Users Restricted Rights - Use, duplication
// or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
///////////////////////////////////////////////////////////////////////////////

#ifndef ZOS_IN_SYSTM_H_
#define ZOS_IN_SYSTM_H_

#include <stdint.h>

// Network types
typedef uint16_t n_short;
typedef uint32_t n_long;
typedef uint32_t n_time;

#endif
55 changes: 55 additions & 0 deletions include/pthread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
///////////////////////////////////////////////////////////////////////////////
// Licensed Materials - Property of IBM
// ZOSLIB
// (C) Copyright IBM Corp. 2021. All Rights Reserved.
// US Government Users Restricted Rights - Use, duplication
// or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
///////////////////////////////////////////////////////////////////////////////

#ifndef ZOS_PTHREAD_H_
#define ZOS_PTHREAD_H_

#define __XPLAT 1
#include "zos-macros.h"
#include <sys/types.h>


#if defined(__cplusplus)
extern "C" {
#endif
__Z_EXPORT int __pthread_create_extended(pthread_t *thread,
const pthread_attr_t *attr,
void *(*start_routine)(void *),
void *arg);
#if defined(__cplusplus)
}
#endif

#if defined(ZOSLIB_OVERRIDE_CLIB) || defined(ZOSLIB_OVERRIDE_CLIB_PTHREAD)
#define pthread_create __pthread_create_replaced
#endif

#include_next <pthread.h>

#if defined(ZOSLIB_OVERRIDE_CLIB) || defined(ZOSLIB_OVERRIDE_CLIB_PTHREAD)

#if defined(__cplusplus)
extern "C" {
#endif

#undef pthread_create
__Z_EXPORT int pthread_create(pthread_t *thread,
const pthread_attr_t *attr,
void *(*start_routine)(void *),
void *arg) asm("__pthread_create_extended");

#if defined(__cplusplus)
}
#endif
#endif /* defined(ZOSLIB_OVERRIDE_CLIB) || defined(ZOSLIB_OVERRIDE_CLIB_PTHREAD) */

#ifndef PTHREAD_RWLOCK_INITIALIZER
#define PTHREAD_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER_NP
#endif

#endif
3 changes: 3 additions & 0 deletions include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define ZOS_STDIO_H_

#include "zos-macros.h"
#include <sys/types.h>

#define __XPLAT 1

Expand Down Expand Up @@ -39,6 +40,8 @@ extern "C" {
#endif

__Z_EXPORT extern FILE *fopen(const char *filename, const char *mode) __asm("__fopen_ascii");
__Z_EXPORT ssize_t getline(char **lineptr, size_t *n, FILE *stream);
__Z_EXPORT ssize_t getdelim(char **lineptr, size_t *n, int delimiter, FILE *stream);

#if defined(__cplusplus)
}
Expand Down
3 changes: 3 additions & 0 deletions include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ extern "C" {
*/
__Z_EXPORT int getloadavg(double loadavg[], int nelem);
__Z_EXPORT const char * getprogname(void);
__Z_EXPORT int mkostemp(char *, int flags);
__Z_EXPORT int mkstemps(char *, int suffixlen);
__Z_EXPORT int mkostemps(char *, int suffixlen, int flags);
#if defined(__cplusplus)
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions include/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ __Z_EXPORT char *strndup(const char *s, size_t n);
__Z_EXPORT char *strsignal(int );
__Z_EXPORT const char *sigdescr_np(int);
__Z_EXPORT const char *sigabbrev_np(int);
__Z_EXPORT void *memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen);
__Z_EXPORT int strverscmp(const char *l0, const char *r0);

// Linux includes strings.h in string.h, this avoids the
// warning - implicitly declaring library function 'strcasecmp'
Expand Down
17 changes: 16 additions & 1 deletion include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ extern "C" {
#endif
__Z_EXPORT int __pipe_ascii(int [2]);
__Z_EXPORT int __close(int);
__Z_EXPORT int __sysconf(int name);

#if defined(__cplusplus)
}
#endif
Expand All @@ -27,19 +29,28 @@ __Z_EXPORT int __close(int);
#define pipe __pipe_replaced
#undef close
#define close __close_replaced
#undef sysconf
#define sysconf __sysconf_replaced
#undef readlink
#define readlink __readlink_replaced
#include_next <unistd.h>
#undef pipe
#undef close
#undef sysconf
#undef readlink

#if defined(__cplusplus)
extern "C" {
#endif

/**
* Same as C pipe but tags pipes as ASCII (819)
*/
__Z_EXPORT int pipe(int [2]) __asm("__pipe_ascii");
__Z_EXPORT int close(int) __asm("__close");
__Z_EXPORT int close(int) __asm("__close");
__Z_EXPORT int sysconf(int name) __asm("__sysconf");
__Z_EXPORT ssize_t readlink(const char *path, char *buf, size_t bufsiz) asm("__readlink");


#if defined(__cplusplus)
}
Expand Down Expand Up @@ -75,4 +86,8 @@ __Z_EXPORT int execvpe(const char *name, char *const argv[],
}
#endif

#ifndef _SC_NPROCESSORS_ONLN
#define _SC_NPROCESSORS_ONLN 58 /* match linux */
#endif

#endif
10 changes: 10 additions & 0 deletions include/zos-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@
#define __ZL_NR(attr,reg) attr "{" #reg "}"
#endif

#if defined(__clang__) && !defined(__ibmxl__)
#define _gdsa __builtin_s390_gdsa
#else
extern "builtin" void *_gdsa();
#endif

#ifndef __dsa
#define __dsa() ((unsigned long *)_gdsa())
#endif

#include "zos-macros.h"
#include "zos-bpx.h"
#include "zos-char-util.h"
Expand Down
2 changes: 1 addition & 1 deletion include/zos-v2r5-symbolfixes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#pragma redefine_extname getrandom getrandom_undefined
#pragma redefine_extname pipe2 pipe2_undefined
#pragma redefine_extname fsstatfs fsstatfs_undefined
#pragma redefine_extname getline getline_undefined
IgorTodorovskiIBM marked this conversation as resolved.
Show resolved Hide resolved
#pragma redefine_extname dprintf dprintf_undefined
#pragma redefine_extname dirfd dirfd_undefined
#pragma redefine_extname fchmodat fchmodat_undefined
Expand All @@ -45,6 +44,7 @@
#pragma redefine_extname setresgid setresgid_undefined
#pragma redefine_extname dup3 dup3_undefined
#pragma redefine_extname shm_open shm_open_undefined
#pragma redefine_extname utimensat utimensat_undefined
#endif

#endif // ZOS_V2R5_SYMBOLFIXES_H
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ set(libsrc
zos.cc
zos-mount.c
zos-mkdtemp.c
zos-instrumentation.cc
)
set(zoslib-help zoslib-help.cc)

Expand All @@ -35,6 +36,10 @@ COMMAND /bin/as -mgoff -o ${CELQUOPT_OBJECT} ${CELQUOPT_SOURCE}
VERBATIM
)

if(${CMAKE_C_COMPILER} MATCHES clang)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest checking if ! xlclang, since compiler can also be ibm-clang.

set_source_files_properties(zos-getentropy.cc PROPERTIES COMPILE_FLAGS "-march=arch14")
endif()

add_library(libzoslib OBJECT ${libsrc})

add_library(zoslib SHARED $<TARGET_OBJECTS:libzoslib>)
Expand Down
29 changes: 29 additions & 0 deletions src/zos-bpx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,35 @@ char *__realpath_extended(const char __restrict__ *path, char __restrict__ *reso
return __realpath_orig(path, resolved_path);
}

ssize_t __readlink_orig(const char *path, char *buf, size_t bufsiz) asm("@@A00202");

ssize_t __readlink(const char *path, char *buf, size_t bufsiz) {
ssize_t len = __readlink_orig(path, buf, bufsiz);
if (len < 0) {
return -1;
}

if ((len > 0 && buf[0] == '$') || (len > 1 && buf[0] == '/' && buf[1] == '$')) {
// Not sure if this is possible, but double check in case:
if (len < bufsiz) {
buf[len] = '\0';
} else {
buf[bufsiz - 1] = '\0';
}
char resolved_path[PATH_MAX];
if (realpath(path, resolved_path) == NULL) {
return -1;
}

len = snprintf(buf, bufsiz, "%s", resolved_path);
if (len >= bufsiz) {
errno = ENAMETOOLONG;
return -1;
}
}

return len;
}

void __bpx4kil(int pid, int signal, void *signal_options, int *return_value,
int *return_code, int *reason_code) {
Expand Down
41 changes: 20 additions & 21 deletions src/zos-char-util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ class fdAttributeCache {
};

fdAttributeCache fdcache;
#define FD_NEEDS_CONVERSION_ATTR 0x0000000000020000UL

void __fd_close(int fd) {
if (!bfdcache_destroyed)
Expand All @@ -506,7 +507,7 @@ int __file_needs_conversion(int fd) {
if (__get_no_tag_read_behaviour() == __NO_TAG_READ_STRICT)
return 0;
unsigned long attr = fdcache.get_attribute(fd);
if (attr == 0x0000000000020000UL) {
if (attr == FD_NEEDS_CONVERSION_ATTR) {
return 1;
}
return 0;
Expand All @@ -527,7 +528,7 @@ int __file_needs_conversion_init(const char *name, int fd) {
if (no_tag_read_behaviour == __NO_TAG_READ_STRICT)
return 0;
if (no_tag_read_behaviour == __NO_TAG_READ_V6) {
fdcache.set_attribute(fd, 0x0000000000020000UL);
fdcache.set_attribute(fd, FD_NEEDS_CONVERSION_ATTR);
return 1;
}
if (lseek(fd, 1, SEEK_SET) == 1 && lseek(fd, 0, SEEK_SET) == 0) {
Expand All @@ -539,27 +540,25 @@ int __file_needs_conversion_init(const char *name, int fd) {
close(fd);
return 0;
}
if (cnt > 8) {
int ccsid;
int am;
unsigned len = strlen_ae((unsigned char *)buf, &ccsid, cnt, &am);
if (ccsid == 1047 && len == cnt) {
if (no_tag_read_behaviour == __NO_TAG_READ_DEFAULT_WITHWARNING) {
if (name) {
len = strlen(name) + 1;
char filename[len];
_convert_e2a(filename, name, len);
dprintf(2, "Warning: File \"%s\" is untagged and seems to contain "
"EBCDIC characters\n", filename);
} else {
dprintf(2, "Warning: File (null) is untagged and seems to contain "
"EBCDIC characters\n");
}
int ccsid;
int am;
unsigned len = strlen_ae((unsigned char *)buf, &ccsid, cnt, &am);
if (ccsid == 1047 && len == cnt) {
if (no_tag_read_behaviour == __NO_TAG_READ_DEFAULT_WITHWARNING) {
if (name) {
len = strlen(name);
char filename[len + 1];
_convert_e2a(filename, name, len);
dprintf(2, "Warning: File \"%s\" is untagged and seems to contain "
"EBCDIC characters\n", filename);
} else {
dprintf(2, "Warning: File (null) is untagged and seems to contain "
"EBCDIC characters\n");
}
fdcache.set_attribute(fd, 0x0000000000020000UL);
return 1;
}
} // cnt > 8
fdcache.set_attribute(fd, FD_NEEDS_CONVERSION_ATTR);
return 1;
}
} // seekable files
return 0; // not seekable
}
Expand Down
Loading