All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5] linux-user: Add close_range() syscall
@ 2022-10-25  2:34 Helge Deller
  2022-10-25  5:30 ` Richard Henderson
  2022-11-02 16:17 ` Laurent Vivier
  0 siblings, 2 replies; 3+ messages in thread
From: Helge Deller @ 2022-10-25  2:34 UTC (permalink / raw)
  To: Laurent Vivier, qemu-devel, Richard Henderson; +Cc: Helge Deller

Signed-off-by: Helge Deller <deller@gmx.de>
---
Changes:
v5: Simplify check of arg2 against target_fd_max even more
v4: Fix check of arg2
v3: fd_trans_unregister() only called if close_range() doesn't fail
v2: consider CLOSE_RANGE_CLOEXEC flag

diff --git a/linux-user/strace.list b/linux-user/strace.list
index a87415bf3d..78796266e8 100644
--- a/linux-user/strace.list
+++ b/linux-user/strace.list
@@ -103,6 +103,9 @@
 #ifdef TARGET_NR_close
 { TARGET_NR_close, "close" , "%s(%d)", NULL, NULL },
 #endif
+#ifdef TARGET_NR_close_range
+{ TARGET_NR_close_range, "close_range" , "%s(%u,%u,%u)", NULL, NULL },
+#endif
 #ifdef TARGET_NR_connect
 { TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL },
 #endif
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 2e954d8dbd..c51d619a5c 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -338,6 +338,13 @@ _syscall3(int,sys_syslog,int,type,char*,bufp,int,len)
 #ifdef __NR_exit_group
 _syscall1(int,exit_group,int,error_code)
 #endif
+#if defined(__NR_close_range) && defined(TARGET_NR_close_range)
+#define __NR_sys_close_range __NR_close_range
+_syscall3(int,sys_close_range,int,first,int,last,int,flags)
+#ifndef CLOSE_RANGE_CLOEXEC
+#define CLOSE_RANGE_CLOEXEC     (1U << 2)
+#endif
+#endif
 #if defined(__NR_futex)
 _syscall6(int,sys_futex,int *,uaddr,int,op,int,val,
           const struct timespec *,timeout,int *,uaddr2,int,val3)
@@ -8699,6 +8706,18 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
     case TARGET_NR_close:
         fd_trans_unregister(arg1);
         return get_errno(close(arg1));
+#if defined(__NR_close_range) && defined(TARGET_NR_close_range)
+    case TARGET_NR_close_range:
+        ret = get_errno(sys_close_range(arg1, arg2, arg3));
+        if (ret == 0 && !(arg3 & CLOSE_RANGE_CLOEXEC)) {
+            abi_long fd, maxfd;
+            maxfd = MIN(arg2, target_fd_max);
+            for (fd = arg1; fd < maxfd; fd++) {
+                fd_trans_unregister(fd);
+            }
+        }
+        return ret;
+#endif

     case TARGET_NR_brk:
         return do_brk(arg1);


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v5] linux-user: Add close_range() syscall
  2022-10-25  2:34 [PATCH v5] linux-user: Add close_range() syscall Helge Deller
@ 2022-10-25  5:30 ` Richard Henderson
  2022-11-02 16:17 ` Laurent Vivier
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2022-10-25  5:30 UTC (permalink / raw)
  To: Helge Deller, Laurent Vivier, qemu-devel

On 10/25/22 12:34, Helge Deller wrote:
> Signed-off-by: Helge Deller<deller@gmx.de>
> ---
> Changes:
> v5: Simplify check of arg2 against target_fd_max even more
> v4: Fix check of arg2
> v3: fd_trans_unregister() only called if close_range() doesn't fail
> v2: consider CLOSE_RANGE_CLOEXEC flag

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

r~


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v5] linux-user: Add close_range() syscall
  2022-10-25  2:34 [PATCH v5] linux-user: Add close_range() syscall Helge Deller
  2022-10-25  5:30 ` Richard Henderson
@ 2022-11-02 16:17 ` Laurent Vivier
  1 sibling, 0 replies; 3+ messages in thread
From: Laurent Vivier @ 2022-11-02 16:17 UTC (permalink / raw)
  To: Helge Deller, qemu-devel, Richard Henderson

Le 25/10/2022 à 04:34, Helge Deller a écrit :
> Signed-off-by: Helge Deller <deller@gmx.de>
> ---
> Changes:
> v5: Simplify check of arg2 against target_fd_max even more
> v4: Fix check of arg2
> v3: fd_trans_unregister() only called if close_range() doesn't fail
> v2: consider CLOSE_RANGE_CLOEXEC flag
> 
> diff --git a/linux-user/strace.list b/linux-user/strace.list
> index a87415bf3d..78796266e8 100644
> --- a/linux-user/strace.list
> +++ b/linux-user/strace.list
> @@ -103,6 +103,9 @@
>   #ifdef TARGET_NR_close
>   { TARGET_NR_close, "close" , "%s(%d)", NULL, NULL },
>   #endif
> +#ifdef TARGET_NR_close_range
> +{ TARGET_NR_close_range, "close_range" , "%s(%u,%u,%u)", NULL, NULL },
> +#endif
>   #ifdef TARGET_NR_connect
>   { TARGET_NR_connect, "connect" , "%s(%d,%#x,%d)", NULL, NULL },
>   #endif
> diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> index 2e954d8dbd..c51d619a5c 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -338,6 +338,13 @@ _syscall3(int,sys_syslog,int,type,char*,bufp,int,len)
>   #ifdef __NR_exit_group
>   _syscall1(int,exit_group,int,error_code)
>   #endif
> +#if defined(__NR_close_range) && defined(TARGET_NR_close_range)
> +#define __NR_sys_close_range __NR_close_range
> +_syscall3(int,sys_close_range,int,first,int,last,int,flags)
> +#ifndef CLOSE_RANGE_CLOEXEC
> +#define CLOSE_RANGE_CLOEXEC     (1U << 2)
> +#endif
> +#endif
>   #if defined(__NR_futex)
>   _syscall6(int,sys_futex,int *,uaddr,int,op,int,val,
>             const struct timespec *,timeout,int *,uaddr2,int,val3)
> @@ -8699,6 +8706,18 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
>       case TARGET_NR_close:
>           fd_trans_unregister(arg1);
>           return get_errno(close(arg1));
> +#if defined(__NR_close_range) && defined(TARGET_NR_close_range)
> +    case TARGET_NR_close_range:
> +        ret = get_errno(sys_close_range(arg1, arg2, arg3));
> +        if (ret == 0 && !(arg3 & CLOSE_RANGE_CLOEXEC)) {
> +            abi_long fd, maxfd;
> +            maxfd = MIN(arg2, target_fd_max);
> +            for (fd = arg1; fd < maxfd; fd++) {
> +                fd_trans_unregister(fd);
> +            }
> +        }
> +        return ret;
> +#endif
> 
>       case TARGET_NR_brk:
>           return do_brk(arg1);
> 

Applied to my linux-user-for-7.2 branch.

Thanks,
Laurent




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-02 16:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25  2:34 [PATCH v5] linux-user: Add close_range() syscall Helge Deller
2022-10-25  5:30 ` Richard Henderson
2022-11-02 16:17 ` Laurent Vivier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.