mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-22 08:52:13 +00:00
add the syscall and create a test
This commit is contained in:
parent
c9969f269c
commit
ad3d361f76
10
lib/emscripten/emtests/test_getcwd.c
vendored
Normal file
10
lib/emscripten/emtests/test_getcwd.c
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
const unsigned int size = 256;
|
||||||
|
char cwd[size] = {};
|
||||||
|
char* buf = getcwd(cwd, size);
|
||||||
|
printf("getcwd\n");
|
||||||
|
return 0;
|
||||||
|
}
|
1
lib/emscripten/emtests/test_getcwd.out
vendored
Normal file
1
lib/emscripten/emtests/test_getcwd.out
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
getcwd
|
BIN
lib/emscripten/emtests/test_getcwd.wasm
vendored
Normal file
BIN
lib/emscripten/emtests/test_getcwd.wasm
vendored
Normal file
Binary file not shown.
@ -502,6 +502,7 @@ pub fn generate_emscripten_env(globals: &mut EmscriptenGlobals) -> ImportObject
|
|||||||
"___syscall168" => func!(crate::syscalls::___syscall168),
|
"___syscall168" => func!(crate::syscalls::___syscall168),
|
||||||
"___syscall180" => func!(crate::syscalls::___syscall180),
|
"___syscall180" => func!(crate::syscalls::___syscall180),
|
||||||
"___syscall181" => func!(crate::syscalls::___syscall181),
|
"___syscall181" => func!(crate::syscalls::___syscall181),
|
||||||
|
"___syscall183" => func!(crate::syscalls::___syscall183),
|
||||||
"___syscall191" => func!(crate::syscalls::___syscall191),
|
"___syscall191" => func!(crate::syscalls::___syscall191),
|
||||||
"___syscall192" => func!(crate::syscalls::___syscall192),
|
"___syscall192" => func!(crate::syscalls::___syscall192),
|
||||||
"___syscall194" => func!(crate::syscalls::___syscall194),
|
"___syscall194" => func!(crate::syscalls::___syscall194),
|
||||||
|
@ -48,6 +48,10 @@ use std::slice;
|
|||||||
// Other platforms do otherwise.
|
// Other platforms do otherwise.
|
||||||
#[cfg(target_os = "darwin")]
|
#[cfg(target_os = "darwin")]
|
||||||
use libc::SO_NOSIGPIPE;
|
use libc::SO_NOSIGPIPE;
|
||||||
|
use crate::utils::copy_cstr_into_wasm;
|
||||||
|
use crate::env::get_emscripten_data;
|
||||||
|
use std::ffi::CString;
|
||||||
|
|
||||||
#[cfg(not(target_os = "darwin"))]
|
#[cfg(not(target_os = "darwin"))]
|
||||||
const SO_NOSIGPIPE: c_int = 0;
|
const SO_NOSIGPIPE: c_int = 0;
|
||||||
|
|
||||||
@ -186,6 +190,25 @@ pub fn ___syscall110(_ctx: &mut Ctx, _one: i32, _two: i32) -> i32 {
|
|||||||
-1
|
-1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getcwd
|
||||||
|
pub fn ___syscall183(ctx: &mut Ctx, buf: u32, _size: u32) -> u32 {
|
||||||
|
debug!("emscripten::___syscall183");
|
||||||
|
use std::env;
|
||||||
|
let path = env::current_dir();
|
||||||
|
match path {
|
||||||
|
Ok(path_buf) => {
|
||||||
|
// write path into buffer
|
||||||
|
let path_string = path_buf.display().to_string();
|
||||||
|
let path_c_string = CString::new(path_string).unwrap();
|
||||||
|
let offset = unsafe { copy_cstr_into_wasm(ctx, path_c_string.as_ptr()) };
|
||||||
|
offset
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// mmap2
|
// mmap2
|
||||||
pub fn ___syscall192(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
|
pub fn ___syscall192(ctx: &mut Ctx, which: c_int, mut varargs: VarArgs) -> c_int {
|
||||||
debug!("emscripten::___syscall192 (mmap2) {}", which);
|
debug!("emscripten::___syscall192 (mmap2) {}", which);
|
||||||
|
9
lib/emscripten/tests/emtests/test_getcwd.rs
Normal file
9
lib/emscripten/tests/emtests/test_getcwd.rs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#[test]
|
||||||
|
fn test_getcwd() {
|
||||||
|
assert_emscripten_output!(
|
||||||
|
"../../emtests/test_getcwd.wasm",
|
||||||
|
"getcwd",
|
||||||
|
vec![],
|
||||||
|
"../../emtests/test_getcwd.out"
|
||||||
|
);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user