尽快推进:收紧HAL运行时shim边界

This commit is contained in:
cnc
2026-06-05 08:02:20 +08:00
parent 810bd92ddc
commit 2e2fb34cc3
2 changed files with 44 additions and 0 deletions

View File

@@ -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",

View File

@@ -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.