Skip to content

Commit

Permalink
Merge pull request #59 from yomaytk/llvm-opt2
Browse files Browse the repository at this point in the history
Fix clock syscall for browser.
  • Loading branch information
yomaytk authored Sep 23, 2024
2 parents 3f083b2 + e33cca1 commit 919e51d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions runtime/syscalls/SyscallBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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) */
Expand Down
4 changes: 2 additions & 2 deletions scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 919e51d

Please sign in to comment.