feat: implement mremap

main
Sean McBride 4 years ago
parent f8113bf3c5
commit 0a15932acd

Binary file not shown.

After

Width:  |  Height:  |  Size: 704 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 KiB

@ -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"

@ -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"
}

@ -515,19 +515,44 @@ 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);
// 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 the current offset, hoping for the best */
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
#define SYS_GETPID 39

Loading…
Cancel
Save