diff mbox series

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

Message ID 20220517180605.109867-1-nalanzeyu@gmail.com
State New
Headers show
Series linux-user: fix ioctl() arguments printing in strace support | expand

Commit Message

Yan Cangang May 17, 2022, 6:06 p.m. UTC
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.

Signed-off-by: Yan Cangang <nalanzeyu@gmail.com>
---
 linux-user/user-internals.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/linux-user/user-internals.h b/linux-user/user-internals.h
index ddc260e465..550d16e2dd 100644
--- a/linux-user/user-internals.h
+++ b/linux-user/user-internals.h
@@ -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;