From a50b67f17b926d3a75fdc97b469b5b49005c32f1 Mon Sep 17 00:00:00 2001 From: Federico Maria Morrone Date: Sun, 22 Dec 2024 17:57:48 +0100 Subject: [PATCH 1/2] Add arm64 image header bindings --- Cargo.toml | 3 +- gen/modules/image.h | 4 ++ gen/src/main.rs | 8 ++++ src/aarch64/image.rs | 80 ++++++++++++++++++++++++++++++++++++++++ src/arm/image.rs | 3 ++ src/csky/image.rs | 3 ++ src/lib.rs | 72 ++++++++++++++++++++++++++++++++++++ src/loongarch64/image.rs | 3 ++ src/mips/image.rs | 3 ++ src/mips32r6/image.rs | 3 ++ src/mips64/image.rs | 3 ++ src/mips64r6/image.rs | 3 ++ src/powerpc/image.rs | 3 ++ src/powerpc64/image.rs | 3 ++ src/riscv32/image.rs | 3 ++ src/riscv64/image.rs | 3 ++ src/s390x/image.rs | 3 ++ src/sparc/image.rs | 3 ++ src/sparc64/image.rs | 3 ++ src/x32/image.rs | 3 ++ src/x86/image.rs | 3 ++ src/x86_64/image.rs | 3 ++ 22 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 gen/modules/image.h create mode 100644 src/aarch64/image.rs create mode 100644 src/arm/image.rs create mode 100644 src/csky/image.rs create mode 100644 src/loongarch64/image.rs create mode 100644 src/mips/image.rs create mode 100644 src/mips32r6/image.rs create mode 100644 src/mips64/image.rs create mode 100644 src/mips64r6/image.rs create mode 100644 src/powerpc/image.rs create mode 100644 src/powerpc64/image.rs create mode 100644 src/riscv32/image.rs create mode 100644 src/riscv64/image.rs create mode 100644 src/s390x/image.rs create mode 100644 src/sparc/image.rs create mode 100644 src/sparc64/image.rs create mode 100644 src/x32/image.rs create mode 100644 src/x86/image.rs create mode 100644 src/x86_64/image.rs diff --git a/Cargo.toml b/Cargo.toml index 14b73999..08dcb4a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ static_assertions = "1.1.0" libc = "0.2.100" [package.metadata.docs.rs] -features = ["default", "bootparam", "btrfs", "elf_uapi", "ioctl", "landlock", "netlink", "io_uring", "if_arp", "if_ether", "if_packet", "net", "ptrace", "prctl", "elf", "xdp", "mempolicy", "system", "loop_device"] +features = ["default", "bootparam", "btrfs", "elf_uapi", "image", "ioctl", "landlock", "netlink", "io_uring", "if_arp", "if_ether", "if_packet", "net", "ptrace", "prctl", "elf", "xdp", "mempolicy", "system", "loop_device"] targets = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"] [lints.rust.unexpected_cfgs] @@ -40,6 +40,7 @@ general = [] if_arp = [] if_ether = [] if_packet = [] +image = [] io_uring = [] ioctl = [] landlock = [] diff --git a/gen/modules/image.h b/gen/modules/image.h new file mode 100644 index 00000000..79a63013 --- /dev/null +++ b/gen/modules/image.h @@ -0,0 +1,4 @@ +#if defined(__aarch64__) +#include +#include +#endif \ No newline at end of file diff --git a/gen/src/main.rs b/gen/src/main.rs index 78d77c1a..7075def3 100644 --- a/gen/src/main.rs +++ b/gen/src/main.rs @@ -272,6 +272,14 @@ fn make_headers_install(linux_arch: &str, linux_headers: &Path) { .status() .unwrap() .success()); + + if linux_arch == "arm64" { + fs::copy( + "linux/arch/arm64/include/asm/image.h", + linux_headers.join("include/asm/image.h"), + ) + .expect("Missing headers"); + } } fn rust_arches(linux_arch: &str) -> &[&str] { diff --git a/src/aarch64/image.rs b/src/aarch64/image.rs new file mode 100644 index 00000000..4b169d04 --- /dev/null +++ b/src/aarch64/image.rs @@ -0,0 +1,80 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + +pub type __s8 = crate::ctypes::c_schar; +pub type __u8 = crate::ctypes::c_uchar; +pub type __s16 = crate::ctypes::c_short; +pub type __u16 = crate::ctypes::c_ushort; +pub type __s32 = crate::ctypes::c_int; +pub type __u32 = crate::ctypes::c_uint; +pub type __s64 = crate::ctypes::c_longlong; +pub type __u64 = crate::ctypes::c_ulonglong; +pub type __kernel_key_t = crate::ctypes::c_int; +pub type __kernel_mqd_t = crate::ctypes::c_int; +pub type __kernel_old_uid_t = crate::ctypes::c_ushort; +pub type __kernel_old_gid_t = crate::ctypes::c_ushort; +pub type __kernel_long_t = crate::ctypes::c_long; +pub type __kernel_ulong_t = crate::ctypes::c_ulong; +pub type __kernel_ino_t = __kernel_ulong_t; +pub type __kernel_mode_t = crate::ctypes::c_uint; +pub type __kernel_pid_t = crate::ctypes::c_int; +pub type __kernel_ipc_pid_t = crate::ctypes::c_int; +pub type __kernel_uid_t = crate::ctypes::c_uint; +pub type __kernel_gid_t = crate::ctypes::c_uint; +pub type __kernel_suseconds_t = __kernel_long_t; +pub type __kernel_daddr_t = crate::ctypes::c_int; +pub type __kernel_uid32_t = crate::ctypes::c_uint; +pub type __kernel_gid32_t = crate::ctypes::c_uint; +pub type __kernel_old_dev_t = crate::ctypes::c_uint; +pub type __kernel_size_t = __kernel_ulong_t; +pub type __kernel_ssize_t = __kernel_long_t; +pub type __kernel_ptrdiff_t = __kernel_long_t; +pub type __kernel_off_t = __kernel_long_t; +pub type __kernel_loff_t = crate::ctypes::c_longlong; +pub type __kernel_old_time_t = __kernel_long_t; +pub type __kernel_time_t = __kernel_long_t; +pub type __kernel_time64_t = crate::ctypes::c_longlong; +pub type __kernel_clock_t = __kernel_long_t; +pub type __kernel_timer_t = crate::ctypes::c_int; +pub type __kernel_clockid_t = crate::ctypes::c_int; +pub type __kernel_caddr_t = *mut crate::ctypes::c_char; +pub type __kernel_uid16_t = crate::ctypes::c_ushort; +pub type __kernel_gid16_t = crate::ctypes::c_ushort; +pub type __s128 = i128; +pub type __u128 = u128; +pub type __le16 = __u16; +pub type __be16 = __u16; +pub type __le32 = __u32; +pub type __be32 = __u32; +pub type __le64 = __u64; +pub type __be64 = __u64; +pub type __sum16 = __u16; +pub type __wsum = __u32; +pub type __poll_t = crate::ctypes::c_uint; +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct arm64_image_header { +pub code0: __le32, +pub code1: __le32, +pub text_offset: __le64, +pub image_size: __le64, +pub flags: __le64, +pub res2: __le64, +pub res3: __le64, +pub res4: __le64, +pub magic: __le32, +pub res5: __le32, +} +pub const __BITS_PER_LONG_LONG: u32 = 64; +pub const ARM64_IMAGE_MAGIC: &[u8; 5] = b"ARMd\0"; +pub const ARM64_IMAGE_FLAG_BE_SHIFT: u32 = 0; +pub const ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT: u32 = 1; +pub const ARM64_IMAGE_FLAG_PHYS_BASE_SHIFT: u32 = 3; +pub const ARM64_IMAGE_FLAG_BE_MASK: u32 = 1; +pub const ARM64_IMAGE_FLAG_PAGE_SIZE_MASK: u32 = 3; +pub const ARM64_IMAGE_FLAG_PHYS_BASE_MASK: u32 = 1; +pub const ARM64_IMAGE_FLAG_LE: u32 = 0; +pub const ARM64_IMAGE_FLAG_BE: u32 = 1; +pub const ARM64_IMAGE_FLAG_PAGE_SIZE_4K: u32 = 1; +pub const ARM64_IMAGE_FLAG_PAGE_SIZE_16K: u32 = 2; +pub const ARM64_IMAGE_FLAG_PAGE_SIZE_64K: u32 = 3; +pub const ARM64_IMAGE_FLAG_PHYS_BASE: u32 = 1; diff --git a/src/arm/image.rs b/src/arm/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/arm/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/csky/image.rs b/src/csky/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/csky/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/lib.rs b/src/lib.rs index 97c4753d..66128f55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -241,6 +241,10 @@ pub mod if_ether; #[cfg(target_arch = "arm")] #[path = "arm/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "arm")] +#[path = "arm/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "arm")] #[path = "arm/io_uring.rs"] @@ -317,6 +321,10 @@ pub mod if_ether; #[cfg(target_arch = "aarch64")] #[path = "aarch64/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "aarch64")] +#[path = "aarch64/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "aarch64")] #[path = "aarch64/io_uring.rs"] @@ -393,6 +401,10 @@ pub mod if_ether; #[cfg(target_arch = "csky")] #[path = "csky/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "csky")] +#[path = "csky/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "csky")] #[path = "csky/io_uring.rs"] @@ -469,6 +481,10 @@ pub mod if_ether; #[cfg(target_arch = "loongarch64")] #[path = "loongarch64/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "loongarch64")] +#[path = "loongarch64/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "loongarch64")] #[path = "loongarch64/io_uring.rs"] @@ -545,6 +561,10 @@ pub mod if_ether; #[cfg(target_arch = "mips")] #[path = "mips/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "mips")] +#[path = "mips/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "mips")] #[path = "mips/io_uring.rs"] @@ -621,6 +641,10 @@ pub mod if_ether; #[cfg(target_arch = "mips64")] #[path = "mips64/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "mips64")] +#[path = "mips64/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "mips64")] #[path = "mips64/io_uring.rs"] @@ -697,6 +721,10 @@ pub mod if_ether; #[cfg(target_arch = "mips32r6")] #[path = "mips32r6/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "mips32r6")] +#[path = "mips32r6/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "mips32r6")] #[path = "mips32r6/io_uring.rs"] @@ -773,6 +801,10 @@ pub mod if_ether; #[cfg(target_arch = "mips64r6")] #[path = "mips64r6/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "mips64r6")] +#[path = "mips64r6/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "mips64r6")] #[path = "mips64r6/io_uring.rs"] @@ -849,6 +881,10 @@ pub mod if_ether; #[cfg(target_arch = "powerpc")] #[path = "powerpc/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "powerpc")] +#[path = "powerpc/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "powerpc")] #[path = "powerpc/io_uring.rs"] @@ -925,6 +961,10 @@ pub mod if_ether; #[cfg(target_arch = "powerpc64")] #[path = "powerpc64/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "powerpc64")] +#[path = "powerpc64/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "powerpc64")] #[path = "powerpc64/io_uring.rs"] @@ -1001,6 +1041,10 @@ pub mod if_ether; #[cfg(target_arch = "riscv32")] #[path = "riscv32/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "riscv32")] +#[path = "riscv32/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "riscv32")] #[path = "riscv32/io_uring.rs"] @@ -1077,6 +1121,10 @@ pub mod if_ether; #[cfg(target_arch = "riscv64")] #[path = "riscv64/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "riscv64")] +#[path = "riscv64/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "riscv64")] #[path = "riscv64/io_uring.rs"] @@ -1153,6 +1201,10 @@ pub mod if_ether; #[cfg(target_arch = "s390x")] #[path = "s390x/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "s390x")] +#[path = "s390x/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "s390x")] #[path = "s390x/io_uring.rs"] @@ -1229,6 +1281,10 @@ pub mod if_ether; #[cfg(target_arch = "sparc")] #[path = "sparc/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "sparc")] +#[path = "sparc/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "sparc")] #[path = "sparc/io_uring.rs"] @@ -1305,6 +1361,10 @@ pub mod if_ether; #[cfg(target_arch = "sparc64")] #[path = "sparc64/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "sparc64")] +#[path = "sparc64/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "sparc64")] #[path = "sparc64/io_uring.rs"] @@ -1381,6 +1441,10 @@ pub mod if_ether; #[cfg(target_arch = "x86")] #[path = "x86/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(target_arch = "x86")] +#[path = "x86/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(target_arch = "x86")] #[path = "x86/io_uring.rs"] @@ -1457,6 +1521,10 @@ pub mod if_ether; #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] #[path = "x86_64/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] +#[path = "x86_64/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] #[path = "x86_64/io_uring.rs"] @@ -1533,6 +1601,10 @@ pub mod if_ether; #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] #[path = "x32/if_packet.rs"] pub mod if_packet; +#[cfg(feature = "image")] +#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] +#[path = "x32/image.rs"] +pub mod image; #[cfg(feature = "io_uring")] #[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))] #[path = "x32/io_uring.rs"] diff --git a/src/loongarch64/image.rs b/src/loongarch64/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/loongarch64/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/mips/image.rs b/src/mips/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/mips/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/mips32r6/image.rs b/src/mips32r6/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/mips32r6/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/mips64/image.rs b/src/mips64/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/mips64/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/mips64r6/image.rs b/src/mips64r6/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/mips64r6/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/powerpc/image.rs b/src/powerpc/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/powerpc/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/powerpc64/image.rs b/src/powerpc64/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/powerpc64/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/riscv32/image.rs b/src/riscv32/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/riscv32/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/riscv64/image.rs b/src/riscv64/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/riscv64/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/s390x/image.rs b/src/s390x/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/s390x/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/sparc/image.rs b/src/sparc/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/sparc/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/sparc64/image.rs b/src/sparc64/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/sparc64/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/x32/image.rs b/src/x32/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/x32/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/x86/image.rs b/src/x86/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/x86/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + diff --git a/src/x86_64/image.rs b/src/x86_64/image.rs new file mode 100644 index 00000000..4f4f6fab --- /dev/null +++ b/src/x86_64/image.rs @@ -0,0 +1,3 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + + From 3848eb92996db0c5effe4720b841ead138e0db5a Mon Sep 17 00:00:00 2001 From: Federico Maria Morrone Date: Sun, 22 Dec 2024 18:00:33 +0100 Subject: [PATCH 2/2] Add comment about missing image header --- gen/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/gen/src/main.rs b/gen/src/main.rs index 7075def3..cd8bed1e 100644 --- a/gen/src/main.rs +++ b/gen/src/main.rs @@ -273,6 +273,7 @@ fn make_headers_install(linux_arch: &str, linux_headers: &Path) { .unwrap() .success()); + // HACK: Header missing from kernel installation - likely an upstream bug that needs to be reported if linux_arch == "arm64" { fs::copy( "linux/arch/arm64/include/asm/image.h",