All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Warner Losh <imp@bsdimp.com>, qemu-devel@nongnu.org
Cc: "Alex Bennée" <alex.bennee@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	kevans@freebsd.org, f4bug@amsat.org,
	"Thomas Huth" <thuth@redhat.com>
Subject: Re: [PATCH v2 04/12] bsd-user: various helper routines for sysctl
Date: Tue, 14 Feb 2023 10:52:49 -1000	[thread overview]
Message-ID: <a36ae3a6-50fa-d969-e9b2-6fe1ff9db9e1@linaro.org> (raw)
In-Reply-To: <20230214002757.99240-5-imp@bsdimp.com>

On 2/13/23 14:27, Warner Losh wrote:
> +#ifdef TARGET_ABI32
> +/*
> + * Limit the amount of available memory to be most of the 32-bit address
> + * space. 0x100c000 was arrived at through trial and error as a good
> + * definition of 'most'.
> + */
> +static const abi_ulong target_max_mem = UINT32_MAX - 0x100c000 + 1;
> +
> +static abi_ulong G_GNUC_UNUSED cap_memory(uint64_t mem)
> +{
> +    if (((unsigned long)target_max_mem) < mem) {
> +        mem = target_max_mem;
> +    }
> +
> +    return mem;
> +}
> +#endif

Identity function for ABI64?

> +static unsigned long host_page_size;
> +
> +static abi_ulong G_GNUC_UNUSED scale_to_target_pages(uint64_t pages)
> +{
> +    if (host_page_size == 0) {
> +        host_page_size = getpagesize();
> +    }

qemu_real_host_page_size()


> +
> +    pages = muldiv64(pages, host_page_size, TARGET_PAGE_SIZE);
> +#ifdef TARGET_ABI32
> +    abi_ulong maxpages = target_max_mem / (abi_ulong)TARGET_PAGE_SIZE;
> +
> +    if (((unsigned long)maxpages) < pages) {
> +        pages = maxpages;
> +    }
> +#endif

No need for either cast.  Just use MIN().

> +#ifdef TARGET_ABI32
> +static abi_long G_GNUC_UNUSED h2t_long_sat(long l)

h2g.

> +{
> +    if (l > INT32_MAX) {
> +        l = INT32_MAX;
> +    } else if (l < INT32_MIN) {
> +        l = INT32_MIN;
> +    }
> +    return l;
> +}
> +
> +static abi_ulong G_GNUC_UNUSED h2t_ulong_sat(u_long ul)
> +{
> +    if (ul > UINT32_MAX) {
> +        ul = UINT32_MAX;
> +    }
> +    return ul;
> +}
> +#endif

Anyway, identity functions for ABI64?


r~


  reply	other threads:[~2023-02-14 20:53 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14  0:27 [PATCH v2 00/12] 2023 Q1 bsd-user upstreaming: bugfixes and sysctl Warner Losh
2023-02-14  0:27 ` [PATCH v2 01/12] bsd-user: Don't truncate the return value from freebsd_syscall Warner Losh
2023-02-14  0:27 ` [PATCH v2 02/12] build: Don't specify -no-pie for --static user-mode programs Warner Losh
2023-02-14  0:27 ` [PATCH v2 03/12] bsd-user: Add sysarch syscall Warner Losh
2023-02-14  0:27 ` [PATCH v2 04/12] bsd-user: various helper routines for sysctl Warner Losh
2023-02-14 20:52   ` Richard Henderson [this message]
2023-02-14 21:31     ` Warner Losh
2023-02-14 21:39       ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 05/12] bsd-user: Helper routines oidfmt Warner Losh
2023-02-14 20:53   ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 06/12] bsd-user: Helper routines h2t_old_sysctl Warner Losh
2023-02-14 21:16   ` Richard Henderson
2023-02-15  5:58     ` Warner Losh
2023-02-14  0:27 ` [PATCH v2 07/12] bsd-user: sysctl helper funtions: sysctl_name2oid and sysctl_oidfmt Warner Losh
2023-02-14 21:18   ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 08/12] bsd-user: common routine do_freebsd_sysctl_oid for all sysctl variants Warner Losh
2023-02-14 21:21   ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 09/12] bsd-user: Start translation of arch-specific sysctls Warner Losh
2023-02-14 21:36   ` Richard Henderson
2023-02-16 22:57     ` Warner Losh
2023-02-14  0:27 ` [PATCH v2 10/12] bsd-user: do_freebsd_sysctl helper for sysctl(2) Warner Losh
2023-02-14 21:45   ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 11/12] bsd-user: implement sysctlbyname(2) Warner Losh
2023-02-14 21:48   ` Richard Henderson
2023-02-14  0:27 ` [PATCH v2 12/12] bsd-user: Add -strict Warner Losh
2023-02-14  6:57   ` Philippe Mathieu-Daudé
2023-02-14 21:49   ` Richard Henderson
2023-02-16 22:37     ` Warner Losh

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=a36ae3a6-50fa-d969-e9b2-6fe1ff9db9e1@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=f4bug@amsat.org \
    --cc=imp@bsdimp.com \
    --cc=kevans@freebsd.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.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.