diff --git a/core/wasm_shims/tooldata/tooldata_probe_main.cc b/core/wasm_shims/tooldata/tooldata_probe_main.cc index 3e36a66..33b630c 100644 --- a/core/wasm_shims/tooldata/tooldata_probe_main.cc +++ b/core/wasm_shims/tooldata/tooldata_probe_main.cc @@ -113,6 +113,42 @@ int main() { return 69; } + const pid_t random_t0_child = fork(); + if (random_t0_child < 0) { + return 70; + } + if (random_t0_child == 0) { + if (tool_mmap_creator(nullptr, 1) != 0) { + _exit(71); + } + tooldata_reset(); + CANON_TOOL_TABLE spindle_t0 = tooldata_entry_init(); + spindle_t0.toolno = 0; + spindle_t0.pocketno = 0; + if (tooldata_put(spindle_t0, 0) == IDX_FAIL) { + _exit(72); + } + CANON_TOOL_TABLE random_t0 = tooldata_entry_init(); + random_t0.toolno = 0; + random_t0.pocketno = 15; + if (tooldata_put(random_t0, 15) == IDX_FAIL) { + _exit(73); + } + // LinuxCNC src/emc/tooldata/tooldata_mmap.cc continues past pocket 0 + // while scanning random toolchanger entries, so a nonzero T0 pocket wins. + if (tooldata_find_index_for_tool(0) != 15) { + _exit(74); + } + _exit(0); + } + int random_t0_status = 0; + if (waitpid(random_t0_child, &random_t0_status, 0) != random_t0_child) { + return 75; + } + if (!WIFEXITED(random_t0_status) || WEXITSTATUS(random_t0_status) != 0) { + return 76; + } + if (tool_mmap_user() != -1) { return 25; }