Zero.h (1097B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef ZERO_H 8 #define ZERO_H 9 10 #include "Globals.h" 11 #include "mozjemalloc.h" 12 13 #include <string.h> 14 15 namespace mozilla { 16 17 static inline void MaybePoison(void* aPtr, size_t aSize) { 18 size_t size; 19 switch (opt_poison) { 20 case NONE: 21 return; 22 case SOME: 23 size = std::min(aSize, opt_poison_size); 24 break; 25 case ALL: 26 size = aSize; 27 break; 28 } 29 MOZ_ASSERT(size != 0 && size <= aSize); 30 memset(aPtr, kAllocPoison, size); 31 } 32 33 // Fill the given range of memory with zeroes or junk depending on opt_junk and 34 // opt_zero. 35 static inline void ApplyZeroOrJunk(void* aPtr, size_t aSize) { 36 if (opt_junk) { 37 memset(aPtr, kAllocJunk, aSize); 38 } else if (opt_zero) { 39 memset(aPtr, 0, aSize); 40 } 41 } 42 43 } // namespace mozilla 44 45 #endif // ! ZERO_H