From 16f3044f9a51cde623c403db422d71f0bc7eeea7 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Sun, 15 Apr 2018 14:37:48 +0200 Subject: [PATCH 1/4] fix undefined behavior in packed structs --- mach-test/build.rs | 19 ++----------------- src/lib.rs | 1 + src/task_info.rs | 4 +--- src/vm_region.rs | 16 ++++------------ 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/mach-test/build.rs b/mach-test/build.rs index 702f2c9..6031898 100644 --- a/mach-test/build.rs +++ b/mach-test/build.rs @@ -141,15 +141,7 @@ fn main() { // FIXME: this type is not exposed in /usr/include/mach // but seems to be exposed in // SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/mach - "ipc_port" | - - // FIXME: should use repr(packed(4)) - "task_dyld_info" | - "vm_region_basic_info_64" | - "vm_region_submap_info_64" | - "vm_region_submap_short_info_64" | - "mach_vm_read_entry" - => true, + "ipc_port" => true, // These are not available in previous MacOSX versions: "dyld_kernel_image_info" | @@ -166,14 +158,7 @@ fn main() { // FIXME: this type is not exposed in /usr/include/mach // but seems to be exposed in // SDKs/MacOSX.sdk/System/Library/Frameworks/Kernel.framework/Versions/A/Headers/mach - "ipc_port_t" | - - // FIXME: corresponding struct should use repr(packed(4)) - "vm_region_basic_info_data_64_t" | - "vm_region_submap_info_data_64_t"| - "vm_region_submap_short_info_data_64_t" | - "mach_vm_read_entry_t" - => true, + "ipc_port_t" => true, // These are not available in previous MacOSX versions "dyld_kernel_image_info_t" | diff --git a/src/lib.rs b/src/lib.rs index 1d40204..4e73fb4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(repr_packed)] #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] diff --git a/src/task_info.rs b/src/task_info.rs index f68d84b..7004ccf 100644 --- a/src/task_info.rs +++ b/src/task_info.rs @@ -34,9 +34,7 @@ pub const TASK_DEBUG_INFO_INTERNAL: ::libc::c_uint = 29; pub type task_flavor_t = natural_t; pub type task_info_t = *mut integer_t; -#[repr(C)] -// Undefined behavior: should be #[repr(packed(4))] once -// that is stable: https://github.com/rust-lang/rust/issues/33158 +#[repr(C, packed(4))] pub struct task_dyld_info { pub all_image_info_addr: mach_vm_address_t, pub all_image_info_size: mach_vm_size_t, diff --git a/src/vm_region.rs b/src/vm_region.rs index 15c3682..df35491 100644 --- a/src/vm_region.rs +++ b/src/vm_region.rs @@ -56,10 +56,8 @@ pub const SM_TRUESHARED: ::libc::c_uchar = 5; pub const SM_PRIVATE_ALIASED: ::libc::c_uchar = 6; pub const SM_SHARED_ALIASED: ::libc::c_uchar = 7; -#[repr(C)] +#[repr(C, packed(4))] #[derive(Copy, Clone, Debug)] -// Undefined behavior: should be #[repr(packed(4))] once -// that is stable: https://github.com/rust-lang/rust/issues/33158 pub struct vm_region_basic_info_64 { pub protection: vm_prot_t, pub max_protection: vm_prot_t, @@ -162,10 +160,8 @@ impl vm_region_submap_info { } } -#[repr(C)] +#[repr(C, packed(4))] #[derive(Copy, Clone, Debug)] -// Undefined behavior: should be #[repr(packed(4))] once -// that is stable: https://github.com/rust-lang/rust/issues/33158 pub struct vm_region_submap_info_64 { pub protection: vm_prot_t, pub max_protection: vm_prot_t, @@ -193,10 +189,8 @@ impl vm_region_submap_info_64 { } } -#[repr(C)] +#[repr(C, packed(4))] #[derive(Copy, Clone, Debug)] -// Undefined behavior: should be #[repr(packed(4))] once -// that is stable: https://github.com/rust-lang/rust/issues/33158 pub struct vm_region_submap_short_info_64 { pub protection: vm_prot_t, pub max_protection: vm_prot_t, @@ -236,10 +230,8 @@ impl vm_page_info_basic { } } -#[repr(C)] +#[repr(C, packed(4))] #[derive(Copy, Clone, Debug)] -// Undefined behavior: should be #[repr(packed(4))] once -// that is stable: https://github.com/rust-lang/rust/issues/33158 pub struct mach_vm_read_entry { pub address: mach_vm_address_t, pub size: mach_vm_size_t, From 961271297bcb0e3f70a8bdf2b1e91537e6d28b12 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Sun, 15 Apr 2018 14:59:03 +0200 Subject: [PATCH 2/4] add unstable feature to opt-in to packed attribute --- Cargo.toml | 2 ++ ci/run.sh | 2 +- mach-test/Cargo.toml | 2 +- src/lib.rs | 2 +- src/task_info.rs | 3 ++- src/vm_region.rs | 12 ++++++++---- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1796df5..cf4eec3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,5 +18,7 @@ default-features = false [features] default = [ "use_std", "deprecated" ] use_std = [ "libc/use_std" ] +# Enables unstable / nightly-only features +unstable = [] # Enables deprecated and removed APIs. deprecated = [] diff --git a/ci/run.sh b/ci/run.sh index 3a4fe9a..51e1cba 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -45,7 +45,7 @@ fi # Runs ctest to verify mach's ABI against the system libraries: if [[ -z "$NOCTEST" ]]; then - if [[ $TRAVIS_RUST_VERSION == "beta" ]] || [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then + if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then cargo test --manifest-path mach-test/Cargo.toml --target $TARGET --verbose cargo test --no-default-features --manifest-path mach-test/Cargo.toml --target $TARGET --verbose fi diff --git a/mach-test/Cargo.toml b/mach-test/Cargo.toml index 15957ad..2834b07 100644 --- a/mach-test/Cargo.toml +++ b/mach-test/Cargo.toml @@ -5,7 +5,7 @@ authors = ["gnzlbg "] build = "build.rs" [dependencies] -mach = { path = ".." } +mach = { path = "..", features = ["unstable"] } libc = "0.2" [build-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 4e73fb4..a9a89fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,8 @@ -#![feature(repr_packed)] #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] #![cfg_attr(not(feature = "use_std"), no_std)] +#![cfg_attr(feature = "unstable", feature(repr_packed))] #[cfg(feature = "use_std")] extern crate core; diff --git a/src/task_info.rs b/src/task_info.rs index 7004ccf..069994e 100644 --- a/src/task_info.rs +++ b/src/task_info.rs @@ -34,7 +34,8 @@ pub const TASK_DEBUG_INFO_INTERNAL: ::libc::c_uint = 29; pub type task_flavor_t = natural_t; pub type task_info_t = *mut integer_t; -#[repr(C, packed(4))] +#[repr(C)] +#[cfg_attr(feature = "unstable", repr(packed(4)))] pub struct task_dyld_info { pub all_image_info_addr: mach_vm_address_t, pub all_image_info_size: mach_vm_size_t, diff --git a/src/vm_region.rs b/src/vm_region.rs index df35491..f64d59c 100644 --- a/src/vm_region.rs +++ b/src/vm_region.rs @@ -56,7 +56,8 @@ pub const SM_TRUESHARED: ::libc::c_uchar = 5; pub const SM_PRIVATE_ALIASED: ::libc::c_uchar = 6; pub const SM_SHARED_ALIASED: ::libc::c_uchar = 7; -#[repr(C, packed(4))] +#[repr(C)] +#[cfg_attr(feature = "unstable", repr(packed(4)))] #[derive(Copy, Clone, Debug)] pub struct vm_region_basic_info_64 { pub protection: vm_prot_t, @@ -160,7 +161,8 @@ impl vm_region_submap_info { } } -#[repr(C, packed(4))] +#[repr(C)] +#[cfg_attr(feature = "unstable", repr(packed(4)))] #[derive(Copy, Clone, Debug)] pub struct vm_region_submap_info_64 { pub protection: vm_prot_t, @@ -189,7 +191,8 @@ impl vm_region_submap_info_64 { } } -#[repr(C, packed(4))] +#[repr(C)] +#[cfg_attr(feature = "unstable", repr(packed(4)))] #[derive(Copy, Clone, Debug)] pub struct vm_region_submap_short_info_64 { pub protection: vm_prot_t, @@ -230,7 +233,8 @@ impl vm_page_info_basic { } } -#[repr(C, packed(4))] +#[repr(C)] +#[cfg_attr(feature = "unstable", repr(packed(4)))] #[derive(Copy, Clone, Debug)] pub struct mach_vm_read_entry { pub address: mach_vm_address_t, From 9811f4dc44b4d516cfa971fd3da7dc86364d084e Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Sun, 15 Apr 2018 19:46:51 +0200 Subject: [PATCH 3/4] bump minimum Rust version to 1.13.0 --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1ee641c..0aa7711 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ matrix: include: # x86_64-apple-darwin - env: TARGET=x86_64-apple-darwin - rust: 1.11.0 + rust: 1.13.0 os: osx osx_image: xcode8.3 - env: TARGET=x86_64-apple-darwin @@ -31,7 +31,7 @@ matrix: # i686-apple-darwin - env: TARGET=i686-apple-darwin - rust: 1.11.0 + rust: 1.13.0 os: osx osx_image: xcode8.3 - env: TARGET=i686-apple-darwin @@ -57,7 +57,7 @@ matrix: # x86_64-apple-ios - env: TARGET=x86_64-apple-ios NORUN=1 - rust: 1.11.0 + rust: 1.13.0 os: osx osx_image: xcode8.3 - env: TARGET=x86_64-apple-ios NORUN=1 @@ -83,7 +83,7 @@ matrix: # i386-apple-ios - env: TARGET=i386-apple-ios NORUN=1 - rust: 1.11.0 + rust: 1.13.0 os: osx osx_image: xcode8.3 - env: TARGET=i386-apple-ios NORUN=1 @@ -109,7 +109,7 @@ matrix: # aarch64-apple-ios - env: TARGET=aarch64-apple-ios NORUN=1 NOCTEST=1 - rust: 1.11.0 + rust: 1.13.0 os: osx osx_image: xcode8.3 - env: TARGET=aarch64-apple-ios NORUN=1 NOCTEST=1 @@ -135,7 +135,7 @@ matrix: # armv7-apple-ios - env: TARGET=armv7-apple-ios NORUN=1 NOCTEST=1 - rust: 1.11.0 + rust: 1.13.0 os: osx osx_image: xcode8.3 - env: TARGET=armv7-apple-ios NORUN=1 NOCTEST=1 From ea395e0632ba6ed446ffa4bc21963863c4528789 Mon Sep 17 00:00:00 2001 From: gnzlbg Date: Fri, 20 Apr 2018 11:24:04 +0200 Subject: [PATCH 4/4] bump mach version to 0.2 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index cf4eec3..475d01f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "mach" -version = "0.1.2" +version = "0.2.0" authors = ["Nick Fitzgerald ", "David Cuddeback "] license = "BSD-2-Clause"