Fixes to make crate safe to migrate.
* Don't compile the C code in build.rs, because it pollutes the out
directory and we have a custom build rule to do it. Add a
corresponding patch.
* Add Android.bp.patch to include the custom build rule.
* Move src/out to out
Bug: http://b/339424309
Test: treehugger
Change-Id: I3dbc267dc1bf169e4dcde71e1cc52c30ef752088
diff --git a/Android.bp b/Android.bp
index 6490bdc..bb42191 100644
--- a/Android.bp
+++ b/Android.bp
@@ -3,6 +3,7 @@
package {
default_applicable_licenses: ["external_rust_crates_userfaultfd-sys_license"],
+ default_team: "trendy_team_android_rust",
}
license {
@@ -12,6 +13,13 @@
license_text: ["LICENSE"],
}
+genrule {
+ name: "copy_userfaultfd-sys_build_out",
+ srcs: ["out/*"],
+ cmd: "cp $(in) $(genDir)",
+ out: ["bindings.rs"],
+}
+
rust_library {
name: "libuserfaultfd_sys",
host_supported: true,
@@ -19,6 +27,7 @@
cargo_env_compat: true,
cargo_pkg_version: "0.5.0",
crate_root: "src/lib.rs",
+ srcs: [":copy_userfaultfd-sys_build_out"],
edition: "2018",
features: ["default"],
rustlibs: ["libcfg_if"],
diff --git a/build.rs b/build.rs
index af7cda6..c18bb2e 100644
--- a/build.rs
+++ b/build.rs
@@ -6,10 +6,6 @@
fn main() {
generate_bindings();
-
- cc::Build::new()
- .file("src/consts.c")
- .compile("userfaultfd_sys_consts");
}
fn generate_bindings() {
diff --git a/cargo_embargo.json b/cargo_embargo.json
index a4735c2..0686456 100644
--- a/cargo_embargo.json
+++ b/cargo_embargo.json
@@ -1,7 +1,9 @@
{
"package": {
"userfaultfd-sys": {
- "add_toplevel_block": "cargo2android_consts.bp"
+ "add_toplevel_block": "cargo2android_consts.bp",
+ "copy_out": true,
+ "patch": "patches/Android.bp.patch"
}
}
}
diff --git a/src/out/bindings.rs b/out/bindings.rs
similarity index 88%
rename from src/out/bindings.rs
rename to out/bindings.rs
index cff34be..2c559b8 100644
--- a/src/out/bindings.rs
+++ b/out/bindings.rs
@@ -1,13 +1,16 @@
/* automatically generated by rust-bindgen 0.68.1 */
+pub const __BITS_PER_LONG_LONG: u32 = 64;
pub const USERFAULTFD_IOC: u32 = 170;
pub const _UFFDIO_REGISTER: u64 = 0;
pub const _UFFDIO_UNREGISTER: u64 = 1;
pub const _UFFDIO_WAKE: u64 = 2;
pub const _UFFDIO_COPY: u64 = 3;
pub const _UFFDIO_ZEROPAGE: u64 = 4;
+pub const _UFFDIO_MOVE: u64 = 5;
pub const _UFFDIO_WRITEPROTECT: u64 = 6;
pub const _UFFDIO_CONTINUE: u64 = 7;
+pub const _UFFDIO_POISON: u64 = 8;
pub const _UFFDIO_API: u64 = 63;
pub const UFFDIO: u8 = 170;
pub const UFFD_EVENT_PAGEFAULT: u8 = 18;
@@ -32,6 +35,9 @@
pub const UFFD_FEATURE_EXACT_ADDRESS: u64 = 2048;
pub const UFFD_FEATURE_WP_HUGETLBFS_SHMEM: u64 = 4096;
pub const UFFD_FEATURE_WP_UNPOPULATED: u64 = 8192;
+pub const UFFD_FEATURE_POISON: u64 = 16384;
+pub const UFFD_FEATURE_WP_ASYNC: u64 = 32768;
+pub const UFFD_FEATURE_MOVE: u64 = 65536;
pub const UFFD_USER_MODE_ONLY: u32 = 1;
pub type __s8 = ::std::os::raw::c_schar;
pub type __u8 = ::std::os::raw::c_uchar;
@@ -949,3 +955,129 @@
)
);
}
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct uffdio_poison {
+ pub range: uffdio_range,
+ pub mode: __u64,
+ pub updated: __s64,
+}
+#[test]
+fn bindgen_test_layout_uffdio_poison() {
+ const UNINIT: ::std::mem::MaybeUninit<uffdio_poison> = ::std::mem::MaybeUninit::uninit();
+ let ptr = UNINIT.as_ptr();
+ assert_eq!(
+ ::std::mem::size_of::<uffdio_poison>(),
+ 32usize,
+ concat!("Size of: ", stringify!(uffdio_poison))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<uffdio_poison>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(uffdio_poison))
+ );
+ assert_eq!(
+ unsafe { ::std::ptr::addr_of!((*ptr).range) as usize - ptr as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(uffdio_poison),
+ "::",
+ stringify!(range)
+ )
+ );
+ assert_eq!(
+ unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize },
+ 16usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(uffdio_poison),
+ "::",
+ stringify!(mode)
+ )
+ );
+ assert_eq!(
+ unsafe { ::std::ptr::addr_of!((*ptr).updated) as usize - ptr as usize },
+ 24usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(uffdio_poison),
+ "::",
+ stringify!(updated)
+ )
+ );
+}
+#[repr(C)]
+#[derive(Debug, Copy, Clone)]
+pub struct uffdio_move {
+ pub dst: __u64,
+ pub src: __u64,
+ pub len: __u64,
+ pub mode: __u64,
+ pub move_: __s64,
+}
+#[test]
+fn bindgen_test_layout_uffdio_move() {
+ const UNINIT: ::std::mem::MaybeUninit<uffdio_move> = ::std::mem::MaybeUninit::uninit();
+ let ptr = UNINIT.as_ptr();
+ assert_eq!(
+ ::std::mem::size_of::<uffdio_move>(),
+ 40usize,
+ concat!("Size of: ", stringify!(uffdio_move))
+ );
+ assert_eq!(
+ ::std::mem::align_of::<uffdio_move>(),
+ 8usize,
+ concat!("Alignment of ", stringify!(uffdio_move))
+ );
+ assert_eq!(
+ unsafe { ::std::ptr::addr_of!((*ptr).dst) as usize - ptr as usize },
+ 0usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(uffdio_move),
+ "::",
+ stringify!(dst)
+ )
+ );
+ assert_eq!(
+ unsafe { ::std::ptr::addr_of!((*ptr).src) as usize - ptr as usize },
+ 8usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(uffdio_move),
+ "::",
+ stringify!(src)
+ )
+ );
+ assert_eq!(
+ unsafe { ::std::ptr::addr_of!((*ptr).len) as usize - ptr as usize },
+ 16usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(uffdio_move),
+ "::",
+ stringify!(len)
+ )
+ );
+ assert_eq!(
+ unsafe { ::std::ptr::addr_of!((*ptr).mode) as usize - ptr as usize },
+ 24usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(uffdio_move),
+ "::",
+ stringify!(mode)
+ )
+ );
+ assert_eq!(
+ unsafe { ::std::ptr::addr_of!((*ptr).move_) as usize - ptr as usize },
+ 32usize,
+ concat!(
+ "Offset of field: ",
+ stringify!(uffdio_move),
+ "::",
+ stringify!(move_)
+ )
+ );
+}
diff --git a/patches/Android.bp.patch b/patches/Android.bp.patch
new file mode 100644
index 0000000..56bc549
--- /dev/null
+++ b/patches/Android.bp.patch
@@ -0,0 +1,12 @@
+diff --git a/Android.bp b/Android.bp
+index c0a0519..bb42191 100644
+--- a/Android.bp
++++ b/Android.bp
+@@ -31,6 +31,7 @@ rust_library {
+ edition: "2018",
+ features: ["default"],
+ rustlibs: ["libcfg_if"],
++ static_libs: ["libuserfaultfd_sys_consts"],
+ apex_available: [
+ "//apex_available:platform",
+ "//apex_available:anyapex",
diff --git a/patches/dont-compile-userfaultfd_sys_consts.patch b/patches/dont-compile-userfaultfd_sys_consts.patch
new file mode 100644
index 0000000..4178244
--- /dev/null
+++ b/patches/dont-compile-userfaultfd_sys_consts.patch
@@ -0,0 +1,15 @@
+diff --git a/build.rs b/build.rs
+index af7cda6..c18bb2e 100644
+--- a/build.rs
++++ b/build.rs
+@@ -6,10 +6,6 @@ use std::path::PathBuf;
+
+ fn main() {
+ generate_bindings();
+-
+- cc::Build::new()
+- .file("src/consts.c")
+- .compile("userfaultfd_sys_consts");
+ }
+
+ fn generate_bindings() {