Commit d9ab6943ed for qemu.org
commit d9ab6943edd4d124d37347dd6a024e02421b0759
Author: Rick Richard <rick@sloservers.com>
Date: Wed Sep 16 03:46:16 2026 -0700
bsd-user: HOST_BIG_ENDIAN and TARGET_BIG_ENDIAN are always
TARGET_BIG_ENDIAN and HOST_BIG_ENDIAN are always defined.
lseek and target_offset64() transpose upper and lower halves
on 32-bit ABIs, -strace prints wrong off_t.
Signed-off-by: Rick Richard <rick@sloservers.com>
[ fixed defined() too and moved to C if() instead of ifdef ]
Reviewed-by: Warner Losh <imp@bsdimp.com>
Signed-off-by: Warner Losh <imp@bsdimp.com>
diff --git a/bsd-user/bsd-file.h b/bsd-user/bsd-file.h
index 0fefc07232..5c32aa0396 100644
--- a/bsd-user/bsd-file.h
+++ b/bsd-user/bsd-file.h
@@ -973,30 +973,31 @@ static abi_long do_bsd_lseek(CPUArchState *env, abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5)
{
abi_long ret;
-#if TARGET_ABI_BITS == 32
- int64_t res;
- /* 32-bit arch's use two 32 registers for 64 bit return value */
- if (regpairs_aligned(env) != 0) {
- res = lseek(arg1, target_arg64(arg3, arg4), arg5);
- } else {
- res = lseek(arg1, target_arg64(arg2, arg3), arg4);
- }
- if (res == -1) {
- ret = get_errno(res);
- set_second_rval(env, 0xFFFFFFFF);
+ if (TARGET_ABI_BITS == 32) {
+ /* 32-bit arch's use two 32 registers for 64 bit return value */
+ int64_t res;
+
+ if (regpairs_aligned(env) != 0) {
+ res = lseek(arg1, target_arg64(arg3, arg4), arg5);
+ } else {
+ res = lseek(arg1, target_arg64(arg2, arg3), arg4);
+ }
+ if (res == -1) {
+ ret = get_errno(res);
+ set_second_rval(env, 0xFFFFFFFF);
+ } else {
+ if (TARGET_BIG_ENDIAN) {
+ ret = ((res >> 32) & 0xFFFFFFFF);
+ set_second_rval(env, res & 0xFFFFFFFF);
+ } else {
+ ret = res & 0xFFFFFFFF;
+ set_second_rval(env, (res >> 32) & 0xFFFFFFFF);
+ }
+ }
} else {
-#ifdef TARGET_BIG_ENDIAN
- ret = ((res >> 32) & 0xFFFFFFFF);
- set_second_rval(env, res & 0xFFFFFFFF);
-#else
- ret = res & 0xFFFFFFFF;
- set_second_rval(env, (res >> 32) & 0xFFFFFFFF);
-#endif
+ ret = get_errno(lseek(arg1, arg2, arg3));
}
-#else
- ret = get_errno(lseek(arg1, arg2, arg3));
-#endif
return ret;
}
diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h
index 0f87b21cc8..be549c4bd9 100644
--- a/bsd-user/freebsd/os-misc.h
+++ b/bsd-user/freebsd/os-misc.h
@@ -106,19 +106,19 @@ static inline abi_long do_freebsd_cpuset_setid(CPUArchState *env, abi_long arg1,
cpuwhich_t which;
target_to_host_cpuset_which(&which, arg1);
-#if TARGET_ABI_BITS == 32
- /* See if we need to align the register pairs */
- if (regpairs_aligned(env)) {
- id = target_arg64(arg3, arg4);
- setid = arg5;
+ if (TARGET_ABI_BITS == 32) {
+ /* See if we need to align the register pairs */
+ if (regpairs_aligned(env)) {
+ id = target_arg64(arg3, arg4);
+ setid = arg5;
+ } else {
+ id = target_arg64(arg2, arg3);
+ setid = arg4;
+ }
} else {
- id = target_arg64(arg2, arg3);
- setid = arg4;
+ id = arg2;
+ setid = arg3;
}
-#else
- id = arg2;
- setid = arg3;
-#endif
return get_errno(cpuset_setid(which, id, setid));
}
@@ -135,13 +135,13 @@ static inline abi_long do_freebsd_cpuset_getid(abi_long arg1, abi_ulong arg2,
target_to_host_cpuset_which(&which, arg1);
target_to_host_cpuset_level(&level, arg2);
-#if TARGET_ABI_BITS == 32
- id = target_arg64(arg3, arg4);
- target_setid = arg5;
-#else
- id = arg3;
- target_setid = arg4;
-#endif
+ if (TARGET_ABI_BITS == 32) {
+ id = target_arg64(arg3, arg4);
+ target_setid = arg5;
+ } else {
+ id = arg3;
+ target_setid = arg4;
+ }
ret = get_errno(cpuset_getid(level, which, id, &setid));
if (is_error(ret)) {
return ret;
@@ -212,15 +212,15 @@ static inline abi_long do_freebsd_cpuset_getaffinity(cpulevel_t level,
id_t id; /* 64-bit */
abi_ulong setsize, target_mask;
-#if TARGET_ABI_BITS == 32
- id = (id_t)target_arg64(arg3, arg4);
- setsize = arg5;
- target_mask = arg6;
-#else
- id = (id_t)arg3;
- setsize = arg4;
- target_mask = arg5;
-#endif
+ if (TARGET_ABI_BITS == 32) {
+ id = (id_t)target_arg64(arg3, arg4);
+ setsize = arg5;
+ target_mask = arg6;
+ } else {
+ id = (id_t)arg3;
+ setsize = arg4;
+ target_mask = arg5;
+ }
ret = get_errno(cpuset_getaffinity(level, which, id, setsize, &mask));
if (ret == 0) {
@@ -241,15 +241,15 @@ static inline abi_long do_freebsd_cpuset_setaffinity(cpulevel_t level,
id_t id; /* 64-bit */
abi_ulong setsize, target_mask;
-#if TARGET_ABI_BITS == 32
- id = (id_t)target_arg64(arg3, arg4);
- setsize = arg5;
- target_mask = arg6;
-#else
- id = (id_t)arg3;
- setsize = arg4;
- target_mask = arg5;
-#endif
+ if (TARGET_ABI_BITS == 32) {
+ id = (id_t)target_arg64(arg3, arg4);
+ setsize = arg5;
+ target_mask = arg6;
+ } else {
+ id = (id_t)arg3;
+ setsize = arg4;
+ target_mask = arg5;
+ }
ret = copy_from_user_cpuset_mask(&mask, target_mask);
if (ret == 0) {
@@ -333,33 +333,30 @@ static inline abi_long do_freebsd_kldsym(abi_long fileid, abi_long cmd,
* New posix calls
*/
-#if TARGET_ABI_BITS == 32
-static inline uint64_t target_offset64(uint32_t word0, uint32_t word1)
-{
-#ifdef TARGET_BIG_ENDIAN
- return ((uint64_t)word0 << 32) | word1;
-#else
- return ((uint64_t)word1 << 32) | word0;
-#endif
-}
-#else /* TARGET_ABI_BITS == 32 */
static inline uint64_t target_offset64(uint64_t word0, uint64_t word1)
{
- return word0;
+ if (TARGET_ABI_BITS == 32) {
+ if (TARGET_BIG_ENDIAN) {
+ return ((uint64_t)word0 << 32) | word1;
+ } else {
+ return ((uint64_t)word1 << 32) | word0;
+ }
+ } else {
+ return word0;
+ }
}
-#endif /* TARGET_ABI_BITS != 32 */
/* posix_fallocate(2) */
static inline abi_long do_freebsd_posix_fallocate(abi_long arg1, abi_long arg2,
abi_long arg3, abi_long arg4, abi_long arg5, abi_long arg6)
{
-#if TARGET_ABI_BITS == 32
- return get_errno(posix_fallocate(arg1, target_offset64(arg3, arg4),
- target_offset64(arg5, arg6)));
-#else
- return get_errno(posix_fallocate(arg1, arg2, arg3));
-#endif
+ if (TARGET_ABI_BITS == 32) {
+ return get_errno(posix_fallocate(arg1, target_offset64(arg3, arg4),
+ target_offset64(arg5, arg6)));
+ } else {
+ return get_errno(posix_fallocate(arg1, arg2, arg3));
+ }
}
/* posix_openpt(2) */
diff --git a/bsd-user/freebsd/os-thread.h b/bsd-user/freebsd/os-thread.h
index 4258b24095..6552c60337 100644
--- a/bsd-user/freebsd/os-thread.h
+++ b/bsd-user/freebsd/os-thread.h
@@ -18,7 +18,7 @@
int safe_thr_suspend(struct timespec *timeout);
int safe__umtx_op(void *, int, unsigned long, void *, void *);
-#if defined(HOST_BIG_ENDIAN) == defined(TARGET_BIG_ENDIAN) && \
+#if HOST_BIG_ENDIAN == TARGET_BIG_ENDIAN && \
(TARGET_ABI_BITS == HOST_LONG_BITS || defined(UMTX_OP__32BIT))
#define _UMTX_OPTIMIZED
#if defined(TARGET_ABI32)