Skip to content

Commit a47467b

Browse files
committed
WASI fixes
1 parent 3b36aa1 commit a47467b

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

src/misc/util/utilAigSim.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include <ctype.h>
2727
#include <time.h>
2828
#include <unistd.h> // mkstemp(), close(), unlink()
29+
#include <fcntl.h>
30+
#include <sys/stat.h>
2931

3032
#define AIGSIM_LIBRARY_ONLY
3133

@@ -284,17 +286,29 @@ static int ends_with(const char *s, const char *suf) {
284286

285287
static int make_tmp_file(char *path, size_t cap, const char *prefix) {
286288
// Creates an existing temp file (for input)
289+
#if defined(__wasm)
290+
static int seq = 0; // no risk of collision since we're in a sandbox
291+
snprintf(path, cap, "%s%08d", prefix, seq++);
292+
int fd = open(path, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE);
293+
#else
287294
snprintf(path, cap, "/tmp/%sXXXXXX", prefix);
288295
int fd = mkstemp(path);
296+
#endif
289297
if (fd < 0) return 0;
290298
close(fd);
291299
return 1;
292300
}
293301

294302
static int make_tmp_path_noexist(char *path, size_t cap, const char *prefix) {
295303
// Creates a unique temp path that does not exist (for output)
304+
#if defined(__wasm)
305+
static int seq = 0; // no risk of collision since we're in a sandbox
306+
snprintf(path, cap, "%s%08d", prefix, seq++);
307+
int fd = open(path, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE);
308+
#else
296309
snprintf(path, cap, "/tmp/%sXXXXXX", prefix);
297310
int fd = mkstemp(path);
311+
#endif
298312
if (fd < 0) return 0;
299313
close(fd);
300314
unlink(path);
@@ -527,7 +541,11 @@ static int SimulateCompareAigBin(const AigMan *p1, const char *bin,
527541
// Run external binary: "<bin> <inFile> <outFile>"
528542
remove(outFile);
529543
snprintf(cmd, sizeof(cmd), "%s %s %s", bin, inFile, outFile);
544+
#if defined(__wasm)
545+
int rc = -1;
546+
#else
530547
int rc = system(cmd);
548+
#endif
531549
if (rc != 0) {
532550
fprintf(stderr, "Error: system() failed (rc=%d): %s\n", rc, cmd);
533551
goto fail;

src/opt/ufar/UfarMgr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include <array>
1515
#include <regex>
1616

17-
#include <sys/wait.h>
18-
1917
#include <base/wlc/wlc.h>
2018
#include <sat/cnf/cnf.h>
2119
#include <aig/gia/giaAig.h>

src/opt/ufar/UfarPth.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ class PDRWLA : public Solver {
184184
Wlc_Par_t _Pars;
185185
};
186186

187+
#if defined(__wasm)
188+
static void pthread_exit(void *retval)
189+
{
190+
}
191+
#endif
192+
187193
void KillOthers() {
188194
pthread_cond_signal( &g_cond );
189195
++g_nRunIds;

src/opt/untk/NtkNtk.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#include <unistd.h>
9-
#include <sys/wait.h>
109
#include <fstream>
1110

1211
#include <base/wlc/wlc.h>

src/opt/util/util.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77

88
#include <iomanip>
9+
#if !defined(__wasm)
910
#include <csignal>
11+
#endif
1012
#include <unistd.h>
1113

1214
#ifdef __linux__

0 commit comments

Comments
 (0)