From 035b25862a28efc02980ec2318c3f9248b43ae91 Mon Sep 17 00:00:00 2001 From: cnc Date: Fri, 5 Jun 2026 09:15:41 +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=A7dlfcn=20shim=E6=BA=90=E7=A0=81=E9=94=9A?= =?UTF-8?q?=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check-linuxcnc-wasm-shims-source-map.sh | 26 +++++++++++++++++++++++++ docs/linuxcnc-wasm-shims-source-map.md | 7 ++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/check-linuxcnc-wasm-shims-source-map.sh b/check-linuxcnc-wasm-shims-source-map.sh index f2744ee..82cdcfe 100755 --- a/check-linuxcnc-wasm-shims-source-map.sh +++ b/check-linuxcnc-wasm-shims-source-map.sh @@ -178,7 +178,31 @@ for shim_path, linuxcnc_sources in expected_shims.items(): 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") +dlfcn_shim = Path("core/wasm_shims/dlfcn.cc").read_text(encoding="utf-8") +dlfcn_header = Path("core/wasm_shims/dlfcn.h").read_text(encoding="utf-8") gettext_shim = Path("core/wasm_shims/gettext_shim.cc").read_text(encoding="utf-8") +for needle in [ + "#define RTLD_GLOBAL 0x00100", + "#define RTLD_NOW 0x00002", + "void *dlopen(const char *filename, int flags);", + "void *dlsym(void *handle, const char *symbol);", + "char *dlerror(void);", + "int dlclose(void *handle);", +]: + if needle not in dlfcn_header: + raise SystemExit(f"dlfcn shim header missing LinuxCNC loader boundary: {needle}") +for needle in [ + "dynamic loading is unavailable in wasm-safe probe", + "void *dlopen(const char *, int)", + "return nullptr;", + "void *dlsym(void *, const char *)", + "char *dlerror(void)", + "return last_error;", + "int dlclose(void *)", + "return 0;", +]: + if needle not in dlfcn_shim: + raise SystemExit(f"dlfcn shim missing unavailable-loader boundary: {needle}") for needle in [ "extern \"C\" char *gettext(const char *msgid)", "return const_cast(msgid ? msgid : \"\");", @@ -280,6 +304,8 @@ for phrase in [ "CMake `linuxcnc_wasm_safe_probe_shims` set", "RS274/WASM manifest", "browser-safe LinuxCNC adaptations", + "LinuxCNC `interp_base.cc` dynamic loader calls", + "unavailable-loader returns", "LinuxCNC `_()` diagnostic call sites", "browser gettext catalogs unavailable", "LinuxCNC NML status constructors", diff --git a/docs/linuxcnc-wasm-shims-source-map.md b/docs/linuxcnc-wasm-shims-source-map.md index 04d5a0a..f91eb8f 100644 --- a/docs/linuxcnc-wasm-shims-source-map.md +++ b/docs/linuxcnc-wasm-shims-source-map.md @@ -14,7 +14,7 @@ only; it must not add CNC behavior and must not expand the temporary smoke parse | Shim | LinuxCNC source basis | Boundary | | --- | --- | --- | -| `core/wasm_shims/dlfcn.cc` | `src/emc/rs274ngc/interp_base.cc` | Satisfies native `dlopen` symbols for browser-safe probes while keeping dynamic loading unavailable. | +| `core/wasm_shims/dlfcn.cc` | `src/emc/rs274ngc/interp_base.cc` | Satisfies LinuxCNC `interp_base.cc` dynamic loader calls and RTLD flags for browser-safe probes while keeping dynamic loading unavailable. | | `core/wasm_shims/emc_status_shim.cc` | `src/emc/sai/dummyemcstat.cc` | Provides the source-backed `emcStatus` singleton shape without task/NML startup. | | `core/wasm_shims/gettext_shim.cc` | `src/emc/rs274ngc/interp_internal.hh` | Preserves LinuxCNC `_()` diagnostic call sites by satisfying `gettext()` while leaving browser gettext catalogs unavailable. | | `core/wasm_shims/linuxcnc_runtime_shim.cc` | `src/emc/rs274ngc/gcodemodule.cc`, `src/emc/task/emctaskmain.cc`, `src/emc/task/taskclass.cc`, `src/emc/rs274ngc/interp_namedparams.cc`, `include/hal.h`, `src/hal/hal_lib.c`, `src/emc/rs274ngc/rs274ngc_pre.cc` | Keeps preview/task, builtin Python module, unavailable HAL lookup, and `wordexp()` edges compile-safe. | @@ -28,6 +28,11 @@ only; it must not add CNC behavior and must not expand the temporary smoke parse ## Runtime Shim Boundaries +- `core/wasm_shims/dlfcn.cc` and `core/wasm_shims/dlfcn.h` cover the + LinuxCNC `interp_base.cc` dynamic loader calls to `dlopen()`, `dlsym()`, + `dlerror()`, `RTLD_GLOBAL`, and `RTLD_NOW`; their unavailable-loader returns + must keep handles and symbols null, keep `dlerror()` diagnostic text stable, + and leave `dlclose()` side-effect free. - `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()`,