From 64f336d6f299d9169a310624b578943723ea08ee Mon Sep 17 00:00:00 2001 From: cnc Date: Sat, 6 Jun 2026 12:48:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E6=BA=90=E9=AA=8C=E8=AF=81tooldata?= =?UTF-8?q?=E4=BD=8E=E7=B4=A2=E5=BC=95=E5=86=99=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 源依据:LinuxCNC src/emc/tooldata/tooldata_mmap.cc 的 tooldata_put() 仅在 idx > last_index 时返回 IDX_NEW 并更新 last_index,否则返回 IDX_OK。 结论:wasm-safe tooldata mmap probe 增加低于当前 last_index 的写入断言,确认返回 IDX_OK、last_index 不变且数据可读回,减少 tooldata_mmap 后端替换风险。 检查:./test-linuxcnc-wasm-tooldata-link.sh;./test-native.sh;./test-linuxcnc-source-link.sh。 --- core/wasm_shims/tooldata/tooldata_probe_main.cc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/wasm_shims/tooldata/tooldata_probe_main.cc b/core/wasm_shims/tooldata/tooldata_probe_main.cc index 9c8da76..d5a61b4 100644 --- a/core/wasm_shims/tooldata/tooldata_probe_main.cc +++ b/core/wasm_shims/tooldata/tooldata_probe_main.cc @@ -272,6 +272,23 @@ int main() { if (tooldata_put(tool, 12) != IDX_NEW) { return 2; } + CANON_TOOL_TABLE lower_index_tool = tooldata_entry_init(); + lower_index_tool.toolno = 3; + lower_index_tool.pocketno = 5; + // LinuxCNC src/emc/tooldata/tooldata_mmap.cc returns IDX_OK for writes at + // or below the current last_index and leaves last_index unchanged. + if (tooldata_put(lower_index_tool, 5) != IDX_OK) { + return 80; + } + if (tooldata_last_index_get() != 12) { + return 81; + } + CANON_TOOL_TABLE lower_index_loaded = tooldata_entry_init(); + if (tooldata_get(&lower_index_loaded, 5) != IDX_OK || + lower_index_loaded.toolno != 3 || + lower_index_loaded.pocketno != 5) { + return 82; + } CANON_TOOL_TABLE loaded = tooldata_entry_init(); if (tooldata_get(&loaded, 12) != IDX_OK) {