[v8,9/9] linux-user/syscall: Align target_sockaddr fields using ABI types
diff mbox series

Message ID 20191021114857.20538-10-f4bug@amsat.org
State New
Headers show
Series
  • linux-user: strace improvements
Related show

Commit Message

Philippe Mathieu-Daudé Oct. 21, 2019, 11:48 a.m. UTC
Target architectures align types differently for instance m68k
aligns on 16bit whereas others on 32bit).
Use ABI types to keep alignments good.

Suggested-by: Laurent Vivier <laurent@vivier.eu>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
v8: Use abi_int for target_sockaddr_ll.sll_ifindex
---
 linux-user/syscall_defs.h | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

Comments

Laurent Vivier Oct. 21, 2019, 12:55 p.m. UTC | #1
Le 21/10/2019 à 13:48, Philippe Mathieu-Daudé a écrit :
> Target architectures align types differently for instance m68k
> aligns on 16bit whereas others on 32bit).
> Use ABI types to keep alignments good.
> 
> Suggested-by: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> v8: Use abi_int for target_sockaddr_ll.sll_ifindex
> ---
>  linux-user/syscall_defs.h | 34 +++++++++++++++++-----------------
>  1 file changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index 7694d72446..98c2119de9 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -134,22 +134,22 @@
>  #define TARGET_IOWRU(type,nr)	TARGET_IOC(TARGET_IOC_READ|TARGET_IOC_WRITE,(type),(nr),TARGET_IOC_SIZEMASK)
>  
>  struct target_sockaddr {
> -    uint16_t sa_family;
> +    abi_ushort sa_family;
>      uint8_t sa_data[14];
>  };
>  
>  struct target_sockaddr_ll {
> -    uint16_t sll_family;   /* Always AF_PACKET */
> -    uint16_t sll_protocol; /* Physical layer protocol */
> -    int      sll_ifindex;  /* Interface number */
> -    uint16_t sll_hatype;   /* ARP hardware type */
> -    uint8_t  sll_pkttype;  /* Packet type */
> -    uint8_t  sll_halen;    /* Length of address */
> -    uint8_t  sll_addr[8];  /* Physical layer address */
> +    abi_ushort sll_family;   /* Always AF_PACKET */
> +    abi_ushort sll_protocol; /* Physical layer protocol */
> +    abi_int    sll_ifindex;  /* Interface number */
> +    abi_ushort sll_hatype;   /* ARP hardware type */
> +    uint8_t    sll_pkttype;  /* Packet type */
> +    uint8_t    sll_halen;    /* Length of address */
> +    uint8_t    sll_addr[8];  /* Physical layer address */
>  };
>  
>  struct target_sockaddr_un {
> -    uint16_t su_family;
> +    abi_ushort su_family;
>      uint8_t sun_path[108];
>  };
>  
> @@ -161,24 +161,24 @@ struct target_sockaddr_nl {
>  };
>  
>  struct target_in_addr {
> -    uint32_t s_addr; /* big endian */
> +    abi_uint s_addr; /* big endian */
>  };
>  
>  struct target_sockaddr_in {
> -  uint16_t sin_family;
> -  int16_t sin_port; /* big endian */
> +  abi_ushort sin_family;
> +  abi_short sin_port; /* big endian */
>    struct target_in_addr sin_addr;
>    uint8_t __pad[sizeof(struct target_sockaddr) -
> -                sizeof(uint16_t) - sizeof(int16_t) -
> +                sizeof(abi_ushort) - sizeof(abi_short) -
>                  sizeof(struct target_in_addr)];
>  };
>  
>  struct target_sockaddr_in6 {
> -    uint16_t sin6_family;
> -    uint16_t sin6_port; /* big endian */
> -    uint32_t sin6_flowinfo; /* big endian */
> +    abi_ushort sin6_family;
> +    abi_ushort sin6_port; /* big endian */
> +    abi_uint sin6_flowinfo; /* big endian */
>      struct in6_addr sin6_addr; /* IPv6 address, big endian */
> -    uint32_t sin6_scope_id;
> +    abi_uint sin6_scope_id;
>  };
>  
>  struct target_sock_filter {
> 

Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Laurent Vivier Oct. 21, 2019, 1:29 p.m. UTC | #2
Le 21/10/2019 à 13:48, Philippe Mathieu-Daudé a écrit :
> Target architectures align types differently for instance m68k
> aligns on 16bit whereas others on 32bit).
> Use ABI types to keep alignments good.
> 
> Suggested-by: Laurent Vivier <laurent@vivier.eu>
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> v8: Use abi_int for target_sockaddr_ll.sll_ifindex
> ---
>  linux-user/syscall_defs.h | 34 +++++++++++++++++-----------------
>  1 file changed, 17 insertions(+), 17 deletions(-)
> 
> diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
> index 7694d72446..98c2119de9 100644
> --- a/linux-user/syscall_defs.h
> +++ b/linux-user/syscall_defs.h
> @@ -134,22 +134,22 @@
>  #define TARGET_IOWRU(type,nr)	TARGET_IOC(TARGET_IOC_READ|TARGET_IOC_WRITE,(type),(nr),TARGET_IOC_SIZEMASK)
>  
>  struct target_sockaddr {
> -    uint16_t sa_family;
> +    abi_ushort sa_family;
>      uint8_t sa_data[14];
>  };
>  
>  struct target_sockaddr_ll {
> -    uint16_t sll_family;   /* Always AF_PACKET */
> -    uint16_t sll_protocol; /* Physical layer protocol */
> -    int      sll_ifindex;  /* Interface number */
> -    uint16_t sll_hatype;   /* ARP hardware type */
> -    uint8_t  sll_pkttype;  /* Packet type */
> -    uint8_t  sll_halen;    /* Length of address */
> -    uint8_t  sll_addr[8];  /* Physical layer address */
> +    abi_ushort sll_family;   /* Always AF_PACKET */
> +    abi_ushort sll_protocol; /* Physical layer protocol */
> +    abi_int    sll_ifindex;  /* Interface number */
> +    abi_ushort sll_hatype;   /* ARP hardware type */
> +    uint8_t    sll_pkttype;  /* Packet type */
> +    uint8_t    sll_halen;    /* Length of address */
> +    uint8_t    sll_addr[8];  /* Physical layer address */
>  };
>  
>  struct target_sockaddr_un {
> -    uint16_t su_family;
> +    abi_ushort su_family;
>      uint8_t sun_path[108];
>  };
>  
> @@ -161,24 +161,24 @@ struct target_sockaddr_nl {
>  };
>  
>  struct target_in_addr {
> -    uint32_t s_addr; /* big endian */
> +    abi_uint s_addr; /* big endian */
>  };
>  
>  struct target_sockaddr_in {
> -  uint16_t sin_family;
> -  int16_t sin_port; /* big endian */
> +  abi_ushort sin_family;
> +  abi_short sin_port; /* big endian */
>    struct target_in_addr sin_addr;
>    uint8_t __pad[sizeof(struct target_sockaddr) -
> -                sizeof(uint16_t) - sizeof(int16_t) -
> +                sizeof(abi_ushort) - sizeof(abi_short) -
>                  sizeof(struct target_in_addr)];
>  };
>  
>  struct target_sockaddr_in6 {
> -    uint16_t sin6_family;
> -    uint16_t sin6_port; /* big endian */
> -    uint32_t sin6_flowinfo; /* big endian */
> +    abi_ushort sin6_family;
> +    abi_ushort sin6_port; /* big endian */
> +    abi_uint sin6_flowinfo; /* big endian */
>      struct in6_addr sin6_addr; /* IPv6 address, big endian */
> -    uint32_t sin6_scope_id;
> +    abi_uint sin6_scope_id;
>  };
>  
>  struct target_sock_filter {
> 

Applied to my linux-user branch.

Thanks,
Laurent

Patch
diff mbox series

diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h
index 7694d72446..98c2119de9 100644
--- a/linux-user/syscall_defs.h
+++ b/linux-user/syscall_defs.h
@@ -134,22 +134,22 @@ 
 #define TARGET_IOWRU(type,nr)	TARGET_IOC(TARGET_IOC_READ|TARGET_IOC_WRITE,(type),(nr),TARGET_IOC_SIZEMASK)
 
 struct target_sockaddr {
-    uint16_t sa_family;
+    abi_ushort sa_family;
     uint8_t sa_data[14];
 };
 
 struct target_sockaddr_ll {
-    uint16_t sll_family;   /* Always AF_PACKET */
-    uint16_t sll_protocol; /* Physical layer protocol */
-    int      sll_ifindex;  /* Interface number */
-    uint16_t sll_hatype;   /* ARP hardware type */
-    uint8_t  sll_pkttype;  /* Packet type */
-    uint8_t  sll_halen;    /* Length of address */
-    uint8_t  sll_addr[8];  /* Physical layer address */
+    abi_ushort sll_family;   /* Always AF_PACKET */
+    abi_ushort sll_protocol; /* Physical layer protocol */
+    abi_int    sll_ifindex;  /* Interface number */
+    abi_ushort sll_hatype;   /* ARP hardware type */
+    uint8_t    sll_pkttype;  /* Packet type */
+    uint8_t    sll_halen;    /* Length of address */
+    uint8_t    sll_addr[8];  /* Physical layer address */
 };
 
 struct target_sockaddr_un {
-    uint16_t su_family;
+    abi_ushort su_family;
     uint8_t sun_path[108];
 };
 
@@ -161,24 +161,24 @@  struct target_sockaddr_nl {
 };
 
 struct target_in_addr {
-    uint32_t s_addr; /* big endian */
+    abi_uint s_addr; /* big endian */
 };
 
 struct target_sockaddr_in {
-  uint16_t sin_family;
-  int16_t sin_port; /* big endian */
+  abi_ushort sin_family;
+  abi_short sin_port; /* big endian */
   struct target_in_addr sin_addr;
   uint8_t __pad[sizeof(struct target_sockaddr) -
-                sizeof(uint16_t) - sizeof(int16_t) -
+                sizeof(abi_ushort) - sizeof(abi_short) -
                 sizeof(struct target_in_addr)];
 };
 
 struct target_sockaddr_in6 {
-    uint16_t sin6_family;
-    uint16_t sin6_port; /* big endian */
-    uint32_t sin6_flowinfo; /* big endian */
+    abi_ushort sin6_family;
+    abi_ushort sin6_port; /* big endian */
+    abi_uint sin6_flowinfo; /* big endian */
     struct in6_addr sin6_addr; /* IPv6 address, big endian */
-    uint32_t sin6_scope_id;
+    abi_uint sin6_scope_id;
 };
 
 struct target_sock_filter {