js/src/yarr/PageBlock.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set ts=8 sts=4 et sw=4 tw=99:
     3  *
     4  * ***** BEGIN LICENSE BLOCK *****
     5  * Copyright (C) 2010 Apple Inc. All rights reserved.
     6  *
     7  * Redistribution and use in source and binary forms, with or without
     8  * modification, are permitted provided that the following conditions
     9  * are met:
    10  * 1. Redistributions of source code must retain the above copyright
    11  *    notice, this list of conditions and the following disclaimer.
    12  * 2. Redistributions in binary form must reproduce the above copyright
    13  *    notice, this list of conditions and the following disclaimer in the
    14  *    documentation and/or other materials provided with the distribution.
    15  *
    16  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
    17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
    20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
    26  * THE POSSIBILITY OF SUCH DAMAGE.
    27  *
    28  * ***** END LICENSE BLOCK ***** */
    30 #ifndef yarr_PageBlock_h
    31 #define yarr_PageBlock_h
    33 #include <stddef.h>
    34 #include <stdint.h>
    36 namespace WTF {
    38 size_t pageSize();
    39 inline bool isPageAligned(void* address) { return !(reinterpret_cast<intptr_t>(address) & (pageSize() - 1)); }
    40 inline bool isPageAligned(size_t size) { return !(size & (pageSize() - 1)); }
    41 inline bool isPowerOfTwo(size_t size) { return !(size & (size - 1)); }
    43 class PageBlock {
    44 public:
    45     PageBlock();
    46     PageBlock(const PageBlock&);
    47     PageBlock(void*, size_t);
    49     void* base() const { return m_base; }
    50     size_t size() const { return m_size; }
    52     operator bool() const { return !!m_base; }
    54     bool contains(void* containedBase, size_t containedSize)
    55     {
    56         return containedBase >= m_base
    57             && (static_cast<char*>(containedBase) + containedSize) <= (static_cast<char*>(m_base) + m_size);
    58     }
    60 private:
    61     void* m_base;
    62     size_t m_size;
    63 };
    65 inline PageBlock::PageBlock()
    66     : m_base(0)
    67     , m_size(0)
    68 {
    69 }
    71 inline PageBlock::PageBlock(const PageBlock& other)
    72     : m_base(other.m_base)
    73     , m_size(other.m_size)
    74 {
    75 }
    77 inline PageBlock::PageBlock(void* base, size_t size)
    78     : m_base(base)
    79     , m_size(size)
    80 {
    81 }
    83 } // namespace WTF
    85 using WTF::pageSize;
    86 using WTF::isPageAligned;
    87 using WTF::isPageAligned;
    88 using WTF::isPowerOfTwo;
    90 #endif /* yarr_PageBlock_h */

mercurial