,
bd: BD,
@@ -127,14 +127,14 @@ pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
P: Fn(&BD, BD::Idx) -> DebugFormatted
{
let flow_state = DataflowAnalysis::new(mir, dead_unwinds, bd);
- flow_state.run(tcx, hir_id, attributes, p)
+ flow_state.run(tcx, def_id, attributes, p)
}
impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation<'tcx>
{
pub(crate) fn run(self,
tcx: TyCtxt<'a, 'gcx, 'tcx>,
- hir_id: HirId,
+ def_id: DefId,
attributes: &[ast::Attribute],
p: P) -> DataflowResults<'tcx, BD>
where P: Fn(&BD, BD::Idx) -> DebugFormatted
@@ -159,7 +159,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitD
name_found(tcx.sess, attributes, "borrowck_graphviz_postflow");
let mut mbcx = DataflowBuilder {
- hir_id,
+ def_id,
print_preflow_to, print_postflow_to, flow_state: self,
};
diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs
index b83f048114b06..b3016cb01d409 100644
--- a/src/librustc_mir/hair/cx/expr.rs
+++ b/src/librustc_mir/hair/cx/expr.rs
@@ -838,13 +838,11 @@ fn method_callee<'a, 'gcx, 'tcx>(
let (def_id, substs, user_ty) = match overloaded_callee {
Some((def_id, substs)) => (def_id, substs, None),
None => {
- let type_dependent_defs = cx.tables().type_dependent_defs();
- let def = type_dependent_defs
- .get(expr.hir_id)
+ let def = cx.tables().type_dependent_def(expr.hir_id)
.unwrap_or_else(|| {
span_bug!(expr.span, "no type-dependent def for method callee")
});
- let user_ty = user_substs_applied_to_def(cx, expr.hir_id, def);
+ let user_ty = user_substs_applied_to_def(cx, expr.hir_id, &def);
debug!("method_callee: user_ty={:?}", user_ty);
(def.def_id(), cx.tables().node_substs(expr.hir_id), user_ty)
}
diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs
index 49967df08891b..50df676aea9fb 100644
--- a/src/librustc_mir/hair/pattern/check_match.rs
+++ b/src/librustc_mir/hair/pattern/check_match.rs
@@ -14,7 +14,6 @@ use rustc::ty::{self, Ty, TyCtxt, TyKind};
use rustc::ty::subst::{InternalSubsts, SubstsRef};
use rustc::lint;
use rustc_errors::{Applicability, DiagnosticBuilder};
-use rustc::util::common::ErrorReported;
use rustc::hir::def::*;
use rustc::hir::def_id::DefId;
@@ -27,25 +26,20 @@ use std::slice;
use syntax::ptr::P;
use syntax_pos::{Span, DUMMY_SP, MultiSpan};
-pub(crate) fn check_match<'a, 'tcx>(
- tcx: TyCtxt<'a, 'tcx, 'tcx>,
- def_id: DefId,
-) -> Result<(), ErrorReported> {
+pub(crate) fn check_match<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
let body_id = if let Some(id) = tcx.hir().as_local_hir_id(def_id) {
tcx.hir().body_owned_by(id)
} else {
- return Ok(());
+ return;
};
- tcx.sess.track_errors(|| {
- MatchVisitor {
- tcx,
- tables: tcx.body_tables(body_id),
- region_scope_tree: &tcx.region_scope_tree(def_id),
- param_env: tcx.param_env(def_id),
- identity_substs: InternalSubsts::identity_for_item(tcx, def_id),
- }.visit_body(tcx.hir().body(body_id));
- })
+ MatchVisitor {
+ tcx,
+ tables: tcx.body_tables(body_id),
+ region_scope_tree: &tcx.region_scope_tree(def_id),
+ param_env: tcx.param_env(def_id),
+ identity_substs: InternalSubsts::identity_for_item(tcx, def_id),
+ }.visit_body(tcx.hir().body(body_id));
}
fn create_e0004<'a>(sess: &'a Session, sp: Span, error_message: String) -> DiagnosticBuilder<'a> {
diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs
index d5098bc1db2b1..023a61588c42e 100644
--- a/src/librustc_mir/transform/elaborate_drops.rs
+++ b/src/librustc_mir/transform/elaborate_drops.rs
@@ -28,7 +28,7 @@ impl MirPass for ElaborateDrops {
{
debug!("elaborate_drops({:?} @ {:?})", src, mir.span);
- let id = tcx.hir().as_local_hir_id(src.def_id()).unwrap();
+ let def_id = src.def_id();
let param_env = tcx.param_env(src.def_id()).with_reveal_all();
let move_data = match MoveData::gather_moves(mir, tcx) {
Ok(move_data) => move_data,
@@ -50,13 +50,13 @@ impl MirPass for ElaborateDrops {
move_data,
param_env,
};
- let dead_unwinds = find_dead_unwinds(tcx, mir, id, &env);
+ let dead_unwinds = find_dead_unwinds(tcx, mir, def_id, &env);
let flow_inits =
- do_dataflow(tcx, mir, id, &[], &dead_unwinds,
+ do_dataflow(tcx, mir, def_id, &[], &dead_unwinds,
MaybeInitializedPlaces::new(tcx, mir, &env),
|bd, p| DebugFormatted::new(&bd.move_data().move_paths[p]));
let flow_uninits =
- do_dataflow(tcx, mir, id, &[], &dead_unwinds,
+ do_dataflow(tcx, mir, def_id, &[], &dead_unwinds,
MaybeUninitializedPlaces::new(tcx, mir, &env),
|bd, p| DebugFormatted::new(&bd.move_data().move_paths[p]));
@@ -80,7 +80,7 @@ impl MirPass for ElaborateDrops {
fn find_dead_unwinds<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
mir: &Mir<'tcx>,
- id: hir::HirId,
+ def_id: hir::def_id::DefId,
env: &MoveDataParamEnv<'tcx, 'tcx>)
-> BitSet
{
@@ -89,7 +89,7 @@ fn find_dead_unwinds<'a, 'tcx>(
// reach cleanup blocks, which can't have unwind edges themselves.
let mut dead_unwinds = BitSet::new_empty(mir.basic_blocks().len());
let flow_inits =
- do_dataflow(tcx, mir, id, &[], &dead_unwinds,
+ do_dataflow(tcx, mir, def_id, &[], &dead_unwinds,
MaybeInitializedPlaces::new(tcx, mir, &env),
|bd, p| DebugFormatted::new(&bd.move_data().move_paths[p]));
for (bb, bb_data) in mir.basic_blocks().iter_enumerated() {
diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs
index b22258a49b24b..c4e303eb9aa1f 100644
--- a/src/librustc_mir/transform/generator.rs
+++ b/src/librustc_mir/transform/generator.rs
@@ -390,13 +390,13 @@ fn locals_live_across_suspend_points(
FxHashMap,
) {
let dead_unwinds = BitSet::new_empty(mir.basic_blocks().len());
- let hir_id = tcx.hir().as_local_hir_id(source.def_id()).unwrap();
+ let def_id = source.def_id();
// Calculate when MIR locals have live storage. This gives us an upper bound of their
// lifetimes.
let storage_live_analysis = MaybeStorageLive::new(mir);
let storage_live =
- do_dataflow(tcx, mir, hir_id, &[], &dead_unwinds, storage_live_analysis,
+ do_dataflow(tcx, mir, def_id, &[], &dead_unwinds, storage_live_analysis,
|bd, p| DebugFormatted::new(&bd.mir().local_decls[p]));
// Find the MIR locals which do not use StorageLive/StorageDead statements.
@@ -410,7 +410,7 @@ fn locals_live_across_suspend_points(
let borrowed_locals = if !movable {
let analysis = HaveBeenBorrowedLocals::new(mir);
let result =
- do_dataflow(tcx, mir, hir_id, &[], &dead_unwinds, analysis,
+ do_dataflow(tcx, mir, def_id, &[], &dead_unwinds, analysis,
|bd, p| DebugFormatted::new(&bd.mir().local_decls[p]));
Some((analysis, result))
} else {
diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs
index f9f8abbe6c065..246f876235d71 100644
--- a/src/librustc_mir/transform/rustc_peek.rs
+++ b/src/librustc_mir/transform/rustc_peek.rs
@@ -3,7 +3,7 @@ use syntax::ast;
use syntax_pos::Span;
use rustc::ty::{self, TyCtxt};
-use rustc::hir;
+use rustc::hir::def_id::DefId;
use rustc::mir::{self, Mir, Location};
use rustc_data_structures::bit_set::BitSet;
use crate::transform::{MirPass, MirSource};
@@ -27,7 +27,6 @@ impl MirPass for SanityCheck {
fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
src: MirSource<'tcx>, mir: &mut Mir<'tcx>) {
let def_id = src.def_id();
- let id = tcx.hir().as_local_hir_id(def_id).unwrap();
if !tcx.has_attr(def_id, "rustc_mir") {
debug!("skipping rustc_peek::SanityCheck on {}", tcx.def_path_str(def_id));
return;
@@ -41,26 +40,26 @@ impl MirPass for SanityCheck {
let mdpe = MoveDataParamEnv { move_data: move_data, param_env: param_env };
let dead_unwinds = BitSet::new_empty(mir.basic_blocks().len());
let flow_inits =
- do_dataflow(tcx, mir, id, &attributes, &dead_unwinds,
+ do_dataflow(tcx, mir, def_id, &attributes, &dead_unwinds,
MaybeInitializedPlaces::new(tcx, mir, &mdpe),
|bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]));
let flow_uninits =
- do_dataflow(tcx, mir, id, &attributes, &dead_unwinds,
+ do_dataflow(tcx, mir, def_id, &attributes, &dead_unwinds,
MaybeUninitializedPlaces::new(tcx, mir, &mdpe),
|bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]));
let flow_def_inits =
- do_dataflow(tcx, mir, id, &attributes, &dead_unwinds,
+ do_dataflow(tcx, mir, def_id, &attributes, &dead_unwinds,
DefinitelyInitializedPlaces::new(tcx, mir, &mdpe),
|bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]));
if has_rustc_mir_with(&attributes, "rustc_peek_maybe_init").is_some() {
- sanity_check_via_rustc_peek(tcx, mir, id, &attributes, &flow_inits);
+ sanity_check_via_rustc_peek(tcx, mir, def_id, &attributes, &flow_inits);
}
if has_rustc_mir_with(&attributes, "rustc_peek_maybe_uninit").is_some() {
- sanity_check_via_rustc_peek(tcx, mir, id, &attributes, &flow_uninits);
+ sanity_check_via_rustc_peek(tcx, mir, def_id, &attributes, &flow_uninits);
}
if has_rustc_mir_with(&attributes, "rustc_peek_definite_init").is_some() {
- sanity_check_via_rustc_peek(tcx, mir, id, &attributes, &flow_def_inits);
+ sanity_check_via_rustc_peek(tcx, mir, def_id, &attributes, &flow_def_inits);
}
if has_rustc_mir_with(&attributes, "stop_after_dataflow").is_some() {
tcx.sess.fatal("stop_after_dataflow ended compilation");
@@ -86,12 +85,12 @@ impl MirPass for SanityCheck {
/// errors are not intended to be used for unit tests.)
pub fn sanity_check_via_rustc_peek<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
mir: &Mir<'tcx>,
- id: hir::HirId,
+ def_id: DefId,
_attributes: &[ast::Attribute],
results: &DataflowResults<'tcx, O>)
where O: BitDenotation<'tcx, Idx=MovePathIndex> + HasMoveData<'tcx>
{
- debug!("sanity_check_via_rustc_peek id: {:?}", id);
+ debug!("sanity_check_via_rustc_peek def_id: {:?}", def_id);
// FIXME: this is not DRY. Figure out way to abstract this and
// `dataflow::build_sets`. (But note it is doing non-standard
// stuff, so such generalization may not be realistic.)
diff --git a/src/librustc_mir/util/graphviz.rs b/src/librustc_mir/util/graphviz.rs
index 69a2adcfce026..f87714b58c442 100644
--- a/src/librustc_mir/util/graphviz.rs
+++ b/src/librustc_mir/util/graphviz.rs
@@ -1,6 +1,7 @@
use rustc::hir::def_id::DefId;
use rustc::mir::*;
use rustc::ty::TyCtxt;
+use rustc_data_structures::indexed_vec::Idx;
use std::fmt::Debug;
use std::io::{self, Write};
@@ -20,6 +21,17 @@ pub fn write_mir_graphviz<'tcx, W>(tcx: TyCtxt<'_, '_, 'tcx>,
Ok(())
}
+// Must match `[0-9A-Za-z_]*`. This does not appear in the rendered graph, so
+// it does not have to be user friendly.
+pub fn graphviz_safe_def_name(def_id: DefId) -> String {
+ format!(
+ "{}_{}_{}",
+ def_id.krate.index(),
+ def_id.index.address_space().index(),
+ def_id.index.as_array_index(),
+ )
+}
+
/// Write a graphviz DOT graph of the MIR.
pub fn write_mir_fn_graphviz<'tcx, W>(tcx: TyCtxt<'_, '_, 'tcx>,
def_id: DefId,
@@ -27,7 +39,7 @@ pub fn write_mir_fn_graphviz<'tcx, W>(tcx: TyCtxt<'_, '_, 'tcx>,
w: &mut W) -> io::Result<()>
where W: Write
{
- writeln!(w, "digraph Mir_{} {{", tcx.hir().as_local_hir_id(def_id).unwrap())?;
+ writeln!(w, "digraph Mir_{} {{", graphviz_safe_def_name(def_id))?;
// Global graph properties
writeln!(w, r#" graph [fontname="monospace"];"#)?;
diff --git a/src/librustc_mir/util/mod.rs b/src/librustc_mir/util/mod.rs
index 29614a33f8e27..1a5a2a92247dd 100644
--- a/src/librustc_mir/util/mod.rs
+++ b/src/librustc_mir/util/mod.rs
@@ -15,7 +15,7 @@ pub mod collect_writes;
pub use self::alignment::is_disaligned;
pub use self::pretty::{dump_enabled, dump_mir, write_mir_pretty, PassWhere};
-pub use self::graphviz::{write_mir_graphviz};
+pub use self::graphviz::{graphviz_safe_def_name, write_mir_graphviz};
pub use self::graphviz::write_node_label as write_graphviz_node_label;
/// If possible, suggest replacing `ref` with `ref mut`.
diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs
index 6de98675a3dc8..fcd51062cd97a 100644
--- a/src/librustc_passes/rvalue_promotion.rs
+++ b/src/librustc_passes/rvalue_promotion.rs
@@ -406,8 +406,7 @@ fn check_expr_kind<'a, 'tcx>(
for index in hirvec.iter() {
method_call_result &= v.check_expr(index);
}
- if let Some(def) = v.tables.type_dependent_defs().get(e.hir_id) {
- let def_id = def.def_id();
+ if let Some(def_id) = v.tables.type_dependent_def_id(e.hir_id) {
match v.tcx.associated_item(def_id).container {
ty::ImplContainer(_) => method_call_result & v.handle_const_fn_call(def_id),
ty::TraitContainer(_) => NotPromotable,
diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs
index 19b5fa1bfbe57..ee72a08b895c6 100644
--- a/src/librustc_privacy/lib.rs
+++ b/src/librustc_privacy/lib.rs
@@ -1039,8 +1039,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
hir::ExprKind::MethodCall(_, span, _) => {
// Method calls have to be checked specially.
self.span = span;
- if let Some(def) = self.tables.type_dependent_defs().get(expr.hir_id) {
- if self.visit(self.tcx.type_of(def.def_id())) {
+ if let Some(def_id) = self.tables.type_dependent_def_id(expr.hir_id) {
+ if self.visit(self.tcx.type_of(def_id)) {
return;
}
} else {
@@ -1069,7 +1069,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
_ => None,
}
hir::QPath::TypeRelative(..) => {
- self.tables.type_dependent_defs().get(id).cloned()
+ self.tables.type_dependent_def(id)
}
};
if let Some(def) = def {
diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs
index 7ad5b7ce8c73e..0b6e9d1bd9917 100644
--- a/src/librustc_save_analysis/lib.rs
+++ b/src/librustc_save_analysis/lib.rs
@@ -573,8 +573,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}
ast::ExprKind::MethodCall(ref seg, ..) => {
let expr_hir_id = self.tcx.hir().definitions().node_to_hir_id(expr.id);
- let method_id = match self.tables.type_dependent_defs().get(expr_hir_id) {
- Some(id) => id.def_id(),
+ let method_id = match self.tables.type_dependent_def_id(expr_hir_id) {
+ Some(id) => id,
None => {
debug!("Could not resolve method id for {:?}", expr);
return None;
diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs
index c30b9d65fec83..5fd6d9330098b 100644
--- a/src/librustc_typeck/check/_match.rs
+++ b/src/librustc_typeck/check/_match.rs
@@ -973,7 +973,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
self.field_ty(span, f, substs)
})
.unwrap_or_else(|| {
- inexistent_fields.push((span, field.ident));
+ inexistent_fields.push(field.ident);
no_field_errors = false;
tcx.types.err
})
@@ -989,15 +989,15 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
.collect::>();
if inexistent_fields.len() > 0 && !variant.recovered {
let (field_names, t, plural) = if inexistent_fields.len() == 1 {
- (format!("a field named `{}`", inexistent_fields[0].1), "this", "")
+ (format!("a field named `{}`", inexistent_fields[0]), "this", "")
} else {
(format!("fields named {}",
inexistent_fields.iter()
- .map(|(_, name)| format!("`{}`", name))
+ .map(|ident| format!("`{}`", ident))
.collect::>()
.join(", ")), "these", "s")
};
- let spans = inexistent_fields.iter().map(|(span, _)| *span).collect::>();
+ let spans = inexistent_fields.iter().map(|ident| ident.span).collect::>();
let mut err = struct_span_err!(tcx.sess,
spans,
E0026,
@@ -1005,8 +1005,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
kind_name,
tcx.def_path_str(variant.did),
field_names);
- if let Some((span, ident)) = inexistent_fields.last() {
- err.span_label(*span,
+ if let Some(ident) = inexistent_fields.last() {
+ err.span_label(ident.span,
format!("{} `{}` does not have {} field{}",
kind_name,
tcx.def_path_str(variant.did),
@@ -1018,8 +1018,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
find_best_match_for_name(input, &ident.as_str(), None);
if let Some(suggested_name) = suggested_name {
err.span_suggestion(
- *span,
- "did you mean",
+ ident.span,
+ "a field with a similar name exists",
suggested_name.to_string(),
Applicability::MaybeIncorrect,
);
diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs
index ab0e4b086bc77..be2454cdd5a85 100644
--- a/src/librustc_typeck/check/mod.rs
+++ b/src/librustc_typeck/check/mod.rs
@@ -702,15 +702,11 @@ fn check_mod_item_types<'tcx>(tcx: TyCtxt<'_, 'tcx, 'tcx>, module_def_id: DefId)
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckItemTypesVisitor { tcx });
}
-fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum)
- -> Result<(), ErrorReported>
-{
+fn typeck_item_bodies<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, crate_num: CrateNum) {
debug_assert!(crate_num == LOCAL_CRATE);
- Ok(tcx.sess.track_errors(|| {
- tcx.par_body_owners(|body_owner_def_id| {
- tcx.ensure().typeck_tables_of(body_owner_def_id);
- });
- })?)
+ tcx.par_body_owners(|body_owner_def_id| {
+ tcx.ensure().typeck_tables_of(body_owner_def_id);
+ });
}
fn check_item_well_formed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) {
@@ -4807,10 +4803,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
(self.to_ty(qself), qself, segment)
}
};
- if let Some(cached_def) = self.tables.borrow().type_dependent_defs().get(hir_id) {
+ if let Some(cached_def) = self.tables.borrow().type_dependent_def(hir_id) {
// Return directly on cache hit. This is useful to avoid doubly reporting
// errors with default match binding modes. See #44614.
- return (*cached_def, Some(ty), slice::from_ref(&**item_segment))
+ return (cached_def, Some(ty), slice::from_ref(&**item_segment))
}
let item_name = item_segment.ident;
let def = match self.resolve_ufcs(span, item_name, ty, hir_id) {
diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs
index cbed7d26a9950..b2c2b233c81ab 100644
--- a/src/librustc_typeck/lib.rs
+++ b/src/librustc_typeck/lib.rs
@@ -363,7 +363,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
})
})?;
- time(tcx.sess, "item-bodies checking", || tcx.typeck_item_bodies(LOCAL_CRATE))?;
+ time(tcx.sess, "item-bodies checking", || tcx.typeck_item_bodies(LOCAL_CRATE));
check_unused::check_crate(tcx);
check_for_entry_fn(tcx);
diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml
index 1a6b58f35b398..b2eaf956d0e2d 100644
--- a/src/libstd/Cargo.toml
+++ b/src/libstd/Cargo.toml
@@ -72,3 +72,7 @@ wasm-bindgen-threads = []
# https://github.com/rust-lang-nursery/stdsimd/blob/master/crates/std_detect/Cargo.toml
std_detect_file_io = []
std_detect_dlsym_getauxval = []
+
+[package.metadata.fortanix-sgx]
+# Maximum possible number of threads when testing
+threads = 125
diff --git a/src/libstd/env.rs b/src/libstd/env.rs
index 97c67f562a7df..f723a2b0bb281 100644
--- a/src/libstd/env.rs
+++ b/src/libstd/env.rs
@@ -975,7 +975,7 @@ mod tests {
use crate::path::Path;
#[test]
- #[cfg_attr(target_os = "emscripten", ignore)]
+ #[cfg_attr(any(target_os = "emscripten", target_env = "sgx"), ignore)]
fn test_self_exe_path() {
let path = current_exe();
assert!(path.is_ok());
@@ -989,6 +989,7 @@ mod tests {
fn test() {
assert!((!Path::new("test-path").is_absolute()));
+ #[cfg(not(target_env = "sgx"))]
current_dir().unwrap();
}
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index 8c3d0da0a7e40..dfff44b88ea78 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -2095,7 +2095,7 @@ impl AsInnerMut for DirBuilder {
}
}
-#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
+#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten", target_env = "sgx"))))]
mod tests {
use crate::io::prelude::*;
diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs
index f5a87cc3ea67a..eaa6a070154f7 100644
--- a/src/libstd/net/addr.rs
+++ b/src/libstd/net/addr.rs
@@ -941,7 +941,10 @@ mod tests {
assert_eq!(Ok(vec![a]), tsa(("2a02:6b8:0:1::1", 53)));
let a = sa4(Ipv4Addr::new(127, 0, 0, 1), 23924);
+ #[cfg(not(target_env = "sgx"))]
assert!(tsa(("localhost", 23924)).unwrap().contains(&a));
+ #[cfg(target_env = "sgx")]
+ let _ = a;
}
#[test]
@@ -953,7 +956,10 @@ mod tests {
assert_eq!(Ok(vec![a]), tsa("[2a02:6b8:0:1::1]:53"));
let a = sa4(Ipv4Addr::new(127, 0, 0, 1), 23924);
+ #[cfg(not(target_env = "sgx"))]
assert!(tsa("localhost:23924").unwrap().contains(&a));
+ #[cfg(target_env = "sgx")]
+ let _ = a;
}
#[test]
diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs
index ce0c5c0bb0dc7..304cdb0155814 100644
--- a/src/libstd/net/tcp.rs
+++ b/src/libstd/net/tcp.rs
@@ -929,12 +929,12 @@ impl fmt::Debug for TcpListener {
#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
mod tests {
+ use crate::fmt;
use crate::io::{ErrorKind, IoVec, IoVecMut};
use crate::io::prelude::*;
use crate::net::*;
use crate::net::test::{next_test_ip4, next_test_ip6};
use crate::sync::mpsc::channel;
- use crate::sys_common::AsInner;
use crate::time::{Instant, Duration};
use crate::thread;
@@ -1129,7 +1129,7 @@ mod tests {
connect(i + 1, addr);
t!(stream.write(&[i as u8]));
});
- t.join().ok().unwrap();
+ t.join().ok().expect("thread panicked");
}
}
@@ -1162,7 +1162,7 @@ mod tests {
connect(i + 1, addr);
t!(stream.write(&[99]));
});
- t.join().ok().unwrap();
+ t.join().ok().expect("thread panicked");
}
}
@@ -1377,6 +1377,8 @@ mod tests {
}
#[test]
+ // FIXME: https://github.com/fortanix/rust-sgx/issues/110
+ #[cfg_attr(target_env = "sgx", ignore)]
fn shutdown_smoke() {
each_ip(&mut |addr| {
let a = t!(TcpListener::bind(&addr));
@@ -1397,6 +1399,8 @@ mod tests {
}
#[test]
+ // FIXME: https://github.com/fortanix/rust-sgx/issues/110
+ #[cfg_attr(target_env = "sgx", ignore)]
fn close_readwrite_smoke() {
each_ip(&mut |addr| {
let a = t!(TcpListener::bind(&addr));
@@ -1550,30 +1554,51 @@ mod tests {
#[test]
fn debug() {
- let name = if cfg!(windows) {"socket"} else {"fd"};
+ #[cfg(not(target_env = "sgx"))]
+ fn render_socket_addr<'a>(addr: &'a SocketAddr) -> impl fmt::Debug + 'a {
+ addr
+ }
+ #[cfg(target_env = "sgx")]
+ fn render_socket_addr<'a>(addr: &'a SocketAddr) -> impl fmt::Debug + 'a {
+ addr.to_string()
+ }
+
+ #[cfg(unix)]
+ use crate::os::unix::io::AsRawFd;
+ #[cfg(target_env = "sgx")]
+ use crate::os::fortanix_sgx::io::AsRawFd;
+ #[cfg(not(windows))]
+ fn render_inner(addr: &dyn AsRawFd) -> impl fmt::Debug {
+ addr.as_raw_fd()
+ }
+ #[cfg(windows)]
+ fn render_inner(addr: &dyn os::windows::io::AsRawSocket) -> impl fmt::Debug {
+ addr.as_raw_socket()
+ }
+
+ let inner_name = if cfg!(windows) {"socket"} else {"fd"};
let socket_addr = next_test_ip4();
let listener = t!(TcpListener::bind(&socket_addr));
- let listener_inner = listener.0.socket().as_inner();
let compare = format!("TcpListener {{ addr: {:?}, {}: {:?} }}",
- socket_addr, name, listener_inner);
+ render_socket_addr(&socket_addr),
+ inner_name,
+ render_inner(&listener));
assert_eq!(format!("{:?}", listener), compare);
- let stream = t!(TcpStream::connect(&("localhost",
- socket_addr.port())));
- let stream_inner = stream.0.socket().as_inner();
- let compare = format!("TcpStream {{ addr: {:?}, \
- peer: {:?}, {}: {:?} }}",
- stream.local_addr().unwrap(),
- stream.peer_addr().unwrap(),
- name,
- stream_inner);
+ let stream = t!(TcpStream::connect(&("localhost", socket_addr.port())));
+ let compare = format!("TcpStream {{ addr: {:?}, peer: {:?}, {}: {:?} }}",
+ render_socket_addr(&stream.local_addr().unwrap()),
+ render_socket_addr(&stream.peer_addr().unwrap()),
+ inner_name,
+ render_inner(&stream));
assert_eq!(format!("{:?}", stream), compare);
}
// FIXME: re-enabled bitrig/openbsd tests once their socket timeout code
// no longer has rounding errors.
#[cfg_attr(any(target_os = "bitrig", target_os = "netbsd", target_os = "openbsd"), ignore)]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
#[test]
fn timeouts() {
let addr = next_test_ip4();
@@ -1601,6 +1626,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn test_read_timeout() {
let addr = next_test_ip4();
let listener = t!(TcpListener::bind(&addr));
@@ -1618,6 +1644,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn test_read_with_timeout() {
let addr = next_test_ip4();
let listener = t!(TcpListener::bind(&addr));
@@ -1661,6 +1688,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)]
fn nodelay() {
let addr = next_test_ip4();
let _listener = t!(TcpListener::bind(&addr));
@@ -1675,6 +1703,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)]
fn ttl() {
let ttl = 100;
@@ -1691,6 +1720,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)]
fn set_nonblocking() {
let addr = next_test_ip4();
let listener = t!(TcpListener::bind(&addr));
@@ -1712,6 +1742,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn peek() {
each_ip(&mut |addr| {
let (txdone, rxdone) = channel();
@@ -1743,6 +1774,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn connect_timeout_valid() {
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let addr = listener.local_addr().unwrap();
diff --git a/src/libstd/net/test.rs b/src/libstd/net/test.rs
index 89fefd9d1d5e0..e2991cbdd8822 100644
--- a/src/libstd/net/test.rs
+++ b/src/libstd/net/test.rs
@@ -36,12 +36,16 @@ pub fn tsa(a: A) -> Result, String> {
// all want to use ports. This function figures out which workspace
// it is running in and assigns a port range based on it.
fn base_port() -> u16 {
- let cwd = env::current_dir().unwrap();
+ let cwd = if cfg!(target_env = "sgx") {
+ String::from("sgx")
+ } else {
+ env::current_dir().unwrap().into_os_string().into_string().unwrap()
+ };
let dirs = ["32-opt", "32-nopt",
"musl-64-opt", "cross-opt",
"64-opt", "64-nopt", "64-opt-vg", "64-debug-opt",
- "all-opt", "snap3", "dist"];
+ "all-opt", "snap3", "dist", "sgx"];
dirs.iter().enumerate().find(|&(_, dir)| {
- cwd.to_str().unwrap().contains(dir)
+ cwd.contains(dir)
}).map(|p| p.0).unwrap_or(0) as u16 * 1000 + 19600
}
diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs
index b42a812304269..836d1f8be632b 100644
--- a/src/libstd/net/udp.rs
+++ b/src/libstd/net/udp.rs
@@ -837,7 +837,7 @@ impl fmt::Debug for UdpSocket {
}
}
-#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
+#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten", target_env = "sgx"))))]
mod tests {
use crate::io::ErrorKind;
use crate::net::*;
diff --git a/src/libstd/path.rs b/src/libstd/path.rs
index ea3fcd8ce2859..4048bc4da2557 100644
--- a/src/libstd/path.rs
+++ b/src/libstd/path.rs
@@ -3801,7 +3801,7 @@ mod tests {
});
);
- if cfg!(unix) {
+ if cfg!(unix) || cfg!(all(target_env = "sgx", target_vendor = "fortanix")) {
tp!("", "foo", "foo");
tp!("foo", "bar", "foo/bar");
tp!("foo/", "bar", "foo/bar");
@@ -3960,7 +3960,7 @@ mod tests {
tfn!("foo", "bar", "bar");
tfn!("foo", "", "");
tfn!("", "foo", "foo");
- if cfg!(unix) {
+ if cfg!(unix) || cfg!(all(target_env = "sgx", target_vendor = "fortanix")) {
tfn!(".", "foo", "./foo");
tfn!("foo/", "bar", "bar");
tfn!("foo/.", "bar", "bar");
diff --git a/src/libstd/process.rs b/src/libstd/process.rs
index ad86acbb47de4..054b398b01f26 100644
--- a/src/libstd/process.rs
+++ b/src/libstd/process.rs
@@ -1621,7 +1621,7 @@ impl Termination for ExitCode {
}
}
-#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))]
+#[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten", target_env = "sgx"))))]
mod tests {
use crate::io::prelude::*;
diff --git a/src/libstd/sync/condvar.rs b/src/libstd/sync/condvar.rs
index c383f21dcd752..2e8182671dd6f 100644
--- a/src/libstd/sync/condvar.rs
+++ b/src/libstd/sync/condvar.rs
@@ -705,6 +705,7 @@ mod tests {
#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn wait_timeout_wait() {
let m = Arc::new(Mutex::new(()));
let c = Arc::new(Condvar::new());
@@ -724,6 +725,7 @@ mod tests {
#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn wait_timeout_until_wait() {
let m = Arc::new(Mutex::new(()));
let c = Arc::new(Condvar::new());
@@ -748,6 +750,7 @@ mod tests {
#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn wait_timeout_until_wake() {
let pair = Arc::new((Mutex::new(false), Condvar::new()));
let pair_copy = pair.clone();
@@ -771,6 +774,7 @@ mod tests {
#[test]
#[cfg_attr(target_os = "emscripten", ignore)]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn wait_timeout_wake() {
let m = Arc::new(Mutex::new(()));
let c = Arc::new(Condvar::new());
diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs
index 90c5c50c23b9c..4ed2bfb175a46 100644
--- a/src/libstd/sync/mpsc/mod.rs
+++ b/src/libstd/sync/mpsc/mod.rs
@@ -1951,7 +1951,7 @@ mod tests {
for _ in 0..10000 {
assert_eq!(rx.recv().unwrap(), 1);
}
- t.join().ok().unwrap();
+ t.join().ok().expect("thread panicked");
}
#[test]
@@ -1977,7 +1977,7 @@ mod tests {
});
}
drop(tx);
- t.join().ok().unwrap();
+ t.join().ok().expect("thread panicked");
}
#[test]
@@ -1996,8 +1996,8 @@ mod tests {
tx2.send(1).unwrap();
}
});
- t1.join().ok().unwrap();
- t2.join().ok().unwrap();
+ t1.join().ok().expect("thread panicked");
+ t2.join().ok().expect("thread panicked");
}
#[test]
@@ -2011,7 +2011,7 @@ mod tests {
for _ in 0..40 {
tx.send(1).unwrap();
}
- t.join().ok().unwrap();
+ t.join().ok().expect("thread panicked");
}
#[test]
@@ -2026,8 +2026,8 @@ mod tests {
tx1.send(1).unwrap();
assert_eq!(rx2.recv().unwrap(), 2);
});
- t1.join().ok().unwrap();
- t2.join().ok().unwrap();
+ t1.join().ok().expect("thread panicked");
+ t2.join().ok().expect("thread panicked");
}
#[test]
@@ -2225,6 +2225,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn oneshot_single_thread_recv_timeout() {
let (tx, rx) = channel();
tx.send(()).unwrap();
@@ -2235,6 +2236,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn stress_recv_timeout_two_threads() {
let (tx, rx) = channel();
let stress = stress_factor() + 100;
@@ -2265,6 +2267,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn recv_timeout_upgrade() {
let (tx, rx) = channel::<()>();
let timeout = Duration::from_millis(1);
@@ -2276,6 +2279,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn stress_recv_timeout_shared() {
let (tx, rx) = channel();
let stress = stress_factor() + 100;
@@ -2306,6 +2310,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn very_long_recv_timeout_wont_panic() {
let (tx, rx) = channel::<()>();
let join_handle = thread::spawn(move || {
@@ -2325,6 +2330,7 @@ mod tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn shared_recv_timeout() {
let (tx, rx) = channel();
let total = 5;
@@ -2550,6 +2556,7 @@ mod sync_tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn recv_timeout() {
let (tx, rx) = sync_channel::(1);
assert_eq!(rx.recv_timeout(Duration::from_millis(1)), Err(RecvTimeoutError::Timeout));
@@ -2639,6 +2646,7 @@ mod sync_tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn stress_recv_timeout_two_threads() {
let (tx, rx) = sync_channel::(0);
@@ -2662,6 +2670,7 @@ mod sync_tests {
}
#[test]
+ #[cfg_attr(target_env = "sgx", ignore)] // FIXME: https://github.com/fortanix/rust-sgx/issues/31
fn stress_recv_timeout_shared() {
const AMT: u32 = 1000;
const NTHREADS: u32 = 8;
diff --git a/src/libstd/sys/sgx/abi/mod.rs b/src/libstd/sys/sgx/abi/mod.rs
index 7426f7be9e961..85ec8be4aae69 100644
--- a/src/libstd/sys/sgx/abi/mod.rs
+++ b/src/libstd/sys/sgx/abi/mod.rs
@@ -1,3 +1,5 @@
+#![cfg_attr(test, allow(unused))] // RT initialization logic is not compiled for test
+
use core::sync::atomic::{AtomicUsize, Ordering};
use crate::io::Write;
@@ -12,8 +14,10 @@ pub mod tls;
#[macro_use]
pub mod usercalls;
+#[cfg(not(test))]
global_asm!(include_str!("entry.S"));
+#[cfg(not(test))]
#[no_mangle]
unsafe extern "C" fn tcs_init(secondary: bool) {
// Be very careful when changing this code: it runs before the binary has been
@@ -48,6 +52,7 @@ unsafe extern "C" fn tcs_init(secondary: bool) {
// FIXME: this item should only exist if this is linked into an executable
// (main function exists). If this is a library, the crate author should be
// able to specify this
+#[cfg(not(test))]
#[no_mangle]
extern "C" fn entry(p1: u64, p2: u64, p3: u64, secondary: bool, p4: u64, p5: u64) -> (u64, u64) {
// FIXME: how to support TLS in library mode?
diff --git a/src/libstd/sys/sgx/abi/panic.rs b/src/libstd/sys/sgx/abi/panic.rs
index 83411cb5b4c26..de86394b4b88c 100644
--- a/src/libstd/sys/sgx/abi/panic.rs
+++ b/src/libstd/sys/sgx/abi/panic.rs
@@ -49,7 +49,7 @@ impl Write for SgxPanicOutput {
}
}
-#[no_mangle]
+#[cfg_attr(not(test), no_mangle)]
pub extern "C" fn panic_msg(msg: &str) -> ! {
let _ = SgxPanicOutput::new().map(|mut out| out.write(msg.as_bytes()));
usercalls::exit(true)
diff --git a/src/libstd/sys/sgx/abi/tls.rs b/src/libstd/sys/sgx/abi/tls.rs
index b2a812c7231da..6b9ab7e383c01 100644
--- a/src/libstd/sys/sgx/abi/tls.rs
+++ b/src/libstd/sys/sgx/abi/tls.rs
@@ -10,45 +10,16 @@ const USIZE_BITS: usize = 64;
const TLS_KEYS: usize = 128; // Same as POSIX minimum
const TLS_KEYS_BITSET_SIZE: usize = (TLS_KEYS + (USIZE_BITS - 1)) / USIZE_BITS;
+#[cfg_attr(test, linkage = "available_externally")]
+#[export_name = "_ZN16__rust_internals3std3sys3sgx3abi3tls14TLS_KEY_IN_USEE"]
static TLS_KEY_IN_USE: SyncBitset = SYNC_BITSET_INIT;
macro_rules! dup {
((* $($exp:tt)*) $($val:tt)*) => (dup!( ($($exp)*) $($val)* $($val)* ));
(() $($val:tt)*) => ([$($val),*])
}
-static TLS_DESTRUCTOR: [AtomicUsize; TLS_KEYS] = [
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
- AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0), AtomicUsize::new(0),
-];
+#[cfg_attr(test, linkage = "available_externally")]
+#[export_name = "_ZN16__rust_internals3std3sys3sgx3abi3tls14TLS_DESTRUCTORE"]
+static TLS_DESTRUCTOR: [AtomicUsize; TLS_KEYS] = dup!((* * * * * * *) (AtomicUsize::new(0)));
extern "C" {
fn get_tls_ptr() -> *const u8;
diff --git a/src/libstd/sys/sgx/abi/usercalls/alloc.rs b/src/libstd/sys/sgx/abi/usercalls/alloc.rs
index b787bd1a5abac..449a5fe5ae308 100644
--- a/src/libstd/sys/sgx/abi/usercalls/alloc.rs
+++ b/src/libstd/sys/sgx/abi/usercalls/alloc.rs
@@ -188,8 +188,13 @@ impl User where T: UserSafe {
// from outside as obtained by `super::alloc`.
fn new_uninit_bytes(size: usize) -> Self {
unsafe {
- let ptr = super::alloc(size, T::align_of()).expect("User memory allocation failed");
- User(NonNull::new_userref(T::from_raw_sized(ptr as _, size)))
+ // Mustn't call alloc with size 0.
+ let ptr = if size > 0 {
+ super::alloc(size, T::align_of()).expect("User memory allocation failed") as _
+ } else {
+ T::align_of() as _ // dangling pointer ok for size 0
+ };
+ User(NonNull::new_userref(T::from_raw_sized(ptr, size)))
}
}
diff --git a/src/libstd/sys/sgx/alloc.rs b/src/libstd/sys/sgx/alloc.rs
index 94dc8ec25b587..98eb8397436bf 100644
--- a/src/libstd/sys/sgx/alloc.rs
+++ b/src/libstd/sys/sgx/alloc.rs
@@ -4,6 +4,8 @@ use super::waitqueue::SpinMutex;
// Using a SpinMutex because we never want to exit the enclave waiting for the
// allocator.
+#[cfg_attr(test, linkage = "available_externally")]
+#[export_name = "_ZN16__rust_internals3std3sys3sgx5alloc8DLMALLOCE"]
static DLMALLOC: SpinMutex = SpinMutex::new(dlmalloc::DLMALLOC_INIT);
#[stable(feature = "alloc_system_type", since = "1.28.0")]
diff --git a/src/libstd/sys/sgx/args.rs b/src/libstd/sys/sgx/args.rs
index b73bf9213b772..a84ab4138761e 100644
--- a/src/libstd/sys/sgx/args.rs
+++ b/src/libstd/sys/sgx/args.rs
@@ -5,9 +5,12 @@ use crate::sys::os_str::Buf;
use crate::sys_common::FromInner;
use crate::slice;
+#[cfg_attr(test, linkage = "available_externally")]
+#[export_name = "_ZN16__rust_internals3std3sys3sgx4args4ARGSE"]
static ARGS: AtomicUsize = AtomicUsize::new(0);
type ArgsStore = Vec;
+#[cfg_attr(test, allow(dead_code))]
pub unsafe fn init(argc: isize, argv: *const *const u8) {
if argc != 0 {
let args = alloc::User::<[ByteBuffer]>::from_raw_parts(argv as _, argc as _);
diff --git a/src/libstd/sys/sgx/condvar.rs b/src/libstd/sys/sgx/condvar.rs
index e9a7684f74d00..f9a76f0baf51a 100644
--- a/src/libstd/sys/sgx/condvar.rs
+++ b/src/libstd/sys/sgx/condvar.rs
@@ -32,7 +32,8 @@ impl Condvar {
mutex.lock()
}
- pub unsafe fn wait_timeout(&self, _mutex: &Mutex, _dur: Duration) -> bool {
+ pub unsafe fn wait_timeout(&self, mutex: &Mutex, _dur: Duration) -> bool {
+ mutex.unlock(); // don't hold the lock while panicking
panic!("timeout not supported in SGX");
}
diff --git a/src/libstd/sys/sgx/net.rs b/src/libstd/sys/sgx/net.rs
index 81f33c16294c3..0e7602a906efa 100644
--- a/src/libstd/sys/sgx/net.rs
+++ b/src/libstd/sys/sgx/net.rs
@@ -41,12 +41,29 @@ impl FromInner for Socket {
}
}
-#[derive(Debug, Clone)]
+#[derive(Clone)]
pub struct TcpStream {
inner: Socket,
peer_addr: Option,
}
+impl fmt::Debug for TcpStream {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let mut res = f.debug_struct("TcpStream");
+
+ if let Some(ref addr) = self.inner.local_addr {
+ res.field("addr", addr);
+ }
+
+ if let Some(ref peer) = self.peer_addr {
+ res.field("peer", peer);
+ }
+
+ res.field("fd", &self.inner.inner.as_inner())
+ .finish()
+ }
+}
+
fn io_err_to_addr(result: io::Result<&SocketAddr>) -> io::Result {
match result {
Ok(saddr) => Ok(saddr.to_string()),
@@ -75,16 +92,32 @@ impl TcpStream {
Ok(TcpStream { inner: Socket::new(fd, local_addr), peer_addr: Some(peer_addr) })
}
- pub fn connect_timeout(addr: &SocketAddr, _: Duration) -> io::Result {
+ pub fn connect_timeout(addr: &SocketAddr, dur: Duration) -> io::Result {
+ if dur == Duration::default() {
+ return Err(io::Error::new(io::ErrorKind::InvalidInput,
+ "cannot set a 0 duration timeout"));
+ }
Self::connect(Ok(addr)) // FIXME: ignoring timeout
}
- pub fn set_read_timeout(&self, _: Option) -> io::Result<()> {
- sgx_ineffective(())
+ pub fn set_read_timeout(&self, dur: Option) -> io::Result<()> {
+ match dur {
+ Some(dur) if dur == Duration::default() => {
+ return Err(io::Error::new(io::ErrorKind::InvalidInput,
+ "cannot set a 0 duration timeout"));
+ }
+ _ => sgx_ineffective(())
+ }
}
- pub fn set_write_timeout(&self, _: Option) -> io::Result<()> {
- sgx_ineffective(())
+ pub fn set_write_timeout(&self, dur: Option) -> io::Result<()> {
+ match dur {
+ Some(dur) if dur == Duration::default() => {
+ return Err(io::Error::new(io::ErrorKind::InvalidInput,
+ "cannot set a 0 duration timeout"));
+ }
+ _ => sgx_ineffective(())
+ }
}
pub fn read_timeout(&self) -> io::Result