1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/yarr/PageBlock.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + * 1.7 + * ***** BEGIN LICENSE BLOCK ***** 1.8 + * Copyright (C) 2010 Apple Inc. All rights reserved. 1.9 + * 1.10 + * Redistribution and use in source and binary forms, with or without 1.11 + * modification, are permitted provided that the following conditions 1.12 + * are met: 1.13 + * 1. Redistributions of source code must retain the above copyright 1.14 + * notice, this list of conditions and the following disclaimer. 1.15 + * 2. Redistributions in binary form must reproduce the above copyright 1.16 + * notice, this list of conditions and the following disclaimer in the 1.17 + * documentation and/or other materials provided with the distribution. 1.18 + * 1.19 + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 1.20 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 1.21 + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.22 + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 1.23 + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 1.24 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 1.25 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 1.26 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 1.27 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 1.28 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 1.29 + * THE POSSIBILITY OF SUCH DAMAGE. 1.30 + * 1.31 + * ***** END LICENSE BLOCK ***** */ 1.32 + 1.33 +#ifndef yarr_PageBlock_h 1.34 +#define yarr_PageBlock_h 1.35 + 1.36 +#include <stddef.h> 1.37 +#include <stdint.h> 1.38 + 1.39 +namespace WTF { 1.40 + 1.41 +size_t pageSize(); 1.42 +inline bool isPageAligned(void* address) { return !(reinterpret_cast<intptr_t>(address) & (pageSize() - 1)); } 1.43 +inline bool isPageAligned(size_t size) { return !(size & (pageSize() - 1)); } 1.44 +inline bool isPowerOfTwo(size_t size) { return !(size & (size - 1)); } 1.45 + 1.46 +class PageBlock { 1.47 +public: 1.48 + PageBlock(); 1.49 + PageBlock(const PageBlock&); 1.50 + PageBlock(void*, size_t); 1.51 + 1.52 + void* base() const { return m_base; } 1.53 + size_t size() const { return m_size; } 1.54 + 1.55 + operator bool() const { return !!m_base; } 1.56 + 1.57 + bool contains(void* containedBase, size_t containedSize) 1.58 + { 1.59 + return containedBase >= m_base 1.60 + && (static_cast<char*>(containedBase) + containedSize) <= (static_cast<char*>(m_base) + m_size); 1.61 + } 1.62 + 1.63 +private: 1.64 + void* m_base; 1.65 + size_t m_size; 1.66 +}; 1.67 + 1.68 +inline PageBlock::PageBlock() 1.69 + : m_base(0) 1.70 + , m_size(0) 1.71 +{ 1.72 +} 1.73 + 1.74 +inline PageBlock::PageBlock(const PageBlock& other) 1.75 + : m_base(other.m_base) 1.76 + , m_size(other.m_size) 1.77 +{ 1.78 +} 1.79 + 1.80 +inline PageBlock::PageBlock(void* base, size_t size) 1.81 + : m_base(base) 1.82 + , m_size(size) 1.83 +{ 1.84 +} 1.85 + 1.86 +} // namespace WTF 1.87 + 1.88 +using WTF::pageSize; 1.89 +using WTF::isPageAligned; 1.90 +using WTF::isPageAligned; 1.91 +using WTF::isPowerOfTwo; 1.92 + 1.93 +#endif /* yarr_PageBlock_h */