Skip to content

Commit

Permalink
pass DLL to create libzoslib.x with xlclang, undo updates to edcwccwi…
Browse files Browse the repository at this point in the history
….h, rm zos-setlibpath.h (#43)

* include: change strlen_ae() max_len type

Change to unsigned long and remove casts

* remove updates to a system header

* build: pass DLL to binder if xlclang

This creates the sidedeck libzoslib.x required when linking to zoslib as a shared library.

* remove unneeded char *bp

* fix memset arguments in test-clib-override.cc
  • Loading branch information
gabylb authored Jan 8, 2024
1 parent 18af824 commit ab9e81a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 92 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ if(${CMAKE_C_COMPILER} MATCHES xlclang)
-qarch=10
-qasm
-qasmlib=sys1.maclib:sys1.modgen)

target_link_options(zoslib PUBLIC "-Wl,DLL")
else()
# min arch14 is required for zos-getentropy.cc to use PRNO instruction.
list(APPEND zoslib_cflags
Expand Down
4 changes: 0 additions & 4 deletions include/edcwccwi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@

#ifndef __edcwccwi
#define __edcwccwi 1
#if !defined(__clang__) || defined(__ibmxl__)
#pragma nomargins nosequence
#pragma checkout(suspend)
#endif
/***************************************************************
* <edcwccwi.h> header file *
* *
Expand Down Expand Up @@ -613,7 +611,5 @@ struct __event1_s {
}
#endif

#if !defined(__clang__) || defined(__ibmxl__)
#pragma checkout(resume)
#endif
#endif /* __edcwccwi */
12 changes: 6 additions & 6 deletions include/zos-char-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class __Z_EXPORT __conv_off {
#endif // ifdef __cplusplus

inline unsigned strlen_ae(const unsigned char *str, int *code_page,
int max_len, int *ambiguous) {
unsigned long max_len, int *ambiguous) {
static int last_ccsid = 819;
static const unsigned char _tab_a[256] __attribute__((aligned(8))) = {
1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
Expand Down Expand Up @@ -233,25 +233,25 @@ inline unsigned strlen_ae(const unsigned char *str, int *code_page,
unsigned long code_out;
const unsigned char *start;

bytes = (unsigned long)max_len;
bytes = max_len;
code_out = 0;
start = str;
__asm volatile(" trte %1,%3,0\n"
" jo *-4\n"
: "+NR:r3"(bytes), "+NR:r2"(str), "+r"(bytes), "+r"(code_out)
: "NR:r1"(_tab_a)
:);
unsigned a_len = (unsigned)((unsigned long)str - (unsigned long)start);
unsigned a_len = str - start;

bytes = (unsigned long)max_len;
bytes = max_len;
code_out = 0;
str = start;
__asm volatile(" trte %1,%3,0\n"
" jo *-4\n"
: "+NR:r3"(bytes), "+NR:r2"(str), "+r"(bytes), "+r"(code_out)
: "NR:r1"(_tab_e)
:);
unsigned e_len = (unsigned)((unsigned long)str - (unsigned long)start);
unsigned e_len = str - start;
if (a_len > e_len) {
*code_page = 819;
last_ccsid = 819;
Expand Down Expand Up @@ -293,7 +293,7 @@ inline unsigned strlen_e(const unsigned char *str, unsigned size) {
: "NR:r1"(_tab_e)
:);

return (unsigned)((unsigned long)str - (unsigned long)start);
return str - start;
}

const unsigned char __ibm1047_iso88591[256] __attribute__((aligned(8))) = {
Expand Down
60 changes: 0 additions & 60 deletions include/zos-setlibpath.h

This file was deleted.

5 changes: 2 additions & 3 deletions src/zos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,6 @@ extern "C" int execvpe(const char *name, char *const argv[],
}
char path[len + 1];
char buf[len + strlen(name) + 2];
char *bp = buf;

if (dp != NULL) {
strncpy(path, dp, sizeof(path));
Expand Down Expand Up @@ -1514,7 +1513,7 @@ extern "C" int execvpe(const char *name, char *const argv[],
buf[lp + ln + 1] = '\0';

retry:
(void)execve(bp, argv, envp);
(void)execve(buf, argv, envp);
switch (errno) {
case EACCES:
eacces = 1;
Expand All @@ -1533,7 +1532,7 @@ extern "C" int execvpe(const char *name, char *const argv[],
memcpy(ap + 2, argv + 1, cnt * sizeof(char *));

ap[0] = (char *)"sh";
ap[1] = bp;
ap[1] = buf;
(void)execve("/bin/sh", ap, envp);
goto done;
}
Expand Down
33 changes: 14 additions & 19 deletions test/test-clib-override.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,17 @@ TEST_F(CLIBOverrides, open) {
close(fd);

char buff[] = "This is a test";
int bufflen = strlen(buff);
char* buff2 = (char*)malloc(bufflen);

char* buff2 = (char*)malloc(sizeof(buff));

#if CHECK_NFS
const char* file_str = "/gsa/tlbgsa/projects/i/igortest/nodejs_data_file";
fd = open(file_str, O_CREAT | O_WRONLY, 0777);
write(fd, buff, bufflen);
write(fd, buff, sizeof(buff));
close(fd);

fd = open(file_str, O_RDONLY);
memset(buff2, bufflen, 1);
read(fd, buff2, bufflen);
memset(buff2, 1, sizeof(buff));
read(fd, buff2, sizeof(buff));
EXPECT_EQ(strcmp(buff, buff2), 0);
close(fd);
#endif
Expand All @@ -75,47 +74,43 @@ TEST_F(CLIBOverrides, open) {
remove(temp_path);
fd = open(temp_path, O_CREAT | O_WRONLY, 0777);
EXPECT_EQ(__getfdccsid(fd), 0x10000 + 1047);
write(fd, buff, bufflen);
write(fd, buff, sizeof(buff));
close(fd);

fd = open(temp_path, O_RDONLY);
EXPECT_EQ(__getfdccsid(fd), 0x10000 + 1047);
memset(buff2, bufflen, 1);
read(fd, buff2, bufflen);
memset(buff2, 1, sizeof(buff));
read(fd, buff2, sizeof(buff));
EXPECT_EQ(strcmp(buff, buff2), 0);
free(buff2);
close(fd);

// Delete and re-open temp_path _ENCODE_FILE_NEW=BINARY
setenv("_ENCODE_FILE_NEW", "BINARY", 1);
remove(temp_path);
fd = open(temp_path, O_CREAT | O_WRONLY, 0777);
EXPECT_EQ(__getfdccsid(fd), 65535);
write(fd, buff, bufflen);
write(fd, buff, sizeof(buff));
close(fd);

fd = open(temp_path, O_RDONLY);
EXPECT_EQ(__getfdccsid(fd), 65535);
buff2 = (char*)malloc(bufflen);
memset(buff2, bufflen, 1);
read(fd, buff2, bufflen);
memset(buff2, 1, sizeof(buff));
read(fd, buff2, sizeof(buff));
EXPECT_EQ(strcmp(buff, buff2), 0);
free(buff2);
close(fd);

// Delete and re-open temp_path _ENCODE_FILE_NEW=ISO8859-1
setenv("_ENCODE_FILE_NEW", "ISO8859-1", 1);
remove(temp_path);
fd = open(temp_path, O_CREAT | O_WRONLY, 0777);
EXPECT_EQ(__getfdccsid(fd), 0x10000 + 819);
write(fd, buff, bufflen);
write(fd, buff, sizeof(buff));
close(fd);

fd = open(temp_path, O_RDONLY);
EXPECT_EQ(__getfdccsid(fd), 0x10000 + 819);
buff2 = (char*)malloc(bufflen);
memset(buff2, bufflen, 1);
read(fd, buff2, bufflen);
memset(buff2, 1, sizeof(buff));
read(fd, buff2, sizeof(buff));
EXPECT_EQ(strcmp(buff, buff2), 0);
free(buff2);
close(fd);
Expand Down

0 comments on commit ab9e81a

Please sign in to comment.