Skip to content

Commit

Permalink
Merge #513
Browse files Browse the repository at this point in the history
513: Fix lseek in emscripten r=syrusakbary a=syrusakbary

Fix lseek in emscripten

Co-authored-by: Syrus <[email protected]>
  • Loading branch information
bors[bot] and syrusakbary committed Jun 27, 2019
2 parents c54a533 + 6cc41f8 commit 9f333bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ All PRs to the Wasmer repository must add to this file.
Blocks of changes will separated by version increments.

## **[Unreleased]**
- [#513](https://github.com/wasmerio/wasmer/pull/510) Fix emscripten lseek implementation.
- [#510](https://github.com/wasmerio/wasmer/pull/510) Simplify construction of floating point constants in LLVM backend. Fix LLVM assertion failure due to definition of %ctx.

## 0.5.1 - 2019-06-24
Expand Down
21 changes: 9 additions & 12 deletions lib/emscripten/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use super::env;
use std::cell::Cell;
#[allow(unused_imports)]
use std::io::Error;
use std::mem;
use std::slice;

/// exit
Expand Down Expand Up @@ -437,23 +436,21 @@ pub fn ___syscall140(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
// -> c_int
debug!("emscripten::___syscall140 (lseek) {}", _which);
let fd: i32 = varargs.get(ctx);
let _ = varargs.get::<i32>(ctx); // ignore high offset
let _offset_high: i32 = varargs.get(ctx); // We don't use the offset high as emscripten skips it
let offset_low: i32 = varargs.get(ctx);
let result_ptr_value = varargs.get::<i32>(ctx);
let result_ptr_value: WasmPtr<i64> = varargs.get(ctx);
let whence: i32 = varargs.get(ctx);
let offset = offset_low as off_t;
let ret = unsafe { lseek(fd, offset, whence) as i32 };
#[allow(clippy::cast_ptr_alignment)]
let result_ptr = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value) as *mut i32;
assert_eq!(8, mem::align_of_val(&result_ptr));
unsafe {
*result_ptr = ret;
}
let ret = unsafe { lseek(fd, offset, whence) as i64 };

let result_ptr = result_ptr_value.deref(ctx.memory(0)).unwrap();
result_ptr.set(ret);

debug!(
"=> fd: {}, offset: {}, result_ptr: {}, whence: {} = {}\nlast os error: {}",
"=> fd: {}, offset: {}, result: {}, whence: {} = {}\nlast os error: {}",
fd,
offset,
result_ptr_value,
ret,
whence,
0,
Error::last_os_error(),
Expand Down

0 comments on commit 9f333bd

Please sign in to comment.