Skip to contentSkip to conversation

linux-user: Add close_range() syscall

PATCH Applied Helge Deller 2 participants 5 messages Sep 27, 2022

v1 of 5 Applied Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 linux-user: Add close_range() syscall

---
 linux-user/strace.list |  3 +++
 linux-user/syscall.c   | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)
linux-user/strace.list +3 -0
index 2fa74b7203..31a2ccd76d 100644
@@ -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
linux-user/syscall.c +19 -0
index 6219ef36c9..8e0bdd7a30 100644
@@ -339,6 +339,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)
@@ -8756,6 +8763,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:
+        if (!(arg3 & CLOSE_RANGE_CLOEXEC)) {
+            abi_long fd;
+            abi_long maxfd = (arg2 == (abi_long)-1) ? target_fd_max : arg2;
+
+            for (fd = arg1; fd <= maxfd; fd++) {
+                fd_trans_unregister(fd);
+            }
+        }
+        return get_errno(sys_close_range(arg1, arg2, arg3));
+#endif
 
     case TARGET_NR_brk:
         return do_brk(arg1);

--
2.37.3

#1 lore raw

PATCH 2/2 linux-user: Add parameters of getrandom() syscall for strace

---
 linux-user/strace.list | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/strace.list +1 -1
index 31a2ccd76d..9bb234a584 100644
@@ -358,7 +358,7 @@
 { TARGET_NR_getpriority, "getpriority", "%s(%#x,%#x)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getrandom
-{ TARGET_NR_getrandom, "getrandom", NULL, NULL, NULL },
+{ TARGET_NR_getrandom, "getrandom", "%s(%p,%u,%u)", NULL, NULL },
 #endif
 #ifdef TARGET_NR_getresgid
 { TARGET_NR_getresgid, "getresgid" , NULL, NULL, NULL },

--
2.37.3

Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] linux-user: Add parameters of getrandom() syscall for strace

Le 27/09/2022 à 11:35, Helge Deller a écrit :

Quoted 19 lines
---
  linux-user/strace.list | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/strace.list +1 -2
index 31a2ccd76d..9bb234a584 100644
@@ -358,7 +358,7 @@
  { TARGET_NR_getpriority, "getpriority", "%s(%#x,%#x)", NULL, NULL },
  #endif
  #ifdef TARGET_NR_getrandom
-{ TARGET_NR_getrandom, "getrandom", NULL, NULL, NULL },
+{ TARGET_NR_getrandom, "getrandom", "%s(%p,%u,%u)", NULL, NULL },
  #endif
  #ifdef TARGET_NR_getresgid
  { TARGET_NR_getresgid, "getresgid" , NULL, NULL, NULL },
--
Quoted 3 lines

2.37.3

#3 lore raw

Re: [PATCH 2/2] linux-user: Add parameters of getrandom() syscall for strace

In reply to Helge Deller

Le 27/09/2022 à 11:35, Helge Deller a écrit :

Quoted 19 lines
---
  linux-user/strace.list | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/strace.list +1 -2
index 31a2ccd76d..9bb234a584 100644
@@ -358,7 +358,7 @@
  { TARGET_NR_getpriority, "getpriority", "%s(%#x,%#x)", NULL, NULL },
  #endif
  #ifdef TARGET_NR_getrandom
-{ TARGET_NR_getrandom, "getrandom", NULL, NULL, NULL },
+{ TARGET_NR_getrandom, "getrandom", "%s(%p,%u,%u)", NULL, NULL },
  #endif
  #ifdef TARGET_NR_getresgid
  { TARGET_NR_getresgid, "getresgid" , NULL, NULL, NULL },
--
Quoted 3 lines

2.37.3

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

Thanks,
Laurent

#4 lore raw
In reply to Helge Deller

Le 27/09/2022 à 11:35, Helge Deller a écrit :

Quoted 43 lines
---
  linux-user/strace.list |  3 +++
  linux-user/syscall.c   | 19 +++++++++++++++++++
  2 files changed, 22 insertions(+)
linux-user/strace.list +3 -0
index 2fa74b7203..31a2ccd76d 100644
@@ -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
linux-user/syscall.c +8 -0
index 6219ef36c9..8e0bdd7a30 100644
@@ -339,6 +339,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)
@@ -8756,6 +8763,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)

linux-user/syscall.c static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1, · line 8776

Quoted 10 lines
linux-user/syscall.c +10 -0
+    case TARGET_NR_close_range:
+        if (!(arg3 & CLOSE_RANGE_CLOEXEC)) {
+            abi_long fd;
+            abi_long maxfd = (arg2 == (abi_long)-1) ? target_fd_max : arg2;
+
+            for (fd = arg1; fd <= maxfd; fd++) {
+                fd_trans_unregister(fd);
+            }
+        }
+        return get_errno(sys_close_range(arg1, arg2, arg3));

fd_trans_unregister() must called only if close_range() doesn't fail.

Thanks,
Laurent

Quoted 8 lines
linux-user/syscall.c +1 -1
+#endif
 
      case TARGET_NR_brk:
          return do_brk(arg1);
--

2.37.3