Fix localtime implementation

This commit is contained in:
Steve Akinyemi
2018-12-07 14:50:35 +01:00
parent bbb2f080cc
commit 181837d7cc
6 changed files with 164 additions and 87 deletions

View File

@ -18,7 +18,7 @@ mod time;
mod utils;
mod varargs;
pub use self::storage::{align_memory, static_alloc};
pub use self::storage::{align_memory};
pub use self::utils::{is_emscripten_module, allocate_on_stack, allocate_cstr_on_stack};
// TODO: Magic number - how is this calculated?
@ -27,6 +27,8 @@ const TOTAL_STACK: u32 = 5242880;
const DYNAMICTOP_PTR_DIFF: u32 = 1088;
// TODO: make this variable
const STATIC_BUMP: u32 = 215536;
// TODO: make this variable
const GLOBAL_BASE: u32 = 1024;
fn stacktop(static_bump: u32) -> u32 {
align_memory(dynamictop_ptr(static_bump) + 4)
@ -44,11 +46,10 @@ fn dynamictop_ptr(static_bump: u32) -> u32 {
static_bump + DYNAMICTOP_PTR_DIFF
}
// fn static_alloc(size: usize, static_top: &mut size) -> usize {
// let ret = *static_top;
// *static_top = (*static_top + size + 15) & (-16 as usize);
// ret
// }
pub fn statictop(static_bump: u32) -> u32 {
GLOBAL_BASE + 5520
}
pub fn emscripten_set_up_memory(memory: &mut LinearMemory) {
let dynamictop_ptr = dynamictop_ptr(STATIC_BUMP) as usize;
@ -383,6 +384,11 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
"_clock_gettime",
ImportValue::Func(time::_clock_gettime as _),
);
import_object.set(
"env",
"_asctime",
ImportValue::Func(time::_asctime as _),
);
import_object.set(
"env",
"_localtime",
@ -393,7 +399,7 @@ pub fn generate_emscripten_env<'a, 'b>() -> ImportObject<&'a str, &'b str> {
import_object.set(
"env",
"_localtime_r",
ImportValue::Func(env::_localtime_r as _),
ImportValue::Func(time::_localtime_r as _),
);
import_object.set(
"env",