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

Side by Side Diff: base/allocator/allocator_shim_override_ucrt_symbols_win.h

Issue 2138173002: Hookup the generic heap intercept for Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Squash the use_experimental_allocator_shim for NaCL as per Brett's suggestion. Created 4 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This header defines symbols to override the same functions in the Visual C++
6 // CRT implementation.
7
8 #ifdef BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_UCRT_SYMBOLS_WIN_H_
9 #error This header is meant to be included only once by allocator_shim.cc
10 #endif
11 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_UCRT_SYMBOLS_WIN_H_
12
13 #include <malloc.h>
14
15 extern "C" {
16
17 void* (*malloc_unchecked)(size_t) = &base::allocator::UncheckedAlloc;
18
19 namespace {
20
21 int win_new_mode = 0;
22
23 } // namespace
24
25 // This function behaves similarly to MSVC's _set_new_mode.
26 // If flag is 0 (default), calls to malloc will behave normally.
27 // If flag is 1, calls to malloc will behave like calls to new,
28 // and the std_new_handler will be invoked on failure.
29 // Returns the previous mode.
30 //
31 // Replaces _set_new_mode in ucrt\heap\new_mode.cpp
32 int _set_new_mode(int flag) {
33 // The MS CRT calls this function early on in startup, so this serves as a low
34 // overhead proof that the allocator shim is in place for this process.
35 base::allocator::g_is_win_shim_layer_initialized = true;
36 int old_mode = win_new_mode;
37 win_new_mode = flag;
38
39 base::allocator::SetCallNewHandlerOnMallocFailure(win_new_mode != 0);
40
41 return old_mode;
42 }
43
44 // Replaces _query_new_mode in ucrt\heap\new_mode.cpp
45 int _query_new_mode() {
46 return win_new_mode;
47 }
48
49 // These symbols override the CRT's implementation of the same functions.
50 __declspec(restrict) void* malloc(size_t size) {
51 return ShimMalloc(size);
52 }
53
54 void free(void* ptr) {
55 ShimFree(ptr);
56 }
57
58 __declspec(restrict) void* realloc(void* ptr, size_t size) {
59 return ShimRealloc(ptr, size);
60 }
61
62 __declspec(restrict) void* calloc(size_t n, size_t size) {
63 return ShimCalloc(n, size);
64 }
65
66 // The default dispatch translation unit has to define also the following
67 // symbols (unless they are ultimately routed to the system symbols):
68 // void malloc_stats(void);
69 // int mallopt(int, int);
70 // struct mallinfo mallinfo(void);
71 // size_t malloc_size(void*);
72 // size_t malloc_usable_size(const void*);
73
74 } // extern "C"
OLDNEW
« no previous file with comments | « base/allocator/allocator_shim_default_dispatch_to_winheap.cc ('k') | base/allocator/allocator_shim_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698