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
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 34 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Build

on:
push:
branches: [ main, ci_debug ]
pull_request:
branches: [ main ]

env:
BUILD_TYPE: Release

jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}

- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --parallel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this different to to the CI testing we already do in build.yml?

I guess one difference is that in build.yml we always prefer ninja as the cmake generator.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry some of the CI stuff was for our own internal testing. Will remove.


# - name: Test
# working-directory: ${{github.workspace}}/build
# run: ctest -V -C ${{env.BUILD_TYPE}}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/bin
/build
/build*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a function of our workflows - separate test directories for build_debug, build_release etc. If this is a huge problem, I can remove it. If it's alright to keep, it would simplify our uses of this repo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Our convention it to use nested build trees under the out/ directory. See the top level Makefile for how that work. e.g. the default build if you just type make will use cmake to create a build directory in out/clang/Debug/. But if you use gcc it will go in out/gcc/Debug/, etc.

I'm not sure why /build is in this file at all.. perhaps we should remove it. Unless maybe its the default directory used by some higher level tool for dealing with cmake projects maybe?

Can you configure your tool to use out/ ? If not I'm OK landing this change, but maybe as a separate change on it own?

/out
/fuzz-out
/emscripten
Expand Down
21 changes: 16 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,9 @@ set(WABT_LIBRARY_SRC

add_library(wabt STATIC ${WABT_LIBRARY_SRC})

IF (NOT WIN32)
add_library(wasm-rt-impl STATIC wasm2c/wasm-rt-impl.c wasm2c/wasm-rt-impl.h)
install(TARGETS wasm-rt-impl DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES wasm2c/wasm-rt.h wasm2c/wasm-rt-impl.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif ()
add_library(wasm-rt-impl STATIC SHARED wasm2c/wasm-rt-impl.c wasm2c/wasm-rt-os-unix.c wasm2c/wasm-rt-os-win.c wasm2c/wasm-rt-wasi.c)
install(TARGETS wasm-rt-impl DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES wasm2c/wasm-rt.h wasm2c/wasm-rt-impl.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

if (BUILD_FUZZ_TOOLS)
set(FUZZ_FLAGS "-fsanitize=fuzzer,address")
Expand Down Expand Up @@ -472,6 +470,19 @@ if (BUILD_TOOLS)
INSTALL
)

if (NOT WIN32)
set(LDL_LIB "-ldl")
else()
set(LDL_LIB "")
endif()

wabt_executable(
NAME wasm2c-runner
SOURCES wasm2c/wasm-rt-runner.c
LIBS ${LDL_LIB}
INSTALL
)

# wasm-opcodecnt
wabt_executable(
NAME wasm-opcodecnt
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Github CI Status](https://github.com/WebAssembly/wabt/workflows/CI/badge.svg)](https://github.com/WebAssembly/wabt)
[![Build](https://github.com/PLSysSec/wasm2c_sandbox_compiler/actions/workflows/cmake.yml/badge.svg)](https://github.com/PLSysSec/wasm2c_sandbox_compiler/actions/workflows/cmake.yml)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to keep using CI in this repo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry some of the CI stuff was for our own internal testing. Will remove.

# WABT: The WebAssembly Binary Toolkit

Expand Down
Loading