]> granicus.if.org Git - strace/commitdiff
ioctl: assume that all ioctl commands have unsigned int type
authorDmitry V. Levin <ldv@altlinux.org>
Mon, 19 Jan 2015 18:44:21 +0000 (18:44 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 20 Jan 2015 00:28:10 +0000 (00:28 +0000)
In linux, ioctl command number has a 32-bit unsigned integer type:
fs/ioctl.c:SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd, unsigned long, arg)
If the kernel completely ignores other bits on 64-bit architectures,
why should strace care?
Let's follow the kernel and treat it as unsigned int.

* defs.h (struct_ioctlent): Change "code" type to "unsigned int".
(ioctl_decode, ioctl_lookup, block_ioctl, loop_ioctl, mtd_ioctl,
ubi_ioctl, ptp_ioctl, scsi_ioctl, sock_ioctl, term_ioctl, rtc_ioctl,
v4l2_ioctl): Likewise.
* ioctl.c (ioctl_decode, ioctl_lookup, compare, ioctl_next_match):
Likewise.
* block.c (block_ioctl): Likewise.
* loop.c (loop_ioctl): Likewise.
* mtd.c (mtd_ioctl, ubi_ioctl): Likewise.
* ptp.c (ptp_ioctl): Likewise.
* scsi.c (scsi_ioctl): Likewise.
* sock.c (sock_ioctl): Likewise.
* term.c (term_ioctl): Likewise.
* time.c (rtc_ioctl): Likewise.
* v4l2.c (v4l2_ioctl): Likewise.
* ioctlsort.c (struct ioctlent, compare, main): Likewise.

12 files changed:
block.c
defs.h
ioctl.c
ioctlsort.c
loop.c
mtd.c
ptp.c
scsi.c
sock.c
term.c
time.c
v4l2.c

diff --git a/block.c b/block.c
index b62e43636c1eb6ca71598d2fe1da638b6df242ff..36d7433feb626ffd92d8d7e3d1baada81cf1d933 100644 (file)
--- a/block.c
+++ b/block.c
@@ -103,7 +103,7 @@ print_blkpg_req(struct tcb *tcp, struct blkpg_ioctl_arg *blkpg)
 }
 
 int
-block_ioctl(struct tcb *tcp, long code, long arg)
+block_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        switch (code) {
        /* take arg as a value, not as a pointer */
diff --git a/defs.h b/defs.h
index 03162176a5bfb0fc773db1aeed75534f2e29ae10..a91031b49b52df9e082f799de9d9b7f76c5a1ea1 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -396,7 +396,7 @@ typedef struct sysent {
 
 typedef struct ioctlent {
        const char *symbol;
-       unsigned long code;
+       unsigned int code;
 } struct_ioctlent;
 
 /* Trace Control Block */
@@ -731,20 +731,19 @@ extern void tprint_open_modes(int);
 extern const char *sprint_open_modes(int);
 extern void print_loff_t(struct tcb *, long);
 
-extern const struct_ioctlent *ioctl_lookup(unsigned long);
+extern const struct_ioctlent *ioctl_lookup(const unsigned int);
 extern const struct_ioctlent *ioctl_next_match(const struct_ioctlent *);
-extern int ioctl_decode(struct tcb *, long, long);
-extern int term_ioctl(struct tcb *, long, long);
-extern int sock_ioctl(struct tcb *, long, long);
-extern int proc_ioctl(struct tcb *, int, int);
-extern int rtc_ioctl(struct tcb *, long, long);
-extern int scsi_ioctl(struct tcb *, long, long);
-extern int block_ioctl(struct tcb *, long, long);
-extern int v4l2_ioctl(struct tcb *, unsigned long, long);
-extern int mtd_ioctl(struct tcb *, long, long);
-extern int ubi_ioctl(struct tcb *, long, long);
-extern int loop_ioctl(struct tcb *, long, long);
-extern int ptp_ioctl(struct tcb *, long, long);
+extern int ioctl_decode(struct tcb *, const unsigned int, long);
+extern int block_ioctl(struct tcb *, const unsigned int, long);
+extern int loop_ioctl(struct tcb *, const unsigned int, long);
+extern int mtd_ioctl(struct tcb *, const unsigned int, long);
+extern int ptp_ioctl(struct tcb *, const unsigned int, long);
+extern int rtc_ioctl(struct tcb *, const unsigned int, long);
+extern int scsi_ioctl(struct tcb *, const unsigned int, long);
+extern int sock_ioctl(struct tcb *, const unsigned int, long);
+extern int term_ioctl(struct tcb *, const unsigned int, long);
+extern int ubi_ioctl(struct tcb *, const unsigned int, long);
+extern int v4l2_ioctl(struct tcb *, const unsigned int, long);
 
 extern int tv_nz(const struct timeval *);
 extern int tv_cmp(const struct timeval *, const struct timeval *);
diff --git a/ioctl.c b/ioctl.c
index cfd5a245f21da6d5477c432202b7f675e9e1bf4b..3d867f7f86e420f3c2a1b86346855e4483bcb3b3 100644 (file)
--- a/ioctl.c
+++ b/ioctl.c
 static int
 compare(const void *a, const void *b)
 {
-       unsigned long code1 = (unsigned long) a;
-       unsigned long code2 = ((struct_ioctlent *) b)->code;
+       const unsigned int code1 = (const unsigned long) a;
+       const unsigned int code2 = ((struct_ioctlent *) b)->code;
        return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
 }
 
 const struct_ioctlent *
-ioctl_lookup(unsigned long code)
+ioctl_lookup(unsigned int code)
 {
        struct_ioctlent *iop;
 
        code &= (_IOC_NRMASK<<_IOC_NRSHIFT) | (_IOC_TYPEMASK<<_IOC_TYPESHIFT);
-       iop = bsearch((void*)code, ioctlent,
+       iop = bsearch((const void *) (const unsigned long) code, ioctlent,
                        nioctlents, sizeof(ioctlent[0]), compare);
        while (iop > ioctlent) {
                iop--;
@@ -60,9 +60,7 @@ ioctl_lookup(unsigned long code)
 const struct_ioctlent *
 ioctl_next_match(const struct_ioctlent *iop)
 {
-       unsigned long code;
-
-       code = iop->code;
+       const unsigned int code = iop->code;
        iop++;
        if (iop < ioctlent + nioctlents && iop->code == code)
                return iop;
@@ -70,9 +68,9 @@ ioctl_next_match(const struct_ioctlent *iop)
 }
 
 int
-ioctl_decode(struct tcb *tcp, long code, long arg)
+ioctl_decode(struct tcb *tcp, unsigned int code, long arg)
 {
-       switch ((code >> 8) & 0xff) {
+       switch (_IOC_TYPE(code)) {
 #if defined(ALPHA) || defined(POWERPC)
        case 'f': case 't': case 'T':
 #else /* !ALPHA */
index 393b534952ffcfab0f718fcb83643d260761f36c..f0f5744ed32b5622fe50835acdc87563c5e786bf 100644 (file)
@@ -13,7 +13,7 @@
 struct ioctlent {
        const char*     header;
        const char*     name;
-       unsigned long   code;
+       unsigned int    code;
 };
 
 struct ioctlent ioctls[] = {
@@ -23,8 +23,8 @@ struct ioctlent ioctls[] = {
 int nioctls = sizeof(ioctls) / sizeof(ioctls[0]);
 
 int compare(const void* a, const void* b) {
-       unsigned long code1 = ((struct ioctlent *) a)->code;
-       unsigned long code2 = ((struct ioctlent *) b)->code;
+       unsigned int code1 = ((struct ioctlent *) a)->code;
+       unsigned int code2 = ((struct ioctlent *) b)->code;
        const char *name1 = ((struct ioctlent *) a)->name;
        const char *name2 = ((struct ioctlent *) b)->name;
        return (code1 > code2) ? 1 : (code1 < code2) ? -1 : strcmp(name1, name2);
@@ -51,7 +51,7 @@ int main(int argc, char** argv) {
        for (i = 0; i < nioctls; i++)
                if (i == 0 || ioctls[i-1].code != ioctls[i].code ||
                    is_not_prefix(ioctls[i-1].name, ioctls[i].name))
-                       printf("\t{\"%s\",\t\"%s\",\t%#06lx},\n",
+                       printf("\t{\"%s\",\t\"%s\",\t%#06x},\n",
                                ioctls[i].header, ioctls[i].name, ioctls[i].code);
 
        return 0;
diff --git a/loop.c b/loop.c
index 2e1634791aa4ddace16043f931633b81d1e645d4..6ce6545a0508f3f8255462503b26785484af999f 100644 (file)
--- a/loop.c
+++ b/loop.c
@@ -34,7 +34,8 @@
 #include "xlat/loop_flags_options.h"
 #include "xlat/loop_crypt_type_options.h"
 
-int loop_ioctl(struct tcb *tcp, long code, long arg)
+int
+loop_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        struct loop_info info;
        struct loop_info64 info64;
diff --git a/mtd.c b/mtd.c
index 88e8dbcc64332917bd856e9473a1e50394e84479..8f05d040239193396e09f1eb2c2626f0bf26eadf 100644 (file)
--- a/mtd.c
+++ b/mtd.c
@@ -47,7 +47,8 @@
 #include "xlat/mtd_otp_options.h"
 #include "xlat/mtd_nandecc_options.h"
 
-int mtd_ioctl(struct tcb *tcp, long code, long arg)
+int
+mtd_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        struct mtd_info_user minfo;
        struct erase_info_user einfo;
@@ -252,7 +253,8 @@ int mtd_ioctl(struct tcb *tcp, long code, long arg)
 #include "xlat/ubi_volume_types.h"
 #include "xlat/ubi_volume_props.h"
 
-int ubi_ioctl(struct tcb *tcp, long code, long arg)
+int
+ubi_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        struct ubi_mkvol_req mkvol;
        struct ubi_rsvol_req rsvol;
diff --git a/ptp.c b/ptp.c
index 1d9cf247ca91f7f527fb31cad6abd00e8d69749b..dbd35834880442a501104d8d4f1a9a207f9b56d9 100644 (file)
--- a/ptp.c
+++ b/ptp.c
@@ -4,7 +4,8 @@
 
 #include "xlat/ptp_flags_options.h"
 
-int ptp_ioctl(struct tcb *tcp, long code, long arg)
+int
+ptp_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        if (!verbose(tcp))
                return 0;
diff --git a/scsi.c b/scsi.c
index a2e23c8b1cb10da3cbff19e7e686ccb310b339cd..daf725200a260090b4ac913e360265ebea5428e8 100644 (file)
--- a/scsi.c
+++ b/scsi.c
@@ -103,7 +103,7 @@ print_sg_io_res(struct tcb *tcp, struct sg_io_hdr *sg_io)
 }
 
 int
-scsi_ioctl(struct tcb *tcp, long code, long arg)
+scsi_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        switch (code) {
        case SG_IO:
diff --git a/sock.c b/sock.c
index 546c651cf46c74788d348063e9d4e543b1b6dfa9..dfdb10a78ebb9a94ea8f5a5b86f943abdb1ab382 100644 (file)
--- a/sock.c
+++ b/sock.c
@@ -52,7 +52,7 @@ print_addr(struct tcb *tcp, long addr, struct ifreq *ifr)
 }
 
 int
-sock_ioctl(struct tcb *tcp, long code, long arg)
+sock_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        struct ifreq ifr;
        struct ifconf ifc;
diff --git a/term.c b/term.c
index d1c9b6530a6d31d61d66a30214ede29f288a5979..b2811f27a9628ebe9075cfcc6056b4b8a468409e 100644 (file)
--- a/term.c
+++ b/term.c
@@ -44,7 +44,8 @@
 #include "xlat/baud_options.h"
 #include "xlat/modem_flags.h"
 
-int term_ioctl(struct tcb *tcp, long code, long arg)
+int
+term_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        struct termios tios;
        struct termio tio;
diff --git a/time.c b/time.c
index b61a74e968831ba1defa41e055784b0b9a85317e..d8e72712cc1b560cbc7a5ce040a483ec834da7af 100644 (file)
--- a/time.c
+++ b/time.c
@@ -739,7 +739,7 @@ print_rtc(struct tcb *tcp, const struct rtc_time *rt)
 }
 
 int
-rtc_ioctl(struct tcb *tcp, long code, long arg)
+rtc_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        switch (code) {
        case RTC_ALM_SET:
diff --git a/v4l2.c b/v4l2.c
index b89928b4dc611b81f5f3789826f2302e480dd5b6..ca165b6b1d32a64d5e527b22dd437c94d0251908 100644 (file)
--- a/v4l2.c
+++ b/v4l2.c
@@ -149,7 +149,7 @@ static void print_v4l2_format_fmt(const struct v4l2_format *f)
 }
 
 int
-v4l2_ioctl(struct tcb *tcp, unsigned long code, long arg)
+v4l2_ioctl(struct tcb *tcp, const unsigned int code, long arg)
 {
        if (!verbose(tcp))
                return 0;