| OLD | NEW |
| 1 /* Copyright (c) 2006, Google Inc. | 1 /* Copyright (c) 2006, Google Inc. |
| 2 * All rights reserved. | 2 * All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // ATTRIBUTE_SECTION(malloc_hook) for Alloc* and Free | 65 // ATTRIBUTE_SECTION(malloc_hook) for Alloc* and Free |
| 66 // are to put all callers of MallocHook::Invoke* in this module | 66 // are to put all callers of MallocHook::Invoke* in this module |
| 67 // into special section, | 67 // into special section, |
| 68 // so that MallocHook::GetCallerStackTrace can function accurately. | 68 // so that MallocHook::GetCallerStackTrace can function accurately. |
| 69 | 69 |
| 70 // Create a new arena. | 70 // Create a new arena. |
| 71 // The root metadata for the new arena is allocated in the | 71 // The root metadata for the new arena is allocated in the |
| 72 // meta_data_arena; the DefaultArena() can be passed for meta_data_arena. | 72 // meta_data_arena; the DefaultArena() can be passed for meta_data_arena. |
| 73 // These values may be ored into flags: | 73 // These values may be ored into flags: |
| 74 enum { | 74 enum { |
| 75 // Calls to Alloc() and Free() will be reported | 75 // Report calls to Alloc() and Free() via the MallocHook interface. |
| 76 // via the MallocHook interface. | 76 // Set in the DefaultArena. |
| 77 // The DefaultArena() has this flag on. | 77 kCallMallocHook = 0x0001, |
| 78 // NewArena(flags, DefaultArena()) w/o this bit in 'flags', | 78 |
| 79 // on the other hand, will not cause any MallocHook | 79 // Make calls to Alloc(), Free() be async-signal-safe. Not set in |
| 80 // calls even during the NewArena call itself | 80 // DefaultArena(). |
| 81 // (it will in fact use meta_data_arena different from DefaultArena()). | 81 kAsyncSignalSafe = 0x0002, |
| 82 kCallMallocHook = 0x0001 | 82 |
| 83 // When used with DefaultArena(), the NewArena() and DeleteArena() calls |
| 84 // obey the flags given explicitly in the NewArena() call, even if those |
| 85 // flags differ from the settings in DefaultArena(). So the call |
| 86 // NewArena(kAsyncSignalSafe, DefaultArena()) is itself async-signal-safe, |
| 87 // as well as generatating an arena that provides async-signal-safe |
| 88 // Alloc/Free. |
| 83 }; | 89 }; |
| 84 static Arena *NewArena(int32 flags, Arena *meta_data_arena); | 90 static Arena *NewArena(int32 flags, Arena *meta_data_arena); |
| 85 | 91 |
| 86 // Destroys an arena allocated by NewArena and returns true, | 92 // Destroys an arena allocated by NewArena and returns true, |
| 87 // provided no allocated blocks remain in the arena. | 93 // provided no allocated blocks remain in the arena. |
| 88 // If allocated blocks remain in the arena, does nothing and | 94 // If allocated blocks remain in the arena, does nothing and |
| 89 // returns false. | 95 // returns false. |
| 90 // It is illegal to attempt to destroy the DefaultArena(). | 96 // It is illegal to attempt to destroy the DefaultArena(). |
| 91 static bool DeleteArena(Arena *arena); | 97 static bool DeleteArena(Arena *arena); |
| 92 | 98 |
| 93 // The default arena that always exists. | 99 // The default arena that always exists. |
| 94 static Arena *DefaultArena(); | 100 static Arena *DefaultArena(); |
| 95 | 101 |
| 96 private: | 102 private: |
| 97 LowLevelAlloc(); // no instances | 103 LowLevelAlloc(); // no instances |
| 98 }; | 104 }; |
| 99 | 105 |
| 100 #endif | 106 #endif |
| OLD | NEW |