diff mbox series

[08/32] bsd-user: Implement target_to_host_rlim and host_to_target_rlim conversion.

Message ID 20230827155746.84781-9-kariem.taha2.7@gmail.com
State New
Headers show
Series bsd-user: Implement freebsd process related system calls. | expand

Commit Message

Karim Taha Aug. 27, 2023, 3:57 p.m. UTC
From: Stacey Son <sson@FreeBSD.org>

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
---
 bsd-user/bsd-proc.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Richard Henderson Aug. 29, 2023, 7:36 p.m. UTC | #1
On 8/27/23 08:57, Karim Taha wrote:
> From: Stacey Son<sson@FreeBSD.org>
> 
> Signed-off-by: Stacey Son<sson@FreeBSD.org>
> Signed-off-by: Karim Taha<kariem.taha2.7@gmail.com>
> ---
>   bsd-user/bsd-proc.c | 33 +++++++++++++++++++++++++++++++++
>   1 file changed, 33 insertions(+)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

> 
> +rlim_t target_to_host_rlim(abi_llong target_rlim)
> +{
> +    abi_llong target_rlim_swap;
> +    rlim_t result;
> +
> +    target_rlim_swap = tswap64(target_rlim);
> +    if (target_rlim_swap == TARGET_RLIM_INFINITY) {
> +        return RLIM_INFINITY;
> +    }
> +
> +    result = target_rlim_swap;
> +    if (target_rlim_swap != (rlim_t)result) {
> +        return RLIM_INFINITY;
> +    }
> +
> +    return result;
> +}
> +
> +abi_llong host_to_target_rlim(rlim_t rlim)
> +{
> +    abi_llong target_rlim_swap;
> +    abi_llong result;
> +
> +    if (rlim == RLIM_INFINITY || rlim != (abi_llong)rlim) {
> +        target_rlim_swap = TARGET_RLIM_INFINITY;
> +    } else {
> +        target_rlim_swap = rlim;
> +    }
> +    result = tswap64(target_rlim_swap);
> +
> +    return result;
> +}

Though I think these are the identity function as well, since afaict we're always talking 
about 64-bit data.


r~
diff mbox series

Patch

diff --git a/bsd-user/bsd-proc.c b/bsd-user/bsd-proc.c
index ae2e636bb3..12e43cfeca 100644
--- a/bsd-user/bsd-proc.c
+++ b/bsd-user/bsd-proc.c
@@ -81,3 +81,36 @@  int target_to_host_resource(int code)
     }
 }
 
+rlim_t target_to_host_rlim(abi_llong target_rlim)
+{
+    abi_llong target_rlim_swap;
+    rlim_t result;
+
+    target_rlim_swap = tswap64(target_rlim);
+    if (target_rlim_swap == TARGET_RLIM_INFINITY) {
+        return RLIM_INFINITY;
+    }
+
+    result = target_rlim_swap;
+    if (target_rlim_swap != (rlim_t)result) {
+        return RLIM_INFINITY;
+    }
+
+    return result;
+}
+
+abi_llong host_to_target_rlim(rlim_t rlim)
+{
+    abi_llong target_rlim_swap;
+    abi_llong result;
+
+    if (rlim == RLIM_INFINITY || rlim != (abi_llong)rlim) {
+        target_rlim_swap = TARGET_RLIM_INFINITY;
+    } else {
+        target_rlim_swap = rlim;
+    }
+    result = tswap64(target_rlim_swap);
+
+    return result;
+}
+