Skip to contentSkip to conversation

linux-user: dup3, fallocate syscalls

PATCH In review Ulrich Hecht 2 participants 3 messages Jul 30, 2009 – Aug 20, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: dup3, fallocate syscalls

implementations of dup3 and fallocate that are good enough to fool LTP

updated fallocate check to new configure, added dup3 check as suggested by Jan-Simon Möller

---
 configure            |   36 ++++++++++++++++++++++++++++++++++++
 linux-user/syscall.c |   12 ++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)
configure +36 -0
index 8160bed..2329f88 100755
@@ -1366,6 +1366,36 @@ if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
   splice=yes
 fi
 
+# check for fallocate
+fallocate=no
+cat > $TMPC << EOF
+#include <fcntl.h>
+
+int main(void)
+{
+    fallocate(0, 0, 0, 0);
+    return 0;
+}
+EOF
+if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
+  fallocate=yes
+fi
+
+# check for dup3
+dup3=no
+cat > $TMPC << EOF
+#include <unistd.h>
+
+int main(void)
+{
+    dup3(0, 0, 0);
+    return 0;
+}
+EOF
+if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
+  dup3=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$build_docs" = "yes" -a \( ! -x "`which texi2html 2>/dev/null`" -o ! -x "`which pod2man 2>/dev/null`" \) ; then
   build_docs="no"
@@ -1639,6 +1669,12 @@ fi
 if test "$splice" = "yes" ; then
   echo "CONFIG_SPLICE=y" >> $config_host_mak
 fi
+if test "$fallocate" = "yes" ; then
+  echo "CONFIG_FALLOCATE=y" >> $config_host_mak
+fi
+if test "$dup3" = "yes" ; then
+  echo "CONFIG_DUP3=y" >> $config_host_mak
+fi
 if test "$inotify" = "yes" ; then
   echo "CONFIG_INOTIFY=y" >> $config_host_mak
 fi
linux-user/syscall.c +12 -0
index 31cf151..d105b8e 100644
@@ -3681,8 +3681,10 @@ static int target_to_host_fcntl_cmd(int cmd)
             return F_SETLEASE;
         case TARGET_F_GETLEASE:
             return F_GETLEASE;
+#ifdef F_DUPFD_CLOEXEC
         case TARGET_F_DUPFD_CLOEXEC:
             return F_DUPFD_CLOEXEC;
+#endif
         case TARGET_F_NOTIFY:
             return F_NOTIFY;
 	default:
@@ -4732,6 +4734,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_dup2:
         ret = get_errno(dup2(arg1, arg2));
         break;
+#if defined(TARGET_NR_dup3) && defined(CONFIG_DUP3)
+    case TARGET_NR_dup3:
+        ret = get_errno(dup3(arg1, arg2, arg3));
+        break;
+#endif
 #ifdef TARGET_NR_getppid /* not on alpha */
     case TARGET_NR_getppid:
         ret = get_errno(getppid());
@@ -6976,6 +6983,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 #endif /* CONFIG_SPLICE */
+#if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
+    case TARGET_NR_fallocate:
+        ret = get_errno(fallocate(arg1, arg2, arg3, arg4));
+        break;
+#endif
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
Signature · 1 line
1.6.2.1
#1 lore raw

Hi,

I quequed the other patches from you execpt this one - The patch didn't apply for me, and a few comments inline:

Quoted 19 lines · Ulrich Hecht

updated fallocate check to new configure, added dup3 check as suggested by Jan-Simon Möller

---
 configure            |   36 ++++++++++++++++++++++++++++++++++++
 linux-user/syscall.c |   12 ++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)
configure +2 -0
index 8160bed..2329f88 100755
@@ -1366,6 +1366,36 @@ if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
   splice=yes
 fi
 
+# check for fallocate
+fallocate=no

configure if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then · line 1380

Quoted 10 lines
configure +10 -0
+cat > $TMPC << EOF
+#include <fcntl.h>
+
+int main(void)
+{
+    fallocate(0, 0, 0, 0);
+    return 0;
+}
+EOF
+if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then

There is new stanza for this in configure:

if compile_prog "" "" ; then

Quoted 5 lines
configure +5 -0
+  fallocate=yes
+fi
+
+# check for dup3
+dup3=no

configure if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then · line 1395

Quoted 10 lines
configure +10 -0
+cat > $TMPC << EOF
+#include <unistd.h>
+
+int main(void)
+{
+    dup3(0, 0, 0);
+    return 0;
+}
+EOF
+if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then

likewise

Quoted 24 lines
configure +9 -0
+  dup3=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$build_docs" = "yes" -a \( ! -x "`which texi2html 2>/dev/null`" -o ! -x "`which pod2man 2>/dev/null`" \) ; then
   build_docs="no"
@@ -1639,6 +1669,12 @@ fi
 if test "$splice" = "yes" ; then
   echo "CONFIG_SPLICE=y" >> $config_host_mak
 fi
+if test "$fallocate" = "yes" ; then
+  echo "CONFIG_FALLOCATE=y" >> $config_host_mak
+fi
+if test "$dup3" = "yes" ; then
+  echo "CONFIG_DUP3=y" >> $config_host_mak
+fi
 if test "$inotify" = "yes" ; then
   echo "CONFIG_INOTIFY=y" >> $config_host_mak
 fi
linux-user/syscall.c +0 -0
index 31cf151..d105b8e 100644

linux-user/syscall.c static int target_to_host_fcntl_cmd(int cmd) · line 3683

Quoted 3 lines
linux-user/syscall.c +0 -0
@@ -3681,8 +3681,10 @@ static int target_to_host_fcntl_cmd(int cmd)
             return F_SETLEASE;
         case TARGET_F_GETLEASE:
             return F_GETLEASE;

This is patching your previous patch? Generally that is frowned upon - it is tricky to find which patches need to be applied first, and it is better to fix it in the original patch so the broken code is never part of the git history.

Quoted 20 lines
linux-user/syscall.c +7 -0
+#ifdef F_DUPFD_CLOEXEC
         case TARGET_F_DUPFD_CLOEXEC:
             return F_DUPFD_CLOEXEC;
+#endif
         case TARGET_F_NOTIFY:
             return F_NOTIFY;
 	default:
@@ -4732,6 +4734,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_dup2:
         ret = get_errno(dup2(arg1, arg2));
         break;
+#if defined(TARGET_NR_dup3) && defined(CONFIG_DUP3)
+    case TARGET_NR_dup3:
+        ret = get_errno(dup3(arg1, arg2, arg3));
+        break;
+#endif
 #ifdef TARGET_NR_getppid /* not on alpha */
     case TARGET_NR_getppid:
         ret = get_errno(getppid());

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6990

Quoted 8 lines
linux-user/syscall.c +5 -0
@@ -6976,6 +6983,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 #endif /* CONFIG_SPLICE */
+#if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
+    case TARGET_NR_fallocate:
+        ret = get_errno(fallocate(arg1, arg2, arg3, arg4));
+        break;
+#endif

This is colliding with other patches in linux-user-for-upstream. It is a good example why it is better to separete patches for seperate features - In that case it would have been quite easy for me to fix it in by hand.

linux-user/syscall.c abi_long do_syscall(void *cpu_env, int num, abi_long arg1, · line 6993

Quoted 3 lines
linux-user/syscall.c +0 -0
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);

Cheers, Riku

#2 lore raw

PATCH 7/13 linux-user: dup3, fallocate syscalls

In reply to Ulrich Hecht

implementations of dup3 and fallocate that are good enough to fool LTP

dup3 check, fallocate check fixed
use compile_prog

---
 configure            |   36 ++++++++++++++++++++++++++++++++++++
 linux-user/syscall.c |   10 ++++++++++
 2 files changed, 46 insertions(+), 0 deletions(-)
configure +36 -0
index 8e109c5..45f7a52 100755
@@ -1349,6 +1349,36 @@ if compile_prog "" "" ; then
   splice=yes
 fi
 
+# check for fallocate
+fallocate=no
+cat > $TMPC << EOF
+#include <fcntl.h>
+
+int main(void)
+{
+    fallocate(0, 0, 0, 0);
+    return 0;
+}
+EOF
+if compile_prog "" "" ; then
+  fallocate=yes
+fi
+
+# check for dup3
+dup3=no
+cat > $TMPC << EOF
+#include <unistd.h>
+
+int main(void)
+{
+    dup3(0, 0, 0);
+    return 0;
+}
+EOF
+if compile_prog "" "" ; then
+  dup3=yes
+fi
+
 # Check if tools are available to build documentation.
 if test "$build_docs" = "yes" -a \( ! -x "`which texi2html 2>/dev/null`" -o ! -x "`which pod2man 2>/dev/null`" \) ; then
   build_docs="no"
@@ -1688,6 +1718,12 @@ fi
 if test "$splice" = "yes" ; then
   echo "CONFIG_SPLICE=y" >> $config_host_mak
 fi
+if test "$fallocate" = "yes" ; then
+  echo "CONFIG_FALLOCATE=y" >> $config_host_mak
+fi
+if test "$dup3" = "yes" ; then
+  echo "CONFIG_DUP3=y" >> $config_host_mak
+fi
 if test "$inotify" = "yes" ; then
   echo "CONFIG_INOTIFY=y" >> $config_host_mak
 fi
linux-user/syscall.c +10 -0
index 6712cb7..7ee66bf 100644
@@ -4731,6 +4731,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
     case TARGET_NR_dup2:
         ret = get_errno(dup2(arg1, arg2));
         break;
+#if defined(TARGET_NR_dup3) && defined(CONFIG_DUP3)
+    case TARGET_NR_dup3:
+        ret = get_errno(dup3(arg1, arg2, arg3));
+        break;
+#endif
 #ifdef TARGET_NR_getppid /* not on alpha */
     case TARGET_NR_getppid:
         ret = get_errno(getppid());
@@ -6983,6 +6988,11 @@ abi_long do_syscall(void *cpu_env, int num, abi_long arg1,
         break;
 #endif
 #endif /* CONFIG_SPLICE */
+#if defined(CONFIG_FALLOCATE) && defined(TARGET_NR_fallocate)
+    case TARGET_NR_fallocate:
+        ret = get_errno(fallocate(arg1, arg2, arg3, arg4));
+        break;
+#endif
     default:
     unimplemented:
         gemu_log("qemu: Unsupported syscall: %d\n", num);
Signature · 1 line
1.6.2.1