Skip to content

Commit

Permalink
fix appveyor installer and build (wasmerio#224)
Browse files Browse the repository at this point in the history
* remove exception handler when function returns or throws

* revert to only reserving and not committing memory due to issues

* appveyor builds for release, caches more, only publish artifact once
  • Loading branch information
xmclark authored Mar 1, 2019
1 parent eed1c3b commit bde2022
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
24 changes: 13 additions & 11 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,36 @@ environment:

cache:
- 'C:\Users\appveyor\.cargo'
- target

install:
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
- rustup-init.exe -yv --default-host %target%
# uncomment these lines if the cache is cleared, or if we must re-install rust for some reason
# - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
# - rustup-init.exe -yv --default-host %target%
- set PATH=%PATH%;%USERPROFILE%\.cargo\bin
- rustup default stable-%target%
- rustup update
- rustc -vV
- cargo -vV
# Install InnoSetup
- appveyor-retry appveyor DownloadFile https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror/2017-08-22-is.exe
- 2017-08-22-is.exe /VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-
- set PATH="C:\Program Files (x86)\Inno Setup 5";%PATH%
# uncomment to RDP to appveyor
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

build_script:
- cargo build --verbose
- cargo build --release --verbose

test_script:
- set RUST_BACKTRACE=1
- cd ./lib/spectests && cargo test -- --test-threads 1 && cd ../..
- cargo test --package wasmer-spectests

before_deploy:
after_build:
- cd ./src/installer
- iscc wasmer.iss
- copy /y .\WasmerInstaller.exe ..\..\WasmerInstaller-%APPVEYOR_REPO_TAG_NAME%.exe
- appveyor PushArtifact WasmerInstaller-%APPVEYOR_REPO_TAG_NAME%.exe

artifacts:
- path: WasmerInstaller-%APPVEYOR_REPO_TAG_NAME%.exe
name: WasmerInstaller.exe
- appveyor PushArtifact ..\..\WasmerInstaller-%APPVEYOR_REPO_TAG_NAME%.exe
- cd ..\..\

deploy:
description: 'WasmerInstaller'
Expand Down
11 changes: 2 additions & 9 deletions lib/runtime-core/src/sys/windows/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Memory {

let protect = protection.to_protect_const();

let ptr = unsafe { VirtualAlloc(ptr::null_mut(), size, MEM_RESERVE | MEM_COMMIT, protect) };
let ptr = unsafe { VirtualAlloc(ptr::null_mut(), size, MEM_RESERVE, protect) };

if ptr.is_null() {
Err("unable to allocate memory".to_string())
Expand All @@ -57,14 +57,7 @@ impl Memory {

let size = round_up_to_page_size(size, page_size::get());

let ptr = unsafe {
VirtualAlloc(
ptr::null_mut(),
size,
MEM_RESERVE | MEM_COMMIT,
PAGE_NOACCESS,
)
};
let ptr = unsafe { VirtualAlloc(ptr::null_mut(), size, MEM_RESERVE, PAGE_NOACCESS) };

if ptr.is_null() {
Err(MemoryCreationError::VirtualMemoryAllocationFailed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ __declspec(thread) DWORD64 caughtInstructionPointer;
__declspec(thread) PVOID savedStackPointer;
__declspec(thread) BOOL exceptionHandlerInstalled = FALSE;
__declspec(thread) BOOL alreadyHandlingException = FALSE;
__declspec(thread) PVOID handle;

void longjmpOutOfHere() {
longjmp(jmpBuf, 1);
Expand Down Expand Up @@ -38,6 +39,14 @@ exceptionHandler(struct _EXCEPTION_POINTERS *ExceptionInfo) {
return EXCEPTION_CONTINUE_EXECUTION;
}

static void removeExceptionHandler() {
if (exceptionHandlerInstalled == FALSE) {
return;
}
RemoveVectoredExceptionHandler(handle);
exceptionHandlerInstalled = FALSE;
}

uint8_t callProtected(trampoline_t trampoline,
const struct wasmer_instance_context_t* ctx,
const struct func_t* func,
Expand All @@ -48,7 +57,7 @@ uint8_t callProtected(trampoline_t trampoline,
// install exception handler
if (exceptionHandlerInstalled == FALSE) {
exceptionHandlerInstalled = TRUE;
AddVectoredExceptionHandler(CALL_FIRST, exceptionHandler);
handle = AddVectoredExceptionHandler(CALL_FIRST, exceptionHandler);
}

// jmp jmp jmp!
Expand All @@ -60,6 +69,8 @@ uint8_t callProtected(trampoline_t trampoline,
out_result->code = 0;
out_result->exceptionAddress = 0;
out_result->instructionPointer = 0;

removeExceptionHandler();
return TRUE;
}

Expand All @@ -70,5 +81,6 @@ uint8_t callProtected(trampoline_t trampoline,
caughtExceptionAddress = 0;
caughtInstructionPointer = 0;

removeExceptionHandler();
return FALSE;
}

0 comments on commit bde2022

Please sign in to comment.