qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 06/12] bsd-user: Helper routines h2t_old_sysctl


From: Richard Henderson
Subject: Re: [PATCH v2 06/12] bsd-user: Helper routines h2t_old_sysctl
Date: Tue, 14 Feb 2023 11:16:50 -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:
+/*
+ * 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.

+ *
+ * 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.

+    /*
+     * 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().

+        }
+#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();


r~



reply via email to

[Prev in Thread] Current Thread [Next in Thread]