Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
riscv-gcc-1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
riscv-gcc-1
Commits
f246eadc
Commit
f246eadc
authored
Nov 24, 2012
by
Jack Howarth
Committed by
Kostya Serebryany
Nov 24, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[libsanitizer] add mach_override and enable libsanitizer on darwin
From-SVN: r193781
parent
9f1b2dcb
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
246 additions
and
6 deletions
+246
-6
gcc/ChangeLog
+4
-0
gcc/config/darwin.h
+3
-0
libsanitizer/ChangeLog
+13
-0
libsanitizer/configure
+21
-2
libsanitizer/configure.ac
+6
-0
libsanitizer/configure.tgt
+3
-0
libsanitizer/interception/Makefile.am
+4
-0
libsanitizer/interception/Makefile.in
+49
-4
libsanitizer/interception/mach_override/LICENSE.txt
+3
-0
libsanitizer/interception/mach_override/mach_override.c
+0
-0
libsanitizer/interception/mach_override/mach_override.h
+140
-0
No files found.
gcc/ChangeLog
View file @
f246eadc
2012
-
11
-
24
Jack
Howarth
<
howarth
@bromo
.
med
.
uc
.
edu
>
*
config
/
darwin
.
h
(
LINK_COMMAND_SPEC_A
)
:
Deal
with
-
fsanitize
=
address
.
2012
-
11
-
24
Matthias
Klose
<
doko
@ubuntu
.
com
>
2012
-
11
-
24
Matthias
Klose
<
doko
@ubuntu
.
com
>
*
configure
.
ac
(
multiarch
)
:
Use
$
enableval
instead
of
$
withval
.
*
configure
.
ac
(
multiarch
)
:
Use
$
enableval
instead
of
$
withval
.
gcc/config/darwin.h
View file @
f246eadc
...
@@ -180,6 +180,9 @@ extern GTY(()) int darwin_ms_struct;
...
@@ -180,6 +180,9 @@ extern GTY(()) int darwin_ms_struct;
%{L*} %(link_libgcc) %o %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \
%{L*} %(link_libgcc) %o %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} \
%{fopenmp|ftree-parallelize-loops=*: \
%{fopenmp|ftree-parallelize-loops=*: \
%{static|static-libgcc|static-libstdc++|static-libgfortran: libgomp.a%s; : -lgomp } } \
%{static|static-libgcc|static-libstdc++|static-libgfortran: libgomp.a%s; : -lgomp } } \
%{fsanitize=address: \
%{static|static-libasan|static-libgcc|static-libgfortran: -framework CoreFoundation -lstdc++ libasan.a%s; \
static-libstdc++: -framework CoreFoundation libstdc++.a%s libasan.a%s; : -framework CoreFoundation -lasan } } \
%{fgnu-tm: \
%{fgnu-tm: \
%{static|static-libgcc|static-libstdc++|static-libgfortran: libitm.a%s; : -litm } } \
%{static|static-libgcc|static-libstdc++|static-libgfortran: libitm.a%s; : -litm } } \
%{!nostdlib:%{!nodefaultlibs:\
%{!nostdlib:%{!nodefaultlibs:\
...
...
libsanitizer/ChangeLog
View file @
f246eadc
2012-11-24 Kostya Serebryany kcc@google.com
Jack Howarth <howarth@bromo.med.uc.edu>
* interception/mach_override/mach_override.c: Migrate from llvm.
* interception/mach_override/mach_override.h: Likewise.
* interception/mach_override/LICENSE.txt: Likewise.
* configure.tgt: Add darwin to supported targets.
* configure.ac: Define USING_MACH_OVERRIDE when on darwin.
* interception/Makefile.am: Compile mach_override.c when
USING_MACH_OVERRIDE defined.
* configure: Regenerated.
* interception/Makefile.in: Likewise.
2012-11-23 H.J. Lu <hongjiu.lu@intel.com>
2012-11-23 H.J. Lu <hongjiu.lu@intel.com>
PR sanitizer/55450
PR sanitizer/55450
...
...
libsanitizer/configure
View file @
f246eadc
...
@@ -604,6 +604,8 @@ ac_subst_vars='am__EXEEXT_FALSE
...
@@ -604,6 +604,8 @@ ac_subst_vars='am__EXEEXT_FALSE
am__EXEEXT_TRUE
am__EXEEXT_TRUE
LTLIBOBJS
LTLIBOBJS
LIBOBJS
LIBOBJS
USING_MACH_OVERRIDE_FALSE
USING_MACH_OVERRIDE_TRUE
TSAN_SUPPORTED_FALSE
TSAN_SUPPORTED_FALSE
TSAN_SUPPORTED_TRUE
TSAN_SUPPORTED_TRUE
enable_static
enable_static
...
@@ -11078,7 +11080,7 @@ else
...
@@ -11078,7 +11080,7 @@ else
lt_dlunknown
=
0
;
lt_dlno_uscore
=
1
;
lt_dlneed_uscore
=
2
lt_dlunknown
=
0
;
lt_dlno_uscore
=
1
;
lt_dlneed_uscore
=
2
lt_status
=
$lt_dlunknown
lt_status
=
$lt_dlunknown
cat
>
conftest.
$ac_ext
<<
_LT_EOF
cat
>
conftest.
$ac_ext
<<
_LT_EOF
#line 1108
1
"configure"
#line 1108
3
"configure"
#include "confdefs.h"
#include "confdefs.h"
#if HAVE_DLFCN_H
#if HAVE_DLFCN_H
...
@@ -11184,7 +11186,7 @@ else
...
@@ -11184,7 +11186,7 @@ else
lt_dlunknown
=
0
;
lt_dlno_uscore
=
1
;
lt_dlneed_uscore
=
2
lt_dlunknown
=
0
;
lt_dlno_uscore
=
1
;
lt_dlneed_uscore
=
2
lt_status
=
$lt_dlunknown
lt_status
=
$lt_dlunknown
cat
>
conftest.
$ac_ext
<<
_LT_EOF
cat
>
conftest.
$ac_ext
<<
_LT_EOF
#line 1118
7
"configure"
#line 1118
9
"configure"
#include "confdefs.h"
#include "confdefs.h"
#if HAVE_DLFCN_H
#if HAVE_DLFCN_H
...
@@ -14494,6 +14496,19 @@ else
...
@@ -14494,6 +14496,19 @@ else
fi
fi
case
"
$host
"
in
*
-
*
-darwin
*
)
MACH_OVERRIDE
=
true
;;
*
)
MACH_OVERRIDE
=
false
;;
esac
if
$MACH_OVERRIDE
;
then
USING_MACH_OVERRIDE_TRUE
=
USING_MACH_OVERRIDE_FALSE
=
'#'
else
USING_MACH_OVERRIDE_TRUE
=
'#'
USING_MACH_OVERRIDE_FALSE
=
fi
ac_config_files
=
"
$ac_config_files
Makefile"
ac_config_files
=
"
$ac_config_files
Makefile"
...
@@ -14670,6 +14685,10 @@ if test -z "${TSAN_SUPPORTED_TRUE}" && test -z "${TSAN_SUPPORTED_FALSE}"; then
...
@@ -14670,6 +14685,10 @@ if test -z "${TSAN_SUPPORTED_TRUE}" && test -z "${TSAN_SUPPORTED_FALSE}"; then
as_fn_error
"conditional
\"
TSAN_SUPPORTED
\"
was never defined.
as_fn_error
"conditional
\"
TSAN_SUPPORTED
\"
was never defined.
Usually this means the macro was only invoked conditionally."
"
$LINENO
"
5
Usually this means the macro was only invoked conditionally."
"
$LINENO
"
5
fi
fi
if
test
-z
"
${
USING_MACH_OVERRIDE_TRUE
}
"
&&
test
-z
"
${
USING_MACH_OVERRIDE_FALSE
}
"
;
then
as_fn_error
"conditional
\"
USING_MACH_OVERRIDE
\"
was never defined.
Usually this means the macro was only invoked conditionally."
"
$LINENO
"
5
fi
:
${
CONFIG_STATUS
=./config.status
}
:
${
CONFIG_STATUS
=./config.status
}
ac_write_fail
=
0
ac_write_fail
=
0
...
...
libsanitizer/configure.ac
View file @
f246eadc
...
@@ -80,6 +80,12 @@ unset TSAN_SUPPORTED
...
@@ -80,6 +80,12 @@ unset TSAN_SUPPORTED
. ${srcdir}/configure.tgt
. ${srcdir}/configure.tgt
AM_CONDITIONAL(TSAN_SUPPORTED, [test "x$TSAN_SUPPORTED" = "xyes"])
AM_CONDITIONAL(TSAN_SUPPORTED, [test "x$TSAN_SUPPORTED" = "xyes"])
case "$host" in
*-*-darwin*) MACH_OVERRIDE=true ;;
*) MACH_OVERRIDE=false ;;
esac
AM_CONDITIONAL(USING_MACH_OVERRIDE, $MACH_OVERRIDE)
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES(AC_FOREACH([DIR], [interception sanitizer_common asan], [DIR/Makefile ]),
AC_CONFIG_FILES(AC_FOREACH([DIR], [interception sanitizer_common asan], [DIR/Makefile ]),
...
...
libsanitizer/configure.tgt
View file @
f246eadc
...
@@ -27,6 +27,9 @@ case "${target}" in
...
@@ -27,6 +27,9 @@ case "${target}" in
;;
;;
sparc*-*-linux*)
sparc*-*-linux*)
;;
;;
x86_64-*-darwin* | i?86-*-darwin*)
TSAN_SUPPORTED=no
;;
*)
*)
UNSUPPORTED=1
UNSUPPORTED=1
;;
;;
...
...
libsanitizer/interception/Makefile.am
View file @
f246eadc
...
@@ -14,7 +14,11 @@ interception_files = \
...
@@ -14,7 +14,11 @@ interception_files = \
interception_mac.cc
\
interception_mac.cc
\
interception_win.cc
interception_win.cc
if
USING_MACH_OVERRIDE
libinterception_la_SOURCES
=
$(interception_files)
mach_override/mach_override.c
else
libinterception_la_SOURCES
=
$(interception_files)
libinterception_la_SOURCES
=
$(interception_files)
endif
# Work around what appears to be a GNU make bug handling MAKEFLAGS
# 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
# values defined in terms of make variables, as is the case for CC and
...
...
libsanitizer/interception/Makefile.in
View file @
f246eadc
...
@@ -53,14 +53,29 @@ CONFIG_CLEAN_FILES =
...
@@ -53,14 +53,29 @@ CONFIG_CLEAN_FILES =
CONFIG_CLEAN_VPATH_FILES
=
CONFIG_CLEAN_VPATH_FILES
=
LTLIBRARIES
=
$(noinst_LTLIBRARIES)
LTLIBRARIES
=
$(noinst_LTLIBRARIES)
libinterception_la_LIBADD
=
libinterception_la_LIBADD
=
am__libinterception_la_SOURCES_DIST
=
interception_linux.cc
\
interception_mac.cc interception_win.cc
\
mach_override/mach_override.c
am__objects_1
=
interception_linux.lo interception_mac.lo
\
am__objects_1
=
interception_linux.lo interception_mac.lo
\
interception_win.lo
interception_win.lo
am_libinterception_la_OBJECTS
=
$(am__objects_1)
@USING_MACH_OVERRIDE_FALSE@
am_libinterception_la_OBJECTS
=
\
@USING_MACH_OVERRIDE_FALSE@
$(am__objects_1)
@USING_MACH_OVERRIDE_TRUE@
am_libinterception_la_OBJECTS
=
\
@USING_MACH_OVERRIDE_TRUE@
$(am__objects_1)
mach_override.lo
libinterception_la_OBJECTS
=
$(am_libinterception_la_OBJECTS)
libinterception_la_OBJECTS
=
$(am_libinterception_la_OBJECTS)
DEFAULT_INCLUDES
=
-I
.@am__isrc@
DEFAULT_INCLUDES
=
-I
.@am__isrc@
depcomp
=
$(SHELL)
$(top_srcdir)
/../depcomp
depcomp
=
$(SHELL)
$(top_srcdir)
/../depcomp
am__depfiles_maybe
=
depfiles
am__depfiles_maybe
=
depfiles
am__mv
=
mv
-f
am__mv
=
mv
-f
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
$@
CXXCOMPILE
=
$(CXX)
$(DEFS)
$(DEFAULT_INCLUDES)
$(INCLUDES)
\
CXXCOMPILE
=
$(CXX)
$(DEFS)
$(DEFAULT_INCLUDES)
$(INCLUDES)
\
$(AM_CPPFLAGS)
$(CPPFLAGS)
$(AM_CXXFLAGS)
$(CXXFLAGS)
$(AM_CPPFLAGS)
$(CPPFLAGS)
$(AM_CXXFLAGS)
$(CXXFLAGS)
LTCXXCOMPILE
=
$(LIBTOOL)
--tag
=
CXX
$(AM_LIBTOOLFLAGS)
$(LIBTOOLFLAGS)
\
LTCXXCOMPILE
=
$(LIBTOOL)
--tag
=
CXX
$(AM_LIBTOOLFLAGS)
$(LIBTOOLFLAGS)
\
...
@@ -71,7 +86,7 @@ CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
...
@@ -71,7 +86,7 @@ CXXLINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode
=
link
$(CXXLD)
$(AM_CXXFLAGS)
$(CXXFLAGS)
$(AM_LDFLAGS)
\
--mode
=
link
$(CXXLD)
$(AM_CXXFLAGS)
$(CXXFLAGS)
$(AM_LDFLAGS)
\
$(LDFLAGS)
-o
$@
$(LDFLAGS)
-o
$@
SOURCES
=
$(libinterception_la_SOURCES)
SOURCES
=
$(libinterception_la_SOURCES)
DIST_SOURCES
=
$(
libinterception_la_SOURCES
)
DIST_SOURCES
=
$(
am__libinterception_la_SOURCES_DIST
)
ETAGS
=
etags
ETAGS
=
etags
CTAGS
=
ctags
CTAGS
=
ctags
DISTFILES
=
$(DIST_COMMON)
$(DIST_SOURCES)
$(TEXINFOS)
$(EXTRA_DIST)
DISTFILES
=
$(DIST_COMMON)
$(DIST_SOURCES)
$(TEXINFOS)
$(EXTRA_DIST)
...
@@ -215,7 +230,8 @@ interception_files = \
...
@@ -215,7 +230,8 @@ interception_files = \
interception_mac.cc
\
interception_mac.cc
\
interception_win.cc
interception_win.cc
libinterception_la_SOURCES
=
$(interception_files)
@USING_MACH_OVERRIDE_FALSE@
libinterception_la_SOURCES
=
$(interception_files)
@USING_MACH_OVERRIDE_TRUE@
libinterception_la_SOURCES
=
$(interception_files)
mach_override/mach_override.c
# Work around what appears to be a GNU make bug handling MAKEFLAGS
# 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
# values defined in terms of make variables, as is the case for CC and
...
@@ -261,7 +277,7 @@ MAKEOVERRIDES =
...
@@ -261,7 +277,7 @@ MAKEOVERRIDES =
all
:
all-am
all
:
all-am
.SUFFIXES
:
.SUFFIXES
:
.SUFFIXES
:
.cc .lo .o .obj
.SUFFIXES
:
.c
.c
c .lo .o .obj
$(srcdir)/Makefile.in
:
@MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
$(srcdir)/Makefile.in
:
@MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.am $(am__configure_deps)
@
for
dep
in
$?
;
do
\
@
for
dep
in
$?
;
do
\
case
'
$(am__configure_deps)
'
in
\
case
'
$(am__configure_deps)
'
in
\
...
@@ -313,6 +329,35 @@ distclean-compile:
...
@@ -313,6 +329,35 @@ distclean-compile:
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/interception_linux.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/interception_linux.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/interception_mac.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/interception_mac.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/interception_win.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/interception_win.Plo@am__quote@
@AMDEP_TRUE@@am__include@
@am__quote@./$(DEPDIR)/mach_override.Plo@am__quote@
.c.o
:
@am__fastdepCC_TRUE@
$(COMPILE)
-MT
$@
-MD
-MP
-MF
$(DEPDIR)/$*.Tpo
-c
-o
$@
$<
@am__fastdepCC_TRUE@
$(am__mv)
$(DEPDIR)/$*.Tpo
$(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@
source
=
'$<'
object
=
'$@'
libtool
=
no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@
DEPDIR
=
$(DEPDIR)
$(CCDEPMODE)
$(depcomp)
@AMDEPBACKSLASH@
@am__fastdepCC_FALSE@
$(COMPILE)
-c
$<
.c.obj
:
@am__fastdepCC_TRUE@
$(COMPILE)
-MT
$@
-MD
-MP
-MF
$(DEPDIR)/$*.Tpo
-c
-o
$@
`$(CYGPATH_W)
'$<'
`
@am__fastdepCC_TRUE@
$(am__mv)
$(DEPDIR)/$*.Tpo
$(DEPDIR)/$*.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@
source
=
'$<'
object
=
'$@'
libtool
=
no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@
DEPDIR
=
$(DEPDIR)
$(CCDEPMODE)
$(depcomp)
@AMDEPBACKSLASH@
@am__fastdepCC_FALSE@
$(COMPILE)
-c
`$(CYGPATH_W)
'$<'
`
.c.lo
:
@am__fastdepCC_TRUE@
$(LTCOMPILE)
-MT
$@
-MD
-MP
-MF
$(DEPDIR)/$*.Tpo
-c
-o
$@
$<
@am__fastdepCC_TRUE@
$(am__mv)
$(DEPDIR)/$*.Tpo
$(DEPDIR)/$*.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@
source
=
'$<'
object
=
'$@'
libtool
=
yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@
DEPDIR
=
$(DEPDIR)
$(CCDEPMODE)
$(depcomp)
@AMDEPBACKSLASH@
@am__fastdepCC_FALSE@
$(LTCOMPILE)
-c
-o
$@
$<
mach_override.lo
:
mach_override/mach_override.c
@am__fastdepCC_TRUE@
$(LIBTOOL)
--tag
=
CC
$(AM_LIBTOOLFLAGS)
$(LIBTOOLFLAGS)
--mode
=
compile
$(CC)
$(DEFS)
$(DEFAULT_INCLUDES)
$(INCLUDES)
$(AM_CPPFLAGS)
$(CPPFLAGS)
$(AM_CFLAGS)
$(CFLAGS)
-MT
mach_override.lo
-MD
-MP
-MF
$(DEPDIR)
/mach_override.Tpo
-c
-o
mach_override.lo
`
test
-f
'mach_override/mach_override.c'
||
echo
'
$(srcdir)
/'
`
mach_override/mach_override.c
@am__fastdepCC_TRUE@
$(am__mv)
$(DEPDIR)/mach_override.Tpo
$(DEPDIR)/mach_override.Plo
@AMDEP_TRUE@@am__fastdepCC_FALSE@
source
=
'mach_override/mach_override.c'
object
=
'mach_override.lo'
libtool
=
yes @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@
DEPDIR
=
$(DEPDIR)
$(CCDEPMODE)
$(depcomp)
@AMDEPBACKSLASH@
@am__fastdepCC_FALSE@
$(LIBTOOL)
--tag
=
CC
$(AM_LIBTOOLFLAGS)
$(LIBTOOLFLAGS)
--mode
=
compile
$(CC)
$(DEFS)
$(DEFAULT_INCLUDES)
$(INCLUDES)
$(AM_CPPFLAGS)
$(CPPFLAGS)
$(AM_CFLAGS)
$(CFLAGS)
-c
-o
mach_override.lo
`
test
-f
'mach_override/mach_override.c'
||
echo
'
$(srcdir)
/'
`
mach_override/mach_override.c
.cc.o
:
.cc.o
:
@am__fastdepCXX_TRUE@
$(CXXCOMPILE)
-MT
$@
-MD
-MP
-MF
$(DEPDIR)/$*.Tpo
-c
-o
$@
$<
@am__fastdepCXX_TRUE@
$(CXXCOMPILE)
-MT
$@
-MD
-MP
-MF
$(DEPDIR)/$*.Tpo
-c
-o
$@
$<
...
...
libsanitizer/interception/mach_override/LICENSE.txt
0 → 100644
View file @
f246eadc
Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
libsanitizer/interception/mach_override/mach_override.c
0 → 100644
View file @
f246eadc
This diff is collapsed.
Click to expand it.
libsanitizer/interception/mach_override/mach_override.h
0 → 100644
View file @
f246eadc
/*******************************************************************************
mach_override.h
Copyright (c) 2003-2009 Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
Some rights reserved: <http://opensource.org/licenses/mit-license.php>
***************************************************************************/
/***************************************************************************//**
@mainpage mach_override
@author Jonathan 'Wolf' Rentzsch: <http://rentzsch.com>
This package, coded in C to the Mach API, allows you to override ("patch")
program- and system-supplied functions at runtime. You can fully replace
functions with your implementations, or merely head- or tail-patch the
original implementations.
Use it by #include'ing mach_override.h from your .c, .m or .mm file(s).
@todo Discontinue use of Carbon's MakeDataExecutable() and
CompareAndSwap() calls and start using the Mach equivalents, if they
exist. If they don't, write them and roll them in. That way, this
code will be pure Mach, which will make it easier to use everywhere.
Update: MakeDataExecutable() has been replaced by
msync(MS_INVALIDATE). There is an OSCompareAndSwap in libkern, but
I'm currently unsure if I can link against it. May have to roll in
my own version...
@todo Stop using an entire 4K high-allocated VM page per 28-byte escape
branch island. Done right, this will dramatically speed up escape
island allocations when they number over 250. Then again, if you're
overriding more than 250 functions, maybe speed isn't your main
concern...
@todo Add detection of: b, bl, bla, bc, bcl, bcla, bcctrl, bclrl
first-instructions. Initially, we should refuse to override
functions beginning with these instructions. Eventually, we should
dynamically rewrite them to make them position-independent.
@todo Write mach_unoverride(), which would remove an override placed on a
function. Must be multiple-override aware, which means an almost
complete rewrite under the covers, because the target address can't
be spread across two load instructions like it is now since it will
need to be atomically updatable.
@todo Add non-rentry variants of overrides to test_mach_override.
***************************************************************************/
#ifdef __APPLE__
#ifndef _mach_override_
#define _mach_override_
#include <sys/types.h>
#include <mach/error.h>
#ifdef __cplusplus
extern
"C"
{
#endif
/**
Returned if the function to be overrided begins with a 'mfctr' instruction.
*/
#define err_cannot_override (err_local|1)
/************************************************************************************//**
Dynamically overrides the function implementation referenced by
originalFunctionAddress with the implentation pointed to by overrideFunctionAddress.
Optionally returns a pointer to a "reentry island" which, if jumped to, will resume
the original implementation.
@param originalFunctionAddress -> Required address of the function to
override (with overrideFunctionAddress).
@param overrideFunctionAddress -> Required address to the overriding
function.
@param originalFunctionReentryIsland <- Optional pointer to pointer to the
reentry island. Can be NULL.
@result <- err_cannot_override if the original
function's implementation begins with
the 'mfctr' instruction.
************************************************************************************/
// We're prefixing mach_override_ptr() with "__asan_" to avoid name conflicts with other
// mach_override_ptr() implementations that may appear in the client program.
mach_error_t
__asan_mach_override_ptr
(
void
*
originalFunctionAddress
,
const
void
*
overrideFunctionAddress
,
void
**
originalFunctionReentryIsland
);
// Allow to use custom allocation and deallocation routines with mach_override_ptr().
// This should help to speed up the things on x86_64.
typedef
mach_error_t
island_malloc
(
void
**
ptr
,
size_t
size
,
void
*
hint
);
typedef
mach_error_t
island_free
(
void
*
ptr
);
mach_error_t
__asan_mach_override_ptr_custom
(
void
*
originalFunctionAddress
,
const
void
*
overrideFunctionAddress
,
void
**
originalFunctionReentryIsland
,
island_malloc
*
alloc
,
island_free
*
dealloc
);
/************************************************************************************//**
************************************************************************************/
#ifdef __cplusplus
#define MACH_OVERRIDE( ORIGINAL_FUNCTION_RETURN_TYPE, ORIGINAL_FUNCTION_NAME, ORIGINAL_FUNCTION_ARGS, ERR ) \
{ \
static ORIGINAL_FUNCTION_RETURN_TYPE (*ORIGINAL_FUNCTION_NAME##_reenter)ORIGINAL_FUNCTION_ARGS; \
static bool ORIGINAL_FUNCTION_NAME##_overriden = false; \
class mach_override_class__##ORIGINAL_FUNCTION_NAME { \
public: \
static kern_return_t override(void *originalFunctionPtr) { \
kern_return_t result = err_none; \
if (!ORIGINAL_FUNCTION_NAME##_overriden) { \
ORIGINAL_FUNCTION_NAME##_overriden = true; \
result = mach_override_ptr( (void*)originalFunctionPtr, \
(void*)mach_override_class__##ORIGINAL_FUNCTION_NAME::replacement, \
(void**)&ORIGINAL_FUNCTION_NAME##_reenter ); \
} \
return result; \
} \
static ORIGINAL_FUNCTION_RETURN_TYPE replacement ORIGINAL_FUNCTION_ARGS {
#define END_MACH_OVERRIDE( ORIGINAL_FUNCTION_NAME ) \
} \
}; \
\
err = mach_override_class__##ORIGINAL_FUNCTION_NAME::override((void*)ORIGINAL_FUNCTION_NAME); \
}
#endif
#ifdef __cplusplus
}
#endif
#endif // _mach_override_
#endif // __APPLE__
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment