Skip to content

Commit 8aec869

Browse files
authored
Add m68k architecture support (#174)
* 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. * Add m68k architecture support * Generate ioctls and bindings
1 parent 9c80662 commit 8aec869

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+25355
-51
lines changed

gen/include/support.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,24 @@ typedef __INT8_TYPE__ int8_t;
1010
typedef __INT16_TYPE__ int16_t;
1111
typedef __INT32_TYPE__ int32_t;
1212
typedef __INT64_TYPE__ int64_t;
13+
#ifdef __m68k__
14+
// Hack: until the fix for [1] is released, lie to clang that `size_t` has
15+
// alignment 4 on m68k. This doesn't affect the correctness of bindings, since
16+
// the only structs that (transitively) contain a size_t are
17+
// `net::{msghdr, cmsghdr, mmsghdr}` and their definitions are the same
18+
// regardless of the alignment of `size_t`.
19+
//
20+
// [1]: https://github.com/rust-lang/rust-bindgen/issues/3312
21+
typedef struct __attribute__((aligned(4))) {
22+
__SIZE_TYPE__ s;
23+
} size_t;
24+
typedef struct __attribute__((aligned(4))) {
25+
__PTRDIFF_TYPE__ s;
26+
} ssize_t;
27+
#else
1328
typedef __SIZE_TYPE__ size_t;
1429
typedef __PTRDIFF_TYPE__ ssize_t;
30+
#endif
1531
typedef __PTRDIFF_TYPE__ ptrdiff_t;
1632
typedef __INTPTR_TYPE__ intptr_t;
1733
typedef __UINTPTR_TYPE__ uintptr_t;

gen/ioctl/generate.sh

Lines changed: 55 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,
@@ -65,7 +105,10 @@ cat loongarch-ioctls.txt >> "$out"
65105
# qemu-csky -L /usr/csky-linux-gnuabiv2 ./main.exe >> "$out"
66106
cat csky-ioctls.txt >> "$out"
67107

108+
install_headers m68k
109+
m68k-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
110+
m68k-linux-gnu-gcc main.c list.o -o main.exe $cflags
111+
qemu-m68k -L /usr/m68k-linux-gnu ./main.exe >> "$out"
112+
68113
# Add any extra custom definitions at the end.
69114
echo "#include \"ioctl-addendum.h\"" >> "$out"
70-
71-
rm list.o main.exe

gen/ioctl/generated.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,6 @@ SWITCHTEC_IOCTL_FLASH_PART_INFO
817817
FW_CDEV_IOC_SEND_PHY_PACKET
818818
NBD_SET_FLAGS
819819
VFIO_DEVICE_GET_REGION_INFO
820-
REISERFS_IOC_UNPACK
821820
FW_CDEV_IOC_REMOVE_DESCRIPTOR
822821
RIO_SET_EVENT_MASK
823822
SNAPSHOT_ALLOC_SWAP_PAGE

gen/ioctl/include/stdint.h

Whitespace-only changes.

gen/ioctl/include/string.h

Whitespace-only changes.

gen/ioctl/list.c

Lines changed: 8 additions & 6 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>
@@ -96,7 +100,7 @@ struct sockaddr {
96100
#include <linux/joystick.h>
97101
#include <linux/kd.h>
98102
#include <linux/kcov.h>
99-
#if !defined(__arm__) && !defined(__loongarch__) && !defined(__powerpc64__) && !defined(__riscv) && !defined(__csky__)// various errors
103+
#if !defined(__arm__) && !defined(__loongarch__) && !defined(__powerpc64__) && !defined(__riscv) && !defined(__csky__) && !defined(__m68k__) // various errors
100104
#include <linux/kvm.h>
101105
#endif
102106
#include <linux/lirc.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);

gen/ioctl/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ int main(void) {
4949
printf("#ifdef __loongarch__\n");
5050
#elif defined(__csky__)
5151
printf("#ifdef __csky__\n");
52+
#elif defined(__m68k__)
53+
printf("#ifdef __m68k__\n");
5254
#else
5355
#error "unimplemented architecture"
5456
#endif

gen/modules/general.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ struct user_desc {
229229
// that its fourth argument be the size of the kernel's internal `sigset_t`
230230
// type. So we define our own.
231231

232-
#if defined(__i386__) || defined(__x86_64__) || defined(__s390x__) || defined(__arm__) || defined(__loongarch__)
232+
#if defined(__i386__) || defined(__x86_64__) || defined(__s390x__) || defined(__arm__) || defined(__loongarch__) || defined(__m68k__)
233233
#define _NSIG 64
234234
#endif
235235

0 commit comments

Comments
 (0)