From 6506d23dc25383340e8c8d3e721354eae5428070 Mon Sep 17 00:00:00 2001 From: cnc Date: Fri, 5 Jun 2026 09:51:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E6=8C=89=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=AF=8D=E6=8E=A8=E8=BF=9B=EF=BC=9A=E8=A1=A5tooldata=20mmap?= =?UTF-8?q?=E5=8D=95=E5=88=9B=E5=BB=BA=E8=80=85=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check-linuxcnc-tooldata-source-map.sh | 12 ++++++++++++ core/wasm_shims/tooldata/tooldata_probe_main.cc | 16 ++++++++++++++++ docs/linuxcnc-tooldata-source-map.md | 3 +++ test-linuxcnc-wasm-tooldata-link.sh | 1 + 4 files changed, 32 insertions(+) diff --git a/check-linuxcnc-tooldata-source-map.sh b/check-linuxcnc-tooldata-source-map.sh index 298592e..3b0b16c 100755 --- a/check-linuxcnc-tooldata-source-map.sh +++ b/check-linuxcnc-tooldata-source-map.sh @@ -48,6 +48,10 @@ grep -F 'int tool_mmap_creator(EMC_TOOL_STAT const * ptr,int random_toolchanger) "$linuxcnc_root/src/emc/tooldata/tooldata_mmap.cc" >/dev/null grep -F 'static int inited=0;' \ "$linuxcnc_root/src/emc/tooldata/tooldata_mmap.cc" >/dev/null +grep -F 'if (inited) {' \ + "$linuxcnc_root/src/emc/tooldata/tooldata_mmap.cc" >/dev/null +grep -F 'inited = 1;' \ + "$linuxcnc_root/src/emc/tooldata/tooldata_mmap.cc" >/dev/null grep -F 'hptr->is_random_toolchanger = random_toolchanger;' \ "$linuxcnc_root/src/emc/tooldata/tooldata_mmap.cc" >/dev/null grep -F 'hptr->last_index = 0;' \ @@ -106,6 +110,8 @@ grep -F '`src/emc/tooldata/tool_mmap_read.cc` is the mmap tool table reader util docs/linuxcnc-tooldata-source-map.md >/dev/null grep -F '`tool_mmap_user()`, `tooldata_last_index_get()`, and `tooldata_get()`' \ docs/linuxcnc-tooldata-source-map.md >/dev/null +grep -F "single-creator process boundary from" docs/linuxcnc-tooldata-source-map.md >/dev/null +grep -F "including after" docs/linuxcnc-tooldata-source-map.md >/dev/null grep -F '`src/emc/tooldata/tool_watch.cc` is the NML/mmap tool table watcher utility' \ docs/linuxcnc-tooldata-source-map.md >/dev/null grep -F '`EMC_STAT::io.tool` fields through `RCS_STAT_CHANNEL`' \ @@ -191,6 +197,10 @@ grep -F 'tooldata_db_init(too_many_db_args, 1) != -1' \ core/wasm_shims/tooldata/tooldata_probe_main.cc >/dev/null grep -F 'tooldata_db_init(non_db_program, 1) != -1' \ core/wasm_shims/tooldata/tooldata_probe_main.cc >/dev/null +grep -F 'tool_mmap_creator(nullptr, 1);' \ + core/wasm_shims/tooldata/tooldata_probe_main.cc >/dev/null +grep -F 'WEXITSTATUS(recreate_status) == 0' \ + core/wasm_shims/tooldata/tooldata_probe_main.cc >/dev/null grep -F 'core/wasm_shims/tooldata/tooldata_mmap_backend.cc' docs/linuxcnc-wasm-shims-source-map.md >/dev/null grep -F 'core/wasm_shims/tooldata/tooldata_runtime_stubs.cc' docs/linuxcnc-wasm-shims-source-map.md >/dev/null @@ -205,6 +215,8 @@ grep -F 'LinuxCNC source basis: this probe compares wasm-safe tooldata runtime s grep -F '!!!!db_init: argc exceeds MAX_DB_PROGRAM_ARGS=10' \ test-linuxcnc-wasm-tooldata-link.sh >/dev/null grep -F 'not executable' test-linuxcnc-wasm-tooldata-link.sh >/dev/null +grep -F 'Error: tool_mmap_creator already called BYE' \ + test-linuxcnc-wasm-tooldata-link.sh >/dev/null grep -F 'run_parallel_wasm_probe "LinuxCNC wasm tooldata shim link probe" ./test-linuxcnc-wasm-tooldata-link.sh' \ build-wasm.sh >/dev/null grep -F 'run_parallel_wasm_probe "LinuxCNC wasm tooldata_common link probe" ./test-linuxcnc-wasm-tooldata-common-link.sh' \ diff --git a/core/wasm_shims/tooldata/tooldata_probe_main.cc b/core/wasm_shims/tooldata/tooldata_probe_main.cc index e524516..506aa70 100644 --- a/core/wasm_shims/tooldata/tooldata_probe_main.cc +++ b/core/wasm_shims/tooldata/tooldata_probe_main.cc @@ -350,5 +350,21 @@ int main() { return 39; } + const pid_t recreate_child = fork(); + if (recreate_child < 0) { + return 60; + } + if (recreate_child == 0) { + tool_mmap_creator(nullptr, 1); + _exit(61); + } + int recreate_status = 0; + if (waitpid(recreate_child, &recreate_status, 0) != recreate_child) { + return 62; + } + if (!WIFEXITED(recreate_status) || WEXITSTATUS(recreate_status) == 0) { + return 63; + } + return 0; } diff --git a/docs/linuxcnc-tooldata-source-map.md b/docs/linuxcnc-tooldata-source-map.md index a11bd57..6b1e17c 100644 --- a/docs/linuxcnc-tooldata-source-map.md +++ b/docs/linuxcnc-tooldata-source-map.md @@ -58,6 +58,9 @@ source-link/shim guard only; it must not add CNC behavior and must not expand th - The mmap backend must keep the LinuxCNC random-toolchanger flag and `last_index` initialization edges from `tool_mmap_creator()`, and `tooldata_last_index_get()` must preserve the last-index unavailable return. +- The mmap backend must keep LinuxCNC's single-creator process boundary from + the `static inited` guard in `tool_mmap_creator()`, including after + `tool_mmap_close()` clears browser-safe in-memory state. - `tool_mmap_user()` must keep LinuxCNC's unavailable mmap failure boundary, and `tool_mmap_close()` must clear the browser-safe in-memory state without adding filesystem mmap behavior. diff --git a/test-linuxcnc-wasm-tooldata-link.sh b/test-linuxcnc-wasm-tooldata-link.sh index 1db5906..d5358d9 100755 --- a/test-linuxcnc-wasm-tooldata-link.sh +++ b/test-linuxcnc-wasm-tooldata-link.sh @@ -11,6 +11,7 @@ probe=$(./build-linuxcnc-wasm-standalone-probe.sh --mode tooldata-link) "$probe" 2>"$probe.err" grep -F "tool_mmap_user(): tool mmap not available" "$probe.err" >/dev/null grep -F "tooldata_put() no tool_mmap_base" "$probe.err" >/dev/null +grep -F "Error: tool_mmap_creator already called BYE" "$probe.err" >/dev/null grep -F "!!!PROBLEM tool_nml_register()" "$probe.err" >/dev/null grep -F "!!!!db_init: <" "$probe.err" >/dev/null grep -F "not executable" "$probe.err" >/dev/null