From c756ba4e975097bf74b952367e2cd1a8db466c69 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 2 Dec 2024 10:57:36 +0100 Subject: tools/syz-declextract: extract file_operations descriptions Extend the clang tool to locate file_operations variables and arrays and dump open/read/write/mmap/ioctl callbacks for each. It also tries to extract set of ioctl commands and argument types for them in a simple best-effort way (for now). It just locates switch in the ioctl callback and extracts each case as a command. --- .../testdata/include/uapi/file_operations.h | 14 +++++++++++++ .../syz-declextract/testdata/include/uapi/ioctl.h | 24 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 tools/syz-declextract/testdata/include/uapi/file_operations.h create mode 100644 tools/syz-declextract/testdata/include/uapi/ioctl.h (limited to 'tools/syz-declextract/testdata/include/uapi') diff --git a/tools/syz-declextract/testdata/include/uapi/file_operations.h b/tools/syz-declextract/testdata/include/uapi/file_operations.h new file mode 100644 index 000000000..6a2a8d259 --- /dev/null +++ b/tools/syz-declextract/testdata/include/uapi/file_operations.h @@ -0,0 +1,14 @@ +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +#include "ioctl.h" + +#define FOO_IOCTL1 _IO('c', 1) +#define FOO_IOCTL2 _IOR('c', 2, int) +#define FOO_IOCTL3 _IOR('c', 3, struct foo_ioctl_arg) +#define FOO_IOCTL4 _IOW('c', 4, struct foo_ioctl_arg) +#define FOO_IOCTL5 _IOWR('c', 5, struct foo_ioctl_arg) + +struct foo_ioctl_arg { + int a, b; +}; diff --git a/tools/syz-declextract/testdata/include/uapi/ioctl.h b/tools/syz-declextract/testdata/include/uapi/ioctl.h new file mode 100644 index 000000000..fae14a74e --- /dev/null +++ b/tools/syz-declextract/testdata/include/uapi/ioctl.h @@ -0,0 +1,24 @@ +// Copyright 2024 syzkaller project authors. All rights reserved. +// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file. + +#define _IOC_NONE 0U +#define _IOC_WRITE 1U +#define _IOC_READ 2U + +#define _IOC_NRBITS 8 +#define _IOC_TYPEBITS 8 +#define _IOC_SIZEBITS 14 +#define _IOC_DIRBITS 2 + +#define _IOC_NRSHIFT 0 +#define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) +#define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) +#define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) + +#define _IOC(dir, type, nr, size) (((dir) << _IOC_DIRSHIFT) | ((type) << _IOC_TYPESHIFT) | \ + ((nr) << _IOC_NRSHIFT) | ((size) << _IOC_SIZESHIFT)) + +#define _IO(type, nr) _IOC(_IOC_NONE, (type), (nr), 0) +#define _IOR(type, nr, arg) _IOC(_IOC_READ, (type), (nr), (sizeof(arg))) +#define _IOW(type, nr, arg) _IOC(_IOC_WRITE, (type), (nr), (sizeof(arg))) +#define _IOWR(type, nr, arg) _IOC(_IOC_READ|_IOC_WRITE, (type), (nr), (sizeof(arg))) -- cgit mrf-deployment