diff mbox series

[09/22] Implement ipc_perm conversion between host and target.

Message ID 20230819094806.14965-10-kariem.taha2.7@gmail.com
State New
Headers show
Series Implement the mmap system call for FreeBSD. | expand

Commit Message

Karim Taha Aug. 19, 2023, 9:47 a.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-mem.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

Comments

Warner Losh Aug. 20, 2023, 4:23 a.m. UTC | #1
On Sat, Aug 19, 2023 at 3:48 AM Karim Taha <kariem.taha2.7@gmail.com> 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-mem.c | 41 +++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 41 insertions(+)
>

Reviewed-by: Warner Losh <imp@bsdimp.com>


> diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c
> index 6c123abf04..e69250cc0d 100644
> --- a/bsd-user/bsd-mem.c
> +++ b/bsd-user/bsd-mem.c
> @@ -36,3 +36,44 @@ void target_set_brk(abi_ulong new_brk)
>      bsd_target_original_brk = bsd_target_brk = HOST_PAGE_ALIGN(new_brk);
>      brk_page = HOST_PAGE_ALIGN(bsd_target_brk);
>  }
> +
> +abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip,
> +        abi_ulong target_addr)
> +{
> +    struct target_ipc_perm *target_ip;
> +
> +    if (!lock_user_struct(VERIFY_READ, target_ip, target_addr, 1)) {
> +        return -TARGET_EFAULT;
> +    }
> +    __get_user(host_ip->cuid, &target_ip->cuid);
> +    __get_user(host_ip->cgid, &target_ip->cgid);
> +    __get_user(host_ip->uid, &target_ip->uid);
> +    __get_user(host_ip->gid, &target_ip->gid);
> +    __get_user(host_ip->mode, &target_ip->mode);
> +    __get_user(host_ip->seq, &target_ip->seq);
> +    __get_user(host_ip->key, &target_ip->key);
> +    unlock_user_struct(target_ip, target_addr, 0);
> +
> +    return 0;
> +}
> +
> +abi_long host_to_target_ipc_perm(abi_ulong target_addr,
> +        struct ipc_perm *host_ip)
> +{
> +    struct target_ipc_perm *target_ip;
> +
> +    if (!lock_user_struct(VERIFY_WRITE, target_ip, target_addr, 0)) {
> +        return -TARGET_EFAULT;
> +    }
> +    __put_user(host_ip->cuid, &target_ip->cuid);
> +    __put_user(host_ip->cgid, &target_ip->cgid);
> +    __put_user(host_ip->uid, &target_ip->uid);
> +    __put_user(host_ip->gid, &target_ip->gid);
> +    __put_user(host_ip->mode, &target_ip->mode);
> +    __put_user(host_ip->seq, &target_ip->seq);
> +    __put_user(host_ip->key, &target_ip->key);
> +    unlock_user_struct(target_ip, target_addr, 1);
> +
> +    return 0;
> +}
> +
> --
> 2.40.0
>
>
Richard Henderson Aug. 20, 2023, 2:16 p.m. UTC | #2
On 8/19/23 02:47, 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-mem.c | 41 +++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 41 insertions(+)

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

r~
diff mbox series

Patch

diff --git a/bsd-user/bsd-mem.c b/bsd-user/bsd-mem.c
index 6c123abf04..e69250cc0d 100644
--- a/bsd-user/bsd-mem.c
+++ b/bsd-user/bsd-mem.c
@@ -36,3 +36,44 @@  void target_set_brk(abi_ulong new_brk)
     bsd_target_original_brk = bsd_target_brk = HOST_PAGE_ALIGN(new_brk);
     brk_page = HOST_PAGE_ALIGN(bsd_target_brk);
 }
+
+abi_long target_to_host_ipc_perm(struct ipc_perm *host_ip,
+        abi_ulong target_addr)
+{
+    struct target_ipc_perm *target_ip;
+
+    if (!lock_user_struct(VERIFY_READ, target_ip, target_addr, 1)) {
+        return -TARGET_EFAULT;
+    }
+    __get_user(host_ip->cuid, &target_ip->cuid);
+    __get_user(host_ip->cgid, &target_ip->cgid);
+    __get_user(host_ip->uid, &target_ip->uid);
+    __get_user(host_ip->gid, &target_ip->gid);
+    __get_user(host_ip->mode, &target_ip->mode);
+    __get_user(host_ip->seq, &target_ip->seq);
+    __get_user(host_ip->key, &target_ip->key);
+    unlock_user_struct(target_ip, target_addr, 0);
+
+    return 0;
+}
+
+abi_long host_to_target_ipc_perm(abi_ulong target_addr,
+        struct ipc_perm *host_ip)
+{
+    struct target_ipc_perm *target_ip;
+
+    if (!lock_user_struct(VERIFY_WRITE, target_ip, target_addr, 0)) {
+        return -TARGET_EFAULT;
+    }
+    __put_user(host_ip->cuid, &target_ip->cuid);
+    __put_user(host_ip->cgid, &target_ip->cgid);
+    __put_user(host_ip->uid, &target_ip->uid);
+    __put_user(host_ip->gid, &target_ip->gid);
+    __put_user(host_ip->mode, &target_ip->mode);
+    __put_user(host_ip->seq, &target_ip->seq);
+    __put_user(host_ip->key, &target_ip->key);
+    unlock_user_struct(target_ip, target_addr, 1);
+
+    return 0;
+}
+