summaryrefslogtreecommitdiffhomepage
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
* z/OS: convert a script's character set only in an ASCII buildfix/zos-script-charsetSean Kurtz5 days1-1/+6
| | | | | | | | | | | | | | | | | input_push_fd() called sys_input_cvt() for every script on z/OS, and that routine converts to the program's own CCSID. In an ASCII build reading an IBM-1047 system it therefore either asked for EBCDIC-to-EBCDIC conversion, which is a no-op that returns 0, or read the bytes unconverted; SETCVTON on a descriptor that sys_dupfd() has renumbered returns 0 and converts nothing on this system either. The parser then saw EBCDIC and dropped the script. An EBCDIC build reads IBM-1047 natively and never wanted the call. With the conversion left to ASCII builds, posix/traps and scripts/signals pass on z/OS: 93 passed, 4 skipped, 0 failed. The untagged-file case still depends on SETCVTON with an explicit fccsid, which is unverified, so the VERIFY note stays.
* C23: nullptr for null pointers, constexpr for typed constantsSean Kurtz5 days31-240/+240
| | | | | | | | | | | | | | nullptr in every place a null pointer constant was meant; NULL is gone from src/. constexpr where it improves on #define without costing anything: the IGGCSI00 work-area offsets and sizes, and the scalar sizes MVS_DSN_MAX, CSI_FIELD_LEN, CSI_WORK_MIN, PDS_DIRBLK, CSI_WORK, CSI_MAX_CALLS. A constexpr in C is a constant expression, so it still bounds the arrays that use it, and it now carries a type and can be checked with static_assert. Feature switches (#if), the CSIETYPE/EBCDIC byte constants read as octets, and the related-constant enum sets stay as they were.
* C23: compile as C23 and use its spellingSean Kurtz5 days9-27/+19
| | | | | | | | | | | | | | | | | | | | | | | The z/OS toolchain would not take C23 when this was first written; IBM Open XL C/C++ 2.2 does (clang 21.1, __STDC_VERSION__ 202311), and so does the clang on Linux. -std=c23 in the Makefile, and the standard attributes in place of the ones that were macros: _Noreturn -> [[noreturn]] (on declarations and definitions) _Static_assert -> static_assert _Alignas -> alignas NODISCARD -> [[nodiscard]] FALLTHROUGH -> [[fallthrough]] PRINTFLIKE and UNREACHABLE() stay macros: [[gnu::format]] and [[gnu::unreachable]] are vendor attributes, and the standard has no [[format]] or [[unreachable]] for a header-only project yet. Standard-library additions newer than the libc of either system (<stdbit.h>, <stdckdint.h>) are not used, so gcc -std=c2x still builds the tree warning-free. The suite, ASan/UBSan and the z/OS lint pass as before; linux/i-dscomplete remains the one local failure it was on main.
* build: 64-bit on z/OSSean Kurtz5 days1-18/+19
| | | | | | | | | | | | | | | | | | The 31-bit choice existed for one reason: a 64-bit start cost 29 ms against 1 ms and a 64-bit fork() 4.2 ms against 0.10. That was the 64-bit C run-time being loaded out of CEE.SCEERUN2 on the linklist on every start; with CELQ* in the dynamic LPA both widths cost 1.5 ms and fork() 0.10 ms (notes/investigation.md has the before and after). So build the shell at the width IBM builds for: -m64 for both the ASCII and the EBCDIC build, and for the debug build. OS_UPSTACK does not exist at -m64, so the two AMODE 31 services (IGGCSI00, BPXWDY2) are declared with plain OS linkage, which is what the 64-bit glue implements. IGGCSI00's VL bit is set from the width of a pointer now, not with 0x80000000. Neither module loads on this system, so the linkage itself stays unverified; csi_call() still traps a program check and retires the catalog if it abends.
* z/OS: keep a close-on-exec pipe out of the child's fd mapSean Kurtz7 days1-5/+34
| | | | | | | | | | | | | | | | | | | | | | | sys_pipe() duplicates the shell's pipe ends above SYS_NFD and marks them FD_CLOEXEC, so that other children do not inherit them. spawn()'s fd_map hands the child the parent's descriptor as it is, without clearing the flag the way dup2() would, so a mapping onto the child's 0..2 carried FD_CLOEXEC into the child. The child could still write, but the next exec inside it lost stdout: ps printed FSUM6004 write error on standard output: EDC5113I Bad file descriptor and a #!/bin/sh shim lost the pipe it was given. Pass a plain duplicate, which fcntl F_DUPFD makes above SYS_NFD without the flag, for every map entry that names a different descriptor, and close the duplicates once spawn() has made the child. Entries that map a descriptor onto itself are untouched. tests/zos/fdmap.sh records the case: a pipe the shell made, read by a child that execs. Reported in #1.
* z/OS: run 31-bit and load IGGCSI00 through the C librarySean Kurtz7 days5-209/+135
| | | | | | | | | | | | | zash was AMODE 64, so calling the AMODE 31 IGGCSI00 needed assembler glue (zos_csi.s) that switched addressing mode around the branch. Built with -m32 the program is 31-bit itself: the call goes through a plain function pointer, the work area and the saved registers live in one 31-bit block in C, and the glue is gone. The rest of the tree follows the change: the build, the off-z/OS lint shim, DESIGN.md and README.md, the benches, the Lean spec of the pattern matcher, and the tests that recorded what the extra address bits had changed.
* added new benches, the logo, and a formal spec for possible verification.Sean Kurtz10 days1-1/+1
|
* docs: say 31-bit, not below the barSean Kurtz11 days1-1/+2
| | | | | | "Below the bar" means below 16 MB, the 24-bit range. IGGCSI00 needs 31-bit addresses, so the block has to stay below 2 GB -- two very different limits. Corrected where the two had been confused.
* z/OS: load IGGCSI00 once and keep the block for the shellSean Kurtz11 days3-72/+120
| | | | | | | | | | | | | | | | | | | | The search interface was reached through LINK, which asked the system to find and attach the module on every call -- and completion issues a call per Tab. The glue now LOADs the module on the first call, writes its entry point into the block, and branches to it directly afterwards, and the block itself is taken from 31-bit storage on the first search and kept, because IGGCSI00 is AMODE 31 and all three of its addresses have to stay below 2 GB. The block is declared packed, so the compiler cannot add padding the assembler's offsets do not know about, and aligned(8), so the save area starts on a doubleword. Its name field is spelled in IBM-1047 bytes rather than as a C string, so the module is named the same way whatever character mode this build runs in. Verified on the machine: SYS1.MA* returns SYS1.MACLIB, SYS1.* returns 135 names, and Tab in an interactive shell completes //'SYS1.MA to //'SYS1.MACLIB' and lists the members of that PDS.
* docs: keep the source ASCII, which the z/OS working tree needsSean Kurtz11 days1-1/+1
|
* exec: run a subshell in process when its body cannot change anythingSean Kurtz11 days2-1/+41
| | | | | | | | | | | | | | A `fork()` copies the address space on z/OS, where a `spawn()` can share it. The subshell row measured 4.7 ms a turn there against 0.3 ms for an external command, and ksh88 does not fork for `( : )` at all. The pipeline stage check already answered the safety question with is_pure(), so a subshell whose body is one output-only builtin with no redirections and no assignments reuses the answer and runs in the shell. Expansion of the arguments is wrapped in the same capture scope a pipeline stage uses, so ${x=1} no longer escapes. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* docs: say it in short sentencesSean Kurtz12 days30-184/+185
| | | | | | | | | | | | | DESIGN.md, README.md and the Doxygen comments leaned on semicolons to join clauses and on trailing "which" clauses to add afterthoughts. Both read as machine-written prose. Each joined clause is now its own sentence, and the afterthoughts are either part of the sentence or a sentence of their own. Also corrected: README said C11 in two places (the tree builds C17), the completion section still described the pre-HLQ-rule filters and the 64-call resume limit, and the z/OS job-control note still called SPAWN_SETTCPGRP unverified.
* completion: no catalog search until a high-level qualifier is completeSean Kurtz12 days3-9/+73
| | | | | | | | | | | | | | | A filter whose first qualifier is generic makes Catalog Management resolve aliases generically, and the manual warns that a generic high-level qualifier can select several catalogs at once: a high-level of "**" means every user catalog. Tab is no reason to ask that of the catalog address space, so completion waits until a whole high-level qualifier is typed before it searches at all. The searches are narrower too: entry types U (user catalog connector) and X (alias) are excluded, since they are not data set names; the required return-area length is checked before a resume, as Managing Catalogs asks; and the editor lists at most one screenful of candidates, with a count of the rest, instead of a fixed 200.
* z/OS: one catalog per completion search, and stop after two callsSean Kurtz12 days2-2/+21
| | | | | | | | | | | | | | CSIS1CAT keeps a generic high-level qualifier from fanning a Tab key out over every alias it matches plus the master catalog, which is what Managing Catalogs warns about for CSIFILTK with generic filters. Two IGGCSI00 calls already return about 2200 names -- one call fills the 64000-byte work area with ~1100 -- so 64 was sweeping a whole catalog per keystroke for names no screen could show. Also: `//'<tab>` searched for "*" and "*.*" before the filter check refused them; it now returns before allocating anything, and tests/run.sh can compare an EBCDIC build's transcript against a .ebcdic.exp.
* z/OS: test a spawn with the script's whole descriptor range openSean Kurtz12 days1-11/+3
| | | | | | | A script owns descriptors 0..SYS_NFD-1 and the shell's own live above them, so filling 3..9 is as far as a script can go; the spawn map keeps the terminal duplicate reachable past them. The earlier '64' map was guessing at a case the shell cannot present: back to SYS_NFD+16.
* z/OS: bound the below-the-bar storage CSI completion usesSean Kurtz12 days2-7/+17
| | | | | | One 64 KB block, freed before the search returns, and a nested search is refused rather than given a second one. The second catalog search is skipped once the candidate list is full.
* z/OS: a wider spawn map, and the suite runs both buildsSean Kurtz12 days1-3/+11
| | | | | | | | | The map carried SYS_NFD+16 descriptors, so a script holding more pushed the terminal's duplicate out of reach and its commands lost the controlling terminal. 64 leaves room. `make zos-check` now builds the EBCDIC program too and runs the character-set tests against it, which nothing did before.
* completion: bound the name before searching for itSean Kurtz12 days1-1/+2
| | | | | | GCC's -Wformat-truncation is right: the search patterns are built from the typed word, so check its length first. The pwd.h include went with the HLQ code it served.
* completion: stop guessing the HLQ for a bare //NAMESean Kurtz12 days1-56/+16
| | | | | | | `//NAME` completed against <user>.NAME, which meant assuming a TSO profile. It now offers nothing: only `//'DSN` and `//DD:` complete. The quoted member form keeps working, and the tests drop the relative cases.
* input: a tty that answers lseek() is still a ttySean Kurtz12 days1-3/+3
| | | | | | | | | A z/OS terminal is seekable, so stdin was classified as a script: no prompt, no line editing, no `bind`, just the driver's own echo. Ask isatty() first; only a non-tty can be seekable. Found with ~/tmp/tty.c on cbt: on a pty `isatty(0)=1 isatty(2)=1 seek=1`.
* editor: `bind`, and prompts that take bash's \[ \] markersSean Kurtz12 days5-14/+221
| | | | | | | | | | | | | | `bind -l` lists the actions the editor can run and `bind '^[[H'=beginning-of-line` gives one to a key sequence, in the notation the BSD shells use. Only the names edit_key() already knows are accepted, so a binding cannot do anything a key could not; `-m` (macro) is refused rather than ignored. The defaults stay bash's: this is for people whose .kshrc moves the arrow keys, not a move towards ksh. `\[` and `\]` in PS1 say "this part does not move the cursor". The width rule already skips control sequences, so dropping the markers is the whole implementation, and a coloured prompt now shows its text instead of the markers.
* editor: rewrap a header comment to 80 columnsSean Kurtz12 days1-4/+4
|
* z/OS: keep the terminal descriptor open for spawnSean Kurtz12 days1-2/+18
| | | | | | | | | | | | spawn() sets the child's foreground process group from inherit.ctlttyfd after it has closed every descriptor from fd_count up, so the shell's terminal descriptor -- which lives above the script's five or so -- was already gone by then. Every external command in an interactive shell died with EDC5113I Bad file descriptor, while the same command outside a terminal worked. Carry the terminal descriptor in the fd map, so the child has it open for exactly the tcsetpgrp() spawn() performs.
* edit_builtin: the emacs keys bash users reach forSean Kurtz12 days1-2/+72
| | | | | | | | meta-u, meta-l and meta-c change the case of a word, meta-t transposes the words either side of the cursor, meta-. inserts the last word of the previous line and meta-\\ collapses the blanks around the cursor. The rest of the map was already bash's: a BSD sh or a bash prompt is the target, not ksh's.
* sys_zos: no /* inside the block commentSean Kurtz12 days1-2/+2
| | | | | -Wcomment is right: a path spelled tests/zos/* starts a nested comment marker.
* zos_csi: keep the equates comment short and the file Latin-1Sean Kurtz12 days1-2/+1
| | | | | | HLASM wants every line inside column 71, so a two-line comment overran the continuation column and as reported ASMA144E. DESIGN.md picked up an em dash, which will not convert to the z/OS working-tree encoding either.
* zos_csi: name the registers the way HLASM sources doSean Kurtz12 days1-11/+32
| | | | | Equates at the bottom (R0 EQU 0 ... R15 EQU 15) and R<n> in every operand field, so the code reads as registers rather than numbers.
* Say the z/OS layer has been built and run thereSean Kurtz12 days3-6/+8
| | | | | | | | The docs and three source headers still claimed the z/OS layer had never been compiled. Both character modes build with ibm-clang, tests/zos/* run it on the machine, LE's heap checker stands in for ASan, and AMBLIST shows the CSI glue inside the program object. What is left is the set of things no test reaches, which the VERIFY notes already name.
* Read startup files like the interactive shell they belong toSean Kurtz12 days3-3/+12
| | | | | | | | | | | A failing line in $ENV ended the shell: run_input() only installed its recovering handler for the main loop, so sh_error() found no handler and called exit_shell(). An interactive shell must not exit for a command that fails (POSIX 2.5.3), and a .kshrc shared with ksh is full of lines zash rejects. Startup files now run with RI_RECOVER, which recovers from an error without printing a prompt, and the rest of the file is still read.
* Fuzz the CSI search cursor and the name and byte-map helpersSean Kurtz12 days1-3/+3
| | | | | | | | | | | | The first byte now selects among six paths. Two new ones: csi_search() driven by a fake IGGCSI00 that hands back the fuzz bytes and may ask for a resume, at both the minimum work area length and three bytes more; and mvs_name(), mvs_from_ebcdic() and mvs_to_ebcdic() over exactly-sized heap buffers, so an off-by-one in trimming or in the 44-byte name fields is caught by ASan. 90 seconds, about 60 million executions, no ASan or UBSan report. src/builtin.c's hunk is clang-format reflowing the previous change.
* sys_info: return empty when an MVS control block is absentSean Kurtz12 days1-2/+10
| | | | | | | CVT, ASCB and now ECVT were dereferenced without a check; a null there would be an S0C4 in 'sysinfo', in 'read -t' timeouts and at job-table refresh. A shell may run where PSAAOLD or the ECVT pointer is not set, so report an empty field as sys_info() already does for a null job name.
* read -t: do not wait for a descriptor that cannot blockSean Kurtz12 days1-2/+13
| | | | | | | z/OS never reports /dev/null as readable, so read -t 1 v </dev/null sat out the whole timeout and returned 128+SIGALRM instead of end of input (1). A regular file or a character device that is not a terminal is read straight away; a terminal still waits on poll().
* Set and export PWD when the environment has noneSean Kurtz12 days2-2/+6
| | | | | | | z/OS non-interactive logins start the shell without PWD, so $PWD was empty: cd worked but PATH=$PWD/bin pointed at /bin, and the purebuiltin pwd check failed. Initialise it from getcwd() and keep PWD/OLDPWD exported when cd sets them.
* zos_csi.s: keep the comment line inside HLASM's 71 columnsSean Kurtz12 days1-1/+1
| | | | | Column 72 is the continuation column; a 72-character comment line made the assembler stop with ASMA144E.
* zos build changesSean Kurtz13 days1-1/+33
|
* z/OS ASCII build: convert own I/O to IBM-1047 on pipes, here-docs, ↵Sean Kurtz13 days1-5/+36
| | | | redirects, std streams
* change __free31()s to free is sys_zos.cSean Kurtz13 days1-2/+2
|
* Fixes for z/OS build and signals.Sean Kurtz13 days1-2/+3
|
* fix issues with z/os build, header visibility, signalsSean Kurtz13 days5-5/+77
|
* More progress, modifications to vscode working environment. Integrated ↵Sean Kurtz13 days5-9/+82
| | | | terminal work.
* Hardening: ENV expanded and ignored for set-ID shells; no truncated profile pathSean Kurtz13 days3-6/+32
| | | | | | | POSIX: ENV is parameter-expanded, and not used when the real and effective user or group IDs differ. The expansion reuses the prompt's contained expansion (expand_quietly), so a bad ENV cannot unwind into startup. $HOME/.profile is not sourced if the path would be truncated.
* z/OS builtins: tag, alloc, freeSean Kurtz2026-11-153-0/+156
| | | | | | | | tag shows and sets file tags in chtag -p form without a process; alloc and free pass BPXWDYN requests. They exist only in z/OS builds (free must not hide procps elsewhere) and in make mvs-asan's build, which runs their usage-error test; tests/zos/builtins.sh covers the real work (unrun, VERIFY).
* z/OS: file tagging, catalog completion, time, and per-command optionsSean Kurtz2026-11-1520-10/+2158
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Tagging and conversion (sys_zos.c, redir.c, input.c, var.c, exec.c): - _TAG_REDIR_IN/OUT/ERR as /bin/sh documents them, cached by variable hooks so redirection tests a byte; honoured as a prefix on external commands and on pipeline stages. - ASCII builds tag new output and here-document files as text, tag pipes IBM-1047 (set +o pipetag to stop), and switch on autoconvert. - Scripts, . files, profile and ENV are read in either character set: tagged files get F_CONTROL_CVT, untagged ones are sniffed. - tag/chtag primitives (sys_tag_get/sys_tag_set) for a builtin to come. Data set completion (complete.c, mvsfmt.[ch], zos_csi.s): - //'HLQ.PART, "//'HLQ.PART, //NAME (user HLQ), //'DSN(MEM, //DD:NAME complete one qualifier at a time from the Catalog Search Interface, PDS directories and the TIOT. - IGGCSI00 is called through HLASM glue that switches to AMODE 31 and keeps every register and parameter below the bar (VERIFY). - The work-area, directory and TIOT decoders are portable and run on Linux against a stand-in catalog that produces the real EBCDIC bytes, including CSI resume and directory-block splits; fuzzed with libFuzzer (make fuzz). - A lone completion inside quotes now closes the quote. Other z/OS features: - time [-p] keyword with shell/children CPU split. - set -o jobnames (_BPX_JOBNAME per command), set -o shareas (_BPX_SHAREAS=YES for foreground commands only), set -o msgid (ZSHnnnnE/W message IDs), ulimit -M (MEMLIMIT), ZOS_SYSNAME, ZOS_SYSPLEX, ZOS_RELEASE, ZOS_ASID, ZOS_JOBNAME, prompt \S. - BPXWDYN entry point for an alloc builtin to come. Checking z/OS code off z/OS: - make zos-lint compiles sys_zos.c against declarations transcribed from the z/OS headers, and the rest with the MVS paths forced on. - make mvs-asan runs the suite with the MVS paths on, under ASan/UBSan. - make asan and make valgrind now check for leaks.
* Errors in command-prefixed special builtins no longer exit; no arena leakSean Kurtz2026-11-151-3/+61
| | | | | | | | | | | | | | `command eval`, `command .` and friends lose the special property that an error exits a non-interactive shell (POSIX 2.14, and dash, bash and ksh93 agree): the error now becomes the status. Only that path pays for a setjmp(). run_input() released its parse arena only on the normal path; an error caught further out (a subshell, command, the prompt) leaked it. Found by running the suite under Valgrind with leak checking, which is now on for make valgrind and make asan. Also renames two locals that shadowed the cond typedef (gcc -Wshadow).
* arith: stop scan_binop reading past the end; keep setjmp off the fast pathSean Kurtz2026-11-152-32/+64
| | | | | | | | scan_binop() read p[1] when p[0] was the terminating NUL: a one-byte heap overread found by ASan when a variable's value is evaluated as an expression. The setjmp() for that evaluation moves to an out-of-line helper; inside var_value() it cost 12M instructions in bench/loop.sh. Adds NOINLINE.
* Add [[ ]], make coverage, and fixes found by edge-case testsSean Kurtz2026-11-1514-36/+704
| | | | | | | [[ ]] is parsed into a tree and evaluated without argv or lookup. Fixes: errexit inside a tested subshell, the ${x:?} message, arithmetic on variables holding expressions, printf %c of an empty argument, job text for arithmetic, and \n and \e prompt escapes.
* Add extensions, job control and the interactive layer; convert to C11Sean Kurtz2026-11-1334-1326/+8714
| | | | | | | | | | | | | | | | | Language: $'...', aliases, function keyword, (( )) and let, typeset and integer, print, whence, setvar, ulimit, read -t, RANDOM, SECONDS, the ERR trap, trap -p, chdir, and more set -o names. Job control: a job table, process groups, terminal hand-over through the spawn layer, jobs/fg/bg, wait %n and kill %n. Interactive: prompt expansion, a built-in line editor with emacs and vi modes, completion, history with fc and HISTFILE, and libedit as a compile-time alternative (make EDIT=libedit LDLIBS=-ledit). The source is now C11 (was C23), uses typedef'd structs and enums, and has Doxygen comments throughout. Adds .clang-tidy, .clangd and a Doxyfile.
* zash: scripting core, test suite and benchmarksSean Kurtz2026-11-1223-0/+8038
A clean-slate POSIX shell for z/OS UNIX in the Almquist tradition, written in C23 for Clang (Linux) and IBM Open XL C/C++ (z/OS). - Parser, expansion, arithmetic, redirection, traps and builtins. - Spawn-first execution: fd plans instead of fork+dup2, in-shell pure builtins for pipelines and command substitution, $(a | b) without a subshell. - Flat .POSIX Makefile; asan, valgrind, bench, compdb and z/OS targets. - Tests: posix (dash-generated), zash, process accounting, linux, zos. Nothing has been compiled or run on z/OS yet.