From e33cca194088f36f5d5d2ab2d84d18901617e27b Mon Sep 17 00:00:00 2001 From: yomaytk Date: Mon, 23 Sep 2024 18:14:10 +0900 Subject: [PATCH] Fix clock syscall for browser. --- runtime/syscalls/SyscallBrowser.cpp | 21 ++++++++++++++++++--- scripts/dev.sh | 4 ++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/runtime/syscalls/SyscallBrowser.cpp b/runtime/syscalls/SyscallBrowser.cpp index f7c7205..c27c2ad 100644 --- a/runtime/syscalls/SyscallBrowser.cpp +++ b/runtime/syscalls/SyscallBrowser.cpp @@ -29,6 +29,14 @@ # define NOP_SYSCALL(sysnum) ; #endif +#if defined(__wasm32__) +typedef uint32_t _ecv_long; +#elif defined(__wasm64__) +typedef uint64_t _ecv_long; +#else +typedef uint32_t _ecv_long; +#endif + /* for ioctl syscall */ @@ -199,10 +207,17 @@ void RuntimeManager::SVCBrowserCall(void) { break; case AARCH64_SYS_CLOCK_GETTIME: /* clock_gettime (clockid_t which_clock, struct __kernel_timespace *tp) */ { - clockid_t which_clock = state_gpr.x0.dword; struct timespec emu_tp; - int clock_time = clock_gettime(which_clock, &emu_tp); - memcpy(TranslateVMA(state_gpr.x1.qword), &emu_tp, sizeof(timespec)); + int clock_time = clock_gettime(CLOCK_REALTIME, &emu_tp); + // int clock_time = clock_gettime(state_gpr.x0.dword, &emu_tp); throw error. + struct { + uint64_t tv_sec; /* time_t */ + uint64_t tv_nsec; /* long (assume that the from target architecture is 64bit) */ + } tp = { + .tv_sec = (uint64_t) emu_tp.tv_sec, + .tv_nsec = (uint64_t) (_ecv_long) emu_tp.tv_nsec, + }; + memcpy(TranslateVMA(state_gpr.x1.qword), &tp, sizeof(tp)); state_gpr.x0.qword = (_ecv_reg64_t) clock_time; } break; case AARCH64_SYS_TGKILL: /* tgkill (pid_t tgid, pid_t pid, int sig) */ diff --git a/scripts/dev.sh b/scripts/dev.sh index e0ad738..aab596f 100755 --- a/scripts/dev.sh +++ b/scripts/dev.sh @@ -111,8 +111,8 @@ main() { $WASMCC $WASMCCFLAGS $ELFCONV_MACROS $ELFCONV_DEBUG_MACROS -o VmIntrinsics.wasm.o -c ${RUNTIME_DIR}/VmIntrinsics.cpp && \ $WASMCC $WASMCCFLAGS $ELFCONV_MACROS $ELFCONV_DEBUG_MACROS -o Util.wasm.o -c ${UTILS_DIR}/Util.cpp && \ $WASMCC $WASMCCFLAGS $ELFCONV_MACROS $ELFCONV_DEBUG_MACROS -o elfconv.wasm.o -c ${UTILS_DIR}/elfconv.cpp && \ - $WASMCC -c lift.ll -o lift.wasm.o - $WASMCC -o exe.wasm.html -sWASM -sALLOW_MEMORY_GROWTH lift.wasm.o Entry.wasm.o Runtime.wasm.o Memory.wasm.o Syscall.wasm.o \ + $WASMCC $WASMCCFLAGS -c lift.ll -o lift.wasm.o + $WASMCC $WASMCCFLAGS -o exe.wasm.html -sALLOW_MEMORY_GROWTH lift.wasm.o Entry.wasm.o Runtime.wasm.o Memory.wasm.o Syscall.wasm.o \ VmIntrinsics.wasm.o Util.wasm.o elfconv.wasm.o echo -e "[\033[32mINFO\033[0m] Generate WASM binary." # delete obj