3262b1
--- firefox-78.9.0/Cargo.lock.D87019-thin-vec-big-endian.diff	2021-03-18 15:53:29.520861862 +0100
3262b1
+++ firefox-78.9.0/Cargo.lock	2021-03-18 15:56:14.193397228 +0100
3262b1
@@ -4792,9 +4792,9 @@ checksum = "8eaa81235c7058867fa8c0e7314f
3262b1
 
3262b1
 [[package]]
3262b1
 name = "thin-vec"
3262b1
-version = "0.1.2"
3262b1
+version = "0.2.1"
3262b1
 source = "registry+https://github.com/rust-lang/crates.io-index"
3262b1
-checksum = "3a93c9ade36a827a69257925808463db46ffcf193442fad01eb9bdc1d31aed81"
3262b1
+checksum = "dcc760ada4a9f56fc6d0e81bd143984ebc7bb1b875a6891aa2fa613ca7394fc0"
3262b1
 
3262b1
 [[package]]
3262b1
 name = "thiserror"
3262b1
--- firefox-78.9.0/gfx/webrender_bindings/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:33.000000000 +0100
3262b1
+++ firefox-78.9.0/gfx/webrender_bindings/Cargo.toml	2021-03-18 15:53:29.522861856 +0100
3262b1
@@ -20,7 +20,7 @@ nsstring = { path = "../../xpcom/rust/ns
3262b1
 bincode = "1.0"
3262b1
 uuid = { version = "0.8", features = ["v4"] }
3262b1
 fxhash = "0.2.1"
3262b1
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
3262b1
 swgl = { path = "../wr/swgl" }
3262b1
 
3262b1
 [dependencies.webrender]
3262b1
--- firefox-78.9.0/intl/l10n/rust/fluent-ffi/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:33.000000000 +0100
3262b1
+++ firefox-78.9.0/intl/l10n/rust/fluent-ffi/Cargo.toml	2021-03-18 15:53:29.524861850 +0100
3262b1
@@ -10,4 +10,4 @@ fluent-pseudo = "0.2"
3262b1
 intl-memoizer = "0.4"
3262b1
 unic-langid = "0.8"
3262b1
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
3262b1
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
3262b1
--- firefox-78.9.0/intl/locale/rust/fluent-langneg-ffi/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:33.000000000 +0100
3262b1
+++ firefox-78.9.0/intl/locale/rust/fluent-langneg-ffi/Cargo.toml	2021-03-18 15:53:29.525861847 +0100
3262b1
@@ -9,7 +9,7 @@ edition = "2018"
3262b1
 nserror = { path = "../../../../xpcom/rust/nserror" }
3262b1
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
3262b1
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
3262b1
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
3262b1
 fluent-langneg = { version = "0.12.1", features = ["cldr"] }
3262b1
 unic-langid = "0.8"
3262b1
 unic-langid-ffi = { path = "../unic-langid-ffi" }
3262b1
--- firefox-78.9.0/intl/locale/rust/unic-langid-ffi/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:33.000000000 +0100
3262b1
+++ firefox-78.9.0/intl/locale/rust/unic-langid-ffi/Cargo.toml	2021-03-18 15:53:29.526861844 +0100
3262b1
@@ -9,5 +9,5 @@ edition = "2018"
3262b1
 nserror = { path = "../../../../xpcom/rust/nserror" }
3262b1
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
3262b1
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
3262b1
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
3262b1
 unic-langid = { version = "0.8", features = ["likelysubtags"] }
3262b1
--- firefox-78.9.0/netwerk/socket/neqo_glue/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:37.000000000 +0100
3262b1
+++ firefox-78.9.0/netwerk/socket/neqo_glue/Cargo.toml	2021-03-18 15:53:29.527861842 +0100
3262b1
@@ -14,7 +14,7 @@ neqo-common = { tag = "v0.2.4", git = "h
3262b1
 nserror = { path = "../../../xpcom/rust/nserror" }
3262b1
 nsstring = { path = "../../../xpcom/rust/nsstring" }
3262b1
 xpcom = { path = "../../../xpcom/rust/xpcom" }
3262b1
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
3262b1
 
3262b1
 [dependencies.neqo-crypto]
3262b1
 tag = "v0.2.4"
3262b1
--- firefox-78.9.0/security/manager/ssl/cert_storage/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:37.000000000 +0100
3262b1
+++ firefox-78.9.0/security/manager/ssl/cert_storage/Cargo.toml	2021-03-18 15:53:29.528861839 +0100
3262b1
@@ -18,6 +18,6 @@ rust_cascade = "0.6.0"
3262b1
 sha2 = "^0.8"
3262b1
 storage_variant = { path = "../../../../storage/variant" }
3262b1
 tempfile = "3"
3262b1
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
3262b1
 time = "0.1"
3262b1
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
3262b1
--- firefox-78.9.0/services/fxaccounts/rust-bridge/firefox-accounts-bridge/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:38.000000000 +0100
3262b1
+++ firefox-78.9.0/services/fxaccounts/rust-bridge/firefox-accounts-bridge/Cargo.toml	2021-03-18 15:53:29.528861839 +0100
3262b1
@@ -20,5 +20,5 @@ nserror = { path = "../../../../xpcom/ru
3262b1
 nsstring = { path = "../../../../xpcom/rust/nsstring" }
3262b1
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
3262b1
 storage_variant = { path = "../../../../storage/variant" }
3262b1
-thin-vec = { version = "0.1", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
3262b1
 fxa-client = { git = "https://github.com/mozilla/application-services", rev = "61dcc364ac0d6d0816ab88a494bbf20d824b009b", features = ["gecko"] }
3262b1
--- firefox-78.9.0/services/sync/golden_gate/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:38.000000000 +0100
3262b1
+++ firefox-78.9.0/services/sync/golden_gate/Cargo.toml	2021-03-18 15:53:29.529861836 +0100
3262b1
@@ -19,5 +19,5 @@ sync15-traits = { git = "https://github.
3262b1
 xpcom = { path = "../../../xpcom/rust/xpcom" }
3262b1
 
3262b1
 [dependencies.thin-vec]
3262b1
-version = "0.1.0"
3262b1
+version = "0.2.1"
3262b1
 features = ["gecko-ffi"]
3262b1
--- firefox-78.9.0/third_party/rust/thin-vec/.cargo-checksum.json.D87019-thin-vec-big-endian.diff	2021-03-18 15:53:29.529861836 +0100
3262b1
+++ firefox-78.9.0/third_party/rust/thin-vec/.cargo-checksum.json	2021-03-18 15:57:43.631168890 +0100
3262b1
@@ -1 +1 @@
3262b1
-{"files":{"Cargo.toml":"7b164cc8a702a204a4732cb4da2940711b8e3be915c258e2a972d4874d767b4c","README.md":"c26d7101e3031e7dd8890ce938e50cad7a1e6adf7fc2f2b0d3c36b03afe68c0b","src/lib.rs":"9f2a087cabfe0b6f83818323bb9004b45fe7548c51376816fd8d4572256bd0e8","src/range.rs":"bac59bcb6230367a39c7e28ac15263e4526f966cd8c72015873017f17c115aaa"},"package":"3a93c9ade36a827a69257925808463db46ffcf193442fad01eb9bdc1d31aed81"}
3262b1
\ No newline at end of file
3262b1
+{"files":{"Cargo.toml":"754c05523d17eb7591c3ea2c9294e47c05fbb257fed04b78546fb2ec7cafa8b4","README.md":"c26d7101e3031e7dd8890ce938e50cad7a1e6adf7fc2f2b0d3c36b03afe68c0b","src/lib.rs":"627c6094c3f0286dba25bc73f5672c06c5061c25b01c513d213cbdda100673a2"},"package":"dcc760ada4a9f56fc6d0e81bd143984ebc7bb1b875a6891aa2fa613ca7394fc0"}
3262b1
--- firefox-78.9.0/third_party/rust/thin-vec/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:42.000000000 +0100
3262b1
+++ firefox-78.9.0/third_party/rust/thin-vec/Cargo.toml	2021-03-18 15:59:34.162886751 +0100
3262b1
@@ -11,8 +11,9 @@
3262b1
 # will likely look very different (and much more reasonable)
3262b1
 
3262b1
 [package]
3262b1
+edition = "2018"
3262b1
 name = "thin-vec"
3262b1
-version = "0.1.2"
3262b1
+version = "0.2.1"
3262b1
 authors = ["Alexis Beingessner <a.beingessner@gmail.com>"]
3262b1
 description = "a vec that takes up less space on the stack"
3262b1
 homepage = "https://github.com/gankro/thin-vec"
3262b1
--- firefox-78.9.0/third_party/rust/thin-vec/src/lib.rs.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:42.000000000 +0100
3262b1
+++ firefox-78.9.0/third_party/rust/thin-vec/src/lib.rs	2021-03-18 16:08:47.212871917 +0100
3262b1
@@ -1,47 +1,252 @@
3262b1
-mod range;
3262b1
+//! ThinVec is exactly the same as Vec, except that it stores its `len` and `capacity` in the buffer
3262b1
+//! it allocates.
3262b1
+//!
3262b1
+//! This makes the memory footprint of ThinVecs lower; notably in cases where space is reserved for
3262b1
+//! a non-existence ThinVec<T>. So `Vec<ThinVec<T>>` and `Option<ThinVec<T>>::None` will waste less
3262b1
+//! space. Being pointer-sized also means it can be passed/stored in registers.
3262b1
+//!
3262b1
+//! Of course, any actually constructed ThinVec will theoretically have a bigger allocation, but
3262b1
+//! the fuzzy nature of allocators means that might not actually be the case.
3262b1
+//!
3262b1
+//! Properties of Vec that are preserved:
3262b1
+//! * `ThinVec::new()` doesn't allocate (it points to a statically allocated singleton)
3262b1
+//! * reallocation can be done in place
3262b1
+//! * `size_of::<ThinVec<T>>()` == `size_of::<Option<ThinVec<T>>>()`
3262b1
+//!
3262b1
+//! Properties of Vec that aren't preserved:
3262b1
+//! * `ThinVec<T>` can't ever be zero-cost roundtripped to a `Box<[T]>`, `String`, or `*mut T`
3262b1
+//! * `from_raw_parts` doesn't exist
3262b1
+//! * ThinVec currently doesn't bother to not-allocate for Zero Sized Types (e.g. `ThinVec<()>`),
3262b1
+//!   but it could be done if someone cared enough to implement it.
3262b1
+//!
3262b1
+//!
3262b1
+//!
3262b1
+//! # Gecko FFI
3262b1
+//!
3262b1
+//! If you enable the gecko-ffi feature, ThinVec will verbatim bridge with the nsTArray type in
3262b1
+//! Gecko (Firefox). That is, ThinVec and nsTArray have identical layouts *but not ABIs*, 
3262b1
+//! so nsTArrays/ThinVecs an be natively manipulated by C++ and Rust, and ownership can be 
3262b1
+//! transferred across the FFI boundary (**IF YOU ARE CAREFUL, SEE BELOW!!**).
3262b1
+//!
3262b1
+//! While this feature is handy, it is also inherently dangerous to use because Rust and C++ do not
3262b1
+//! know about eachother. Specifically, this can be an issue with non-POD types (types which
3262b1
+//! have destructors, move constructors, or are `!Copy`).
3262b1
+//!
3262b1
+//! ## Do Not Pass By Value
3262b1
+//!
3262b1
+//! The biggest thing to keep in mind is that **FFI functions cannot pass ThinVec/nsTArray 
3262b1
+//! by-value**. That is, these are busted APIs:
3262b1
+//!
3262b1
+//! ```rust,ignore
3262b1
+//! // BAD WRONG
3262b1
+//! extern fn process_data(data: ThinVec<u32>) { ... }
3262b1
+//! // BAD WRONG
3262b1
+//! extern fn get_data() -> ThinVec<u32> { ... }
3262b1
+//! ```
3262b1
+//!
3262b1
+//! You must instead pass by-reference:
3262b1
+//!
3262b1
+//! ```rust
3262b1
+//! # use thin_vec::*;
3262b1
+//! # use std::mem;
3262b1
+//!
3262b1
+//! // Read-only access, ok!
3262b1
+//! extern fn process_data(data: &ThinVec<u32>) {
3262b1
+//!     for val in data {
3262b1
+//!         println!("{}", val);
3262b1
+//!     }
3262b1
+//! }
3262b1
+//! 
3262b1
+//! // Replace with empty instance to take ownership, ok!
3262b1
+//! extern fn consume_data(data: &mut ThinVec<u32>) {
3262b1
+//!     let owned = mem::replace(data, ThinVec::new());
3262b1
+//!     mem::drop(owned);
3262b1
+//! }
3262b1
+//! 
3262b1
+//! // Mutate input, ok!
3262b1
+//! extern fn add_data(dataset: &mut ThinVec<u32>) {
3262b1
+//!     dataset.push(37);
3262b1
+//!     dataset.push(12);
3262b1
+//! }
3262b1
+//! 
3262b1
+//! // Return via out-param, usually ok!
3262b1
+//! //
3262b1
+//! // WARNING: output must be initialized! (Empty nsTArrays are free, so just do it!)
3262b1
+//! extern fn get_data(output: &mut ThinVec<u32>) {
3262b1
+//!     *output = thin_vec![1, 2, 3, 4, 5];
3262b1
+//! }
3262b1
+//! ```
3262b1
+//!
3262b1
+//! Ignorable Explanation For Those Who Really Want To Know Why:
3262b1
+//!
3262b1
+//! > The fundamental issue is that Rust and C++ can't currently communicate about destructors, and
3262b1
+//! > the semantics of C++ require destructors of function arguments to be run when the function
3262b1
+//! > returns. Whether the callee or caller is responsible for this is also platform-specific, so
3262b1
+//! > trying to hack around it manually would be messy. 
3262b1
+//! >
3262b1
+//! > Also a type having a destructor changes its C++ ABI, because that type must actually exist 
3262b1
+//! > in memory (unlike a trivial struct, which is often passed in registers). We don't currently
3262b1
+//! > have a way to communicate to Rust that this is happening, so even if we worked out the
3262b1
+//! > destructor issue with say, MaybeUninit, it would still be a non-starter without some RFCs
3262b1
+//! > to add explicit rustc support.
3262b1
+//! >
3262b1
+//! > Realistically, the best answer here is to have a "heavier" bindgen that can secretly
3262b1
+//! > generate FFI glue so we can pass things "by value" and have it generate by-reference code
3262b1
+//! > behind our back (like the cxx crate does). This would muddy up debugging/searchfox though.
3262b1
+//!
3262b1
+//! ## Types Should Be Trivially Relocatable
3262b1
+//!
3262b1
+//! Types in Rust are always trivially relocatable (unless suitably borrowed/[pinned][]/hidden).
3262b1
+//! This means all Rust types are legal to relocate with a bitwise copy, you cannot provide
3262b1
+//! copy or move constructors to execute when this happens, and the old location won't have its
3262b1
+//! destructor run. This will cause problems for types which have a significant location
3262b1
+//! (types that intrusively point into themselves or have their location registered with a service).
3262b1
+//!
3262b1
+//! While relocations are generally predictable if you're very careful, **you should avoid using
3262b1
+//! types with significant locations with Rust FFI**.
3262b1
+//!
3262b1
+//! Specifically, ThinVec will trivially relocate its contents whenever it needs to reallocate its
3262b1
+//! buffer to change its capacity. This is the default reallocation strategy for nsTArray, and is
3262b1
+//! suitable for the vast majority of types. Just be aware of this limitation!
3262b1
+//!
3262b1
+//! ## Auto Arrays Are Dangerous
3262b1
+//!
3262b1
+//! ThinVec has *some* support for handling auto arrays which store their buffer on the stack, 
3262b1
+//! but this isn't well tested.
3262b1
+//!
3262b1
+//! Regardless of how much support we provide, Rust won't be aware of the buffer's limited lifetime,
3262b1
+//! so standard auto array safety caveats apply about returning/storing them! ThinVec won't ever
3262b1
+//! produce an auto array on its own, so this is only an issue for transferring an nsTArray into
3262b1
+//! Rust.
3262b1
+//!
3262b1
+//! ## Other Issues
3262b1
+//!
3262b1
+//! Standard FFI caveats also apply: 
3262b1
+//!
3262b1
+//!  * Rust is more strict about POD types being initialized (use MaybeUninit if you must)
3262b1
+//!  * `ThinVec<T>` has no idea if the C++ version of `T` has move/copy/assign/delete overloads
3262b1
+//!  * `nsTArray<T>` has no idea if the Rust version of `T` has a Drop/Clone impl
3262b1
+//!  * C++ can do all sorts of unsound things that Rust can't catch
3262b1
+//!  * C++ and Rust don't agree on how zero-sized/empty types should be handled
3262b1
+//!
3262b1
+//! The gecko-ffi feature will not work if you aren't linking with code that has nsTArray
3262b1
+//! defined. Specifically, we must share the symbol for nsTArray's empty singleton. You will get
3262b1
+//! linking errors if that isn't defined.
3262b1
+//!
3262b1
+//! The gecko-ffi feature also limits ThinVec to the legacy behaviors of nsTArray. Most notably,
3262b1
+//! nsTArray has a maximum capacity of i32::MAX (~2.1 billion items). Probably not an issue.
3262b1
+//! Probably.
3262b1
+//!
3262b1
+//! [pinned]: https://doc.rust-lang.org/std/pin/index.html
3262b1
 
3262b1
 use std::{fmt, io, ptr, mem, slice};
3262b1
 use std::collections::Bound;
3262b1
 use std::iter::FromIterator;
3262b1
 use std::slice::IterMut;
3262b1
-use std::ops::{Deref, DerefMut};
3262b1
+use std::ops::{Deref, DerefMut, RangeBounds};
3262b1
 use std::marker::PhantomData;
3262b1
 use std::alloc::*;
3262b1
 use std::cmp::*;
3262b1
 use std::hash::*;
3262b1
 use std::borrow::*;
3262b1
-use range::RangeArgument;
3262b1
 use std::ptr::NonNull;
3262b1
 
3262b1
-#[cfg(not(feature = "gecko-ffi"))]
3262b1
-type SizeType = usize;
3262b1
-#[cfg(feature = "gecko-ffi")]
3262b1
-type SizeType = u32;
3262b1
+use impl_details::*;
3262b1
 
3262b1
-#[cfg(feature = "gecko-ffi")]
3262b1
-const AUTO_MASK: u32 = 1 << 31;
3262b1
-#[cfg(feature = "gecko-ffi")]
3262b1
-const CAP_MASK: u32 = !AUTO_MASK;
3262b1
+// modules: a simple way to cfg a whole bunch of impl details at once
3262b1
 
3262b1
 #[cfg(not(feature = "gecko-ffi"))]
3262b1
-const MAX_CAP: usize = !0;
3262b1
-#[cfg(feature = "gecko-ffi")]
3262b1
-const MAX_CAP: usize = i32::max_value() as usize;
3262b1
+mod impl_details {
3262b1
+    pub type SizeType = usize;
3262b1
+    pub const MAX_CAP: usize = !0;
3262b1
 
3262b1
-#[cfg(not(feature = "gecko-ffi"))]
3262b1
-#[inline(always)]
3262b1
-fn assert_size(x: usize) -> SizeType { x }
3262b1
+    #[inline(always)]
3262b1
+    pub fn assert_size(x: usize) -> SizeType { x }
3262b1
+}
3262b1
 
3262b1
 #[cfg(feature = "gecko-ffi")]
3262b1
-#[inline]
3262b1
-fn assert_size(x: usize) -> SizeType {
3262b1
-    if x > MAX_CAP as usize {
3262b1
-        panic!("nsTArray size may not exceed the capacity of a 32-bit sized int");
3262b1
+mod impl_details {
3262b1
+    // Support for briding a gecko nsTArray verbatim into a ThinVec.
3262b1
+    //
3262b1
+    // ThinVec can't see copy/move/delete implementations
3262b1
+    // from C++
3262b1
+    //
3262b1
+    // The actual layout of an nsTArray is:
3262b1
+    //
3262b1
+    // ```cpp
3262b1
+    // struct {
3262b1
+    //   uint32_t mLength;
3262b1
+    //   uint32_t mCapacity: 31;
3262b1
+    //   uint32_t mIsAutoArray: 1;
3262b1
+    // }
3262b1
+    // ```
3262b1
+    //
3262b1
+    // Rust doesn't natively support bit-fields, so we manually mask
3262b1
+    // and shift the bit. When the "auto" bit is set, the header and buffer
3262b1
+    // are actually on the stack, meaning the ThinVec pointer-to-header
3262b1
+    // is essentially an "owned borrow", and therefore dangerous to handle.
3262b1
+    // There are no safety guards for this situation.
3262b1
+    //
3262b1
+    // On little-endian platforms, the auto bit will be the high-bit of
3262b1
+    // our capacity u32. On big-endian platforms, it will be the low bit.
3262b1
+    // Hence we need some platform-specific CFGs for the necessary masking/shifting.
3262b1
+    // 
3262b1
+    // ThinVec won't ever construct an auto array. They only happen when
3262b1
+    // bridging from C++. This means we don't need to ever set/preserve the bit.
3262b1
+    // We just need to be able to read and handle it if it happens to be there.
3262b1
+    //
3262b1
+    // Handling the auto bit mostly just means not freeing/reallocating the buffer.
3262b1
+
3262b1
+    pub type SizeType = u32;
3262b1
+
3262b1
+    pub const MAX_CAP: usize = i32::max_value() as usize;
3262b1
+
3262b1
+    // Little endian: the auto bit is the high bit, and the capacity is
3262b1
+    // verbatim. So we just need to mask off the high bit. Note that
3262b1
+    // this masking is unnecessary when packing, because assert_size
3262b1
+    // guards against the high bit being set.
3262b1
+    #[cfg(target_endian = "little")]
3262b1
+    pub fn pack_capacity(cap: SizeType) -> SizeType {
3262b1
+        cap as SizeType
3262b1
+    }
3262b1
+    #[cfg(target_endian = "little")]
3262b1
+    pub fn unpack_capacity(cap: SizeType) -> usize {
3262b1
+        (cap as usize) & !(1 << 31)
3262b1
+    }
3262b1
+    #[cfg(target_endian = "little")]
3262b1
+    pub fn is_auto(cap: SizeType) -> bool {
3262b1
+        (cap & (1 << 31)) != 0
3262b1
+    }
3262b1
+
3262b1
+    // Big endian: the auto bit is the low bit, and the capacity is
3262b1
+    // shifted up one bit. Masking out the auto bit is unnecessary,
3262b1
+    // as rust shifts always shift in 0's for unsigned integers.
3262b1
+    #[cfg(target_endian = "big")]
3262b1
+    pub fn pack_capacity(cap: SizeType) -> SizeType {
3262b1
+        (cap as SizeType) << 1
3262b1
+    }
3262b1
+    #[cfg(target_endian = "big")]
3262b1
+    pub fn unpack_capacity(cap: SizeType) -> usize {
3262b1
+        (cap >> 1) as usize
3262b1
+    }
3262b1
+    #[cfg(target_endian = "big")]
3262b1
+    pub fn is_auto(cap: SizeType) -> bool {
3262b1
+        (cap & 1) != 0
3262b1
     }
3262b1
-    x as SizeType
3262b1
+
3262b1
+    #[inline]
3262b1
+    pub fn assert_size(x: usize) -> SizeType {
3262b1
+        if x > MAX_CAP as usize {
3262b1
+            panic!("nsTArray size may not exceed the capacity of a 32-bit sized int");
3262b1
+        }
3262b1
+        x as SizeType
3262b1
+    }
3262b1
+
3262b1
 }
3262b1
 
3262b1
-/// The header of a ThinVec
3262b1
+/// The header of a ThinVec.
3262b1
+///
3262b1
+/// The _cap can be a bitfield, so use accessors to avoid trouble.
3262b1
 #[repr(C)]
3262b1
 struct Header {
3262b1
     _len: SizeType,
3262b1
@@ -53,38 +258,10 @@ impl Header {
3262b1
         self._len as usize
3262b1
     }
3262b1
 
3262b1
-    #[cfg(feature = "gecko-ffi")]
3262b1
-    fn cap(&self) -> usize {
3262b1
-        (self._cap & CAP_MASK) as usize
3262b1
-    }
3262b1
-
3262b1
-    #[cfg(not(feature = "gecko-ffi"))]
3262b1
-    fn cap(&self) -> usize {
3262b1
-        self._cap as usize
3262b1
-    }
3262b1
-
3262b1
     fn set_len(&mut self, len: usize) {
3262b1
         self._len = assert_size(len);
3262b1
     }
3262b1
 
3262b1
-    #[cfg(feature = "gecko-ffi")]
3262b1
-    fn set_cap(&mut self, cap: usize) {
3262b1
-        debug_assert!(cap & (CAP_MASK as usize) == cap);
3262b1
-        // FIXME: this is busted because it reads uninit memory
3262b1
-        // debug_assert!(!self.uses_stack_allocated_buffer());
3262b1
-        self._cap = assert_size(cap) & CAP_MASK;
3262b1
-    }
3262b1
-
3262b1
-    #[cfg(feature = "gecko-ffi")]
3262b1
-    fn uses_stack_allocated_buffer(&self) -> bool {
3262b1
-        self._cap & AUTO_MASK != 0
3262b1
-    }
3262b1
-
3262b1
-    #[cfg(not(feature = "gecko-ffi"))]
3262b1
-    fn set_cap(&mut self, cap: usize) {
3262b1
-        self._cap = assert_size(cap);
3262b1
-    }
3262b1
-
3262b1
     fn data<T>(&self) -> *mut T {
3262b1
         let header_size = mem::size_of::<Header>();
3262b1
         let padding = padding::<T>();
3262b1
@@ -102,6 +279,41 @@ impl Header {
3262b1
     }
3262b1
 }
3262b1
 
3262b1
+
3262b1
+#[cfg(feature = "gecko-ffi")]
3262b1
+impl Header {
3262b1
+    fn cap(&self) -> usize {
3262b1
+        unpack_capacity(self._cap)
3262b1
+    }
3262b1
+
3262b1
+    fn set_cap(&mut self, cap: usize) {
3262b1
+        // debug check that our packing is working
3262b1
+        debug_assert_eq!(unpack_capacity(pack_capacity(cap as SizeType)), cap);
3262b1
+        // FIXME: this assert is busted because it reads uninit memory
3262b1
+        // debug_assert!(!self.uses_stack_allocated_buffer());
3262b1
+
3262b1
+        // NOTE: this always stores a cleared auto bit, because set_cap
3262b1
+        // is only invoked by Rust, and Rust doesn't create auto arrays.
3262b1
+        self._cap = pack_capacity(assert_size(cap));
3262b1
+    }
3262b1
+
3262b1
+    fn uses_stack_allocated_buffer(&self) -> bool {
3262b1
+        is_auto(self._cap)
3262b1
+    }
3262b1
+}
3262b1
+
3262b1
+#[cfg(not(feature = "gecko-ffi"))]
3262b1
+impl Header {
3262b1
+    fn cap(&self) -> usize {
3262b1
+        self._cap as usize
3262b1
+    }
3262b1
+
3262b1
+    fn set_cap(&mut self, cap: usize) {
3262b1
+        self._cap = assert_size(cap);
3262b1
+    }
3262b1
+}
3262b1
+
3262b1
+
3262b1
 /// Singleton that all empty collections share.
3262b1
 /// Note: can't store non-zero ZSTs, we allocate in that case. We could
3262b1
 /// optimize everything to not do that (basically, make ptr == len and branch
3262b1
@@ -118,9 +330,7 @@ extern {
3262b1
 
3262b1
 // TODO: overflow checks everywhere
3262b1
 
3262b1
-// Utils
3262b1
-
3262b1
-fn oom() -> ! { std::process::abort() }
3262b1
+// Utils for computing layouts of allocations
3262b1
 
3262b1
 fn alloc_size<T>(cap: usize) -> usize {
3262b1
     // Compute "real" header size with pointer math
3262b1
@@ -165,9 +375,10 @@ fn layout<T>(cap: usize) -> Layout {
3262b1
 fn header_with_capacity<T>(cap: usize) -> NonNull<Header> {
3262b1
     debug_assert!(cap > 0);
3262b1
     unsafe {
3262b1
-        let header = alloc(layout::<T>(cap)) as *mut Header;
3262b1
+        let layout = layout::<T>(cap);
3262b1
+        let header = alloc(layout) as *mut Header;
3262b1
 
3262b1
-        if header.is_null() { oom() }
3262b1
+        if header.is_null() { handle_alloc_error(layout) }
3262b1
 
3262b1
         // "Infinite" capacity for zero-sized types:
3262b1
         (*header).set_cap(if mem::size_of::<T>() == 0 { MAX_CAP } else { cap });
3262b1
@@ -179,28 +390,8 @@ fn header_with_capacity<T>(cap: usize) -
3262b1
 
3262b1
 
3262b1
 
3262b1
-/// ThinVec is exactly the same as Vec, except that it stores its `len` and `capacity` in the buffer
3262b1
-/// it allocates.
3262b1
-///
3262b1
-/// This makes the memory footprint of ThinVecs lower; notably in cases where space is reserved for
3262b1
-/// a non-existence ThinVec<T>. So `Vec<ThinVec<T>>` and `Option<ThinVec<T>>::None` will waste less
3262b1
-/// space. Being pointer-sized also means it can be passed/stored in registers.
3262b1
-///
3262b1
-/// Of course, any actually constructed ThinVec will theoretically have a bigger allocation, but
3262b1
-/// the fuzzy nature of allocators means that might not actually be the case.
3262b1
-///
3262b1
-/// Properties of Vec that are preserved:
3262b1
-/// * `ThinVec::new()` doesn't allocate (it points to a statically allocated singleton)
3262b1
-/// * reallocation can be done in place
3262b1
-/// * `size_of::<ThinVec<T>>()` == `size_of::<Option<ThinVec<T>>>()`
3262b1
-///   * NOTE: This is only possible when the `unstable` feature is used.
3262b1
-///
3262b1
-/// Properties of Vec that aren't preserved:
3262b1
-/// * `ThinVec<T>` can't ever be zero-cost roundtripped to a `Box<[T]>`, `String`, or `*mut T`
3262b1
-/// * `from_raw_parts` doesn't exist
3262b1
-/// * ThinVec currently doesn't bother to not-allocate for Zero Sized Types (e.g. `ThinVec<()>`),
3262b1
-///   but it could be done if someone cared enough to implement it.
3262b1
-#[cfg_attr(feature = "gecko-ffi", repr(C))]
3262b1
+/// See the crate's top level documentation for a description of this type.
3262b1
+#[repr(C)]
3262b1
 pub struct ThinVec<T> {
3262b1
     ptr: NonNull<Header>,
3262b1
     boo: PhantomData<T>,
3262b1
@@ -630,15 +821,15 @@ impl<T> ThinVec<T> {
3262b1
     }
3262b1
 
3262b1
     pub fn drain<R>(&mut self, range: R) -> Drain<T>
3262b1
-        where R: RangeArgument<usize>
3262b1
+        where R: RangeBounds<usize>
3262b1
     {
3262b1
         let len = self.len();
3262b1
-        let start = match range.start() {
3262b1
+        let start = match range.start_bound() {
3262b1
             Bound::Included(&n) => n,
3262b1
             Bound::Excluded(&n) => n + 1,
3262b1
             Bound::Unbounded => 0,
3262b1
         };
3262b1
-        let end = match range.end() {
3262b1
+        let end = match range.end_bound() {
3262b1
             Bound::Included(&n) => n + 1,
3262b1
             Bound::Excluded(&n) => n,
3262b1
             Bound::Unbounded => len,
3262b1
@@ -688,11 +879,30 @@ impl<T> ThinVec<T> {
3262b1
                 alloc_size::<T>(new_cap),
3262b1
             ) as *mut Header;
3262b1
 
3262b1
-            if ptr.is_null() { oom() }
3262b1
+            if ptr.is_null() { handle_alloc_error(layout::<T>(new_cap)) }
3262b1
             (*ptr).set_cap(new_cap);
3262b1
             self.ptr = NonNull::new_unchecked(ptr);
3262b1
         } else {
3262b1
-            self.ptr = header_with_capacity::<T>(new_cap);
3262b1
+            let mut new_header = header_with_capacity::<T>(new_cap);
3262b1
+
3262b1
+            // If we get here and have a non-zero len, then we must be handling
3262b1
+            // a gecko auto array, and we have items in a stack buffer. We shouldn't
3262b1
+            // free it, but we should memcopy the contents out of it and mark it as empty.
3262b1
+            //
3262b1
+            // T is assumed to be trivially relocatable, as this is ~required
3262b1
+            // for Rust compatibility anyway. Furthermore, we assume C++ won't try
3262b1
+            // to unconditionally destroy the contents of the stack allocated buffer
3262b1
+            // (i.e. it's obfuscated behind a union).
3262b1
+            //
3262b1
+            // In effect, we are partially reimplementing the auto array move constructor
3262b1
+            // by leaving behind a valid empty instance.
3262b1
+            let len = self.len();
3262b1
+            if cfg!(feature = "gecko-ffi") && len > 0 {
3262b1
+                new_header.as_mut().data::<T>().copy_from_nonoverlapping(self.data_raw(), len);
3262b1
+                self.set_len(0);
3262b1
+            }
3262b1
+            
3262b1
+            self.ptr = new_header;
3262b1
         }
3262b1
     }
3262b1
 
3262b1
@@ -1093,10 +1303,7 @@ mod tests {
3262b1
         use std::mem::size_of;
3262b1
         assert_eq!(size_of::<ThinVec<u8>>(), size_of::<&u8>());
3262b1
 
3262b1
-        // We don't perform the null-pointer optimization on stable rust.
3262b1
-        if cfg!(feature = "unstable") {
3262b1
-            assert_eq!(size_of::<Option<ThinVec<u8>>>(), size_of::<&u8>());
3262b1
-        }
3262b1
+        assert_eq!(size_of::<Option<ThinVec<u8>>>(), size_of::<&u8>());
3262b1
     }
3262b1
 
3262b1
     #[test]
3262b1
@@ -1731,7 +1938,6 @@ mod std_tests {
3262b1
         assert_eq!(v, &[(), ()]);
3262b1
     }
3262b1
 
3262b1
-/* TODO: support inclusive ranges
3262b1
     #[test]
3262b1
     fn test_drain_inclusive_range() {
3262b1
         let mut v = thin_vec!['a', 'b', 'c', 'd', 'e'];
3262b1
@@ -1761,6 +1967,7 @@ mod std_tests {
3262b1
     }
3262b1
 
3262b1
     #[test]
3262b1
+    #[cfg(not(feature = "gecko-ffi"))]
3262b1
     fn test_drain_max_vec_size() {
3262b1
         let mut v = ThinVec::<()>::with_capacity(usize::max_value());
3262b1
         unsafe { v.set_len(usize::max_value()); }
3262b1
@@ -1781,7 +1988,6 @@ mod std_tests {
3262b1
         let mut v = thin_vec![1, 2, 3, 4, 5];
3262b1
         v.drain(5..=5);
3262b1
     }
3262b1
-*/
3262b1
 
3262b1
 /* TODO: implement splice?
3262b1
     #[test]
3262b1
@@ -2187,7 +2393,7 @@ mod std_tests {
3262b1
         assert!(v.capacity() >= 33)
3262b1
     }
3262b1
 
3262b1
-/* TODO: implement try_reserve 
3262b1
+/* TODO: implement try_reserve
3262b1
     #[test]
3262b1
     fn test_try_reserve() {
3262b1
 
3262b1
--- firefox-78.9.0/toolkit/components/cascade_bloom_filter/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:42.000000000 +0100
3262b1
+++ firefox-78.9.0/toolkit/components/cascade_bloom_filter/Cargo.toml	2021-03-18 15:54:35.137670977 +0100
3262b1
@@ -8,5 +8,5 @@ nserror = { path = "../../../xpcom/rust/
3262b1
 nsstring = { path = "../../../xpcom/rust/nsstring" }
3262b1
 rental = "0.5.5"
3262b1
 rust_cascade = "0.6.0"
3262b1
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
3262b1
 xpcom = { path = "../../../xpcom/rust/xpcom" }
3262b1
--- firefox-78.9.0/toolkit/components/extensions/storage/webext_storage_bridge/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:42.000000000 +0100
3262b1
+++ firefox-78.9.0/toolkit/components/extensions/storage/webext_storage_bridge/Cargo.toml	2021-03-18 15:54:35.139670971 +0100
3262b1
@@ -13,7 +13,7 @@ moz_task = { path = "../../../../../xpco
3262b1
 nserror = { path = "../../../../../xpcom/rust/nserror" }
3262b1
 nsstring = { path = "../../../../../xpcom/rust/nsstring" }
3262b1
 once_cell = "1"
3262b1
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
3262b1
 xpcom = { path = "../../../../../xpcom/rust/xpcom" }
3262b1
 serde = "1"
3262b1
 serde_json = "1"
3262b1
--- firefox-78.9.0/toolkit/components/kvstore/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:42.000000000 +0100
3262b1
+++ firefox-78.9.0/toolkit/components/kvstore/Cargo.toml	2021-03-18 15:54:35.141670966 +0100
3262b1
@@ -18,7 +18,7 @@ rkv = "0.10.2"
3262b1
 storage_variant = { path = "../../../storage/variant" }
3262b1
 xpcom = { path = "../../../xpcom/rust/xpcom" }
3262b1
 tempfile = "3"
3262b1
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
3262b1
 
3262b1
 # Get rid of failure's dependency on backtrace. Eventually
3262b1
 # backtrace will move into Rust core, but we don't need it here.
3262b1
--- firefox-78.9.0/toolkit/components/places/bookmark_sync/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:42.000000000 +0100
3262b1
+++ firefox-78.9.0/toolkit/components/places/bookmark_sync/Cargo.toml	2021-03-18 15:54:35.142670963 +0100
3262b1
@@ -19,5 +19,5 @@ url = "2.0"
3262b1
 xpcom = { path = "../../../../xpcom/rust/xpcom" }
3262b1
 
3262b1
 [dependencies.thin-vec]
3262b1
-version = "0.1.0"
3262b1
+version = "0.2.1"
3262b1
 features = ["gecko-ffi"]
3262b1
--- firefox-78.9.0/tools/profiler/rust-helper/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:42.000000000 +0100
3262b1
+++ firefox-78.9.0/tools/profiler/rust-helper/Cargo.toml	2021-03-18 15:54:35.143670960 +0100
3262b1
@@ -23,7 +23,7 @@ features = ["endian_fd", "elf32", "elf64
3262b1
 default-features = false
3262b1
 
3262b1
 [dependencies.thin-vec]
3262b1
-version = "0.1.0"
3262b1
+version = "0.2.1"
3262b1
 features = ["gecko-ffi"]
3262b1
 
3262b1
 [features]
3262b1
--- firefox-78.9.0/xpcom/rust/xpcom/Cargo.toml.D87019-thin-vec-big-endian.diff	2021-03-15 16:52:43.000000000 +0100
3262b1
+++ firefox-78.9.0/xpcom/rust/xpcom/Cargo.toml	2021-03-18 15:54:35.149670942 +0100
3262b1
@@ -9,4 +9,4 @@ nsstring = { path = "../nsstring" }
3262b1
 nserror = { path = "../nserror" }
3262b1
 threadbound = "0.1"
3262b1
 xpcom_macros = { path = "xpcom_macros" }
3262b1
-thin-vec = { version = "0.1.0", features = ["gecko-ffi"] }
3262b1
+thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }