mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Update fortanix-sgx-abi and export some useful SGX usercall traits
Update fortanix-sgx-abi to 0.5.0 to add support for cancel queue (see https://github.com/fortanix/rust-sgx/pull/405 and https://github.com/fortanix/rust-sgx/pull/404). Export some useful traits for processing SGX usercall. This is needed for https://github.com/fortanix/rust-sgx/pull/404 to avoid duplication.
This commit is contained in:
parent
a39bdb1d6b
commit
70dd980c8d
@ -1421,9 +1421,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fortanix-sgx-abi"
|
name = "fortanix-sgx-abi"
|
||||||
version = "0.3.3"
|
version = "0.5.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c56c422ef86062869b2d57ae87270608dc5929969dd130a6e248979cf4fb6ca6"
|
checksum = "57cafc2274c10fab234f176b25903ce17e690fca7597090d50880e047a0389c5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"compiler_builtins",
|
"compiler_builtins",
|
||||||
"rustc-std-workspace-core",
|
"rustc-std-workspace-core",
|
||||||
|
@ -39,7 +39,7 @@ rand = "0.7"
|
|||||||
dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] }
|
dlmalloc = { version = "0.2.3", features = ['rustc-dep-of-std'] }
|
||||||
|
|
||||||
[target.x86_64-fortanix-unknown-sgx.dependencies]
|
[target.x86_64-fortanix-unknown-sgx.dependencies]
|
||||||
fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] }
|
fortanix-sgx-abi = { version = "0.5.0", features = ['rustc-dep-of-std'] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "hermit")'.dependencies]
|
[target.'cfg(target_os = "hermit")'.dependencies]
|
||||||
hermit-abi = { version = "0.2.0", features = ['rustc-dep-of-std'] }
|
hermit-abi = { version = "0.2.0", features = ['rustc-dep-of-std'] }
|
||||||
|
@ -26,6 +26,7 @@ pub mod usercalls {
|
|||||||
free, insecure_time, launch_thread, read, read_alloc, send, wait, write,
|
free, insecure_time, launch_thread, read, read_alloc, send, wait, write,
|
||||||
};
|
};
|
||||||
pub use crate::sys::abi::usercalls::raw::{do_usercall, Usercalls as UsercallNrs};
|
pub use crate::sys::abi::usercalls::raw::{do_usercall, Usercalls as UsercallNrs};
|
||||||
|
pub use crate::sys::abi::usercalls::raw::{Register, RegisterArgument, ReturnValue};
|
||||||
|
|
||||||
// fortanix-sgx-abi re-exports
|
// fortanix-sgx-abi re-exports
|
||||||
pub use crate::sys::abi::usercalls::raw::Error;
|
pub use crate::sys::abi::usercalls::raw::Error;
|
||||||
|
@ -56,6 +56,8 @@ unsafe impl UserSafeSized for Usercall {}
|
|||||||
#[unstable(feature = "sgx_platform", issue = "56975")]
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
unsafe impl UserSafeSized for Return {}
|
unsafe impl UserSafeSized for Return {}
|
||||||
#[unstable(feature = "sgx_platform", issue = "56975")]
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
|
unsafe impl UserSafeSized for Cancel {}
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
unsafe impl<T: UserSafeSized> UserSafeSized for [T; 2] {}
|
unsafe impl<T: UserSafeSized> UserSafeSized for [T; 2] {}
|
||||||
|
|
||||||
/// A type that can be represented in memory as one or more `UserSafeSized`s.
|
/// A type that can be represented in memory as one or more `UserSafeSized`s.
|
||||||
|
@ -292,12 +292,17 @@ fn check_os_error(err: Result) -> i32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait FromSgxResult {
|
/// Translate the raw result of an SGX usercall.
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
|
pub trait FromSgxResult {
|
||||||
|
/// Return type
|
||||||
type Return;
|
type Return;
|
||||||
|
|
||||||
|
/// Translate the raw result of an SGX usercall.
|
||||||
fn from_sgx_result(self) -> IoResult<Self::Return>;
|
fn from_sgx_result(self) -> IoResult<Self::Return>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl<T> FromSgxResult for (Result, T) {
|
impl<T> FromSgxResult for (Result, T) {
|
||||||
type Return = T;
|
type Return = T;
|
||||||
|
|
||||||
@ -310,6 +315,7 @@ impl<T> FromSgxResult for (Result, T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl FromSgxResult for Result {
|
impl FromSgxResult for Result {
|
||||||
type Return = ();
|
type Return = ();
|
||||||
|
|
||||||
|
@ -37,14 +37,23 @@ pub unsafe fn do_usercall(
|
|||||||
(a, b)
|
(a, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Register = u64;
|
/// A value passed or returned in a CPU register.
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
|
pub type Register = u64;
|
||||||
|
|
||||||
trait RegisterArgument {
|
/// Translate a type from/to Register to be used as an argument.
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
|
pub trait RegisterArgument {
|
||||||
|
/// Translate a Register to Self.
|
||||||
fn from_register(_: Register) -> Self;
|
fn from_register(_: Register) -> Self;
|
||||||
|
/// Translate self to a Register.
|
||||||
fn into_register(self) -> Register;
|
fn into_register(self) -> Register;
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ReturnValue {
|
/// Translate a pair of Registers to the raw usercall return value.
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
|
pub trait ReturnValue {
|
||||||
|
/// Translate a pair of Registers to the raw usercall return value.
|
||||||
fn from_registers(call: &'static str, regs: (Register, Register)) -> Self;
|
fn from_registers(call: &'static str, regs: (Register, Register)) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +77,7 @@ macro_rules! define_usercalls {
|
|||||||
|
|
||||||
macro_rules! define_ra {
|
macro_rules! define_ra {
|
||||||
(< $i:ident > $t:ty) => {
|
(< $i:ident > $t:ty) => {
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl<$i> RegisterArgument for $t {
|
impl<$i> RegisterArgument for $t {
|
||||||
fn from_register(a: Register) -> Self {
|
fn from_register(a: Register) -> Self {
|
||||||
a as _
|
a as _
|
||||||
@ -78,6 +88,7 @@ macro_rules! define_ra {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
($i:ty as $t:ty) => {
|
($i:ty as $t:ty) => {
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl RegisterArgument for $t {
|
impl RegisterArgument for $t {
|
||||||
fn from_register(a: Register) -> Self {
|
fn from_register(a: Register) -> Self {
|
||||||
a as $i as _
|
a as $i as _
|
||||||
@ -88,6 +99,7 @@ macro_rules! define_ra {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
($t:ty) => {
|
($t:ty) => {
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl RegisterArgument for $t {
|
impl RegisterArgument for $t {
|
||||||
fn from_register(a: Register) -> Self {
|
fn from_register(a: Register) -> Self {
|
||||||
a as _
|
a as _
|
||||||
@ -112,6 +124,7 @@ define_ra!(usize as isize);
|
|||||||
define_ra!(<T> *const T);
|
define_ra!(<T> *const T);
|
||||||
define_ra!(<T> *mut T);
|
define_ra!(<T> *mut T);
|
||||||
|
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl RegisterArgument for bool {
|
impl RegisterArgument for bool {
|
||||||
fn from_register(a: Register) -> bool {
|
fn from_register(a: Register) -> bool {
|
||||||
if a != 0 { true } else { false }
|
if a != 0 { true } else { false }
|
||||||
@ -121,6 +134,7 @@ impl RegisterArgument for bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl<T: RegisterArgument> RegisterArgument for Option<NonNull<T>> {
|
impl<T: RegisterArgument> RegisterArgument for Option<NonNull<T>> {
|
||||||
fn from_register(a: Register) -> Option<NonNull<T>> {
|
fn from_register(a: Register) -> Option<NonNull<T>> {
|
||||||
NonNull::new(a as _)
|
NonNull::new(a as _)
|
||||||
@ -130,12 +144,14 @@ impl<T: RegisterArgument> RegisterArgument for Option<NonNull<T>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl ReturnValue for ! {
|
impl ReturnValue for ! {
|
||||||
fn from_registers(call: &'static str, _regs: (Register, Register)) -> Self {
|
fn from_registers(call: &'static str, _regs: (Register, Register)) -> Self {
|
||||||
rtabort!("Usercall {call}: did not expect to be re-entered");
|
rtabort!("Usercall {call}: did not expect to be re-entered");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl ReturnValue for () {
|
impl ReturnValue for () {
|
||||||
fn from_registers(call: &'static str, usercall_retval: (Register, Register)) -> Self {
|
fn from_registers(call: &'static str, usercall_retval: (Register, Register)) -> Self {
|
||||||
rtassert!(usercall_retval.0 == 0);
|
rtassert!(usercall_retval.0 == 0);
|
||||||
@ -144,6 +160,7 @@ impl ReturnValue for () {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl<T: RegisterArgument> ReturnValue for T {
|
impl<T: RegisterArgument> ReturnValue for T {
|
||||||
fn from_registers(call: &'static str, usercall_retval: (Register, Register)) -> Self {
|
fn from_registers(call: &'static str, usercall_retval: (Register, Register)) -> Self {
|
||||||
rtassert!(usercall_retval.1 == 0);
|
rtassert!(usercall_retval.1 == 0);
|
||||||
@ -151,6 +168,7 @@ impl<T: RegisterArgument> ReturnValue for T {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "sgx_platform", issue = "56975")]
|
||||||
impl<T: RegisterArgument, U: RegisterArgument> ReturnValue for (T, U) {
|
impl<T: RegisterArgument, U: RegisterArgument> ReturnValue for (T, U) {
|
||||||
fn from_registers(_call: &'static str, regs: (Register, Register)) -> Self {
|
fn from_registers(_call: &'static str, regs: (Register, Register)) -> Self {
|
||||||
(T::from_register(regs.0), U::from_register(regs.1))
|
(T::from_register(regs.0), U::from_register(regs.1))
|
||||||
|
Loading…
Reference in New Issue
Block a user