1 // Copyright (C) 2013 Jann Horn <jann@thejh.net>
2 // This file is licensed under the GNU GPL v2 (see
8 #include <linux/ioctl.h>
11 #include <sys/ioctl.h>
13 struct fetch_fops_args {
18 #define MOCTEL_FETCH_FOPS _IOR('m', 1, struct fetch_fops_args)
20 struct file_operations {
40 void *get_unmapped_area;
51 int main(int argc, char **argv) {
52 if (argc != 2) fputs("Usage: show_ioctl <device>\n", stderr), exit(1);
54 char *devname = argv[1];
55 int devfd = open(devname, O_RDONLY);
56 if (devfd == -1) fprintf(stderr, "Can't open %s: %m\n", devname), exit(1);
58 int ioctlfd = open("/dev/ioctl_info", O_RDONLY);
59 if (ioctlfd == -1) fprintf(stderr, "Can't open /dev/ioctl_info: %m\n"), exit(1);
61 struct file_operations fops;
62 struct fetch_fops_args ioctl_args = {
64 .retp = (uint64_t)&fops
66 int ret = ioctl(ioctlfd, MOCTEL_FETCH_FOPS, &ioctl_args);
67 if (ret) fprintf(stderr, "can't perform MOCTEL_FETCH_FOPS: %m\n"), exit(1);
72 printf("unlocked_ioctl: %llx\n", (unsigned long long)fops.unlocked_ioctl);