On 2/13/23 14:27, Warner Losh wrote:
> +/*
> + * Convert the old value from host to target.
host vs guest is clearer language; "target" gets overloaded, even though still present in
the code base.
OK. Will do. We have that all over the place upstream... I'll start there too...
> + *
> + * For LONG and ULONG on ABI32, we need to 'down convert' the 8 byte quantities
> + * to 4 bytes. The caller setup a buffer in host memory to get this data from
> + * the kernel and pass it to us. We do the down conversion and adjust the length
> + * so the caller knows what to write as the returned length into the target when
> + * it copies the down converted values into the target.
> + *
> + * For normal integral types, we just need to byte swap. No size changes.
> + *
> + * For strings and node data, there's no conversion needed.
> + *
> + * For opaque data, per sysctl OID converts take care of it.
> + */
> +static void G_GNUC_UNUSED h2t_old_sysctl(void *holdp, size_t *holdlen, uint32_t kind)
h2g.
OK.
> + /*
> + * hlen == 0 for CTLTYPE_STRING and CTLTYPE_NODE, which need no conversion
> + * as well as CTLTYPE_OPAQUE, which needs special converters.
> + */
> + if (hlen == 0) {
> + return;
> + }
> +
> + while (len < *holdlen) {
> + if (hlen == tlen) {
> + switch (hlen) {
> + case 1:
> + /* Nothing needed: no byteswapping and assigning in place */
> + break;
> + case 2:
> + *(uint16_t *)tp = tswap16(*(uint16_t *)hp);
> + break;
> + case 4:
> + *(uint32_t *)tp = tswap32(*(uint32_t *)hp);
> + break;
> + case 8:
> + *(uint64_t *)tp = tswap64(*(uint64_t *)hp);
> + break;
> + }
default: g_assert_not_reached().
Ah! I need that in several places... Thanks.
> + }
> +#ifdef TARGET_ABI32
> + else {
> + /*
> + * Saturating assignment for the only two types that differ between
> + * 32-bit and 64-bit machines. All other integral types have the
> + * same, fixed size and will be converted w/o loss of precision
> + * in the above switch.
> + */
> + switch (kind & CTLTYPE) {
> + case CTLTYPE_LONG:
> + *(abi_long *)tp = tswap32(h2t_long_sat(*(long *)hp));
> + break;
> + case CTLTYPE_ULONG:
> + *(abi_ulong *)tp = tswap32(h2t_ulong_sat(*(u_long *)hp));
> + break;
> + }
default: g_assert_not_reached().
> + }
> +#endif
#else
g_assert_not_reached();
Gotcha... Thanks!
Warner
r~