|
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 ***** */ |
|
29 |
|
30 #include "yarr/PageBlock.h" |
|
31 #include "assembler/wtf/Assertions.h" |
|
32 |
|
33 #if WTF_OS_UNIX && !WTF_OS_SYMBIAN |
|
34 #include <unistd.h> |
|
35 #endif |
|
36 |
|
37 #if WTF_OS_WINDOWS |
|
38 #include <malloc.h> |
|
39 #include <windows.h> |
|
40 #endif |
|
41 |
|
42 #if WTF_OS_SYMBIAN |
|
43 #include <e32hal.h> |
|
44 #include <e32std.h> |
|
45 #endif |
|
46 |
|
47 #if WTF_OS_OS2 |
|
48 #include <stdlib.h> |
|
49 #endif |
|
50 |
|
51 namespace WTF { |
|
52 |
|
53 static size_t s_pageSize; |
|
54 |
|
55 #if (WTF_OS_UNIX && !WTF_OS_SYMBIAN) || WTF_OS_OS2 |
|
56 |
|
57 inline size_t systemPageSize() |
|
58 { |
|
59 return getpagesize(); |
|
60 } |
|
61 |
|
62 #elif WTF_OS_WINDOWS |
|
63 |
|
64 inline size_t systemPageSize() |
|
65 { |
|
66 static size_t size = 0; |
|
67 SYSTEM_INFO system_info; |
|
68 GetSystemInfo(&system_info); |
|
69 size = system_info.dwPageSize; |
|
70 return size; |
|
71 } |
|
72 |
|
73 #elif WTF_OS_SYMBIAN |
|
74 |
|
75 inline size_t systemPageSize() |
|
76 { |
|
77 static TInt page_size = 0; |
|
78 UserHal::PageSizeInBytes(page_size); |
|
79 return page_size; |
|
80 } |
|
81 |
|
82 #endif |
|
83 |
|
84 size_t pageSize() |
|
85 { |
|
86 if (!s_pageSize) |
|
87 s_pageSize = systemPageSize(); |
|
88 ASSERT(isPowerOfTwo(s_pageSize)); |
|
89 return s_pageSize; |
|
90 } |
|
91 |
|
92 } // namespace WTF |