Skip to content

Commit dcb5db8

Browse files
author
Jethro Beekman
committed
Add std::os::fortanix_sgx module
1 parent 38f5c97 commit dcb5db8

File tree

13 files changed

+328
-59
lines changed

13 files changed

+328
-59
lines changed

Cargo.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
817817

818818
[[package]]
819819
name = "fortanix-sgx-abi"
820-
version = "0.3.1"
820+
version = "0.3.2"
821821
source = "registry+https://github.com/rust-lang/crates.io-index"
822822
dependencies = [
823823
"compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2890,7 +2890,7 @@ dependencies = [
28902890
"compiler_builtins 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
28912891
"core 0.0.0",
28922892
"dlmalloc 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
2893-
"fortanix-sgx-abi 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
2893+
"fortanix-sgx-abi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
28942894
"libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
28952895
"panic_abort 0.0.0",
28962896
"panic_unwind 0.0.0",
@@ -3447,7 +3447,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
34473447
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
34483448
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
34493449
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
3450-
"checksum fortanix-sgx-abi 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "26105e20b4c3f7a319db1376b54ac9a46e5761e949405553375095d05a0cee4d"
3450+
"checksum fortanix-sgx-abi 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3f8cbee5e872cf7db61a999a041f9bc4706ca7bf7df4cb914f53fabb1c1bc550"
34513451
"checksum fs2 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213"
34523452
"checksum fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5f2a4a2034423744d2cc7ca2068453168dcdb82c438419e639a26bd87839c674"
34533453
"checksum fst 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d94485a00b1827b861dd9d1a2cc9764f9044d4c535514c0760a5a2012ef3399f"

src/libstd/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rustc_tsan = { path = "../librustc_tsan" }
4040
dlmalloc = { version = "0.1", features = ['rustc-dep-of-std'] }
4141

4242
[target.x86_64-fortanix-unknown-sgx.dependencies]
43-
fortanix-sgx-abi = { version = "0.3.1", features = ['rustc-dep-of-std'] }
43+
fortanix-sgx-abi = { version = "0.3.2", features = ['rustc-dep-of-std'] }
4444

4545
[build-dependencies]
4646
cc = "1.0"

src/libstd/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
#![feature(alloc_layout_extra)]
315315
#![feature(maybe_uninit)]
316316
#![cfg_attr(target_env = "sgx", feature(global_asm, range_contains, slice_index_methods,
317-
decl_macro, coerce_unsized))]
317+
decl_macro, coerce_unsized, sgx_platform))]
318318

319319
#![default_lib_allocator]
320320

src/libstd/os/fortanix_sgx/mod.rs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Functionality specific to the `x86_64-fortanix-unknown-sgx` target.
12+
//!
13+
//! This includes functions to deal with memory isolation, usercalls, and the
14+
//! SGX instruction set.
15+
16+
#![deny(missing_docs, missing_debug_implementations)]
17+
#![unstable(feature = "sgx_platform", issue = "56975")]
18+
19+
/// Low-level interfaces to usercalls. See the [ABI documentation] for more
20+
/// information.
21+
///
22+
/// [ABI documentation]: https://docs.rs/fortanix-sgx-abi/
23+
pub mod usercalls {
24+
pub use sys::abi::usercalls::*;
25+
26+
/// Primitives for allocating memory in userspace as well as copying data
27+
/// to and from user memory.
28+
pub mod alloc {
29+
pub use sys::abi::usercalls::alloc;
30+
}
31+
32+
/// Lowest-level interfaces to usercalls and usercall ABI type definitions.
33+
pub mod raw {
34+
use sys::abi::usercalls::raw::invoke_with_usercalls;
35+
pub use sys::abi::usercalls::raw::do_usercall;
36+
pub use sys::abi::usercalls::raw::{accept_stream, alloc, async_queues, bind_stream, close,
37+
connect_stream, exit, flush, free, insecure_time,
38+
launch_thread, read, read_alloc, send, wait, write};
39+
40+
macro_rules! define_usercallnrs {
41+
($(fn $f:ident($($n:ident: $t:ty),*) $(-> $r:ty)*; )*) => {
42+
/// Usercall numbers as per the ABI.
43+
#[repr(C)]
44+
#[unstable(feature = "sgx_platform", issue = "56975")]
45+
#[derive(Copy, Clone, Hash, PartialEq, Eq, Debug)]
46+
#[allow(missing_docs)]
47+
pub enum UsercallNrs {
48+
$($f,)*
49+
}
50+
};
51+
}
52+
invoke_with_usercalls!(define_usercallnrs);
53+
54+
// fortanix-sgx-abi re-exports
55+
pub use sys::abi::usercalls::raw::{ByteBuffer, FifoDescriptor, Return, Usercall};
56+
pub use sys::abi::usercalls::raw::Error;
57+
pub use sys::abi::usercalls::raw::{EV_RETURNQ_NOT_EMPTY, EV_UNPARK, EV_USERCALLQ_NOT_FULL,
58+
FD_STDERR, FD_STDIN, FD_STDOUT, RESULT_SUCCESS,
59+
USERCALL_USER_DEFINED, WAIT_INDEFINITE, WAIT_NO};
60+
pub use sys::abi::usercalls::raw::{Fd, Result, Tcs};
61+
}
62+
}
63+
64+
/// Functions for querying mapping information for pointers.
65+
pub mod mem {
66+
pub use sys::abi::mem::*;
67+
}

src/libstd/os/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@ cfg_if! {
6161
#[cfg(target_os = "emscripten")] pub mod emscripten;
6262
#[cfg(target_os = "fuchsia")] pub mod fuchsia;
6363
#[cfg(target_os = "hermit")] pub mod hermit;
64+
#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] pub mod fortanix_sgx;
6465

6566
pub mod raw;

src/libstd/sys/sgx/abi/mem.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
// Do not remove inline: will result in relocation failure
1212
#[inline(always)]
13-
pub unsafe fn rel_ptr<T>(offset: u64) -> *const T {
13+
pub(crate) unsafe fn rel_ptr<T>(offset: u64) -> *const T {
1414
(image_base() + offset) as *const T
1515
}
1616

1717
// Do not remove inline: will result in relocation failure
1818
#[inline(always)]
19-
pub unsafe fn rel_ptr_mut<T>(offset: u64) -> *mut T {
19+
pub(crate) unsafe fn rel_ptr_mut<T>(offset: u64) -> *mut T {
2020
(image_base() + offset) as *mut T
2121
}
2222

@@ -34,13 +34,17 @@ fn image_base() -> u64 {
3434
base
3535
}
3636

37+
/// Returns `true` if the specified memory range is in the enclave.
38+
#[unstable(feature = "sgx_platform", issue = "56975")]
3739
pub fn is_enclave_range(p: *const u8, len: usize) -> bool {
3840
let start=p as u64;
3941
let end=start + (len as u64);
4042
start >= image_base() &&
4143
end <= image_base() + (unsafe { ENCLAVE_SIZE } as u64) // unsafe ok: link-time constant
4244
}
4345

46+
/// Returns `true` if the specified memory range is in userspace.
47+
#[unstable(feature = "sgx_platform", issue = "56975")]
4448
pub fn is_user_range(p: *const u8, len: usize) -> bool {
4549
let start=p as u64;
4650
let end=start + (len as u64);

src/libstd/sys/sgx/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use io::Write;
1313

1414
// runtime features
1515
mod reloc;
16-
mod mem;
1716
pub(super) mod panic;
1817

1918
// library features
19+
pub mod mem;
2020
pub mod thread;
2121
pub mod tls;
2222
#[macro_use]

0 commit comments

Comments
 (0)