v4 ACL: the countdown at call, as v3 -- the call hook may redirect
Build / Image PC (push) Successful in 6m13s
Build / Image MILKV (push) Successful in 6m40s
Build / v4 tests (32- and 64-bit cells) (push) Successful in 14m18s
Build / Image RASPI (push) Successful in 3m11s

Captain Bob ruled "As v3: add at call", "Engine: call redirects" and
"Build it".
- The engine's call hook returns where P goes.
- The kernel checks every call from code defined at run time. A TTL is
  counted down at the call. At a TTL of 0, or a denied word, the call is
  sent to (ACL-CALL), with the target on the data stack, which rechecks
  or refuses it by the word's own name, then goes on to it.
- A word being compiled is no longer checked, as in v3.

Two things were added while building, both from v3:
- (ACL-BUSY) turns the check off while the policy rechecks. Without it
  the recheck recursed.
- (ACL-CALL) does its own refusal and leaves WORD's buffer alone. A first
  version broke POST's CONVERT.digits.

Test first: test_mesh_boot's five new checks failed before; now 120 pass
and POST is 990/990. test_exec tests the redirect. test_host_quit's two
v4-only expectations now follow v3: a denied word compiles.

All 52 tests, test-32 and ASan/UBSan pass. An amd64 session passes 18/18.
Five alternating host boots: +1.4% median, inside the noise.
DECOMPOSITION.md 5.20 is updated, and the FPGA's call opcode is recorded
as owing the same redirect.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-19 14:10:16 +00:00
parent 666cf39b8b
commit 7af88cc704
30 changed files with 1383 additions and 35 deletions
+5 -2
View File
@@ -41,8 +41,11 @@
#include "v4/node.h"
/* Called at `call` once the return address is pushed and before P moves to the
* target (so P is still the return address). NULL: no hook. */
typedef void (*v4_call_hook)(void *ctx, v4_node *n, v4_cell target);
* target (so P is still the return address). It returns where P goes: the
* target, or another address the call is sent to instead, which returns to the
* caller as the target would (the ACL's check at call, docs/v4.0.0/plans/
* 2026-11-19-acl-at-call.md). NULL: no hook, and P goes to the target. */
typedef v4_cell (*v4_call_hook)(void *ctx, v4_node *n, v4_cell target);
/* Called when an instruction retires, after HEAT-OP counts it, with its opcode (0..31): compudynamics on the
* opcodes (#189 Phase 7, ruling 7). NULL: no hook. */
+4
View File
@@ -83,6 +83,10 @@ typedef struct {
* defined at run time, from which a call is a word run; and where INTERPRET and EXECUTE make their calls */
v4_cell tokens, dict_lo, dict_hi, runx, exec;
/* the ACL's check at call (docs/v4.0.0/plans/2026-11-19-acl-at-call.md): the cell that holds (ACL-CALL)'s address,
* and the cell that is 1 while the policy rechecks a word */
v4_cell acl_call, acl_busy;
/* the block window: the word address of the slots the kernel copies
* blocks into (v4/blocks.h) */
v4_cell block_window;
+1 -1
View File
@@ -137,7 +137,7 @@ void v4_exec_op(v4_node *n, v4_exec_state *es, v4_heat *h,
case V4_OP_CALL:
x = v4_iword_branch(n->p, w, slot);
v4_rstack_push(rs, n->p);
if (es->on_call) es->on_call(es->on_call_ctx, n, x);
if (es->on_call) x = es->on_call(es->on_call_ctx, n, x);
n->p = x;
break;
case V4_OP_UNEXT:
+26 -3
View File
@@ -695,7 +695,28 @@ static void heartbeat_cycle(unsigned place, v4_mesh_physics *p)
/* at `call` (exec.h), on a word -- any other target, nothing -- in v3's order (physics_pre_execute,
* V3-PARITY.md 2.1; Captain Bob, 2026-11-13: "Every call, as v3"): decay by the ticks since, heat +1,
* the count the Stadium is charged by, the temperature, the rolling window */
static void on_call(void *ctx, v4_node *n, v4_cell target)
/* The ACL's check at a call from code defined at run time (docs/v4.0.0/plans/2026-11-19-acl-at-call.md), as v3's
* inner interpreter: the word's flags cell (compile.f18: bit 5 denied, bits 16 .. 31 the TTL). An allowed word
* with TTL left is counted down here, and the call goes on; at a TTL of 0, or a denied word, the call is sent to
* (ACL-CALL), the target on the data stack, which rechecks or refuses it in FORTH and goes on to the word. While
* the policy rechecks a word ((ACL-BUSY) 1) nothing is checked, as v3 runs its policy with the check off. */
static v4_cell acl_at_call(v4_node *n, const v4_image *im, v4_cell target)
{
v4_cell flags, to;
if (im->acl_call <= 0 || im->acl_busy <= 0 || n->mem[im->acl_busy] != 0) return target;
to = n->mem[im->acl_call];
if (to <= 0 || to >= (v4_cell)V4_NODE_WORDS || target < 4) return target;
flags = n->mem[target - 3];
if ((flags & (v4_cell)0xFFFF0000) != 0 && (flags & 32) == 0) {
n->mem[target - 3] = flags - (v4_cell)0x10000; /* one use fewer */
return target;
}
if (n->ds.depth >= V4_DATA_RING + 2u) return target; /* no room for the target: as no check */
v4_dstack_push(&n->ds, target);
return to;
}
static v4_cell on_call(void *ctx, v4_node *n, v4_cell target)
{
unsigned place = place_of_device(ctx);
v4_cell id, ret = n->p; /* P is still the return address (exec.h) */
@@ -706,9 +727,9 @@ static void on_call(void *ctx, v4_node *n, v4_cell target)
* system's own calls among its words (v3's are C) */
from_code = (ret >= im->dict_lo && ret < im->dict_hi) || ret == im->exec + 1;
dispatched = ret == im->runx + 1;
if ((!from_code && !dispatched) || !is_word(place, target)) return;
if ((!from_code && !dispatched) || !is_word(place, target)) return target;
id = n->mem[target - 4];
if (id < 0 || id >= (v4_cell)V4_MESH_WORD_IDS) return;
if (id < 0 || id >= (v4_cell)V4_MESH_WORD_IDS) return target;
a = &accounts_of(place)[id];
if (the->physics) {
v4_mesh_physics *p = &the->physics[place];
@@ -731,6 +752,8 @@ static void on_call(void *ctx, v4_node *n, v4_cell target)
}
a->calls++;
a->since++;
/* INTERPRET's own dispatch is checked by (ACL?) before it is made: only calls from code are checked here */
return from_code ? acl_at_call(n, im, target) : target;
}
void v4_mesh_set_tick(v4_mesh *ms, uint64_t tick)
+10 -2
View File
@@ -127,8 +127,14 @@
#define ROM_IMG (BUF0_W - 119) /* idle, fault table, KEY, the word after KEY: 4 cells */
#define EXEC_W (BUF0_W - 22) /* (EXEC): EXECUTE's `call xt`, and the ; after it (compile.f18; #189) */
#define RUNX_W (BUF0_W - 115) /* (RUNX): INTERPRET's `call xt`, and the jump back (compile.f18; #189) */
/* FREE, plain memory: BUF0_W - 113; BUF0_W - 144 .. - 141 (what a flush makes zero after
* a full output buffer); and OUT_W - 144 .. OUT_W - 65. They and
/* The ACL's check at call (docs/v4.0.0/plans/2026-11-19-acl-at-call.md): where (ACL-CALL) is, which the kernel sends
* a call to when the word's TTL is 0 or it is denied; and 1 while the policy rechecks a word, when the kernel checks
* nothing (v3's acl_recheck runs its policy so). A full output buffer's flush zeroes BUF0_W - 144 .. - 141: (ACL-BUSY)
* zeroed is only its default, and costs one more level of recheck at most. */
#define ACL_CALL_W (BUF0_W - 113) /* (ACL-CALLX): the code address of (ACL-CALL), stored by end.f18 */
#define ACL_BUSY_W (BUF0_W - 144) /* (ACL-BUSY): 1 while (ACL-RECHECK) runs the policy */
/* FREE, plain memory: BUF0_W - 143 .. - 141 (what a flush makes zero after
* a full output buffer). They and
* the cells above held the messages waiting, the refusals owed and what went with them (MESH.md 7a, 7b), which a
* node no longer keeps. */
#define AWAIT_FROM (BUF0_W - 39) /* the node whose word of how text ended is waited for */
@@ -384,6 +390,8 @@ static unsigned host_branch_slots(void)
X("HEAT-OP", HEAT_REG) \
X("(EXEC)", EXEC_W) \
X("(RUNX)", RUNX_W) \
X("(ACL-CALLX)", ACL_CALL_W) \
X("(ACL-BUSY)", ACL_BUSY_W) \
X("ANTICLOCK", HEAT_REG + 32) \
X("CFBASE", CFS_W) \
X("CFEND", CFS_W + CFS_CELLS)
+25 -1
View File
@@ -575,12 +575,21 @@ static void test_address_faults(void)
* is pushed and before P moves; with no hook the node runs exactly as before. */
static v4_cell seen[8];
static unsigned nseen, hook_bad;
static void record_call(void *ctx, v4_node *nd, v4_cell target)
static v4_cell record_call(void *ctx, v4_node *nd, v4_cell target)
{
if (ctx != (void *)&seen || nd != &n) hook_bad++;
if (nd->p != nd->rs.r) hook_bad++; /* P not moved yet: still the return address */
if (nseen < 8) seen[nseen] = target;
nseen++;
return target; /* the call goes where it was going */
}
/* a hook that sends the call to 300 instead, when it is for 200 (the ACL's redirect, 2026-11-19) */
static v4_cell redirect_call(void *ctx, v4_node *nd, v4_cell target)
{
(void)ctx; (void)nd;
if (nseen < 8) seen[nseen] = target;
nseen++;
return target == 200 ? 300 : target;
}
static void call_programme(void) /* 100, 200, 100 again, 300; then a halt loop */
@@ -620,6 +629,21 @@ static void test_call_hook_sees_every_call(void)
"with no hook the node runs the same (P %ld/%ld, depth %u/%u, retired %u/%u)",
(long)p_plain, (long)p_hooked, depth_plain, depth_hooked, retired_plain, retired_hooked);
CHECK(es.on_call == 0, "v4_exec_reset leaves no hook");
/* the hook may send the call elsewhere: where it returns is where P goes, and the return address is
* the one the call pushed, so the place it is sent to returns to the caller */
call_programme();
n.mem[300] = word6(V4_OP_SEMI, NOP, NOP, NOP, NOP, NOP);
es.on_call = redirect_call; es.on_call_ctx = 0;
nseen = 0;
v4_exec_step_word(&n, &es, &h); /* call 100, ; */
v4_exec_step_word(&n, &es, &h);
v4_exec_step_word(&n, &es, &h); /* call 200 -- sent to 300 */
CHECK(n.p == 300 && n.rs.depth == 1 && n.rs.r == 12, "a hook that returns 300 for a call to 200 sends it to 300 (P %ld, R %ld)",
(long)n.p, (long)n.rs.r);
v4_exec_step_word(&n, &es, &h); /* 300's ; */
CHECK(n.p == 12 && n.rs.depth == 0, " which returns to the caller, after the call (P %ld)", (long)n.p);
v4_exec_reset(&es);
}
/* the hook at retire (#189 Phase 7, ruling 7: compudynamics on the opcodes): every retired instruction, its opcode,
+2 -1
View File
@@ -72,11 +72,12 @@ static void new_session(void)
static int watching;
static v4_cell called[4096];
static unsigned ncalled;
static void record_call(void *ctx, v4_node *nd, v4_cell target)
static v4_cell record_call(void *ctx, v4_node *nd, v4_cell target)
{
(void)ctx; (void)nd;
if (ncalled < sizeof called / sizeof called[0]) called[ncalled] = target;
ncalled++;
return target;
}
static unsigned times_called(v4_cell xt)
{
+6 -4
View File
@@ -735,10 +735,12 @@ static const transcript script[] = {
{ "' DUP ACL-TTL@ . ' DUP ACL-MODE@ . ' DUP ACL-ALLOW@ . ' DUP ACL-PINNED? .\n", "0 0 -1 0 ok\nok> ", 1 },
{ ": FOO 65 EMIT ; 5 ' FOO ACL-TTL! 0 ' FOO ACL-ALLOW! 1 2 FOO 66 EMIT\n.S ' FOO ACL-TTL@ .\n",
"\033[33mWARN: \033[0mACL: denied 'FOO'\n ERROR\nok> <0> \n4 ok\nok> ", 1 },
/* v4's own: the TTL is sixteen bits; a denied word cannot be compiled; with no policy a recheck allows */
/* v4's own: the TTL is sixteen bits; with no policy a recheck allows. A denied word can be compiled, as v3
* (2026-11-19): the check is at its call, which is the kernel's (v4/system/mesh.c; test_mesh_boot.c checks it),
* and this host node has no kernel watching its calls -- so here the definition runs it */
{ ": BAZ 67 EMIT ; 0 ' BAZ ACL-ALLOW! BAZ ' BAZ ACL-TTL@ . ' BAZ ACL-ALLOW@ .\n", "C65535 -1 ok\nok> ", 0 },
{ ": FOO 65 EMIT ; 5 ' FOO ACL-TTL! 0 ' FOO ACL-ALLOW! : BAR FOO ; 66 EMIT\nBAR\n' FOO ACL-TTL@ .\n",
"\033[33mWARN: \033[0mACL: denied 'FOO'\n ERROR\nok> UNKNOWN WORD: 'BAR'\n ERROR\nok> 4 ok\nok> ", 0 },
"B ok\nok> A ok\nok> 5 ok\nok> ", 0 },
{ ": FOO 65 EMIT ; : BAR FOO ; 5 ' FOO ACL-TTL! 0 ' FOO ACL-ALLOW! BAR\n", "A ok\nok> ", 0 },
{ "99999 ' DUP ACL-TTL! ' DUP ACL-TTL@ . 65535 ' DUP ACL-TTL! ' DUP ACL-TTL@ .\n", "65535 65535 ok\nok> ", 0 },
{ "258 ' DUP ACL-MODE! ' DUP ACL-MODE@ . 0 ' DUP ACL-ALLOW! ' DUP ACL-ALLOW@ .\n7 ' DUP ACL-ALLOW! ' DUP ACL-ALLOW@ . ' DUP ACL-TTL@ .\n", "2 0 ok\nok> -1 0 ok\nok> ", 0 },
@@ -1651,8 +1653,8 @@ int main(void)
CHECK(is(say("0 ' FOO ACL-TTL! FOO\n"), "A ok\nok> "), "and when its TTL runs out the policy is asked again: this one allows");
CHECK(is(say(": NOFOO DUP ['] FOO = IF 0 SWAP ACL-ALLOW! ELSE ACL-RECHECK THEN ;\n"), " ok\nok> ")
&& is(say("' NOFOO ACL-HOOK ! 0 ' FOO ACL-TTL!\n"), " ok\nok> "), "a policy that denies one word");
CHECK(is(say("69 EMIT FOO\n"), "E\033[33mWARN: \033[0mACL: denied 'FOO'\n ERROR\nok> ") && is(say("SFOO : G FOO ;\n"), "B\033[33mWARN: \033[0mACL: denied 'FOO'\n ERROR\nok> ")
&& is(say("1 2 + . SFOO\n"), "3 B ok\nok> "), "that word is refused, interpreted or compiled, and nothing else is");
CHECK(is(say("69 EMIT FOO\n"), "E\033[33mWARN: \033[0mACL: denied 'FOO'\n ERROR\nok> ") && is(say("SFOO : G FOO ;\n"), "B ok\nok> ")
&& is(say("1 2 + . SFOO\n"), "3 B ok\nok> "), "that word is refused when it is interpreted, and nothing else is; compiling it is not checked, as v3");
CHECK(is(say("1 2 HERMES-CHANNEL-OPEN? . ACL-CA-KEY-LO . ' DUP ACL-ENTRY ' DUP = .\n"), "1 0 -1 ok\nok> "), "the rest of v3's policy file is there");
CHECK(is(say("COLD\n"), "FORTH-79 Cold Start\nSystem initialized.\n ok\nok> ") && n.mem[ACL_HOOK] == 0 && is(say("ACL-BOOT\n"), "UNKNOWN WORD: 'ACL-BOOT'\n ERROR\nok> "),
"COLD takes the policy away with everything else that was loaded");
+18
View File
@@ -164,6 +164,24 @@ int main(void)
}
CHECK(all, "init.4th pinned the %u words that create or end nodes", (unsigned)(sizeof pinned / sizeof pinned[0]));
}
{ /* the ACL countdown at call, as v3's inner interpreter (docs/v4.0.0/plans/2026-11-19-acl-at-call.md) */
long t1 = -1, t2 = -1;
r = line(V4_MESH_HERA, ": F1 65 EMIT ; : G1 F1 ; G1 ' F1 ACL-TTL@ . G1 ' F1 ACL-TTL@ .", &how);
if (how == V4_TEXT_COMPLETED) (void)sscanf(r, "A%ld A%ld", &t1, &t2);
CHECK(t1 >= 256 && t2 == t1 - 1, "a word called from a definition is checked at the call, and counted down: \"%s\"", r);
r = line(V4_MESH_HERA, "0 ' F1 ACL-ALLOW! G1", &how);
CHECK(how == V4_TEXT_ERROR && strstr(r, "ACL: denied 'F1'"),
"a denied word called from a definition is refused at the call, by its own name: \"%s\"", r);
CHECK(strstr(r, "denied 'F1'") && strncmp(r, "A", 1) != 0, " and does not run: \"%s\"", r);
r = line(V4_MESH_HERA, ": G2 F1 ;", &how);
CHECK(how == V4_TEXT_COMPLETED, "a denied word can be compiled into a definition, as v3: \"%s\" (%d)", r, how);
r = line(V4_MESH_HERA, "G2", &how);
CHECK(how == V4_TEXT_ERROR && strstr(r, "ACL: denied 'F1'"), " and it is refused when the definition runs: \"%s\"", r);
t1 = t2 = -1;
r = line(V4_MESH_HERA, ": F3 66 EMIT ; F3 ' F3 ACL-TTL@ . F3 ' F3 ACL-TTL@ .", &how);
if (how == V4_TEXT_COMPLETED) (void)sscanf(r, "B%ld B%ld", &t1, &t2);
CHECK(t1 >= 256 && t2 == t1 - 1, "a word at the prompt is counted once a use, not twice: \"%s\"", r);
}
r = line(V4_MESH_HERA, "1900 BLOCK 16 TYPE", &how);
CHECK(how == V4_TEXT_COMPLETED && strncmp(r, "( forth79.4th --", 16) == 0, "forth79.4th's lowest block is in RAM block 1900: \"%.20s\" (%d)", r, how);
/* starshipos.4th, a system capsule loaded before POST (MACHINE.md 3, step 3; ruled 2026-11-18) */
+3 -2
View File
@@ -53,11 +53,12 @@ static int image_description(void)
printf("#include \"v4/image.h\"\n\nconst v4_image v4_map_image = {\n");
printf(" %uu, %uu, %uu, %uu,\n", (unsigned)V4_CELL_BITS, (unsigned)V4_NODE_WORDS, (unsigned)V4_DATA_RING, (unsigned)V4_RET_RING);
printf(" -1,\n -1, %ld,\n -1, -1,\n", (long)PORT);
printf(" %ld, %ld, %ld,\n %ld, %ld,\n %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld,\n %ld,\n %ld, %ld, %ld, %ld, %ld,\n %ld,\n",
printf(" %ld, %ld, %ld,\n %ld, %ld,\n %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld, %ld,\n %ld,\n %ld,\n %ld, %ld, %ld, %ld, %ld,\n %ld, %ld,\n %ld,\n",
(long)CONSOLE_TX, (long)CONSOLE_RX, (long)CONSOLE_ST, (long)DSTACK_REG, (long)RSTACK_REG,
(long)NODE_ERROR, (long)HEAT_REG, (long)ME, (long)DP, (long)LATEST, (long)BOOT_CELLS, (long)FENCE,
(long)NEXT_ID, (long)BOOT_ID, (long)WORD_DEFINED, (long)WORD_FORGOTTEN, (long)HOTVARS, (long)CONTEXT,
(long)TOKENS, (long)DICT_W, (long)DICT_END_W, (long)RUNX_W, (long)EXEC_W, (long)BUF0_W);
(long)TOKENS, (long)DICT_W, (long)DICT_END_W, (long)RUNX_W, (long)EXEC_W, (long)ACL_CALL_W, (long)ACL_BUSY_W,
(long)BUF0_W);
printf(" %ld, %ld, %ld\n};\n", (long)ROM_IMG, (long)ROM_FAILED, (long)ROM_ERRLINE);
return 0;
}