summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-28 21:58:27 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-28 21:58:27 -0600
commitb97207f7e5dd3d8d147da525ede1ba3609f5c983 (patch)
treef8f4dfcaccdfbfccb26df192e0d2e2bc27c7f3e3
parent3a8fab2c0e0fdabe8063ee86df7d2e17020ea9b9 (diff)
downloadzash-b97207f7e5dd3d8d147da525ede1ba3609f5c983.tar.gz
Fix z/OS 64-bit linkage/storage, EBCDIC, editor, and checkout issues
- Guard #pragma linkage with _LP64 (OS on -m64, OS_UPSTACK on -m32), use bit 31 (0x80000000u) for the OS VL bit, and allocate IGGCSI00/BPXWDY2 work areas via __malloc31() per z/OS C/C++ Runtime Library Reference and Open XL C/C++ 2.2 Compiler Reference. - Use isupper()/isdigit() in complete.c hlq_ok() and an EBCDIC/ASCII-safe ctrl_byte() helper in edit_builtin.c bind_keys(). - Tag temp files with sys_tmp_tag() in fc_edit() and edit_external(), add EINTR retry loops in edit_external(), route edit_bind_list() through out1, and clamp CSI/vi repeat counts against signed int overflow. - Destroy posix_spawn_file_actions_t on error in sys_spawn() and clamp put_name() copy length in sys_posix.c. - Replace non-ISO8859-1 dashes in README.md and C-PROGRAMMING-STANDARDS.md and mark notes/review-2026-11-27.md UTF-8 in .gitattributes so git checkout succeeds on z/OS. Verified locally on Linux (make, make zos-lint, make check: 128/129 pass, only pre-existing linux/i-dscomplete differs); z/OS CBT verification next.
-rw-r--r--.gitattributes1
-rw-r--r--C-PROGRAMMING-STANDARDS.md6
-rw-r--r--README.md2
-rw-r--r--src/complete.c6
-rw-r--r--src/edit_builtin.c69
-rw-r--r--src/history.c2
-rw-r--r--src/sys_posix.c12
-rw-r--r--src/sys_zos.c20
8 files changed, 87 insertions, 31 deletions
diff --git a/.gitattributes b/.gitattributes
index e1f0af5..2b0be7a 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -15,6 +15,7 @@ formal/zash-spec.typ zos-working-tree-encoding=UTF-8
formal/zash_spec/ZashSpec.lean zos-working-tree-encoding=UTF-8
formal/zash_spec/ZashSpec/Patterns.lean zos-working-tree-encoding=UTF-8
notes/investigation.md zos-working-tree-encoding=UTF-8
+notes/review-2026-11-27.md zos-working-tree-encoding=UTF-8
formal/zash-spec.pdf binary -zos-working-tree-encoding
packaging/zash.ico binary -zos-working-tree-encoding
tests/posix/printf-ext.exp binary -zos-working-tree-encoding
diff --git a/C-PROGRAMMING-STANDARDS.md b/C-PROGRAMMING-STANDARDS.md
index 6196875..ed23daf 100644
--- a/C-PROGRAMMING-STANDARDS.md
+++ b/C-PROGRAMMING-STANDARDS.md
@@ -142,8 +142,8 @@ Formatting is strictly enforced via `.clang-format` based on LLVM style:
### 5.1 Dual-Encoding Awareness (ASCII and EBCDIC)
Projects build in ASCII mode (`-fzos-le-char-mode=ascii`, CCSID 819 / ISO8859-1) or native EBCDIC mode (CCSID 1047):
-* No in-band control markers: Never use byte values in the `0x80`–`0xFF` range as internal state flags; in IBM-1047, `0x81` represents the letter `'a'`.
-* Non-contiguous alphabet safety: In EBCDIC, letters `a`–`z` and `A`–`Z` are not contiguous. Never perform pointer or integer arithmetic assuming sequential alphabetic values. Character classification must always use standard `<ctype.h>` functions (`isalpha`, `isdigit`, `isspace`).
+* No in-band control markers: Never use byte values in the `0x80`-`0xFF` range as internal state flags; in IBM-1047, `0x81` represents the letter `'a'`.
+* Non-contiguous alphabet safety: In EBCDIC, letters `a`-`z` and `A`-`Z` are not contiguous. Never perform pointer or integer arithmetic assuming sequential alphabetic values. Character classification must always use standard `<ctype.h>` functions (`isalpha`, `isdigit`, `isspace`).
* Character literals: Always write character literals (`'a'`, `'\n'`), never hexadecimal ASCII numeric literals.
* Control codes: Where terminal or protocol escapes are required, abstract the values (e.g., via `charset.h`) so appropriate ASCII (`0x1B`) or EBCDIC sequences are selected at compile time.
@@ -151,7 +151,7 @@ Projects build in ASCII mode (`-fzos-le-char-mode=ascii`, CCSID 819 / ISO8859-1)
* Tagging: On z/OS UNIX, source code and text files are tagged ISO8859-1 (`chtag -t -c ISO8859-1`).
* Runtime Conversion: Use `fcntl(fd, F_CONTROL_CVT, ...)` to manage programmatic conversion.
* ASCII Build Tagging Rule: In ASCII builds, newly created text files, pipes, and inherited stdout must be explicitly tagged IBM-1047 with programmatic conversion enabled so standard z/OS tools read them correctly.
-* zopen conventions: Wherever possible, character conversion follows the zopen community's guidance — a file created in ASCII mode is tagged ISO8859-1 (CCSID 819) at open time via `setccsid()`/`__fchattr()`, the call is double-guarded with `#ifdef __MVS__` and `#if (__CHARSET_LIB == 1)`, and the same tagging is applied from the shell with `chtag -tc819`. See [zopen community — C pipe, C open do not tag newly created file descriptors](https://zopen.community/Guides/CommonSolutions#c-pipe-c-open-do-not-tag-newly-created-file-descriptors).
+* zopen conventions: Wherever possible, character conversion follows the zopen community's guidance -- a file created in ASCII mode is tagged ISO8859-1 (CCSID 819) at open time via `setccsid()`/`__fchattr()`, the call is double-guarded with `#ifdef __MVS__` and `#if (__CHARSET_LIB == 1)`, and the same tagging is applied from the shell with `chtag -tc819`. See [zopen community -- C pipe, C open do not tag newly created file descriptors](https://zopen.community/Guides/CommonSolutions#c-pipe-c-open-do-not-tag-newly-created-file-descriptors).
### 5.3 System Data Areas and Control Blocks
* Reading MVS Control Blocks:
diff --git a/README.md b/README.md
index 0156f78..4a257e0 100644
--- a/README.md
+++ b/README.md
@@ -376,7 +376,7 @@ common area, which had 255 MB free.
### zopen / ASCII builds: avoid double pipe conversion
An ASCII build tags pipes IBM-1047 (EBCDIC) so that EBCDIC readers see
-EBCDIC. Between two ASCII programs that costs two conversions per byte —
+EBCDIC. Between two ASCII programs that costs two conversions per byte --
write through the tag to 1047, then read through it back to ASCII.
`set +o pipetag` avoids both conversions when no EBCDIC tool is in the
pipeline. The setting can go in `.profile` or a per-script `set +o
diff --git a/src/complete.c b/src/complete.c
index ea12197..d675180 100644
--- a/src/complete.c
+++ b/src/complete.c
@@ -190,9 +190,9 @@ static bool hlq_ok(const char *p, size_t len) {
if (len == 0 || len > 8)
return false;
for (size_t i = 0; i < len; i++) {
- char c = p[i];
- if (!((c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '@' ||
- c == '#' || c == '$' || c == '-'))
+ unsigned char c = (unsigned char)p[i];
+ if (!(isupper(c) || isdigit(c) || c == '@' || c == '#' || c == '$' ||
+ c == '-'))
return false;
}
return true;
diff --git a/src/edit_builtin.c b/src/edit_builtin.c
index bc66b5a..d9d7873 100644
--- a/src/edit_builtin.c
+++ b/src/edit_builtin.c
@@ -499,26 +499,49 @@ static int bind_key(int k, const char *seq, size_t n) {
}
/**
+ * @brief Decode the character after `^` in a `bind` key specification.
+ *
+ * `^[` is Escape, `^?` is Delete, and `^@`..`^_` (letters case-insensitive)
+ * map to their control codes in the build's character set.
+ *
+ * @return The control byte, or -1 if `d` does not name one.
+ */
+static int ctrl_byte(unsigned char d) {
+ if (d == '[')
+ return CH_ESC;
+ if (d == '?')
+ return CH_DEL;
+ d = (unsigned char)toupper(d);
+#if ZASH_ASCII
+ if (d >= '@' && d <= '_')
+ return d & 0x1f;
+ return -1;
+#else
+ static const char letters[] = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
+ const char *at = strchr(letters, (char)d);
+ if (!at)
+ return -1;
+ return mvs_a2e[(size_t)(at - letters)];
+#endif
+}
+
+/**
* @brief Turn the key notation of a `bind` line into bytes.
*
* `^X` is a control key, `^[` is Escape and `^?` is Delete. Anything else
- * stands for itself. The `& 0x3f` that makes `^A` into 0x01 also works on
- * an EBCDIC letter, where 'A' is 0xC1.
+ * stands for itself.
*
- * @return 0, or -1 if the notation does not fit BIND_SEQ_MAX bytes.
+ * @return 0, or -1 if the notation is invalid or does not fit BIND_SEQ_MAX.
*/
static int bind_keys(const char *s, size_t len, char *out, size_t *outlen) {
size_t n = 0;
for (size_t i = 0; i < len; i++) {
unsigned char c = (unsigned char)s[i];
if (c == '^' && i + 1 < len) {
- unsigned char d = (unsigned char)s[++i];
- if (d == '[')
- c = CH_ESC;
- else if (d == '?')
- c = CH_DEL;
- else
- c = (unsigned char)(d & 0x3f);
+ int cb = ctrl_byte((unsigned char)s[++i]);
+ if (cb < 0)
+ return -1;
+ c = (unsigned char)cb;
}
if (n == BIND_SEQ_MAX)
return -1;
@@ -572,8 +595,7 @@ int edit_bind(const char *spec) {
void edit_bind_list(void) {
for (size_t i = 0; i < sizeof bind_actions / sizeof bind_actions[0]; i++)
- printf("%s\n", bind_actions[i].name);
- fflush(stdout);
+ out_printf(&out1, "%s\n", bind_actions[i].name);
}
/* ---- reading keys ---------------------------------------------------- */
@@ -637,7 +659,8 @@ static int read_key_raw(void) {
if (n < BIND_SEQ_MAX)
seq[n++] = (char)c;
if (isdigit(c)) {
- args[np] = args[np] * 10 + (c - '0');
+ if (args[np] < 100000)
+ args[np] = args[np] * 10 + (c - '0');
} else if (c == ';') {
if (np < 1)
np++;
@@ -980,14 +1003,21 @@ static void edit_external(void) {
ob_flush();
return;
}
+ if (SYS_MVS)
+ sys_tmp_tag(fd);
size_t off = 0;
while (off < ed.len) {
ssize_t w = write(fd, ed.buf + off, ed.len - off);
+ if (w < 0 && errno == EINTR)
+ continue;
if (w <= 0)
break;
off += (size_t)w;
}
- bool wrote = off == ed.len && write(fd, "\n", 1) == 1;
+ ssize_t nl = -1;
+ while (off == ed.len && (nl = write(fd, "\n", 1)) < 0 && errno == EINTR)
+ ;
+ bool wrote = off == ed.len && nl == 1;
close(fd);
const char *editor = var_get("VISUAL");
if (!editor || !*editor)
@@ -1025,8 +1055,12 @@ static void edit_external(void) {
text = xmalloc(256);
size_t cap = 256;
ssize_t r;
- while (nread + 1 < cap &&
- (r = read(fd, text + nread, cap - nread - 1)) > 0) {
+ while (nread + 1 < cap) {
+ r = read(fd, text + nread, cap - nread - 1);
+ if (r < 0 && errno == EINTR)
+ continue;
+ if (r <= 0)
+ break;
nread += (size_t)r;
if (nread + 1 == cap) {
cap *= 2;
@@ -1208,7 +1242,8 @@ static bool vi_read_pattern(char lead) {
static bool vi_command(int key) {
int count = 0;
while ((key >= '1' && key <= '9') || (count && key == '0')) {
- count = count * 10 + (key - '0');
+ if (count < 100000)
+ count = count * 10 + (key - '0');
key = read_key();
}
bool counted = count > 0;
diff --git a/src/history.c b/src/history.c
index b15d6b8..e42a634 100644
--- a/src/history.c
+++ b/src/history.c
@@ -281,6 +281,8 @@ static int fc_edit(const char *editor, int lo, int hi) {
sh_warn("fc: cannot create a temporary file: %s", strerror(errno));
return 1;
}
+ if (SYS_MVS)
+ sys_tmp_tag(fd);
char buf[1024];
output o = {buf, 0, sizeof buf, fd, 0};
int step = lo <= hi ? 1 : -1;
diff --git a/src/sys_posix.c b/src/sys_posix.c
index 2517d3f..b50d830 100644
--- a/src/sys_posix.c
+++ b/src/sys_posix.c
@@ -125,6 +125,10 @@ pid_t sys_spawn(const spawn_req *rq) {
if (need_fa) {
rc = posix_spawn_file_actions_init(&fa);
+ if (rc) {
+ errno = rc;
+ return -1;
+ }
#if HAVE_SPAWN_TCSETPGRP
/*
* Runs in the child after it has joined its process group and
@@ -132,12 +136,13 @@ pid_t sys_spawn(const spawn_req *rq) {
* terminal before its first instruction and cannot be stopped by
* SIGTTOU for asking.
*/
- if (!rc && rq->tty_fd >= 0)
+ if (rq->tty_fd >= 0)
rc = posix_spawn_file_actions_addtcsetpgrp_np(&fa, rq->tty_fd);
#endif
if (!rc)
rc = add_fd_actions(&fa, rq->fdmap);
if (rc) {
+ posix_spawn_file_actions_destroy(&fa);
errno = rc;
return -1;
}
@@ -399,8 +404,11 @@ static void put32(unsigned char *p, size_t v) {
/** @brief Store a name, blank-padded, in EBCDIC. */
static void put_name(unsigned char *p, const char *name, size_t n) {
+ size_t len = strlen(name);
+ if (len > n)
+ len = n;
memset(p, ' ', n);
- memcpy(p, name, strlen(name));
+ memcpy(p, name, len);
mvs_to_ebcdic((char *)p, n);
}
diff --git a/src/sys_zos.c b/src/sys_zos.c
index 38908ce..31db09d 100644
--- a/src/sys_zos.c
+++ b/src/sys_zos.c
@@ -607,7 +607,11 @@ typedef struct csi_req {
} csi_req;
typedef int iggcsi_fn(void *reason, void *field, void *work);
+#ifdef _LP64
#pragma linkage(iggcsi_fn, OS)
+#else
+#pragma linkage(iggcsi_fn, OS_UPSTACK)
+#endif
static iggcsi_fn *csi_ep; /**< from fetch(), nullptr until loaded */
static bool csi_dead; /**< fetch failed or a call abended */
@@ -640,9 +644,9 @@ static int csi_call(csi_area *a, void *ctx) {
sigaction(sigs[i], &sa, &old[i]);
volatile int rc;
if (sigsetjmp(csi_jb, 1) == 0) {
- /* VL bit on the last address; harmless if the compiler sets it. */
- void *work = (void *)((uintptr_t)a->work |
- ((uintptr_t)1 << (sizeof(uintptr_t) * 8 - 1)));
+ /* VL bit (bit 31) on the last 31-bit address; harmless if the
+ * compiler sets it. */
+ void *work = (void *)((uintptr_t)a->work | (uintptr_t)0x80000000u);
rc = csi_ep(a->reason, a->field, work);
} else {
*abended = true;
@@ -680,7 +684,8 @@ bool sys_catalog_list(const char *filter, mvs_name_fn *fn, void *arg) {
return false;
}
}
- csi_req *r = malloc(sizeof *r);
+ /* IGGCSI00 is AMODE 31, so all three areas must live below 2 GB. */
+ csi_req *r = __malloc31(sizeof *r);
if (!r)
return false; /* not sticky: storage may come back */
csi_area a = {r->reason, r->field, r->work, CSI_WORK};
@@ -752,7 +757,11 @@ bool sys_dd_names(mvs_name_fn *fn, void *arg) {
/* ---- dynamic allocation ------------------------------------------------ */
typedef int bpxwdyn_fn(char *);
+#ifdef _LP64
#pragma linkage(bpxwdyn_fn, OS)
+#else
+#pragma linkage(bpxwdyn_fn, OS_UPSTACK)
+#endif
/**
* @brief Issue a BPXWDYN request, such as `alloc dd(in) da(x.y) shr`.
@@ -779,7 +788,8 @@ int sys_dynalloc(const char *request, char *msg, size_t msglen) {
return -1;
}
size_t len = strlen(request);
- char *text = malloc(len + 1);
+ /* BPXWDY2 is AMODE 31, so the request string must live below 2 GB. */
+ char *text = __malloc31(len + 1);
if (!text) {
snprintf(msg, msglen, "out of storage");
return -1;