From c39b6f1dc2654171fb10f0217643099ecdf21939 Mon Sep 17 00:00:00 2001 From: He Sun Date: Fri, 25 Sep 2020 22:27:17 +0800 Subject: [PATCH] Eliminate compiler warnings --- src/libos/src/exception/mod.rs | 18 +++--------------- src/libos/src/interrupt/mod.rs | 18 +++--------------- src/libos/src/lib.rs | 2 -- src/libos/src/syscall/mod.rs | 21 +++++++++++++++++++++ 4 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/libos/src/exception/mod.rs b/src/libos/src/exception/mod.rs index e14ec0f0..bb193141 100644 --- a/src/libos/src/exception/mod.rs +++ b/src/libos/src/exception/mod.rs @@ -5,6 +5,7 @@ use self::rdtsc::{handle_rdtsc_exception, RDTSC_OPCODE}; use self::syscall::{handle_syscall_exception, SYSCALL_OPCODE}; use super::*; use crate::signal::{FaultSignal, SigSet}; +use crate::syscall::exception_interrupt_syscall_c_abi; use crate::syscall::{CpuContext, FpRegs, SyscallNum}; use aligned::{Aligned, A16}; use core::arch::x86_64::_fxsave; @@ -26,24 +27,11 @@ pub fn register_exception_handlers() { #[no_mangle] extern "C" fn handle_exception(info: *mut sgx_exception_info_t) -> i32 { - // Rust compiler would complain about passing to external C functions a CpuContext - // pointer, which includes a FpRegs pointer that is not safe to use by external - // modules. In our case, the FpRegs pointer will not be used actually. So the - // Rust warning is a false alarm. We suppress it here. - #[allow(improper_ctypes)] - extern "C" { - fn __occlum_syscall_c_abi( - num: u32, - info: *mut sgx_exception_info_t, - fpregs: *mut FpRegs, - ) -> u32; - } - let mut fpregs = FpRegs::save(); unsafe { - __occlum_syscall_c_abi( + exception_interrupt_syscall_c_abi( SyscallNum::HandleException as u32, - info, + info as *mut _, &mut fpregs as *mut FpRegs, ) }; diff --git a/src/libos/src/interrupt/mod.rs b/src/libos/src/interrupt/mod.rs index c532faef..c3b14bdf 100644 --- a/src/libos/src/interrupt/mod.rs +++ b/src/libos/src/interrupt/mod.rs @@ -1,6 +1,7 @@ pub use self::sgx::sgx_interrupt_info_t; use crate::prelude::*; use crate::process::ThreadRef; +use crate::syscall::exception_interrupt_syscall_c_abi; use crate::syscall::{CpuContext, FpRegs, SyscallNum}; use aligned::{Aligned, A16}; use core::arch::x86_64::_fxsave; @@ -15,24 +16,11 @@ pub fn init() { } extern "C" fn handle_interrupt(info: *mut sgx_interrupt_info_t) -> i32 { - // Rust compiler would complain about passing to external C functions a CpuContext - // pointer, which includes a FpRegs pointer that is not safe to use by external - // modules. In our case, the FpRegs pointer will not be used actually. So the - // Rust warning is a false alarm. We suppress it here. - #[allow(improper_ctypes)] - extern "C" { - fn __occlum_syscall_c_abi( - num: u32, - info: *mut sgx_interrupt_info_t, - fpregs: *mut FpRegs, - ) -> u32; - } - let mut fpregs = FpRegs::save(); unsafe { - __occlum_syscall_c_abi( + exception_interrupt_syscall_c_abi( SyscallNum::HandleInterrupt as u32, - info, + info as *mut _, &mut fpregs as *mut FpRegs, ) }; diff --git a/src/libos/src/lib.rs b/src/libos/src/lib.rs index 1d915bac..8e98315c 100644 --- a/src/libos/src/lib.rs +++ b/src/libos/src/lib.rs @@ -6,8 +6,6 @@ #![feature(allocator_api)] #![feature(core_intrinsics)] #![feature(stmt_expr_attributes)] -#![feature(atomic_min_max)] -#![feature(no_more_cas)] #![feature(alloc_layout_extra)] #![feature(concat_idents)] #![feature(trace_macros)] diff --git a/src/libos/src/syscall/mod.rs b/src/libos/src/syscall/mod.rs index bc8fcd95..2fbf5189 100644 --- a/src/libos/src/syscall/mod.rs +++ b/src/libos/src/syscall/mod.rs @@ -994,3 +994,24 @@ impl CpuContext { } } } + +// exception and interrupt syscalls share the same c abi +// +// num: occlum syscall number +// info: pointer to sgx_exception_info_t or sgx_interrupt_info_t +// fpregs: pointer to FpRegs. Rust compiler would complain about passing +// to external C functions a CpuContext pointer, which includes a FpRegs +// pointer that is not safe to use by external modules. In our case, the +// FpRegs pointer will not be used actually. So the Rust warning is a +// false alarm. We suppress it here. +pub unsafe fn exception_interrupt_syscall_c_abi( + num: u32, + info: *mut c_void, + fpregs: *mut FpRegs, +) -> u32 { + #[allow(improper_ctypes)] + extern "C" { + pub fn __occlum_syscall_c_abi(num: u32, info: *mut c_void, fpregs: *mut FpRegs) -> u32; + } + __occlum_syscall_c_abi(num, info, fpregs) +}