Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions gen/include/support.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,24 @@ typedef __INT8_TYPE__ int8_t;
typedef __INT16_TYPE__ int16_t;
typedef __INT32_TYPE__ int32_t;
typedef __INT64_TYPE__ int64_t;
#ifdef __m68k__
// Hack: until the fix for [1] is released, lie to clang that `size_t` has
// alignment 4 on m68k. This doesn't affect the correctness of bindings, since
// the only structs that (transitively) contain a size_t are
// `net::{msghdr, cmsghdr, mmsghdr}` and their definitions are the same
// regardless of the alignment of `size_t`.
//
// [1]: https://github.com/rust-lang/rust-bindgen/issues/3312
typedef struct __attribute__((aligned(4))) {
__SIZE_TYPE__ s;
} size_t;
typedef struct __attribute__((aligned(4))) {
__PTRDIFF_TYPE__ s;
} ssize_t;
#else
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ssize_t;
#endif
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
Expand Down
67 changes: 55 additions & 12 deletions gen/ioctl/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,71 @@ set -ueo pipefail
# to add new ioctl codes or a new architecture, and are unable to run it,
# please file an issue in the issue tracker.

linux_version="$(sed -n 's/^const LINUX_VERSION: &str = "\(v.*\)";$/\1/p' ../src/main.rs)"

pushd ../linux
git clean -fd
git checkout "$linux_version" -f
git clean -fd
popd

tmp_dir="$(mktemp --tmpdir -d linux-raw-sys-ioctl.XXXXXXXXXX)"
header_dir="$tmp_dir/linux-headers"
mkdir "$header_dir"
touch list.o main.exe

cleanup() {
rm -r "$tmp_dir"
rm list.o main.exe
}
trap cleanup EXIT

install_headers() {
arch="$1"
rm -r "$header_dir"
make -C ../linux headers_install ARCH="$arch" INSTALL_HDR_PATH="$header_dir"
}

cflags="-Wall"
includes=(
-nostdinc
-Iinclude
"-I$header_dir/include"
)
out="../modules/ioctl.h"

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

i686-linux-gnu-gcc -Iinclude -c list.c $cflags
install_headers x86
i686-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
i686-linux-gnu-gcc main.c list.o -o main.exe $cflags
./main.exe >> "$out"
x86_64-linux-gnu-gcc -Iinclude -c list.c $cflags
install_headers x86_64
x86_64-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
x86_64-linux-gnu-gcc main.c list.o -o main.exe $cflags
./main.exe >> "$out"
aarch64-linux-gnu-gcc -Iinclude -c list.c $cflags
install_headers arm64
aarch64-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
aarch64-linux-gnu-gcc main.c list.o -o main.exe $cflags
qemu-aarch64 -L /usr/aarch64-linux-gnu ./main.exe >> "$out"
arm-linux-gnueabihf-gcc -Iinclude -c list.c $cflags
install_headers arm
arm-linux-gnueabihf-gcc "${includes[@]}" -c list.c $cflags
arm-linux-gnueabihf-gcc main.c list.o -o main.exe $cflags
qemu-arm -L /usr/arm-linux-gnueabihf ./main.exe >> "$out"
powerpc64le-linux-gnu-gcc -Iinclude -c list.c $cflags
install_headers powerpc
powerpc64le-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
powerpc64le-linux-gnu-gcc main.c list.o -o main.exe $cflags
qemu-ppc64le -L /usr/powerpc64le-linux-gnu ./main.exe >> "$out"
powerpc-linux-gnu-gcc -Iinclude -c list.c $cflags
install_headers powerpc
powerpc-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
powerpc-linux-gnu-gcc main.c list.o -o main.exe $cflags
qemu-ppc -L /usr/powerpc-linux-gnu ./main.exe >> "$out"
mips64el-linux-gnuabi64-gcc -Iinclude -c list.c $cflags
install_headers mips
mips64el-linux-gnuabi64-gcc "${includes[@]}" -c list.c $cflags
mips64el-linux-gnuabi64-gcc main.c list.o -o main.exe $cflags
qemu-mips64el -L /usr/mips64el-linux-gnuabi64 ./main.exe >> "$out"
mipsel-linux-gnu-gcc -Iinclude -c list.c $cflags
install_headers mips
mipsel-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
mipsel-linux-gnu-gcc main.c list.o -o main.exe $cflags
qemu-mipsel -L /usr/mipsel-linux-gnu ./main.exe >> "$out"

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

riscv64-linux-gnu-gcc -Iinclude -c list.c $cflags
install_headers riscv
riscv64-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
riscv64-linux-gnu-gcc main.c list.o -o main.exe $cflags
qemu-riscv64 -L /usr/riscv64-linux-gnu ./main.exe >> "$out"
s390x-linux-gnu-gcc -Iinclude -c list.c $cflags
install_headers s390
s390x-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
s390x-linux-gnu-gcc main.c list.o -o main.exe $cflags
qemu-s390x -L /usr/s390x-linux-gnu ./main.exe >> "$out"
# As LoongArch and CSKY cross toolchain is not yet packaged in mainstream distros yet,
Expand All @@ -65,7 +105,10 @@ cat loongarch-ioctls.txt >> "$out"
# qemu-csky -L /usr/csky-linux-gnuabiv2 ./main.exe >> "$out"
cat csky-ioctls.txt >> "$out"

install_headers m68k
m68k-linux-gnu-gcc "${includes[@]}" -c list.c $cflags
m68k-linux-gnu-gcc main.c list.o -o main.exe $cflags
qemu-m68k -L /usr/m68k-linux-gnu ./main.exe >> "$out"

# Add any extra custom definitions at the end.
echo "#include \"ioctl-addendum.h\"" >> "$out"

rm list.o main.exe
1 change: 0 additions & 1 deletion gen/ioctl/generated.txt
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,6 @@ SWITCHTEC_IOCTL_FLASH_PART_INFO
FW_CDEV_IOC_SEND_PHY_PACKET
NBD_SET_FLAGS
VFIO_DEVICE_GET_REGION_INFO
REISERFS_IOC_UNPACK
FW_CDEV_IOC_REMOVE_DESCRIPTOR
RIO_SET_EVENT_MASK
SNAPSHOT_ALLOC_SWAP_PAGE
Expand Down
Empty file added gen/ioctl/include/stdint.h
Empty file.
Empty file added gen/ioctl/include/string.h
Empty file.
14 changes: 8 additions & 6 deletions gen/ioctl/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
// headers.
int printf(const char *, ...);

typedef __UINT32_TYPE__ u32;
typedef __UINT64_TYPE__ u64;
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ u_quad_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __SIZE_TYPE__ size_t;
typedef __UINTPTR_TYPE__ uintptr_t;

typedef unsigned short u_short;
typedef unsigned long u_long;

void *memset(void *, int, size_t);

#include <linux/types.h>
#include <linux/version.h>
#include <linux/socket.h>
Expand Down Expand Up @@ -96,7 +100,7 @@ struct sockaddr {
#include <linux/joystick.h>
#include <linux/kd.h>
#include <linux/kcov.h>
#if !defined(__arm__) && !defined(__loongarch__) && !defined(__powerpc64__) && !defined(__riscv) && !defined(__csky__)// various errors
#if !defined(__arm__) && !defined(__loongarch__) && !defined(__powerpc64__) && !defined(__riscv) && !defined(__csky__) && !defined(__m68k__) // various errors
#include <linux/kvm.h>
#endif
#include <linux/lirc.h>
Expand Down Expand Up @@ -128,7 +132,6 @@ struct sockaddr {
#include <linux/psp-sev.h>
#include <linux/radeonfb.h>
#include <linux/random.h>
#include <linux/reiserfs_fs.h>
#include <linux/remoteproc_cdev.h>
#include <linux/rfkill.h>
#include <linux/rio_cm_cdev.h>
Expand Down Expand Up @@ -1134,7 +1137,6 @@ void list(void) {
IOCTL_REQUEST(FW_CDEV_IOC_SEND_PHY_PACKET);
IOCTL_REQUEST(NBD_SET_FLAGS);
IOCTL_REQUEST(VFIO_DEVICE_GET_REGION_INFO);
IOCTL_REQUEST(REISERFS_IOC_UNPACK);
IOCTL_REQUEST(FW_CDEV_IOC_REMOVE_DESCRIPTOR);
IOCTL_REQUEST(RIO_SET_EVENT_MASK);
IOCTL_REQUEST(SNAPSHOT_ALLOC_SWAP_PAGE);
Expand Down
2 changes: 2 additions & 0 deletions gen/ioctl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ int main(void) {
printf("#ifdef __loongarch__\n");
#elif defined(__csky__)
printf("#ifdef __csky__\n");
#elif defined(__m68k__)
printf("#ifdef __m68k__\n");
#else
#error "unimplemented architecture"
#endif
Expand Down
2 changes: 1 addition & 1 deletion gen/modules/general.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct user_desc {
// that its fourth argument be the size of the kernel's internal `sigset_t`
// type. So we define our own.

#if defined(__i386__) || defined(__x86_64__) || defined(__s390x__) || defined(__arm__) || defined(__loongarch__)
#if defined(__i386__) || defined(__x86_64__) || defined(__s390x__) || defined(__arm__) || defined(__loongarch__) || defined(__m68k__)
#define _NSIG 64
#endif

Expand Down
Loading