From 2e2fb34cc319a8c62c3b0e044b107804d16eefbc Mon Sep 17 00:00:00 2001 From: cnc Date: Fri, 5 Jun 2026 08:02:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=BD=E5=BF=AB=E6=8E=A8=E8=BF=9B=EF=BC=9A?= =?UTF-8?q?=E6=94=B6=E7=B4=A7HAL=E8=BF=90=E8=A1=8C=E6=97=B6shim=E8=BE=B9?= =?UTF-8?q?=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check-linuxcnc-wasm-shims-source-map.sh | 32 +++++++++++++++++++++++++ docs/linuxcnc-wasm-shims-source-map.md | 12 ++++++++++ 2 files changed, 44 insertions(+) diff --git a/check-linuxcnc-wasm-shims-source-map.sh b/check-linuxcnc-wasm-shims-source-map.sh index b88b143..93b1a4e 100755 --- a/check-linuxcnc-wasm-shims-source-map.sh +++ b/check-linuxcnc-wasm-shims-source-map.sh @@ -36,6 +36,12 @@ grep -F 'hal_get_signal_value_by_name(hal_name, &type, &ptr, &conn)' \ grep -F 'hal_get_param_value_by_name(hal_name, &type, &ptr)' \ "$linuxcnc_root/src/emc/rs274ngc/interp_namedparams.cc" >/dev/null grep -F 'HAL_TYPE_UNINITIALIZED = 0,' "$linuxcnc_root/include/hal.h" >/dev/null +grep -F 'extern int hal_get_pin_value_by_name(' "$linuxcnc_root/include/hal.h" >/dev/null +grep -F 'extern int hal_get_signal_value_by_name(' "$linuxcnc_root/include/hal.h" >/dev/null +grep -F 'extern int hal_get_param_value_by_name(' "$linuxcnc_root/include/hal.h" >/dev/null +grep -F 'int hal_get_pin_value_by_name(' "$linuxcnc_root/src/hal/hal_lib.c" >/dev/null +grep -F 'int hal_get_signal_value_by_name(' "$linuxcnc_root/src/hal/hal_lib.c" >/dev/null +grep -F 'int hal_get_param_value_by_name(' "$linuxcnc_root/src/hal/hal_lib.c" >/dev/null grep -F 'wordexp(basename, &exp_result, 0);' "$linuxcnc_root/src/emc/rs274ngc/rs274ngc_pre.cc" >/dev/null grep -F 'EMC_STAT *emcStatus = new EMC_STAT;' "$linuxcnc_root/src/emc/sai/dummyemcstat.cc" >/dev/null grep -F 'NMLmsg::NMLmsg' "$linuxcnc_root/src/libnml/nml/nmlmsg.cc" >/dev/null @@ -124,6 +130,29 @@ for shim_path, linuxcnc_sources in expected_shims.items(): if source not in manifest_text: raise SystemExit(f"{source} is not tracked in {manifest}") +runtime_shim = Path("core/wasm_shims/linuxcnc_runtime_shim.cc").read_text(encoding="utf-8") +runtime_probe = Path("core/wasm_shims/cnc_sim_wasm_runtime_probe_main.cc").read_text(encoding="utf-8") +for needle in [ + 'extern "C" int hal_get_pin_value_by_name', + 'extern "C" int hal_get_signal_value_by_name', + 'extern "C" int hal_get_param_value_by_name', + "*type = HAL_TYPE_UNINITIALIZED;", + "*data = nullptr;", + "return -1;", +]: + if needle not in runtime_shim: + raise SystemExit(f"linuxcnc runtime shim missing HAL unavailable boundary: {needle}") +for needle in [ + "bool hal_lookup_is_unavailable()", + 'hal_get_pin_value_by_name("cnc-sim.missing-pin", &type, &data, &connected) != -1', + 'hal_get_signal_value_by_name("cnc-sim.missing-signal", &type, &data, &has_writers) != -1', + 'hal_get_param_value_by_name("cnc-sim.missing-param", &type, &data) != -1', + "type != HAL_TYPE_UNINITIALIZED", + "data != nullptr", +]: + if needle not in runtime_probe: + raise SystemExit(f"runtime probe missing HAL unavailable assertion: {needle}") + for phrase in [ "must not add CNC behavior", "must not expand the temporary smoke parser", @@ -132,6 +161,9 @@ for phrase in [ "browser-safe LinuxCNC adaptations", "dynamic loading unavailable", "unavailable HAL lookup", + "must leave HAL values unavailable", + "must not switch browser-safe probes into task mode", + "must not become a shell expansion feature", "inactive-DB return values", "negative-status short-circuit behavior", "./check-linuxcnc-wasm-shims-source-map.sh", diff --git a/docs/linuxcnc-wasm-shims-source-map.md b/docs/linuxcnc-wasm-shims-source-map.md index 3304d5a..a7e4b56 100644 --- a/docs/linuxcnc-wasm-shims-source-map.md +++ b/docs/linuxcnc-wasm-shims-source-map.md @@ -26,6 +26,18 @@ only; it must not add CNC behavior and must not expand the temporary smoke parse | `core/wasm_shims/tooldata/tooldata_runtime_stubs.cc` | `src/emc/tooldata/tooldata_nml.cc`, `src/emc/tooldata/tooldata_db.cc` | Satisfies NML and external tool database entry points without native services, preserving inactive-DB return values. | | `core/wasm_shims/pythonplugin/python_plugin.cc` | `src/emc/pythonplugin/python_plugin.cc`, `src/emc/pythonplugin/python_plugin.hh` | Keeps LinuxCNC PythonPlugin API and negative-status short-circuit behavior available while Python execution is disabled for browser-safe probes. | +## Runtime Shim Boundaries + +- `core/wasm_shims/linuxcnc_runtime_shim.cc` must keep `_task=0` for preview, + matching `src/emc/rs274ngc/gcodemodule.cc`; it must not switch browser-safe probes into task mode. +- The HAL lookup shim covers `hal_get_pin_value_by_name()`, + `hal_get_signal_value_by_name()`, and `hal_get_param_value_by_name()` from + `src/emc/rs274ngc/interp_namedparams.cc`, `include/hal.h`, and + `src/hal/hal_lib.c`; it must leave HAL values unavailable by returning `-1`, + `HAL_TYPE_UNINITIALIZED`, and null data pointers. +- `wordexp()` support is limited to the browser-safe path expansion needed by + `src/emc/rs274ngc/rs274ngc_pre.cc`; it must not become a shell expansion feature. + ## Boundaries - The CMake `linuxcnc_wasm_safe_probe_shims` set and `list-linuxcnc-wasm-safe-shims.sh` must stay synchronized.