OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Its purpose is to SHIM_ALIAS_SYMBOL the Libc symbols for malloc/new to the | 5 // Its purpose is to SHIM_ALIAS_SYMBOL the Libc symbols for malloc/new to the |
6 // shim layer entry points. | 6 // shim layer entry points. |
7 | 7 |
8 #ifdef BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_LIBC_SYMBOLS_H_ | 8 #ifdef BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_LIBC_SYMBOLS_H_ |
9 #error This header is meant to be included only once by allocator_shim.cc | 9 #error This header is meant to be included only once by allocator_shim.cc |
10 #endif | 10 #endif |
11 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_LIBC_SYMBOLS_H_ | 11 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_LIBC_SYMBOLS_H_ |
12 | 12 |
13 #include <malloc.h> | 13 #include <malloc.h> |
14 | 14 |
15 #include "base/allocator/allocator_shim_internals.h" | 15 #include "base/allocator/allocator_shim_internals.h" |
16 | 16 |
17 extern "C" { | 17 extern "C" { |
18 | 18 |
19 #if !defined(OS_WIN) | |
20 | |
19 SHIM_ALWAYS_EXPORT void* malloc(size_t size) __THROW | 21 SHIM_ALWAYS_EXPORT void* malloc(size_t size) __THROW |
20 SHIM_ALIAS_SYMBOL(ShimMalloc); | 22 SHIM_ALIAS_SYMBOL(ShimMalloc); |
21 | 23 |
22 SHIM_ALWAYS_EXPORT void free(void* ptr) __THROW | 24 SHIM_ALWAYS_EXPORT void free(void* ptr) __THROW |
23 SHIM_ALIAS_SYMBOL(ShimFree); | 25 SHIM_ALIAS_SYMBOL(ShimFree); |
24 | 26 |
25 SHIM_ALWAYS_EXPORT void* realloc(void* ptr, size_t size) __THROW | 27 SHIM_ALWAYS_EXPORT void* realloc(void* ptr, size_t size) __THROW |
26 SHIM_ALIAS_SYMBOL(ShimRealloc); | 28 SHIM_ALIAS_SYMBOL(ShimRealloc); |
27 | 29 |
28 SHIM_ALWAYS_EXPORT void* calloc(size_t n, size_t size) __THROW | 30 SHIM_ALWAYS_EXPORT void* calloc(size_t n, size_t size) __THROW |
29 SHIM_ALIAS_SYMBOL(ShimCalloc); | 31 SHIM_ALIAS_SYMBOL(ShimCalloc); |
30 | 32 |
31 SHIM_ALWAYS_EXPORT void cfree(void* ptr) __THROW | 33 SHIM_ALWAYS_EXPORT void cfree(void* ptr) __THROW |
32 SHIM_ALIAS_SYMBOL(ShimFree); | 34 SHIM_ALIAS_SYMBOL(ShimFree); |
33 | 35 |
34 SHIM_ALWAYS_EXPORT void* memalign(size_t align, size_t s) __THROW | 36 SHIM_ALWAYS_EXPORT void* memalign(size_t align, size_t s) __THROW |
35 SHIM_ALIAS_SYMBOL(ShimMemalign); | 37 SHIM_ALIAS_SYMBOL(ShimMemalign); |
36 | 38 |
37 SHIM_ALWAYS_EXPORT void* valloc(size_t size) __THROW | 39 SHIM_ALWAYS_EXPORT void* valloc(size_t size) __THROW |
38 SHIM_ALIAS_SYMBOL(ShimValloc); | 40 SHIM_ALIAS_SYMBOL(ShimValloc); |
39 | 41 |
40 SHIM_ALWAYS_EXPORT void* pvalloc(size_t size) __THROW | 42 SHIM_ALWAYS_EXPORT void* pvalloc(size_t size) __THROW |
41 SHIM_ALIAS_SYMBOL(ShimPvalloc); | 43 SHIM_ALIAS_SYMBOL(ShimPvalloc); |
42 | 44 |
43 SHIM_ALWAYS_EXPORT int posix_memalign(void** r, size_t a, size_t s) __THROW | 45 SHIM_ALWAYS_EXPORT int posix_memalign(void** r, size_t a, size_t s) __THROW |
44 SHIM_ALIAS_SYMBOL(ShimPosixMemalign); | 46 SHIM_ALIAS_SYMBOL(ShimPosixMemalign); |
45 | 47 |
48 #else | |
49 | |
50 __declspec(restrict) void* malloc(size_t size) { | |
Primiano Tucci (use gerrit)
2016/07/12 14:51:05
maybe let's move these to a allocator_shim_overrid
Sigurður Ásgeirsson
2016/07/14 19:04:27
Yeah, I like that.
| |
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 #endif | |
46 // The default dispatch translation unit has to define also the following | 67 // The default dispatch translation unit has to define also the following |
47 // symbols (unless they are ultimately routed to the system symbols): | 68 // symbols (unless they are ultimately routed to the system symbols): |
48 // void malloc_stats(void); | 69 // void malloc_stats(void); |
49 // int mallopt(int, int); | 70 // int mallopt(int, int); |
50 // struct mallinfo mallinfo(void); | 71 // struct mallinfo mallinfo(void); |
51 // size_t malloc_size(void*); | 72 // size_t malloc_size(void*); |
52 // size_t malloc_usable_size(const void*); | 73 // size_t malloc_usable_size(const void*); |
53 | 74 |
54 } // extern "C" | 75 } // extern "C" |
OLD | NEW |