mirror of
https://github.com/fluencelabs/wasmer
synced 2024-12-13 22:25:40 +00:00
Make reading database files work too!
This commit is contained in:
parent
3500d5a7c7
commit
93432bdb12
@ -28,6 +28,7 @@ use libc::{
|
||||
getpid,
|
||||
// iovec,
|
||||
lseek,
|
||||
off_t,
|
||||
// open,
|
||||
read,
|
||||
// readv,
|
||||
@ -41,6 +42,8 @@ use wasmer_runtime_core::vm::Ctx;
|
||||
|
||||
use super::env;
|
||||
use std::cell::Cell;
|
||||
#[allow(unused_imports)]
|
||||
use std::io::Error;
|
||||
use std::slice;
|
||||
|
||||
/// exit
|
||||
@ -254,10 +257,26 @@ 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 offset: i32 = varargs.get(ctx);
|
||||
let _ = varargs.get::<i32>(ctx); // ignore high offset
|
||||
let offset_low: i32 = varargs.get(ctx);
|
||||
let result_ptr_value = varargs.get::<i32>(ctx);
|
||||
let whence: i32 = varargs.get(ctx);
|
||||
debug!("=> fd: {}, offset: {}, whence = {}", fd, offset, whence);
|
||||
unsafe { lseek(fd, offset as _, whence) as _ }
|
||||
let offset = offset_low as off_t;
|
||||
let ret = unsafe { lseek(fd, offset, whence) as i32 };
|
||||
let result_ptr = emscripten_memory_pointer!(ctx.memory(0), result_ptr_value) as *mut i32;
|
||||
unsafe {
|
||||
*result_ptr = ret;
|
||||
}
|
||||
debug!(
|
||||
"=> fd: {}, offset: {}, result_ptr: {}, whence: {} = {}\nlast os error: {}",
|
||||
fd,
|
||||
offset,
|
||||
result_ptr_value,
|
||||
whence,
|
||||
0,
|
||||
Error::last_os_error(),
|
||||
);
|
||||
0
|
||||
}
|
||||
|
||||
/// readv
|
||||
@ -343,16 +362,6 @@ pub fn ___syscall191(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
-1
|
||||
}
|
||||
|
||||
pub fn ___syscall194(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall194 - stub");
|
||||
-1
|
||||
}
|
||||
|
||||
pub fn ___syscall196(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall194 - stub");
|
||||
-1
|
||||
}
|
||||
|
||||
pub fn ___syscall199(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall199 - stub");
|
||||
-1
|
||||
@ -369,7 +378,14 @@ pub fn ___syscall195(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
||||
unsafe {
|
||||
let mut _stat: stat = std::mem::zeroed();
|
||||
let ret = stat(pathname_addr, &mut _stat);
|
||||
debug!("ret: {}", ret);
|
||||
debug!(
|
||||
"=> pathname: {}, buf: {}, path: {} = {}\nlast os error: {}",
|
||||
pathname,
|
||||
buf,
|
||||
std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap(),
|
||||
ret,
|
||||
Error::last_os_error()
|
||||
);
|
||||
if ret != 0 {
|
||||
return ret;
|
||||
}
|
||||
@ -408,8 +424,14 @@ pub fn ___syscall221(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
||||
// fcntl64
|
||||
let _fd: i32 = varargs.get(ctx);
|
||||
let cmd: u32 = varargs.get(ctx);
|
||||
// (FAPPEND - 0x08
|
||||
// |FASYNC - 0x40
|
||||
// |FFSYNC - 0x80
|
||||
// |FNONBLOCK - 0x04
|
||||
debug!("=> fd: {}, cmd: {}", _fd, cmd);
|
||||
match cmd {
|
||||
2 => 0,
|
||||
13 | 14 => 0, // pretend file locking worked
|
||||
_ => -1,
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,8 @@ use libc::{
|
||||
};
|
||||
use wasmer_runtime_core::vm::Ctx;
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use std::io::Error;
|
||||
use std::mem;
|
||||
|
||||
// Linking to functions that are not provided by rust libc
|
||||
@ -82,10 +84,11 @@ extern "C" {
|
||||
pub fn wait4(pid: pid_t, status: *mut c_int, options: c_int, rusage: *mut rusage) -> pid_t;
|
||||
pub fn madvise(addr: *mut c_void, len: size_t, advice: c_int) -> c_int;
|
||||
pub fn fdatasync(fd: c_int) -> c_int;
|
||||
pub fn lstat64(path: *const c_char, buf: *mut c_void) -> c_int;
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
use libc::{fallocate, fdatasync, madvise, wait4};
|
||||
use libc::{fallocate, fdatasync, ftruncate64, lstat64, madvise, wait4};
|
||||
|
||||
// Another conditional constant for name resolution: Macos et iOS use
|
||||
// SO_NOSIGPIPE as a setsockopt flag to disable SIGPIPE emission on socket.
|
||||
@ -105,8 +108,13 @@ pub fn ___syscall5(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int
|
||||
let _path_str = unsafe { std::ffi::CStr::from_ptr(pathname_addr).to_str().unwrap() };
|
||||
let fd = unsafe { open(pathname_addr, flags, mode) };
|
||||
debug!(
|
||||
"=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}",
|
||||
pathname, flags, mode, fd, _path_str
|
||||
"=> pathname: {}, flags: {}, mode: {} = fd: {}\npath: {}\nlast os error: {}",
|
||||
pathname,
|
||||
flags,
|
||||
mode,
|
||||
fd,
|
||||
_path_str,
|
||||
Error::last_os_error(),
|
||||
);
|
||||
fd
|
||||
}
|
||||
@ -159,6 +167,19 @@ pub fn ___syscall83(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int
|
||||
result
|
||||
}
|
||||
|
||||
/// ftruncate64
|
||||
pub fn ___syscall194(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall194 (ftruncate64) {}", _which);
|
||||
let _fd: c_int = varargs.get(ctx);
|
||||
let _length: i64 = varargs.get(ctx);
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
unsafe {
|
||||
ftruncate64(_fd, _length)
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// lchown
|
||||
pub fn ___syscall198(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall198 (lchown) {}", _which);
|
||||
@ -738,6 +759,25 @@ pub fn ___syscall122(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_in
|
||||
unsafe { uname(buf_addr) }
|
||||
}
|
||||
|
||||
/// lstat64
|
||||
pub fn ___syscall196(ctx: &mut Ctx, _which: i32, mut varargs: VarArgs) -> i32 {
|
||||
debug!("emscripten::___syscall196 (lstat64) {}", _which);
|
||||
let path_ptr: c_int = varargs.get(ctx);
|
||||
let buf_ptr: c_int = varargs.get(ctx);
|
||||
let path = emscripten_memory_pointer!(ctx.memory(0), path_ptr) as *const c_char;
|
||||
let buf = emscripten_memory_pointer!(ctx.memory(0), buf_ptr) as *mut c_void;
|
||||
let result = unsafe { lstat64(path, buf as _) };
|
||||
debug!(
|
||||
"=> path: {}, buf: {} = fd: {}\npath: {}\nlast os error: {}",
|
||||
path_ptr,
|
||||
buf_ptr,
|
||||
result,
|
||||
unsafe { std::ffi::CStr::from_ptr(path).to_str().unwrap() },
|
||||
Error::last_os_error(),
|
||||
);
|
||||
result
|
||||
}
|
||||
|
||||
/// fallocate
|
||||
pub fn ___syscall324(ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall324 (fallocate) {}", _which);
|
||||
|
@ -64,6 +64,12 @@ pub fn ___syscall9(_ctx: &mut Ctx, _which: c_int, mut varargs: VarArgs) -> c_int
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
/// ftruncate64
|
||||
pub fn ___syscall194(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall194 - stub");
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
// chown
|
||||
pub fn ___syscall212(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall212 (chown) {}", which);
|
||||
@ -239,6 +245,12 @@ pub fn ___syscall122(_ctx: &mut Ctx, which: c_int, mut _varargs: VarArgs) -> c_i
|
||||
-1
|
||||
}
|
||||
|
||||
/// lstat64
|
||||
pub fn ___syscall196(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
||||
debug!("emscripten::___syscall196 (lstat64) - stub");
|
||||
-1
|
||||
}
|
||||
|
||||
/// fchown
|
||||
pub fn ___syscall207(_ctx: &mut Ctx, _which: c_int, _varargs: VarArgs) -> c_int {
|
||||
debug!("emscripten::___syscall207 (fchown) {}", _which);
|
||||
|
Loading…
Reference in New Issue
Block a user