| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #include "wtf/Assertions.h" | 34 #include "wtf/Assertions.h" |
| 35 #include "wtf/CPU.h" | 35 #include "wtf/CPU.h" |
| 36 #include "wtf/WTFExport.h" | 36 #include "wtf/WTFExport.h" |
| 37 #include <cstddef> | 37 #include <cstddef> |
| 38 #include <stdint.h> | 38 #include <stdint.h> |
| 39 | 39 |
| 40 namespace WTF { | 40 namespace WTF { |
| 41 | 41 |
| 42 #if OS(WIN) | 42 #if OS(WIN) |
| 43 static const size_t kPageAllocationGranularityShift = 16; // 64KB | 43 static const size_t kPageAllocationGranularityShift = 16; // 64KB |
| 44 #else | 44 #else |
| 45 static const size_t kPageAllocationGranularityShift = 12; // 4KB | 45 static const size_t kPageAllocationGranularityShift = 12; // 4KB |
| 46 #endif | 46 #endif |
| 47 static const size_t kPageAllocationGranularity = 1 << kPageAllocationGranularity
Shift; | 47 static const size_t kPageAllocationGranularity = |
| 48 static const size_t kPageAllocationGranularityOffsetMask = kPageAllocationGranul
arity - 1; | 48 1 << kPageAllocationGranularityShift; |
| 49 static const size_t kPageAllocationGranularityBaseMask = ~kPageAllocationGranula
rityOffsetMask; | 49 static const size_t kPageAllocationGranularityOffsetMask = |
| 50 kPageAllocationGranularity - 1; |
| 51 static const size_t kPageAllocationGranularityBaseMask = |
| 52 ~kPageAllocationGranularityOffsetMask; |
| 50 | 53 |
| 51 // All Blink-supported systems have 4096 sized system pages and can handle | 54 // All Blink-supported systems have 4096 sized system pages and can handle |
| 52 // permissions and commit / decommit at this granularity. | 55 // permissions and commit / decommit at this granularity. |
| 53 static const size_t kSystemPageSize = 4096; | 56 static const size_t kSystemPageSize = 4096; |
| 54 static const size_t kSystemPageOffsetMask = kSystemPageSize - 1; | 57 static const size_t kSystemPageOffsetMask = kSystemPageSize - 1; |
| 55 static const size_t kSystemPageBaseMask = ~kSystemPageOffsetMask; | 58 static const size_t kSystemPageBaseMask = ~kSystemPageOffsetMask; |
| 56 | 59 |
| 57 enum PageAccessibilityConfiguration { | 60 enum PageAccessibilityConfiguration { |
| 58 PageAccessible, | 61 PageAccessible, |
| 59 PageInaccessible, | 62 PageInaccessible, |
| 60 }; | 63 }; |
| 61 | 64 |
| 62 // Allocate one or more pages. | 65 // Allocate one or more pages. |
| 63 // The requested address is just a hint; the actual address returned may | 66 // The requested address is just a hint; the actual address returned may |
| 64 // differ. The returned address will be aligned at least to align bytes. | 67 // differ. The returned address will be aligned at least to align bytes. |
| 65 // len is in bytes, and must be a multiple of kPageAllocationGranularity. | 68 // len is in bytes, and must be a multiple of kPageAllocationGranularity. |
| 66 // align is in bytes, and must be a power-of-two multiple of | 69 // align is in bytes, and must be a power-of-two multiple of |
| 67 // kPageAllocationGranularity. | 70 // kPageAllocationGranularity. |
| 68 // If addr is null, then a suitable and randomized address will be chosen | 71 // If addr is null, then a suitable and randomized address will be chosen |
| 69 // automatically. | 72 // automatically. |
| 70 // PageAccessibilityConfiguration controls the permission of the | 73 // PageAccessibilityConfiguration controls the permission of the |
| 71 // allocated pages. | 74 // allocated pages. |
| 72 // This call will return null if the allocation cannot be satisfied. | 75 // This call will return null if the allocation cannot be satisfied. |
| 73 WTF_EXPORT void* allocPages(void* addr, size_t len, size_t align, PageAccessibil
ityConfiguration); | 76 WTF_EXPORT void* allocPages(void* addr, |
| 77 size_t len, |
| 78 size_t align, |
| 79 PageAccessibilityConfiguration); |
| 74 | 80 |
| 75 // Free one or more pages. | 81 // Free one or more pages. |
| 76 // addr and len must match a previous call to allocPages(). | 82 // addr and len must match a previous call to allocPages(). |
| 77 WTF_EXPORT void freePages(void* addr, size_t len); | 83 WTF_EXPORT void freePages(void* addr, size_t len); |
| 78 | 84 |
| 79 // Mark one or more system pages as being inaccessible. | 85 // Mark one or more system pages as being inaccessible. |
| 80 // Subsequently accessing any address in the range will fault, and the | 86 // Subsequently accessing any address in the range will fault, and the |
| 81 // addresses will not be re-used by future allocations. | 87 // addresses will not be re-used by future allocations. |
| 82 // len must be a multiple of kSystemPageSize bytes. | 88 // len must be a multiple of kSystemPageSize bytes. |
| 83 WTF_EXPORT void setSystemPagesInaccessible(void* addr, size_t len); | 89 WTF_EXPORT void setSystemPagesInaccessible(void* addr, size_t len); |
| 84 | 90 |
| 85 // Mark one or more system pages as being accessible. | 91 // Mark one or more system pages as being accessible. |
| 86 // The pages will be readable and writeable. | 92 // The pages will be readable and writeable. |
| 87 // len must be a multiple of kSystemPageSize bytes. | 93 // len must be a multiple of kSystemPageSize bytes. |
| 88 // The result bool value indicates whether the permission | 94 // The result bool value indicates whether the permission |
| 89 // change succeeded or not. You must check the result | 95 // change succeeded or not. You must check the result |
| 90 // (in most cases you need to RELEASE_ASSERT that it is | 96 // (in most cases you need to RELEASE_ASSERT that it is |
| 91 // true). | 97 // true). |
| 92 WTF_EXPORT WARN_UNUSED_RETURN bool setSystemPagesAccessible(void* addr, size_t l
en); | 98 WTF_EXPORT WARN_UNUSED_RETURN bool setSystemPagesAccessible(void* addr, |
| 99 size_t len); |
| 93 | 100 |
| 94 // Decommit one or more system pages. Decommitted means that the physical memory | 101 // Decommit one or more system pages. Decommitted means that the physical memory |
| 95 // is released to the system, but the virtual address space remains reserved. | 102 // is released to the system, but the virtual address space remains reserved. |
| 96 // System pages are re-committed by calling recommitSystemPages(). Touching | 103 // System pages are re-committed by calling recommitSystemPages(). Touching |
| 97 // a decommitted page _may_ fault. | 104 // a decommitted page _may_ fault. |
| 98 // Clients should not make any assumptions about the contents of decommitted | 105 // Clients should not make any assumptions about the contents of decommitted |
| 99 // system pages, before or after they write to the page. The only guarantee | 106 // system pages, before or after they write to the page. The only guarantee |
| 100 // provided is that the contents of the system page will be deterministic again | 107 // provided is that the contents of the system page will be deterministic again |
| 101 // after recommitting and writing to it. In particlar note that system pages are | 108 // after recommitting and writing to it. In particlar note that system pages are |
| 102 // not guaranteed to be zero-filled upon re-commit. len must be a multiple of | 109 // not guaranteed to be zero-filled upon re-commit. len must be a multiple of |
| (...skipping 16 matching lines...) Expand all Loading... |
| 119 // A read or write to a discarded page will not fault. | 126 // A read or write to a discarded page will not fault. |
| 120 // Reading from a discarded page may return the original page content, or a | 127 // Reading from a discarded page may return the original page content, or a |
| 121 // page full of zeroes. | 128 // page full of zeroes. |
| 122 // Writing to a discarded page is the only guaranteed way to tell the system | 129 // Writing to a discarded page is the only guaranteed way to tell the system |
| 123 // that the page is required again. Once written to, the content of the page is | 130 // that the page is required again. Once written to, the content of the page is |
| 124 // guaranteed stable once more. After being written to, the page content may be | 131 // guaranteed stable once more. After being written to, the page content may be |
| 125 // based on the original page content, or a page of zeroes. | 132 // based on the original page content, or a page of zeroes. |
| 126 // len must be a multiple of kSystemPageSize bytes. | 133 // len must be a multiple of kSystemPageSize bytes. |
| 127 WTF_EXPORT void discardSystemPages(void* addr, size_t len); | 134 WTF_EXPORT void discardSystemPages(void* addr, size_t len); |
| 128 | 135 |
| 129 } // namespace WTF | 136 } // namespace WTF |
| 130 | 137 |
| 131 #endif // WTF_PageAllocator_h | 138 #endif // WTF_PageAllocator_h |
| OLD | NEW |