aboutsummaryrefslogtreecommitdiff
path: root/libmpx/mpxrt
diff options
context:
space:
mode:
authorIlya Enkovich <ilya.enkovich@intel.com>2015-03-10 09:37:41 +0000
committerIlya Enkovich <ienkovich@gcc.gnu.org>2015-03-10 09:37:41 +0000
commit5373cd33a8cdb54a31bc7bf2ae4c9903efa4911c (patch)
tree4c3d129c804e483567ad1709e6159edb9e847d6e /libmpx/mpxrt
parent5a434178855e784d2667d68f0acf3c01bf48e847 (diff)
downloadgcc-5373cd33a8cdb54a31bc7bf2ae4c9903efa4911c.zip
gcc-5373cd33a8cdb54a31bc7bf2ae4c9903efa4911c.tar.gz
gcc-5373cd33a8cdb54a31bc7bf2ae4c9903efa4911c.tar.bz2
Makefile.def: Add libmpx.
* Makefile.def: Add libmpx. * configure.ac: Add libmpx. * Makefile.in: Regenerate. * configure: Regenerate. gcc/ * config/i386/linux-common.h (LIBMPX_LIBS): New. (LIBMPX_SPEC): New. (CHKP_SPEC): New. * gcc.c (CHKP_SPEC): New. (LINK_COMMAND_SPEC): Add CHKP_SPEC. * c-family/c.opt (static-libmpx): New. libmpx/ Initial commit. From-SVN: r221311
Diffstat (limited to 'libmpx/mpxrt')
-rw-r--r--libmpx/mpxrt/Makefile.am60
-rw-r--r--libmpx/mpxrt/Makefile.in549
-rw-r--r--libmpx/mpxrt/libmpx.map5
-rw-r--r--libmpx/mpxrt/libtool-version6
-rw-r--r--libmpx/mpxrt/mpxrt-utils.c505
-rw-r--r--libmpx/mpxrt/mpxrt-utils.h65
-rw-r--r--libmpx/mpxrt/mpxrt.c515
7 files changed, 1705 insertions, 0 deletions
diff --git a/libmpx/mpxrt/Makefile.am b/libmpx/mpxrt/Makefile.am
new file mode 100644
index 0000000..a00a808
--- /dev/null
+++ b/libmpx/mpxrt/Makefile.am
@@ -0,0 +1,60 @@
+ACLOCAL_AMFLAGS = -I $(top_srcdir) -I $(top_srcdir)/config
+
+if LIBMPX_SUPPORTED
+# May be used by toolexeclibdir.
+gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
+
+AM_CPPFLAGS = -I$(top_srcdir)/..
+AM_CFLAGS = $(XCFLAGS)
+
+toolexeclib_LTLIBRARIES = libmpx.la
+
+libmpx_la_SOURCES = mpxrt.c mpxrt-utils.c
+
+libmpx_la_CFLAGS = -fPIC
+libmpx_la_DEPENDENCIES = libmpx.map
+libmpx_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmpx.map $(link_libmpx)
+
+mpxrt.lo: mpxrt-utils.h
+mpxrt-utils.lo: mpxrt-utils.h
+endif
+
+# Work around what appears to be a GNU make bug handling MAKEFLAGS
+# values defined in terms of make variables, as is the case for CC and
+# friends when we are called from the top level Makefile.
+AM_MAKEFLAGS = \
+ "AR_FLAGS=$(AR_FLAGS)" \
+ "CC_FOR_BUILD=$(CC_FOR_BUILD)" \
+ "CFLAGS=$(CFLAGS)" \
+ "CXXFLAGS=$(CXXFLAGS)" \
+ "CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
+ "CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
+ "INSTALL=$(INSTALL)" \
+ "INSTALL_DATA=$(INSTALL_DATA)" \
+ "INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
+ "INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
+ "JC1FLAGS=$(JC1FLAGS)" \
+ "LDFLAGS=$(LDFLAGS)" \
+ "LIBCFLAGS=$(LIBCFLAGS)" \
+ "LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
+ "MAKE=$(MAKE)" \
+ "MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
+ "PICFLAG=$(PICFLAG)" \
+ "PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
+ "SHELL=$(SHELL)" \
+ "RUNTESTFLAGS=$(RUNTESTFLAGS)" \
+ "exec_prefix=$(exec_prefix)" \
+ "infodir=$(infodir)" \
+ "libdir=$(libdir)" \
+ "prefix=$(prefix)" \
+ "includedir=$(includedir)" \
+ "AR=$(AR)" \
+ "AS=$(AS)" \
+ "LD=$(LD)" \
+ "LIBCFLAGS=$(LIBCFLAGS)" \
+ "NM=$(NM)" \
+ "PICFLAG=$(PICFLAG)" \
+ "RANLIB=$(RANLIB)" \
+ "DESTDIR=$(DESTDIR)"
+
+MAKEOVERRIDES=
diff --git a/libmpx/mpxrt/Makefile.in b/libmpx/mpxrt/Makefile.in
new file mode 100644
index 0000000..e1997d6
--- /dev/null
+++ b/libmpx/mpxrt/Makefile.in
@@ -0,0 +1,549 @@
+# Makefile.in generated by automake 1.11.1 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+target_triplet = @target@
+subdir = mpxrt
+DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+ $(top_srcdir)/../config/lead-dot.m4 \
+ $(top_srcdir)/../config/libstdc++-raw-cxx.m4 \
+ $(top_srcdir)/../config/multi.m4 \
+ $(top_srcdir)/../config/override.m4 \
+ $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
+ $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
+ $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(SHELL) $(top_srcdir)/../mkinstalldirs
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
+am__install_max = 40
+am__nobase_strip_setup = \
+ srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
+am__nobase_strip = \
+ for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
+am__nobase_list = $(am__nobase_strip_setup); \
+ for p in $$list; do echo "$$p $$p"; done | \
+ sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
+ $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
+ if (++n[$$2] == $(am__install_max)) \
+ { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
+ END { for (dir in files) print dir, files[dir] }'
+am__base_list = \
+ sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
+ sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
+am__installdirs = "$(DESTDIR)$(toolexeclibdir)"
+LTLIBRARIES = $(toolexeclib_LTLIBRARIES)
+libmpx_la_LIBADD =
+@LIBMPX_SUPPORTED_TRUE@am_libmpx_la_OBJECTS = libmpx_la-mpxrt.lo \
+@LIBMPX_SUPPORTED_TRUE@ libmpx_la-mpxrt-utils.lo
+libmpx_la_OBJECTS = $(am_libmpx_la_OBJECTS)
+libmpx_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
+ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(libmpx_la_CFLAGS) \
+ $(CFLAGS) $(libmpx_la_LDFLAGS) $(LDFLAGS) -o $@
+@LIBMPX_SUPPORTED_TRUE@am_libmpx_la_rpath = -rpath $(toolexeclibdir)
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp =
+am__depfiles_maybe =
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
+SOURCES = $(libmpx_la_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCAS = @CCAS@
+CCASFLAGS = @CCASFLAGS@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBSTDCXX_RAW_CXX_CXXFLAGS = @LIBSTDCXX_RAW_CXX_CXXFLAGS@
+LIBSTDCXX_RAW_CXX_LDFLAGS = @LIBSTDCXX_RAW_CXX_LDFLAGS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBOBJS = @LTLIBOBJS@
+MAINT = @MAINT@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_URL = @PACKAGE_URL@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+XCFLAGS = @XCFLAGS@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__leading_dot = @am__leading_dot@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+enable_shared = @enable_shared@
+enable_static = @enable_static@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+link_libmpx = @link_libmpx@
+localedir = @localedir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+multi_basedir = @multi_basedir@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target = @target@
+target_alias = @target_alias@
+target_cpu = @target_cpu@
+target_noncanonical = @target_noncanonical@
+target_os = @target_os@
+target_vendor = @target_vendor@
+toolexecdir = @toolexecdir@
+toolexeclibdir = @toolexeclibdir@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+ACLOCAL_AMFLAGS = -I $(top_srcdir) -I $(top_srcdir)/config
+
+# May be used by toolexeclibdir.
+@LIBMPX_SUPPORTED_TRUE@gcc_version := $(shell cat $(top_srcdir)/../gcc/BASE-VER)
+@LIBMPX_SUPPORTED_TRUE@AM_CPPFLAGS = -I$(top_srcdir)/..
+@LIBMPX_SUPPORTED_TRUE@AM_CFLAGS = $(XCFLAGS)
+@LIBMPX_SUPPORTED_TRUE@toolexeclib_LTLIBRARIES = libmpx.la
+@LIBMPX_SUPPORTED_TRUE@libmpx_la_SOURCES = mpxrt.c mpxrt-utils.c
+@LIBMPX_SUPPORTED_TRUE@libmpx_la_CFLAGS = -fPIC
+@LIBMPX_SUPPORTED_TRUE@libmpx_la_DEPENDENCIES = libmpx.map
+@LIBMPX_SUPPORTED_TRUE@libmpx_la_LDFLAGS = -Wl,--version-script=$(srcdir)/libmpx.map $(link_libmpx)
+
+# Work around what appears to be a GNU make bug handling MAKEFLAGS
+# values defined in terms of make variables, as is the case for CC and
+# friends when we are called from the top level Makefile.
+AM_MAKEFLAGS = \
+ "AR_FLAGS=$(AR_FLAGS)" \
+ "CC_FOR_BUILD=$(CC_FOR_BUILD)" \
+ "CFLAGS=$(CFLAGS)" \
+ "CXXFLAGS=$(CXXFLAGS)" \
+ "CFLAGS_FOR_BUILD=$(CFLAGS_FOR_BUILD)" \
+ "CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)" \
+ "INSTALL=$(INSTALL)" \
+ "INSTALL_DATA=$(INSTALL_DATA)" \
+ "INSTALL_PROGRAM=$(INSTALL_PROGRAM)" \
+ "INSTALL_SCRIPT=$(INSTALL_SCRIPT)" \
+ "JC1FLAGS=$(JC1FLAGS)" \
+ "LDFLAGS=$(LDFLAGS)" \
+ "LIBCFLAGS=$(LIBCFLAGS)" \
+ "LIBCFLAGS_FOR_TARGET=$(LIBCFLAGS_FOR_TARGET)" \
+ "MAKE=$(MAKE)" \
+ "MAKEINFO=$(MAKEINFO) $(MAKEINFOFLAGS)" \
+ "PICFLAG=$(PICFLAG)" \
+ "PICFLAG_FOR_TARGET=$(PICFLAG_FOR_TARGET)" \
+ "SHELL=$(SHELL)" \
+ "RUNTESTFLAGS=$(RUNTESTFLAGS)" \
+ "exec_prefix=$(exec_prefix)" \
+ "infodir=$(infodir)" \
+ "libdir=$(libdir)" \
+ "prefix=$(prefix)" \
+ "includedir=$(includedir)" \
+ "AR=$(AR)" \
+ "AS=$(AS)" \
+ "LD=$(LD)" \
+ "LIBCFLAGS=$(LIBCFLAGS)" \
+ "NM=$(NM)" \
+ "PICFLAG=$(PICFLAG)" \
+ "RANLIB=$(RANLIB)" \
+ "DESTDIR=$(DESTDIR)"
+
+MAKEOVERRIDES =
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+ && { if test -f $@; then exit 0; else break; fi; }; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign --ignore-deps mpxrt/Makefile'; \
+ $(am__cd) $(top_srcdir) && \
+ $(AUTOMAKE) --foreign --ignore-deps mpxrt/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: @MAINTAINER_MODE_TRUE@ $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): @MAINTAINER_MODE_TRUE@ $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-toolexeclibLTLIBRARIES: $(toolexeclib_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ test -z "$(toolexeclibdir)" || $(MKDIR_P) "$(DESTDIR)$(toolexeclibdir)"
+ @list='$(toolexeclib_LTLIBRARIES)'; test -n "$(toolexeclibdir)" || list=; \
+ list2=; for p in $$list; do \
+ if test -f $$p; then \
+ list2="$$list2 $$p"; \
+ else :; fi; \
+ done; \
+ test -z "$$list2" || { \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(toolexeclibdir)'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(toolexeclibdir)"; \
+ }
+
+uninstall-toolexeclibLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @list='$(toolexeclib_LTLIBRARIES)'; test -n "$(toolexeclibdir)" || list=; \
+ for p in $$list; do \
+ $(am__strip_dir) \
+ echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(toolexeclibdir)/$$f'"; \
+ $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(toolexeclibdir)/$$f"; \
+ done
+
+clean-toolexeclibLTLIBRARIES:
+ -test -z "$(toolexeclib_LTLIBRARIES)" || rm -f $(toolexeclib_LTLIBRARIES)
+ @list='$(toolexeclib_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+libmpx.la: $(libmpx_la_OBJECTS) $(libmpx_la_DEPENDENCIES)
+ $(libmpx_la_LINK) $(am_libmpx_la_rpath) $(libmpx_la_OBJECTS) $(libmpx_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+.c.o:
+ $(COMPILE) -c $<
+
+.c.obj:
+ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+ $(LTCOMPILE) -c -o $@ $<
+
+libmpx_la-mpxrt.lo: mpxrt.c
+ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmpx_la_CFLAGS) $(CFLAGS) -c -o libmpx_la-mpxrt.lo `test -f 'mpxrt.c' || echo '$(srcdir)/'`mpxrt.c
+
+libmpx_la-mpxrt-utils.lo: mpxrt-utils.c
+ $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libmpx_la_CFLAGS) $(CFLAGS) -c -o libmpx_la-mpxrt-utils.lo `test -f 'mpxrt-utils.c' || echo '$(srcdir)/'`mpxrt-utils.c
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ set x; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ shift; \
+ if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ if test $$# -gt 0; then \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ "$$@" $$unique; \
+ else \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$unique; \
+ fi; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+ END { if (nonempty) { for (i in files) print i; }; }'`; \
+ test -z "$(CTAGS_ARGS)$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && $(am__cd) $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+ for dir in "$(DESTDIR)$(toolexeclibdir)"; do \
+ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+ -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libtool clean-toolexeclibLTLIBRARIES \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-toolexeclibLTLIBRARIES
+
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-toolexeclibLTLIBRARIES
+
+.MAKE: install-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libtool clean-toolexeclibLTLIBRARIES ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags dvi dvi-am html html-am info info-am install \
+ install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am install-man \
+ install-pdf install-pdf-am install-ps install-ps-am \
+ install-strip install-toolexeclibLTLIBRARIES installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am uninstall-toolexeclibLTLIBRARIES
+
+
+@LIBMPX_SUPPORTED_TRUE@mpxrt.lo: mpxrt-utils.h
+@LIBMPX_SUPPORTED_TRUE@mpxrt-utils.lo: mpxrt-utils.h
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/libmpx/mpxrt/libmpx.map b/libmpx/mpxrt/libmpx.map
new file mode 100644
index 0000000..90093b7
--- /dev/null
+++ b/libmpx/mpxrt/libmpx.map
@@ -0,0 +1,5 @@
+LIBMPX_1.0
+{
+ local:
+ *;
+};
diff --git a/libmpx/mpxrt/libtool-version b/libmpx/mpxrt/libtool-version
new file mode 100644
index 0000000..5aa6ed7
--- /dev/null
+++ b/libmpx/mpxrt/libtool-version
@@ -0,0 +1,6 @@
+# This file is used to maintain libtool version info for libmpx. See
+# the libtool manual to understand the meaning of the fields. This is
+# a separate file so that version updates don't involve re-running
+# automake.
+# CURRENT:REVISION:AGE
+1:0:0
diff --git a/libmpx/mpxrt/mpxrt-utils.c b/libmpx/mpxrt/mpxrt-utils.c
new file mode 100644
index 0000000..057a355
--- /dev/null
+++ b/libmpx/mpxrt/mpxrt-utils.c
@@ -0,0 +1,505 @@
+/* mpxrt-utils.c -*-C++-*-
+ *
+ *************************************************************************
+ *
+ * @copyright
+ * Copyright (C) 2014, Intel Corporation
+ * All rights reserved.
+ *
+ * @copyright
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * @copyright
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+ * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ **************************************************************************/
+
+#define __STDC_FORMAT_MACROS
+#include "config.h"
+#include <inttypes.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <pthread.h>
+#include "mpxrt-utils.h"
+
+#ifndef HAVE_SECURE_GETENV
+#define secure_getenv __secure_getenv
+#endif
+
+#define MPX_RT_OUT "CHKP_RT_OUT_FILE"
+#define MPX_RT_ERR "CHKP_RT_ERR_FILE"
+#define MPX_RT_VERBOSE "CHKP_RT_VERBOSE"
+#define MPX_RT_VERBOSE_DEFAULT VERB_BR
+#define MPX_RT_MODE "CHKP_RT_MODE"
+#define MPX_RT_MODE_DEFAULT MPX_RT_COUNT
+#define MPX_RT_MODE_DEFAULT_STR "count"
+#define MPX_RT_HELP "CHKP_RT_HELP"
+#define MPX_RT_ADDPID "CHKP_RT_ADDPID"
+#define MPX_RT_BNDPRESERVE "CHKP_RT_BNDPRESERVE"
+#define MPX_RT_BNDPRESERVE_DEFAULT 0
+#define MPX_RT_PRINT_SUMMARY "CHKP_RT_PRINT_SUMMARY"
+
+#define MAX_FILE_NAME PATH_MAX
+
+typedef struct env_var_s {
+ char *env_name;
+ char *env_val;
+ struct env_var_s *next;
+} env_var_t;
+
+typedef struct {
+ env_var_t *first;
+ env_var_t *last;
+} env_var_list_t;
+
+/* Following vars are initialized at process startup only
+ and thus are considered to be thread safe. */
+static int summary;
+static int add_pid;
+static mpx_rt_mode_t mode;
+static env_var_list_t env_var_list;
+static verbose_type verbose_val;
+static FILE *out;
+static FILE *err;
+static char out_name[MAX_FILE_NAME];
+static char err_name[MAX_FILE_NAME];
+
+/* Following vars are read at process finalization only.
+ All write accesses use the same value and thus are
+ considered to be thread safe. */
+static int out_file_dirty;
+static int err_file_dirty;
+static int files_overwritten;
+
+/* Mutex used to sync output. */
+static pthread_mutex_t lock;
+
+static void *
+malloc_check (size_t size)
+{
+ void *res = malloc (size);
+ if (!res)
+ __mpxrt_print (VERB_ERROR, "Couldn't allocate %zu bytes.", size);
+ else
+ memset (res, 0, size);
+ return res;
+}
+
+static void
+env_var_list_add (const char* env, const char* val)
+{
+ env_var_t* n;
+
+ if (val == 0)
+ return;
+
+ n = (env_var_t *)malloc_check (sizeof (env_var_t));
+ if (!n)
+ return;
+
+ if (env_var_list.first == 0)
+ env_var_list.first = n;
+
+ if (env_var_list.last)
+ env_var_list.last->next = n;
+
+ env_var_list.last = n;
+
+ n->env_name = (char *)malloc_check (strlen (env) + 1);
+ n->env_val = (char *)malloc_check (strlen (val) + 1);
+
+ if (!n->env_name || !n->env_val)
+ return;
+
+ strcpy (n->env_name, env);
+ strcpy (n->env_val, val);
+}
+
+static void
+set_file_stream (FILE** file, char* file_name,
+ const char* env, FILE* deflt)
+{
+ int pid;
+ if (env != 0)
+ {
+ if (add_pid)
+ {
+ pid = getpid ();
+ snprintf (file_name, MAX_FILE_NAME, "%s.%d", env, pid);
+ }
+ else
+ snprintf (file_name, MAX_FILE_NAME, "%s", env);
+
+ *file = fopen (file_name, "we");
+ if (*file != 0)
+ return;
+ }
+ *file = deflt;
+}
+
+/*
+ * this function will be called after fork in the child
+ * open new files with pid of the process
+ */
+static void
+open_child_files ()
+{
+ char *out_env;
+ char *err_env;
+
+ out_env = secure_getenv (MPX_RT_OUT);
+ err_env = secure_getenv (MPX_RT_ERR);
+
+ if (add_pid == 0 && (out_env != 0 || err_env != 0))
+ {
+ __mpxrt_print (VERB_ERROR, "MPX RUNTIME WARNING: out/err files are "
+ "overwritten in new processes since %s was not set.\n",
+ MPX_RT_ADDPID);
+ files_overwritten = 1;
+ }
+
+ set_file_stream (&out, out_name, out_env, stdout);
+ if (out_env == 0 || err_env == 0 || (strcmp (out_env, err_env) != 0))
+ set_file_stream (&err, err_name, err_env, stderr);
+ else
+ /* in case we get the same file name for err and out */
+ err = out;
+}
+
+/*
+ * this function is called after fork in the parent
+ */
+static void
+at_fork_check (void)
+{
+ char *out_env;
+ char *err_env;
+
+ out_env = secure_getenv (MPX_RT_OUT);
+ err_env = secure_getenv (MPX_RT_ERR);
+
+ if (add_pid == 0 && (out_env != 0 || err_env != 0))
+ files_overwritten = 1;
+}
+
+static mpx_rt_mode_t
+set_mpx_rt_mode (const char *env)
+{
+ if (env == 0)
+ return MPX_RT_MODE_DEFAULT;
+ else if (strcmp (env, "stop") == 0)
+ return MPX_RT_STOP;
+ else if (strcmp (env,"count") == 0)
+ return MPX_RT_COUNT;
+ {
+ __mpxrt_print (VERB_ERROR, "Illegal value '%s' for %s. Legal values are"
+ "[stop | count]\nUsing default value %s\n",
+ env, MPX_RT_MODE, MPX_RT_MODE_DEFAULT_STR);
+ return MPX_RT_MODE_DEFAULT;
+ }
+}
+
+static void
+print_help (void)
+{
+ fprintf (out, "MPX Runtime environment variables help.\n");
+
+ fprintf (out, "%s \t set output file for info & debug [default: stdout]\n",
+ MPX_RT_OUT);
+ fprintf (out, "%s \t set output file for error [default: stderr]\n",
+ MPX_RT_ERR);
+ fprintf (out, "%s \t set verbosity type [default: %d]\n"
+ "\t\t\t 0 - print only internal run time errors\n"
+ "\t\t\t 1 - just print summary\n"
+ "\t\t\t 2 - print summary and bound violation information\n "
+ "\t\t\t 3 - print debug information\n",
+ MPX_RT_VERBOSE, MPX_RT_VERBOSE_DEFAULT);
+ fprintf (out, "%s \t\t set MPX runtime behavior on #BR exception."
+ " [stop | count]\n"
+ "\t\t\t [default: %s]\n", MPX_RT_MODE, MPX_RT_MODE_DEFAULT_STR);
+ fprintf (out, "%s \t\t generate out,err file for each process.\n"
+ "\t\t\t generated file will be MPX_RT_{OUT,ERR}_FILE.pid\n"
+ "\t\t\t [default: no]\n", MPX_RT_ADDPID);
+ fprintf (out, "%s \t set value for BNDPRESERVE bit.\n"
+ "\t\t\t BNDPRESERVE = 0 flush bounds on unprefixed call/ret/jmp\n"
+ "\t\t\t BNDPRESERVE = 1 do NOT flush bounds\n"
+ "\t\t\t [default: %d]\n", MPX_RT_BNDPRESERVE,
+ MPX_RT_BNDPRESERVE_DEFAULT);
+ fprintf (out, "%s \t print summary at the end of the run\n"
+ "\t\t\t [default: no]\n", MPX_RT_PRINT_SUMMARY);
+
+ fprintf (out, "%s \t\t print this help and exit.\n"
+ "\t\t\t [default: no]\n", MPX_RT_HELP);
+
+ exit (0);
+}
+
+static void
+validate_bndpreserve (const char *env, int *bndpreserve)
+{
+ if (env == 0)
+ bndpreserve = MPX_RT_BNDPRESERVE_DEFAULT;
+ else if (strcmp (env, "0") == 0)
+ *bndpreserve = 0;
+ else if (strcmp (env, "1") == 0)
+ *bndpreserve = 1;
+ else
+ {
+ __mpxrt_print (VERB_ERROR, "Illegal value '%s' for %s. Legal values "
+ "are [0 | 1]\nUsing default value %d\n",
+ env, MPX_RT_BNDPRESERVE, MPX_RT_BNDPRESERVE_DEFAULT);
+ *bndpreserve = MPX_RT_BNDPRESERVE_DEFAULT;
+ }
+}
+
+static verbose_type
+init_verbose_val (const char *env)
+{
+ if (env == 0)
+ return MPX_RT_VERBOSE_DEFAULT;
+ else if (strcmp(env, "0") == 0)
+ return VERB_ERROR;
+ else if (strcmp(env, "1") == 0)
+ return VERB_INFO;
+ else if (strcmp(env, "2") == 0)
+ return VERB_BR;
+ else if (strcmp(env, "3") == 0)
+ return VERB_DEBUG;
+
+ __mpxrt_print (VERB_ERROR, "Illegal value '%s' for %s. Legal values "
+ "are [0..3]\nUsing default value %d\n",
+ env, MPX_RT_VERBOSE, (int)MPX_RT_VERBOSE_DEFAULT);
+
+ return MPX_RT_VERBOSE_DEFAULT;
+}
+
+static void
+env_var_print_summary (void)
+{
+ env_var_t* node;
+
+ __mpxrt_print (VERB_DEBUG, "Used environment variables:\n");
+
+ node = env_var_list.first;
+ while (node != 0)
+ {
+ __mpxrt_print (VERB_DEBUG, " %s = %s\n", node->env_name, node->env_val);
+ node = node->next;
+ }
+}
+
+/* Return 1 if passes env var value should enable feature. */
+
+static int
+check_yes (const char *val)
+{
+ return val && (!strcmp (val, "yes") || !strcmp (val, "1"));
+}
+
+void
+__mpxrt_init_env_vars (int* bndpreserve)
+{
+ char *out_env;
+ char *err_env;
+ char *env;
+
+ pthread_mutex_init (&lock, NULL);
+
+ out_env = secure_getenv (MPX_RT_OUT);
+ env_var_list_add (MPX_RT_OUT, out_env);
+
+ err_env = secure_getenv (MPX_RT_ERR);
+ env_var_list_add (MPX_RT_ERR, err_env);
+
+ env = secure_getenv (MPX_RT_ADDPID);
+ env_var_list_add (MPX_RT_ADDPID, env);
+ add_pid = check_yes (env);
+
+ set_file_stream (&out, out_name, out_env, stdout);
+ if (out_env == 0 || err_env == 0 || (strcmp (out_env, err_env) != 0))
+ set_file_stream (&err, err_name, err_env, stderr);
+ else
+ /* in case we get the same file name for err and out */
+ err = out;
+
+ env = secure_getenv (MPX_RT_VERBOSE);
+ env_var_list_add (MPX_RT_VERBOSE, env);
+ verbose_val = init_verbose_val (env);
+
+ env = secure_getenv (MPX_RT_MODE);
+ env_var_list_add (MPX_RT_MODE, env);
+ mode = set_mpx_rt_mode (env);
+
+ env = secure_getenv (MPX_RT_BNDPRESERVE);
+ env_var_list_add (MPX_RT_BNDPRESERVE, env);
+ validate_bndpreserve (env, bndpreserve);
+
+ env = secure_getenv (MPX_RT_PRINT_SUMMARY);
+ env_var_list_add (MPX_RT_PRINT_SUMMARY, env);
+ summary = check_yes (env);
+
+ env = secure_getenv (MPX_RT_HELP);
+ if (check_yes (env))
+ print_help ();
+
+ /*
+ * at fork - create new files for output and err according
+ * to the env vars.
+ */
+ pthread_atfork (NULL, at_fork_check, open_child_files);
+
+ env_var_print_summary ();
+}
+
+void
+__mpxrt_utils_free (void)
+{
+ if (files_overwritten)
+ __mpxrt_print (VERB_INFO, "\nMPX RUNTIME WARNING: out/err files are"
+ " overwritten in new processes since %s was not set.\n",
+ MPX_RT_ADDPID);
+
+ if (out != stdout)
+ {
+ fclose (out);
+ if (out_file_dirty != 1)
+ remove (out_name);
+ }
+
+ if (err != stderr)
+ {
+ fclose (err);
+ if (err_file_dirty != 1)
+ remove (err_name);
+ }
+
+ pthread_mutex_destroy (&lock);
+}
+
+void
+__mpxrt_write_uint (verbose_type vt, uint64_t val, unsigned base)
+{
+ static const char digits[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+ char str[65];
+ int pos = 64;;
+
+ str[pos--] = 0;
+
+ if (vt > verbose_val || base <= 1 || base > sizeof (digits))
+ return;
+
+ if (val < base)
+ str[pos--] = digits[val];
+ else
+ while (val)
+ {
+ str[pos--] = digits[val % base];
+ val = val / base;
+ }
+
+ __mpxrt_write (vt, str + pos + 1);
+}
+
+void
+__mpxrt_write (verbose_type vt, const char* str)
+{
+ va_list argp;
+ FILE *print_to;
+
+ if (vt > verbose_val)
+ return;
+
+ if (vt == VERB_ERROR)
+ {
+ print_to = err;
+ err_file_dirty = 1;
+ }
+ else
+ {
+ print_to = out;
+ out_file_dirty = 1;
+ }
+ pthread_mutex_lock (&lock);
+ write (fileno (print_to), str, strlen (str));
+ pthread_mutex_unlock (&lock);
+ va_end (argp);
+}
+
+void
+__mpxrt_print (verbose_type vt, const char* frmt, ...)
+{
+ va_list argp;
+ FILE *print_to;
+
+ if (vt > verbose_val)
+ return;
+
+ va_start (argp, frmt);
+ if (vt == VERB_ERROR)
+ {
+ print_to = err;
+ err_file_dirty = 1;
+ }
+ else
+ {
+ print_to = out;
+ out_file_dirty = 1;
+ }
+ pthread_mutex_lock (&lock);
+ vfprintf (print_to, frmt, argp);
+ fflush (print_to);
+ pthread_mutex_unlock (&lock);
+ va_end (argp);
+}
+
+mpx_rt_mode_t
+__mpxrt_mode (void)
+{
+ return mode;
+}
+
+void
+__mpxrt_print_summary (uint64_t num_brs, uint64_t l1_size)
+{
+
+ if (summary == 0)
+ return;
+
+ out_file_dirty = 1;
+
+ pthread_mutex_lock (&lock);
+ fprintf (out, "MPX runtime summary:\n");
+ fprintf (out, " Number of bounds violations: %" PRIu64 ".\n", num_brs);
+ fprintf (out, " Size of allocated L1: %" PRIu64 "B\n", l1_size);
+ fflush (out);
+ pthread_mutex_unlock (&lock);
+}
diff --git a/libmpx/mpxrt/mpxrt-utils.h b/libmpx/mpxrt/mpxrt-utils.h
new file mode 100644
index 0000000..d62937d
--- /dev/null
+++ b/libmpx/mpxrt/mpxrt-utils.h
@@ -0,0 +1,65 @@
+/* mpxrt-utils.h -*-C++-*-
+ *
+ *************************************************************************
+ *
+ * @copyright
+ * Copyright (C) 2014, Intel Corporation
+ * All rights reserved.
+ *
+ * @copyright
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * @copyright
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+ * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ **************************************************************************/
+
+#ifndef MPXRT_UTILS_H
+#define MPXRT_UTILS_H
+
+#include <stdint.h>
+
+typedef enum {
+ VERB_ERROR,
+ VERB_INFO,
+ VERB_BR,
+ VERB_DEBUG
+} verbose_type;
+
+typedef enum {
+ MPX_RT_COUNT,
+ MPX_RT_STOP
+} mpx_rt_mode_t;
+
+void __mpxrt_init_env_vars (int* bndpreserve);
+void __mpxrt_write_uint (verbose_type vt, uint64_t val, unsigned base);
+void __mpxrt_write (verbose_type vt, const char* str);
+void __mpxrt_print (verbose_type vt, const char* frmt, ...);
+mpx_rt_mode_t __mpxrt_mode (void);
+void __mpxrt_utils_free (void);
+void __mpxrt_print_summary (uint64_t num_brs, uint64_t l1_size);
+
+#endif /* MPXRT_UTILS_H */
diff --git a/libmpx/mpxrt/mpxrt.c b/libmpx/mpxrt/mpxrt.c
new file mode 100644
index 0000000..0eff87e
--- /dev/null
+++ b/libmpx/mpxrt/mpxrt.c
@@ -0,0 +1,515 @@
+/* mpxrt.c -*-C++-*-
+ *
+ *************************************************************************
+ *
+ * @copyright
+ * Copyright (C) 2014, Intel Corporation
+ * All rights reserved.
+ *
+ * @copyright
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * @copyright
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
+ * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ **************************************************************************/
+
+#define __STDC_FORMAT_MACROS
+#include "config.h"
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <signal.h>
+#include <assert.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/prctl.h>
+#include <cpuid.h>
+#include "mpxrt-utils.h"
+
+#ifdef __i386__
+
+/* i386 directory size is 4MB */
+#define NUM_L1_BITS 20
+
+#define REG_IP_IDX REG_EIP
+#define REX_PREFIX
+
+#define XSAVE_OFFSET_IN_FPMEM sizeof (struct _libc_fpstate)
+
+#else /* __i386__ */
+
+/* x86_64 directory size is 2GB */
+#define NUM_L1_BITS 28
+
+#define REG_IP_IDX REG_RIP
+#define REX_PREFIX "0x48, "
+
+#define XSAVE_OFFSET_IN_FPMEM 0
+
+#endif /* !__i386__ */
+
+#define MPX_ENABLE_BIT_NO 0
+#define BNDPRESERVE_BIT_NO 1
+
+const size_t MPX_L1_SIZE = (1UL << NUM_L1_BITS) * sizeof (void *);
+
+struct xsave_hdr_struct
+{
+ uint64_t xstate_bv;
+ uint64_t reserved1[2];
+ uint64_t reserved2[5];
+} __attribute__ ((packed));
+
+struct bndregs_struct
+{
+ uint64_t bndregs[8];
+} __attribute__ ((packed));
+
+struct bndcsr_struct {
+ uint64_t cfg_reg_u;
+ uint64_t status_reg;
+} __attribute__((packed));
+
+struct xsave_struct
+{
+ uint8_t fpu_sse[512];
+ struct xsave_hdr_struct xsave_hdr;
+ uint8_t ymm[256];
+ uint8_t lwp[128];
+ struct bndregs_struct bndregs;
+ struct bndcsr_struct bndcsr;
+} __attribute__ ((packed));
+
+/* Following vars are initialized at process startup only
+ and thus are considered to be thread safe. */
+static void *l1base = NULL;
+static int bndpreserve;
+static int enable = 1;
+
+/* Var holding number of occured BRs. It is modified from
+ signal handler only and thus it should be thread safe. */
+static uint64_t num_bnd_chk = 0;
+
+static inline void
+xrstor_state (struct xsave_struct *fx, uint64_t mask)
+{
+ uint32_t lmask = mask;
+ uint32_t hmask = mask >> 32;
+
+ asm volatile (".byte " REX_PREFIX "0x0f,0xae,0x2f\n\t"
+ : : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
+ : "memory");
+}
+
+static inline void
+xsave_state (struct xsave_struct *fx, uint64_t mask)
+{
+ uint32_t lmask = mask;
+ uint32_t hmask = mask >> 32;
+
+ asm volatile (".byte " REX_PREFIX "0x0f,0xae,0x27\n\t"
+ : : "D" (fx), "m" (*fx), "a" (lmask), "d" (hmask)
+ : "memory");
+}
+
+static inline uint64_t
+xgetbv (uint32_t index)
+{
+ uint32_t eax, edx;
+
+ asm volatile (".byte 0x0f,0x01,0xd0" /* xgetbv */
+ : "=a" (eax), "=d" (edx)
+ : "c" (index));
+ return eax + ((uint64_t)edx << 32);
+}
+
+static uint64_t
+read_mpx_status_sig (ucontext_t *uctxt)
+{
+ uint8_t __attribute__ ((__aligned__ (64))) buffer[4096];
+ struct xsave_struct *xsave_buf = (struct xsave_struct *)buffer;
+
+ memset (buffer, 0, sizeof (buffer));
+ memcpy (buffer,
+ (uint8_t *)uctxt->uc_mcontext.fpregs + XSAVE_OFFSET_IN_FPMEM,
+ sizeof (struct xsave_struct));
+ return xsave_buf->bndcsr.status_reg;
+}
+
+static uint8_t *
+get_next_inst_ip (uint8_t *addr)
+{
+ uint8_t *ip = addr;
+ uint8_t sib;
+
+ /* Determine the prefix. */
+ switch (*ip)
+ {
+ case 0xf2:
+ case 0xf3:
+ case 0x66:
+ ip++;
+ break;
+ }
+
+ /* Look for rex prefix. */
+ if ((*ip & 0x40) == 0x40)
+ ip++;
+
+ /* Make sure we have a MPX instruction. */
+ if (*ip++ != 0x0f)
+ return addr;
+
+ /* Skip the op code byte. */
+ ip++;
+
+ /* Get the moderm byte. */
+ uint8_t modrm = *ip++;
+
+ /* Break it down into parts. */
+ uint8_t rm = modrm & 7;
+ uint8_t mod = (modrm >> 6);
+
+ /* Init the parts of the address mode. */
+ uint8_t base = 8;
+
+ /* Is it a mem mode? */
+ if (mod != 3)
+ {
+ /* Look for scaled indexed addressing. */
+ if (rm == 4)
+ {
+ /* SIB addressing. */
+ sib = *ip++;
+ base = sib & 7;
+ switch (mod)
+ {
+ case 0:
+ if (base == 5)
+ ip += 4;
+ break;
+
+ case 1:
+ ip++;
+ break;
+
+ case 2:
+ ip += 4;
+ break;
+ }
+ }
+ else
+ {
+ /* MODRM addressing. */
+ switch (mod)
+ {
+ case 0:
+ if (rm == 5)
+ /* DISP32 addressing, no base. */
+ ip += 4;
+ break;
+
+ case 1:
+ ip++;
+ break;
+
+ case 2:
+ ip += 4;
+ break;
+ }
+ }
+ }
+ return ip;
+}
+
+static void
+handler (int sig __attribute__ ((unused)),
+ siginfo_t *info __attribute__ ((unused)),
+ void *vucontext,
+ struct xsave_struct *buf __attribute__ ((unused)))
+{
+ ucontext_t* uctxt;
+ greg_t trapno;
+ greg_t ip;
+
+ uctxt = vucontext;
+ trapno = uctxt->uc_mcontext.gregs[REG_TRAPNO];
+ ip = uctxt->uc_mcontext.gregs[REG_IP_IDX];
+
+ if (trapno == 5)
+ {
+ uint64_t status = read_mpx_status_sig (uctxt);
+ uint64_t br_reason = status & 0x3;
+
+ __mpxrt_write (VERB_BR, "Saw a #BR! status ");
+ __mpxrt_write_uint (VERB_BR, status, 10);
+ __mpxrt_write (VERB_BR, " at 0x");
+ __mpxrt_write_uint (VERB_BR, ip, 16);
+ __mpxrt_write (VERB_BR, "\n");
+
+ switch (br_reason)
+ {
+ case 1: /* traditional BR */
+ num_bnd_chk++;
+ uctxt->uc_mcontext.gregs[REG_IP_IDX] =
+ (greg_t)get_next_inst_ip ((uint8_t *)ip);
+ if (__mpxrt_mode () == MPX_RT_STOP)
+ exit (255);
+ return;
+
+ default:
+ __mpxrt_write (VERB_BR, "Unexpected status with bound exception: ");
+ __mpxrt_write_uint (VERB_BR, status, 10);
+ __mpxrt_write (VERB_BR, "\n");
+ break;
+ }
+ }
+ else if (trapno == 14)
+ {
+ __mpxrt_write (VERB_ERROR, "In signal handler, trapno = ");
+ __mpxrt_write_uint (VERB_ERROR, trapno, 10);
+ __mpxrt_write (VERB_ERROR, ", ip = 0x");
+ __mpxrt_write_uint (VERB_ERROR, ip, 16);
+ __mpxrt_write (VERB_BR, "\n");
+ exit (255);
+ }
+ else
+ {
+ __mpxrt_write (VERB_ERROR, "Unexpected trap ");
+ __mpxrt_write_uint (VERB_ERROR, trapno, 10);
+ __mpxrt_write (VERB_ERROR, "! at 0x");
+ __mpxrt_write_uint (VERB_ERROR, ip, 16);
+ __mpxrt_write (VERB_BR, "\n");
+ exit (255);
+ }
+}
+
+/* Using wrapper to the real handler in order to save the bnd regs
+ using xsave before any unprefixed call. an unprefixed call to
+ __i686.get_pc_thunk.bx is added by the linker in 32bit at the
+ beginning of handler function since there are references to
+ global variables. */
+static void
+handler_wrap (int signum, siginfo_t* si, void* vucontext)
+{
+ /* Since the OS currently not handling chkptr regs.
+ We need to store them for later use. They might be
+ init due to unprefixed call,Jcc,ret. avoiding calling
+ function since the function will be unprefixed as well. */
+ uint8_t __attribute__ ((__aligned__ (64))) buffer[4096];
+ struct xsave_struct *xsave_buf = (struct xsave_struct *)buffer;
+ uint64_t mask = 0x18;
+ uint32_t lmask = mask;
+ uint32_t hmask = mask >> 32;
+
+ asm volatile (".byte " REX_PREFIX "0x0f,0xae,0x27\n\t"
+ : : "D" (xsave_buf), "m" (*xsave_buf),
+ "a" (lmask), "d" (hmask)
+ : "memory");
+
+ handler (signum, si, vucontext, xsave_buf);
+}
+
+static bool
+check_mpx_support (void)
+{
+ unsigned int eax, ebx, ecx, edx;
+ unsigned int max_level = __get_cpuid_max (0, NULL);
+
+ if (max_level < 13)
+ {
+ __mpxrt_print (VERB_DEBUG, "No required CPUID level support.\n");
+ return false;
+ }
+
+ __cpuid_count (0, 0, eax, ebx, ecx, edx);
+ if (!(ecx & bit_XSAVE))
+ {
+ __mpxrt_print (VERB_DEBUG, "No XSAVE support.\n");
+ return false;
+ }
+
+ if (!(ecx & bit_OSXSAVE))
+ {
+ __mpxrt_print (VERB_DEBUG, "No OSXSAVE support.\n");
+ return false;
+ }
+
+ __cpuid_count (7, 0, eax, ebx, ecx, edx);
+ if (!(ebx & bit_MPX))
+ {
+ __mpxrt_print (VERB_DEBUG, "No MPX support.\n");
+ return false;
+ }
+
+ __cpuid_count (13, 0, eax, ebx, ecx, edx);
+ if (!(eax & bit_BNDREGS))
+ {
+ __mpxrt_print (VERB_DEBUG, "No BNDREGS support.\n");
+ return false;
+ }
+
+ if (!(eax & bit_BNDCSR))
+ {
+ __mpxrt_print (VERB_DEBUG, "No BNDCSR support.\n");
+ return false;
+ }
+
+ return true;
+}
+
+static void
+enable_mpx (void)
+{
+ uint8_t __attribute__ ((__aligned__ (64))) buffer[4096];
+ struct xsave_struct *xsave_buf = (struct xsave_struct *)buffer;
+
+ memset (buffer, 0, sizeof (buffer));
+ xrstor_state (xsave_buf, 0x18);
+
+ __mpxrt_print (VERB_DEBUG, "Initalizing MPX...\n");
+ __mpxrt_print (VERB_DEBUG, " Enable bit: %d\n", enable);
+ __mpxrt_print (VERB_DEBUG, " BNDPRESERVE bit: %d\n", bndpreserve);
+
+ /* Enable MPX. */
+ xsave_buf->xsave_hdr.xstate_bv = 0x10;
+ xsave_buf->bndcsr.cfg_reg_u = (unsigned long)l1base;
+ xsave_buf->bndcsr.cfg_reg_u |= enable << MPX_ENABLE_BIT_NO;
+ xsave_buf->bndcsr.cfg_reg_u |= bndpreserve << BNDPRESERVE_BIT_NO;
+ xsave_buf->bndcsr.status_reg = 0;
+
+ xrstor_state (xsave_buf, 0x10);
+}
+
+static void
+disable_mpx (void)
+{
+ uint8_t __attribute__ ((__aligned__ (64))) buffer[4096];
+ struct xsave_struct *xsave_buf = (struct xsave_struct *)buffer;
+
+ memset(buffer, 0, sizeof(buffer));
+ xrstor_state(xsave_buf, 0x18);
+
+ /* Disable MPX. */
+ xsave_buf->xsave_hdr.xstate_bv = 0x10;
+ xsave_buf->bndcsr.cfg_reg_u = 0;
+ xsave_buf->bndcsr.status_reg = 0;
+
+ xrstor_state(xsave_buf, 0x10);
+}
+
+static bool
+process_specific_init (void)
+{
+ if (!check_mpx_support ())
+ return false;
+
+ l1base = mmap (NULL, MPX_L1_SIZE, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (l1base == MAP_FAILED)
+ {
+ perror ("mmap");
+ exit (EXIT_FAILURE);
+ }
+
+ enable_mpx ();
+
+ if (prctl (43, 0, 0, 0, 0))
+ {
+ __mpxrt_print (VERB_ERROR, "No MPX support\n");
+ disable_mpx ();
+ return false;
+ }
+
+ return true;
+}
+
+static bool
+process_specific_finish (void)
+{
+ if (!check_mpx_support ())
+ return false;
+
+ if (prctl (44, 0, 0, 0, 0))
+ {
+ __mpxrt_print (VERB_ERROR, "No MPX support\n");
+ return false;
+ }
+
+ munmap (l1base, MPX_L1_SIZE);
+
+ return true;
+}
+
+static void
+setup_handler (void)
+{
+ int r,rs;
+ struct sigaction newact;
+
+ /* #BR is mapped to sigsegv */
+ int signum = SIGSEGV;
+
+ newact.sa_handler = 0;
+ newact.sa_sigaction = handler_wrap;
+
+ /* sigset_t - signals to block while in the handler
+ get the old signal mask. */
+ rs = sigprocmask (SIG_SETMASK, 0, &newact.sa_mask);
+ assert (rs == 0);
+
+ /* Call sa_sigaction, not sa_handler. */
+ newact.sa_flags = SA_SIGINFO;
+ /* In case we call user's handler on SIGSEGV (not bound
+ violation exception) we want to allow bound checking
+ inside the user handler -> nested exception. */
+ newact.sa_flags |= SA_NODEFER;
+
+ newact.sa_restorer = 0;
+ r = sigaction (signum, &newact, 0);
+ assert (r == 0);
+}
+
+/* Set constructor priority to two to make it run after the
+ constructor in sigaction.c. */
+static void __attribute__ ((constructor (1005)))
+mpxrt_prepare (void)
+{
+ __mpxrt_init_env_vars (&bndpreserve);
+ setup_handler ();
+ process_specific_init ();
+}
+
+static void __attribute__ ((destructor))
+mpxrt_cleanup (void)
+{
+ __mpxrt_print_summary (num_bnd_chk, MPX_L1_SIZE);
+ __mpxrt_utils_free ();
+ process_specific_finish ();
+}