[RFC,10/11] x86-64: make the number of nops after syscall configurable
diff mbox series

Message ID a3c8c8f1c9904965e9da08dae16c96b3b16b2e36.1568219400.git.isaku.yamahata@gmail.com
State New
Headers show
Series
  • Library OS support
Related show

Commit Message

Isaku Yamahata Sept. 11, 2019, 9:04 p.m. UTC
This is tentative patch for convenience.
This patch make it configurable how many nops are inserted after
syscall instruction.
Once the consensus on the number of nops is made,
this patch can be removed.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
---
 configure.ac                            | 19 +++++++++++++++++++
 sysdeps/unix/sysv/linux/x86_64/sysdep.h | 15 ++++++++++++---
 2 files changed, 31 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/configure.ac b/configure.ac
index aa902787f0..150570dd54 100644
--- a/configure.ac
+++ b/configure.ac
@@ -480,6 +480,25 @@  AC_ARG_ENABLE([cet],
 	      [enable_cet=$enableval],
 	      [enable_cet=no])
 
+AC_ARG_ENABLE([libos-num-nops],
+              AC_HELP_STRING([--enable-libos-num-nops=NUM-NOPS],
+                             [specify the number of nops for syscall, x86-64 only
+                             only mealingful when libos support enabled.]),
+              [libos_num_nops=$enableval],
+              [libos_num_nops=''])
+if test -n "$libos_num_nops"; then
+   case "$libos_num_nops" in
+   *[!0-9]*)
+     AC_MSG_ERROR([--enable-libos-num-nops requires a number])
+     ;;
+   *)
+     ;;
+   esac
+   AC_DEFINE_UNQUOTED(ENALBE_LIBOS_NUM_NOPS, $libos_num_nops, [libos num nops])
+   libos_nops=$(printf 'nops;%.0s' $(seq $libos_num_nops))
+   AC_DEFINE_UNQUOTED(ENALBE_LIBOS_NOPS, "$libos_nops", [libos nops])
+fi
+
 # We keep the original values in `$config_*' and never modify them, so we
 # can write them unchanged into config.make.  Everything else uses
 # $machine, $vendor, and $os, and changes them whenever convenient.
diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
index d958c1ca7a..8da5e4e154 100644
--- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
@@ -26,11 +26,17 @@ 
 /* Defines RTLD_PRIVATE_ERRNO.  */
 #include <dl-sysdep.h>
 
-#ifdef __ASSEMBLER__
+#ifdef ENABLE_LIBOS_NOPS
+# define NOP_REPEAT ENABLE_LIBOS_NOPS
+#else
+# define NOP_REPEAT nop;nop;nop;nop;nop;nop;nop;nop;nop;nop
+#endif
+
+# ifdef __ASSEMBLER__
 .macro SYSCALL_INST
     551:
     syscall
-    nop;nop;nop;nop;nop;nop;nop;nop;nop;nop
+    NOP_REPEAT
     552:
     .pushsection .libos.instructions.syscall, "a"
     .balign 8
@@ -39,10 +45,13 @@ 
     .popsection
 .endm
 #else
+#define STRINGIFY(name)   STRINGIFY_1(name)
+#define STRINGIFY_1(name) #name
 #define SYSCALL_INST                                        \
     "551:\n\t"                                              \
     "syscall\n\t"                                           \
-    "nop;nop;nop;nop;nop;nop;nop;nop;nop;nop\n\t"           \
+    STRINGIFY(NOP_REPEAT)                                   \
+    "\n\t"                                                  \
     "552:\n\t"                                              \
     ".pushsection .libos.instructions.syscall, \"a\"\n\t"   \
     ".balign 8\n\t"                                         \