diff --git a/core/wasm_shims/tooldata/tooldata_probe_main.cc b/core/wasm_shims/tooldata/tooldata_probe_main.cc index 506aa70..3e36a66 100644 --- a/core/wasm_shims/tooldata/tooldata_probe_main.cc +++ b/core/wasm_shims/tooldata/tooldata_probe_main.cc @@ -84,6 +84,35 @@ int main() { return 45; } + const pid_t nonrandom_t0_child = fork(); + if (nonrandom_t0_child < 0) { + return 64; + } + if (nonrandom_t0_child == 0) { + if (tool_mmap_creator(nullptr, 0) != 0) { + _exit(65); + } + CANON_TOOL_TABLE nonrandom_t0 = tooldata_entry_init(); + nonrandom_t0.toolno = 0; + nonrandom_t0.pocketno = 12; + if (tooldata_put(nonrandom_t0, 12) == IDX_FAIL) { + _exit(66); + } + // LinuxCNC src/emc/tooldata/tooldata_mmap.cc returns pocket 0 for T0 + // before scanning table entries when the toolchanger is not random. + if (tooldata_find_index_for_tool(0) != 0) { + _exit(67); + } + _exit(0); + } + int nonrandom_t0_status = 0; + if (waitpid(nonrandom_t0_child, &nonrandom_t0_status, 0) != nonrandom_t0_child) { + return 68; + } + if (!WIFEXITED(nonrandom_t0_status) || WEXITSTATUS(nonrandom_t0_status) != 0) { + return 69; + } + if (tool_mmap_user() != -1) { return 25; }