diff --git a/runtime/experiments/applications/imageresize/by_resolution/expected_result_large.png b/runtime/experiments/applications/imageresize/by_resolution/expected_result_large.png new file mode 100644 index 0000000..d4b1d67 Binary files /dev/null and b/runtime/experiments/applications/imageresize/by_resolution/expected_result_large.png differ diff --git a/runtime/experiments/applications/imageresize/by_resolution/expected_result_medium.png b/runtime/experiments/applications/imageresize/by_resolution/expected_result_medium.png new file mode 100644 index 0000000..58cb1f3 Binary files /dev/null and b/runtime/experiments/applications/imageresize/by_resolution/expected_result_medium.png differ diff --git a/runtime/experiments/applications/imageresize/by_resolution/expected_result_old.png b/runtime/experiments/applications/imageresize/by_resolution/expected_result_old.png deleted file mode 100644 index 1f95aae..0000000 Binary files a/runtime/experiments/applications/imageresize/by_resolution/expected_result_old.png and /dev/null differ diff --git a/runtime/experiments/applications/imageresize/by_resolution/expected_result.png b/runtime/experiments/applications/imageresize/by_resolution/expected_result_small.png similarity index 100% rename from runtime/experiments/applications/imageresize/by_resolution/expected_result.png rename to runtime/experiments/applications/imageresize/by_resolution/expected_result_small.png diff --git a/runtime/experiments/applications/imageresize/by_resolution/run.sh b/runtime/experiments/applications/imageresize/by_resolution/run.sh index 99f6f39..1e00455 100755 --- a/runtime/experiments/applications/imageresize/by_resolution/run.sh +++ b/runtime/experiments/applications/imageresize/by_resolution/run.sh @@ -28,35 +28,30 @@ for ((i = 0; i < total_count; i++)); do ext="$RANDOM" curl -H 'Expect:' -H "Content-Type: image/jpg" --data-binary "@shrinking_man_small.jpg" --output "result_${ext}_small.png" localhost:10000 2>/dev/null 1>/dev/null - pixel_differences="$(compare -identify -metric AE "result_${ext}_small.png" expected_result.png null: 2>&1 >/dev/null)" - if [[ "$pixel_differences" == "0" ]]; then - success_count=$((success_count + 1)) - else + pixel_differences="$(compare -identify -metric AE "result_${ext}_small.png" expected_result_small.png null: 2>&1 >/dev/null)" + if [[ "$pixel_differences" != "0" ]]; then echo "Small FAIL" echo "$pixel_differences pixel differences detected" exit fi curl -H 'Expect:' -H "Content-Type: image/jpg" --data-binary "@shrinking_man_medium.jpg" --output "result_${ext}_medium.png" localhost:10001 2>/dev/null 1>/dev/null - pixel_differences="$(compare -identify -metric AE "result_${ext}_medium.png" expected_result.png null: 2>&1 >/dev/null)" - if [[ "$pixel_differences" == "0" ]]; then - success_count=$((success_count + 1)) - else - echo "Medium FAIL" + pixel_differences="$(compare -identify -metric AE "result_${ext}_medium.png" expected_result_medium.png null: 2>&1 >/dev/null)" + if [[ "$pixel_differences" != "0" ]]; then + echo "Small FAIL" echo "$pixel_differences pixel differences detected" exit fi curl -H 'Expect:' -H "Content-Type: image/jpg" --data-binary "@shrinking_man_large.jpg" --output "result_${ext}_large.png" localhost:10002 2>/dev/null 1>/dev/null - pixel_differences="$(compare -identify -metric AE "result_${ext}_large.png" expected_result.png null: 2>&1 >/dev/null)" - - if [[ "$pixel_differences" == "0" ]]; then - success_count=$((success_count + 1)) - else - echo "Large FAIL" + pixel_differences="$(compare -identify -metric AE "result_${ext}_large.png" expected_result_large.png null: 2>&1 >/dev/null)" + if [[ "$pixel_differences" != "0" ]]; then + echo "Small FAIL" echo "$pixel_differences pixel differences detected" exit fi + + success_count=$((success_count + 1)) done echo "$success_count / $total_count" diff --git a/runtime/experiments/applications/imageresize/by_resolution/spec.json b/runtime/experiments/applications/imageresize/by_resolution/spec.json index 06f8459..eb8c9bc 100644 --- a/runtime/experiments/applications/imageresize/by_resolution/spec.json +++ b/runtime/experiments/applications/imageresize/by_resolution/spec.json @@ -35,8 +35,8 @@ "argsize": 1, "http-req-headers": [], "http-req-content-type": "image/jpeg", - "http-req-size": 1024000, + "http-req-size": 1524000, "http-resp-headers": [], - "http-resp-size": 1024000, + "http-resp-size": 1524000, "http-resp-content-type": "image/png" } diff --git a/runtime/src/libc/syscall.c b/runtime/src/libc/syscall.c index d54c5a1..c389b95 100644 --- a/runtime/src/libc/syscall.c +++ b/runtime/src/libc/syscall.c @@ -515,17 +515,42 @@ int32_t wasm_mremap(int32_t offset, int32_t old_size, int32_t new_size, int32_t flags) { /* Should fit within the 32-bit linear address space */ - /* TODO: Improve with errno */ - assert(offset + old_size < INT32_MAX); - assert(new_size < INT32_MAX); + /* TODO: Improve with errno and handle flags properly */ + // debuglog("Offset: %d, Old Size: %d, New Size: %d, May Move: %s, Fixed: %s\n", offset, old_size, new_size, + // (flags & MREMAP_MAYMOVE) == MREMAP_MAYMOVE ? "true" : "false", + // (flags & MREMAP_FIXED) == MREMAP_FIXED ? "true" : "false"); - /* Not really implemented, so dump out usage to understand requirements */ - debuglog("Offset: %d, Old Size: %d, New Size: %d, May Move: %s, Fixed: %s\n", offset, old_size, new_size, - (flags & MREMAP_MAYMOVE) == MREMAP_MAYMOVE ? "true" : "false", - (flags & MREMAP_FIXED) == MREMAP_FIXED ? "true" : "false"); + assert(offset >= 0); + assert(offset + old_size <= INT32_MAX); - /* Return the current offset, hoping for the best */ - return offset; + // We do not implement compaction yet, so just return immediately if shrinking + if (new_size <= old_size) return offset; + + // If at end of linear memory, just expand and return same address + if (offset + old_size == local_sandbox_context_cache.linear_memory_size) { + int32_t amount_to_expand = new_size - old_size; + int32_t pages_to_allocate = amount_to_expand / WASM_PAGE_SIZE; + if (amount_to_expand % WASM_PAGE_SIZE > 0) pages_to_allocate++; + for (int i = 0; i < pages_to_allocate; i++) expand_memory(); + + return offset; + } + + // Otherwise allocate at end of address space and copy + int32_t pages_to_allocate = new_size / WASM_PAGE_SIZE; + if (new_size % WASM_PAGE_SIZE > 0) pages_to_allocate++; + int32_t new_offset = local_sandbox_context_cache.linear_memory_size; + for (int i = 0; i < pages_to_allocate; i++) expand_memory(); + + // Get pointer of old offset and pointer of new offset + char *linear_mem = local_sandbox_context_cache.linear_memory_start; + char *src = &linear_mem[offset]; + char *dest = &linear_mem[new_offset]; + + // Copy Values. We can use memcpy because we don't overlap + memcpy((void *)dest, (void *)src, old_size); + + return new_offset; } #define SYS_MADVISE 28