about summary refs log tree commit diff
path: root/src/libstd/os
diff options
context:
space:
mode:
authorJethro Beekman <jethro@fortanix.com>2018-12-19 17:26:17 +0530
committerJethro Beekman <jethro@fortanix.com>2018-12-20 10:09:52 +0530
commitdcb5db80b25b8e7fe2ce3a382b793673803cbc1a (patch)
treef8bd289683c752af7ff09901cb4d20f5d701851f /src/libstd/os
parent38f5c97c3383fb8424fbde6ccdc1aaad4c28ae0f (diff)
downloadrust-dcb5db80b25b8e7fe2ce3a382b793673803cbc1a.tar.gz
rust-dcb5db80b25b8e7fe2ce3a382b793673803cbc1a.zip
Add `std::os::fortanix_sgx` module
Diffstat (limited to 'src/libstd/os')
-rw-r--r--src/libstd/os/fortanix_sgx/mod.rs67
-rw-r--r--src/libstd/os/mod.rs1
2 files changed, 68 insertions, 0 deletions
diff --git a/src/libstd/os/fortanix_sgx/mod.rs b/src/libstd/os/fortanix_sgx/mod.rs
new file mode 100644
index 00000000000..825e7f359d6
--- /dev/null
+++ b/src/libstd/os/fortanix_sgx/mod.rs
@@ -0,0 +1,67 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Functionality specific to the `x86_64-fortanix-unknown-sgx` target.
+//!
+//! This includes functions to deal with memory isolation, usercalls, and the
+//! SGX instruction set.
+
+#![deny(missing_docs, missing_debug_implementations)]
+#![unstable(feature = "sgx_platform", issue = "56975")]
+
+/// Low-level interfaces to usercalls. See the [ABI documentation] for more
+/// information.
+///
+/// [ABI documentation]: https://docs.rs/fortanix-sgx-abi/
+pub mod usercalls {
+    pub use sys::abi::usercalls::*;
+
+    /// Primitives for allocating memory in userspace as well as copying data
+    /// to and from user memory.
+    pub mod alloc {
+        pub use sys::abi::usercalls::alloc;
+    }
+
+    /// Lowest-level interfaces to usercalls and usercall ABI type definitions.
+    pub mod raw {
+        use sys::abi::usercalls::raw::invoke_with_usercalls;
+        pub use sys::abi::usercalls::raw::do_usercall;
+        pub use sys::abi::usercalls::raw::{accept_stream, alloc, async_queues, bind_stream, close,
+                                           connect_stream, exit, flush, free, insecure_time,
+                                           launch_thread, read, read_alloc, send, wait, write};
+
+        macro_rules! define_usercallnrs {
+            ($(fn $f:ident($($n:ident: $t:ty),*) $(-> $r:ty)*; )*) => {
+                /// Usercall numbers as per the ABI.
+                #[repr(C)]
+                #[unstable(feature = "sgx_platform", issue = "56975")]
+                #[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
+                #[allow(missing_docs)]
+                pub enum UsercallNrs {
+                    $($f,)*
+                }
+            };
+        }
+        invoke_with_usercalls!(define_usercallnrs);
+
+        // fortanix-sgx-abi re-exports
+        pub use sys::abi::usercalls::raw::{ByteBuffer, FifoDescriptor, Return, Usercall};
+        pub use sys::abi::usercalls::raw::Error;
+        pub use sys::abi::usercalls::raw::{EV_RETURNQ_NOT_EMPTY, EV_UNPARK, EV_USERCALLQ_NOT_FULL,
+                                           FD_STDERR, FD_STDIN, FD_STDOUT, RESULT_SUCCESS,
+                                           USERCALL_USER_DEFINED, WAIT_INDEFINITE, WAIT_NO};
+        pub use sys::abi::usercalls::raw::{Fd, Result, Tcs};
+    }
+}
+
+/// Functions for querying mapping information for pointers.
+pub mod mem {
+    pub use sys::abi::mem::*;
+}
diff --git a/src/libstd/os/mod.rs b/src/libstd/os/mod.rs
index 0ab8fa424e3..ba5b938ed4c 100644
--- a/src/libstd/os/mod.rs
+++ b/src/libstd/os/mod.rs
@@ -61,5 +61,6 @@ cfg_if! {
 #[cfg(target_os = "emscripten")] pub mod emscripten;
 #[cfg(target_os = "fuchsia")]    pub mod fuchsia;
 #[cfg(target_os = "hermit")]     pub mod hermit;
+#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] pub mod fortanix_sgx;
 
 pub mod raw;