From 92a97d1dd486f793d35a33fa7b111d34f0e4e657 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Wed, 5 Dec 2018 15:14:58 -0800 Subject: [PATCH] Added emscripten _sysconf --- Cargo.lock | 2 +- src/apis/emscripten/env.rs | 10 +++++++++- src/apis/emscripten/mod.rs | 7 ++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc345ad5915..a9e9873ecac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -675,7 +675,7 @@ dependencies = [ [[package]] name = "wasmer" -version = "0.1.0" +version = "0.1.1" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "cranelift-codegen 0.23.0", diff --git a/src/apis/emscripten/env.rs b/src/apis/emscripten/env.rs index f10bd8f770d..cd4e8db4bc3 100644 --- a/src/apis/emscripten/env.rs +++ b/src/apis/emscripten/env.rs @@ -1,6 +1,6 @@ use super::super::host; /// NOTE: These syscalls only support wasm_32 for now because they take u32 offset -use libc::{c_int, getgrnam as libc_getgrnam, getpwnam as libc_getpwnam}; +use libc::{c_int, getgrnam as libc_getgrnam, getpwnam as libc_getpwnam, c_long, sysconf}; use std::ffi::CStr; use std::mem; use std::os::raw::c_char; @@ -110,3 +110,11 @@ pub extern "C" fn _getpagesize() -> u32 { pub extern "C" fn ___build_environment(environ: c_int) { debug!("emscripten::___build_environment {}", environ); } + +pub extern "C" fn _sysconf(name: c_int, instance: &mut Instance) -> c_long { + debug!("emscripten::_sysconf {}", name); + // TODO: Implement like emscripten expects regarding memory/page size + unsafe { + sysconf(name) + } +} diff --git a/src/apis/emscripten/mod.rs b/src/apis/emscripten/mod.rs index cca522fc834..ad6165211d2 100644 --- a/src/apis/emscripten/mod.rs +++ b/src/apis/emscripten/mod.rs @@ -409,12 +409,17 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> { "_getpagesize", ImportValue::Func(env::_getpagesize as _), ); + import_object.set( + "env", + "_sysconf", + ImportValue::Func(env::_sysconf as _), + ); mock_external!(import_object, _waitpid); mock_external!(import_object, _utimes); mock_external!(import_object, _usleep); // mock_external!(import_object, _time); - mock_external!(import_object, _sysconf); + // mock_external!(import_object, _sysconf); // mock_external!(import_object, _strftime); mock_external!(import_object, _sigsuspend); // mock_external!(import_object, _sigprocmask);