diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/base/abc/abcShow.c | 8 | ||||
-rw-r--r-- | src/base/cmd/cmd.c | 4 | ||||
-rw-r--r-- | src/base/cmd/cmdUtils.c | 5 | ||||
-rw-r--r-- | src/base/main/mainReal.c | 6 | ||||
-rw-r--r-- | src/misc/util/utilFile.c | 28 | ||||
-rw-r--r-- | src/misc/util/utilSignal.c | 4 | ||||
-rw-r--r-- | src/sat/bsat2/Alloc.h | 8 | ||||
-rw-r--r-- | src/sat/bsat2/Vec.h | 4 | ||||
-rw-r--r-- | src/sat/bsat2/XAlloc.h | 4 | ||||
-rw-r--r-- | src/sat/glucose/Alloc.h | 8 | ||||
-rw-r--r-- | src/sat/glucose/IntTypes.h | 14 | ||||
-rw-r--r-- | src/sat/glucose/Vec.h | 4 | ||||
-rw-r--r-- | src/sat/glucose/XAlloc.h | 4 | ||||
-rw-r--r-- | src/sat/glucose2/Alloc.h | 8 | ||||
-rw-r--r-- | src/sat/glucose2/IntTypes.h | 14 | ||||
-rw-r--r-- | src/sat/glucose2/Vec.h | 8 | ||||
-rw-r--r-- | src/sat/glucose2/XAlloc.h | 4 |
17 files changed, 116 insertions, 19 deletions
diff --git a/src/base/abc/abcShow.c b/src/base/abc/abcShow.c index ff43dbe6..dd8e9efe 100644 --- a/src/base/abc/abcShow.c +++ b/src/base/abc/abcShow.c @@ -363,7 +363,11 @@ void Abc_ShowFile( char * FileNameDot ) // generate the PostScript file using DOT sprintf( CommandDot, "%s -Tps -o %s %s", pDotName, FileNamePs, FileNameDot ); +#if defined(__wasm) + RetValue = -1; +#else RetValue = system( CommandDot ); +#endif if ( RetValue == -1 ) { fprintf( stdout, "Command \"%s\" did not succeed.\n", CommandDot ); @@ -401,7 +405,11 @@ void Abc_ShowFile( char * FileNameDot ) char CommandPs[1000]; unlink( FileNameDot ); sprintf( CommandPs, "%s %s &", pGsNameUnix, FileNamePs ); +#if defined(__wasm) + if ( 1 ) +#else if ( system( CommandPs ) == -1 ) +#endif { fprintf( stdout, "Cannot execute \"%s\".\n", CommandPs ); return; diff --git a/src/base/cmd/cmd.c b/src/base/cmd/cmd.c index a0042443..259c9d78 100644 --- a/src/base/cmd/cmd.c +++ b/src/base/cmd/cmd.c @@ -2175,7 +2175,11 @@ void Gia_ManGnuplotShow( char * pPlotFileName ) { char Command[1000]; sprintf( Command, "%s %s ", pProgNameGnuplot, pPlotFileName ); +#if defined(__wasm) + if ( 1 ) +#else if ( system( Command ) == -1 ) +#endif { fprintf( stdout, "Cannot execute \"%s\".\n", Command ); return; diff --git a/src/base/cmd/cmdUtils.c b/src/base/cmd/cmdUtils.c index 3409543f..c10e9134 100644 --- a/src/base/cmd/cmdUtils.c +++ b/src/base/cmd/cmdUtils.c @@ -52,6 +52,9 @@ int cmdCheckShellEscape( Abc_Frame_t * pAbc, int argc, char ** argv) int RetValue; if (argv[0][0] == '!') { +#if defined(__wasm) + RetValue = -1; +#else const int size = 4096; int i; char * buffer = ABC_ALLOC(char, 10000); @@ -70,7 +73,7 @@ int cmdCheckShellEscape( Abc_Frame_t * pAbc, int argc, char ** argv) // the parts, we lose information. So a command like // `!ls "file name"` will be sent to the system as // `ls file name` which is a BUG - +#endif return 1; } else diff --git a/src/base/main/mainReal.c b/src/base/main/mainReal.c index 922e0521..a13be5e5 100644 --- a/src/base/main/mainReal.c +++ b/src/base/main/mainReal.c @@ -49,7 +49,9 @@ SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. #include <sys/times.h> #include <sys/resource.h> #include <unistd.h> +#if !defined(__wasm) #include <signal.h> +#endif #include <stdlib.h> #endif @@ -132,7 +134,7 @@ int Abc_RealMain( int argc, char * argv[] ) break; case 'm': { -#if !defined(WIN32) && !defined(ABC_NO_RLIMIT) +#if !defined(WIN32) && !defined(__wasm) int maxMb = atoi(globalUtilOptarg); printf("Limiting memory use to %d MB\n", maxMb); struct rlimit limit = { @@ -144,7 +146,7 @@ int Abc_RealMain( int argc, char * argv[] ) break; } case 'l': { -#if !defined(WIN32) && !defined(ABC_NO_RLIMIT) +#if !defined(WIN32) && !defined(__wasm) rlim_t maxTime = atoi(globalUtilOptarg); printf("Limiting time to %d seconds\n", (int)maxTime); struct rlimit limit = { diff --git a/src/misc/util/utilFile.c b/src/misc/util/utilFile.c index 4bb2f4c6..f64d71c2 100644 --- a/src/misc/util/utilFile.c +++ b/src/misc/util/utilFile.c @@ -25,6 +25,23 @@ #include <fcntl.h> #include <sys/stat.h> +// Handle legacy macros +#if !defined(S_IREAD) +#if defined(S_IRUSR) +#define S_IREAD S_IRUSR +#else +#error S_IREAD is undefined +#endif +#endif + +#if !defined(S_IWRITE) +#if defined(S_IWUSR) +#define S_IWRITE S_IWUSR +#else +#error S_IWRITE is undefined +#endif +#endif + #if defined(_MSC_VER) || defined(__MINGW32__) #include <windows.h> #include <process.h> @@ -102,6 +119,17 @@ int tmpFile(const char* prefix, const char* suffix, char** out_name) } assert(0); // -- could not open temporary file return 0; +#elif defined(__wasm) + static int seq = 0; // no risk of collision since we're in a sandbox + int fd; + *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 9); + sprintf(*out_name, "%s%08d%s", prefix, seq++, suffix); + fd = open(*out_name, O_CREAT | O_EXCL | O_RDWR, S_IREAD | S_IWRITE); + if (fd == -1){ + free(*out_name); + *out_name = NULL; + } + return fd; #else int fd; *out_name = (char*)malloc(strlen(prefix) + strlen(suffix) + 7); diff --git a/src/misc/util/utilSignal.c b/src/misc/util/utilSignal.c index 03af81d1..137ff54b 100644 --- a/src/misc/util/utilSignal.c +++ b/src/misc/util/utilSignal.c @@ -43,7 +43,11 @@ ABC_NAMESPACE_IMPL_START int Util_SignalSystem(const char* cmd) { +#if defined(__wasm) + return -1; +#else return system(cmd); +#endif } int tmpFile(const char* prefix, const char* suffix, char** out_name); diff --git a/src/sat/bsat2/Alloc.h b/src/sat/bsat2/Alloc.h index 7f506cb5..9a65cf0c 100644 --- a/src/sat/bsat2/Alloc.h +++ b/src/sat/bsat2/Alloc.h @@ -97,7 +97,11 @@ void RegionAllocator<T>::capacity(uint32_t min_cap) cap += delta; if (cap <= prev_cap) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } // printf(" .. (%p) cap = %u\n", this, cap); @@ -119,7 +123,11 @@ RegionAllocator<T>::alloc(int size) // Handle overflow: if (sz < prev_sz) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif return prev_sz; } diff --git a/src/sat/bsat2/Vec.h b/src/sat/bsat2/Vec.h index f0e07d01..5eea6174 100644 --- a/src/sat/bsat2/Vec.h +++ b/src/sat/bsat2/Vec.h @@ -97,7 +97,11 @@ void vec<T>::capacity(int min_cap) { if (cap >= min_cap) return; int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2 if (add > INT_MAX - cap || (((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM)) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } diff --git a/src/sat/bsat2/XAlloc.h b/src/sat/bsat2/XAlloc.h index 1da17602..33741e33 100644 --- a/src/sat/bsat2/XAlloc.h +++ b/src/sat/bsat2/XAlloc.h @@ -34,7 +34,11 @@ static inline void* xrealloc(void *ptr, size_t size) { void* mem = realloc(ptr, size); if (mem == NULL && errno == ENOMEM){ +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif }else return mem; } diff --git a/src/sat/glucose/Alloc.h b/src/sat/glucose/Alloc.h index e56b5441..a63de032 100644 --- a/src/sat/glucose/Alloc.h +++ b/src/sat/glucose/Alloc.h @@ -100,7 +100,11 @@ void RegionAllocator<T>::capacity(uint32_t min_cap) cap += delta; if (cap <= prev_cap) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } //printf(" .. (%p) cap = %u\n", this, cap); @@ -122,7 +126,11 @@ RegionAllocator<T>::alloc(int size) // Handle overflow: if (sz < prev_sz) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif return prev_sz; } diff --git a/src/sat/glucose/IntTypes.h b/src/sat/glucose/IntTypes.h index 3f75862b..5c4176b2 100644 --- a/src/sat/glucose/IntTypes.h +++ b/src/sat/glucose/IntTypes.h @@ -28,20 +28,18 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA # include <sys/int_fmtio.h> # include <sys/int_limits.h> -#else +#elif _WIN32 -#define __STDC_LIMIT_MACROS # include "pstdint.h" -//# include <inttypes.h> -#endif +#else -#include <limits.h> +# define __STDC_LIMIT_MACROS +# include <limits.h> +# include <inttypes.h> -#ifndef PRIu64 -#define PRIu64 "lu" -#define PRIi64 "ld" #endif + //================================================================================================= #include <misc/util/abc_namespaces.h> diff --git a/src/sat/glucose/Vec.h b/src/sat/glucose/Vec.h index dd1bc20a..d2781635 100644 --- a/src/sat/glucose/Vec.h +++ b/src/sat/glucose/Vec.h @@ -100,7 +100,11 @@ void vec<T>::capacity(int min_cap) { if (cap >= min_cap) return; int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2 if (add > INT_MAX - cap || (((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM)) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } diff --git a/src/sat/glucose/XAlloc.h b/src/sat/glucose/XAlloc.h index 233f834e..d1f1062a 100644 --- a/src/sat/glucose/XAlloc.h +++ b/src/sat/glucose/XAlloc.h @@ -39,7 +39,11 @@ static inline void* xrealloc(void *ptr, size_t size) { void* mem = realloc(ptr, size); if (mem == NULL && errno == ENOMEM){ +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif }else { return mem; } diff --git a/src/sat/glucose2/Alloc.h b/src/sat/glucose2/Alloc.h index b7bebaca..427cd323 100644 --- a/src/sat/glucose2/Alloc.h +++ b/src/sat/glucose2/Alloc.h @@ -100,7 +100,11 @@ void RegionAllocator<T>::capacity(uint32_t min_cap) cap += delta; if (cap <= prev_cap) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } //printf(" .. (%p) cap = %u\n", this, cap); @@ -122,7 +126,11 @@ RegionAllocator<T>::alloc(int size) // Handle overflow: if (sz < prev_sz) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif return prev_sz; } diff --git a/src/sat/glucose2/IntTypes.h b/src/sat/glucose2/IntTypes.h index 3f75862b..5c4176b2 100644 --- a/src/sat/glucose2/IntTypes.h +++ b/src/sat/glucose2/IntTypes.h @@ -28,20 +28,18 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA # include <sys/int_fmtio.h> # include <sys/int_limits.h> -#else +#elif _WIN32 -#define __STDC_LIMIT_MACROS # include "pstdint.h" -//# include <inttypes.h> -#endif +#else -#include <limits.h> +# define __STDC_LIMIT_MACROS +# include <limits.h> +# include <inttypes.h> -#ifndef PRIu64 -#define PRIu64 "lu" -#define PRIi64 "ld" #endif + //================================================================================================= #include <misc/util/abc_namespaces.h> diff --git a/src/sat/glucose2/Vec.h b/src/sat/glucose2/Vec.h index eaeed207..bc989217 100644 --- a/src/sat/glucose2/Vec.h +++ b/src/sat/glucose2/Vec.h @@ -102,14 +102,22 @@ void vec<T>::capacity(int min_cap) { if (cap >= min_cap) return; int add = imax((min_cap - cap + 1) & ~1, ((cap >> 1) + 2) & ~1); // NOTE: grow by approximately 3/2 if (add > INT_MAX - cap || (((data = (T*)::realloc(data, (cap += add) * sizeof(T))) == NULL) && errno == ENOMEM)) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif } template<class T> void vec<T>::prelocate(int ext_cap) { if (cap >= ext_cap) return; if (ext_cap > INT_MAX || (((data = (T*)::realloc(data, ext_cap * sizeof(T))) == NULL) && errno == ENOMEM)) +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif cap = ext_cap; } diff --git a/src/sat/glucose2/XAlloc.h b/src/sat/glucose2/XAlloc.h index 716643ef..86e65a49 100644 --- a/src/sat/glucose2/XAlloc.h +++ b/src/sat/glucose2/XAlloc.h @@ -39,7 +39,11 @@ static inline void* xrealloc(void *ptr, size_t size) { void* mem = realloc(ptr, size); if (mem == NULL && errno == ENOMEM){ +#ifdef __wasm + abort(); +#else throw OutOfMemoryException(); +#endif }else { return mem; } |