From 5010de0779d0a7de02426cfe63727bd9a84af7c3 Mon Sep 17 00:00:00 2001 From: Michael Adams Date: Sat, 4 Nov 2023 21:39:06 -0700 Subject: [PATCH] Made a few improvements to the WebAssembly support. --- CMakeLists.txt | 1 + build/build_wasi_jasper | 12 ++++++------ src/libjasper/base/jas_malloc.c | 10 +++++++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17ffcf30..ba6f1173 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,6 +197,7 @@ if(JAS_WASM) set(JAS_STDC_VERSION "201112L") set(JAS_ENABLE_MULTITHREADING_SUPPORT 0) set(JAS_ENABLE_SHARED 0) + set(JAS_USE_JAS_INIT 0) add_compile_definitions(JAS_WASI_LIBC) endif() diff --git a/build/build_wasi_jasper b/build/build_wasi_jasper index e5aad739..5594410f 100755 --- a/build/build_wasi_jasper +++ b/build/build_wasi_jasper @@ -111,15 +111,15 @@ configure_options=( -DCMAKE_INSTALL_PREFIX="$install_dir" -DCMAKE_BUILD_TYPE=Release -DCMAKE_VERBOSE_MAKEFILE=1 - -DJAS_CROSSCOMPILING=1 - -DJAS_STDC_VERSION=201112L - -DJAS_ENABLE_MULTITHREADING_SUPPORT=0 - -DJAS_ENABLE_SHARED=0 + -DJAS_WASM=1 -DJAS_ENABLE_CXX=0 - -DJAS_USE_JAS_INIT=1 -DJAS_STRICT=0 - -DJAS_WASM=1 -DJAS_ENABLE_DOC=0 + #-DJAS_CROSSCOMPILING=1 + #-DJAS_STDC_VERSION=201112L + #-DJAS_ENABLE_MULTITHREADING_SUPPORT=0 + #-DJAS_ENABLE_SHARED=0 + #-DJAS_USE_JAS_INIT=0 ) cmake -H"$source_dir" -B"$build_dir" "${configure_options[@]}" || \ diff --git a/src/libjasper/base/jas_malloc.c b/src/libjasper/base/jas_malloc.c index 7eb3e6a2..9b540008 100644 --- a/src/libjasper/base/jas_malloc.c +++ b/src/libjasper/base/jas_malloc.c @@ -626,7 +626,15 @@ void jas_basic_free(jas_allocator_t *allocator, void *ptr) size_t jas_get_total_mem_size() { -#if defined(__linux__) +#if defined(JAS_WASI_LIBC) + /* + NOTE: On the 32-bit WebAssembly platform, the unsigned integral type + size_t is likely to have a size of 32 bits. So, choose the maximum + memory to be less than 2 ^ 32 in order to avoid overflow. + */ + return JAS_CAST(size_t, 4096) * JAS_CAST(size_t, 1024) * + JAS_CAST(size_t, 1024) - 1; +#elif defined(__linux__) struct sysinfo buf; if (sysinfo(&buf)) { return 0;