Skip to contentSkip to conversation

linux-user: fix ioctl() arguments printing in strace support

PATCH New Yan Cangang 1 participant 1 message May 17, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: fix ioctl() arguments printing in strace support

When both of the following conditions are satisfied, ioctl() arguments printing in strace support is not working:
- highest bit of ioctl() request command is 1
- sizeof abi_long is 8 bytes

print_ioctl() and print_syscall_ret_ioctl() find IOCTLEntry by this way:

    /* ie->target_cmd is int, arg1 is abi_long, both are signed */
    for (ie = ioctl_entries; ie->target_cmd != 0; ie++)
        if (ie->target_cmd == arg1)
            break;

Operator "==" will convert target_cmd to abi_long by sign extension, resulting in a negative number, will not match any ioctl request number.

This patch simply changes type of target_cmd to unsigned int, avoids sign extension. ioctl command values are 32-bit constants, explain highest bit as sign bit is pointless.

---
 linux-user/user-internals.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/user-internals.h +1 -1
index ddc260e465..550d16e2dd 100644
@@ -35,7 +35,7 @@ typedef abi_long do_ioctl_fn(const IOCTLEntry *ie, uint8_t *buf_temp,
                              int fd, int cmd, abi_long arg);
 
 struct IOCTLEntry {
-    int target_cmd;
+    unsigned int target_cmd;
     unsigned int host_cmd;
     const char *name;
     int access;
Signature · 1 line
2.36.1