diff mbox series

[06/22] Implement shm_rename(2) system call

Message ID 20230819094806.14965-7-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: Kyle Evans <kevans@FreeBSD.org>

Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
---
 bsd-user/freebsd/os-misc.h    | 24 ++++++++++++++++++++++++
 bsd-user/freebsd/os-syscall.c |  6 ++++++
 2 files changed, 30 insertions(+)

Comments

Warner Losh Aug. 20, 2023, 4:18 a.m. UTC | #1
On Sat, Aug 19, 2023 at 3:48 AM Karim Taha <kariem.taha2.7@gmail.com> wrote:

> From: Kyle Evans <kevans@FreeBSD.org>
>
> Signed-off-by: Kyle Evans <kevans@FreeBSD.org>
> Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
> ---
>  bsd-user/freebsd/os-misc.h    | 24 ++++++++++++++++++++++++
>  bsd-user/freebsd/os-syscall.c |  6 ++++++
>  2 files changed, 30 insertions(+)
>

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

The FreeBSD 13 ifdef below still is needed since FreeBSD 12 is still
supported by the
project until the end of the year.


> diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h
> index 993e4598f9..3509ef026e 100644
> --- a/bsd-user/freebsd/os-misc.h
> +++ b/bsd-user/freebsd/os-misc.h
> @@ -76,5 +76,29 @@ static inline abi_long do_freebsd_shm_open2(abi_ulong
> pathptr, abi_ulong flags,
>  #undef SHM_PATH
>  #endif /* __FreeBSD_version >= 1300048 */
>
> +#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049
> +/* shm_rename(2) */
> +static inline abi_long do_freebsd_shm_rename(abi_ulong fromptr, abi_ulong
> toptr,
> +        abi_ulong flags)
> +{
> +    int ret;
> +    void *ufrom, *uto;
> +
> +    ufrom = lock_user_string(fromptr);
> +    if (ufrom == NULL) {
> +        return -TARGET_EFAULT;
> +    }
> +    uto = lock_user_string(toptr);
> +    if (uto == NULL) {
> +        unlock_user(ufrom, fromptr, 0);
> +        return -TARGET_EFAULT;
> +    }
> +    ret = get_errno(shm_rename(ufrom, uto, flags));
> +    unlock_user(ufrom, fromptr, 0);
> +    unlock_user(uto, toptr, 0);
> +
> +    return ret;
> +}
> +#endif /* __FreeBSD_version >= 1300049 */
>
>  #endif /* OS_MISC_H */
> diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
> index b4311db578..2920370ad2 100644
> --- a/bsd-user/freebsd/os-syscall.c
> +++ b/bsd-user/freebsd/os-syscall.c
> @@ -495,6 +495,12 @@ static abi_long freebsd_syscall(void *cpu_env, int
> num, abi_long arg1,
>          break;
>  #endif
>
> +#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049
> +    case TARGET_FREEBSD_NR_shm_rename: /* shm_rename(2) */
> +        ret = do_freebsd_shm_rename(arg1, arg2, arg3);
> +        break;
> +#endif
> +
>          /*
>           * sys{ctl, arch, call}
>           */
> --
> 2.40.0
>
>
Richard Henderson Aug. 20, 2023, 2:05 p.m. UTC | #2
On 8/19/23 02:47, Karim Taha wrote:
> From: Kyle Evans<kevans@FreeBSD.org>
> 
> Signed-off-by: Kyle Evans<kevans@FreeBSD.org>
> Signed-off-by: Karim Taha<kariem.taha2.7@gmail.com>
> ---
>   bsd-user/freebsd/os-misc.h    | 24 ++++++++++++++++++++++++
>   bsd-user/freebsd/os-syscall.c |  6 ++++++
>   2 files changed, 30 insertions(+)

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

r~
diff mbox series

Patch

diff --git a/bsd-user/freebsd/os-misc.h b/bsd-user/freebsd/os-misc.h
index 993e4598f9..3509ef026e 100644
--- a/bsd-user/freebsd/os-misc.h
+++ b/bsd-user/freebsd/os-misc.h
@@ -76,5 +76,29 @@  static inline abi_long do_freebsd_shm_open2(abi_ulong pathptr, abi_ulong flags,
 #undef SHM_PATH
 #endif /* __FreeBSD_version >= 1300048 */
 
+#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049
+/* shm_rename(2) */
+static inline abi_long do_freebsd_shm_rename(abi_ulong fromptr, abi_ulong toptr,
+        abi_ulong flags)
+{
+    int ret;
+    void *ufrom, *uto;
+
+    ufrom = lock_user_string(fromptr);
+    if (ufrom == NULL) {
+        return -TARGET_EFAULT;
+    }
+    uto = lock_user_string(toptr);
+    if (uto == NULL) {
+        unlock_user(ufrom, fromptr, 0);
+        return -TARGET_EFAULT;
+    }
+    ret = get_errno(shm_rename(ufrom, uto, flags));
+    unlock_user(ufrom, fromptr, 0);
+    unlock_user(uto, toptr, 0);
+
+    return ret;
+}
+#endif /* __FreeBSD_version >= 1300049 */
 
 #endif /* OS_MISC_H */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index b4311db578..2920370ad2 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -495,6 +495,12 @@  static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 
+#if defined(__FreeBSD_version) && __FreeBSD_version >= 1300049
+    case TARGET_FREEBSD_NR_shm_rename: /* shm_rename(2) */
+        ret = do_freebsd_shm_rename(arg1, arg2, arg3);
+        break;
+#endif
+
         /*
          * sys{ctl, arch, call}
          */