linux-user/syscall: xtensa: fix target_msqid_ds and ipc_perm conversion
PATCH 1/1 linux-user/syscall: xtensa: fix target_msqid_ds and ipc_perm conversion
- target_ipc_perm::mode and target_ipc_perm::__seq fields are 32-bit wide on xtensa and thus need to use tswap32
- target_msqid_ds::msg_*time field pairs are reversed on big-endian xtensa
Both issues result in incorrect conversion results on big-endian xtensa targets, spotted by the libc-test http://nsz.repo.hu/git/?p=libc-test
--- linux-user/syscall.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
linux-user/syscall.c +15 -4
@@ -3758,12 +3758,13 @@ static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip, host_ip->gid =tswap32 (target_ip->gid); host_ip->cuid =tswap32 (target_ip->cuid); host_ip->cgid =tswap32 (target_ip->cgid); -#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_PPC ) +#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_PPC ) || \ + defined(TARGET_XTENSA ) host_ip->mode =tswap32 (target_ip->mode);#else host_ip->mode =tswap16 (target_ip->mode);#endif -#if defined(TARGET_PPC ) +#if defined(TARGET_PPC ) || defined(TARGET_XTENSA ) host_ip->__seq =tswap32 (target_ip->__seq);#else host_ip->__seq =tswap16 (target_ip->__seq);
@@ -3786,12 +3787,13 @@ static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr, target_ip->gid =tswap32 (host_ip->gid); target_ip->cuid =tswap32 (host_ip->cuid); target_ip->cgid =tswap32 (host_ip->cgid); -#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_PPC ) +#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_PPC ) || \ + defined(TARGET_XTENSA ) target_ip->mode =tswap32 (host_ip->mode);#else target_ip->mode =tswap16 (host_ip->mode);#endif -#if defined(TARGET_PPC ) +#if defined(TARGET_PPC ) || defined(TARGET_XTENSA ) target_ip->__seq =tswap32 (host_ip->__seq);#else target_ip->__seq =tswap16 (host_ip->__seq);
@@ -4111,6 +4113,14 @@ static inline abi_long do_semtimedop(int semid,struct target_msqid_ds {struct target_ipc_perm msg_perm; +#if defined(TARGET_XTENSA ) &&TARGET_BIG_ENDIAN +abi_ulong __unused1; +abi_ulong msg_stime; +abi_ulong __unused2; +abi_ulong msg_rtime; +abi_ulong __unused3; +abi_ulong msg_ctime; +#else abi_ulong msg_stime;#if TARGET_ABI_BITS ==32 abi_ulong __unused1;
@@ -4122,6 +4132,7 @@ struct target_msqid_dsabi_ulong msg_ctime;#if TARGET_ABI_BITS ==32 abi_ulong __unused3; +#endif #endif abi_ulong __msg_cbytes;abi_ulong msg_qnum;
Signature · 1 line
2.39.2
Hi Max,
Quoted 4 lines · Max Filippov
-
target_ipc_perm::modeandtarget_ipc_perm::__seqfields are 32-bit wide on xtensa and thus need to use tswap32
- target_msqid_ds::msg_*time field pairs are reversed on big-endian xtensa
Please split in 2 distinct patches.
Quoted 47 lines
Both issues result in incorrect conversion results on big-endian xtensa targets, spotted by the libc-test http://nsz.repo.hu/git/?p=libc-test
Fixes a3da8be5126b ("target/xtensa: linux-user: fix sysv IPC structures")Signed-off-by Max Filippov <[email protected]>--- linux-user/syscall.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)linux-user/syscall.c +6
-4@@ -3758,12 +3758,13 @@ static inline abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip, host_ip->gid =tswap32 (target_ip->gid); host_ip->cuid =tswap32 (target_ip->cuid); host_ip->cgid =tswap32 (target_ip->cgid); -#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_PPC ) +#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_PPC ) || \ + defined(TARGET_XTENSA ) host_ip->mode =tswap32 (target_ip->mode);#else host_ip->mode =tswap16 (target_ip->mode);#endif -#if defined(TARGET_PPC ) +#if defined(TARGET_PPC ) || defined(TARGET_XTENSA ) host_ip->__seq =tswap32 (target_ip->__seq);#else host_ip->__seq =tswap16 (target_ip->__seq);@@ -3786,12 +3787,13 @@ static inline abi_long host_to_target_ipc_perm(abi_ulong target_addr, target_ip->gid =tswap32 (host_ip->gid); target_ip->cuid =tswap32 (host_ip->cuid); target_ip->cgid =tswap32 (host_ip->cgid); -#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_PPC ) +#if defined(TARGET_ALPHA ) || defined(TARGET_MIPS ) || defined(TARGET_PPC ) || \ + defined(TARGET_XTENSA ) target_ip->mode =tswap32 (host_ip->mode);#else target_ip->mode =tswap16 (host_ip->mode);#endif -#if defined(TARGET_PPC ) +#if defined(TARGET_PPC ) || defined(TARGET_XTENSA ) target_ip->__seq =tswap32 (host_ip->__seq);#else target_ip->__seq =tswap16 (host_ip->__seq);
linux-user/syscall.c static inline abi_long do_semtimedop(int semid, · line 4116
Quoted 4 lines
linux-user/syscall.c +1
-0@@ -4111,6 +4113,14 @@ static inline abi_long do_semtimedop(int semid,struct target_msqid_ds {struct target_ipc_perm msg_perm; +#if defined(TARGET_XTENSA ) &&TARGET_BIG_ENDIAN
Why restrict to only Xtensa here?
Quoted 18 lines
linux-user/syscall.c +8
-0+abi_ulong __unused1; +abi_ulong msg_stime; +abi_ulong __unused2; +abi_ulong msg_rtime; +abi_ulong __unused3; +abi_ulong msg_ctime; +#else abi_ulong msg_stime;#if TARGET_ABI_BITS ==32 abi_ulong __unused1;@@ -4122,6 +4132,7 @@ struct target_msqid_dsabi_ulong msg_ctime;#if TARGET_ABI_BITS ==32 abi_ulong __unused3; +#endif #endif abi_ulong __msg_cbytes;abi_ulong msg_qnum;
Quoted 10 lines · Philippe Mathieu-Daudé
Hi Max,
Quoted 4 lines · Max Filippov
-
target_ipc_perm::modeandtarget_ipc_perm::__seqfields are 32-bit wide on xtensa and thus need to use tswap32
- target_msqid_ds::msg_*time field pairs are reversed on big-endian xtensaPlease split in 2 distinct patches.
Ok.
Quoted 6 lines
Quoted 4 lines
struct
target_msqid_ds{ struct target_ipc_perm msg_perm;+#if
defined(TARGET_XTENSA)&&TARGET_BIG_ENDIANWhy restrict to only Xtensa here?
I have detected and tested it on xtensa.
I see other architectures (mips, parisc, ppc, sparc) that may need that, but AFAICS it's not that it's applicable for all big endians.
Quoted 7 lines
Quoted 7 lines
linux-user/syscall.c +7
-0+abi_ulong __unused1; +abi_ulong msg_stime; +abi_ulong __unused2; +abi_ulong msg_rtime; +abi_ulong __unused3; +abi_ulong msg_ctime; +#else
Signature · 2 lines
Thanks. -- Max