Skip to content

Commit 7ffc240

Browse files
authored
Add arm64 image header bindings (#118)
* Add arm64 image header bindings * Add comment about missing image header
1 parent cba1a84 commit 7ffc240

File tree

22 files changed

+218
-1
lines changed

22 files changed

+218
-1
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static_assertions = "1.1.0"
2121
libc = "0.2.100"
2222

2323
[package.metadata.docs.rs]
24-
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"]
24+
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"]
2525
targets = ["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"]
2626

2727
[lints.rust.unexpected_cfgs]
@@ -40,6 +40,7 @@ general = []
4040
if_arp = []
4141
if_ether = []
4242
if_packet = []
43+
image = []
4344
io_uring = []
4445
ioctl = []
4546
landlock = []

gen/modules/image.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#if defined(__aarch64__)
2+
#include <linux/types.h>
3+
#include <asm/image.h>
4+
#endif

gen/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ fn make_headers_install(linux_arch: &str, linux_headers: &Path) {
272272
.status()
273273
.unwrap()
274274
.success());
275+
276+
// HACK: Header missing from kernel installation - likely an upstream bug that needs to be reported
277+
if linux_arch == "arm64" {
278+
fs::copy(
279+
"linux/arch/arm64/include/asm/image.h",
280+
linux_headers.join("include/asm/image.h"),
281+
)
282+
.expect("Missing headers");
283+
}
275284
}
276285

277286
fn rust_arches(linux_arch: &str) -> &[&str] {

src/aarch64/image.rs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* automatically generated by rust-bindgen 0.70.1 */
2+
3+
pub type __s8 = crate::ctypes::c_schar;
4+
pub type __u8 = crate::ctypes::c_uchar;
5+
pub type __s16 = crate::ctypes::c_short;
6+
pub type __u16 = crate::ctypes::c_ushort;
7+
pub type __s32 = crate::ctypes::c_int;
8+
pub type __u32 = crate::ctypes::c_uint;
9+
pub type __s64 = crate::ctypes::c_longlong;
10+
pub type __u64 = crate::ctypes::c_ulonglong;
11+
pub type __kernel_key_t = crate::ctypes::c_int;
12+
pub type __kernel_mqd_t = crate::ctypes::c_int;
13+
pub type __kernel_old_uid_t = crate::ctypes::c_ushort;
14+
pub type __kernel_old_gid_t = crate::ctypes::c_ushort;
15+
pub type __kernel_long_t = crate::ctypes::c_long;
16+
pub type __kernel_ulong_t = crate::ctypes::c_ulong;
17+
pub type __kernel_ino_t = __kernel_ulong_t;
18+
pub type __kernel_mode_t = crate::ctypes::c_uint;
19+
pub type __kernel_pid_t = crate::ctypes::c_int;
20+
pub type __kernel_ipc_pid_t = crate::ctypes::c_int;
21+
pub type __kernel_uid_t = crate::ctypes::c_uint;
22+
pub type __kernel_gid_t = crate::ctypes::c_uint;
23+
pub type __kernel_suseconds_t = __kernel_long_t;
24+
pub type __kernel_daddr_t = crate::ctypes::c_int;
25+
pub type __kernel_uid32_t = crate::ctypes::c_uint;
26+
pub type __kernel_gid32_t = crate::ctypes::c_uint;
27+
pub type __kernel_old_dev_t = crate::ctypes::c_uint;
28+
pub type __kernel_size_t = __kernel_ulong_t;
29+
pub type __kernel_ssize_t = __kernel_long_t;
30+
pub type __kernel_ptrdiff_t = __kernel_long_t;
31+
pub type __kernel_off_t = __kernel_long_t;
32+
pub type __kernel_loff_t = crate::ctypes::c_longlong;
33+
pub type __kernel_old_time_t = __kernel_long_t;
34+
pub type __kernel_time_t = __kernel_long_t;
35+
pub type __kernel_time64_t = crate::ctypes::c_longlong;
36+
pub type __kernel_clock_t = __kernel_long_t;
37+
pub type __kernel_timer_t = crate::ctypes::c_int;
38+
pub type __kernel_clockid_t = crate::ctypes::c_int;
39+
pub type __kernel_caddr_t = *mut crate::ctypes::c_char;
40+
pub type __kernel_uid16_t = crate::ctypes::c_ushort;
41+
pub type __kernel_gid16_t = crate::ctypes::c_ushort;
42+
pub type __s128 = i128;
43+
pub type __u128 = u128;
44+
pub type __le16 = __u16;
45+
pub type __be16 = __u16;
46+
pub type __le32 = __u32;
47+
pub type __be32 = __u32;
48+
pub type __le64 = __u64;
49+
pub type __be64 = __u64;
50+
pub type __sum16 = __u16;
51+
pub type __wsum = __u32;
52+
pub type __poll_t = crate::ctypes::c_uint;
53+
#[repr(C)]
54+
#[derive(Debug, Copy, Clone)]
55+
pub struct arm64_image_header {
56+
pub code0: __le32,
57+
pub code1: __le32,
58+
pub text_offset: __le64,
59+
pub image_size: __le64,
60+
pub flags: __le64,
61+
pub res2: __le64,
62+
pub res3: __le64,
63+
pub res4: __le64,
64+
pub magic: __le32,
65+
pub res5: __le32,
66+
}
67+
pub const __BITS_PER_LONG_LONG: u32 = 64;
68+
pub const ARM64_IMAGE_MAGIC: &[u8; 5] = b"ARMd\0";
69+
pub const ARM64_IMAGE_FLAG_BE_SHIFT: u32 = 0;
70+
pub const ARM64_IMAGE_FLAG_PAGE_SIZE_SHIFT: u32 = 1;
71+
pub const ARM64_IMAGE_FLAG_PHYS_BASE_SHIFT: u32 = 3;
72+
pub const ARM64_IMAGE_FLAG_BE_MASK: u32 = 1;
73+
pub const ARM64_IMAGE_FLAG_PAGE_SIZE_MASK: u32 = 3;
74+
pub const ARM64_IMAGE_FLAG_PHYS_BASE_MASK: u32 = 1;
75+
pub const ARM64_IMAGE_FLAG_LE: u32 = 0;
76+
pub const ARM64_IMAGE_FLAG_BE: u32 = 1;
77+
pub const ARM64_IMAGE_FLAG_PAGE_SIZE_4K: u32 = 1;
78+
pub const ARM64_IMAGE_FLAG_PAGE_SIZE_16K: u32 = 2;
79+
pub const ARM64_IMAGE_FLAG_PAGE_SIZE_64K: u32 = 3;
80+
pub const ARM64_IMAGE_FLAG_PHYS_BASE: u32 = 1;

src/arm/image.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* automatically generated by rust-bindgen 0.70.1 */
2+
3+

src/csky/image.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* automatically generated by rust-bindgen 0.70.1 */
2+
3+

src/lib.rs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ pub mod if_ether;
241241
#[cfg(target_arch = "arm")]
242242
#[path = "arm/if_packet.rs"]
243243
pub mod if_packet;
244+
#[cfg(feature = "image")]
245+
#[cfg(target_arch = "arm")]
246+
#[path = "arm/image.rs"]
247+
pub mod image;
244248
#[cfg(feature = "io_uring")]
245249
#[cfg(target_arch = "arm")]
246250
#[path = "arm/io_uring.rs"]
@@ -317,6 +321,10 @@ pub mod if_ether;
317321
#[cfg(target_arch = "aarch64")]
318322
#[path = "aarch64/if_packet.rs"]
319323
pub mod if_packet;
324+
#[cfg(feature = "image")]
325+
#[cfg(target_arch = "aarch64")]
326+
#[path = "aarch64/image.rs"]
327+
pub mod image;
320328
#[cfg(feature = "io_uring")]
321329
#[cfg(target_arch = "aarch64")]
322330
#[path = "aarch64/io_uring.rs"]
@@ -393,6 +401,10 @@ pub mod if_ether;
393401
#[cfg(target_arch = "csky")]
394402
#[path = "csky/if_packet.rs"]
395403
pub mod if_packet;
404+
#[cfg(feature = "image")]
405+
#[cfg(target_arch = "csky")]
406+
#[path = "csky/image.rs"]
407+
pub mod image;
396408
#[cfg(feature = "io_uring")]
397409
#[cfg(target_arch = "csky")]
398410
#[path = "csky/io_uring.rs"]
@@ -469,6 +481,10 @@ pub mod if_ether;
469481
#[cfg(target_arch = "loongarch64")]
470482
#[path = "loongarch64/if_packet.rs"]
471483
pub mod if_packet;
484+
#[cfg(feature = "image")]
485+
#[cfg(target_arch = "loongarch64")]
486+
#[path = "loongarch64/image.rs"]
487+
pub mod image;
472488
#[cfg(feature = "io_uring")]
473489
#[cfg(target_arch = "loongarch64")]
474490
#[path = "loongarch64/io_uring.rs"]
@@ -545,6 +561,10 @@ pub mod if_ether;
545561
#[cfg(target_arch = "mips")]
546562
#[path = "mips/if_packet.rs"]
547563
pub mod if_packet;
564+
#[cfg(feature = "image")]
565+
#[cfg(target_arch = "mips")]
566+
#[path = "mips/image.rs"]
567+
pub mod image;
548568
#[cfg(feature = "io_uring")]
549569
#[cfg(target_arch = "mips")]
550570
#[path = "mips/io_uring.rs"]
@@ -621,6 +641,10 @@ pub mod if_ether;
621641
#[cfg(target_arch = "mips64")]
622642
#[path = "mips64/if_packet.rs"]
623643
pub mod if_packet;
644+
#[cfg(feature = "image")]
645+
#[cfg(target_arch = "mips64")]
646+
#[path = "mips64/image.rs"]
647+
pub mod image;
624648
#[cfg(feature = "io_uring")]
625649
#[cfg(target_arch = "mips64")]
626650
#[path = "mips64/io_uring.rs"]
@@ -697,6 +721,10 @@ pub mod if_ether;
697721
#[cfg(target_arch = "mips32r6")]
698722
#[path = "mips32r6/if_packet.rs"]
699723
pub mod if_packet;
724+
#[cfg(feature = "image")]
725+
#[cfg(target_arch = "mips32r6")]
726+
#[path = "mips32r6/image.rs"]
727+
pub mod image;
700728
#[cfg(feature = "io_uring")]
701729
#[cfg(target_arch = "mips32r6")]
702730
#[path = "mips32r6/io_uring.rs"]
@@ -773,6 +801,10 @@ pub mod if_ether;
773801
#[cfg(target_arch = "mips64r6")]
774802
#[path = "mips64r6/if_packet.rs"]
775803
pub mod if_packet;
804+
#[cfg(feature = "image")]
805+
#[cfg(target_arch = "mips64r6")]
806+
#[path = "mips64r6/image.rs"]
807+
pub mod image;
776808
#[cfg(feature = "io_uring")]
777809
#[cfg(target_arch = "mips64r6")]
778810
#[path = "mips64r6/io_uring.rs"]
@@ -849,6 +881,10 @@ pub mod if_ether;
849881
#[cfg(target_arch = "powerpc")]
850882
#[path = "powerpc/if_packet.rs"]
851883
pub mod if_packet;
884+
#[cfg(feature = "image")]
885+
#[cfg(target_arch = "powerpc")]
886+
#[path = "powerpc/image.rs"]
887+
pub mod image;
852888
#[cfg(feature = "io_uring")]
853889
#[cfg(target_arch = "powerpc")]
854890
#[path = "powerpc/io_uring.rs"]
@@ -925,6 +961,10 @@ pub mod if_ether;
925961
#[cfg(target_arch = "powerpc64")]
926962
#[path = "powerpc64/if_packet.rs"]
927963
pub mod if_packet;
964+
#[cfg(feature = "image")]
965+
#[cfg(target_arch = "powerpc64")]
966+
#[path = "powerpc64/image.rs"]
967+
pub mod image;
928968
#[cfg(feature = "io_uring")]
929969
#[cfg(target_arch = "powerpc64")]
930970
#[path = "powerpc64/io_uring.rs"]
@@ -1001,6 +1041,10 @@ pub mod if_ether;
10011041
#[cfg(target_arch = "riscv32")]
10021042
#[path = "riscv32/if_packet.rs"]
10031043
pub mod if_packet;
1044+
#[cfg(feature = "image")]
1045+
#[cfg(target_arch = "riscv32")]
1046+
#[path = "riscv32/image.rs"]
1047+
pub mod image;
10041048
#[cfg(feature = "io_uring")]
10051049
#[cfg(target_arch = "riscv32")]
10061050
#[path = "riscv32/io_uring.rs"]
@@ -1077,6 +1121,10 @@ pub mod if_ether;
10771121
#[cfg(target_arch = "riscv64")]
10781122
#[path = "riscv64/if_packet.rs"]
10791123
pub mod if_packet;
1124+
#[cfg(feature = "image")]
1125+
#[cfg(target_arch = "riscv64")]
1126+
#[path = "riscv64/image.rs"]
1127+
pub mod image;
10801128
#[cfg(feature = "io_uring")]
10811129
#[cfg(target_arch = "riscv64")]
10821130
#[path = "riscv64/io_uring.rs"]
@@ -1153,6 +1201,10 @@ pub mod if_ether;
11531201
#[cfg(target_arch = "s390x")]
11541202
#[path = "s390x/if_packet.rs"]
11551203
pub mod if_packet;
1204+
#[cfg(feature = "image")]
1205+
#[cfg(target_arch = "s390x")]
1206+
#[path = "s390x/image.rs"]
1207+
pub mod image;
11561208
#[cfg(feature = "io_uring")]
11571209
#[cfg(target_arch = "s390x")]
11581210
#[path = "s390x/io_uring.rs"]
@@ -1229,6 +1281,10 @@ pub mod if_ether;
12291281
#[cfg(target_arch = "sparc")]
12301282
#[path = "sparc/if_packet.rs"]
12311283
pub mod if_packet;
1284+
#[cfg(feature = "image")]
1285+
#[cfg(target_arch = "sparc")]
1286+
#[path = "sparc/image.rs"]
1287+
pub mod image;
12321288
#[cfg(feature = "io_uring")]
12331289
#[cfg(target_arch = "sparc")]
12341290
#[path = "sparc/io_uring.rs"]
@@ -1305,6 +1361,10 @@ pub mod if_ether;
13051361
#[cfg(target_arch = "sparc64")]
13061362
#[path = "sparc64/if_packet.rs"]
13071363
pub mod if_packet;
1364+
#[cfg(feature = "image")]
1365+
#[cfg(target_arch = "sparc64")]
1366+
#[path = "sparc64/image.rs"]
1367+
pub mod image;
13081368
#[cfg(feature = "io_uring")]
13091369
#[cfg(target_arch = "sparc64")]
13101370
#[path = "sparc64/io_uring.rs"]
@@ -1381,6 +1441,10 @@ pub mod if_ether;
13811441
#[cfg(target_arch = "x86")]
13821442
#[path = "x86/if_packet.rs"]
13831443
pub mod if_packet;
1444+
#[cfg(feature = "image")]
1445+
#[cfg(target_arch = "x86")]
1446+
#[path = "x86/image.rs"]
1447+
pub mod image;
13841448
#[cfg(feature = "io_uring")]
13851449
#[cfg(target_arch = "x86")]
13861450
#[path = "x86/io_uring.rs"]
@@ -1457,6 +1521,10 @@ pub mod if_ether;
14571521
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
14581522
#[path = "x86_64/if_packet.rs"]
14591523
pub mod if_packet;
1524+
#[cfg(feature = "image")]
1525+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
1526+
#[path = "x86_64/image.rs"]
1527+
pub mod image;
14601528
#[cfg(feature = "io_uring")]
14611529
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
14621530
#[path = "x86_64/io_uring.rs"]
@@ -1533,6 +1601,10 @@ pub mod if_ether;
15331601
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
15341602
#[path = "x32/if_packet.rs"]
15351603
pub mod if_packet;
1604+
#[cfg(feature = "image")]
1605+
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
1606+
#[path = "x32/image.rs"]
1607+
pub mod image;
15361608
#[cfg(feature = "io_uring")]
15371609
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
15381610
#[path = "x32/io_uring.rs"]

src/loongarch64/image.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* automatically generated by rust-bindgen 0.70.1 */
2+
3+

src/mips/image.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* automatically generated by rust-bindgen 0.70.1 */
2+
3+

src/mips32r6/image.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* automatically generated by rust-bindgen 0.70.1 */
2+
3+

0 commit comments

Comments
 (0)