diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-02-17 03:34:49 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-02-17 03:34:49 +0000 |
commit | f7c7836b218c48d0679b7e0bcb9f1f761a314304 (patch) | |
tree | 7b14a24af26486283f595479fc9215e55d1fccda | |
parent | 997f90e1e3956932e8296344a30ff6d9f6b401d9 (diff) | |
parent | b9ce3fd360024e04bff9e8b3ad89f8bd5825e128 (diff) | |
download | crossbeam-epoch-f7c7836b218c48d0679b7e0bcb9f1f761a314304.tar.gz |
Snap for 8191477 from b9ce3fd360024e04bff9e8b3ad89f8bd5825e128 to tm-frc-scheduling-release
Change-Id: I247f42c92d5c492c2ed4a8dc316c85a12c5c3ab7
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 72 | ||||
-rw-r--r-- | CHANGELOG.md | 11 | ||||
-rw-r--r-- | Cargo.lock | 39 | ||||
-rw-r--r-- | Cargo.toml | 6 | ||||
-rw-r--r-- | Cargo.toml.orig | 21 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | TEST_MAPPING | 24 | ||||
-rw-r--r-- | build.rs | 32 | ||||
-rw-r--r-- | cargo2android.json | 5 | ||||
-rw-r--r-- | no_atomic.rs | 59 | ||||
-rw-r--r-- | src/atomic.rs | 30 | ||||
-rw-r--r-- | src/lib.rs | 11 |
14 files changed, 204 insertions, 118 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 1d9c34d..1f53d5d 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "d841a2028dc72b4e09739116f07e865db60f3690" + "sha1": "6d4cdd4daf9a897deef6cde9569f2fbf12c29bc5" } } @@ -1,4 +1,4 @@ -// This file is generated by cargo2android.py --run --device --dependencies --tests. +// This file is generated by cargo2android.py --config cargo2android.json. // Do not modify this file as changes will be overridden on upgrade. package { @@ -39,48 +39,18 @@ license { ], } -rust_defaults { - name: "crossbeam-epoch_defaults", +rust_test { + name: "crossbeam-epoch_test_src_lib", + host_supported: true, crate_name: "crossbeam_epoch", + cargo_env_compat: true, + cargo_pkg_version: "0.9.5", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, - edition: "2018", - features: [ - "alloc", - "default", - "lazy_static", - "std", - ], - rustlibs: [ - "libcfg_if", - "libcrossbeam_utils", - "liblazy_static", - "libmemoffset", - "librand", - "libscopeguard", - ], -} - -rust_test_host { - name: "crossbeam-epoch_host_test_src_lib", - defaults: ["crossbeam-epoch_defaults"], test_options: { unit_test: true, }, -} - -rust_test { - name: "crossbeam-epoch_device_test_src_lib", - defaults: ["crossbeam-epoch_defaults"], -} - -rust_defaults { - name: "crossbeam-epoch_defaults_loom", - crate_name: "loom", - srcs: ["tests/loom.rs"], - test_suites: ["general-tests"], - auto_gen_config: true, edition: "2018", features: [ "alloc", @@ -90,7 +60,6 @@ rust_defaults { ], rustlibs: [ "libcfg_if", - "libcrossbeam_epoch", "libcrossbeam_utils", "liblazy_static", "libmemoffset", @@ -99,23 +68,12 @@ rust_defaults { ], } -rust_test_host { - name: "crossbeam-epoch_host_test_tests_loom", - defaults: ["crossbeam-epoch_defaults_loom"], - test_options: { - unit_test: true, - }, -} - -rust_test { - name: "crossbeam-epoch_device_test_tests_loom", - defaults: ["crossbeam-epoch_defaults_loom"], -} - rust_library { name: "libcrossbeam_epoch", host_supported: true, crate_name: "crossbeam_epoch", + cargo_env_compat: true, + cargo_pkg_version: "0.9.5", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -132,17 +90,3 @@ rust_library { "libscopeguard", ], } - -// dependent_library ["feature_list"] -// autocfg-1.0.1 -// cfg-if-1.0.0 -// crossbeam-utils-0.8.3 "lazy_static,std" -// getrandom-0.2.2 "std" -// lazy_static-1.4.0 -// libc-0.2.92 -// memoffset-0.6.3 "default" -// ppv-lite86-0.2.10 "simd,std" -// rand-0.8.3 "alloc,default,getrandom,libc,rand_chacha,rand_hc,std,std_rng" -// rand_chacha-0.3.0 "std" -// rand_core-0.6.2 "alloc,getrandom,std" -// scopeguard-1.1.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f30b70..c78fbf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# Version 0.9.5 + +- Fix UB in `Pointable` impl of `[MaybeUninit<T>]` (#694) +- Support targets that do not have atomic CAS on stable Rust (#698) +- Fix breakage with nightly feature due to rust-lang/rust#84510 (#692) + +# Version 0.9.4 + +- Fix UB in `<[MaybeUninit<T>] as Pointable>::init` when global allocator failed allocation (#690) +- Bump `loom` dependency to version 0.5. (#686) + # Version 0.9.3 - Make `loom` dependency optional. (#666) @@ -10,9 +10,9 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "cc" -version = "1.0.67" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" +checksum = "4a72c244c1ff497a746a7e1fb3d14bd08420ecda70c8f25c7112f2781652d787" [[package]] name = "cfg-if" @@ -22,13 +22,13 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "const_fn" -version = "0.4.5" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b9d6de7f49e22cf97ad17fc4036ece69300032f45f78f30b4a4482cdc3f4a6" +checksum = "f92cfa0fd5690b3cf8c1ef2cabbd9b7ef22fa53cf5e1f92b05103f6d5d1cf6e7" [[package]] name = "crossbeam-epoch" -version = "0.9.3" +version = "0.9.5" dependencies = [ "cfg-if", "const_fn", @@ -42,11 +42,10 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.3" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" dependencies = [ - "autocfg", "cfg-if", "lazy_static", "loom", @@ -54,9 +53,9 @@ dependencies = [ [[package]] name = "generator" -version = "0.6.24" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9fed24fd1e18827652b4d55652899a1e9da8e54d91624dc3437a5bc3a9f9a9c" +checksum = "c1d9279ca822891c1a4dae06d185612cf8fc6acfe5dff37781b41297811b12ee" dependencies = [ "cc", "libc", @@ -67,9 +66,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" dependencies = [ "cfg-if", "libc", @@ -84,9 +83,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.86" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36" [[package]] name = "log" @@ -99,9 +98,9 @@ dependencies = [ [[package]] name = "loom" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d44c73b4636e497b4917eb21c33539efa3816741a2d3ff26c6316f1b529481a4" +checksum = "7aa5348dc45fa5f2419b6dd4ea20345e6b01b1fcc9d176a322eada1ac3f382ba" dependencies = [ "cfg-if", "generator", @@ -110,9 +109,9 @@ dependencies = [ [[package]] name = "memoffset" -version = "0.6.1" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87" +checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" dependencies = [ "autocfg", ] @@ -165,9 +164,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb5d2a036dc6d2d8fd16fde3498b04306e29bd193bf306a57427019b823d5acd" +checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088" [[package]] name = "scoped-tls" @@ -13,7 +13,7 @@ [package] edition = "2018" name = "crossbeam-epoch" -version = "0.9.3" +version = "0.9.5" authors = ["The Crossbeam Project Developers"] description = "Epoch-based garbage collection" homepage = "https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-epoch" @@ -30,7 +30,7 @@ version = "0.4.4" optional = true [dependencies.crossbeam-utils] -version = "0.8.3" +version = "0.8.5" default-features = false [dependencies.lazy_static] @@ -53,6 +53,6 @@ loom = ["loom-crate", "crossbeam-utils/loom"] nightly = ["crossbeam-utils/nightly", "const_fn"] std = ["alloc", "crossbeam-utils/std", "lazy_static"] [target."cfg(crossbeam_loom)".dependencies.loom-crate] -version = "0.4" +version = "0.5" optional = true package = "loom" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 8961f25..939e346 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -4,7 +4,7 @@ name = "crossbeam-epoch" # - Update CHANGELOG.md # - Update README.md # - Create "crossbeam-epoch-X.Y.Z" git tag -version = "0.9.3" +version = "0.9.5" authors = ["The Crossbeam Project Developers"] edition = "2018" license = "MIT OR Apache-2.0" @@ -24,18 +24,21 @@ std = ["alloc", "crossbeam-utils/std", "lazy_static"] # Enable to use APIs that require `alloc`. # This is enabled by default and also enabled if the `std` feature is enabled. +# +# NOTE: Disabling both `std` *and* `alloc` features is not supported yet. alloc = [] # Enable to use of unstable functionality. # This is disabled by default and requires recent nightly compiler. -# Note that this is outside of the normal semver guarantees and minor versions -# of crossbeam may make breaking changes to them at any time. +# +# NOTE: This feature is outside of the normal semver guarantees and minor or +# patch versions of crossbeam may make breaking changes to them at any time. nightly = ["crossbeam-utils/nightly", "const_fn"] # Enable the use of loom for concurrency testing. # -# This configuration option is outside of the normal semver guarantees: minor -# versions of crossbeam may make breaking changes to it at any time. +# NOTE: This feature is outside of the normal semver guarantees and minor or +# patch versions of crossbeam may make breaking changes to them at any time. loom = ["loom-crate", "crossbeam-utils/loom"] [dependencies] @@ -45,13 +48,13 @@ memoffset = "0.6" # Enable the use of loom for concurrency testing. # -# This configuration option is outside of the normal semver guarantees: minor -# versions of crossbeam may make breaking changes to it at any time. +# NOTE: This feature is outside of the normal semver guarantees and minor or +# patch versions of crossbeam may make breaking changes to them at any time. [target.'cfg(crossbeam_loom)'.dependencies] -loom-crate = { package = "loom", version = "0.4", optional = true } +loom-crate = { package = "loom", version = "0.5", optional = true } [dependencies.crossbeam-utils] -version = "0.8.3" +version = "0.8.5" path = "../crossbeam-utils" default-features = false @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/crossbeam-epoch/crossbeam-epoch-0.9.3.crate" + value: "https://static.crates.io/crates/crossbeam-epoch/crossbeam-epoch-0.9.5.crate" } - version: "0.9.3" + version: "0.9.5" license_type: NOTICE last_upgrade_date { year: 2021 - month: 4 - day: 1 + month: 6 + day: 21 } } @@ -10,7 +10,7 @@ https://crates.io/crates/crossbeam-epoch) https://docs.rs/crossbeam-epoch) [![Rust 1.36+](https://img.shields.io/badge/rust-1.36+-lightgray.svg)]( https://www.rust-lang.org) -[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.gg/BBYwKq) +[![chat](https://img.shields.io/discord/569610676205781012.svg?logo=discord)](https://discord.com/invite/JXYwgWZ) This crate provides epoch-based garbage collection for building concurrent data structures. diff --git a/TEST_MAPPING b/TEST_MAPPING index 25a9cdc..161921c 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -1,8 +1,30 @@ // Generated by update_crate_tests.py for tests that depend on this crate. { + "imports": [ + { + "path": "external/rust/crates/base64" + }, + { + "path": "external/rust/crates/crossbeam-deque" + }, + { + "path": "external/rust/crates/tinytemplate" + }, + { + "path": "external/rust/crates/tinyvec" + }, + { + "path": "external/rust/crates/unicode-xid" + } + ], "presubmit": [ { - "name": "crossbeam-epoch_device_test_src_lib" + "name": "crossbeam-epoch_test_src_lib" + } + ], + "presubmit-rust": [ + { + "name": "crossbeam-epoch_test_src_lib" } ] } diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..4ef1279 --- /dev/null +++ b/build.rs @@ -0,0 +1,32 @@ +#![warn(rust_2018_idioms)] + +use std::env; + +include!("no_atomic.rs"); + +// The rustc-cfg strings below are *not* public API. Please let us know by +// opening a GitHub issue if your build environment requires some way to enable +// these cfgs other than by executing our build script. +fn main() { + let target = match env::var("TARGET") { + Ok(target) => target, + Err(e) => { + println!( + "cargo:warning={}: unable to get TARGET environment variable: {}", + env!("CARGO_PKG_NAME"), + e + ); + return; + } + }; + + // Note that this is `no_*`, not `has_*`. This allows treating + // `cfg(target_has_atomic = "ptr")` as true when the build script doesn't + // run. This is needed for compatibility with non-cargo build systems that + // don't run the build script. + if NO_ATOMIC_CAS.contains(&&*target) { + println!("cargo:rustc-cfg=crossbeam_no_atomic_cas"); + } + + println!("cargo:rerun-if-changed=no_atomic.rs"); +} diff --git a/cargo2android.json b/cargo2android.json new file mode 100644 index 0000000..d36fb44 --- /dev/null +++ b/cargo2android.json @@ -0,0 +1,5 @@ +{ + "device": true, + "run": true, + "tests": true +}
\ No newline at end of file diff --git a/no_atomic.rs b/no_atomic.rs new file mode 100644 index 0000000..522b3b8 --- /dev/null +++ b/no_atomic.rs @@ -0,0 +1,59 @@ +// This file is @generated by no_atomic.sh. +// It is not intended for manual editing. + +const NO_ATOMIC_CAS: &[&str] = &[ + "avr-unknown-gnu-atmega328", + "msp430-none-elf", + "riscv32i-unknown-none-elf", + "riscv32imc-unknown-none-elf", + "thumbv4t-none-eabi", + "thumbv6m-none-eabi", +]; +#[allow(dead_code)] +const NO_ATOMIC_64: &[&str] = &[ + "arm-linux-androideabi", + "armebv7r-none-eabi", + "armebv7r-none-eabihf", + "armv4t-unknown-linux-gnueabi", + "armv5te-unknown-linux-gnueabi", + "armv5te-unknown-linux-musleabi", + "armv5te-unknown-linux-uclibceabi", + "armv7r-none-eabi", + "armv7r-none-eabihf", + "hexagon-unknown-linux-musl", + "mips-unknown-linux-gnu", + "mips-unknown-linux-musl", + "mips-unknown-linux-uclibc", + "mipsel-unknown-linux-gnu", + "mipsel-unknown-linux-musl", + "mipsel-unknown-linux-uclibc", + "mipsel-unknown-none", + "mipsisa32r6-unknown-linux-gnu", + "mipsisa32r6el-unknown-linux-gnu", + "powerpc-unknown-linux-gnu", + "powerpc-unknown-linux-gnuspe", + "powerpc-unknown-linux-musl", + "powerpc-unknown-netbsd", + "powerpc-unknown-openbsd", + "powerpc-wrs-vxworks", + "powerpc-wrs-vxworks-spe", + "riscv32gc-unknown-linux-gnu", + "riscv32gc-unknown-linux-musl", + "riscv32imac-unknown-none-elf", + "thumbv7em-none-eabi", + "thumbv7em-none-eabihf", + "thumbv7m-none-eabi", + "thumbv8m.base-none-eabi", + "thumbv8m.main-none-eabi", + "thumbv8m.main-none-eabihf", + "mipsel-sony-psp", + "thumbv4t-none-eabi", + "thumbv6m-none-eabi", +]; +#[allow(dead_code)] +const NO_ATOMIC: &[&str] = &[ + "avr-unknown-gnu-atmega328", + "msp430-none-elf", + "riscv32i-unknown-none-elf", + "riscv32imc-unknown-none-elf", +]; diff --git a/src/atomic.rs b/src/atomic.rs index e4ca23f..adb0afa 100644 --- a/src/atomic.rs +++ b/src/atomic.rs @@ -238,7 +238,8 @@ impl<T> Pointable for T { // [`alloc::alloc::Layout::extend`] instead. #[repr(C)] struct Array<T> { - size: usize, + /// The number of elements (not the number of bytes). + len: usize, elements: [MaybeUninit<T>; 0], } @@ -247,28 +248,31 @@ impl<T> Pointable for [MaybeUninit<T>] { type Init = usize; - unsafe fn init(size: Self::Init) -> usize { - let size = mem::size_of::<Array<T>>() + mem::size_of::<MaybeUninit<T>>() * size; + unsafe fn init(len: Self::Init) -> usize { + let size = mem::size_of::<Array<T>>() + mem::size_of::<MaybeUninit<T>>() * len; let align = mem::align_of::<Array<T>>(); let layout = alloc::Layout::from_size_align(size, align).unwrap(); let ptr = alloc::alloc(layout) as *mut Array<T>; - (*ptr).size = size; + if ptr.is_null() { + alloc::handle_alloc_error(layout); + } + (*ptr).len = len; ptr as usize } unsafe fn deref<'a>(ptr: usize) -> &'a Self { let array = &*(ptr as *const Array<T>); - slice::from_raw_parts(array.elements.as_ptr() as *const _, array.size) + slice::from_raw_parts(array.elements.as_ptr() as *const _, array.len) } unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut Self { let array = &*(ptr as *mut Array<T>); - slice::from_raw_parts_mut(array.elements.as_ptr() as *mut _, array.size) + slice::from_raw_parts_mut(array.elements.as_ptr() as *mut _, array.len) } unsafe fn drop(ptr: usize) { let array = &*(ptr as *mut Array<T>); - let size = mem::size_of::<Array<T>>() + mem::size_of::<MaybeUninit<T>>() * array.size; + let size = mem::size_of::<Array<T>>() + mem::size_of::<MaybeUninit<T>>() * array.len; let align = mem::align_of::<Array<T>>(); let layout = alloc::Layout::from_size_align(size, align).unwrap(); alloc::dealloc(ptr as *mut u8, layout); @@ -1526,7 +1530,8 @@ impl<T: ?Sized + Pointable> Default for Shared<'_, T> { #[cfg(all(test, not(crossbeam_loom)))] mod tests { - use super::Shared; + use super::{Owned, Shared}; + use std::mem::MaybeUninit; #[test] fn valid_tag_i8() { @@ -1542,6 +1547,13 @@ mod tests { #[test] fn const_atomic_null() { use super::Atomic; - const _: Atomic<u8> = Atomic::<u8>::null(); + static _U: Atomic<u8> = Atomic::<u8>::null(); + } + + #[test] + fn array_init() { + let owned = Owned::<[MaybeUninit<usize>]>::init(10); + let arr: &[MaybeUninit<usize>] = &*owned; + assert_eq!(arr.len(), 10); } } @@ -62,8 +62,7 @@ unreachable_pub )] #![cfg_attr(not(feature = "std"), no_std)] -#![cfg_attr(feature = "nightly", feature(cfg_target_has_atomic))] -#![cfg_attr(feature = "nightly", feature(const_fn))] +#![cfg_attr(feature = "nightly", feature(const_fn_trait_bound))] #[cfg(crossbeam_loom)] extern crate loom_crate as loom; @@ -105,10 +104,11 @@ mod primitive { pub(crate) use loom::lazy_static; pub(crate) use loom::thread_local; } +#[cfg(not(crossbeam_no_atomic_cas))] #[cfg(not(crossbeam_loom))] #[allow(unused_imports, dead_code)] mod primitive { - #[cfg(any(feature = "alloc", feature = "std"))] + #[cfg(feature = "alloc")] pub(crate) mod cell { #[derive(Debug)] #[repr(transparent)] @@ -136,14 +136,13 @@ mod primitive { } } } - #[cfg(any(feature = "alloc", feature = "std"))] + #[cfg(feature = "alloc")] pub(crate) mod sync { pub(crate) mod atomic { pub(crate) use core::sync::atomic::compiler_fence; pub(crate) use core::sync::atomic::fence; pub(crate) use core::sync::atomic::AtomicUsize; } - #[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))] pub(crate) use alloc::sync::Arc; } @@ -154,7 +153,7 @@ mod primitive { pub(crate) use lazy_static::lazy_static; } -#[cfg_attr(feature = "nightly", cfg(target_has_atomic = "ptr"))] +#[cfg(not(crossbeam_no_atomic_cas))] cfg_if! { if #[cfg(feature = "alloc")] { extern crate alloc; |