Skip to content

Commit 9892a86

Browse files
committed
Make ioctl generation use correct version of Linux headers
Ioctls now use the same kernel version that's used in `gen/src/main.rs` for generating other bindings. They are no longer based on any system-wide headers which happen to exist in the system include directories. This removes the `REISERFS_IOC_UNPACK` ioctl because reiserfs was removed from the kernel and its userspace headers in Linux 6.13.
1 parent e730548 commit 9892a86

File tree

4 files changed

+57
-17
lines changed

4 files changed

+57
-17
lines changed

gen/ioctl/generate.sh

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,71 @@ set -ueo pipefail
1212
# to add new ioctl codes or a new architecture, and are unable to run it,
1313
# please file an issue in the issue tracker.
1414

15+
linux_version="$(sed -n 's/^const LINUX_VERSION: &str = "\(v.*\)";$/\1/p' ../src/main.rs)"
16+
17+
pushd ../linux
18+
git clean -fd
19+
git checkout "$linux_version" -f
20+
git clean -fd
21+
popd
22+
23+
tmp_dir="$(mktemp --tmpdir -d linux-raw-sys-ioctl.XXXXXXXXXX)"
24+
header_dir="$tmp_dir/linux-headers"
25+
mkdir "$header_dir"
26+
touch list.o main.exe
27+
28+
cleanup() {
29+
rm -r "$tmp_dir"
30+
rm list.o main.exe
31+
}
32+
trap cleanup EXIT
33+
34+
install_headers() {
35+
arch="$1"
36+
rm -r "$header_dir"
37+
make -C ../linux headers_install ARCH="$arch" INSTALL_HDR_PATH="$header_dir"
38+
}
39+
1540
cflags="-Wall"
41+
includes=(
42+
-nostdinc
43+
-Iinclude
44+
"-I$header_dir/include"
45+
)
1646
out="../modules/ioctl.h"
1747

1848
echo "// This file is generated from the ioctl/generate.sh script." > "$out"
1949

20-
i686-linux-gnu-gcc -Iinclude -c list.c $cflags
50+
install_headers x86
51+
i686-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
2152
i686-linux-gnu-gcc main.c list.o -o main.exe $cflags
2253
./main.exe >> "$out"
23-
x86_64-linux-gnu-gcc -Iinclude -c list.c $cflags
54+
install_headers x86_64
55+
x86_64-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
2456
x86_64-linux-gnu-gcc main.c list.o -o main.exe $cflags
2557
./main.exe >> "$out"
26-
aarch64-linux-gnu-gcc -Iinclude -c list.c $cflags
58+
install_headers arm64
59+
aarch64-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
2760
aarch64-linux-gnu-gcc main.c list.o -o main.exe $cflags
2861
qemu-aarch64 -L /usr/aarch64-linux-gnu ./main.exe >> "$out"
29-
arm-linux-gnueabihf-gcc -Iinclude -c list.c $cflags
62+
install_headers arm
63+
arm-linux-gnueabihf-gcc "${includes[@]}" -c list.c $cflags
3064
arm-linux-gnueabihf-gcc main.c list.o -o main.exe $cflags
3165
qemu-arm -L /usr/arm-linux-gnueabihf ./main.exe >> "$out"
32-
powerpc64le-linux-gnu-gcc -Iinclude -c list.c $cflags
66+
install_headers powerpc
67+
powerpc64le-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
3368
powerpc64le-linux-gnu-gcc main.c list.o -o main.exe $cflags
3469
qemu-ppc64le -L /usr/powerpc64le-linux-gnu ./main.exe >> "$out"
35-
powerpc-linux-gnu-gcc -Iinclude -c list.c $cflags
70+
install_headers powerpc
71+
powerpc-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
3672
powerpc-linux-gnu-gcc main.c list.o -o main.exe $cflags
3773
qemu-ppc -L /usr/powerpc-linux-gnu ./main.exe >> "$out"
38-
mips64el-linux-gnuabi64-gcc -Iinclude -c list.c $cflags
74+
install_headers mips
75+
mips64el-linux-gnuabi64-gcc "${includes[@]}" -c list.c $cflags
3976
mips64el-linux-gnuabi64-gcc main.c list.o -o main.exe $cflags
4077
qemu-mips64el -L /usr/mips64el-linux-gnuabi64 ./main.exe >> "$out"
41-
mipsel-linux-gnu-gcc -Iinclude -c list.c $cflags
78+
install_headers mips
79+
mipsel-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
4280
mipsel-linux-gnu-gcc main.c list.o -o main.exe $cflags
4381
qemu-mipsel -L /usr/mipsel-linux-gnu ./main.exe >> "$out"
4482

@@ -51,10 +89,12 @@ qemu-mipsel -L /usr/mipsel-linux-gnu ./main.exe >> "$out"
5189
# /opt/riscv/bin/qemu-riscv32 -L /opt/riscv/sysroot/ ./main.exe >> "$out"
5290
cat riscv32-ioctls.txt >> "$out"
5391

54-
riscv64-linux-gnu-gcc -Iinclude -c list.c $cflags
92+
install_headers riscv
93+
riscv64-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
5594
riscv64-linux-gnu-gcc main.c list.o -o main.exe $cflags
5695
qemu-riscv64 -L /usr/riscv64-linux-gnu ./main.exe >> "$out"
57-
s390x-linux-gnu-gcc -Iinclude -c list.c $cflags
96+
install_headers s390
97+
s390x-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
5898
s390x-linux-gnu-gcc main.c list.o -o main.exe $cflags
5999
qemu-s390x -L /usr/s390x-linux-gnu ./main.exe >> "$out"
60100
# As LoongArch and CSKY cross toolchain is not yet packaged in mainstream distros yet,
@@ -67,5 +107,3 @@ cat csky-ioctls.txt >> "$out"
67107

68108
# Add any extra custom definitions at the end.
69109
echo "#include \"ioctl-addendum.h\"" >> "$out"
70-
71-
rm list.o main.exe

gen/ioctl/include/stdint.h

Whitespace-only changes.

gen/ioctl/include/string.h

Whitespace-only changes.

gen/ioctl/list.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
// headers.
33
int printf(const char *, ...);
44

5-
typedef __UINT32_TYPE__ u32;
6-
typedef __UINT64_TYPE__ u64;
75
typedef __INT64_TYPE__ int64_t;
8-
typedef __UINT64_TYPE__ u_quad_t;
6+
typedef __UINT8_TYPE__ uint8_t;
7+
typedef __UINT16_TYPE__ uint16_t;
8+
typedef __UINT32_TYPE__ uint32_t;
9+
typedef __UINT64_TYPE__ uint64_t;
910
typedef __SIZE_TYPE__ size_t;
11+
typedef __UINTPTR_TYPE__ uintptr_t;
1012

1113
typedef unsigned short u_short;
1214
typedef unsigned long u_long;
1315

16+
void *memset(void *, int, size_t);
17+
1418
#include <linux/types.h>
1519
#include <linux/version.h>
1620
#include <linux/socket.h>
@@ -128,7 +132,6 @@ struct sockaddr {
128132
#include <linux/psp-sev.h>
129133
#include <linux/radeonfb.h>
130134
#include <linux/random.h>
131-
#include <linux/reiserfs_fs.h>
132135
#include <linux/remoteproc_cdev.h>
133136
#include <linux/rfkill.h>
134137
#include <linux/rio_cm_cdev.h>
@@ -1134,7 +1137,6 @@ void list(void) {
11341137
IOCTL_REQUEST(FW_CDEV_IOC_SEND_PHY_PACKET);
11351138
IOCTL_REQUEST(NBD_SET_FLAGS);
11361139
IOCTL_REQUEST(VFIO_DEVICE_GET_REGION_INFO);
1137-
IOCTL_REQUEST(REISERFS_IOC_UNPACK);
11381140
IOCTL_REQUEST(FW_CDEV_IOC_REMOVE_DESCRIPTOR);
11391141
IOCTL_REQUEST(RIO_SET_EVENT_MASK);
11401142
IOCTL_REQUEST(SNAPSHOT_ALLOC_SWAP_PAGE);

0 commit comments

Comments
 (0)