Skip to content

Commit

Permalink
i#1667 Mac false pos: replace _platform string and memory routines
Browse files Browse the repository at this point in the history
Adds several _platform_* string and memory routines from OSX to the
replacement list in order to avoid false positives.

Fixes #1667

Review-URL: https://codereview.appspot.com/186680043
  • Loading branch information
derekbruening committed Jan 5, 2015
1 parent 9ea3784 commit a911d5a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
21 changes: 11 additions & 10 deletions common/utils.h
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2010-2014 Google, Inc. All rights reserved.
* Copyright (c) 2010-2015 Google, Inc. All rights reserved.
* Copyright (c) 2007-2010 VMware, Inc. All rights reserved.
* **********************************************************/

Expand Down Expand Up @@ -64,15 +64,16 @@
# define IF_LINUX_ELSE(x,y) y
# define IF_LINUX_(x) x,
# endif
# ifdef MACOS
# define IF_MACOS(x) x
# define IF_MACOS_ELSE(x,y) x
# define IF_MACOS_(x) x,
# else
# define IF_MACOS(x)
# define IF_MACOS_ELSE(x,y) y
# define IF_MACOS_(x) x,
# endif
#endif

#ifdef MACOS
# define IF_MACOS(x) x
# define IF_MACOS_ELSE(x,y) x
# define IF_MACOS_(x) x,
#else
# define IF_MACOS(x)
# define IF_MACOS_ELSE(x,y) y
# define IF_MACOS_(x) x,
#endif

#ifdef X64
Expand Down
5 changes: 4 additions & 1 deletion drmemory/docs/release.dox
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2010-2014 Google, Inc. All rights reserved.
* Copyright (c) 2010-2015 Google, Inc. All rights reserved.
* Copyright (c) 2009-2010 VMware, Inc. All rights reserved.
* **********************************************************/

Expand Down Expand Up @@ -60,6 +60,9 @@ The Dr. Memory distribution contains the following:
\section sec_changes Changes Since Prior Releases

The current version is \TOOL_VERSION.
The changes between \TOOL_VERSION and version 1.8.0 include:
- Added support for Mac OSX Yosemite.

The changes between \TOOL_VERSION and version 1.7.0 include:
- Dropped official support for Windows 2000.
- Enabled -delay_frees_stack by default.
Expand Down
29 changes: 20 additions & 9 deletions drmemory/replace.c
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2010-2014 Google, Inc. All rights reserved.
* Copyright (c) 2010-2015 Google, Inc. All rights reserved.
* Copyright (c) 2008-2010 VMware, Inc. All rights reserved.
* **********************************************************/

Expand Down Expand Up @@ -50,14 +50,17 @@
# include "drsyms.h"
#endif

#undef strcasecmp /* undo def from utils.h */

/* On Windows, keep this updated with drmemory.pl which queries these pre-run.
*
* When adding, make sure the regexs passed to find_syms_regex() cover
* the new name!
*
* Template: REPLACE_DEF(name, corresponding-wide-char-version)
* Template: REPLACE_NAME_DEF(app-name, replace_ func name, corresponding-wide-char)
*
*/
#define REPLACE_DEF(name, wide) REPLACE_NAME_DEF(name, name, wide)
#define REPLACE_DEFS() \
REPLACE_DEF(memset, NULL) \
REPLACE_DEF(memcpy, NULL) \
Expand Down Expand Up @@ -94,24 +97,32 @@
REPLACE_DEF(strcspn, NULL) \
REPLACE_DEF(stpcpy, NULL) \
REPLACE_DEF(strstr, "wcsstr") \
REPLACE_DEF(wcsstr, NULL)
REPLACE_DEF(wcsstr, NULL) \
IF_MACOS(REPLACE_NAME_DEF(_platform_memchr, memchr, NULL)) \
IF_MACOS(REPLACE_NAME_DEF(_platform_memcmp, memcmp, NULL)) \
IF_MACOS(REPLACE_NAME_DEF(_platform_memmove, memmove, NULL)) \
IF_MACOS(REPLACE_NAME_DEF(_platform_memset, memset, NULL)) \
IF_MACOS(REPLACE_NAME_DEF(_platform_strchr, strchr, NULL)) \
IF_MACOS(REPLACE_NAME_DEF(_platform_strcmp, strcmp, NULL)) \
IF_MACOS(REPLACE_NAME_DEF(_platform_strncmp, strncmp, NULL)) \
IF_MACOS(REPLACE_NAME_DEF(_platform_strlen, strlen, NULL))

/* XXX i#350: add wrappers for wcsncpy, wcscat,
* wcsncat, wmemmove.
*/

static const char *replace_routine_name[] = {
#define REPLACE_DEF(nm, wide) STRINGIFY(nm),
#define REPLACE_NAME_DEF(nm, func, wide) STRINGIFY(nm),
REPLACE_DEFS()
#undef REPLACE_DEF
#undef REPLACE_NAME_DEF
};
#define REPLACE_NUM (sizeof(replace_routine_name)/sizeof(replace_routine_name[0]))

#ifdef WINDOWS
static const char * const replace_routine_wide_alt[] = {
# define REPLACE_DEF(nm, wide) wide,
# define REPLACE_NAME_DEF(nm, func, wide) wide,
REPLACE_DEFS()
# undef REPLACE_DEF
# undef REPLACE_NAME_DEF
};
#endif

Expand Down Expand Up @@ -819,9 +830,9 @@ ACTUAL_PRAGMA( code_seg() )
***************************************************************************/

static const void *replace_routine_addr[] = {
#define REPLACE_DEF(nm, wide) replace_##nm,
#define REPLACE_NAME_DEF(nm, func, wide) replace_##func,
REPLACE_DEFS()
#undef REPLACE_DEF
#undef REPLACE_NAME_DEF
};

static app_pc
Expand Down

0 comments on commit a911d5a

Please sign in to comment.