diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 21:08:28 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 21:08:28 -0600 |
| commit | b9c2a4b5f138c3d7eff351f0c49aa6b631a9c1c8 (patch) | |
| tree | 8c5b5271057bf45dee2dc415162cd82668532952 | |
| parent | 642fbc02fb2a8e74d1e6663118d55110a9e5dfd7 (diff) | |
| download | ztop-b9c2a4b5f138c3d7eff351f0c49aa6b631a9c1c8.tar.gz | |
zvslist: fix the service call and build the stub with clang
Three separate faults kept the call from returning:
- the binder rewrites =A(zvslist) into a function descriptor in an
XPLINK module, so loading it into the base register sent every literal
and branch elsewhere; BALR alone is the base setup the assembler needs;
- WKAREA=((4),5) passes the literal 5 as the work-area length, not R5,
so the macro stored its control block at the start of a request it had
been told was five bytes long;
- FREE and UNALLOC are different macro expansions, not a runtime space
operand, so the stub now branches to power the right one.
Rename the source to src/zvslist.S and let ibm-clang assemble it, which
removes the chtag/column-71/EBCDIC dance from the build. With these
changes VSMLIST answers without an APF bit, so the docs no longer claim
otherwise, and the sample output is the real layout.
| -rw-r--r-- | DESIGN.md | 83 | ||||
| -rw-r--r-- | Makefile | 36 | ||||
| -rw-r--r-- | README.md | 18 | ||||
| -rw-r--r-- | src/zvslist.S (renamed from src/zvslist.s) | 32 |
4 files changed, 82 insertions, 87 deletions
@@ -9,34 +9,24 @@ the only documented interface that reports allocated storage by subpool for CSA, SQA, LSQA and the private area. Per subpool it returns the 4K-multiple blocks that hold allocations and the bytes allocated inside them. -## Authorization: APF, by design +## Authorization -This is an administrator's utility, so it is APF-authorized and uses -`VSMLIST` with `LINKAGE=SYSTEM`, the path the reference opens to an -authorized program (problem state, PSW key 8-15, `LINKAGE=BRANCH` would -want supervisor state and key 0 and is not used). +Not needed, as it turned out. `VSMLIST` was called with the default +`LINKAGE=SYSTEM` (PC-number path, problem state, PSW key 8) from an +ordinary HFS executable with no APF bit, and returned data. `D PROG,APF` +on CBT lists datasets only, so no HFS path could have been authorized +anyway. -Measured once without APF, on z/OS 3.1 (29.00), before the decision, and -kept here so nobody repeats it: +The earlier "SC78 R=90 on an unauthorized program" reading was wrong: the +abend came from a malformed work area. `WKAREA=(4,5)` is an address +constant, not a register pair, so the macro stored the literal 4 as the +subpool and the literal 5 as the work-area length, then wrote its control +block over the request. With `WKAREA=((4),(5))` the service is called +correctly and does not look at the caller's authority. -- `LINKAGE=SYSTEM`: `Possible Bad Branch` through the macro's PC-number path - (`L 15,16(0,0)` CVT, `+772` SVT, `+88`, `PC 0(15)`). -- `LINKAGE=BRANCH`: 0C1 at the `CVT+1140` branch entry, which is what the - reference promises for supervisor-state-only. -- `LINKAGE=SVC` (SVC 72): 0C4 inside the service. - -What the installation needs, none of it in the tool: - -- an APF-listed load path. `D PROG,APF` on CBT lists 54 entries and every - one is a partitioned data set -- no HFS directory is APF-authorized, so - one has to be added (PROGxx `APF ADD DSNAME('/some/dir')`, or - `SETPROG APF,ADD,DSNAME=...` at runtime) before an executable in the z/OS - UNIX file system can be marked; -- `extattr +ap` on the executable that lives there; -- a review of the program itself, because everything it does now runs with - the installation's authority. ztop only reads VSM data and writes to - standard output; it must not grow a feature that takes a path, a command - or a name from an untrusted caller without stripping authority first. +What still matters is that the program only reads VSM data and writes to +standard output; it must not grow a feature that takes a path, a command +or a name from an untrusted caller. ## What ZOAU already provides @@ -59,26 +49,38 @@ Rejected as sources, and why: ## Why assembler, and only there -`VSMLIST` is a macro: it builds a parameter list and issues an SVC, and -there is no C-visible entry point. So `src/zvslist.s` is the whole of the -system interface, one page, and everything else -- parsing, formatting, +`VSMLIST` is a macro: it builds a parameter list and calls a PC service, +and there is no C-visible entry point. So `src/zvslist.S` is the whole of +the system interface, one page, and everything else -- parsing, formatting, options -- is C23. No control-block offsets are written down anywhere: -the macro brings its own. +the macro brings its own. The `.S` suffix makes ibm-clang assemble the +file in-process; a separate `as` wants the source tagged and converted +to EBCDIC first. The C side calls it with `#pragma linkage(zvslist, OS)`; `OS_UPSTACK`, `__attribute__((OS))` and `OS31_NOSTACK` all abended at `-m32`, plain `OS` does not. HLASM upcases the entry name, so the C side binds `ZVSLIST` with `__asm__("ZVSLIST")`. -Two things about the stub that are not obvious and cost a day each: +Three things about the stub that are not obvious and cost a day each: - In an XPLINK load module an assembler CSECT is read-only. Reading a word - out of it works; the first store takes a 0C4. So the save area and every - scratch word live in the caller's block (`struct zreq`), and the CSECT - holds only code, the base register and the literal pool. +out of it works; the first store takes a 0C4. So the save area and every +scratch word live in the caller's block (`struct zreq`); the CSECT holds +only code and the literal pool. +- In an XPLINK load module the binder turns `=A(zvslist)` into a function +descriptor, and the loader fills that with an address that is not the +CSECT. Loading it into the base register made every literal and branch +go elsewhere (0C1, 0C4 or 0C7 depending on what happened to be there). +`BALR 12,0` plus the assembler's own `USING` is the whole of the base +setup; no address constant is needed. - `WKAREA=(4,5)` is read as an address constant, not a register: the macro - then generates `LA 1,4` and stores its control block at address 12. A - register operand needs the doubled form, `WKAREA=((4),5)`. +then generates `LA 15,5` and stores the literal 5 as the length. A +register operand needs the doubled form, `WKAREA=((4),(5))`. + +`SPACE` is not a runtime operand of the macro: FREE and UNALLOC are two +different expansions, which is why the stub branches to one or the other +before issuing it. ## Language level @@ -142,13 +144,14 @@ Three z/OS details are load-bearing: ## Open -- Live confirmation. The parser follows the documented layout and is - covered by synthetic data areas in `tests/test_vsm.c`, but no real - `VSMLIST` answer has been parsed yet: the executable is APF-marked and - still abends SC78 R=90 because no HFS directory is APF-listed. The - first run on an authorized system is the acceptance test for the framing. +- Live confirmation was the first acceptance test and passed: `ztop -a + csa`, `-a sqa`, `-a lsqa` and `-a pvt` returned data on CBT with the + parser reporting no warning. The 4K-block, free-descriptor and + unallocated streams match the layout above. - Area sizes for SQA, LSQA and the private area. `VSMLIST` reports allocation and free space, not the limit; a percentage there needs a different source, and none is planned. - `SP=PVT` output is already grouped by owning TCB, but the view still prints one list; per-TCB folding is a display change, not a data change. +- The full-screen view has been exercised on a Linux pty only; the first + run over a real SSH terminal is still to do. @@ -6,7 +6,6 @@ # ztop - what VSM has allocated, by subpool. # # make build ./ztop -# make apf build it and give the executable the APF bit # make check run it against each area # make clean remove what the targets above write # @@ -20,7 +19,6 @@ # parenthesised (make/tests on the ztop machine depend on that). CC = ibm-clang -AS = as CFLAGS = -std=c23 -O2 -m32 -Wall -Wextra -Wshadow -Wpedantic \ -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200112L # The parser and the TUI framework have no z/OS dependency; the test and @@ -28,13 +26,14 @@ CFLAGS = -std=c23 -O2 -m32 -Wall -Wextra -Wshadow -Wpedantic \ TESTCC = ibm-clang TESTFLAGS = -std=c17 -g -O1 -Wall -Wextra -Wshadow -Wpedantic \ -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200112L -# AC(1) is half of what makes an executable APF-authorized, the other -# half being the APF bit on the file (make apf). Quoted: the z/OS shell -# reads `(` in an unquoted word as a syntax error. +# AC(1) selects XPLINK. Quoted: the z/OS shell reads `(` in an +# unquoted word as a syntax error. LDFLAGS = -Wl,'-bAC(1)' -OBJ = src/zvslist.o -SRC = src/ztop.c src/vsm.c src/tui.c +# The .S suffix sends the stub through the compiler and its integrated +# assembler, which reads the ASCII source directly; a separate `as` +# would need the file tagged and converted first. +SRC = src/ztop.c src/vsm.c src/tui.c src/zvslist.S HDR = src/vsm.h src/tui.h all: @@ -42,25 +41,8 @@ all: { echo "ztop builds only on z/OS; this tree is a backup copy"; exit 1; } $(MAKE) ztop -ztop: $(SRC) $(HDR) $(OBJ) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SRC) $(OBJ) - -# The assembler reads HFS source through the file's coded character set -# tag; a git checkout arrives tagged UTF-8 and HLASM then reads the file -# as if it were EBCDIC ("SYNAD ... WRONG LEN RECRD"). Tag it as ASCII, -# and keep every statement inside column 71: column 72 is the -# continuation mark, and a long comment turns the next line into one. -# An explicit rule, not .s.o: z/OS make is happy with those and spins on -# a suffix rule for a file in a subdirectory. -src/zvslist.o: src/zvslist.s - chtag -t -c ISO8859-1 src/zvslist.s - @awk 'length > 71 { print FILENAME ":" FNR ": past column 71"; bad = 1 } END { exit bad }' src/zvslist.s - $(AS) -o src/zvslist.o src/zvslist.s - -# A relink drops the APF bit, so run this after every build. -apf: ztop - extattr +a ztop - ls -E ztop +ztop: $(SRC) $(HDR) + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(SRC) check: ztop ./ztop @@ -76,4 +58,4 @@ demo: tests/demo_tui.c src/tui.c src/tui.h $(TESTCC) $(TESTFLAGS) -o tests/demo_tui tests/demo_tui.c src/tui.c clean: - rm -f ztop $(OBJ) tests/test_vsm tests/demo_tui + rm -f ztop tests/test_vsm tests/demo_tui @@ -10,21 +10,25 @@ subpool key blocks used free mapped largest address CSF total: 17825792 bytes, 17121280 mapped (96.2% of mapped+unallocated) ``` -The numbers come from `VSMLIST`, the interface z/OS offers an authorized -program for exactly this. It is an assembler macro with no C equivalent, so -`src/zvslist.s` issues it and `src/vsm.c` parses the answer; `src/tui.c` is +The numbers come from `VSMLIST`, the interface z/OS offers for exactly +this. It is an assembler macro with no C equivalent, so +`src/zvslist.S` issues it and `src/vsm.c` parses the answer; `src/tui.c` is the terminal layer and `src/ztop.c` is the command. ## Build -z/OS only for the real binary, with IBM Open XL and HLASM in the path: +z/OS only for the real binary, with IBM Open XL in the path: ```sh -chtag -t -c ISO8859-1 Makefile # after a checkout: make reads it as text -make # ibm-clang -std=c23 -m32, plus `as` for src/zvslist.s -make apf # then give the executable the APF bit +make # ibm-clang -std=c23 -m32; the .S is assembled in-process +make check # run it against each area ``` +No APF bit and no special directory: `VSMLIST` was called successfully +from an ordinary HFS executable without `extattr`. (An earlier build did +abend SC78 R=90, but that was a malformed work area: the macro stores the +length itself unless the register is doubly parenthesised.) + The parser and the TUI framework have no z/OS dependency, so on any host with a C compiler and a terminal: diff --git a/src/zvslist.s b/src/zvslist.S index b773b23..927d0a5 100644 --- a/src/zvslist.s +++ b/src/zvslist.S @@ -20,13 +20,16 @@ * and the first store into it takes a 0C4. Only the base register and * the literal pool stay here, and both are read-only. * -* LINKAGE=SVC is used rather than the default SYSTEM: the PC-number -* path through CVT+772/+88 branches off to a bad address here, the -* branch entry does not. +* No address constant is loaded into the base register: in an XPLINK +* load module the binder turns =A(zvslist) into a function descriptor +* and the loader fills it with an address that is not this CSECT, so +* every literal and branch went to the wrong place. BALR alone sets a +* base the assembler can use. * * VSMLIST writes its control block into the first 32 bytes of the work * area and needs the register operand in doubled parentheses: with -* WKAREA=(4,5) the macro generates "LA 1,4" and stores at address 12. +* WKAREA=((4),5) the macro generates "LA 15,5" and stores the length +* at address 12, but with WKAREA=((4),(5)) it stores R5. * * The return code at work+0 is the service's own state: it must be zero * before the first call, and left alone for the continuation calls. @@ -40,7 +43,6 @@ zvslist RMODE 24 STM 14,12,12(13) BALR 12,0 USING *,12 - L 12,=A(zvslist) the macro needs a literal pool L 2,0(1) R2 -> struct zreq LR 11,2 R11 keeps it: services keep R11 LA 10,24(,2) our save area, in that block @@ -63,21 +65,25 @@ zvslist RMODE 24 CHI 3,4 BE PVT B OUT -CSA CHI 6,2 +CSA CHI 6,1 + BE CSAF + CHI 6,2 BE CSAU - VSMLIST SP=CSA,WKAREA=((4),5) +CSAF VSMLIST SP=CSA,SPACE=FREE,WKAREA=((4),(5)) B DONE -CSAU VSMLIST SP=CSA,SPACE=UNALLOC,WKAREA=((4),5) +CSAU VSMLIST SP=CSA,SPACE=UNALLOC,WKAREA=((4),(5)) B DONE -SQA VSMLIST SP=SQA,WKAREA=((4),5) +SQA VSMLIST SP=SQA,SPACE=FREE,WKAREA=((4),(5)) B DONE -LSQA VSMLIST SP=LSQA,WKAREA=((4),5) +LSQA VSMLIST SP=LSQA,SPACE=FREE,WKAREA=((4),(5)) B DONE -PVT CHI 6,2 +PVT CHI 6,1 + BE PVTF + CHI 6,2 BE PVTU - VSMLIST SP=PVT,WKAREA=((4),5) +PVTF VSMLIST SP=PVT,SPACE=FREE,WKAREA=((4),(5)) B DONE -PVTU VSMLIST SP=PVT,SPACE=UNALLOC,WKAREA=((4),5) +PVTU VSMLIST SP=PVT,SPACE=UNALLOC,WKAREA=((4),(5)) DONE LR 2,11 the struct, kept in R11 L 4,8(2) work area L 15,0(4) service return code |
