Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Unified Diff: third_party/tcmalloc/chromium/src/windows/patch_functions.cc

Issue 7050034: Merge google-perftools r109 (the current contents of third_party/tcmalloc/vendor) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/tcmalloc/chromium/src/windows/patch_functions.cc
===================================================================
--- third_party/tcmalloc/chromium/src/windows/patch_functions.cc (revision 87277)
+++ third_party/tcmalloc/chromium/src/windows/patch_functions.cc (working copy)
@@ -122,6 +122,11 @@
extern "C" PERFTOOLS_DLL_DECL void _tcmalloc();
void _tcmalloc() { }
+// This is the version needed for windows x64, which has a different
+// decoration scheme which doesn't auto-add a leading underscore.
+extern "C" PERFTOOLS_DLL_DECL void __tcmalloc();
+void __tcmalloc() { }
+
namespace { // most everything here is in an unnamed namespace
typedef void (*GenericFnPtr)();
@@ -175,7 +180,7 @@
kNew, kNewArray, kDelete, kDeleteArray,
kNewNothrow, kNewArrayNothrow, kDeleteNothrow, kDeleteArrayNothrow,
// These are windows-only functions from malloc.h
- k_Msize, k_Expand, k_Aligned_malloc, k_Aligned_free,
+ k_Msize, k_Expand,
kNumFunctions
};
@@ -274,12 +279,12 @@
const std::nothrow_t&) __THROW;
static size_t Perftools__msize(void *ptr) __THROW;
static void* Perftools__expand(void *ptr, size_t size) __THROW;
- static void* Perftools__aligned_malloc(size_t size, size_t alignment) __THROW;
- static void Perftools__aligned_free(void *ptr) __THROW;
// malloc.h also defines these functions:
+ // _aligned_malloc, _aligned_free,
// _recalloc, _aligned_offset_malloc, _aligned_realloc, _aligned_recalloc
// _aligned_offset_realloc, _aligned_offset_recalloc, _malloca, _freea
// But they seem pretty obscure, and I'm fine not overriding them for now.
+ // It may be they all call into malloc/free anyway.
};
// This is a subset of MODDULEENTRY32, that we need for patching.
@@ -300,10 +305,19 @@
ModuleEntryCopy(const MODULEINFO& mi) {
this->modBaseAddr = mi.lpBaseOfDll;
this->modBaseSize = mi.SizeOfImage;
- for (int i = 0; i < sizeof(rgProcAddresses)/sizeof(*rgProcAddresses); i++)
- rgProcAddresses[i] = (GenericFnPtr)::GetProcAddress(
+ LPVOID modEndAddr = (char*)mi.lpBaseOfDll + mi.SizeOfImage;
+ for (int i = 0; i < sizeof(rgProcAddresses)/sizeof(*rgProcAddresses); i++) {
+ FARPROC target = ::GetProcAddress(
reinterpret_cast<const HMODULE>(mi.lpBaseOfDll),
LibcInfo::function_name(i));
+ // Sometimes a DLL forwards a function to a function in another
+ // DLL. We don't want to patch those forwarded functions --
+ // they'll get patched when the other DLL is processed.
+ if (target >= modBaseAddr && target < modEndAddr)
+ rgProcAddresses[i] = (GenericFnPtr)target;
+ else
+ rgProcAddresses[i] = (GenericFnPtr)NULL;
+ }
}
};
@@ -390,7 +404,7 @@
NULL, // kMangledNewArrayNothrow,
NULL, // kMangledDeleteNothrow,
NULL, // kMangledDeleteArrayNothrow,
- "_msize", "_expand", "_aligned_malloc", "_aligned_free",
+ "_msize", "_expand",
};
// For mingw, I can't patch the new/delete here, because the
@@ -421,14 +435,6 @@
#endif
(GenericFnPtr)&::_msize,
(GenericFnPtr)&::_expand,
-#ifdef PERFTOOLS_NO_ALIGNED_MALLOC // for older versions of mingw
- // _aligned_malloc isn't always available in mingw, so don't try to patch.
- (GenericFnPtr)NULL,
- (GenericFnPtr)NULL,
-#else
- (GenericFnPtr)&::_aligned_malloc,
- (GenericFnPtr)&::_aligned_free,
-#endif
};
template<int T> GenericFnPtr LibcInfoWithPatchFunctions<T>::origstub_fn_[] = {
@@ -451,8 +457,6 @@
(GenericFnPtr)&Perftools_deletearray_nothrow,
(GenericFnPtr)&Perftools__msize,
(GenericFnPtr)&Perftools__expand,
- (GenericFnPtr)&Perftools__aligned_malloc,
- (GenericFnPtr)&Perftools__aligned_free,
};
/*static*/ WindowsInfo::FunctionInfo WindowsInfo::function_info_[] = {
@@ -908,21 +912,6 @@
return NULL;
}
-template<int T>
-void* LibcInfoWithPatchFunctions<T>::Perftools__aligned_malloc(size_t size,
- size_t alignment)
- __THROW {
- void* result = do_memalign_or_cpp_memalign(alignment, size);
- MallocHook::InvokeNewHook(result, size);
- return result;
-}
-
-template<int T>
-void LibcInfoWithPatchFunctions<T>::Perftools__aligned_free(void *ptr) __THROW {
- MallocHook::InvokeDeleteHook(ptr);
- do_free_with_callback(ptr, (void (*)(void*))origstub_fn_[k_Aligned_free]);
-}
-
LPVOID WINAPI WindowsInfo::Perftools_HeapAlloc(HANDLE hHeap, DWORD dwFlags,
DWORD_PTR dwBytes) {
LPVOID result = ((LPVOID (WINAPI *)(HANDLE, DWORD, DWORD_PTR))

Powered by Google App Engine
This is Rietveld 408576698