[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 04/12] bsd-user: various helper routines for sysctl
From: |
Richard Henderson |
Subject: |
Re: [PATCH v2 04/12] bsd-user: various helper routines for sysctl |
Date: |
Tue, 14 Feb 2023 10:52:49 -1000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 |
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~
- [PATCH v2 00/12] 2023 Q1 bsd-user upstreaming: bugfixes and sysctl, Warner Losh, 2023/02/13
- [PATCH v2 01/12] bsd-user: Don't truncate the return value from freebsd_syscall, Warner Losh, 2023/02/13
- [PATCH v2 02/12] build: Don't specify -no-pie for --static user-mode programs, Warner Losh, 2023/02/13
- [PATCH v2 03/12] bsd-user: Add sysarch syscall, Warner Losh, 2023/02/13
- [PATCH v2 05/12] bsd-user: Helper routines oidfmt, Warner Losh, 2023/02/13
- [PATCH v2 04/12] bsd-user: various helper routines for sysctl, Warner Losh, 2023/02/13
- Re: [PATCH v2 04/12] bsd-user: various helper routines for sysctl,
Richard Henderson <=
- [PATCH v2 07/12] bsd-user: sysctl helper funtions: sysctl_name2oid and sysctl_oidfmt, Warner Losh, 2023/02/13
- [PATCH v2 08/12] bsd-user: common routine do_freebsd_sysctl_oid for all sysctl variants, Warner Losh, 2023/02/13
- [PATCH v2 09/12] bsd-user: Start translation of arch-specific sysctls, Warner Losh, 2023/02/13
- [PATCH v2 12/12] bsd-user: Add -strict, Warner Losh, 2023/02/13