From 78e94fe29b0af964f92d012f59e277a796223041 Mon Sep 17 00:00:00 2001 From: "Tate, Hongliang Tian" Date: Wed, 9 Jan 2019 22:50:39 +0800 Subject: [PATCH] Add sync syscall --- src/Enclave.edl | 1 + src/libos/include/syscall.h | 2 ++ src/libos/src/fs/mod.rs | 9 +++++++++ src/libos/src/syscall/mod.rs | 13 +++++++++++++ src/libos/src/syscall/syscall_entry.c | 4 ++++ src/pal/pal.c | 4 ++++ 6 files changed, 33 insertions(+) diff --git a/src/Enclave.edl b/src/Enclave.edl index e3a2014e..71bbdd60 100644 --- a/src/Enclave.edl +++ b/src/Enclave.edl @@ -15,5 +15,6 @@ enclave { void ocall_print_string([in, string] const char* msg); int ocall_run_new_task(void); void ocall_gettimeofday([out] long* seconds, [out] long* microseconds); + void ocall_sync(void); }; }; diff --git a/src/libos/include/syscall.h b/src/libos/include/syscall.h index 9d76aad4..756807f7 100644 --- a/src/libos/include/syscall.h +++ b/src/libos/include/syscall.h @@ -19,6 +19,8 @@ extern ssize_t occlum_write(int fd, const void* buf, size_t size); extern ssize_t occlum_writev(int fd, const struct iovec* iov, int count); extern off_t occlum_lseek(int fd, off_t offset, int whence); +extern int occlum_sync(void); + extern int occlum_pipe(int fds[2]); extern int occlum_pipe2(int fds[2], int flags); diff --git a/src/libos/src/fs/mod.rs b/src/libos/src/fs/mod.rs index 48871f6a..018baf9d 100644 --- a/src/libos/src/fs/mod.rs +++ b/src/libos/src/fs/mod.rs @@ -153,3 +153,12 @@ pub fn do_dup3(old_fd: FileDesc, new_fd: FileDesc, flags: u32) -> Result Result<(), Error> { + unsafe { ocall_sync(); } + Ok(()) +} + +extern { + fn ocall_sync() -> sgx_status_t; +} diff --git a/src/libos/src/syscall/mod.rs b/src/libos/src/syscall/mod.rs index e9cce890..8335ef89 100644 --- a/src/libos/src/syscall/mod.rs +++ b/src/libos/src/syscall/mod.rs @@ -540,6 +540,19 @@ pub extern "C" fn occlum_dup3(old_fd: c_int, new_fd: c_int, flags: c_int) } } +#[no_mangle] +pub extern "C" fn occlum_sync() -> c_int +{ + match fs::do_sync() { + Ok(()) => { + 0 as c_int + } + Err(e) => { + e.errno.as_retval() + } + } +} + // TODO: handle tz: timezone_t #[no_mangle] pub extern "C" fn occlum_gettimeofday(tv: *mut timeval_t) -> c_int diff --git a/src/libos/src/syscall/syscall_entry.c b/src/libos/src/syscall/syscall_entry.c index 75be0c7c..ba4579f9 100644 --- a/src/libos/src/syscall/syscall_entry.c +++ b/src/libos/src/syscall/syscall_entry.c @@ -85,6 +85,10 @@ long dispatch_syscall(int num, long arg0, long arg1, long arg2, long arg3, long ret = occlum_getppid(); break; } + case SYS_sync: { + ret = occlum_sync(); + break; + } case SYS_mmap: { DECL_SYSCALL_ARG(void*, addr, arg0); DECL_SYSCALL_ARG(size_t, length, arg1); diff --git a/src/pal/pal.c b/src/pal/pal.c index c8399074..91d3cf31 100644 --- a/src/pal/pal.c +++ b/src/pal/pal.c @@ -205,6 +205,10 @@ void ocall_gettimeofday(long* seconds, long* microseconds) { *microseconds = tv.tv_usec; } +void ocall_sync(void) { + sync(); +} + /* Application entry */ int SGX_CDECL main(int argc, const char *argv[])