All of lore.kernel.org
 help / color / mirror / Atom feed
From: Warner Losh <imp@bsdimp.com>
To: qemu-devel@nongnu.org
Cc: Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>,
	Rick Richard <rick@sloservers.com>
Subject: [PULL 01/11] bsd-user: HOST_BIG_ENDIAN and TARGET_BIG_ENDIAN are always
Date: Tue, 22 Sep 2026 13:20:59 -0600	[thread overview]
Message-ID: <20260922192109.98467-2-imp@bsdimp.com> (raw)
In-Reply-To: <20260922192109.98467-1-imp@bsdimp.com>

From: Rick Richard <rick@sloservers.com>

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>
---
 bsd-user/bsd-file.h          |  43 +++++++-------
 bsd-user/freebsd/os-misc.h   | 105 +++++++++++++++++------------------
 bsd-user/freebsd/os-thread.h |   2 +-
 3 files changed, 74 insertions(+), 76 deletions(-)

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)
-- 
2.55.0



  reply	other threads:[~2026-09-22 19:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 19:20 [PULL 00/11] Bsd user 2026q3 patches Warner Losh
2026-09-22 19:20 ` Warner Losh [this message]
2026-09-22 19:21 ` [PULL 02/11] bsd-user: Drop support for FreeBSD 12 Warner Losh
2026-09-22 19:21 ` [PULL 03/11] bsd-user: Flag shared memory as needing atomics Warner Losh
2026-09-22 19:21 ` [PULL 04/11] bsd-user: Initialize per-arch child registers Warner Losh
2026-09-22 19:21 ` [PULL 05/11] bsd-user: Fix crazy bug with mmap Warner Losh
2026-09-22 19:21 ` [PULL 06/11] bsd-user: Move tb_flush stuff to begin_parallel_context Warner Losh
2026-09-22 19:21 ` [PULL 07/11] bsd-user: Implement exterrctl(2) Warner Losh
2026-09-22 19:21 ` [PULL 08/11] bsd-user: Implement sigfastblock Warner Losh
2026-09-22 19:21 ` [PULL 09/11] bsd-user: Eliminate unused regs arg in load_elf_binary Warner Losh
2026-09-22 19:21 ` [PULL 10/11] bsd-user: #ifdef sockopt that aren't in 14 Warner Losh
2026-09-22 19:21 ` [PULL 11/11] bsd-user: Remove host-os.h Warner Losh
2026-09-23 19:44 ` [PULL 00/11] Bsd user 2026q3 patches Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260922192109.98467-2-imp@bsdimp.com \
    --to=imp@bsdimp.com \
    --cc=kevans@freebsd.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rick@sloservers.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.