1 // Copyright (c) 2007, Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 // Author: Mike Belshe
33 // To link tcmalloc into a EXE or DLL statically without using the patching
34 // facility, we can take a stock libcmt and remove all the allocator functions.
35 // When we relink the EXE/DLL with the modified libcmt and tcmalloc, a few
36 // functions are missing. This file contains the additional overrides which
37 // are required in the VS2005 libcmt in order to link the modified libcmt.
40 // http://groups.google.com/group/google-perftools/browse_thread/thread/41cd3710af85e57b
45 # error You should only be including this file in a windows environment!
48 #ifndef WIN32_OVERRIDE_ALLOCATORS
49 # error This file is intended for use when overriding allocators
52 #include "tcmalloc.cc"
54 extern "C" void* _recalloc(void* p
, size_t n
, size_t size
) {
55 void* result
= realloc(p
, n
* size
);
56 memset(result
, 0, n
* size
);
60 extern "C" void* _calloc_impl(size_t n
, size_t size
) {
61 return calloc(n
, size
);
64 extern "C" size_t _msize(void* p
) {
65 return MallocExtension::instance()->GetAllocatedSize(p
);
68 extern "C" intptr_t _get_heap_handle() {
72 // The CRT heap initialization stub.
73 extern "C" int _heap_init() {
74 // We intentionally leak this object. It lasts for the process
75 // lifetime. Trying to teardown at _heap_term() is so late that
76 // you can't do anything useful anyway.
81 // The CRT heap cleanup stub.
82 extern "C" void _heap_term() {
85 extern "C" int _set_new_mode(int flag
) {
86 return tc_set_new_mode(flag
);
93 int _CrtDbgReport(int, const char*, int, const char*, const char*, ...) {
97 int _CrtDbgReportW(int, const wchar_t*, int, const wchar_t*, const wchar_t*, ...) {
101 int _CrtSetReportMode(int, int) {
105 extern "C" void* _malloc_dbg(size_t size
, int , const char*, int) {
109 extern "C" void _free_dbg(void* ptr
, int) {
113 extern "C" void* _calloc_dbg(size_t n
, size_t size
, int, const char*, int) {
114 return calloc(n
, size
);
118 // We set this to 1 because part of the CRT uses a check of _crtheap != 0
119 // to test whether the CRT has been initialized. Once we've ripped out
120 // the allocators from libcmt, we need to provide this definition so that
121 // the rest of the CRT is still usable.
122 extern "C" void* _crtheap
= reinterpret_cast<void*>(1);