v4 ACL: the countdown at call, as v3 -- the call hook may redirect
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:
+10
-2
@@ -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
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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) */
|
||||
|
||||
Reference in New Issue
Block a user