From ef74590ebd78b3b707eeba56d8284faf018affa6 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Tue, 30 Dec 2025 09:22:59 +0100 Subject: [PATCH] WASI fixes --- src/misc/util/utilAigSim.c | 18 ++++++++++++++++++ src/opt/ufar/UfarMgr.cpp | 2 -- src/opt/ufar/UfarPth.cpp | 4 ++++ src/opt/untk/NtkNtk.cpp | 1 - src/opt/util/util.cpp | 2 ++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/misc/util/utilAigSim.c b/src/misc/util/utilAigSim.c index a12d71d81..a05b0f966 100644 --- a/src/misc/util/utilAigSim.c +++ b/src/misc/util/utilAigSim.c @@ -26,6 +26,8 @@ #include #include #include // mkstemp(), close(), unlink() +#include +#include #define AIGSIM_LIBRARY_ONLY @@ -284,8 +286,14 @@ static int ends_with(const char *s, const char *suf) { static int make_tmp_file(char *path, size_t cap, const char *prefix) { // Creates an existing temp file (for input) +#if defined(__wasm) + static int seq = 0; // no risk of collision since we're in a sandbox + snprintf(path, cap, "%s%08d", prefix, seq++); + int fd = open(path, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE); +#else snprintf(path, cap, "/tmp/%sXXXXXX", prefix); int fd = mkstemp(path); +#endif if (fd < 0) return 0; close(fd); return 1; @@ -293,8 +301,14 @@ static int make_tmp_file(char *path, size_t cap, const char *prefix) { static int make_tmp_path_noexist(char *path, size_t cap, const char *prefix) { // Creates a unique temp path that does not exist (for output) +#if defined(__wasm) + static int seq = 0; // no risk of collision since we're in a sandbox + snprintf(path, cap, "%s%08d", prefix, seq++); + int fd = open(path, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE); +#else snprintf(path, cap, "/tmp/%sXXXXXX", prefix); int fd = mkstemp(path); +#endif if (fd < 0) return 0; close(fd); unlink(path); @@ -527,7 +541,11 @@ static int SimulateCompareAigBin(const AigMan *p1, const char *bin, // Run external binary: " " remove(outFile); snprintf(cmd, sizeof(cmd), "%s %s %s", bin, inFile, outFile); +#if defined(__wasm) + int rc = -1; +#else int rc = system(cmd); +#endif if (rc != 0) { fprintf(stderr, "Error: system() failed (rc=%d): %s\n", rc, cmd); goto fail; diff --git a/src/opt/ufar/UfarMgr.cpp b/src/opt/ufar/UfarMgr.cpp index ea565b5e4..18a9c3eba 100755 --- a/src/opt/ufar/UfarMgr.cpp +++ b/src/opt/ufar/UfarMgr.cpp @@ -14,8 +14,6 @@ #include #include -#include - #include #include #include diff --git a/src/opt/ufar/UfarPth.cpp b/src/opt/ufar/UfarPth.cpp index 6df45657f..6f3486295 100755 --- a/src/opt/ufar/UfarPth.cpp +++ b/src/opt/ufar/UfarPth.cpp @@ -184,6 +184,10 @@ class PDRWLA : public Solver { Wlc_Par_t _Pars; }; +#if defined(__wasm) +static void pthread_exit(void *retval) __attribute__((noreturn)) { } +#endif + void KillOthers() { pthread_cond_signal( &g_cond ); ++g_nRunIds; diff --git a/src/opt/untk/NtkNtk.cpp b/src/opt/untk/NtkNtk.cpp index 0ee5e5fd7..463407641 100755 --- a/src/opt/untk/NtkNtk.cpp +++ b/src/opt/untk/NtkNtk.cpp @@ -6,7 +6,6 @@ */ #include -#include #include #include diff --git a/src/opt/util/util.cpp b/src/opt/util/util.cpp index df5de2fd8..cdcd6e3fa 100644 --- a/src/opt/util/util.cpp +++ b/src/opt/util/util.cpp @@ -6,7 +6,9 @@ */ #include +#if !defined(__wasm) #include +#endif #include #ifdef __linux__