From 17380f2ac6d0d259ab6fd3685f9f107e368c01d3 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 24 Dec 2017 11:29:13 -0800 Subject: [PATCH 1/7] Minor rewrite of env::current_exe docs; clarify symlinks. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update example in ‘security’ section to use hard links, like the linked securityvulns.com example. - Weaken language on symbolic links – indicate behavior is platform-specific Fixes https://github.com/rust-lang/rust/issues/43617. --- src/libstd/env.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 457c6e1409d3c..ed34c1204b3a1 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -571,8 +571,11 @@ pub fn temp_dir() -> PathBuf { /// Returns the full filesystem path of the current running executable. /// -/// The path returned is not necessarily a "real path" of the executable as -/// there may be intermediate symlinks. +/// # Platform-specific behavior +/// +/// If the executable was invoked through a symbolic link, some platforms will +/// return the path of the symbolic link and other platforms will return the +/// path of the symbolic link’s target. /// /// # Errors /// @@ -599,14 +602,14 @@ pub fn temp_dir() -> PathBuf { /// Ok("/home/alex/foo") /// ``` /// -/// And you make a symbolic link of the program: +/// And you make a hard link of the program: /// /// ```bash /// $ ln foo bar /// ``` /// -/// When you run it, you won't get the original executable, you'll get the -/// symlink: +/// When you run it, you won’t get the path of the original executable, you’ll +/// get the path of the hard link: /// /// ```bash /// $ ./bar @@ -614,9 +617,9 @@ pub fn temp_dir() -> PathBuf { /// ``` /// /// This sort of behavior has been known to [lead to privilege escalation] when -/// used incorrectly, for example. +/// used incorrectly. /// -/// [lead to privilege escalation]: http://securityvulns.com/Wdocument183.html +/// [lead to privilege escalation]: https://securityvulns.com/Wdocument183.html /// /// # Examples /// @@ -625,7 +628,7 @@ pub fn temp_dir() -> PathBuf { /// /// match env::current_exe() { /// Ok(exe_path) => println!("Path of this executable is: {}", -/// exe_path.display()), +/// exe_path.display()), /// Err(e) => println!("failed to get current exe path: {}", e), /// }; /// ``` From d7bbd3042cc674fb1a863c89085044a8a4a8b15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Fri, 8 Dec 2017 10:53:46 +0100 Subject: [PATCH 2/7] Remove outdated LLVMRustBuildLandingPad() wrapper The function was added as a wrapper to handle compatibility with older LLVM versions that we no longer support, so it can be removed. Refs #46437 --- src/librustc_llvm/ffi.rs | 13 ++++++------- src/librustc_trans/builder.rs | 7 +++---- src/librustc_trans/intrinsic.rs | 2 +- src/librustc_trans/mir/block.rs | 2 +- src/rustllvm/RustWrapper.cpp | 7 ------- 5 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index 7d65349446516..746c5a7cb247e 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -812,13 +812,12 @@ extern "C" { Bundle: OperandBundleDefRef, Name: *const c_char) -> ValueRef; - pub fn LLVMRustBuildLandingPad(B: BuilderRef, - Ty: TypeRef, - PersFn: ValueRef, - NumClauses: c_uint, - Name: *const c_char, - F: ValueRef) - -> ValueRef; + pub fn LLVMBuildLandingPad(B: BuilderRef, + Ty: TypeRef, + PersFn: ValueRef, + NumClauses: c_uint, + Name: *const c_char) + -> ValueRef; pub fn LLVMBuildResume(B: BuilderRef, Exn: ValueRef) -> ValueRef; pub fn LLVMBuildUnreachable(B: BuilderRef) -> ValueRef; diff --git a/src/librustc_trans/builder.rs b/src/librustc_trans/builder.rs index 5b697d6b99c95..4a0b1381a4008 100644 --- a/src/librustc_trans/builder.rs +++ b/src/librustc_trans/builder.rs @@ -1012,12 +1012,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } pub fn landing_pad(&self, ty: Type, pers_fn: ValueRef, - num_clauses: usize, - llfn: ValueRef) -> ValueRef { + num_clauses: usize) -> ValueRef { self.count_insn("landingpad"); unsafe { - llvm::LLVMRustBuildLandingPad(self.llbuilder, ty.to_ref(), pers_fn, - num_clauses as c_uint, noname(), llfn) + llvm::LLVMBuildLandingPad(self.llbuilder, ty.to_ref(), pers_fn, + num_clauses as c_uint, noname()) } } diff --git a/src/librustc_trans/intrinsic.rs b/src/librustc_trans/intrinsic.rs index 3cd60e7f1bc7f..cfddd99d0dd9a 100644 --- a/src/librustc_trans/intrinsic.rs +++ b/src/librustc_trans/intrinsic.rs @@ -925,7 +925,7 @@ fn trans_gnu_try<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, // rust_try ignores the selector. let lpad_ty = Type::struct_(ccx, &[Type::i8p(ccx), Type::i32(ccx)], false); - let vals = catch.landing_pad(lpad_ty, bcx.ccx.eh_personality(), 1, catch.llfn()); + let vals = catch.landing_pad(lpad_ty, bcx.ccx.eh_personality(), 1); catch.add_clause(vals, C_null(Type::i8p(ccx))); let ptr = catch.extract_value(vals, 0); let ptr_align = bcx.tcx().data_layout.pointer_align; diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs index 422b8210b3544..8c9fb03954583 100644 --- a/src/librustc_trans/mir/block.rs +++ b/src/librustc_trans/mir/block.rs @@ -753,7 +753,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { let llpersonality = self.ccx.eh_personality(); let llretty = self.landing_pad_type(); - let lp = bcx.landing_pad(llretty, llpersonality, 1, self.llfn); + let lp = bcx.landing_pad(llretty, llpersonality, 1); bcx.set_cleanup(lp); let slot = self.get_personality_slot(&bcx); diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 6f51ea67cb1d1..d5095f1f94c3e 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -1144,13 +1144,6 @@ extern "C" void LLVMRustWriteSMDiagnosticToString(LLVMSMDiagnosticRef D, unwrap(D)->print("", OS); } -extern "C" LLVMValueRef -LLVMRustBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty, - LLVMValueRef PersFn, unsigned NumClauses, - const char *Name, LLVMValueRef F) { - return LLVMBuildLandingPad(B, Ty, PersFn, NumClauses, Name); -} - extern "C" LLVMValueRef LLVMRustBuildCleanupPad(LLVMBuilderRef B, LLVMValueRef ParentPad, unsigned ArgCount, From 493c29d35ac7ad1fd1558155b4f5ea056dfc7d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Fri, 8 Dec 2017 11:07:08 +0100 Subject: [PATCH 3/7] Remove unused function LLVMRustGetValueContext() Refs #46437 --- src/librustc_llvm/ffi.rs | 3 --- src/rustllvm/RustWrapper.cpp | 4 ---- 2 files changed, 7 deletions(-) diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index 746c5a7cb247e..4e65195626507 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -538,9 +538,6 @@ extern "C" { /// See llvm::LLVMTypeKind::getTypeID. pub fn LLVMRustGetTypeKind(Ty: TypeRef) -> TypeKind; - /// See llvm::Value::getContext - pub fn LLVMRustGetValueContext(V: ValueRef) -> ContextRef; - // Operations on integer types pub fn LLVMInt1TypeInContext(C: ContextRef) -> TypeRef; pub fn LLVMInt8TypeInContext(C: ContextRef) -> TypeRef; diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index d5095f1f94c3e..d4480002d4000 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -1348,10 +1348,6 @@ extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext, uint64_t *hig return true; } -extern "C" LLVMContextRef LLVMRustGetValueContext(LLVMValueRef V) { - return wrap(&unwrap(V)->getContext()); -} - enum class LLVMRustVisibility { Default = 0, Hidden = 1, From 7e522b2f0ebddd60fb3df467cb755c2de0f37f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Fri, 8 Dec 2017 11:23:23 +0100 Subject: [PATCH 4/7] Simplify LLVMRustModuleCost() --- src/rustllvm/RustWrapper.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index d4480002d4000..96fb05ee06e37 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -1428,11 +1428,6 @@ LLVMRustModuleBufferLen(const LLVMRustModuleBuffer *Buffer) { extern "C" uint64_t LLVMRustModuleCost(LLVMModuleRef M) { - Module &Mod = *unwrap(M); - uint64_t cost = 0; - for (auto &F : Mod.functions()) { - (void)F; - cost += 1; - } - return cost; + auto f = unwrap(M)->functions(); + return std::distance(std::begin(f), std::end(f)); } From 91c3eee1735ad72b579f99cbb6919c3471747d94 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Wed, 3 Jan 2018 12:09:22 -0800 Subject: [PATCH 5/7] [unix] Don't clone command-line args on startup --- src/libstd/sys/unix/args.rs | 39 +++++++++++++++---------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/libstd/sys/unix/args.rs b/src/libstd/sys/unix/args.rs index 72169773df596..e1c7ffc19e51e 100644 --- a/src/libstd/sys/unix/args.rs +++ b/src/libstd/sys/unix/args.rs @@ -69,7 +69,7 @@ impl DoubleEndedIterator for Args { target_os = "fuchsia"))] mod imp { use os::unix::prelude::*; - use mem; + use ptr; use ffi::{CStr, OsString}; use marker::PhantomData; use libc; @@ -77,49 +77,42 @@ mod imp { use sys_common::mutex::Mutex; - static mut GLOBAL_ARGS_PTR: usize = 0; + static mut ARGC: isize = 0; + static mut ARGV: *const *const u8 = ptr::null(); static LOCK: Mutex = Mutex::new(); pub unsafe fn init(argc: isize, argv: *const *const u8) { - let args = (0..argc).map(|i| { - CStr::from_ptr(*argv.offset(i) as *const libc::c_char).to_bytes().to_vec() - }).collect(); - LOCK.lock(); - let ptr = get_global_ptr(); - assert!((*ptr).is_none()); - (*ptr) = Some(box args); + ARGC = argc; + ARGV = argv; LOCK.unlock(); } pub unsafe fn cleanup() { LOCK.lock(); - *get_global_ptr() = None; + ARGC = 0; + ARGV = ptr::null(); LOCK.unlock(); } pub fn args() -> Args { - let bytes = clone().unwrap_or(Vec::new()); - let v: Vec = bytes.into_iter().map(|v| { - OsStringExt::from_vec(v) - }).collect(); - Args { iter: v.into_iter(), _dont_send_or_sync_me: PhantomData } + Args { + iter: clone().into_iter(), + _dont_send_or_sync_me: PhantomData + } } - fn clone() -> Option>> { + fn clone() -> Vec { unsafe { LOCK.lock(); - let ptr = get_global_ptr(); - let ret = (*ptr).as_ref().map(|s| (**s).clone()); + let ret = (0..ARGC).map(|i| { + let cstr = CStr::from_ptr(*ARGV.offset(i) as *const libc::c_char); + OsStringExt::from_vec(cstr.to_bytes().to_vec()) + }).collect(); LOCK.unlock(); return ret } } - - fn get_global_ptr() -> *mut Option>>> { - unsafe { mem::transmute(&GLOBAL_ARGS_PTR) } - } - } #[cfg(any(target_os = "macos", From eea860f84c9338fbd89c1afe0aedd2c344aa6476 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 5 Jan 2018 01:14:10 +0100 Subject: [PATCH 6/7] Fix search bar defocus --- src/librustdoc/html/static/main.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index c128a812b93b0..b4dbd76d0b4d0 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1132,6 +1132,10 @@ e.preventDefault(); } else if (e.which === 16) { // shift // Does nothing, it's just to avoid losing "focus" on the highlighted element. + } else if (e.which === 27) { // escape + removeClass(actives[currentTab][0], 'highlighted'); + document.getElementsByClassName('search-input')[0].value = ''; + defocusSearchBar(); } else if (actives[currentTab].length > 0) { removeClass(actives[currentTab][0], 'highlighted'); } From d301da55f8cd7b8b10771d3171ae60ba334bf067 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Fri, 5 Jan 2018 04:24:12 -0800 Subject: [PATCH 7/7] Clarify appending behavior of 'io::Read::read_to_string()'. --- src/libstd/io/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index e9b707c57ebbf..ad9cf1eed7013 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -601,7 +601,7 @@ pub trait Read { read_to_end(self, buf) } - /// Read all bytes until EOF in this source, placing them into `buf`. + /// Read all bytes until EOF in this source, appending them to `buf`. /// /// If successful, this function returns the number of bytes which were read /// and appended to `buf`.