sccommunity / crates-sgx

crates-sgx is a monorepo of all Rust crates ported for Teaclave SGX SDK targeting Intel SGX.
https://sccommunity.github.io/crates-sgx
Apache License 2.0
12 stars 2 forks source link

feature(thread-id): add thread-id@v3.3.0 #19

Closed sammyne closed 4 years ago

sammyne commented 4 years ago

Add Crates

Description

Add thread-id@v3.3.0

Crate Meta

NOTICES

The original project failed to compile when upgrading to rust 2018, so this commit consists of two commits

  1. format and fix syntax errors for upgrading
  2. port to teaclave-sgx-sdk

Hence, the Diff of Changes reported below is the difference of 2 from 1.

About Test

Tests can't be ported due to missing SGX counterpart for sync primitives such as the mpsc module.

Diff of Changes

diff --git a/crates/thread-id/Cargo.lock b/crates/thread-id/Cargo.lock
index 7bfd533..6d89632 100644
--- a/crates/thread-id/Cargo.lock
+++ b/crates/thread-id/Cargo.lock
@@ -1,21 +1,21 @@
 # This file is automatically @generated by Cargo.
 # It is not intended for manual editing.
-[[package]]
-name = "libc"
-version = "0.2.22"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-
 [[package]]
 name = "redox_syscall"
 version = "0.1.18"
 source = "registry+https://github.com/rust-lang/crates.io-index"

+[[package]]
+name = "sgx_types"
+version = "1.1.1"
+source = "git+https://github.com/apache/incubator-teaclave-sgx-sdk.git?tag=v1.1.1#66aaa2888992c63137e87adc688ddedab1181056"
+
 [[package]]
 name = "thread-id"
 version = "3.3.0"
 dependencies = [
- "libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
  "redox_syscall 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)",
+ "sgx_types 1.1.1 (git+https://github.com/apache/incubator-teaclave-sgx-sdk.git?tag=v1.1.1)",
  "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
 ]

@@ -39,8 +39,8 @@ version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"

 [metadata]
-"checksum libc 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)" = "babb8281da88cba992fa1f4ddec7d63ed96280a1a53ec9b919fd37b53d71e502"
 "checksum redox_syscall 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "3041aeb6000db123d2c9c751433f526e1f404b23213bd733167ab770c3989b4d"
+"checksum sgx_types 1.1.1 (git+https://github.com/apache/incubator-teaclave-sgx-sdk.git?tag=v1.1.1)" = "<none>"
 "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3"
 "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
 "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/crates/thread-id/Cargo.toml b/crates/thread-id/Cargo.toml
index cbacea1..ca1c541 100644
--- a/crates/thread-id/Cargo.toml
+++ b/crates/thread-id/Cargo.toml
@@ -14,11 +14,21 @@ edition = "2018"
 travis-ci = { repository = "ruuda/thread-id", branch = "v3.3.0" }
 appveyor = { repository = "ruuda/thread-id", branch = "v3.3.0" }

-[target.'cfg(unix)'.dependencies]
-libc = "0.2.6"
+#[target.'cfg(unix)'.dependencies]
+#libc = "0.2.6"

 [target.'cfg(windows)'.dependencies]
 winapi = { version = "0.3", features = ["processthreadsapi"] }

 [target.'cfg(target_os = "redox")'.dependencies]
 redox_syscall = "0.1"
+
+[dependencies.sgx_types]
+git = "https://github.com/apache/incubator-teaclave-sgx-sdk.git"
+optional = true
+tag = "v1.1.1"
+
+[features]
+default = ["mesalock_sgx"]
+mesalock_sgx = ["sgx_types"]
+
diff --git a/crates/thread-id/src/lib.rs b/crates/thread-id/src/lib.rs
index 6322f59..35ce65e 100644
--- a/crates/thread-id/src/lib.rs
+++ b/crates/thread-id/src/lib.rs
@@ -24,9 +24,10 @@
 //! ```

 #![warn(missing_docs)]
+#![no_std]

-#[cfg(unix)]
-extern crate libc;
+//#[cfg(unix)]
+//extern crate libc;

 #[cfg(windows)]
 extern crate winapi;
@@ -47,7 +48,7 @@ pub fn get() -> usize {
 #[cfg(unix)]
 #[inline]
 fn get_internal() -> usize {
-    unsafe { libc::pthread_self() as usize }
+    unsafe { sgx_types::sgx_thread_self() as usize }
 }

 #[cfg(windows)]
mssun commented 4 years ago

To make all consistent, let declare sgx_tstd dependency like this:

sgx_tstd = { git = "https://github.com/apache/incubator-teaclave-sgx-sdk.git", tag = "v1.1.1", optional = true }

or

[dependencies.sgx_types]
git = "https://github.com/apache/teaclave-sgx-sdk.git"
optional = true
tag = "v1.1.1"
sammyne commented 4 years ago

Now, it should be ready @mssun

mssun commented 4 years ago

Merged. Thank you!