fast method_name->source_file lookups, heuristics for finding ioctl names
[moctel.git] / show_ioctl.c
index e090d9a..8e36dbf 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright (C) 2013 Jann Horn <jann@thejh.net>
+// This file is licensed under the GNU GPL v2 (see
+// the LICENSE file).
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -6,6 +10,8 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 
 #include <fcntl.h>
 #include <sys/ioctl.h>
 
+#define KSYM_NAME_LEN 128
+
 struct fetch_fops_args {
   int fd;
   uint64_t retp;
 struct fetch_fops_args {
   int fd;
   uint64_t retp;
@@ -13,37 +19,6 @@ struct fetch_fops_args {
 
 #define MOCTEL_FETCH_FOPS _IOR('m', 1, struct fetch_fops_args)
 
 
 #define MOCTEL_FETCH_FOPS _IOR('m', 1, struct fetch_fops_args)
 
-struct file_operations {
-        void *owner;
-        void *llseek;
-        void *read;
-        void *write;
-        void *aio_read;
-        void *aio_write;
-        void *readdir;
-        void *poll;
-        void *unlocked_ioctl;
-        void *compat_ioctl;
-        void *mmap;
-        void *open;
-        void *flush;
-        void *release;
-        void *fsync;
-        void *aio_fsync;
-        void *fasync;
-        void *lock;
-        void *sendpage;
-        void *get_unmapped_area;
-        void *check_flags;
-        void *flock;
-        void *splice_write;
-        void *splice_read;
-        void *setlease;
-        void *fallocate;
-};
-
-
-
 int main(int argc, char **argv) {
   if (argc != 2) fputs("Usage: show_ioctl <device>\n", stderr), exit(1);
 
 int main(int argc, char **argv) {
   if (argc != 2) fputs("Usage: show_ioctl <device>\n", stderr), exit(1);
 
@@ -54,10 +29,10 @@ int main(int argc, char **argv) {
   int ioctlfd = open("/dev/ioctl_info", O_RDONLY);
   if (ioctlfd == -1) fprintf(stderr, "Can't open /dev/ioctl_info: %m\n"), exit(1);
 
   int ioctlfd = open("/dev/ioctl_info", O_RDONLY);
   if (ioctlfd == -1) fprintf(stderr, "Can't open /dev/ioctl_info: %m\n"), exit(1);
 
-  struct file_operations fops;
+  char resbuf[KSYM_NAME_LEN];
   struct fetch_fops_args ioctl_args = {
     .fd = devfd,
   struct fetch_fops_args ioctl_args = {
     .fd = devfd,
-    .retp = (uint64_t)&fops
+    .retp = (uint64_t)resbuf
   };
   int ret = ioctl(ioctlfd, MOCTEL_FETCH_FOPS, &ioctl_args);
   if (ret) fprintf(stderr, "can't perform MOCTEL_FETCH_FOPS: %m\n"), exit(1);
   };
   int ret = ioctl(ioctlfd, MOCTEL_FETCH_FOPS, &ioctl_args);
   if (ret) fprintf(stderr, "can't perform MOCTEL_FETCH_FOPS: %m\n"), exit(1);
@@ -65,7 +40,7 @@ int main(int argc, char **argv) {
   close(ioctlfd);
   close(devfd);
 
   close(ioctlfd);
   close(devfd);
 
-  printf("unlocked_ioctl: %llx\n", (unsigned long long)fops.unlocked_ioctl);
+  printf("%s\n", resbuf);
 
   return 0;
 }
 
   return 0;
 }