On Tue, Feb 14, 2023 at 1:52 PM Richard Henderson < richard.henderson@linaro.org> wrote: > 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? > Indirectly, yes. For ABI64 we simply don't intercept these sysctl nodes. > > +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() > OK. Easy enough. That was a warning from checkpatch anyway that had slipped my mind. > > + > > + 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(). > Gotcha. > > +#ifdef TARGET_ABI32 > > +static abi_long G_GNUC_UNUSED h2t_long_sat(long l) > > h2g. > OK. > > +{ > > + 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? > Right now they aren't used at all for ABI64... But that's in later patches... We only do special things for LONG or ULONG on ABI32... Otherwise, the normal paths wouldn't call these at all. Warner