Browse Source

Merge branch 'master' of https://github.com/oscarlab/graphene

Adrian Dombeck 7 years ago
parent
commit
443f1eb8d0
68 changed files with 504 additions and 2820 deletions
  1. 4 2
      LibOS/Makefile
  2. 0 1911
      LibOS/glibc-2.17.patch
  3. 0 1
      LibOS/glibc-2.17/elf/syscallas.S
  4. 0 1
      LibOS/glibc-2.17/elf/syscalldb.c
  5. 0 56
      LibOS/glibc-2.17/libos/Makefile
  6. 0 15
      LibOS/glibc-2.17/libos/Versions
  7. 0 27
      LibOS/glibc-2.17/libos/benchmark.c
  8. 0 13
      LibOS/glibc-2.17/libos/checkpoint.c
  9. 0 13
      LibOS/glibc-2.17/libos/msgpersist.c
  10. 0 27
      LibOS/glibc-2.17/libos/sandbox.c
  11. 0 11
      LibOS/glibc-2.17/syscallas.S
  12. 0 10
      LibOS/glibc-2.17/syscalldb.c
  13. 0 15
      LibOS/glibc-2.17/syscalldb.h
  14. 0 1
      LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/syscalldb.h
  15. 111 134
      LibOS/glibc-2.19.patch
  16. 19 0
      LibOS/glibc-2.19/syscalldb.h
  17. 1 1
      LibOS/shim/include/glibc-version.h
  18. 4 0
      LibOS/shim/include/shim_defs.h
  19. 2 2
      LibOS/shim/include/shim_fs.h
  20. 4 11
      LibOS/shim/include/shim_internal.h
  21. 3 3
      LibOS/shim/include/shim_ipc.h
  22. 1 1
      LibOS/shim/include/shim_signal.h
  23. 2 0
      LibOS/shim/include/shim_tls.h
  24. 1 3
      LibOS/shim/include/shim_utils.h
  25. 0 1
      LibOS/shim/src/.gitignore
  26. 0 0
      LibOS/shim/src/.packed/shim.sha384
  27. BIN
      LibOS/shim/src/.packed/shim.tar.gz
  28. 3 0
      LibOS/shim/src/bookkeep/shim_handle.c
  29. 4 1
      LibOS/shim/src/bookkeep/shim_signal.c
  30. 3 0
      LibOS/shim/src/elf/do-rel.h
  31. 3 0
      LibOS/shim/src/elf/rel.h
  32. 2 4
      LibOS/shim/src/elf/shim_rtld.c
  33. 3 1
      LibOS/shim/src/ipc/shim_ipc.c
  34. 1 1
      LibOS/shim/src/shim.map
  35. 1 10
      LibOS/shim/src/shim_init.c
  36. 2 0
      LibOS/shim/src/shim_malloc.c
  37. 1 1
      LibOS/shim/src/shim_parser.c
  38. 0 1
      LibOS/shim/src/shim_syscalls.c
  39. 64 1
      LibOS/shim/src/sys/shim_epoll.c
  40. 0 7
      LibOS/shim/src/sys/shim_open.c
  41. 27 17
      LibOS/shim/src/sys/shim_poll.c
  42. 1 1
      LibOS/shim/src/sys/shim_uname.c
  43. 8 9
      LibOS/shim/src/syscallas.S
  44. 6 0
      LibOS/shim/src/utils/printf.c
  45. 5 6
      LibOS/shim/test/Makefile
  46. 1 1
      LibOS/shim/test/apps/lighttpd/Makefile
  47. 0 14
      LibOS/shim/test/apps/pal_loader
  48. 1 1
      LibOS/shim/test/native/.packed/test.sha384
  49. BIN
      LibOS/shim/test/native/.packed/test.tar.gz
  50. 2 2
      LibOS/shim/test/native/Makefile
  51. 39 37
      Pal/ipc/linux/graphene-ipc.c
  52. 0 1
      Pal/ipc/linux/graphene.h
  53. 2 1
      Pal/ipc/linux/install.sh
  54. 19 0
      Pal/ipc/linux/ksyms.h
  55. 6 5
      Pal/ipc/linux/load.sh
  56. 3 2
      Pal/ipc/linux/uninstall.sh
  57. 1 1
      Pal/regression/.packed/test.sha384
  58. BIN
      Pal/regression/.packed/test.tar.gz
  59. 35 39
      Pal/src/db_exception.c
  60. 0 17
      Pal/src/db_main.c
  61. 15 25
      Pal/src/db_rtld.c
  62. 3 1
      Pal/src/do-rel.h
  63. 5 0
      Pal/src/dynamic_link.h
  64. 29 85
      Pal/src/host/Linux-SGX/db_exception.c
  65. 1 5
      Pal/src/host/Linux-SGX/elf-x86_64.h
  66. 53 254
      Pal/src/host/Linux/db_exception.c
  67. 2 2
      Pal/src/host/Linux/pal_host.h
  68. 1 8
      Pal/src/pal_internal.h

+ 4 - 2
LibOS/Makefile

@@ -20,18 +20,20 @@ ifeq ($(SYS),x86_64-linux-gnu)
 $(GLIBC_TARGET): $(BUILD_DIR)/Makefile
 	cd $(BUILD_DIR) && $(MAKE)
 
-$(BUILD_DIR)/Makefile: $(GLIBC_SRC)/configure
+$(BUILD_DIR)/Makefile: $(addprefix $(GLIBC_SRC)/,configure elf/Versions nptl/Versions dlfcn/Versions)
 ifeq ($(DEBUG),1)
 	./buildglibc.py --quiet --debug
 else
 	./buildglibc.py --quiet
 endif
 
-$(GLIBC_SRC)/configure:
+ifeq ($(shell git ls-files $(GLIBC_SRC)/configure),)
+$(GLIBC_SRC)/configure: $(GLIBC_SRC).patch
 	[ -f $(GLIBC_SRC).tar.gz ] || \
 	wget http://ftp.gnu.org/gnu/glibc/$(GLIBC_SRC).tar.gz
 	tar -xzf $(GLIBC_SRC).tar.gz
 	cd $(GLIBC_SRC) && patch -p1 < ../$(GLIBC_SRC).patch
+endif
 
 .PHONY: pack
 pack: $(GLIBC_TARGET)

+ 0 - 1911
LibOS/glibc-2.17.patch

@@ -1,1911 +0,0 @@
-diff --git a/Makeconfig b/Makeconfig
-index 70a3d9d..2c543c3 100644
---- a/Makeconfig
-+++ b/Makeconfig
-@@ -718,7 +718,8 @@ endif	# $(+cflags) == ""
- +sysdep-includes = $(addprefix -I,$(+sysdep_dirs))
- +includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
- 	    $(+sysdep-includes) $(includes) \
--	    $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)
-+	    $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes) \
-+	    -I$(common-objpfx)../shim/include
- 
- # Since libio has several internal header files, we use a -I instead
- # of many little headers in the include directory.
-@@ -987,7 +988,7 @@ all-subdirs = csu assert ctype locale intl catgets math setjmp signal	    \
- 	      stdlib stdio-common libio malloc string wcsmbs time dirent    \
- 	      grp pwd posix io termios resource misc socket sysvipc gmon    \
- 	      gnulib iconv iconvdata wctype manual shadow gshadow po argp   \
--	      crypt nss localedata timezone rt conform debug		    \
-+	      crypt nss localedata timezone rt conform debug libos	    \
- 	      $(add-on-subdirs) dlfcn elf
- 
- ifndef avoid-generated
-diff --git a/Makefile b/Makefile
-index 6c1e392..3df0ac6 100644
---- a/Makefile
-+++ b/Makefile
-@@ -197,6 +197,8 @@ $(inst_includedir)/gnu/stubs.h: $(+force)
- install-others-nosubdir: $(installed-stubs)
- endif
- 
-+# For Graphene
-+CFLAGS-syscalldb.c = -fPIC
- 
- # Since stubs.h is never needed when building the library, we simplify the
- # hairy installation process by producing it in place only as the last part
-diff --git a/Versions.def b/Versions.def
-index 3c9e0ae..034ab2b 100644
---- a/Versions.def
-+++ b/Versions.def
-@@ -39,6 +39,7 @@ libc {
-   GCC_3.0
- %endif
-   GLIBC_PRIVATE
-+  SHIM
- }
- libcrypt {
-   GLIBC_2.0
-@@ -48,6 +49,7 @@ libdl {
-   GLIBC_2.1
-   GLIBC_2.3.3
-   GLIBC_2.3.4
-+  SHIM
- }
- libm {
-   GLIBC_2.0
-@@ -100,6 +102,7 @@ libpthread {
-   GLIBC_2.11
-   GLIBC_2.12
-   GLIBC_PRIVATE
-+  SHIM
- }
- libresolv {
-   GLIBC_2.0
-@@ -127,6 +130,7 @@ ld {
-   GLIBC_2.3
-   GLIBC_2.4
-   GLIBC_PRIVATE
-+  SHIM
- }
- libthread_db {
-   GLIBC_2.1.3
-@@ -140,3 +144,6 @@ libanl {
- libcidn {
-   GLIBC_PRIVATE
- }
-+liblibos {
-+  GLIBC_2.12
-+}
-diff --git a/configure b/configure
-index 8799b7d..22e4c2c 100755
---- a/configure
-+++ b/configure
-@@ -636,7 +636,8 @@ SED
- MAKEINFO
- MSGFMT
- MAKE
--LD
-+LD_GOLD
-+LD_BFD
- AS
- MIG
- OBJCOPY
-@@ -4792,17 +4793,22 @@ if test $ac_verc_fail = yes; then
-   AS=: critic_missing="$critic_missing as"
- fi
- 
--for ac_prog in $LD
-+LD_BFD=
-+LD_GOLD=
-+ld_is_gold="`$LD --version | sed -n 's/^GNU \(gold\).*$/\1/p'`"
-+if test -z "$ld_is_gold"; then
-+  LD_BFD=$LD
-+  for ac_prog in $LD_BFD
- do
-   # Extract the first word of "$ac_prog", so it can be a program name with args.
- set dummy $ac_prog; ac_word=$2
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
- $as_echo_n "checking for $ac_word... " >&6; }
--if ${ac_cv_prog_LD+:} false; then :
-+if ${ac_cv_prog_LD_BFD+:} false; then :
-   $as_echo_n "(cached) " >&6
- else
--  if test -n "$LD"; then
--  ac_cv_prog_LD="$LD" # Let the user override the test.
-+  if test -n "$LD_BFD"; then
-+  ac_cv_prog_LD_BFD="$LD_BFD" # Let the user override the test.
- else
- as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
- for as_dir in $PATH
-@@ -4811,7 +4817,7 @@ do
-   test -z "$as_dir" && as_dir=.
-     for ac_exec_ext in '' $ac_executable_extensions; do
-   if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
--    ac_cv_prog_LD="$ac_prog"
-+    ac_cv_prog_LD_BFD="$ac_prog"
-     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-     break 2
-   fi
-@@ -4821,26 +4827,26 @@ IFS=$as_save_IFS
- 
- fi
- fi
--LD=$ac_cv_prog_LD
--if test -n "$LD"; then
--  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD" >&5
--$as_echo "$LD" >&6; }
-+LD_BFD=$ac_cv_prog_LD_BFD
-+if test -n "$LD_BFD"; then
-+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD_BFD" >&5
-+$as_echo "$LD_BFD" >&6; }
- else
-   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
- $as_echo "no" >&6; }
- fi
- 
- 
--  test -n "$LD" && break
-+  test -n "$LD_BFD" && break
- done
- 
--if test -z "$LD"; then
-+if test -z "$LD_BFD"; then
-   ac_verc_fail=yes
- else
-   # Found it, now check the version.
--  { $as_echo "$as_me:${as_lineno-$LINENO}: checking version of $LD" >&5
--$as_echo_n "checking version of $LD... " >&6; }
--  ac_prog_version=`$LD --version 2>&1 | sed -n 's/^.*GNU ld.* \([0-9][0-9]*\.[0-9.]*\).*$/\1/p'`
-+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking version of $LD_BFD" >&5
-+$as_echo_n "checking version of $LD_BFD... " >&6; }
-+  ac_prog_version=`$LD_BFD --version 2>&1 | sed -n 's/^.*GNU ld.* \([0-9][0-9]*\.[0-9.]*\).*$/\1/p'`
-   case $ac_prog_version in
-     '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
-     2.1[0-9][0-9]*|2.[2-9][0-9]*|[3-9].*|[1-9][0-9]*)
-@@ -4852,9 +4858,80 @@ $as_echo_n "checking version of $LD... " >&6; }
- $as_echo "$ac_prog_version" >&6; }
- fi
- if test $ac_verc_fail = yes; then
--  LD=: critic_missing="$critic_missing ld"
-+  LD_BFD=:
- fi
- 
-+else
-+# Accept gold 1.11 or higher.
-+  LD_GOLD=$LD
-+  for ac_prog in $LD_GOLD
-+do
-+  # Extract the first word of "$ac_prog", so it can be a program name with args.
-+set dummy $ac_prog; ac_word=$2
-+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
-+$as_echo_n "checking for $ac_word... " >&6; }
-+if ${ac_cv_prog_LD_GOLD+:} false; then :
-+  $as_echo_n "(cached) " >&6
-+else
-+  if test -n "$LD_GOLD"; then
-+  ac_cv_prog_LD_GOLD="$LD_GOLD" # Let the user override the test.
-+else
-+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
-+for as_dir in $PATH
-+do
-+  IFS=$as_save_IFS
-+  test -z "$as_dir" && as_dir=.
-+    for ac_exec_ext in '' $ac_executable_extensions; do
-+  if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
-+    ac_cv_prog_LD_GOLD="$ac_prog"
-+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
-+    break 2
-+  fi
-+done
-+  done
-+IFS=$as_save_IFS
-+
-+fi
-+fi
-+LD_GOLD=$ac_cv_prog_LD_GOLD
-+if test -n "$LD_GOLD"; then
-+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LD_GOLD" >&5
-+$as_echo "$LD_GOLD" >&6; }
-+else
-+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-+$as_echo "no" >&6; }
-+fi
-+
-+
-+  test -n "$LD_GOLD" && break
-+done
-+
-+if test -z "$LD_GOLD"; then
-+  ac_verc_fail=yes
-+else
-+  # Found it, now check the version.
-+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking version of $LD_GOLD" >&5
-+$as_echo_n "checking version of $LD_GOLD... " >&6; }
-+  ac_prog_version=`$LD_GOLD --version 2>&1 | sed -n 's/^.*GNU gold.* \([0-9][0-9]*\.[0-9.]*\).*$/\1/p'`
-+  case $ac_prog_version in
-+    '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
-+    1.1[1-9]*|1.[2-9][0-9]*|1.1[0-9][0-9]*|[2-9].*|[1-9][0-9]*)
-+       ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
-+    *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
-+
-+  esac
-+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5
-+$as_echo "$ac_prog_version" >&6; }
-+fi
-+if test $ac_verc_fail = yes; then
-+  LD_GOLD=:
-+fi
-+
-+fi
-+# Neither ld nor gold are new enough.
-+if test -z "$LD_BFD" && test -z "$LD_GOLD"; then
-+  critic_missing="$critic_missing ld"
-+fi
- 
- # These programs are version sensitive.
- 
-@@ -6670,6 +6747,16 @@ $as_echo "$libc_cv_use_default_link" >&6; }
-   use_default_link=$libc_cv_use_default_link
- fi
- 
-+# The gold linker has no builtin default linker script,
-+# and the fallback of editing the builtin linker
-+# script is not available. Therefore if use_default_link
-+# is `no' then we can't use gold. This check is independent
-+# of gold's version and is used to sanity check that the
-+# linker continues to produce a useful shared link.
-+if test "$ld_is_gold" && test "$use_default_link" = "no"; then
-+  as_fn_error $? "$LD did not generate a useful shared link. Try using GNU ld.bfd?" "$LINENO" 5
-+fi
-+
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker output format" >&5
- $as_echo_n "checking linker output format... " >&6; }
- if ${libc_cv_output_format+:} false; then :
-@@ -6688,6 +6775,17 @@ fi
- $as_echo "$libc_cv_output_format" >&6; }
- 
- 
-+# The gold linker has no builtin default linker script,
-+# and the fallback of parsing the builtin linker
-+# script to determine the target is not available.
-+# Therefore if libc_cv_output_format is `unknown' then
-+# we can't use gold. This check is independent of gold's
-+# version and is used to sanity check that the linker
-+# continues to support --print-output-format.
-+if test "$ld_is_gold" && test "$libc_cv_output_format" = "unknown"; then
-+  as_fn_error $? "$LD did not support --print-output-format. Try using GNU ld.bfd?" "$LINENO" 5
-+fi
-+
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fno-toplevel-reorder -fno-section-anchors" >&5
- $as_echo_n "checking for -fno-toplevel-reorder -fno-section-anchors... " >&6; }
- if ${libc_cv_fno_toplevel_reorder+:} false; then :
-diff --git a/configure.in b/configure.in
-index d369382..38ff3cd 100644
---- a/configure.in
-+++ b/configure.in
-@@ -924,9 +924,25 @@ AC_SUBST(MIG)dnl Needed by sysdeps/mach/configure.in
- AC_CHECK_PROG_VER(AS, $AS, --version,
- 		  [GNU assembler.* \([0-9]*\.[0-9.]*\)],
- 		  [2.1[0-9][0-9]*|2.[2-9][0-9]*|[3-9].*|[1-9][0-9]*], AS=: critic_missing="$critic_missing as")
--AC_CHECK_PROG_VER(LD, $LD, --version,
-+LD_BFD=
-+LD_GOLD=
-+ld_is_gold="`$LD --version | sed -n 's/^GNU \(gold\).*$/\1/p'`"
-+if test -z "$ld_is_gold"; then
-+  LD_BFD=$LD
-+  AC_CHECK_PROG_VER(LD_BFD, $LD_BFD, --version,
- 		  [GNU ld.* \([0-9][0-9]*\.[0-9.]*\)],
--		  [2.1[0-9][0-9]*|2.[2-9][0-9]*|[3-9].*|[1-9][0-9]*], LD=: critic_missing="$critic_missing ld")
-+		  [2.1[0-9][0-9]*|2.[2-9][0-9]*|[3-9].*|[1-9][0-9]*],LD_BFD=:)
-+else
-+# Accept gold 1.11 or higher.
-+  LD_GOLD=$LD
-+  AC_CHECK_PROG_VER(LD_GOLD, $LD_GOLD, --version,
-+		  [GNU gold.* \([0-9][0-9]*\.[0-9.]*\)],
-+		  [1.1[1-9]*|1.[2-9][0-9]*|1.1[0-9][0-9]*|[2-9].*|[1-9][0-9]*],LD_GOLD=:)
-+fi
-+# Neither ld nor gold are new enough.
-+if test -z "$LD_BFD" && test -z "$LD_GOLD"; then
-+  critic_missing="$critic_missing ld"
-+fi
- 
- # These programs are version sensitive.
- AC_CHECK_TOOL_PREFIX
-@@ -1635,6 +1651,16 @@ $ac_try"
-   use_default_link=$libc_cv_use_default_link
- fi
- 
-+# The gold linker has no builtin default linker script,
-+# and the fallback of editing the builtin linker
-+# script is not available. Therefore if use_default_link
-+# is `no' then we can't use gold. This check is independent
-+# of gold's version and is used to sanity check that the
-+# linker continues to produce a useful shared link.
-+if test "$ld_is_gold" && test "$use_default_link" = "no"; then
-+  AC_MSG_ERROR([$LD did not generate a useful shared link. Try using GNU ld.bfd?])
-+fi
-+
- AC_CACHE_CHECK(linker output format, libc_cv_output_format, [dnl
- if libc_cv_output_format=`
- ${CC-cc} -nostartfiles -nostdlib -Wl,--print-output-format 2>&AS_MESSAGE_LOG_FD`
-@@ -1646,6 +1672,17 @@ fi
- test -n "$libc_cv_output_format" || libc_cv_output_format=unknown])
- AC_SUBST(libc_cv_output_format)
- 
-+# The gold linker has no builtin default linker script,
-+# and the fallback of parsing the builtin linker
-+# script to determine the target is not available.
-+# Therefore if libc_cv_output_format is `unknown' then
-+# we can't use gold. This check is independent of gold's
-+# version and is used to sanity check that the linker
-+# continues to support --print-output-format.
-+if test "$ld_is_gold" && test "$libc_cv_output_format" = "unknown"; then
-+  AC_MSG_ERROR([$LD did not support --print-output-format. Try using GNU ld.bfd?])
-+fi
-+
- AC_CACHE_CHECK(for -fno-toplevel-reorder -fno-section-anchors, libc_cv_fno_toplevel_reorder, [dnl
- cat > conftest.c <<EOF
- int foo;
-diff --git a/dlfcn/Versions b/dlfcn/Versions
-index 97902f0..c1874c1 100644
---- a/dlfcn/Versions
-+++ b/dlfcn/Versions
-@@ -14,4 +14,7 @@ libdl {
-   GLIBC_PRIVATE {
-     _dlfcn_hook;
-   }
-+  SHIM {
-+    syscalldb;
-+  }
- }
-diff --git a/elf/Makefile b/elf/Makefile
-index 6c7bc97..b51a799 100644
---- a/elf/Makefile
-+++ b/elf/Makefile
-@@ -21,7 +21,7 @@ subdir		:= elf
- 
- include ../Makeconfig
- 
--headers		= elf.h bits/elfclass.h link.h bits/link.h
-+headers		= elf.h bits/elfclass.h link.h bits/link.h syscalldb.h
- routines	= $(dl-routines) dl-support dl-iteratephdr \
- 		  dl-addr enbl-secure dl-profstub \
- 		  dl-origin dl-libc dl-sym dl-tsd dl-sysdep
-@@ -31,7 +31,8 @@ routines	= $(dl-routines) dl-support dl-iteratephdr \
- dl-routines	= $(addprefix dl-,load lookup object reloc deps hwcaps \
- 				  runtime error init fini debug misc \
- 				  version profile conflict tls origin scope \
--				  execstack caller open close trampoline)
-+				  execstack caller open close trampoline) \
-+		  syscalldb syscallas
- ifeq (yes,$(use-ldconfig))
- dl-routines += dl-cache
- endif
-diff --git a/elf/Versions b/elf/Versions
-index 87e27c5..a0e345b 100644
---- a/elf/Versions
-+++ b/elf/Versions
-@@ -24,14 +24,15 @@ libc {
-     _dl_open_hook;
-     __libc_dlopen_mode; __libc_dlsym; __libc_dlclose;
-   }
-+  SHIM {
-+    syscalldb;
-+  }
- }
- 
- ld {
-   GLIBC_2.0 {
-     # Function from libc.so which must be shared with libc.
-     calloc; free; malloc; realloc; __libc_memalign;
--
--    _r_debug;
-   }
-   GLIBC_2.1 {
-     # functions used in other libraries
-@@ -59,8 +60,11 @@ ld {
-     _dl_tls_setup; _dl_rtld_di_serinfo;
-     _dl_make_stack_executable;
-     # Only here for gdb while a better method is developed.
--    _dl_debug_state;
-+    __libc_r_debug; __libc_dl_debug_state;
-     # Pointer protection.
-     __pointer_chk_guard;
-   }
-+  SHIM {
-+    syscalldb; glibc_vers_2_17; register_library;
-+  }
- }
-diff --git a/elf/circleload1.c b/elf/circleload1.c
-index 990ff84..ccf92d3 100644
---- a/elf/circleload1.c
-+++ b/elf/circleload1.c
-@@ -5,7 +5,7 @@
- #include <stdlib.h>
- #include <string.h>
- 
--#define MAPS ((struct link_map *) _r_debug.r_map)
-+#define MAPS ((struct link_map *) __libc_r_debug.r_map)
- 
- static int
- check_loaded_objects (const char **loaded)
-diff --git a/elf/dl-close.c b/elf/dl-close.c
-index cda0e71..580e1e2 100644
---- a/elf/dl-close.c
-+++ b/elf/dl-close.c
-@@ -468,7 +468,7 @@ _dl_close_worker (struct link_map *map)
-   /* Notify the debugger we are about to remove some loaded objects.  */
-   struct r_debug *r = _dl_debug_initialize (0, nsid);
-   r->r_state = RT_DELETE;
--  _dl_debug_state ();
-+  __libc_dl_debug_state ();
-   LIBC_PROBE (unmap_start, 2, nsid, r);
- 
-   if (unload_global)
-@@ -742,7 +742,7 @@ _dl_close_worker (struct link_map *map)
- 
-   /* Notify the debugger those objects are finalized and gone.  */
-   r->r_state = RT_CONSISTENT;
--  _dl_debug_state ();
-+  __libc_dl_debug_state ();
-   LIBC_PROBE (unmap_complete, 2, nsid, r);
- 
-   /* Recheck if we need to retry, release the lock.  */
-diff --git a/elf/dl-debug.c b/elf/dl-debug.c
-index 4106e42..b95bd27 100644
---- a/elf/dl-debug.c
-+++ b/elf/dl-debug.c
-@@ -35,7 +35,7 @@ extern const int verify_link_map_members[(VERIFY_MEMBER (l_addr)
-    normally finds it via the DT_DEBUG entry in the dynamic section, but in
-    a statically-linked program there is no dynamic section for the debugger
-    to examine and it looks for this particular symbol name.  */
--struct r_debug _r_debug;
-+struct r_debug __libc_r_debug __attribute__((weak));
- 
- 
- /* Initialize _r_debug if it has not already been done.  The argument is
-@@ -49,7 +49,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
-   struct r_debug *r;
- 
-   if (ns == LM_ID_BASE)
--    r = &_r_debug;
-+    r = &__libc_r_debug;
-   else
-     r = &GL(dl_ns)[ns]._ns_debug;
- 
-@@ -57,9 +57,9 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
-     {
-       /* Tell the debugger where to find the map of loaded objects.  */
-       r->r_version = 1	/* R_DEBUG_VERSION XXX */;
--      r->r_ldbase = ldbase ?: _r_debug.r_ldbase;
-+      r->r_ldbase = ldbase ?: __libc_r_debug.r_ldbase;
-       r->r_map = (void *) GL(dl_ns)[ns]._ns_loaded;
--      r->r_brk = (ElfW(Addr)) &_dl_debug_state;
-+      r->r_brk = (ElfW(Addr)) &__libc_dl_debug_state;
-     }
- 
-   return r;
-@@ -71,7 +71,7 @@ _dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
-    examining the r_brk member of struct r_debug, but GDB 4.15 in fact looks
-    for this particular symbol name in the PT_INTERP file.  */
- void
--_dl_debug_state (void)
-+__libc_dl_debug_state (void)
- {
- }
--rtld_hidden_def (_dl_debug_state)
-+__attribute__((weak));
-diff --git a/elf/dl-load.c b/elf/dl-load.c
-index 70fe78f..4ec655a 100644
---- a/elf/dl-load.c
-+++ b/elf/dl-load.c
-@@ -39,6 +39,8 @@
- 
- #include <dl-dst.h>
- 
-+#include <glibc-version.h>
-+
- /* On some systems, no flag bits are given to specify file mapping.  */
- #ifndef MAP_FILE
- # define MAP_FILE	0
-@@ -896,7 +898,7 @@ lose (int code, int fd, const char *name, char *realname, struct link_map *l,
-   if (r != NULL)
-     {
-       r->r_state = RT_CONSISTENT;
--      _dl_debug_state ();
-+      __libc_dl_debug_state ();
-       LIBC_PROBE (map_failed, 2, nsid, r);
-     }
- 
-@@ -1042,7 +1044,7 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
- 	 call _dl_debug_initialize in a static program in case dynamic
- 	 linking has not been used before.  */
-       r->r_state = RT_ADD;
--      _dl_debug_state ();
-+      __libc_dl_debug_state ();
-       LIBC_PROBE (map_start, 2, nsid, r);
-       make_consistent = true;
-     }
-@@ -1585,6 +1587,9 @@ cannot enable executable stack as shared object requires");
-   DL_AFTER_LOAD (l);
- #endif
- 
-+  /* register the library to SHIM */
-+  register_library(l->l_name, l->l_addr);
-+
-   /* Now that the object is fully initialized add it to the object list.  */
-   _dl_add_to_namespace_list (l, nsid);
- 
-diff --git a/elf/dl-open.c b/elf/dl-open.c
-index 9c39a34..a21f51e 100644
---- a/elf/dl-open.c
-+++ b/elf/dl-open.c
-@@ -294,7 +294,7 @@ dl_open_worker (void *a)
-   /* Notify the debugger all new objects are now ready to go.  */
-   struct r_debug *r = _dl_debug_initialize (0, args->nsid);
-   r->r_state = RT_CONSISTENT;
--  _dl_debug_state ();
-+  __libc_dl_debug_state ();
-   LIBC_PROBE (map_complete, 3, args->nsid, r, new);
- 
-   /* Print scope information.  */
-diff --git a/elf/link.h b/elf/link.h
-index 11136cc..db5c4e3 100644
---- a/elf/link.h
-+++ b/elf/link.h
-@@ -64,7 +64,7 @@ struct r_debug
-   };
- 
- /* This is the instance of that structure used by the dynamic linker.  */
--extern struct r_debug _r_debug;
-+extern struct r_debug __libc_r_debug;
- 
- /* This symbol refers to the "dynamic structure" in the `.dynamic' section
-    of whatever module refers to `_DYNAMIC'.  So, to find its own
-diff --git a/elf/loadtest.c b/elf/loadtest.c
-index 727469b..568ddef 100644
---- a/elf/loadtest.c
-+++ b/elf/loadtest.c
-@@ -70,7 +70,7 @@ static const struct
- 
- #include <include/link.h>
- 
--#define MAPS ((struct link_map *) _r_debug.r_map)
-+#define MAPS ((struct link_map *) __libc_r_debug.r_map)
- 
- #define OUT \
-   for (map = MAPS; map != NULL; map = map->l_next)		      \
-diff --git a/elf/neededtest.c b/elf/neededtest.c
-index 3cea499..e098d48 100644
---- a/elf/neededtest.c
-+++ b/elf/neededtest.c
-@@ -5,7 +5,7 @@
- #include <stdlib.h>
- #include <string.h>
- 
--#define MAPS ((struct link_map *) _r_debug.r_map)
-+#define MAPS ((struct link_map *) __libc_r_debug.r_map)
- 
- static int
- check_loaded_objects (const char **loaded)
-diff --git a/elf/neededtest2.c b/elf/neededtest2.c
-index 17c75f2..5a73a95 100644
---- a/elf/neededtest2.c
-+++ b/elf/neededtest2.c
-@@ -5,7 +5,7 @@
- #include <stdlib.h>
- #include <string.h>
- 
--#define MAPS ((struct link_map *) _r_debug.r_map)
-+#define MAPS ((struct link_map *) __libc_r_debug.r_map)
- 
- static int
- check_loaded_objects (const char **loaded)
-diff --git a/elf/neededtest3.c b/elf/neededtest3.c
-index 41970cf..5126615 100644
---- a/elf/neededtest3.c
-+++ b/elf/neededtest3.c
-@@ -5,7 +5,7 @@
- #include <stdlib.h>
- #include <string.h>
- 
--#define MAPS ((struct link_map *) _r_debug.r_map)
-+#define MAPS ((struct link_map *) __libc_r_debug.r_map)
- 
- static int
- check_loaded_objects (const char **loaded)
-diff --git a/elf/neededtest4.c b/elf/neededtest4.c
-index 0ae0b7f..f883910 100644
---- a/elf/neededtest4.c
-+++ b/elf/neededtest4.c
-@@ -5,7 +5,7 @@
- #include <stdlib.h>
- #include <string.h>
- 
--#define MAPS ((struct link_map *) _r_debug.r_map)
-+#define MAPS ((struct link_map *) __libc_r_debug.r_map)
- 
- static int
- check_loaded_objects (const char **loaded)
-diff --git a/elf/rtld.c b/elf/rtld.c
-index b0126e5..2fb4fe9 100644
---- a/elf/rtld.c
-+++ b/elf/rtld.c
-@@ -356,6 +356,23 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
-   return start_addr;
- }
- 
-+/* For graphene, check if glibc version match to the compatible SHIM
-+   library. If not, tell the user to update glibc. */
-+#include "glibc-version.h"
-+
-+volatile const int glibc_vers_2_17 __attribute__((weak)) = GLIBC_VERSION_2_17;
-+
-+static void __attribute__((noinline,optimize("-O0")))
-+check_glibc_version (void)
-+{
-+  if (glibc_vers_2_17 != GLIBC_VERSION_2_17)
-+    {
-+      _dl_fatal_printf ("Warning from Graphene: "
-+			"Glibc version is incorrect. Please rebuild Glibc.\n");
-+      _exit (1);
-+    }
-+}
-+
- static ElfW(Addr) __attribute_used__ internal_function
- _dl_start (void *arg)
- {
-@@ -546,6 +563,9 @@ _dl_start (void *arg)
-      therefore need not test whether we have to allocate the array
-      for the relocation results (as done in dl-reloc.c).  */
- 
-+  /* For Graphene, check if the glibc version is correct. */
-+  check_glibc_version();
-+
-   /* Now life is sane; we can call functions and access global data.
-      Set up to use the operating system facilities, and find out from
-      the operating system's program loader where to find the program
-@@ -1230,9 +1250,20 @@ of this helper program; chances are you did not intend to run this program.\n\
- 	    main_map->l_map_end = allocend;
- 	  if ((ph->p_flags & PF_X) && allocend > main_map->l_text_end)
- 	    main_map->l_text_end = allocend;
-+
-+#if 0
-+	  ElfW(Addr) mapend = (allocend + GLRO(dl_pagesize) - 1)
-+		               & ~(GLRO(dl_pagesize) - 1);
-+	  int prot = ((ph->p_flags & PF_R) ? PROT_READ  : 0)|
-+	             ((ph->p_flags & PF_W) ? PROT_WRITE : 0)|
-+	             ((ph->p_flags & PF_X) ? PROT_EXEC  : 0);
-+	  __mmap ((void *) mapstart, mapend - mapstart,
-+		  prot,
-+		  MAP_ANON|MAP_PRIVATE|MAP_FIXED|0x20000000,
-+		  -1, 0);
-+#endif
- 	}
- 	break;
--
-       case PT_TLS:
- 	if (ph->p_memsz > 0)
- 	  {
-@@ -1378,13 +1409,31 @@ of this helper program; chances are you did not intend to run this program.\n\
-   /* PT_GNU_RELRO is usually the last phdr.  */
-   size_t cnt = rtld_ehdr->e_phnum;
-   while (cnt-- > 0)
-+  {
-     if (rtld_phdr[cnt].p_type == PT_GNU_RELRO)
-       {
- 	GL(dl_rtld_map).l_relro_addr = rtld_phdr[cnt].p_vaddr;
- 	GL(dl_rtld_map).l_relro_size = rtld_phdr[cnt].p_memsz;
--	break;
-       }
- 
-+#if 0
-+    if (rtld_phdr[cnt].p_type == PT_LOAD)
-+      {
-+	ElfW(Addr) mapstart = rtld_phdr[cnt].p_vaddr & ~(GLRO(dl_pagesize) - 1);
-+	ElfW(Addr) mapend = (rtld_phdr[cnt].p_vaddr + rtld_phdr[cnt].p_memsz
-+		             + GLRO(dl_pagesize) - 1)
-+		             & ~(GLRO(dl_pagesize) - 1);
-+	int prot = ((rtld_phdr[cnt].p_flags & PF_R) ? PROT_READ  : 0)|
-+	           ((rtld_phdr[cnt].p_flags & PF_W) ? PROT_WRITE : 0)|
-+	           ((rtld_phdr[cnt].p_flags & PF_X) ? PROT_EXEC  : 0);
-+	__mmap ((void *) mapstart, mapend - mapstart,
-+		prot,
-+		MAP_ANON|MAP_PRIVATE|MAP_FIXED|0x20000000,
-+		-1, 0);
-+      }
-+#endif
-+  }
-+
-   /* Add the dynamic linker to the TLS list if it also uses TLS.  */
-   if (GL(dl_rtld_map).l_tls_blocksize != 0)
-     /* Assign a module ID.  Do this before loading any audit modules.  */
-@@ -1585,7 +1634,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
- 
-   /* We start adding objects.  */
-   r->r_state = RT_ADD;
--  _dl_debug_state ();
-+  __libc_dl_debug_state ();
-   LIBC_PROBE (init_start, 2, LM_ID_BASE, r);
- 
-   /* Auditing checkpoint: we are ready to signal that the initial map
-@@ -2305,7 +2354,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n",
-      the address since by now the variable might be in another object.  */
-   r = _dl_debug_initialize (0, LM_ID_BASE);
-   r->r_state = RT_CONSISTENT;
--  _dl_debug_state ();
-+  __libc_dl_debug_state ();
-   LIBC_PROBE (init_complete, 2, LM_ID_BASE, r);
- 
- #if defined USE_LDCONFIG && !defined MAP_COPY
-diff --git a/elf/unload.c b/elf/unload.c
-index 4566f22..73046de 100644
---- a/elf/unload.c
-+++ b/elf/unload.c
-@@ -9,7 +9,7 @@
- #include <stdio.h>
- #include <stdlib.h>
- 
--#define MAPS ((struct link_map *) _r_debug.r_map)
-+#define MAPS ((struct link_map *) __libc_r_debug.r_map)
- 
- #define OUT \
-   for (map = MAPS; map != NULL; map = map->l_next)			      \
-diff --git a/elf/unload2.c b/elf/unload2.c
-index eef2bfd..a21d2ac 100644
---- a/elf/unload2.c
-+++ b/elf/unload2.c
-@@ -6,7 +6,7 @@
- #include <stdio.h>
- #include <stdlib.h>
- 
--#define MAPS ((struct link_map *) _r_debug.r_map)
-+#define MAPS ((struct link_map *) __libc_r_debug.r_map)
- 
- #define OUT \
-   for (map = MAPS; map != NULL; map = map->l_next)			      \
-diff --git a/nptl/Makefile b/nptl/Makefile
-index e33432e..8ec263f 100644
---- a/nptl/Makefile
-+++ b/nptl/Makefile
-@@ -20,7 +20,7 @@
- #
- subdir	:= nptl
- 
--headers := pthread.h semaphore.h bits/semaphore.h
-+headers := pthread.h semaphore.h bits/semaphore.h syscalldb.h
- 
- extra-libs := libpthread
- extra-libs-others := $(extra-libs)
-diff --git a/nptl/Versions b/nptl/Versions
-index 6a10375..4a1eb35 100644
---- a/nptl/Versions
-+++ b/nptl/Versions
-@@ -31,6 +31,9 @@ libc {
-     # Internal libc interface to libpthread
-     __libc_dl_error_tsd;
-   }
-+  SHIM {
-+    syscalldb;
-+  }
- }
- 
- libpthread {
-@@ -257,4 +260,8 @@ libpthread {
-     __pthread_clock_gettime; __pthread_clock_settime;
-     __pthread_unwind; __pthread_get_minstack;
-   }
-+
-+  SHIM {
-+    syscalldb;
-+  }
- }
-diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
-index 197dfa7..6cf8fa6 100644
---- a/nptl/pthread_create.c
-+++ b/nptl/pthread_create.c
-@@ -398,8 +398,11 @@ start_thread (void *arg)
- # error "to do"
- #endif
-   assert (freesize < pd->stackblock_size);
-+  /* XXX: may not be necessary */
-+#if 0
-   if (freesize > PTHREAD_STACK_MIN)
-     __madvise (pd->stackblock, freesize - PTHREAD_STACK_MIN, MADV_DONTNEED);
-+#endif
- 
-   /* If the thread is detached free the TCB.  */
-   if (IS_DETACHED (pd))
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S b/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
-index 31bb08b..4729064 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/cancellation.S
-@@ -111,7 +111,8 @@ ENTRY(__pthread_disable_asynccancel)
- 	xorq	%r10, %r10
- 	addq	$CANCELHANDLING, %rdi
- 	LOAD_PRIVATE_FUTEX_WAIT (%esi)
--	syscall
-+	SYSCALL
-+
- 	movl	%fs:CANCELHANDLING, %eax
- 	jmp	3b
- END(__pthread_disable_asynccancel)
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c b/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
-index dedbabd..5bd873e 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/fork.c
-@@ -21,10 +21,20 @@
- #include <sysdep.h>
- #include <tls.h>
- 
--
--#define ARCH_FORK() \
-+/* In Graphene, we prefer to call fork system call directly than clone */
-+#if USE_clone_FOR_fork
-+# define ARCH_FORK() \
-   INLINE_SYSCALL (clone, 4,						      \
- 		  CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0,     \
- 		  NULL, &THREAD_SELF->tid)
-+#else
-+# define ARCH_FORK() \
-+ ({ unsigned long ret = INLINE_SYSCALL (fork, 0);	\
-+    if (!ret) {						\
-+	pid_t pid = INLINE_SYSCALL (getpid, 0);		\
-+	THREAD_SETMEM (THREAD_SELF, pid, pid);		\
-+	THREAD_SETMEM (THREAD_SELF, tid, pid);		\
-+    } ret; })
-+#endif
- 
- #include "../fork.c"
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
-index dc95421..a772f66 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
-@@ -90,7 +90,7 @@ __lll_lock_wait_private:
- 
- 1:	LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 2:	movl	%edx, %eax
- 	xchgl	%eax, (%rdi)	/* NB:	 lock is implied */
-@@ -130,7 +130,7 @@ __lll_lock_wait:
- 
- 1:	LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 2:	movl	%edx, %eax
- 	xchgl	%eax, (%rdi)	/* NB:	 lock is implied */
-@@ -185,7 +185,7 @@ __lll_timedlock_wait:
- 
- 1:	movl	$SYS_futex, %eax
- 	movl	$2, %edx
--	syscall
-+	SYSCALL
- 
- 2:	xchgl	%edx, (%rdi)	/* NB:   lock is implied */
- 
-@@ -279,7 +279,7 @@ __lll_timedlock_wait:
- 	LOAD_FUTEX_WAIT (%esi)
- 	movq	%r12, %rdi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	/* NB: %edx == 2 */
- 	xchgl	%edx, (%r12)
-@@ -336,7 +336,7 @@ __lll_unlock_wake_private:
- 	LOAD_PRIVATE_FUTEX_WAKE (%esi)
- 	movl	$1, %edx	/* Wake one thread.  */
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	popq	%rdx
- 	cfi_adjust_cfa_offset(-8)
-@@ -366,7 +366,7 @@ __lll_unlock_wake:
- 	LOAD_FUTEX_WAKE (%esi)
- 	movl	$1, %edx	/* Wake one thread.  */
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	popq	%rdx
- 	cfi_adjust_cfa_offset(-8)
-@@ -435,7 +435,7 @@ __lll_timedwait_tid:
- #endif
- 	movq	%r12, %rdi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	cmpl	$0, (%rdi)
- 	jne	1f
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
-index 5a80ddd..f7319ca 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.h
-@@ -214,7 +214,7 @@ LLL_STUB_UNWIND_INFO_END
-     register const struct timespec *__to __asm ("r10") = timeout;	      \
-     int __status;							      \
-     register __typeof (val) _val __asm ("edx") = (val);			      \
--    __asm __volatile ("syscall"						      \
-+    __asm __volatile (SYSCALLDB						      \
- 		      : "=a" (__status)					      \
- 		      : "0" (SYS_futex), "D" (futex),			      \
- 			"S" (__lll_private_flag (FUTEX_WAIT, private)),	      \
-@@ -229,7 +229,7 @@ LLL_STUB_UNWIND_INFO_END
-     int __ignore;							      \
-     register __typeof (nr) _nr __asm ("edx") = (nr);			      \
-     LIBC_PROBE (lll_futex_wake, 3, futex, nr, private);                       \
--    __asm __volatile ("syscall"						      \
-+    __asm __volatile (SYSCALLDB						      \
- 		      : "=a" (__ignore)					      \
- 		      : "0" (SYS_futex), "D" (futex),			      \
- 			"S" (__lll_private_flag (FUTEX_WAKE, private)),	      \
-@@ -532,7 +532,7 @@ LLL_STUB_UNWIND_INFO_END
-     {									      \
-       int ignore;							      \
-       __asm __volatile (LOCK_INSTR "orl %3, (%2)\n\t"			      \
--			"syscall"					      \
-+			SYSCALLDB					      \
- 			: "=m" (futex), "=a" (ignore)			      \
- 			: "D" (&(futex)), "i" (FUTEX_OWNER_DIED),	      \
- 			  "S" (__lll_private_flag (FUTEX_WAKE, private)),     \
-@@ -547,7 +547,7 @@ LLL_STUB_UNWIND_INFO_END
-      register int __nr_move __asm ("r10") = nr_move;			      \
-      register void *__mutex __asm ("r8") = mutex;			      \
-      register int __val __asm ("r9") = val;				      \
--     __asm __volatile ("syscall"					      \
-+     __asm __volatile (SYSCALLDB					      \
- 		       : "=a" (__res)					      \
- 		       : "0" (__NR_futex), "D" ((void *) ftx),		      \
- 			 "S" (__lll_private_flag (FUTEX_CMP_REQUEUE,	      \
-@@ -573,7 +573,7 @@ LLL_STUB_UNWIND_INFO_END
-     if (_tid != 0)							      \
-       __asm __volatile ("xorq %%r10, %%r10\n\t"				      \
- 			"1:\tmovq %2, %%rax\n\t"			      \
--			"syscall\n\t"					      \
-+			SYSCALLDB					      \
- 			"cmpl $0, (%%rdi)\n\t"				      \
- 			"jne 1b"					      \
- 			: "=&a" (__ignore)				      \
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
-index 0b4ef71..36c5572 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
-@@ -80,7 +80,7 @@ __lll_robust_lock_wait:
- 	jnz	2f
- 
- 1:	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	movl	(%rdi), %eax
- 
-@@ -145,7 +145,7 @@ __lll_robust_timedlock_wait:
- 	jnz	6f
- 
- 5:	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	movl	%eax, %ecx
- 
- 	movl	(%rdi), %eax
-@@ -257,7 +257,7 @@ __lll_robust_timedlock_wait:
- 	LOAD_FUTEX_WAIT (%esi)
- 	movq	%r12, %rdi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	movq	%rax, %rcx
- 
- 	movl	(%r12), %eax
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
-index 61c2f54..e70362c 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
-@@ -62,7 +62,7 @@ pthread_barrier_wait:
- #endif
- 	xorq	%r10, %r10
- 8:	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	/* Don't return on spurious wakeups.  The syscall does not change
- 	   any register except %eax so there is no need to reload any of
-@@ -109,7 +109,7 @@ pthread_barrier_wait:
- 	movl	$FUTEX_WAKE, %esi
- 	orl	PRIVATE(%rdi), %esi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	/* Increment LEFT.  If this brings the count back to the
- 	   initial count unlock the object.  */
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
-index 67ff5fc..a95f808 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
-@@ -90,7 +90,7 @@ __pthread_cond_broadcast:
- 	movl	$SYS_futex, %eax
- 	movl	$1, %edx
- 	movl	$0x7fffffff, %r10d
--	syscall
-+	SYSCALL
- 
- 	/* For any kind of error, which mainly is EAGAIN, we try again
- 	   with WAKE.  The general test also covers running on old
-@@ -106,7 +106,7 @@ __pthread_cond_broadcast:
- 	movl	$SYS_futex, %eax
- 	movl	$1, %edx
- 	movl	$0x7fffffff, %r10d
--	syscall
-+	SYSCALL
- 
- 	/* For any kind of error, which mainly is EAGAIN, we try again
- 	   with WAKE.  The general test also covers running on old
-@@ -172,7 +172,7 @@ __pthread_cond_broadcast:
- 	orl	$FUTEX_WAKE, %esi
- #endif
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	jmp	10b
- 	.size	__pthread_cond_broadcast, .-__pthread_cond_broadcast
- versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
-index 3bff19b..80f4b47 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
-@@ -82,7 +82,7 @@ __pthread_cond_signal:
- 	addq	$cond_lock, %r8
- #endif
- 	movl	$FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
--	syscall
-+	SYSCALL
- #if cond_lock != 0
- 	subq	$cond_lock, %r8
- #endif
-@@ -99,7 +99,7 @@ __pthread_cond_signal:
- 	movq	%rcx, %r8
- 	xorq	%r10, %r10
- 	movl	(%rdi), %r9d	// XXX Can this be right?
--	syscall
-+	SYSCALL
- 
- 	leaq	-cond_futex(%rdi), %r8
- 
-@@ -118,7 +118,7 @@ __pthread_cond_signal:
- 	movl	$SYS_futex, %eax
- 	/* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
- 	movl	$1, %edx  */
--	syscall
-+	SYSCALL
- 
- 	/* Unlock.  */
- 4:	LOCK
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
-index 15e451a..14b768a 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
-@@ -188,7 +188,7 @@ __pthread_cond_timedwait:
- 	movq	%r12, %rdx
- 	addq	$cond_futex, %rdi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	cmpl	$0, %eax
- 	sete	%r15b
-@@ -234,7 +234,7 @@ __pthread_cond_timedwait:
- 	movq	%r12, %rdx
- 	addq	$cond_futex, %rdi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 62:	movq	%rax, %r14
- 
- 	movl	(%rsp), %edi
-@@ -321,7 +321,7 @@ __pthread_cond_timedwait:
- 	orl	$FUTEX_WAKE, %esi
- #endif
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	subq	$cond_nwaiters, %rdi
- 
- 55:	LOCK
-@@ -485,15 +485,8 @@ __pthread_cond_timedwait:
- 	/* Only clocks 0 and 1 are allowed so far.  Both are handled in the
- 	   kernel.  */
- 	leaq	32(%rsp), %rsi
--#  ifdef SHARED
--	mov	__vdso_clock_gettime@GOTPCREL(%rip), %RAX_LP
--	mov	(%rax), %RAX_LP
--	PTR_DEMANGLE (%RAX_LP)
--	call	*%rax
--#  else
- 	movl	$__NR_clock_gettime, %eax
--	syscall
--#  endif
-+	SYSCALL
- 
- 	/* Compute relative timeout.  */
- 	movq	(%r13), %rcx
-@@ -560,7 +553,7 @@ __pthread_cond_timedwait:
- # endif
- 	addq	$cond_futex, %rdi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	movq	%rax, %r14
- 
- 	movl	(%rsp), %edi
-@@ -732,7 +725,7 @@ __condvar_cleanup2:
- 	orl	$FUTEX_WAKE, %esi
- #endif
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	subq	$cond_nwaiters, %rdi
- 	movl	$1, %r12d
- 
-@@ -769,7 +762,7 @@ __condvar_cleanup2:
- 	orl	$FUTEX_WAKE, %esi
- #endif
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	/* Lock the mutex only if we don't own it already.  This only happens
- 	   in case of PI mutexes, if we got cancelled after a successful
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
-index 2c6b515..296659c 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
-@@ -138,7 +138,7 @@ __pthread_cond_wait:
- 
- 	movl	$(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	cmpl	$0, %eax
- 	sete	%r8b
-@@ -180,7 +180,7 @@ __pthread_cond_wait:
- #endif
- 60:	xorb	%r8b, %r8b
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 62:	movl	(%rsp), %edi
- 	callq	__pthread_disable_asynccancel
-@@ -239,7 +239,7 @@ __pthread_cond_wait:
- 	orl	$FUTEX_WAKE, %esi
- #endif
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	subq	$cond_nwaiters, %rdi
- 
- 17:	LOCK
-@@ -455,7 +455,7 @@ __condvar_cleanup1:
- 	orl	$FUTEX_WAKE, %esi
- #endif
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	subq	$cond_nwaiters, %rdi
- 	movl	$1, %ecx
- 
-@@ -493,7 +493,7 @@ __condvar_cleanup1:
- 	orl	$FUTEX_WAKE, %esi
- #endif
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	/* Lock the mutex only if we don't own it already.  This only happens
- 	   in case of PI mutexes, if we got cancelled after a successful
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
-index 7f5c081..38ecb12 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
-@@ -90,7 +90,7 @@ __pthread_once:
- # endif
- #endif
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	jmp	6b
- 
- 	/* Preserve the pointer to the control variable.  */
-@@ -123,7 +123,7 @@ __pthread_once:
- 	orl	%fs:PRIVATE_FUTEX, %esi
- #endif
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 4:	addq	$8, %rsp
- 	cfi_adjust_cfa_offset(-8)
-@@ -152,7 +152,7 @@ clear_once_control:
- 	orl	%fs:PRIVATE_FUTEX, %esi
- #endif
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	movq	%r8, %rdi
- .LcallUR:
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
-index 264ba58..c54f316 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
-@@ -82,7 +82,7 @@ __pthread_rwlock_rdlock:
- #endif
- 	addq	$READERS_WAKEUP, %rdi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	subq	$READERS_WAKEUP, %rdi
- 
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
-index f60530e..fb7894a 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
-@@ -109,7 +109,7 @@ pthread_rwlock_timedrdlock:
- #endif
- 21:	leaq	READERS_WAKEUP(%r12), %rdi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	movq	%rax, %rdx
- 
- #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
-index 7870733..f9eee96 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
-@@ -107,7 +107,7 @@ pthread_rwlock_timedwrlock:
- #endif
- 21:	leaq	WRITERS_WAKEUP(%r12), %rdi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 	movq	%rax, %rdx
- 
- #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
-index e971529..bdd1f4d 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
-@@ -79,7 +79,7 @@ __pthread_rwlock_unlock:
- #endif
- 	movl	$SYS_futex, %eax
- 	movq	%r10, %rdi
--	syscall
-+	SYSCALL
- 
- 	xorl	%eax, %eax
- 	retq
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
-index ff5392c..1afe769 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
-@@ -80,7 +80,7 @@ __pthread_rwlock_wrlock:
- #endif
- 	addq	$WRITERS_WAKEUP, %rdi
- 	movl	$SYS_futex, %eax
--	syscall
-+	SYSCALL
- 
- 	subq	$WRITERS_WAKEUP, %rdi
- 
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
-index 65e715d..7152395 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
-@@ -52,7 +52,7 @@ sem_post:
- 	movl	$FUTEX_WAKE, %esi
- 	orl	PRIVATE(%rdi), %esi
- 	movl	$1, %edx
--	syscall
-+	SYSCALL
- 
- 	testq	%rax, %rax
- 	js	1f
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
-index acb79db..f9db4d1 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
-@@ -97,7 +97,7 @@ sem_timedwait:
- 	orl	PRIVATE(%rdi), %esi
- 	movl	$SYS_futex, %eax
- 	xorl	%edx, %edx
--	syscall
-+	SYSCALL
- 	movq	%rax, %r9
- #if VALUE != 0
- 	leaq	-VALUE(%rdi), %rdi
-@@ -233,7 +233,7 @@ sem_timedwait:
- # endif
- 	movl	$SYS_futex, %eax
- 	xorl	%edx, %edx
--	syscall
-+	SYSCALL
- 	movq	%rax, %r14
- 
- 	movl	16(%rsp), %edi
-diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
-index 7f91148..ac4b8e8 100644
---- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
-+++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
-@@ -81,7 +81,7 @@ sem_wait:
- 	orl	PRIVATE(%rdi), %esi
- #endif
- 	xorl	%edx, %edx
--	syscall
-+	SYSCALL
- 	movq	%rax, %rcx
- 
- 	xchgq	%r8, %rdi
-diff --git a/nptl/sysdeps/x86_64/pthreaddef.h b/nptl/sysdeps/x86_64/pthreaddef.h
-index 50587b8..374b553 100644
---- a/nptl/sysdeps/x86_64/pthreaddef.h
-+++ b/nptl/sysdeps/x86_64/pthreaddef.h
-@@ -48,4 +48,5 @@
- 
- /* While there is no such syscall.  */
- #define __exit_thread_inline(val) \
--  asm volatile ("syscall" :: "a" (__NR_exit), "D" (val))
-+  asm volatile ("pushq %%rbx\n\tmovq syscalldb@GOTPCREL(%%rip), %%rbx\n\t" \
-+		"call %%rbx\n\t" :: "a" (__NR_exit), "D" (val) : "bx" )
-diff --git a/nptl/sysdeps/x86_64/tls.h b/nptl/sysdeps/x86_64/tls.h
-index f3b7649..433b8c9 100644
---- a/nptl/sysdeps/x86_64/tls.h
-+++ b/nptl/sysdeps/x86_64/tls.h
-@@ -28,6 +28,7 @@
- # include <sysdep.h>
- # include <libc-internal.h>
- # include <kernel-features.h>
-+# include <shim_tls.h>
- 
- /* Replacement type for __m128 since this file is included by ld.so,
-    which is compiled with -mno-sse.  It must not change the alignment
-@@ -67,6 +68,10 @@ typedef struct
- # else
-   int __unused1;
- # endif
-+
-+  shim_tcb_t shim_tcb;	/* For graphene, we allocate a shim_tcb
-+			   in the real tcb. */
-+
-   int rtld_must_xmm_save;
-   /* Reservation of some values for the TM ABI.  */
-   void *__private_tm[5];
-@@ -135,6 +140,12 @@ typedef struct
- # define GET_DTV(descr) \
-   (((tcbhead_t *) (descr))->dtv)
- 
-+/* For Graphene */
-+#define SYSCALLDB							      \
-+	"pushq %%rbx\n\t"						      \
-+	"movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t"			      \
-+	"callq *%%rbx\n\t"						      \
-+	"popq %%rbx\n\t"
- 
- /* Code to initially initialize the thread pointer.  This might need
-    special attention since 'errno' is not yet available and if the
-@@ -152,7 +163,7 @@ typedef struct
-      _head->self = _thrdescr;						      \
- 									      \
-      /* It is a simple syscall to set the %fs value for the thread.  */	      \
--     asm volatile ("syscall"						      \
-+     asm volatile (SYSCALLDB						      \
- 		   : "=a" (_result)					      \
- 		   : "0" ((unsigned long int) __NR_arch_prctl),		      \
- 		     "D" ((unsigned long int) ARCH_SET_FS),		      \
-diff --git a/scripts/mkinstalldirs b/scripts/mkinstalldirs
-index f945dbf..3c0e48c 100755
---- a/scripts/mkinstalldirs
-+++ b/scripts/mkinstalldirs
-@@ -20,9 +20,9 @@ do
-      esac
- 
-      if test ! -d "$pathcomp"; then
--        echo "mkdir $pathcomp" 1>&2
-+        echo "mkdir -p $pathcomp" 1>&2
- 
--        mkdir "$pathcomp" || lasterr=$?
-+        mkdir -p "$pathcomp" || lasterr=$?
- 
-         if test ! -d "$pathcomp"; then
-   	  errstatus=$lasterr
-diff --git a/shlib-versions b/shlib-versions
-index 9344590..4edb370 100644
---- a/shlib-versions
-+++ b/shlib-versions
-@@ -107,3 +107,5 @@ sparc64.*-.*-.*		libBrokenLocale=1	GLIBC_2.2
- # This defines the libgcc soname version this glibc is to load for
- # asynchronous cancellation to work correctly.
- .*-.*-.*		libgcc_s=1
-+
-+.*-.*-.*		liblibos=1
-diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
-index c667e34..9803b8a 100644
---- a/sysdeps/generic/ldsodefs.h
-+++ b/sysdeps/generic/ldsodefs.h
-@@ -854,8 +854,7 @@ extern void _dl_sort_fini (struct link_map **maps, size_t nmaps, char *used,
-    any shared object mappings.  The `r_state' member of `struct r_debug'
-    says what change is taking place.  This function's address is
-    the value of the `r_brk' member.  */
--extern void _dl_debug_state (void);
--rtld_hidden_proto (_dl_debug_state)
-+extern void __libc_dl_debug_state (void) __attribute__((weak));
- 
- /* Initialize `struct r_debug' if it has not already been done.  The
-    argument is the run-time load address of the dynamic linker, to be put
-diff --git a/sysdeps/unix/sysv/linux/_exit.c b/sysdeps/unix/sysv/linux/_exit.c
-index 18c4fce..a21fb32 100644
---- a/sysdeps/unix/sysv/linux/_exit.c
-+++ b/sysdeps/unix/sysv/linux/_exit.c
-@@ -29,9 +29,9 @@ _exit (status)
-   while (1)
-     {
- #ifdef __NR_exit_group
--      INLINE_SYSCALL (exit_group, 1, status);
-+      INLINE_SYSCALL_ASM (exit_group, 1, status);
- #endif
--      INLINE_SYSCALL (exit, 1, status);
-+      INLINE_SYSCALL_ASM (exit, 1, status);
- 
- #ifdef ABORT_INSTRUCTION
-       ABORT_INSTRUCTION;
-diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
-index d9bdb67..9719699 100644
---- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
-+++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
-@@ -84,7 +84,8 @@ ENTRY(____longjmp_chk)
- 	xorl	%edi, %edi
- 	lea	-sizeSS(%rsp), %RSI_LP
- 	movl	$__NR_sigaltstack, %eax
--	syscall
-+	SYSCALL
-+
- 	/* Without working sigaltstack we cannot perform the test.  */
- 	testl	%eax, %eax
- 	jne	.Lok2
-diff --git a/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c b/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
-index f712110..f6bad14 100644
---- a/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
-+++ b/sysdeps/unix/sysv/linux/x86_64/clock_gettime.c
-@@ -1,5 +1,6 @@
- #include "bits/libc-vdso.h"
- 
-+#if 0 /* in Graphene, disallow VDSO calls */
- #ifdef SHARED
- # define SYSCALL_GETTIME(id, tp) \
-   ({ long int (*f) (clockid_t, struct timespec *) = __vdso_clock_gettime; \
-@@ -16,5 +17,6 @@
-   PTR_DEMANGLE (f);							  \
-   f (id, tp); })
- #endif
-+#endif
- 
- #include "../clock_gettime.c"
-diff --git a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S
-index 53f9fbd..80d28b5 100644
---- a/sysdeps/unix/sysv/linux/x86_64/clone.S
-+++ b/sysdeps/unix/sysv/linux/x86_64/clone.S
-@@ -61,11 +61,15 @@ ENTRY (BP_SYM (__clone))
- 	jz	SYSCALL_ERROR_LABEL
- 
- 	/* Insert the argument onto the new stack.  */
--	subq	$16,%rsi
--	movq	%rcx,8(%rsi)
-+	subq	$24,%rsi
-+	movq	%rcx,16(%rsi)
- 
- 	/* Save the function pointer.  It will be popped off in the
- 	   child in the ebx frobbing below.  */
-+	movq	%rdi,8(%rsi)
-+
-+	/* Push an additional pointer as return address into the stack */
-+	leaq	L(clone_return)(%rip),%rdi
- 	movq	%rdi,0(%rsi)
- 
- 	/* Do the system call.  */
-@@ -78,8 +82,9 @@ ENTRY (BP_SYM (__clone))
- 	/* End FDE now, because in the child the unwind info will be
- 	   wrong.  */
- 	cfi_endproc;
--	syscall
-+	SYSCALL
- 
-+L(clone_return):
- 	testq	%rax,%rax
- 	jl	SYSCALL_ERROR_LABEL
- 	jz	L(thread_start)
-@@ -101,13 +106,14 @@ L(thread_start):
- 	movl	$-1, %eax
- 	jne	2f
- 	movl	$SYS_ify(getpid), %eax
--	syscall
-+	SYSCALL
- 2:	movl	%eax, %fs:PID
- 	movl	%eax, %fs:TID
- 1:
- #endif
- 
- 	/* Set up arguments for the function call.  */
-+	addq	$8,%rsp		/* Skip the return address */
- 	popq	%rax		/* Function to call.  */
- 	popq	%rdi		/* Argument.  */
- 	call	*%rax
-diff --git a/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
-index 5f2b64c..df57736 100644
---- a/sysdeps/unix/sysv/linux/x86_64/getcontext.S
-+++ b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
-@@ -75,7 +75,7 @@ ENTRY(__getcontext)
- #endif
- 	movl	$_NSIG8,%r10d
- 	movl	$__NR_rt_sigprocmask, %eax
--	syscall
-+	SYSCALL
- 	cmpq	$-4095, %rax		/* Check %rax for error.  */
- 	jae	SYSCALL_ERROR_LABEL	/* Jump to error handler if error.  */
- 
-diff --git a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
-index d52f938..d75b502 100644
---- a/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
-+++ b/sysdeps/unix/sysv/linux/x86_64/gettimeofday.c
-@@ -17,6 +17,7 @@
- 
- #include <sys/time.h>
- 
-+#if 0 /* In graphene, do not use vsyscall or VDSO call */
- #ifdef SHARED
- 
- # include <dl-vdso.h>
-@@ -42,7 +43,8 @@ asm (".type __gettimeofday, %gnu_indirect_function");
- asm (".globl __GI___gettimeofday\n"
-      "__GI___gettimeofday = __gettimeofday");
- 
--#else
-+#endif
-+#endif
- 
- # include <sysdep.h>
- # include <errno.h>
-@@ -54,6 +56,5 @@ __gettimeofday (struct timeval *tv, struct timezone *tz)
- }
- libc_hidden_def (__gettimeofday)
- 
--#endif
- weak_alias (__gettimeofday, gettimeofday)
- libc_hidden_weak (gettimeofday)
-diff --git a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
-index 3b319d7..98d8612 100644
---- a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
-+++ b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
-@@ -30,6 +30,7 @@ ENTRY (sched_getcpu)
- 	sub	$0x8, %rsp
- 	cfi_adjust_cfa_offset(8)
- 
-+#if 0 /* for Graphene, never do VDSO calls */
- 	movq	%rsp, %rdi
- 	xorl	%esi, %esi
- 	movl	$VGETCPU_CACHE_OFFSET, %edx
-@@ -39,16 +40,19 @@ ENTRY (sched_getcpu)
- 	movq	__vdso_getcpu(%rip), %rax
- 	PTR_DEMANGLE (%rax)
- 	callq	*%rax
--#else
--# ifdef __NR_getcpu
-+#endif
-+#endif
-+
-+#ifdef __NR_getcpu
- 	movl	$__NR_getcpu, %eax
--	syscall
--#  ifndef __ASSUME_GETCPU_SYSCALL
-+	SYSCALL
-+#endif
-+
-+#if 0 /* for Graphene, never do vsyscall */
-+# ifndef __ASSUME_GETCPU_SYSCALL
- 	cmpq	$-ENOSYS, %rax
- 	jne	1f
--#  endif
--# endif
--# ifndef __ASSUME_GETCPU_SYSCALL
-+
- 	movq	$VSYSCALL_ADDR_vgetcpu, %rax
- 	callq	*%rax
- 1:
-diff --git a/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
-index adcb243..0d662e3 100644
---- a/sysdeps/unix/sysv/linux/x86_64/setcontext.S
-+++ b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
-@@ -43,7 +43,7 @@ ENTRY(__setcontext)
- 	movl	$SIG_SETMASK, %edi
- 	movl	$_NSIG8,%r10d
- 	movl	$__NR_rt_sigprocmask, %eax
--	syscall
-+	SYSCALL
- 	popq	%rdi			/* Reload %rdi, adjust stack.  */
- 	cfi_adjust_cfa_offset(-8)
- 	cmpq	$-4095, %rax		/* Check %rax for error.  */
-diff --git a/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
-index 5a3ad18..9ac8b6e 100644
---- a/sysdeps/unix/sysv/linux/x86_64/sigaction.c
-+++ b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
-@@ -129,7 +129,8 @@ asm									\
-    "	.type __" #name ",@function\n"					\
-    "__" #name ":\n"							\
-    "	movq $" #syscall ", %rax\n"					\
--   "	syscall\n"							\
-+   "	movq syscalldb@GOTPCREL(%rip), %rbx\n"				\
-+   "	call *%rbx\n"							\
-    ".LEND_" #name ":\n"							\
-    ".section .eh_frame,\"a\",@progbits\n"				\
-    ".LSTARTFRAME_" #name ":\n"						\
-diff --git a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
-index 0d04a01..e8483db 100644
---- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
-+++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
-@@ -75,7 +75,7 @@ ENTRY(__swapcontext)
- 	movl	$SIG_SETMASK, %edi
- 	movl	$_NSIG8,%r10d
- 	movl	$__NR_rt_sigprocmask, %eax
--	syscall
-+	SYSCALL
- 	cmpq	$-4095, %rax		/* Check %rax for error.  */
- 	jae	SYSCALL_ERROR_LABEL	/* Jump to error handler if error.  */
- 
-diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/x86_64/syscall.S
-index 87dfd8c..c144b42 100644
---- a/sysdeps/unix/sysv/linux/x86_64/syscall.S
-+++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S
-@@ -34,7 +34,7 @@ ENTRY (syscall)
- 	movq %r8, %r10
- 	movq %r9, %r8
- 	movq 8(%rsp),%r9	/* arg6 is on the stack.  */
--	syscall			/* Do the system call.  */
-+	SYSCALL			/* Do the system call.  */
- 	cmpq $-4095, %rax	/* Check %rax for error.  */
- 	jae SYSCALL_ERROR_LABEL	/* Jump to error handler if error.  */
- 	ret			/* Return to caller.  */
-diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
-index 5323104..d466181 100644
---- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
-+++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
-@@ -23,6 +23,7 @@
- #include <bp-sym.h>
- #include <bp-asm.h>
- #include <tls.h>
-+#include "syscalldb.h"
- 
- #ifdef IS_IN_rtld
- # include <dl-sysdep.h>		/* Defines RTLD_PRIVATE_ERRNO.  */
-@@ -174,11 +175,18 @@
- 
-     Syscalls of more than 6 arguments are not supported.  */
- 
-+# undef	SYSCALL
-+# define SYSCALL				\
-+    pushq %rbx;					\
-+    movq syscalldb@GOTPCREL(%rip), %rbx;	\
-+    call *%rbx;					\
-+    popq %rbx;
-+
- # undef	DO_CALL
- # define DO_CALL(syscall_name, args)		\
-     DOARGS_##args				\
-     movl $SYS_ify (syscall_name), %eax;		\
--    syscall;
-+    SYSCALL
- 
- # define DOARGS_0 /* nothing */
- # define DOARGS_1 /* nothing */
-@@ -192,9 +200,20 @@
- /* Define a macro which expands inline into the wrapper code for a system
-    call.  */
- # undef INLINE_SYSCALL
--# define INLINE_SYSCALL(name, nr, args...) \
-+# define INLINE_SYSCALL(name, nr_args...) \
-+  ({									      \
-+    unsigned long int resultvar = INTERNAL_SYSCALL (name, , ##nr_args);	      \
-+    if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0))	      \
-+      {									      \
-+	__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, ));		      \
-+	resultvar = (unsigned long int) -1;				      \
-+      }									      \
-+    (long int) resultvar; })
-+
-+# undef INLINE_SYSCALL_ASM
-+# define INLINE_SYSCALL_ASM(name, nr_args...) \
-   ({									      \
--    unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args);	      \
-+    unsigned long int resultvar = INTERNAL_SYSCALL_ASM (name, , ##nr_args);   \
-     if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0))	      \
-       {									      \
- 	__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, ));		      \
-@@ -206,9 +225,9 @@
-    into the wrapper code for a system call.  It should be used when size
-    of any argument > size of long int.  */
- # undef INLINE_SYSCALL_TYPES
--# define INLINE_SYSCALL_TYPES(name, nr, args...) \
-+# define INLINE_SYSCALL_TYPES(name, nr_args...) \
-   ({									      \
--    unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , nr, args);  \
-+    unsigned long int resultvar = INTERNAL_SYSCALL_TYPES (name, , ##nr_args); \
-     if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0))	      \
-       {									      \
- 	__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, ));		      \
-@@ -225,13 +244,20 @@
-     LOAD_ARGS_##nr (args)						      \
-     LOAD_REGS_##nr							      \
-     asm volatile (							      \
--    "syscall\n\t"							      \
-+    "movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t"				      \
-+    "call *%%rbx\n\t"							      \
-     : "=a" (resultvar)							      \
--    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
-+    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx", "bx");	      \
-     (long int) resultvar; })
-+# define INTERNAL_SYSCALL_NCS_ASM INTERNAL_SYSCALL_NCS
-+
- # undef INTERNAL_SYSCALL
--# define INTERNAL_SYSCALL(name, err, nr, args...) \
--  INTERNAL_SYSCALL_NCS (__NR_##name, err, nr, ##args)
-+# define INTERNAL_SYSCALL(name, err, nr_args...) \
-+  INTERNAL_SYSCALL_NCS (__NR_##name, err, ##nr_args)
-+
-+# undef INTERNAL_SYSCALL_ASM
-+# define INTERNAL_SYSCALL_ASM(name, err, nr_args...) \
-+  INTERNAL_SYSCALL_NCS_ASM (__NR_##name, err, ##nr_args)
- 
- # define INTERNAL_SYSCALL_NCS_TYPES(name, err, nr, args...) \
-   ({									      \
-@@ -239,9 +265,10 @@
-     LOAD_ARGS_TYPES_##nr (args)						      \
-     LOAD_REGS_TYPES_##nr (args)						      \
-     asm volatile (							      \
--    "syscall\n\t"							      \
-+    "movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t"				      \
-+    "call *%%rbx\n\t"							      \
-     : "=a" (resultvar)							      \
--    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
-+    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx", "bx");	      \
-     (long int) resultvar; })
- # undef INTERNAL_SYSCALL_TYPES
- # define INTERNAL_SYSCALL_TYPES(name, err, nr, args...) \
-@@ -254,6 +281,7 @@
- # undef INTERNAL_SYSCALL_ERRNO
- # define INTERNAL_SYSCALL_ERRNO(val, err)	(-(val))
- 
-+# if 0 /* for Graphene, never do vsyscall */
- # ifdef SHARED
- #  define INLINE_VSYSCALL(name, nr, args...) \
-   ({									      \
-@@ -302,12 +330,13 @@
-     v_ret;								      \
-   })
- 
--# else
--#  define INLINE_VSYSCALL(name, nr, args...) \
--  INLINE_SYSCALL (name, nr, ##args)
--#  define INTERNAL_VSYSCALL(name, err, nr, args...) \
--  INTERNAL_SYSCALL (name, err, nr, ##args)
- # endif
-+# endif
-+
-+#  define INLINE_VSYSCALL(name, nr_args...) \
-+  INLINE_SYSCALL (name, ##nr_args)
-+#  define INTERNAL_VSYSCALL(name, err, nr_args...) \
-+  INTERNAL_SYSCALL (name, err, ##nr_args)
- 
- # define LOAD_ARGS_0()
- # define LOAD_REGS_0
-diff --git a/sysdeps/unix/sysv/linux/x86_64/time.c b/sysdeps/unix/sysv/linux/x86_64/time.c
-deleted file mode 100644
-index 65703ca..0000000
---- a/sysdeps/unix/sysv/linux/x86_64/time.c
-+++ /dev/null
-@@ -1,60 +0,0 @@
--/* Copyright (C) 2001,02,2003,2011 Free Software Foundation, Inc.
--   This file is part of the GNU C Library.
--
--   The GNU C Library is free software; you can redistribute it and/or
--   modify it under the terms of the GNU Lesser General Public
--   License as published by the Free Software Foundation; either
--   version 2.1 of the License, or (at your option) any later version.
--
--   The GNU C Library is distributed in the hope that it will be useful,
--   but WITHOUT ANY WARRANTY; without even the implied warranty of
--   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--   Lesser General Public License for more details.
--
--   You should have received a copy of the GNU Lesser General Public
--   License along with the GNU C Library; if not, see
--   <http://www.gnu.org/licenses/>.  */
--
--#ifdef SHARED
--/* Redefine time so that the compiler won't complain about the type
--   mismatch with the IFUNC selector in strong_alias, below.  */
--#undef time
--#define time __redirect_time
--#include <time.h>
--
--#include <dl-vdso.h>
--
--#define VSYSCALL_ADDR_vtime	0xffffffffff600400
--
--/* Avoid DWARF definition DIE on ifunc symbol so that GDB can handle
--   ifunc symbol properly.  */
--extern __typeof (__redirect_time) __libc_time;
--void *time_ifunc (void) __asm__ ("__libc_time");
--
--void *
--time_ifunc (void)
--{
--  PREPARE_VERSION (linux26, "LINUX_2.6", 61765110);
--
--  /* If the vDSO is not available we fall back on the old vsyscall.  */
--  return _dl_vdso_vsym ("__vdso_time", &linux26) ?: (void *) VSYSCALL_ADDR_vtime;
--}
--__asm (".type __libc_time, %gnu_indirect_function");
--
--#undef time
--strong_alias (__libc_time, time)
--libc_hidden_ver (__libc_time, time)
--
--#else
--
--# include <time.h>
--# include <sysdep.h>
--
--time_t
--time (time_t *t)
--{
--  INTERNAL_SYSCALL_DECL (err);
--  return INTERNAL_SYSCALL (time, err, 1, t);
--}
--
--#endif
-diff --git a/sysdeps/unix/sysv/linux/x86_64/vfork.S b/sysdeps/unix/sysv/linux/x86_64/vfork.S
-index c28087d..ea4ff9f 100644
---- a/sysdeps/unix/sysv/linux/x86_64/vfork.S
-+++ b/sysdeps/unix/sysv/linux/x86_64/vfork.S
-@@ -38,7 +38,7 @@ ENTRY (__vfork)
- 
- 	/* Stuff the syscall number in RAX and enter into the kernel.  */
- 	movl	$SYS_ify (vfork), %eax
--	syscall
-+	SYSCALL
- 
- 	/* Push back the return PC.  */
- 	pushq	%rdi
-diff --git a/sysdeps/x86_64/dl-machine.h b/sysdeps/x86_64/dl-machine.h
-index d2654aa..9bd840f 100644
---- a/sysdeps/x86_64/dl-machine.h
-+++ b/sysdeps/x86_64/dl-machine.h
-@@ -511,7 +511,8 @@ elf_machine_lazy_rel (struct link_map *map,
- 	value = ((ElfW(Addr) (*) (void)) value) ();
-       *reloc_addr = value;
-     }
--  else
-+  /* for graphene, get around R_X86_64_NONE */
-+  else if (__builtin_expect (r_type != R_X86_64_NONE, 1))
-     _dl_reloc_bad_type (map, r_type, 1);
- }
- 

+ 0 - 1
LibOS/glibc-2.17/elf/syscallas.S

@@ -1 +0,0 @@
-../syscallas.S

+ 0 - 1
LibOS/glibc-2.17/elf/syscalldb.c

@@ -1 +0,0 @@
-../syscalldb.c

+ 0 - 56
LibOS/glibc-2.17/libos/Makefile

@@ -1,56 +0,0 @@
-# Copyright (C) 1996-2001,2002,2003,2004,2005,2006
-#	Free Software Foundation, Inc.
-# This file is part of the GNU C Library.
-
-# The GNU C Library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-
-# The GNU C Library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-
-# You should have received a copy of the GNU Lesser General Public
-# License along with the GNU C Library; if not, write to the Free
-# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307 USA.
-
-# Makefile for the libos library.
-
-subdir		:= libos
-
-# Installed header files.
-headers		:= 
-
-# Internal header files.
-distribute	:= errno.h
-
-liblibos-routines := checkpoint sandbox msgpersist benchmark
-
-# Build the -llibos library.
-
-extra-libs	:= liblibos
-extra-libs-others = $(extra-libs)
-
-include ../Makeconfig
-
-ifeq ($(versioning),yes)
-liblibos-routines	+=
-liblibos-shared-only-routines :=
-endif
-
-tests =
-
-modules-names =
-
-extra-test-objs += $(modules-names:=.os)
-generated := $(modules-names:=.so)
-
-include ../Rules
-
-# Depend on libc.so so a DT_NEEDED is generated in the shared objects.
-# This ensures they will load libc.so for needed symbols if loaded by
-# a statically-linked program that hasn't already loaded it.
-$(objpfx)liblibos.so: $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a

+ 0 - 15
LibOS/glibc-2.17/libos/Versions

@@ -1,15 +0,0 @@
-liblibos {
-  GLIBC_2.12 {
-    # checkpoint.c
-    checkpoint;
-
-    # sandbox.c
-    sandbox_create; sandbox_attach; sandbox_current;
-
-    # msgpersist.c
-    msgpersist;
-
-    # benchmark.c
-    benchmark_rpc; send_rpc; recv_rpc;
-  }
-}

+ 0 - 27
LibOS/glibc-2.17/libos/benchmark.c

@@ -1,27 +0,0 @@
-#include <errno.h>
-#include <sysdep-cancel.h>
-#include <sys/syscall.h>
-#include <kernel-features.h>
-#include <sysdep.h>
-#include <shim_unistd.h>
-
-#ifdef __NR_benchmark_rpc
-int benchmark_rpc(pid_t pid, int times, const void * buf, size_t size)
-{
-	return INLINE_SYSCALL (benchmark_rpc, 4, pid, times, buf, size);
-}
-#endif
-
-#ifdef __NR_send_rpc
-size_t send_rpc (pid_t pid, const void * buf, size_t size)
-{
-	return INLINE_SYSCALL (send_rpc, 3, pid, buf, size);
-}
-#endif
-
-#ifdef __NR_recv_rpc
-size_t recv_rpc (pid_t * pid, void * buf, size_t size)
-{
-	return INLINE_SYSCALL (recv_rpc, 3, pid, buf, size);
-}
-#endif

+ 0 - 13
LibOS/glibc-2.17/libos/checkpoint.c

@@ -1,13 +0,0 @@
-#include <errno.h>
-#include <sysdep-cancel.h>
-#include <sys/syscall.h>
-#include <kernel-features.h>
-#include <sysdep.h>
-#include <shim_unistd.h>
-
-#ifdef __NR_checkpoint
-int checkpoint (const char * filename)
-{
-	return INLINE_SYSCALL (checkpoint, 1, filename);
-}
-#endif

+ 0 - 13
LibOS/glibc-2.17/libos/msgpersist.c

@@ -1,13 +0,0 @@
-#include <errno.h>
-#include <sysdep-cancel.h>
-#include <sys/syscall.h>
-#include <kernel-features.h>
-#include <sysdep.h>
-#include <shim_unistd.h>
-
-#ifdef __NR_msgpersist
-int msgpersist (int msqid, int cmd)
-{
-	return INLINE_SYSCALL (msgpersist, 2, msqid, cmd);
-}
-#endif

+ 0 - 27
LibOS/glibc-2.17/libos/sandbox.c

@@ -1,27 +0,0 @@
-#include <errno.h>
-#include <sysdep-cancel.h>
-#include <sys/syscall.h>
-#include <kernel-features.h>
-#include <sysdep.h>
-#include <shim_unistd.h>
-
-#ifdef __NR_sandbox_create
-long sandbox_create(int flags, const char *fs_sb, struct net_sb *net_sb)
-{
-	return INLINE_SYSCALL (sandbox_create, 3, flags, fs_sb, net_sb);
-}
-#endif
-
-#ifdef __NR_sandbox_attach
-int sandbox_attach(unsigned int sbid)
-{
-	return INLINE_SYSCALL (sandbox_attach, 1, sbid);
-}
-#endif
-
-#ifdef __NR_sandbox_current
-long sandbox_current(void)
-{
-	return INLINE_SYSCALL (sandbox_current, 0);
-}
-#endif

+ 0 - 11
LibOS/glibc-2.17/syscallas.S

@@ -1,11 +0,0 @@
-#include <syscalldb.h>
-
-.weak syscalldb
-.type syscalldb,@function
-
-syscalldb:
-	.cfi_startproc
-	syscall
-	retq
-	.cfi_endproc
-	.size syscalldb,.-syscalldb

+ 0 - 10
LibOS/glibc-2.17/syscalldb.c

@@ -1,10 +0,0 @@
-#include "syscalldb.h"
-#include <stdarg.h>
-
-int register_library (const char * name, unsigned long load_address)
-	__attribute__((weak));
-
-int register_library (const char * name, unsigned long load_address)
-{
-	return 0;
-}

+ 0 - 15
LibOS/glibc-2.17/syscalldb.h

@@ -1,15 +0,0 @@
-#ifndef _SYSCALLDB_H_
-#define _SYSCALLDB_H_
-
-#ifdef __ASSEMBLER__
-.weak syscalldb
-.type syscalldb, @function
-
-#else /* !__ASSEMBLER__ */
-asm (
-".weak syscalldb\r\n"
-".type syscalldb, @function\r\n");
-
-#endif /* Assembler */
-
-#endif /* _SYSCALLDB_H */

+ 0 - 1
LibOS/glibc-2.17/sysdeps/unix/sysv/linux/x86_64/syscalldb.h

@@ -1 +0,0 @@
-../../../../../syscalldb.h

+ 111 - 134
LibOS/glibc-2.19.patch

@@ -316,7 +316,7 @@ index 4c58fc9..0ae2fa8 100644
  dl-routines += dl-cache
  endif
 diff --git a/elf/Versions b/elf/Versions
-index 2383992..1cdf63a 100644
+index 2383992..98687f6 100644
 --- a/elf/Versions
 +++ b/elf/Versions
 @@ -24,14 +24,15 @@ libc {
@@ -348,7 +348,7 @@ index 2383992..1cdf63a 100644
      __pointer_chk_guard;
    }
 +  SHIM {
-+    syscalldb; glibc_vers_2_17; glibc_option; register_library;
++    syscalldb; glibc_version; glibc_option; register_library;
 +  }
  }
 diff --git a/elf/circleload1.c b/elf/circleload1.c
@@ -563,7 +563,7 @@ index 0ae0b7f..f883910 100644
  static int
  check_loaded_objects (const char **loaded)
 diff --git a/elf/rtld.c b/elf/rtld.c
-index 6dcbabc..82cfb7d 100644
+index 6dcbabc..c87c773 100644
 --- a/elf/rtld.c
 +++ b/elf/rtld.c
 @@ -356,6 +356,23 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
@@ -574,15 +574,15 @@ index 6dcbabc..82cfb7d 100644
 +   library. If not, tell the user to update glibc. */
 +#include "glibc-version.h"
 +
-+volatile const int glibc_vers_2_17 __attribute__((weak)) = GLIBC_VERSION_2_17;
++volatile const int glibc_version __attribute__((weak)) = GLIBC_VERSION;
 +
 +static void __attribute__((noinline,optimize("-O0")))
 +check_glibc_version (void)
 +{
-+  if (glibc_vers_2_17 != GLIBC_VERSION_2_17)
++  if (glibc_version != GLIBC_VERSION)
 +    {
 +      _dl_fatal_printf ("Warning from Graphene: "
-+			"Glibc version is incorrect. Please rebuild Glibc.\n");
++                        "Glibc version is incorrect. Please rebuild Glibc.\n");
 +      _exit (1);
 +    }
 +}
@@ -994,7 +994,7 @@ index a036b92..40a1eaf 100644
  
  #include "../fork.c"
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
-index f2dca07..e5b3f2f 100644
+index f2dca07..0ce7c67 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S
 @@ -90,7 +90,7 @@ __lll_lock_wait_private:
@@ -1002,7 +1002,7 @@ index f2dca07..e5b3f2f 100644
  1:	LIBC_PROBE (lll_lock_wait_private, 1, %rdi)
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  2:	movl	%edx, %eax
  	xchgl	%eax, (%rdi)	/* NB:	 lock is implied */
@@ -1011,7 +1011,7 @@ index f2dca07..e5b3f2f 100644
  1:	LIBC_PROBE (lll_lock_wait, 2, %rdi, %rsi)
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  2:	movl	%edx, %eax
  	xchgl	%eax, (%rdi)	/* NB:	 lock is implied */
@@ -1020,7 +1020,7 @@ index f2dca07..e5b3f2f 100644
  1:	movl	$SYS_futex, %eax
  	movl	$2, %edx
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  2:	xchgl	%edx, (%rdi)	/* NB:   lock is implied */
  
@@ -1029,7 +1029,7 @@ index f2dca07..e5b3f2f 100644
  	movq	%r12, %rdi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	/* NB: %edx == 2 */
  	xchgl	%edx, (%r12)
@@ -1038,7 +1038,7 @@ index f2dca07..e5b3f2f 100644
  	movl	$1, %edx	/* Wake one thread.  */
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	popq	%rdx
  	cfi_adjust_cfa_offset(-8)
@@ -1047,7 +1047,7 @@ index f2dca07..e5b3f2f 100644
  	movl	$1, %edx	/* Wake one thread.  */
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	popq	%rdx
  	cfi_adjust_cfa_offset(-8)
@@ -1056,7 +1056,7 @@ index f2dca07..e5b3f2f 100644
  	movq	%r12, %rdi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	cmpl	$0, (%rdi)
  	jne	1f
@@ -1110,7 +1110,7 @@ index 0a26739..8aae14a 100644
  			"jne 1b"					      \
  			: "=&a" (__ignore)				      \
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
-index 990b6f9..89dbe32 100644
+index 990b6f9..b01214d 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S
 @@ -80,7 +80,7 @@ __lll_robust_lock_wait:
@@ -1118,7 +1118,7 @@ index 990b6f9..89dbe32 100644
  
  1:	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	movl	(%rdi), %eax
  
@@ -1127,7 +1127,7 @@ index 990b6f9..89dbe32 100644
  
  5:	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	movl	%eax, %ecx
  
  	movl	(%rdi), %eax
@@ -1136,12 +1136,12 @@ index 990b6f9..89dbe32 100644
  	movq	%r12, %rdi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	movq	%rax, %rcx
  
  	movl	(%r12), %eax
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
-index eec17f2..4472960 100644
+index eec17f2..a350340 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_barrier_wait.S
 @@ -62,7 +62,7 @@ pthread_barrier_wait:
@@ -1149,7 +1149,7 @@ index eec17f2..4472960 100644
  	xorq	%r10, %r10
  8:	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	/* Don't return on spurious wakeups.  The syscall does not change
  	   any register except %eax so there is no need to reload any of
@@ -1158,12 +1158,12 @@ index eec17f2..4472960 100644
  	orl	PRIVATE(%rdi), %esi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	/* Increment LEFT.  If this brings the count back to the
  	   initial count unlock the object.  */
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
-index 985e0f1..f180ab1 100644
+index 985e0f1..d559456 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_broadcast.S
 @@ -90,7 +90,7 @@ __pthread_cond_broadcast:
@@ -1171,7 +1171,7 @@ index 985e0f1..f180ab1 100644
  	movl	$1, %edx
  	movl	$0x7fffffff, %r10d
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	/* For any kind of error, which mainly is EAGAIN, we try again
  	   with WAKE.  The general test also covers running on old
@@ -1180,7 +1180,7 @@ index 985e0f1..f180ab1 100644
  	movl	$1, %edx
  	movl	$0x7fffffff, %r10d
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	/* For any kind of error, which mainly is EAGAIN, we try again
  	   with WAKE.  The general test also covers running on old
@@ -1189,12 +1189,12 @@ index 985e0f1..f180ab1 100644
  #endif
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	jmp	10b
  	.size	__pthread_cond_broadcast, .-__pthread_cond_broadcast
  versioned_symbol (libpthread, __pthread_cond_broadcast, pthread_cond_broadcast,
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
-index 53d65b6..8724325 100644
+index 53d65b6..16df581 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_signal.S
 @@ -82,7 +82,7 @@ __pthread_cond_signal:
@@ -1202,7 +1202,7 @@ index 53d65b6..8724325 100644
  #endif
  	movl	$FUTEX_OP_CLEAR_WAKE_IF_GT_ONE, %r9d
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  #if cond_lock != 0
  	subq	$cond_lock, %r8
  #endif
@@ -1211,7 +1211,7 @@ index 53d65b6..8724325 100644
  	xorq	%r10, %r10
  	movl	(%rdi), %r9d	// XXX Can this be right?
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	leaq	-cond_futex(%rdi), %r8
  
@@ -1220,12 +1220,12 @@ index 53d65b6..8724325 100644
  	/* %rdx should be 1 already from $FUTEX_WAKE_OP syscall.
  	movl	$1, %edx  */
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	/* Unlock.  */
  4:	LOCK
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
-index 0dc2340..cac13bf 100644
+index 0dc2340..8aff242 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S
 @@ -188,7 +188,7 @@ __pthread_cond_timedwait:
@@ -1233,7 +1233,7 @@ index 0dc2340..cac13bf 100644
  	addq	$cond_futex, %rdi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	cmpl	$0, %eax
  	sete	%r15b
@@ -1242,7 +1242,7 @@ index 0dc2340..cac13bf 100644
  	addq	$cond_futex, %rdi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  62:	movq	%rax, %r14
  
  	movl	(%rsp), %edi
@@ -1251,7 +1251,7 @@ index 0dc2340..cac13bf 100644
  #endif
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	subq	$cond_nwaiters, %rdi
  
  55:	LOCK
@@ -1268,7 +1268,7 @@ index 0dc2340..cac13bf 100644
  	movl	$__NR_clock_gettime, %eax
 -	syscall
 -#  endif
-+	SYSCALL
++	SYSCALLDB
  
  	/* Compute relative timeout.  */
  	movq	(%r13), %rcx
@@ -1277,7 +1277,7 @@ index 0dc2340..cac13bf 100644
  	addq	$cond_futex, %rdi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	movq	%rax, %r14
  
  	movl	(%rsp), %edi
@@ -1286,7 +1286,7 @@ index 0dc2340..cac13bf 100644
  #endif
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	subq	$cond_nwaiters, %rdi
  	movl	$1, %r12d
  
@@ -1295,12 +1295,12 @@ index 0dc2340..cac13bf 100644
  #endif
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	/* Lock the mutex only if we don't own it already.  This only happens
  	   in case of PI mutexes, if we got cancelled after a successful
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
-index 0e61d0a..60e104b 100644
+index 0e61d0a..b4bcc15 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S
 @@ -138,7 +138,7 @@ __pthread_cond_wait:
@@ -1308,7 +1308,7 @@ index 0e61d0a..60e104b 100644
  	movl	$(FUTEX_WAIT_REQUEUE_PI|FUTEX_PRIVATE_FLAG), %esi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	cmpl	$0, %eax
  	sete	%r8b
@@ -1317,7 +1317,7 @@ index 0e61d0a..60e104b 100644
  60:	xorb	%r8b, %r8b
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  62:	movl	(%rsp), %edi
  	callq	__pthread_disable_asynccancel
@@ -1326,7 +1326,7 @@ index 0e61d0a..60e104b 100644
  #endif
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	subq	$cond_nwaiters, %rdi
  
  17:	LOCK
@@ -1335,7 +1335,7 @@ index 0e61d0a..60e104b 100644
  #endif
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	subq	$cond_nwaiters, %rdi
  	movl	$1, %ecx
  
@@ -1344,12 +1344,12 @@ index 0e61d0a..60e104b 100644
  #endif
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	/* Lock the mutex only if we don't own it already.  This only happens
  	   in case of PI mutexes, if we got cancelled after a successful
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
-index 2cbe2fa..d4e229a 100644
+index 2cbe2fa..489998a 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_once.S
 @@ -90,7 +90,7 @@ __pthread_once:
@@ -1357,7 +1357,7 @@ index 2cbe2fa..d4e229a 100644
  #endif
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	jmp	6b
  
  	/* Preserve the pointer to the control variable.  */
@@ -1366,7 +1366,7 @@ index 2cbe2fa..d4e229a 100644
  #endif
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  4:	addq	$8, %rsp
  	cfi_adjust_cfa_offset(-8)
@@ -1375,12 +1375,12 @@ index 2cbe2fa..d4e229a 100644
  #endif
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	movq	%r8, %rdi
  .LcallUR:
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
-index 3bbb4c7..8ebf317 100644
+index 3bbb4c7..53d5ca6 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_rdlock.S
 @@ -82,7 +82,7 @@ __pthread_rwlock_rdlock:
@@ -1388,12 +1388,12 @@ index 3bbb4c7..8ebf317 100644
  	addq	$READERS_WAKEUP, %rdi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	subq	$READERS_WAKEUP, %rdi
  
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
-index 40bcc04..d6c9c82 100644
+index 40bcc04..348170e 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S
 @@ -109,7 +109,7 @@ pthread_rwlock_timedrdlock:
@@ -1401,12 +1401,12 @@ index 40bcc04..d6c9c82 100644
  21:	leaq	READERS_WAKEUP(%r12), %rdi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	movq	%rax, %rdx
  
  #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
-index f57ef52..78a2655 100644
+index f57ef52..e9ac77f 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S
 @@ -106,7 +106,7 @@ pthread_rwlock_timedwrlock:
@@ -1414,12 +1414,12 @@ index f57ef52..78a2655 100644
  21:	leaq	WRITERS_WAKEUP(%r12), %rdi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	movq	%rax, %rdx
  
  #ifndef __ASSUME_FUTEX_CLOCK_REALTIME
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
-index d779f7b..4dec0c0 100644
+index d779f7b..849c74f 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_unlock.S
 @@ -79,7 +79,7 @@ __pthread_rwlock_unlock:
@@ -1427,12 +1427,12 @@ index d779f7b..4dec0c0 100644
  	movl	$SYS_futex, %eax
  	movq	%r10, %rdi
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	xorl	%eax, %eax
  	retq
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
-index e444def..ba31821 100644
+index e444def..fd94930 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_wrlock.S
 @@ -80,7 +80,7 @@ __pthread_rwlock_wrlock:
@@ -1440,12 +1440,12 @@ index e444def..ba31821 100644
  	addq	$WRITERS_WAKEUP, %rdi
  	movl	$SYS_futex, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	subq	$WRITERS_WAKEUP, %rdi
  
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
-index 1c11600..d276efa 100644
+index 1c11600..bd166cf 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_post.S
 @@ -52,7 +52,7 @@ sem_post:
@@ -1453,12 +1453,12 @@ index 1c11600..d276efa 100644
  	orl	PRIVATE(%rdi), %esi
  	movl	$1, %edx
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	testq	%rax, %rax
  	js	1f
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
-index 880610e..06fd57c 100644
+index 880610e..e520049 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S
 @@ -97,7 +97,7 @@ sem_timedwait:
@@ -1466,7 +1466,7 @@ index 880610e..06fd57c 100644
  	movl	$SYS_futex, %eax
  	xorl	%edx, %edx
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	movq	%rax, %r9
  #if VALUE != 0
  	leaq	-VALUE(%rdi), %rdi
@@ -1475,12 +1475,12 @@ index 880610e..06fd57c 100644
  	movl	$SYS_futex, %eax
  	xorl	%edx, %edx
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	movq	%rax, %r14
  
  	movl	16(%rsp), %edi
 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
-index 8f4d068..d9b49e4 100644
+index 8f4d068..fe6dfbf 100644
 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
 +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S
 @@ -81,7 +81,7 @@ sem_wait:
@@ -1488,34 +1488,34 @@ index 8f4d068..d9b49e4 100644
  #endif
  	xorl	%edx, %edx
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	movq	%rax, %rcx
  
  	xchgq	%r8, %rdi
 diff --git a/nptl/sysdeps/x86_64/pthreaddef.h b/nptl/sysdeps/x86_64/pthreaddef.h
-index 18a15a1..ac3d6d3 100644
+index 18a15a1..f050241 100644
 --- a/nptl/sysdeps/x86_64/pthreaddef.h
 +++ b/nptl/sysdeps/x86_64/pthreaddef.h
-@@ -48,4 +48,5 @@
+@@ -48,4 +48,4 @@
  
  /* While there is no such syscall.  */
  #define __exit_thread_inline(val) \
 -  asm volatile ("syscall" :: "a" (__NR_exit), "D" (val))
-+  asm volatile ("pushq %%rbx\n\tmovq syscalldb@GOTPCREL(%%rip), %%rbx\n\t" \
-+		"call %%rbx\n\t" :: "a" (__NR_exit), "D" (val) : "bx" )
++  asm volatile (SYSCALLDB :: "a" (__NR_exit), "D" (val))
 diff --git a/nptl/sysdeps/x86_64/tls.h b/nptl/sysdeps/x86_64/tls.h
-index cbb5e9e..19b18ef 100644
+index cbb5e9e..9b87e25 100644
 --- a/nptl/sysdeps/x86_64/tls.h
 +++ b/nptl/sysdeps/x86_64/tls.h
-@@ -28,6 +28,7 @@
+@@ -28,6 +28,8 @@
  # include <sysdep.h>
  # include <libc-internal.h>
  # include <kernel-features.h>
 +# include <shim_tls.h>
++# include <syscalldb.h>
  
  /* Replacement type for __m128 since this file is included by ld.so,
     which is compiled with -mno-sse.  It must not change the alignment
-@@ -67,6 +68,10 @@ typedef struct
+@@ -67,6 +69,10 @@ typedef struct
  # else
    int __glibc_reserved1;
  # endif
@@ -1526,20 +1526,15 @@ index cbb5e9e..19b18ef 100644
    int rtld_must_xmm_save;
    /* Reservation of some values for the TM ABI.  */
    void *__private_tm[4];
-@@ -137,6 +142,12 @@ typedef struct
+@@ -137,7 +143,6 @@ typedef struct
  # define GET_DTV(descr) \
    (((tcbhead_t *) (descr))->dtv)
  
-+/* For Graphene */
-+#define SYSCALLDB							      \
-+	"pushq %%rbx\n\t"						      \
-+	"movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t"			      \
-+	"callq *%%rbx\n\t"						      \
-+	"popq %%rbx\n\t"
- 
+-
  /* Code to initially initialize the thread pointer.  This might need
     special attention since 'errno' is not yet available and if the
-@@ -154,7 +165,7 @@ typedef struct
+    operation can cause a failure 'errno' must not be touched.
+@@ -154,7 +159,7 @@ typedef struct
       _head->self = _thrdescr;						      \
  									      \
       /* It is a simple syscall to set the %fs value for the thread.  */	      \
@@ -1605,7 +1600,7 @@ index 2468228..a9f1cd6 100644
  #ifdef ABORT_INSTRUCTION
        ABORT_INSTRUCTION;
 diff --git a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
-index 49f0384..ee59c00 100644
+index 49f0384..6b1a975 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
 +++ b/sysdeps/unix/sysv/linux/x86_64/____longjmp_chk.S
 @@ -84,7 +84,8 @@ ENTRY(____longjmp_chk)
@@ -1613,7 +1608,7 @@ index 49f0384..ee59c00 100644
  	lea	-sizeSS(%rsp), %RSI_LP
  	movl	$__NR_sigaltstack, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
 +
  	/* Without working sigaltstack we cannot perform the test.  */
  	testl	%eax, %eax
@@ -1637,7 +1632,7 @@ index f712110..f6bad14 100644
  
  #include "../clock_gettime.c"
 diff --git a/sysdeps/unix/sysv/linux/x86_64/clone.S b/sysdeps/unix/sysv/linux/x86_64/clone.S
-index 0508730..c011e7a 100644
+index 0508730..e1b35ec 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/clone.S
 +++ b/sysdeps/unix/sysv/linux/x86_64/clone.S
 @@ -59,11 +59,15 @@ ENTRY (__clone)
@@ -1663,7 +1658,7 @@ index 0508730..c011e7a 100644
  	   wrong.  */
  	cfi_endproc;
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
 +L(clone_return):
  	testq	%rax,%rax
@@ -1674,7 +1669,7 @@ index 0508730..c011e7a 100644
  	jne	2f
  	movl	$SYS_ify(getpid), %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  2:	movl	%eax, %fs:PID
  	movl	%eax, %fs:TID
  1:
@@ -1686,7 +1681,7 @@ index 0508730..c011e7a 100644
  	popq	%rdi		/* Argument.  */
  	call	*%rax
 diff --git a/sysdeps/unix/sysv/linux/x86_64/getcontext.S b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
-index 140db03..870fb02 100644
+index 140db03..6967f10 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/getcontext.S
 +++ b/sysdeps/unix/sysv/linux/x86_64/getcontext.S
 @@ -75,7 +75,7 @@ ENTRY(__getcontext)
@@ -1694,7 +1689,7 @@ index 140db03..870fb02 100644
  	movl	$_NSIG8,%r10d
  	movl	$__NR_rt_sigprocmask, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	cmpq	$-4095, %rax		/* Check %rax for error.  */
  	jae	SYSCALL_ERROR_LABEL	/* Jump to error handler if error.  */
  
@@ -1728,7 +1723,7 @@ index 440ca7f..571125d 100644
  weak_alias (__gettimeofday, gettimeofday)
  libc_hidden_weak (gettimeofday)
 diff --git a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
-index 0fd47f2..0247e2f 100644
+index 0fd47f2..7a82975 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
 +++ b/sysdeps/unix/sysv/linux/x86_64/sched_getcpu.S
 @@ -30,6 +30,7 @@ ENTRY (sched_getcpu)
@@ -1752,7 +1747,7 @@ index 0fd47f2..0247e2f 100644
  	movl	$__NR_getcpu, %eax
 -	syscall
 -#  ifndef __ASSUME_GETCPU_SYSCALL
-+	SYSCALL
++	SYSCALLDB
 +#endif
 +
 +#if 0 /* for Graphene, never do vsyscall */
@@ -1767,7 +1762,7 @@ index 0fd47f2..0247e2f 100644
  	callq	*%rax
  1:
 diff --git a/sysdeps/unix/sysv/linux/x86_64/setcontext.S b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
-index b726fa0..96bf0ec 100644
+index b726fa0..bb3ae34 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/setcontext.S
 +++ b/sysdeps/unix/sysv/linux/x86_64/setcontext.S
 @@ -43,7 +43,7 @@ ENTRY(__setcontext)
@@ -1775,26 +1770,25 @@ index b726fa0..96bf0ec 100644
  	movl	$_NSIG8,%r10d
  	movl	$__NR_rt_sigprocmask, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	popq	%rdi			/* Reload %rdi, adjust stack.  */
  	cfi_adjust_cfa_offset(-8)
  	cmpq	$-4095, %rax		/* Check %rax for error.  */
 diff --git a/sysdeps/unix/sysv/linux/x86_64/sigaction.c b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
-index ab23985..39d0bdc 100644
+index ab23985..38a6b69 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/sigaction.c
 +++ b/sysdeps/unix/sysv/linux/x86_64/sigaction.c
-@@ -129,7 +129,8 @@ asm									\
+@@ -129,7 +129,7 @@ asm									\
     "	.type __" #name ",@function\n"					\
     "__" #name ":\n"							\
     "	movq $" #syscall ", %rax\n"					\
 -   "	syscall\n"							\
-+   "	movq syscalldb@GOTPCREL(%rip), %rbx\n"				\
-+   "	call *%rbx\n"							\
++   SYSCALLDB_ASM							\
     ".LEND_" #name ":\n"							\
     ".section .eh_frame,\"a\",@progbits\n"				\
     ".LSTARTFRAME_" #name ":\n"						\
 diff --git a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
-index b3854fa..fd42f66 100644
+index b3854fa..6369bfe 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
 +++ b/sysdeps/unix/sysv/linux/x86_64/swapcontext.S
 @@ -75,7 +75,7 @@ ENTRY(__swapcontext)
@@ -1802,12 +1796,12 @@ index b3854fa..fd42f66 100644
  	movl	$_NSIG8,%r10d
  	movl	$__NR_rt_sigprocmask, %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  	cmpq	$-4095, %rax		/* Check %rax for error.  */
  	jae	SYSCALL_ERROR_LABEL	/* Jump to error handler if error.  */
  
 diff --git a/sysdeps/unix/sysv/linux/x86_64/syscall.S b/sysdeps/unix/sysv/linux/x86_64/syscall.S
-index 92c2f5b..7b7ee12 100644
+index 92c2f5b..33f820f 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/syscall.S
 +++ b/sysdeps/unix/sysv/linux/x86_64/syscall.S
 @@ -34,7 +34,7 @@ ENTRY (syscall)
@@ -1815,12 +1809,12 @@ index 92c2f5b..7b7ee12 100644
  	movq %r9, %r8
  	movq 8(%rsp),%r9	/* arg6 is on the stack.  */
 -	syscall			/* Do the system call.  */
-+	SYSCALL			/* Do the system call.  */
++	SYSCALLDB		/* Do the system call.  */
  	cmpq $-4095, %rax	/* Check %rax for error.  */
  	jae SYSCALL_ERROR_LABEL	/* Jump to error handler if error.  */
  	ret			/* Return to caller.  */
 diff --git a/sysdeps/unix/sysv/linux/x86_64/sysdep.h b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
-index 4a9a9d9..3b7434d 100644
+index 4a9a9d9..dc452ed 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/sysdep.h
 +++ b/sysdeps/unix/sysv/linux/x86_64/sysdep.h
 @@ -21,6 +21,7 @@
@@ -1831,33 +1825,23 @@ index 4a9a9d9..3b7434d 100644
  
  #ifdef IS_IN_rtld
  # include <dl-sysdep.h>		/* Defines RTLD_PRIVATE_ERRNO.  */
-@@ -172,11 +173,18 @@
- 
-     Syscalls of more than 6 arguments are not supported.  */
- 
-+# undef	SYSCALL
-+# define SYSCALL				\
-+    pushq %rbx;					\
-+    movq syscalldb@GOTPCREL(%rip), %rbx;	\
-+    call *%rbx;					\
-+    popq %rbx;
-+
- # undef	DO_CALL
+@@ -176,7 +177,7 @@
  # define DO_CALL(syscall_name, args)		\
      DOARGS_##args				\
      movl $SYS_ify (syscall_name), %eax;		\
 -    syscall;
-+    SYSCALL
++    SYSCALLDB
  
  # define DOARGS_0 /* nothing */
  # define DOARGS_1 /* nothing */
-@@ -190,9 +198,20 @@
+@@ -190,9 +191,20 @@
  /* Define a macro which expands inline into the wrapper code for a system
     call.  */
  # undef INLINE_SYSCALL
 -# define INLINE_SYSCALL(name, nr, args...) \
 +# define INLINE_SYSCALL(name, nr_args...) \
-+  ({									      \
+   ({									      \
+-    unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args);	      \
 +    unsigned long int resultvar = INTERNAL_SYSCALL (name, , ##nr_args);	      \
 +    if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0))	      \
 +      {									      \
@@ -1868,13 +1852,12 @@ index 4a9a9d9..3b7434d 100644
 +
 +# undef INLINE_SYSCALL_ASM
 +# define INLINE_SYSCALL_ASM(name, nr_args...) \
-   ({									      \
--    unsigned long int resultvar = INTERNAL_SYSCALL (name, , nr, args);	      \
++  ({									      \
 +    unsigned long int resultvar = INTERNAL_SYSCALL_ASM (name, , ##nr_args);   \
      if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0))	      \
        {									      \
  	__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, ));		      \
-@@ -204,9 +223,9 @@
+@@ -204,9 +216,9 @@
     into the wrapper code for a system call.  It should be used when size
     of any argument > size of long int.  */
  # undef INLINE_SYSCALL_TYPES
@@ -1886,16 +1869,14 @@ index 4a9a9d9..3b7434d 100644
      if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0))	      \
        {									      \
  	__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, ));		      \
-@@ -223,13 +242,20 @@
+@@ -223,13 +235,19 @@
      LOAD_ARGS_##nr (args)						      \
      LOAD_REGS_##nr							      \
      asm volatile (							      \
 -    "syscall\n\t"							      \
-+    "movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t"				      \
-+    "call *%%rbx\n\t"							      \
++    SYSCALLDB								      \
      : "=a" (resultvar)							      \
--    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
-+    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx", "bx");	      \
+     : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
      (long int) resultvar; })
 +# define INTERNAL_SYSCALL_NCS_ASM INTERNAL_SYSCALL_NCS
 +
@@ -1911,20 +1892,16 @@ index 4a9a9d9..3b7434d 100644
  
  # define INTERNAL_SYSCALL_NCS_TYPES(name, err, nr, args...) \
    ({									      \
-@@ -237,9 +263,10 @@
+@@ -237,7 +255,7 @@
      LOAD_ARGS_TYPES_##nr (args)						      \
      LOAD_REGS_TYPES_##nr (args)						      \
      asm volatile (							      \
 -    "syscall\n\t"							      \
-+    "movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t"				      \
-+    "call *%%rbx\n\t"							      \
++    SYSCALLDB								      \
      : "=a" (resultvar)							      \
--    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
-+    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx", "bx");	      \
+     : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
      (long int) resultvar; })
- # undef INTERNAL_SYSCALL_TYPES
- # define INTERNAL_SYSCALL_TYPES(name, err, nr, args...) \
-@@ -252,6 +279,7 @@
+@@ -252,6 +270,7 @@
  # undef INTERNAL_SYSCALL_ERRNO
  # define INTERNAL_SYSCALL_ERRNO(val, err)	(-(val))
  
@@ -1932,7 +1909,7 @@ index 4a9a9d9..3b7434d 100644
  # ifdef SHARED
  #  define INLINE_VSYSCALL(name, nr, args...) \
    ({									      \
-@@ -300,12 +328,13 @@
+@@ -300,12 +319,13 @@
      v_ret;								      \
    })
  
@@ -2018,7 +1995,7 @@ index 79f1fab..0000000
 -
 -#endif
 diff --git a/sysdeps/unix/sysv/linux/x86_64/vfork.S b/sysdeps/unix/sysv/linux/x86_64/vfork.S
-index d3b450a..76bda33 100644
+index d3b450a..75a63e1 100644
 --- a/sysdeps/unix/sysv/linux/x86_64/vfork.S
 +++ b/sysdeps/unix/sysv/linux/x86_64/vfork.S
 @@ -38,7 +38,7 @@ ENTRY (__vfork)
@@ -2026,7 +2003,7 @@ index d3b450a..76bda33 100644
  	/* Stuff the syscall number in RAX and enter into the kernel.  */
  	movl	$SYS_ify (vfork), %eax
 -	syscall
-+	SYSCALL
++	SYSCALLDB
  
  	/* Push back the return PC.  */
  	pushq	%rdi

+ 19 - 0
LibOS/glibc-2.19/syscalldb.h

@@ -5,11 +5,30 @@
 .weak syscalldb
 .type syscalldb, @function
 
+# define SYSCALLDB				\
+    pushq %rbx;					\
+    movq syscalldb@GOTPCREL(%rip), %rbx;	\
+    call *%rbx;					\
+    popq %rbx;
+
+
 #else /* !__ASSEMBLER__ */
 asm (
 ".weak syscalldb\r\n"
 ".type syscalldb, @function\r\n");
 
+#define SYSCALLDB							      \
+	"subq $128, %%rsp\n\t"						      \
+	"pushq %%rbx\n\t"						      \
+	"movq syscalldb@GOTPCREL(%%rip), %%rbx\n\t"			      \
+	"callq *%%rbx\n\t"						      \
+	"popq %%rbx\n\t"						      \
+	"addq $128, %%rsp\n\t"
+
+#define SYSCALLDB_ASM							      \
+	"movq syscalldb@GOTPCREL(%rip), %rbx\n\t"			      \
+	"callq *%rbx\n\t"
+
 long int glibc_option (const char * opt);
 
 asm (

+ 1 - 1
LibOS/shim/include/glibc-version.h

@@ -1,6 +1,6 @@
 /* update the file whenever changes made to glibc.
    pick whatever random value. */
 
-#define GLIBC_VERSION_2_17      0xd893a451
+#define GLIBC_VERSION      0xf200364c
 
 int register_library (const char * name, unsigned long load_address);

+ 4 - 0
LibOS/shim/include/shim_defs.h

@@ -17,4 +17,8 @@
 
 #define EXECVE_RTLD                 1
 
+/* debug message printout */
+#define DEBUGBUF_SIZE               256
+#define DEBUGBUF_BREAK              0
+
 #endif /* _SHIM_DEFS_H_ */

+ 2 - 2
LibOS/shim/include/shim_fs.h

@@ -331,7 +331,7 @@ int directory_open (struct shim_handle * hdl, struct shim_dentry * dent,
 void get_dentry (struct shim_dentry * dent);
 void put_dentry (struct shim_dentry * dent);
 
-static inline __attribute__((always_inline))
+static_inline
 void fast_pathcpy (char * dst, const char * src, int size, char ** ptr)
 {
     char * d = dst;
@@ -341,7 +341,7 @@ void fast_pathcpy (char * dst, const char * src, int size, char ** ptr)
     *ptr = d;
 }
 
-static inline __attribute__((always_inline))
+static_inline
 char * dentry_get_path (struct shim_dentry * dent, bool on_stack,
                         int * sizeptr)
 {

+ 4 - 11
LibOS/shim/include/shim_internal.h

@@ -35,6 +35,8 @@
 #define extern_alias(name) \
     extern __typeof(name) shim_##name __attribute ((alias (alias_str(name))))
 
+#define static_inline static inline __attribute__((always_inline))
+
 #include <shim_types.h>
 #include <shim_defs.h>
 #include <shim_atomic.h>
@@ -49,9 +51,6 @@
 #define IS_INTERNAL(thread)     ((thread)->tid >= INTERNAL_TID_BASE)
 #define TID_PRINTFMT
 
-/* debug message printout */
-# define DEBUGBUF_SIZE       80
-
 struct debug_buf {
     int start;
     int end;
@@ -137,18 +136,12 @@ int shim_terminate (void);
 #define USE_PAUSE       1
 #define USE_ASSERT      1
 
-extern bool in_gdb;
 static inline void do_pause (void);
 
-#define BREAK_GDB() do { asm volatile ("int $3"); } while (0)
-
 #if USE_PAUSE == 1
-# define pause()                                                            \
-    do {                                                                    \
-        if (in_gdb) BREAK_GDB(); else do_pause();                           \
-    } while (0)
+# define pause() do { do_pause(); } while (0)
 #else
-# define pause() do { if (in_gdb) BREAK_GDB(); } while (0)
+# define pause() do {} while (0)
 #endif
 
 #define bug()                                                               \

+ 3 - 3
LibOS/shim/include/shim_ipc.h

@@ -535,7 +535,7 @@ struct shim_ipc_info * discover_client (struct shim_ipc_port * port,
 int __init_ipc_msg (struct shim_ipc_msg * msg, int code, int size, IDTYPE dest);
 struct shim_ipc_msg * create_ipc_msg (int code, int size, IDTYPE dest);
 
-static inline __attribute__((always_inline))
+static_inline
 struct shim_ipc_msg * create_ipc_msg_on_stack (int code, int size, IDTYPE dest)
 {
     struct shim_ipc_msg * msg = __alloca(IPC_MSG_SIZE(size));
@@ -548,7 +548,7 @@ int __init_ipc_msg_duplex (struct shim_ipc_msg_obj * msg, int code, int size,
 struct shim_ipc_msg_obj *
 create_ipc_msg_duplex (int code, int size, IDTYPE dest);
 
-static inline __attribute__((always_inline))
+static_inline
 struct shim_ipc_msg_obj *
 create_ipc_msg_duplex_on_stack (int code, int size, IDTYPE dest)
 {
@@ -563,7 +563,7 @@ int __init_ipc_resp_msg (struct shim_ipc_msg * resp, int ret,
 struct shim_ipc_msg *
 create_ipc_resp_msg (int ret, IDTYPE dest, unsigned long seq);
 
-static inline __attribute__((always_inline))
+static_inline
 struct shim_ipc_msg *
 create_ipc_resp_msg_on_stack (int ret, IDTYPE dest, unsigned long seq)
 {

+ 1 - 1
LibOS/shim/include/shim_signal.h

@@ -113,7 +113,7 @@ struct shim_signal_log {
 
 extern const char * const siglist[NUM_KNOWN_SIGS + 1];
 
-static inline const char * signal_name (int sig)
+static_inline const char * signal_name (int sig)
 {
     if (sig <= NUM_KNOWN_SIGS)
         return siglist[sig];

+ 2 - 0
LibOS/shim/include/shim_tls.h

@@ -33,6 +33,8 @@ struct shim_regs {
     unsigned long           r14;
     unsigned long           r13;
     unsigned long           r12;
+    unsigned long           r11;
+    unsigned long           r10;
     unsigned long           r9;
     unsigned long           r8;
     unsigned long           rcx;

+ 1 - 3
LibOS/shim/include/shim_utils.h

@@ -167,9 +167,7 @@ void free (void * mem);
 void * remalloc (const void * mem, size_t size);
 #endif
 
-static inline
-__attribute__((always_inline))
-char * qstrtostr (struct shim_qstr * qstr, bool on_stack)
+static_inline char * qstrtostr (struct shim_qstr * qstr, bool on_stack)
 {
     int len = qstr->len;
     char * buf = on_stack ? __alloca(len + 1) : malloc(len + 1);

+ 0 - 1
LibOS/shim/src/.gitignore

@@ -1 +0,0 @@
-libsysdb.so.cached

File diff suppressed because it is too large
+ 0 - 0
LibOS/shim/src/.packed/shim.sha384


BIN
LibOS/shim/src/.packed/shim.tar.gz


+ 3 - 0
LibOS/shim/src/bookkeep/shim_handle.c

@@ -804,6 +804,9 @@ BEGIN_CP_FUNC(handle)
             entry->phandle = &new_hdl->pal_handle;
         }
 
+        if (hdl->type == TYPE_EPOLL)
+            DO_CP(epoll_fd, &hdl->info.epoll.fds, &new_hdl->info.epoll.fds);
+
         unlock(hdl->lock);
         ADD_CP_FUNC_ENTRY(off);
     } else {

+ 4 - 1
LibOS/shim/src/bookkeep/shim_signal.c

@@ -115,6 +115,9 @@ void __store_context (shim_tcb_t * tcb, PAL_CONTEXT * pal_context,
             context->uc_mcontext.gregs[REG_R15] = regs->r15;
             context->uc_mcontext.gregs[REG_R14] = regs->r14;
             context->uc_mcontext.gregs[REG_R13] = regs->r13;
+            context->uc_mcontext.gregs[REG_R12] = regs->r12;
+            context->uc_mcontext.gregs[REG_R11] = regs->r11;
+            context->uc_mcontext.gregs[REG_R10] = regs->r10;
             context->uc_mcontext.gregs[REG_R9]  = regs->r9;
             context->uc_mcontext.gregs[REG_R8]  = regs->r8;
             context->uc_mcontext.gregs[REG_RCX] = regs->rcx;
@@ -268,7 +271,7 @@ static void illegal_upcall (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 {
     if (IS_INTERNAL_TID(get_cur_tid()) || is_internal(context)) {
 internal:
-        internal_fault("Internal memory fault", arg, context);
+        internal_fault("Internal illegal fault", arg, context);
         pause();
         goto ret_exception;
     }

+ 3 - 0
LibOS/shim/src/elf/do-rel.h

@@ -60,6 +60,9 @@
 static void __attribute__((unused))
 elf_dynamic_do_rel (struct link_map * l, ElfW(Addr) reladdr, int relsize)
 {
+    if (!l->l_info[DT_SYMTAB])
+        return;
+
     ElfW(Sym) * symtab = (void *) D_PTR (l->l_info[DT_SYMTAB]);
     ElfW(Rel) * r = (void *) reladdr;
     ElfW(Rel) * end = (void *) (reladdr + relsize);

+ 3 - 0
LibOS/shim/src/elf/rel.h

@@ -34,6 +34,9 @@ elf_get_dynamic_info (struct link_map * l)
 #endif
     ElfW(Dyn) * dyn = l->l_ld;
 
+    if (dyn == NULL)
+        return;
+
     while (dyn->d_tag != DT_NULL) {
         int tag = 0;
 

+ 2 - 4
LibOS/shim/src/elf/shim_rtld.c

@@ -692,12 +692,10 @@ postmap:
             goto call_lose;
         }
     } else {
-        l->l_ld = (ElfW(Dyn) *) RELOCATE(l, l->l_ld);
+        l->l_real_ld = (ElfW(Dyn) *) RELOCATE(l, l->l_ld);
+        l->l_ld = remalloc(l->l_real_ld, sizeof(ElfW(Dyn)) * l->l_ldnum);
     }
 
-    l->l_real_ld = l->l_ld;
-    l->l_ld = remalloc(l->l_ld, sizeof(ElfW(Dyn)) * l->l_ldnum);
-
     elf_get_dynamic_info(l);
 
     /* When we profile the SONAME might be needed for something else but

+ 3 - 1
LibOS/shim/src/ipc/shim_ipc.c

@@ -389,8 +389,10 @@ int close_ipc_message_duplex (struct shim_ipc_msg_obj * msg,
         unlock(port->msgs_lock);
     }
 
-    if (msg->thread)
+    if (msg->thread) {
         put_thread(msg->thread);
+        msg->thread = NULL;
+    }
 
     return 0;
 }

+ 1 - 1
LibOS/shim/src/shim.map

@@ -1,6 +1,6 @@
 SHIM {
     global:
         syscalldb; register_library;
-        glibc_vers_*; glibc_option;
+        glibc_version; glibc_option;
     local: *;
 };

+ 1 - 10
LibOS/shim/src/shim_init.c

@@ -49,7 +49,7 @@ unsigned long allocmask;
    SHIM libraries */
 #include "glibc-version.h"
 
-const unsigned int glibc_vers_2_17   = GLIBC_VERSION_2_17;
+const unsigned int glibc_version = GLIBC_VERSION;
 
 static void handle_failure (PAL_PTR event, PAL_NUM arg, PAL_CONTEXT * context)
 {
@@ -174,8 +174,6 @@ const char ** library_paths;
 LOCKTYPE __master_lock;
 bool lock_enabled;
 
-bool in_gdb;
-
 void init_tcb (shim_tcb_t * tcb)
 {
     tcb->canary = SHIM_TLS_CANARY;
@@ -421,13 +419,6 @@ int read_environs (const char ** envp)
                 }
                 break;
             }
-            case 'I': {
-                if (strcmp_static(*e, "IN_GDB=1")) {
-                    in_gdb = true;
-                    break;
-                }
-                break;
-            }
         }
     }
 

+ 2 - 0
LibOS/shim/src/shim_malloc.c

@@ -106,7 +106,9 @@ static struct shim_heap * __alloc_enough_heap (size_t size)
         if (heap == smallest && heap->current != heap->end) {
             DkVirtualMemoryFree(heap->current, heap->end - heap->current);
             int flags = VMA_INTERNAL;
+            unlock(shim_heap_lock);
             bkeep_munmap(heap->current, heap->end - heap->current, &flags);
+            lock(shim_heap_lock);
         }
 
         heap->start = heap->current = start;

+ 1 - 1
LibOS/shim/src/shim_parser.c

@@ -974,7 +974,7 @@ static void parse_ioctlop (const char * type, va_list * ap)
         PUTS(opnames[op - TCGETS]);
         return;
     }
-    PRINTF("OP 0x%04u", op);
+    PRINTF("OP 0x%04x", op);
 }
 
 static void parse_seek (const char * type, va_list * ap)

+ 0 - 1
LibOS/shim/src/shim_syscalls.c

@@ -423,7 +423,6 @@ DEFINE_SHIM_SYSCALL (fsync, 1, shim_do_fsync, int, int, fd)
 /* fdatasync: sys/shim_open.c */
 DEFINE_SHIM_SYSCALL (fdatasync, 1, shim_do_fdatasync, int, int, fd)
 
-
 /* truncate: sys/shim_open.c */
 DEFINE_SHIM_SYSCALL (truncate, 2, shim_do_truncate, int, const char *, path,
                      loff_t, length)

+ 64 - 1
LibOS/shim/src/sys/shim_epoll.c

@@ -29,6 +29,7 @@
 #include <shim_thread.h>
 #include <shim_handle.h>
 #include <shim_fs.h>
+#include <shim_checkpoint.h>
 
 #include <pal.h>
 #include <pal_error.h>
@@ -64,6 +65,9 @@ struct shim_epoll_fd {
 
 int shim_do_epoll_create1 (int flags)
 {
+    if ((flags & ~EPOLL_CLOEXEC))
+        return -EINVAL;
+
     struct shim_handle * hdl = get_new_handle();
     if (!hdl)
         return -ENOMEM;
@@ -79,7 +83,8 @@ int shim_do_epoll_create1 (int flags)
     create_event(&epoll->event);
     INIT_LIST_HEAD(&epoll->fds);
 
-    int vfd = set_new_fd_handle(hdl, flags, NULL);
+    int vfd = set_new_fd_handle(hdl, (flags & EPOLL_CLOEXEC) ? FD_CLOEXEC : 0,
+                                NULL);
     put_handle(hdl);
     return vfd;
 }
@@ -87,6 +92,9 @@ int shim_do_epoll_create1 (int flags)
 /* the 'size' argument of epoll_create is not used */
 int shim_do_epoll_create (int size)
 {
+    if (size < 0)
+        return -EINVAL;
+
     return shim_do_epoll_create1(0);
 }
 
@@ -321,3 +329,58 @@ struct shim_fs_ops epoll_fs_ops = {
 
 struct shim_mount epoll_builtin_fs = { .type = "epoll",
                                        .fs_ops = &epoll_fs_ops, };
+
+BEGIN_CP_FUNC(epoll_fd)
+{
+    assert(size == sizeof(struct list_head));
+
+    struct list_head * old_list = (struct list_head *) obj;
+    struct list_head * new_list = (struct list_head *) objp;
+    struct shim_epoll_fd * epoll_fd;
+
+    debug("checkpoint epoll: %p -> %p (base = %p)\n", old_list, new_list, base);
+
+    INIT_LIST_HEAD(new_list);
+
+    list_for_each_entry(epoll_fd, old_list, list) {
+        ptr_t off = ADD_CP_OFFSET(sizeof(struct shim_epoll_fd));
+
+        struct shim_epoll_fd * new_epoll_fd =
+                    (struct shim_epoll_fd *) (base + off);
+
+        new_epoll_fd->fd      = epoll_fd->fd;
+        new_epoll_fd->events  = epoll_fd->events;
+        new_epoll_fd->data    = epoll_fd->data;
+        new_epoll_fd->revents = epoll_fd->revents;
+        new_epoll_fd->pal_handle = NULL;
+        list_add(new_list, &new_epoll_fd->list);
+
+        DO_CP(handle, epoll_fd->handle, &new_epoll_fd->handle);
+    }
+
+    ADD_CP_FUNC_ENTRY((ptr_t) objp - base);
+}
+END_CP_FUNC(epoll_fd)
+
+BEGIN_RS_FUNC(epoll_fd)
+{
+    struct list_head * list = (void *) (base + GET_CP_FUNC_ENTRY());
+    struct list_head * e;
+
+    CP_REBASE(*list);
+
+    for (e = list->next ; e != list ; e = e->next) {
+        struct shim_epoll_fd * epoll_fd =
+                list_entry(e, struct shim_epoll_fd, list);
+
+        CP_REBASE(epoll_fd->handle);
+        epoll_fd->pal_handle = epoll_fd->handle->pal_handle;
+        CP_REBASE(*e);
+
+        DEBUG_RS("fd=%d,path=%s,type=%s,uri=%s",
+                 epoll_fd->fd, qstrgetstr(&epoll_fd->handle->path),
+                 epoll_fd->handle->fs_type,
+                 qstrgetstr(&epoll_fd->handle->uri));
+    }
+}
+END_RS_FUNC(epoll_fd)

+ 0 - 7
LibOS/shim/src/sys/shim_open.c

@@ -481,13 +481,6 @@ out:
     return ret;
 }
 
-// DEP 10/20/16: Assuming fsync >> fdatasync for now
-//  and no app depends on only syncing data for correctness.
-int shim_do_fdatasync (int fd)
-{
-    return shim_do_fsync(fd);
-}
-
 
 // DEP 10/20/16: Assuming fsync >> fdatasync for now
 //  and no app depends on only syncing data for correctness.

+ 27 - 17
LibOS/shim/src/sys/shim_poll.c

@@ -117,6 +117,7 @@ static int __do_poll (int npolls, struct poll_handle * polls,
     struct poll_handle * polling = NULL;
     struct poll_handle * p, ** n, * q;
     PAL_HANDLE * pals = NULL;
+    int ret = 0;
 
 #ifdef PROFILE
     unsigned long begin_time = GET_PROFILE_INTERVAL();
@@ -215,22 +216,28 @@ no_op:
             if (need_poll) {
                 int polled = hdl->fs->fs_ops->poll(hdl, need_poll);
 
-                if (polled & FS_POLL_ER) {
-                    debug("fd %d known to have error\n", p->fd);
-                    p->flags |= KNOWN_R|KNOWN_W|RET_E;
-                    do_r = do_w = false;
-                }
-
-                if ((polled & FS_POLL_RD)) {
-                    debug("fd %d known to be readable\n", p->fd);
-                    p->flags |= KNOWN_R|RET_R;
-                    do_r = false;
-                }
+                if (polled < 0) {
+                    if (polled != -EAGAIN) {
+                        ret = polled;
+                        goto done_polling;
+                    }
+                } else {
+                    if (polled & FS_POLL_ER) {
+                        debug("fd %d known to have error\n", p->fd);
+                        p->flags |= KNOWN_R|KNOWN_W|RET_E;
+                    }
+
+                    if ((polled & FS_POLL_RD)) {
+                        debug("fd %d known to be readable\n", p->fd);
+                        p->flags |= KNOWN_R|RET_R;
+                    }
+
+                    if (polled & FS_POLL_WR) {
+                        debug("fd %d known to be writeable\n", p->fd);
+                        p->flags |= KNOWN_W|RET_W;
+                    }
 
-                if (polled & FS_POLL_WR) {
-                    debug("fd %d known to be writeable\n", p->fd);
-                    p->flags |= KNOWN_W|RET_W;
-                    do_w = false;
+                    do_r = do_w = false;
                 }
             }
 
@@ -274,8 +281,10 @@ done_finding:
 
     SAVE_PROFILE_INTERVAL_SINCE(do_poll_first_loop, begin_time);
 
-    if (!npals)
+    if (!npals) {
+        ret = 0;
         goto done_polling;
+    }
 
     pals = __try_alloca(cur, sizeof(PAL_HANDLE) * npals);
     npals = 0;
@@ -364,6 +373,7 @@ done_finding:
         SAVE_PROFILE_INTERVAL(do_poll_third_loop);
     }
 
+    ret = 0;
 done_polling:
     for (p = polling ; p ; p = p->next)
         put_handle(p->handle);
@@ -373,7 +383,7 @@ done_polling:
     if (pals)
         __try_free(cur, pals);
 
-    return 0;
+    return ret;
 }
 
 int shim_do_poll (struct pollfd * fds, nfds_t nfds, int timeout)

+ 1 - 1
LibOS/shim/src/sys/shim_uname.c

@@ -36,7 +36,7 @@
 static struct old_utsname graphene_uname = {
     .sysname = "Linux",
     .nodename = "localhost",
-    .release = "3.10",
+    .release = "3.10.0",
     .version = "1",
     .machine = "x86_64"
 };

+ 8 - 9
LibOS/shim/src/syscallas.S

@@ -31,15 +31,11 @@
 syscalldb:
         .cfi_startproc
 
-        # avoid red zone for previous rsp
-        subq $128, %rsp
-        .cfi_def_cfa_offset 136
-
         # DEP 7/9/12: Push a stack pointer so clone can find the return address
         pushq %rbp
-        .cfi_def_cfa_offset 144
+        .cfi_def_cfa_offset 16
         movq %rsp, %rbp
-        .cfi_offset 6,-144
+        .cfi_offset 6,-16
         .cfi_def_cfa_register 6
 
         pushq %rbx
@@ -59,15 +55,17 @@ isdef:
         pushq %rcx
         pushq %r8
         pushq %r9
+        pushq %r10
+        pushq %r11
         pushq %r12
         pushq %r13
         pushq %r14
         pushq %r15
 
         movq %rax, %fs:(SHIM_TCB_OFFSET + 24)
-        leaq 232(%rsp), %rax
+        leaq 8(%rbp), %rax
         movq %rax, %fs:(SHIM_TCB_OFFSET + 32)
-        movq -8(%rax), %rax
+        movq (%rbp), %rax
         movq %rax, %fs:(SHIM_TCB_OFFSET + 40)
         movq %rsp, %fs:(SHIM_TCB_OFFSET + 48)
 
@@ -82,6 +80,8 @@ isdef:
         popq %r14
         popq %r13
         popq %r12
+        popq %r11
+        popq %r10
         popq %r9
         popq %r8
         popq %rcx
@@ -101,7 +101,6 @@ isundef:
 ret:
         popq %rbx
         popq %rbp
-        addq $128, %rsp
         retq
 
         .cfi_endproc

+ 6 - 0
LibOS/shim/src/utils/printf.c

@@ -56,6 +56,7 @@ debug_fputch (void * f, int ch, void * b)
         return 0;
     }
 
+#if DEBUGBUF_BREAK == 1
     if (buf->end == DEBUGBUF_SIZE - 4) {
         buf->buf[buf->end++] = '.';
         buf->buf[buf->end++] = '.';
@@ -65,6 +66,11 @@ debug_fputch (void * f, int ch, void * b)
         buf->buf[buf->end++] = '.';
         buf->buf[buf->end++] = '.';
     }
+#else
+    if (buf->end == DEBUGBUF_SIZE) {
+        debug_fputs(NULL, buf->buf, buf->end);
+    }
+#endif
 
     return 0;
 }

+ 5 - 6
LibOS/shim/test/Makefile

@@ -28,19 +28,18 @@ CXX += -g
 endif
 export DEBUG
 
-reldir = $(shell p=`dirname $(1)` ; d=; while [ "$$p" != "." ]; do p=`dirname $$p`; d=../$$d; done; echo $$d)
-
 manifest_rules = \
-	-e 's:\$$(PALDIR):$(PALDIR):g' \
+	-e 's:\$$(PALDIR):'$$RELDIR'$(PALDIR):g' \
 	-e 's:\$$(PWD):$(PWD):g' \
 	-e 's:\$$(BIN):$(subst .manifest,,$(notdir $@)):g' \
-	-e 's:\$$(SHIMDIR):$(SHIMDIR):g' \
-	-e 's:\$$(SHIMPATH):$(SHIMDIR)/libsysdb.so:g' \
-	-e 's:\$$(LIBCDIR):$(LIBCDIR):g' \
+	-e 's:\$$(SHIMDIR):'$$RELDIR'$(SHIMDIR):g' \
+	-e 's:\$$(SHIMPATH):'$$RELDIR'$(SHIMDIR)/libsysdb.so:g' \
+	-e 's:\$$(LIBCDIR):'$$RELDIR'$(LIBCDIR):g' \
 	$(extra_rules)
 
 %manifest: %manifest.template
 	@echo [ $@ ]
+	RELDIR=$(filter-out ./,$(shell realpath --relative-to=$(abspath $(dir $@)) $(PWD))/) && \
 	sed $(manifest_rules) $< > $@
 	(grep -q '^#!' $@ && chmod +x $@) || true
 

+ 1 - 1
LibOS/shim/test/apps/lighttpd/Makefile

@@ -55,7 +55,7 @@ start-multithreaded-native-server:
                 $(if $(CONF),$(CONF),lighttpd-multithreaded.conf)
 
 start-graphene-server:
-	$(PREFIX) ./lighttpd.manifest.sgx -D -m /lighttpd -f \
+	$(PREFIX) ./lighttpd.manifest -D -m /lighttpd -f \
 		$(if $(CONF),$(CONF),lighttpd.conf)
 
 start-multithreaded-graphene-server:

+ 0 - 14
LibOS/shim/test/apps/pal_loader

@@ -3,7 +3,6 @@
 PAL_LOADER=$(readlink -f ${BASH_SOURCE[0]})
 PAL_DIR=$(readlink -f $(dirname $PAL_LOADER)/../../../../Pal/src)
 PAL=$PAL_DIR/pal
-PAL_SEC=$PAL_DIR/pal_sec
 
 MANIFEST=
 GDB_CMD=
@@ -19,23 +18,10 @@ fi
 
 if [ "$SEC" == "1" ]; then
 	echo "Use reference monitor"
-	PAL_CMD=$PAL_SEC
 fi
 
 while [ "$1" != "" ];
 do
-	if [ "$1" = "-gdb" ]; then
-		GDB_CMD="gdb --args"
-		shift
-		continue
-	fi
-
-	if [ "$1" = "-sec" ]; then
-		PAL_CMD=$PAL_SEC
-		shift
-		continue
-	fi
-
 	if [ "$MANIFEST" == "" ]; then
 		MANIFEST=$1
 		shift

+ 1 - 1
LibOS/shim/test/native/.packed/test.sha384

@@ -1 +1 @@
-alarm brk clone condvar.pthread cpuinfo dir divzero dup epoll epoll_socket errno exec exec_fork exec_victim file fork fork_bomb fork_exec fs futextest.pthread get_time.m helloworld helloworld.pthread kill malloc meminfo msg_create msg_create.libos msg_send msg_send.libos multiproc multisleep pid_alloc pid_kill pie pipe pipe_latency proc readdir rename sandbox_create.libos script sem sleep socketpair sqrt.m start.pthread.m static sync.pthread system tcp test_start_pthread_m.m time udp unix vfork vfork_exec 3c639d63c9ff0015a3841d70bb63af6b9ae969d9130b6a3ab6820100d0c8fac53cb0605f9137cc253be503dbeaadc38d
+alarm brk clone condvar.pthread cpuinfo dir divzero dup epoll epoll_socket errno exec exec_fork exec_victim file fork fork_bomb fork_exec fs futextest.pthread get_time.m helloworld helloworld.pthread kill malloc meminfo msg_create msg_create.libos msg_send msg_send.libos multiproc multisleep pid_alloc pid_kill pie pipe pipe_latency proc readdir rename sandbox_create.libos script sem sleep socketpair sqrt.m start.pthread.m static sync.pthread system tcp test_start_pthread_m.m time udp unix vfork vfork_exec 611bc4da88ef4941be3cfbba5c7402d9cc0b95281d139e18ae86d4a0d799fc536785bbc42af5e6951fe230ede19fc7f0

BIN
LibOS/shim/test/native/.packed/test.tar.gz


+ 2 - 2
LibOS/shim/test/native/Makefile

@@ -1,10 +1,10 @@
 special_executables = static pie
 c_executables = $(filter-out $(special_executables),$(patsubst %.c,%,$(wildcard *.c)))
 cxx_executables = $(patsubst %.cpp,%,$(wildcard *.cpp))
-manifests = $(patsubst %.template,%,$(wildcard *.manifest.template))
+manifests = $(patsubst %.template,%,$(wildcard *.manifest.template)) manifest
 
 exec_target = $(special_executables) $(c_executables) $(cxx_executables) ls.manifest
-target = $(exec_target) $(manifests) pal pal_sec
+target = $(exec_target) $(manifests) pal
 
 level = ../
 include ../Makefile

+ 39 - 37
Pal/ipc/linux/graphene-ipc.c

@@ -15,10 +15,9 @@
 #include <linux/bitmap.h>
 #include <asm/mman.h>
 #include <asm/tlb.h>
-#ifdef CONFIG_GRAPHENE_BULK_IPC
-# include "graphene.h"
-#endif
+
 #include "graphene-ipc.h"
+#include "ksyms.h"
 
 MODULE_LICENSE("Dual BSD/GPL");
 
@@ -37,19 +36,6 @@ struct kmem_cache *gipc_send_buffer_cachep;
 # define GIPC_BUG_ON(cond)
 #endif
 
-#define LOOKUP_KALLSYMS(sym)						\
-	do {								\
-		my_##sym = (void *) kallsyms_lookup_name(#sym);		\
-		if (!my_##sym) {					\
-			printk(KERN_ERR "Graphene error: "		\
-			       "can't find kernel function " #sym "\n");\
-			return -ENOENT;					\
-		} else {						\
-			printk(KERN_INFO "resolved symbol " #sym " %p\n", \
-			       my_##sym);				\
-		}							\
-	} while (0)
-
 #if defined(CONFIG_GRAPHENE_BULK_IPC) || LINUX_VERSION_CODE < KERNEL_VERSION(3, 4, 0)
 # if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
 #  define DO_MMAP_PGOFF(file, addr, len, prot, flags, pgoff)		\
@@ -64,27 +50,30 @@ struct kmem_cache *gipc_send_buffer_cachep;
 	do_mmap_pgoff((file), (addr), (len), (prot), (flags), (pgoff))
 # endif /* kernel_version < 3.9.0 */
 #else
-# if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
+# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
+#  define MY_DO_MMAP
+#  define DO_MMAP_PGOFF(file, addr, len, prot, flags, pgoff)		\
+	({								\
+		unsigned long populate;					\
+		unsigned long rv;					\
+	 	rv = KSYM(do_mmap)((file), (addr), (len),		\
+				   (prot), (flags), 0, (pgoff),		\
+				   &populate);				\
+	rv; })
+# elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
 #  define MY_DO_MMAP_PGOFF
-unsigned long (*my_do_mmap_pgoff) (struct file *, unsigned long,
-				   unsigned long, unsigned long,
-				   unsigned long, unsigned long,
-				   unsigned long *);
 #  define DO_MMAP_PGOFF(file, addr, len, prot, flags, pgoff)		\
 	({								\
 		unsigned long populate;					\
-		unsigned long rv = my_do_mmap_pgoff((file), (addr),	\
-						    (len), (prot),	\
-						    (flags), (pgoff), 	\
-						    &populate);		\
+		unsigned long rv;					\
+	 	rv = KSYM(do_mmap_pgoff)((file), (addr), (len),		\
+					 (prot), (flags), (pgoff),	\
+					 &populate);			\
 	rv; })
 # else
 #  define MY_DO_MMAP_PGOFF
-unsigned long (*my_do_mmap_pgoff) (struct file *, unsigned long,
-				   unsigned long, unsigned long,
-				   unsigned long, unsigned long);
 #  define DO_MMAP_PGOFF(file, addr, len, prot, flags, pgoff)		\
-	my_do_mmap_pgoff((file), (addr), (len), (prot), (flags), (pgoff))
+	KSYM(do_mmap_pgoff)((file), (addr), (len), (prot), (flags), (pgoff))
 # endif /* kernel version < 3.9 */
 #endif /* !CONFIG_GRAPHENE_BULK_IPC && kernel version > 3.4.0 */
 
@@ -93,20 +82,30 @@ unsigned long (*my_do_mmap_pgoff) (struct file *, unsigned long,
 #  define FLUSH_TLB_MM_RANGE flush_tlb_mm_range
 # else
 #  define MY_FLUSH_TLB_MM_RANGE
-void (*my_flush_tlb_mm_range) (struct mm_struct *, unsigned long,
-			       unsigned long, unsigned long);
-#  define FLUSH_TLB_MM_RANGE my_flush_tlb_mm_range
+#  define FLUSH_TLB_MM_RANGE KSYM(flush_tlb_mm_range)
 # endif
 #else /* LINUX_VERSION_CODE < 3.7.0 */
 # if defined(CONFIG_GRAPHENE_BULK_IPC) || LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0)
 #  define FLUSH_TLB_PAGE flush_tlb_page
 # else
 #  define MY_FLUSH_TLB_PAGE
-void (*my_flush_tlb_page) (struct vm_area_struct *, unsigned long);
-#  define FLUSH_TLB_PAGE my_flush_tlb_page
+#  define FLUSH_TLB_PAGE KSYM(flush_tlb_page)
 # endif
 #endif
 
+#ifdef MY_DO_MMAP
+	IMPORT_KSYM(do_mmap);
+#endif
+#ifdef MY_DO_MMAP_PGOFF
+	IMPORT_KSYM(do_mmap_pgoff);
+#endif
+#ifdef MY_FLUSH_TLB_MM_RANGE
+	IMPORT_KSYM(flush_tlb_mm_range);
+#endif
+#ifdef MY_FLUSH_TLB_PAGE
+	IMPORT_KSYM(flush_tlb_page);
+#endif
+
 #ifndef gipc_get_session
 u64 (*my_gipc_get_session) (struct task_struct *) = NULL;
 #endif
@@ -916,14 +915,17 @@ static int __init gipc_init(void)
 {
 	int rv = 0;
 
+#ifdef MY_DO_MMAP
+	LOOKUP_KSYM(do_mmap);
+#endif
 #ifdef MY_DO_MMAP_PGOFF
-	LOOKUP_KALLSYMS(do_mmap_pgoff);
+	LOOKUP_KSYM(do_mmap_pgoff);
 #endif
 #ifdef MY_FLUSH_TLB_MM_RANGE
-	LOOKUP_KALLSYMS(flush_tlb_mm_range);
+	LOOKUP_KSYM(flush_tlb_mm_range);
 #endif
 #ifdef MY_FLUSH_TLB_PAGE
-	LOOKUP_KALLSYMS(flush_tlb_page);
+	LOOKUP_KSYM(flush_tlb_page);
 #endif
 
 #ifndef gipc_get_session

+ 0 - 1
Pal/ipc/linux/graphene.h

@@ -1 +0,0 @@
-../../linux-kernel/graphene/graphene.h

+ 2 - 1
Pal/ipc/linux/install.sh

@@ -3,9 +3,10 @@
 SCRIPT=`readlink -f "${BASH_SOURCE[0]}"`
 DIR=`dirname $SCRIPT`
 MOD=graphene-ipc
+MODNAME=graphene_ipc
 VER=0.0.1
 
-/sbin/lsmod | grep -q graphene_ipc
+/sbin/lsmod | grep -q $MODNAME
 if [ $? -eq 0 ]; then
 	echo "$MOD already running"
 	exit 0

+ 19 - 0
Pal/ipc/linux/ksyms.h

@@ -0,0 +1,19 @@
+#ifndef _KSYM_H
+#define _KSYM_H
+
+#include <linux/kallsyms.h>
+
+#define __KSYM(name) __ksym_##name
+#define KSYM(name) ({ BUG_ON(!__KSYM(name)); __KSYM(name); })
+#define IMPORT_KSYM(name) __typeof(name) * __KSYM(name)
+#define IMPORT_KSYM_PROTO(name, ret, ...) ret (*__KSYM(name)) (__VA_ARGS__)
+#define LOOKUP_KSYM(name)						\
+	do {								\
+		__KSYM(name) = (void *) kallsyms_lookup_name(#name);	\
+		if (!__KSYM(name)) {					\
+			pr_err("Unknown symbol: " #name "\n");		\
+			return -EINVAL;					\
+		}							\
+	} while (0)
+
+#endif

+ 6 - 5
Pal/ipc/linux/load.sh

@@ -1,11 +1,12 @@
 #!/bin/sh
 
-module="graphene-ipc"
+MOD=graphene-ipc
+MODNAME=graphene_ipc
 
-(/sbin/lsmod | grep -q "graphene_ipc") && \
-((echo "unloading graphene_ipc..."; /sbin/rmmod graphene_ipc) || exit 1) || continue
+(/sbin/lsmod | grep -q $MODNAME) && \
+((echo "unloading $MODNAME..."; /sbin/rmmod $MODNAME) || exit 1) || continue
 
 # invoke insmod with all arguments we got
 # and use a pathname, as newer modutils don't look in . by default
-echo "loading graphene_ipc..."
-/sbin/insmod ./$module.ko $* || exit 1
+echo "loading $MODNAME..."
+/sbin/insmod ./$MOD.ko $* || exit 1

+ 3 - 2
Pal/ipc/linux/uninstall.sh

@@ -2,11 +2,12 @@
 
 DIR=`readlink -f "${BASH_SOURCE[0]}"`
 MOD=graphene-ipc
+MODNAME=graphene_ipc
 VER=0.0.1
 
-/sbin/lsmod | grep -q graphene_ipc
+/sbin/lsmod | grep -q $MODNAME
 if [ $? -eq 0 ]; then
-	modprobe -r graphene-ipc
+	modprobe -r $MODNAME
 fi
 
 /usr/sbin/dkms status | grep -q $MOD

+ 1 - 1
Pal/regression/.packed/test.sha384

@@ -1 +1 @@
-Bootstrap Bootstrap2 Bootstrap3 Directory Exception File Ipc Memory Misc Pipe Preload1.so Preload2.so Process Process2 Process3 SendHandle Socket Symbols Thread acacabbb77227418b9442ca05ee56c5b884e6db4561907c3ac66ba611286675ea89f9e37f9bb86ff5d54b8f0d1e06391
+Bootstrap Bootstrap2 Bootstrap3 Directory Exception File Ipc Memory Misc Pipe Preload1.so Preload2.so Process Process2 Process3 SendHandle Socket Symbols Thread da9eddeb36c6f24f4fbebb7f94c198b81fe757849556080cda2c40cbbeadf4cd86e72533983cda9fc0af34f65ce75d16

BIN
Pal/regression/.packed/test.tar.gz


+ 35 - 39
Pal/src/db_exception.c

@@ -31,23 +31,50 @@
 #include "api.h"
 #include "linux_list.h"
 
+#define INIT_EVENT_HANDLER      { .lock = LOCK_INIT }
+
+struct pal_event_handler {
+    PAL_LOCK lock;
+    PAL_EVENT_HANDLER upcall;
+};
+
+struct pal_event_handler handlers[] = {
+        [PAL_EVENT_DIVZERO]     = INIT_EVENT_HANDLER,
+        [PAL_EVENT_MEMFAULT]    = INIT_EVENT_HANDLER,
+        [PAL_EVENT_ILLEGAL]     = INIT_EVENT_HANDLER,
+        [PAL_EVENT_QUIT]        = INIT_EVENT_HANDLER,
+        [PAL_EVENT_SUSPEND]     = INIT_EVENT_HANDLER,
+        [PAL_EVENT_RESUME]      = INIT_EVENT_HANDLER,
+        [PAL_EVENT_FAILURE]     = INIT_EVENT_HANDLER,
+    };
+
+PAL_EVENT_HANDLER _DkGetExceptionHandler (PAL_NUM event)
+{
+    struct pal_event_handler * eh = &handlers[event];
+
+    _DkInternalLock(&eh->lock);
+    PAL_EVENT_HANDLER upcall = eh->upcall;
+    _DkInternalUnlock(&eh->lock);
+
+    return upcall;
+}
+
 PAL_BOL
-DkSetExceptionHandler (void (*handler) (PAL_PTR, PAL_NUM, PAL_CONTEXT *),
-                       PAL_NUM event, PAL_FLG flags)
+DkSetExceptionHandler (PAL_EVENT_HANDLER handler, PAL_NUM event, PAL_FLG flags)
 {
     ENTER_PAL_CALL(DkSetExceptionHandler);
 
-    if (!handler || event <= 0 || event > PAL_EVENT_NUM_BOUND) {
+    if (!handler || event == 0 ||
+        event > sizeof(handlers) / sizeof(handlers[0])) {
         _DkRaiseFailure(PAL_ERROR_INVAL);
         LEAVE_PAL_CALL_RETURN(PAL_FALSE);
     }
 
-    int ret = _DkExceptionHandlers[event](event, handler, flags);
+    struct pal_event_handler * eh = &handlers[event];
 
-    if (ret < 0) {
-        _DkRaiseFailure(-ret);
-        LEAVE_PAL_CALL_RETURN(PAL_FALSE);
-    }
+    _DkInternalLock(&eh->lock);
+    eh->upcall = handler;
+    _DkInternalUnlock(&eh->lock);
 
     LEAVE_PAL_CALL_RETURN(PAL_TRUE);
 }
@@ -56,34 +83,3 @@ void DkExceptionReturn (PAL_PTR event)
 {
     _DkExceptionReturn(event);
 }
-
-#ifndef NO_HANDLE_COMPATIBILITY
-unsigned long _DkHandleCompatibilityException (unsigned long syscallno,
-                                               unsigned long args[6])
-{
-    printf("compatibility support: detected an unintercepted system call\n");
-
-    if (!pal_state.syscall_sym_addr)
-        _DkProcessExit(-1);
-
-    unsigned long ret;
-
-    asm volatile ("movq %6, %%r10\r\n"
-                  "movq %7, %%r8\r\n"
-                  "movq %8, %%r9\r\n"
-                  "callq *%1\r\n"
-                  "movq %%rax, %0\r\n"
-                  : "=a" (ret)
-                  : "r"(pal_state.syscall_sym_addr),
-                    "a" (syscallno),
-                    "D" (args[0]),
-                    "S" (args[1]),
-                    "d" (args[2]),
-                    "r" (args[3]),
-                    "r" (args[4]),
-                    "r" (args[5])
-                  : "memory", "r10", "r8", "r9");
-
-    return ret;
-}
-#endif

+ 0 - 17
Pal/src/db_main.c

@@ -204,22 +204,6 @@ out:
     __pal_control.debug_stream = handle;
 }
 
-static void set_syscall_symbol (void)
-{
-    char cfgbuf[CONFIG_MAX];
-    int ret;
-
-    if (!pal_state.root_config)
-        return;
-
-    ret = get_config(pal_state.root_config, "loader.syscall_symbol",
-                     cfgbuf, CONFIG_MAX);
-    if (ret <= 0)
-        return;
-
-    pal_state.syscall_sym_name = remalloc(cfgbuf, ret + 1);
-}
-
 static int loader_filter (const char * key, int len)
 {
     /* try to do this as fast as possible */
@@ -413,7 +397,6 @@ has_manifest:
 #endif
 
     set_debug_type();
-    set_syscall_symbol();
 
     __pal_control.process_id         = _DkGetProcessId();
     __pal_control.host_id            = _DkGetHostId();

+ 15 - 25
Pal/src/db_rtld.c

@@ -419,13 +419,12 @@ postmap:
             goto call_lose;
         }
     } else {
-        l->l_ld = (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr);
-    }
-
-    l->l_real_ld = l->l_ld;
+        l->l_real_ld = l->l_ld =
+            (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr);
 
-    if (do_copy_dyn)
-        l->l_ld = remalloc(l->l_ld, sizeof(ElfW(Dyn)) * l->l_ldnum);
+        if (do_copy_dyn)
+            l->l_ld = remalloc(l->l_ld, sizeof(ElfW(Dyn)) * l->l_ldnum);
+    }
 
     elf_get_dynamic_info(l->l_ld, l->l_info, l->l_addr);
 
@@ -496,7 +495,9 @@ void free_elf_object (struct link_map * map)
     if (map->l_next)
         map->l_next->l_prev = map->l_prev;
 
+#ifdef DEBUG
     _DkDebugDelMap(map);
+#endif
 
     if (loaded_maps == map)
         loaded_maps = map->l_next;
@@ -572,7 +573,10 @@ int add_elf_object(void * addr, PAL_HANDLE handle, int type)
     if (type == OBJECT_EXEC)
         exec_map = map;
 
+#ifdef DEBUG
     _DkDebugAddMap(map);
+#endif
+
     return 0;
 }
 
@@ -903,7 +907,10 @@ done:
     if (map->l_type == OBJECT_EXEC)
         exec_map = map;
 
+#ifdef DEBUG
     _DkDebugAddMap(map);
+#endif
+
     return 0;
 
 verify_failed:
@@ -1201,33 +1208,16 @@ static int relocate_elf_object (struct link_map * l)
         if ((ret = protect_relro(l)) < 0)
             return ret;
 
-    if (l->l_type == OBJECT_PRELOAD && pal_state.syscall_sym_name) {
-        uint_fast32_t fast_hash = elf_fast_hash(pal_state.syscall_sym_name);
-        long int hash = elf_hash(pal_state.syscall_sym_name);
-        ElfW(Sym) * sym = NULL;
-
-        sym = do_lookup_map(NULL, pal_state.syscall_sym_name, fast_hash,
-                            hash, l);
-
-        if (sym) {
-            pal_state.syscall_sym_addr =
-                    (void *) (l->l_addr + sym->st_value);
-        }
-    }
-
     return 0;
 }
 
 void DkDebugAttachBinary (PAL_STR uri, PAL_PTR start_addr)
 {
 #ifdef DEBUG
-    const char * realname;
-
-    if (strpartcmp_static(uri, "file:"))
-        realname = uri + static_strlen("file:");
-    else
+    if (!strpartcmp_static(uri, "file:"))
         return;
 
+    const char * realname = uri + static_strlen("file:");
     struct link_map * l = new_elf_object(realname, OBJECT_EXTERNAL);
 
     /* This is the ELF header.  We read it in `open_verify'.  */

+ 3 - 1
Pal/src/do-rel.h

@@ -41,7 +41,9 @@
                               (void *) (l->l_addr + relative->r_offset))
 #endif
 
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#ifndef MIN
+# define MIN(a, b) (((a) < (b)) ? (a) : (b))
+#endif
 
 static void __attribute_unused
 elf_dynamic_do_rel (struct link_map *l, ElfW(Addr) reladdr, int relsize)

+ 5 - 0
Pal/src/dynamic_link.h

@@ -70,6 +70,11 @@ elf_get_dynamic_info (ElfW(Dyn) *dyn, ElfW(Dyn) **l_info, ElfW(Addr) l_addr)
     typedef Elf64_Xword d_tag_utype;
 #endif
 
+#ifndef RTLD_BOOTSTRAP
+    if (dyn == NULL)
+        return;
+#endif
+
     while (dyn->d_tag != DT_NULL) {
         if ((d_tag_utype) dyn->d_tag < DT_NUM)
             l_info[dyn->d_tag] = dyn;

+ 29 - 85
Pal/src/host/Linux-SGX/db_exception.c

@@ -39,43 +39,11 @@
 #include <linux/signal.h>
 #include <ucontext.h>
 
-struct exception_handler {
-    struct spinlock lock;
-    int flags;
-    PAL_UPCALL upcall;
-} __attribute__((aligned(sizeof(int))));
-
-struct exception_event {
-    int event_num;
-    int flags;
-    PAL_CONTEXT * context;
-    struct pal_frame * frame;
-};
-
-#define DECLARE_HANDLER_HEAD(event)                     \
-    static struct exception_handler handler_##event =   \
-        { .lock = LOCK_INIT,                            \
-          .upcall = NULL,                               \
-          .flags = 0, }
-
-DECLARE_HANDLER_HEAD(DivZero);
-DECLARE_HANDLER_HEAD(MemFault);
-DECLARE_HANDLER_HEAD(Illegal);
-DECLARE_HANDLER_HEAD(Quit);
-DECLARE_HANDLER_HEAD(Suspend);
-DECLARE_HANDLER_HEAD(Resume);
-DECLARE_HANDLER_HEAD(Failure);
-
-struct exception_handler * pal_handlers [PAL_EVENT_NUM_BOUND] = {
-        NULL, /* reserved */
-        &handler_DivZero,
-        &handler_MemFault,
-        &handler_Illegal,
-        &handler_Quit,
-        &handler_Suspend,
-        &handler_Resume,
-        &handler_Failure,
-    };
+typedef struct exception_event {
+    PAL_IDX             event_num;
+    PAL_CONTEXT *       context;
+    struct pal_frame *  frame;
+} PAL_EVENT;
 
 #define SIGNAL_MASK_TIME 1000
 
@@ -84,30 +52,27 @@ struct exception_handler * pal_handlers [PAL_EVENT_NUM_BOUND] = {
                   "movq %%rax, %0\r\n"              \
                   : "=b"(ptr) :: "memory", "rax")
 
-void _DkGenericEventTrigger (int event_num, PAL_UPCALL upcall,
-                             int flags, PAL_NUM arg, struct pal_frame * frame,
+void _DkGenericEventTrigger (PAL_IDX event_num, PAL_EVENT_HANDLER upcall,
+                             PAL_NUM arg, struct pal_frame * frame,
                              PAL_CONTEXT * context)
 {
     struct exception_event event;
+
     event.event_num = event_num;
-    event.flags = flags;
     event.context = context;
     event.frame = frame;
+
     (*upcall) ((PAL_PTR) &event, arg, context);
 }
 
-static bool _DkGenericSignalHandle (int event_num, PAL_NUM arg,
-                                    struct pal_frame * frame,
-                                    PAL_CONTEXT * context)
+static bool
+_DkGenericSignalHandle (int event_num, PAL_NUM arg, struct pal_frame * frame,
+                        PAL_CONTEXT * context)
 {
-    struct exception_handler * handler = pal_handlers[event_num];
-    _DkSpinLock(&handler->lock);
-    PAL_UPCALL upcall = handler->upcall;
-    int flags = handler->flags;
-    _DkSpinUnlock(&handler->lock);
+    PAL_EVENT_HANDLER upcall = _DkGetExceptionHandler(event_num);
 
     if (upcall) {
-        _DkGenericEventTrigger(event_num, upcall, flags, arg, frame, context);
+        _DkGenericEventTrigger(event_num, upcall, arg, frame, context);
         return true;
     }
 
@@ -146,30 +111,6 @@ static struct pal_frame * get_frame (sgx_context_t * uc)
     return NULL;
 }
 
-static int _DkEventUpcall (int event_num, PAL_UPCALL upcall, int flags)
-{
-    struct exception_handler * handler = pal_handlers[event_num];
-    _DkSpinLock(&handler->lock);
-    handler->upcall = upcall;
-    handler->flags = flags;
-    _DkSpinUnlock(&handler->lock);
-    return 0;
-}
-
-typedef void (*PAL_UPCALL) (PAL_PTR, PAL_NUM, PAL_CONTEXT *);
-
-int (*_DkExceptionHandlers[PAL_EVENT_NUM_BOUND])
-    (int, PAL_UPCALL, int) = {
-        /* reserved   */ NULL,
-        /* DivZero    */ &_DkEventUpcall,
-        /* MemFault   */ &_DkEventUpcall,
-        /* Illegal    */ &_DkEventUpcall,
-        /* Quit       */ &_DkEventUpcall,
-        /* Suspend    */ &_DkEventUpcall,
-        /* Resume     */ &_DkEventUpcall,
-        /* Failure    */ &_DkEventUpcall,
-    };
-
 asm (".type arch_exception_return_asm, @function;"
      "arch_exception_return_asm:"
      "  pop %rax;"
@@ -190,8 +131,8 @@ asm (".type arch_exception_return_asm, @function;"
 
 extern void arch_exception_return (void) asm ("arch_exception_return_asm");
 
-void _DkExceptionRealHandler (int event, PAL_CONTEXT * context, PAL_NUM arg,
-                              struct pal_frame * frame)
+void _DkExceptionRealHandler (int event, PAL_NUM arg, struct pal_frame * frame,
+                              PAL_CONTEXT * context)
 {
     if (frame) {
         frame = __alloca(sizeof(struct pal_frame));
@@ -341,25 +282,28 @@ handle_event:
     struct pal_frame * frame = get_frame(uc);
 
     PAL_NUM arg = 0;
-    _DkExceptionRealHandler(event_num, ctx, arg, frame);
+    _DkExceptionRealHandler(event_num, arg, frame, ctx);
     restore_sgx_context(uc);
 }
 
 void _DkRaiseFailure (int error)
 {
-    _DkSpinLock(&handler_Failure.lock);
-    PAL_UPCALL upcall = handler_Failure.upcall;
-    int flags = handler_Failure.flags;
-    _DkSpinUnlock(&handler_Failure.lock);
-
-    if (upcall)
-        _DkGenericEventTrigger(PAL_EVENT_FAILURE, upcall, flags, error,
-                               NULL, NULL);
+    PAL_EVENT_HANDLER upcall = _DkGetExceptionHandler(PAL_EVENT_FAILURE);
+
+    if (!upcall)
+        return;
+
+    PAL_EVENT event;
+    event.event_num = PAL_EVENT_FAILURE;
+    event.context   = NULL;
+    event.frame     = NULL;
+
+    (*upcall) ((PAL_PTR) &event, error, NULL);
 }
 
 void _DkExceptionReturn (void * event)
 {
-    struct exception_event * e = (struct exception_event *) event;
+    PAL_EVENT * e = event;
     sgx_context_t uc;
     PAL_CONTEXT * ctx = e->context;
 

+ 1 - 5
Pal/src/host/Linux-SGX/elf-x86_64.h

@@ -37,13 +37,9 @@
 static inline Elf64_Addr __attribute__ ((unused))
 elf_machine_dynamic (void)
 {
-    Elf64_Addr addr;
-
     /* This works because we have our GOT address available in the small PIC
        model.  */
-    addr = (Elf64_Addr) &_DYNAMIC;
-
-    return addr;
+    return (Elf64_Addr) &_DYNAMIC;
 }
 
 /* Return the run-time load address of the shared object.  */

+ 53 - 254
Pal/src/host/Linux/db_exception.c

@@ -32,7 +32,6 @@
 #include "pal_error.h"
 #include "pal_security.h"
 #include "api.h"
-#include "linux_list.h"
 
 #include <atomic.h>
 #include <sigset.h>
@@ -98,9 +97,6 @@ int set_sighandler (int * sigs, int nsig, void * handler)
     __sigaddset((__sigset_t *) &action.sa_mask, SIGCONT);
 
     for (int i = 0 ; i < nsig ; i++) {
-        if (__sigismember(&linux_state.set_signals, sigs[i]))
-            continue;
-
 #if defined(__i386__)
         int ret = INLINE_SYSCALL(sigaction, 3, sigs[i], &action, NULL)
 #else
@@ -109,133 +105,17 @@ int set_sighandler (int * sigs, int nsig, void * handler)
 #endif
         if (IS_ERR(ret))
             return -PAL_ERROR_DENIED;
-
-        __sigaddset(&linux_state.set_signals, sigs[i]);
-    }
-
-
-    bool maskset = false;
-    int ret = 0;
-    __sigset_t mask;
-    __sigemptyset(&mask);
-
-    for (int i = 0 ; i < nsig ; i++)
-        if (__sigismember(&linux_state.blocked_signals, sigs[i])) {
-            __sigdelset(&linux_state.blocked_signals, sigs[i]);
-            __sigaddset(&mask, sigs[i]);
-            maskset = true;
-        }
-
-    if (maskset) {
-#if defined(__i386__)
-        ret = INLINE_SYSCALL(sigprocmask, 3, SIG_UNBLOCK, &mask, NULL)
-#else
-        ret = INLINE_SYSCALL(rt_sigprocmask, 4, SIG_UNBLOCK, &mask, NULL,
-                             sizeof(sigset_t));
-#endif
-    }
-
-    if (IS_ERR(ret))
-        return -PAL_ERROR_DENIED;
-
-    return 0;
-}
-
-int block_signals (int * sigs, int nsig)
-{
-    bool maskset = false;
-    int ret = 0;
-    __sigset_t mask;
-    __sigemptyset(&mask);
-
-    for (int i = 0 ; i < nsig ; i++)
-        if (!__sigismember(&linux_state.blocked_signals, sigs[i])) {
-            __sigaddset(&linux_state.blocked_signals, sigs[i]);
-            __sigaddset(&mask, sigs[i]);
-            maskset = true;
-        }
-
-    if (maskset) {
-#if defined(__i386__)
-        ret = INLINE_SYSCALL(sigprocmask, 3, SIG_BLOCK, &mask, NULL)
-#else
-        ret = INLINE_SYSCALL(rt_sigprocmask, 4, SIG_BLOCK, &mask, NULL,
-                             sizeof(sigset_t));
-#endif
     }
 
-    if (IS_ERR(ret))
-        return -PAL_ERROR_DENIED;
-
     return 0;
 }
 
-int unblock_signals (int * sigs, int nsig)
-{
-    bool maskset = false;
-    int ret = 0;
-    __sigset_t mask;
-    __sigemptyset(&mask);
-    for (int i = 0 ; i < nsig ; i++)
-        if (__sigismember(&linux_state.blocked_signals, sigs[i])) {
-            __sigdelset(&linux_state.blocked_signals, sigs[i]);
-            __sigaddset(&mask, sigs[i]);
-            maskset = true;
-        }
-
-    if (maskset) {
-#if defined(__i386__)
-        ret = INLINE_SYSCALL(sigprocmask, 3, SIG_UNBLOCK, &mask, NULL)
-#else
-        ret = INLINE_SYSCALL(rt_sigprocmask, 4, SIG_UNBLOCK, &mask, NULL,
-                             sizeof(sigset_t));
-#endif
-    }
-
-    if (IS_ERR(ret))
-        return -PAL_ERROR_DENIED;
-
-    return 0;
-}
-
-struct exception_handler {
-    struct mutex_handle lock;
-    int flags;
-    PAL_UPCALL upcall;
-} __attribute__((aligned(sizeof(int))));
-
-struct exception_event {
-    int event_num;
-    int flags;
-    PAL_CONTEXT context;
-    ucontext_t * uc;
-    void * eframe;
-};
-
-#define DECLARE_HANDLER_HEAD(event)                         \
-    static struct exception_handler handler_##event =       \
-        {  .lock = MUTEX_HANDLE_INIT,                       \
-           .upcall = NULL,                                  \
-           .flags = 0, };
-
-DECLARE_HANDLER_HEAD(DivZero);
-DECLARE_HANDLER_HEAD(MemFault);
-DECLARE_HANDLER_HEAD(Illegal);
-DECLARE_HANDLER_HEAD(Quit);
-DECLARE_HANDLER_HEAD(Suspend);
-DECLARE_HANDLER_HEAD(Resume);
-DECLARE_HANDLER_HEAD(Failure);
-
-struct exception_handler * pal_handlers [PAL_EVENT_NUM_BOUND] = {
-        NULL, /* reserved */
-        &handler_DivZero,
-        &handler_MemFault,
-        &handler_Illegal,
-        &handler_Quit,
-        &handler_Suspend,
-        &handler_Resume,
-        &handler_Failure,
-    };
+typedef struct {
+    PAL_IDX         event_num;
+    PAL_CONTEXT     context;
+    ucontext_t *    uc;
+    PAL_PTR         eframe;
+} PAL_EVENT;
 
 #define SIGNAL_MASK_TIME 1000
 
@@ -249,7 +129,7 @@ static int get_event_num (int signum)
     switch(signum) {
         case SIGFPE:                return PAL_EVENT_DIVZERO;
         case SIGSEGV: case SIGBUS:  return PAL_EVENT_MEMFAULT;
-        case SIGILL:                return PAL_EVENT_ILLEGAL;
+        case SIGILL:  case SIGSYS:  return PAL_EVENT_ILLEGAL;
         case SIGTERM:               return PAL_EVENT_QUIT;
         case SIGINT:                return PAL_EVENT_SUSPEND;
         case SIGCONT:               return PAL_EVENT_RESUME;
@@ -257,13 +137,12 @@ static int get_event_num (int signum)
     }
 }
 
-void _DkGenericEventTrigger (int event_num, PAL_UPCALL upcall,
-                             int flags, PAL_NUM arg, struct pal_frame * frame,
+void _DkGenericEventTrigger (PAL_IDX event_num, PAL_EVENT_HANDLER upcall,
+                             PAL_NUM arg, struct pal_frame * frame,
                              ucontext_t * uc, void * eframe)
 {
-    struct exception_event event;
+    PAL_EVENT event;
     event.event_num = event_num;
-    event.flags = flags;
 
     if (uc)
         memcpy(&event.context, uc->uc_mcontext.gregs, sizeof(PAL_CONTEXT));
@@ -280,6 +159,8 @@ void _DkGenericEventTrigger (int event_num, PAL_UPCALL upcall,
         event.context.rsp = frame->arch.rbp + sizeof(unsigned long) * 2;
         event.context.rbp = ((unsigned long *) frame->arch.rbp)[0];
         event.context.rip = ((unsigned long *) frame->arch.rbp)[1];
+        /* making rax = 0 to tell the caller that this PAL call failed */
+        event.context.rax = 0;
     }
 
     event.uc = uc;
@@ -292,12 +173,7 @@ static bool _DkGenericSignalHandle (int event_num, siginfo_t * info,
                                     struct pal_frame * frame,
                                     ucontext_t * uc, void * eframe)
 {
-    struct exception_handler * handler = pal_handlers[event_num];
-
-    _DkMutexLock(&handler->lock);
-    PAL_UPCALL upcall = handler->upcall;
-    int flags = handler->flags;
-    _DkMutexUnlock(&handler->lock);
+    PAL_EVENT_HANDLER upcall = _DkGetExceptionHandler(event_num);
 
     if (upcall) {
         PAL_NUM arg = 0;
@@ -307,8 +183,7 @@ static bool _DkGenericSignalHandle (int event_num, siginfo_t * info,
             event_num == PAL_EVENT_ILLEGAL)
             arg = (PAL_NUM) (info ? info->si_addr : 0);
 
-        _DkGenericEventTrigger(event_num, upcall, flags, arg, frame,
-                               uc, eframe);
+        _DkGenericEventTrigger(event_num, upcall, arg, frame, uc, eframe);
         return true;
     }
 
@@ -351,9 +226,9 @@ static void return_frame (struct pal_frame * frame, int err)
     __clear_frame(frame);
     arch_restore_frame(&frame->arch);
 
-    asm volatile ("xor %%rax, %%rax\r\n"
+    asm volatile ("xor %rax, %rax\r\n"
                   "leaveq\r\n"
-                  "retq\r\n" ::: "memory");
+                  "retq\r\n");
 }
 
 static void _DkGenericSighandler (int signum, siginfo_t * info,
@@ -417,14 +292,17 @@ static void _DkPipeSighandler (int signum, siginfo_t * info,
 
 void _DkRaiseFailure (int error)
 {
-    _DkMutexLock(&handler_Failure.lock);
-    PAL_UPCALL upcall = handler_Failure.upcall;
-    int flags = handler_Failure.flags;
-    _DkMutexUnlock(&handler_Failure.lock);
-
-    if (upcall)
-        _DkGenericEventTrigger(PAL_EVENT_FAILURE, upcall, flags, error,
-                               NULL, NULL, NULL);
+    PAL_EVENT_HANDLER upcall = _DkGetExceptionHandler(PAL_EVENT_FAILURE);
+
+    if (!upcall)
+        return;
+
+    PAL_EVENT event;
+    event.event_num = PAL_EVENT_FAILURE;
+    event.uc = NULL;
+    event.eframe = NULL;
+
+    (*upcall) ((PAL_PTR) &event, error, NULL);
 }
 
 struct signal_ops {
@@ -432,21 +310,19 @@ struct signal_ops {
     void (*handler) (int signum, siginfo_t * info, ucontext_t * uc);
 };
 
-struct signal_ops on_signals[PAL_EVENT_NUM_BOUND] = {
-        /* reserved    */ { .signum = { 0 }, .handler = NULL },
-        /* DivZero     */ { .signum = { SIGFPE, 0 },
-                            .handler = _DkGenericSighandler },
-        /* MemFault    */ { .signum = { SIGSEGV, SIGBUS, 0 },
-                            .handler = _DkGenericSighandler },
-        /* Illegal     */ { .signum = { SIGILL, 0 },
-                            .handler = _DkGenericSighandler },
-        /* Quit        */ { .signum = { SIGTERM, 0, 0 },
-                            .handler = _DkTerminateSighandler },
-        /* Suspend     */ { .signum = { SIGINT, 0 },
-                            .handler = _DkTerminateSighandler },
-        /* Resume      */ { .signum = { SIGCONT, 0 },
-                            .handler = _DkGenericSighandler },
-        /* Failure     */ { .signum = { 0 }, .handler = NULL },
+struct signal_ops on_signals[] = {
+        [PAL_EVENT_DIVZERO]     = { .signum = { SIGFPE, 0 },
+                                    .handler = _DkGenericSighandler },
+        [PAL_EVENT_MEMFAULT]    = { .signum = { SIGSEGV, SIGBUS, 0 },
+                                    .handler = _DkGenericSighandler },
+        [PAL_EVENT_ILLEGAL]     = { .signum = { SIGILL,  SIGSYS, 0 },
+                                    .handler = _DkGenericSighandler },
+        [PAL_EVENT_QUIT]        = { .signum = { SIGTERM, 0, 0 },
+                                    .handler = _DkTerminateSighandler },
+        [PAL_EVENT_SUSPEND]     = { .signum = { SIGINT, 0 },
+                                    .handler = _DkTerminateSighandler },
+        [PAL_EVENT_RESUME]      = { .signum = { SIGCONT, 0 },
+                                    .handler = _DkGenericSighandler },
     };
 
 static int _DkPersistentSighandlerSetup (int event_num)
@@ -461,77 +337,6 @@ static int _DkPersistentSighandlerSetup (int event_num)
     return 0;
 }
 
-static int _DkPersistentEventUpcall (int event_num, PAL_UPCALL upcall,
-                                     int flags)
-{
-    struct exception_handler * handler = pal_handlers[event_num];
-    _DkMutexLock(&handler->lock);
-    handler->upcall = upcall;
-    handler->flags = flags;
-    _DkMutexUnlock(&handler->lock);
-    return _DkPersistentSighandlerSetup(event_num);
-}
-
-static int _DkGenericEventUpcall (int event_num, PAL_UPCALL upcall,
-                                  int flags)
-{
-    int nsigs, * sigs = on_signals[event_num].signum;
-    for (nsigs = 0 ; sigs[nsigs] ; nsigs++);
-
-    struct exception_handler * handler = pal_handlers[event_num];
-    int ret = 0;
-
-    _DkMutexLock(&handler->lock);
-    handler->upcall = upcall;
-    handler->flags = flags;
-    _DkMutexUnlock(&handler->lock);
-
-    if (upcall)
-        ret = set_sighandler(sigs, nsigs, on_signals[event_num].handler);
-    else
-        ret = block_signals(sigs, nsigs);
-
-    return ret;
-}
-
-static int _DkDummyEventUpcall (int event_num, PAL_UPCALL upcall,
-                                int flags)
-{
-    struct exception_handler * handler = pal_handlers[event_num];
-    _DkMutexLock(&handler->lock);
-    handler->upcall = upcall;
-    handler->flags = flags;
-    _DkMutexUnlock(&handler->lock);
-    return 0;
-}
-
-typedef void (*PAL_UPCALL) (PAL_PTR, PAL_NUM, PAL_CONTEXT *);
-
-int (*_DkExceptionHandlers[PAL_EVENT_NUM_BOUND])
-    (int, PAL_UPCALL, int) = {
-        /* reserved   */ NULL,
-        /* DivZero    */ &_DkPersistentEventUpcall,
-        /* MemFault   */ &_DkPersistentEventUpcall,
-        /* Illegal    */ &_DkPersistentEventUpcall,
-        /* Quit       */ &_DkGenericEventUpcall,
-        /* Suspend    */ &_DkGenericEventUpcall,
-        /* Resume     */ &_DkGenericEventUpcall,
-        /* Failure    */ &_DkDummyEventUpcall,
-    };
-
-static void _DkCompatibilitySighandler (int signum, siginfo_t * info,
-                                        ucontext_t * uc)
-{
-    unsigned long args[6] = { uc->uc_mcontext.gregs[REG_RDI],
-                              uc->uc_mcontext.gregs[REG_RSI],
-                              uc->uc_mcontext.gregs[REG_RDX],
-                              uc->uc_mcontext.gregs[REG_R10],
-                              uc->uc_mcontext.gregs[REG_R8],
-                              uc->uc_mcontext.gregs[REG_R9] };
-    uc->uc_mcontext.gregs[REG_RAX] =
-        _DkHandleCompatibilityException(uc->uc_mcontext.gregs[REG_RAX], args);
-}
-
 void signal_setup (void)
 {
     int ret, sig = SIGCHLD;
@@ -541,22 +346,22 @@ void signal_setup (void)
 #endif
         set_sighandler(&sig, 1, NULL);
 
-    if ((ret = _DkPersistentEventUpcall(PAL_EVENT_DIVZERO,  NULL, 0)) < 0)
-        goto err;
-
-    if ((ret = _DkPersistentEventUpcall(PAL_EVENT_MEMFAULT,  NULL, 0)) < 0)
-        goto err;
-
-    if ((ret = _DkPersistentEventUpcall(PAL_EVENT_ILLEGAL,  NULL, 0)) < 0)
-        goto err;
-
     sig = SIGPIPE;
     if ((ret = set_sighandler(&sig, 1, &_DkPipeSighandler)) < 0)
         goto err;
 
-    sig = SIGSYS;
-    if ((ret = set_sighandler(&sig, 1, &_DkCompatibilitySighandler)) < 0)
-        goto err;
+    int events[] = {
+        PAL_EVENT_DIVZERO,
+        PAL_EVENT_MEMFAULT,
+        PAL_EVENT_ILLEGAL,
+        PAL_EVENT_QUIT,
+        PAL_EVENT_SUSPEND,
+        PAL_EVENT_RESUME,
+    };
+
+    for (int e = 0 ; e < sizeof(events) / sizeof(events[0]) ; e++)
+        if ((ret = _DkPersistentSighandlerSetup(events[e])) < 0)
+            goto err;
 
     return;
 err:
@@ -565,7 +370,7 @@ err:
 
 void _DkExceptionReturn (void * event)
 {
-    struct exception_event * e = (struct exception_event *) event;
+    PAL_EVENT * e = event;
 
     if (e->eframe) {
         struct pal_frame * frame = (struct pal_frame *) e->eframe;
@@ -586,16 +391,10 @@ void _DkExceptionReturn (void * event)
             _DkRaiseFailure(err);
 
         __clear_frame(frame);
-        e->context.rax = 0;
     }
 
     if (e->uc) {
         /* copy the context back to ucontext */
         memcpy(e->uc->uc_mcontext.gregs, &e->context, sizeof(PAL_CONTEXT));
-
-        /* return to the frame of exception handler */
-        asm volatile ("movq %0, %%rbp\r\n"
-                      "leaveq\r\n"
-                      "retq\r\n" :: "r"(e->eframe) : "memory");
     }
 }

+ 2 - 2
Pal/src/host/Linux/pal_host.h

@@ -188,7 +188,7 @@ struct arch_frame {
 
 #ifdef __x86_64__
 # define store_register(reg, var)     \
-    asm volatile ("movq %%" #reg ", %0" : "=g" (var) :: "memory");
+    asm volatile ("movq %%" #reg ", %0" : "=a" (var) :: "memory");
 
 # define store_register_in_frame(reg, f)     store_register(reg, (f)->reg)
 
@@ -235,10 +235,10 @@ static inline
 void __store_frame (struct pal_frame * frame,
                     void * func, const char * funcname)
 {
+    arch_store_frame(&frame->arch)
     *(volatile void **) &frame->self = frame;
     frame->func = func;
     frame->funcname = funcname;
-    arch_store_frame(&frame->arch)
 }
 
 #define ENTER_PAL_CALL(name)                \

+ 1 - 8
Pal/src/pal_internal.h

@@ -230,11 +230,7 @@ extern struct pal_internal_state {
 
     PAL_HANDLE      console;
 
-    const char *    syscall_sym_name;
-    void *          syscall_sym_addr;
-
     unsigned long   start_time;
-
 #if PROFILING == 1
     unsigned long   relocation_time;
     unsigned long   linking_time;
@@ -351,8 +347,7 @@ int _DkObjectsWaitAny (int count, PAL_HANDLE * handleArray, int timeout,
                        PAL_HANDLE * polled);
 
 /* DkException calls & structures */
-typedef void (*PAL_UPCALL) (PAL_PTR, PAL_NUM, PAL_CONTEXT *);
-int (*_DkExceptionHandlers[PAL_EVENT_NUM_BOUND]) (int, PAL_UPCALL, int);
+PAL_EVENT_HANDLER _DkGetExceptionHandler (PAL_NUM event_num);
 void _DkRaiseFailure (int error);
 void _DkExceptionReturn (void * event);
 
@@ -371,8 +366,6 @@ int _DkPhysicalMemoryCommit (PAL_HANDLE channel, int entries,
 int _DkPhysicalMemoryMap (PAL_HANDLE channel, int entries,
                           PAL_PTR * addrs, PAL_NUM * sizes, PAL_FLG * prots);
 int _DkCpuIdRetrieve (unsigned int leaf, unsigned int subleaf, unsigned int values[4]);
-unsigned long _DkHandleCompatibilityException (unsigned long syscallno,
-                                               unsigned long args[6]);
 
 #define init_fail(exitcode, reason)                                     \
     do {                                                                \

Some files were not shown because too many files changed in this diff