michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsRuleData.h" michael@0: michael@0: #include "mozilla/Poison.h" michael@0: #include michael@0: michael@0: inline size_t michael@0: nsRuleData::GetPoisonOffset() michael@0: { michael@0: // Fill in mValueOffsets such that mValueStorage + mValueOffsets[i] michael@0: // will yield the frame poison value for all uninitialized value michael@0: // offsets. michael@0: static_assert(sizeof(uintptr_t) == sizeof(size_t), michael@0: "expect uintptr_t and size_t to be the same size"); michael@0: static_assert(uintptr_t(-1) > uintptr_t(0), michael@0: "expect uintptr_t to be unsigned"); michael@0: static_assert(size_t(-1) > size_t(0), michael@0: "expect size_t to be unsigned"); michael@0: uintptr_t framePoisonValue = mozPoisonValue(); michael@0: return size_t(framePoisonValue - uintptr_t(mValueStorage)) / michael@0: sizeof(nsCSSValue); michael@0: } michael@0: michael@0: nsRuleData::nsRuleData(uint32_t aSIDs, nsCSSValue* aValueStorage, michael@0: nsPresContext* aContext, nsStyleContext* aStyleContext) michael@0: : mSIDs(aSIDs), michael@0: mCanStoreInRuleTree(true), michael@0: mPresContext(aContext), michael@0: mStyleContext(aStyleContext), michael@0: mValueStorage(aValueStorage) michael@0: { michael@0: #ifndef MOZ_VALGRIND michael@0: size_t framePoisonOffset = GetPoisonOffset(); michael@0: for (size_t i = 0; i < nsStyleStructID_Length; ++i) { michael@0: mValueOffsets[i] = framePoisonOffset; michael@0: } michael@0: #endif michael@0: } michael@0: michael@0: #ifdef DEBUG michael@0: nsRuleData::~nsRuleData() michael@0: { michael@0: #ifndef MOZ_VALGRIND michael@0: // assert nothing in mSIDs has poison value michael@0: size_t framePoisonOffset = GetPoisonOffset(); michael@0: for (size_t i = 0; i < nsStyleStructID_Length; ++i) { michael@0: NS_ABORT_IF_FALSE(!(mSIDs & (1 << i)) || michael@0: mValueOffsets[i] != framePoisonOffset, michael@0: "value in SIDs was left with poison offset"); michael@0: } michael@0: #endif michael@0: } michael@0: #endif