Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per instance, cross platform library sandboxing support in wasm2c #1721

Open
wants to merge 114 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
6f33f73
remove signal handling, longjmp, stack depth counting, move func type…
shravanrn Apr 22, 2021
27ea992
Create a sandbox struct for all the sandbox params and change referen…
shravanrn Apr 22, 2021
8499ad7
Fix exports - functions are visible with original symbols, separate l…
shravanrn Apr 23, 2021
9961123
Add lookup_wasm2c_func_index api
shravanrn Apr 23, 2021
1ef9cdb
Add apis to add/remove callbacks
shravanrn Apr 23, 2021
485f13c
Make sandbox used 4GB aligned heaps, add windows mmap equivalent support
shravanrn Apr 23, 2021
f44a45f
Fix memory check macro
shravanrn Apr 23, 2021
b2c2e84
Add wasi support to runtime (adapted from emscripten repo)
shravanrn Apr 23, 2021
f52df71
Misc bugfixes
shravanrn Apr 23, 2021
9df1f1c
Extra comment for clairification
shravanrn Apr 23, 2021
1fe2c83
Changes for easier static and dynamic linking, bugfixes, callback tab…
shravanrn Apr 27, 2021
eeec5e7
Bugfixes for wasi-clang
shravanrn Apr 27, 2021
e96c086
Some bug fixes and simplify future use of static linking
shravanrn Apr 28, 2021
def21e5
Fixes for MSVC/Windows compatibility
shravanrn May 10, 2021
c1c13f7
Remove/replace builtins use for windows compat
shravanrn May 10, 2021
93f5e60
Minor fixes for static inline
shravanrn May 10, 2021
8ea640f
Remove builtin expect for windows
shravanrn May 10, 2021
0cf9eed
More windows related fixes
shravanrn May 10, 2021
7aed71b
Func storage class bugfix
shravanrn May 10, 2021
0a92330
Fix storage class bug
shravanrn May 10, 2021
3cf430b
Nit
shravanrn May 10, 2021
1629f71
More linkage fixes and enable windows guard page model
shravanrn May 10, 2021
c544b30
Fix mmap_aligned for windows
shravanrn May 10, 2021
d38698a
More fixes for mmap aligned
shravanrn May 10, 2021
85f0730
More fixes for windows os_mmap_aligned
shravanrn May 10, 2021
830f18e
Remove windows mmap unecessary memory reserve and make mmap more robust
shravanrn May 13, 2021
80b767d
Format os specific files
shravanrn May 13, 2021
497efba
Cleanup macros to enable explicit bounds checks
shravanrn May 13, 2021
8f00744
Nit - bugfix for memory init
shravanrn May 13, 2021
138bf0a
Emit const qualifiers so compilers can optimize better
shravanrn May 13, 2021
3fe9636
Fix unused variable/function warnings
shravanrn May 13, 2021
f31cc44
Add a runner to execute wasm files with a main
shravanrn May 13, 2021
2973221
Minor fixes for windows
shravanrn May 14, 2021
d3eee27
Improve clock implementation
shravanrn May 29, 2021
6e89d56
Fixes for mac wasi clock
shravanrn May 29, 2021
6715e4d
Move platform specific clock impl to correct loc
shravanrn Jun 1, 2021
f8d636f
Reuse config.h.in code for msvc intrinsics
shravanrn Jun 1, 2021
81e6a57
Remove unused variable
shravanrn Jun 1, 2021
c0663a2
Fix clock_gettime on windows
shravanrn Jun 1, 2021
d28eeef
Revert "Reuse config.h.in code for msvc intrinsics"
shravanrn Jun 1, 2021
9bce5ab
Add missing include
shravanrn Jun 2, 2021
9955e5f
Fixes for mac build
shravanrn Jun 10, 2021
3936887
Allow wasm2c to be used with global heaps
shravanrn Jun 15, 2021
67a6d24
Cleanup wasi runtime (add dummy symbols), separate wasi and emscripte…
shravanrn Jul 9, 2021
0a0457d
Remove nested macros due to windows breaks
shravanrn Jul 10, 2021
d336e1e
Change default module prefix in wasm2c runner
shravanrn Jul 10, 2021
3107ff7
Add logging to aligned heap mapping
shravanrn Jul 10, 2021
931630b
Fix macro invocation
shravanrn Jul 10, 2021
e901425
Cleanup deallocation
shravanrn Jul 10, 2021
1f4dbd9
Separate commit and reserve of memory for wasm heap
shravanrn Jul 11, 2021
54a9a93
Cleanup func types on destroy_sandbox
shravanrn Jul 11, 2021
5c1ebfd
Add CI build
shravanrn Jul 11, 2021
8823e81
Correct handling of error codes
shravanrn Jul 11, 2021
dbd6efc
Move one time wasmrt init to its own function
shravanrn Jul 11, 2021
75af36f
Fix CI and badge
shravanrn Jul 11, 2021
a70f295
Include submodules for CI build
shravanrn Jul 11, 2021
c886c4a
Make CI build parallel
shravanrn Jul 11, 2021
a4ace58
Fix bug in void functions function type registration
shravanrn Jul 11, 2021
00fe62e
Fix some ISO c pedantic warnings
shravanrn Jul 11, 2021
24231b0
Fix leak in wasm2c func_types cleanup
shravanrn Jul 11, 2021
265ebc8
Fix cleanup of function types
shravanrn Jul 11, 2021
286a854
wasi_fd_prestat_get should return specific error codes to support was…
shravanrn Jul 18, 2021
3ade79d
Optional shadow/memory ASAN (with malloc metadata tracking)
shravanrn Jul 21, 2021
c5e060e
Implement used state and own state in ASAN
shravanrn Jul 21, 2021
d5c0c37
Make wasm2c_shadow rt func linkages consistent
shravanrn Jul 21, 2021
2c51eb1
Update the lookup function inside sandbox to lookup non-exports
shravanrn Jul 22, 2021
7cdc7ca
Move mac/windows clock's static state to wasi metadata
shravanrn Jul 22, 2021
a8235f3
Fix os_clock include and encapusulate win wasi clock state
shravanrn Jul 22, 2021
c64cca0
Fix typo in mac wasi clock
shravanrn Jul 22, 2021
18ba2d2
Fix typo in win wasi clock
shravanrn Jul 22, 2021
b3360a3
Update wasm2c trap generation code to avoid comma operator
shravanrn Jul 27, 2021
80b727c
Revert "Update wasm2c trap generation code to avoid comma operator"
shravanrn Jul 28, 2021
f4264b4
Eliminate unused value in some trap calls
shravanrn Jul 28, 2021
3c43ee6
Modify wasm2c rt to correctly handle 32bit mode
shravanrn Jul 30, 2021
e3b7194
Update wasm2c to have fixed location memory for 32-bit sandboxes also
shravanrn Jul 31, 2021
0704a66
Correct implementation of wasi clock
shravanrn Aug 3, 2021
08a9425
Remove unecessary indirection for imports
shravanrn Aug 4, 2021
f322ffc
Defensive code for nanosecond calc from timspec_t
shravanrn Aug 4, 2021
678af59
wasm2c support for masking on 32-bit platforms
shravanrn Aug 5, 2021
8e78c53
All executing a pro/epi-logue before external callbacks
shravanrn Aug 13, 2021
8bf2674
Add wasm module entry prologue/epilogue
shravanrn Aug 13, 2021
5526c4c
Fix bug EXTERNAL_CALLBACK_PROLOGUE_EXEC
shravanrn Aug 13, 2021
33d91ff
Minor fix for entry functions
shravanrn Aug 13, 2021
ee6383b
Avoid redefining NOMINMAX
glandium Aug 18, 2021
0a5c750
Fix "non-portable path to file '<windows.h>'" warning
glandium Aug 24, 2021
4829761
Remove non-MSVC definitions of ssize_t for Windows
glandium Aug 24, 2021
e5ac875
Correct signature of clock_time_get to match spec
shravanrn Sep 2, 2021
bc8702e
Update the err msg logging on heap alloc failure
shravanrn Sep 3, 2021
fc4e65d
Fix minor typo
shravanrn Sep 3, 2021
f203e7d
Fix unused variable error in os_win
shravanrn Sep 3, 2021
1bab45b
Fix clock time to return nano seconds per spec
shravanrn Sep 9, 2021
81f21c6
Remove guard pages in 32-bit platforms to save virtual space
shravanrn Sep 29, 2021
f62a28e
Return null sandbox for heap alloc fail instead of abort
shravanrn Sep 29, 2021
fa01b44
Correct windows heap allocation to handle no alignment
shravanrn Oct 4, 2021
0ed7397
Improve wasm2c rt handling of func types with void params or returns
shravanrn Oct 6, 2021
672d3dd
Restore the export of functions in header, so we can support static c…
shravanrn Oct 14, 2021
bce85cc
Cleanup function declarations in header
shravanrn Oct 15, 2021
06fa46d
Add optional configu macro to not export functions
shravanrn Oct 15, 2021
4249593
Cleanup generated struct refs in wasm2c
shravanrn Oct 15, 2021
1b3aece
More detailed errors on call indirect
shravanrn Oct 26, 2021
71fb6d6
Allow specifying a custom trap handler for the runtime
shravanrn Oct 26, 2021
0753375
Add a forward declaration of WASM_RT_CUSTOM_TRAP_HANDLER
shravanrn Oct 26, 2021
0470f5e
Cleanup handling of WASM_RT_TRAP_NONE
shravanrn Oct 26, 2021
81c6fc3
Update comment in header
shravanrn Oct 26, 2021
e159109
Typo in comment
shravanrn Oct 26, 2021
247bd88
Move error message to printf
shravanrn Oct 26, 2021
cd4b501
Fix 32-bit wasm impl to permit use of the top half of the heap
shravanrn Oct 31, 2021
15bd21f
Support for variable size sandboxes on 32-bit platforms
shravanrn Nov 6, 2021
b803dc3
Improve shadow memory tracking
shravanrn Nov 6, 2021
504848a
Expose method to get the default value of max_size_for_wasm_memory
shravanrn Nov 6, 2021
da81308
Add a configuration to see if malloc failed
shravanrn Nov 9, 2021
cdcf201
Forward declare WASM2C_MALLOC_FAIL_CALLBACK
shravanrn Nov 9, 2021
f407501
Dedup size computation for heap reserve
shravanrn Nov 9, 2021
fd9d099
Formatting pass
shravanrn Nov 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Dedup size computation for heap reserve
  • Loading branch information
shravanrn committed Nov 9, 2021
commit f4075014ddb77757ef6cd7aeb1499c7639231963
9 changes: 7 additions & 2 deletions wasm2c/wasm-rt-impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ uint64_t wasm_rt_get_default_max_linear_memory_size() {
return ret;
}

static uint64_t compute_heap_reserve_space(uint32_t chosen_max_pages) {
const uint64_t heap_reserve_size = ((uint64_t) chosen_max_pages) * WASM_PAGE_SIZE + WASM_HEAP_GUARD_PAGE_SIZE;
return heap_reserve_size;
}

bool wasm_rt_allocate_memory(wasm_rt_memory_t* memory,
uint32_t initial_pages,
uint32_t max_pages) {
Expand All @@ -249,7 +254,7 @@ bool wasm_rt_allocate_memory(wasm_rt_memory_t* memory,
// Guard pages already allocates memory incrementally thus we don't need to look at WASM_USE_INCREMENTAL_MOVEABLE_MEMORY_ALLOC
void* addr = NULL;
const uint64_t retries = 10;
const uint64_t heap_reserve_size = ((uint64_t) chosen_max_pages) * WASM_PAGE_SIZE + WASM_HEAP_GUARD_PAGE_SIZE;
const uint64_t heap_reserve_size = compute_heap_reserve_space(chosen_max_pages);

// 32-bit platforms rely on masking for sandboxing
// thus we require the heap reserve size to always be a power of 2
Expand Down Expand Up @@ -306,7 +311,7 @@ bool wasm_rt_allocate_memory(wasm_rt_memory_t* memory,

void wasm_rt_deallocate_memory(wasm_rt_memory_t* memory) {
#ifdef WASM_USE_GUARD_PAGES
const uint64_t heap_reserve_size = ((uint64_t) memory->max_pages) * WASM_PAGE_SIZE + WASM_HEAP_GUARD_PAGE_SIZE;
const uint64_t heap_reserve_size = compute_heap_reserve_space(memory->max_pages);
os_munmap(memory->data, heap_reserve_size);
#else
free(memory->data);
Expand Down