| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // Clients should only call commit on uncommitted regions and decommit on co
mmitted regions. | 53 // Clients should only call commit on uncommitted regions and decommit on co
mmitted regions. |
| 54 static void commit(void*, size_t, bool writable, bool executable); | 54 static void commit(void*, size_t, bool writable, bool executable); |
| 55 static void decommit(void*, size_t); | 55 static void decommit(void*, size_t); |
| 56 | 56 |
| 57 // These methods are symmetric; reserveAndCommit allocates VM in an committe
d state, | 57 // These methods are symmetric; reserveAndCommit allocates VM in an committe
d state, |
| 58 // decommitAndRelease should be called on a region of VM allocated by a sing
le reservation, | 58 // decommitAndRelease should be called on a region of VM allocated by a sing
le reservation, |
| 59 // the memory must all currently be in a committed state. | 59 // the memory must all currently be in a committed state. |
| 60 WTF_EXPORT_PRIVATE static void* reserveAndCommit(size_t, Usage = UnknownUsag
e, bool writable = true, bool executable = false, bool includesGuardPages = fals
e); | 60 WTF_EXPORT_PRIVATE static void* reserveAndCommit(size_t, Usage = UnknownUsag
e, bool writable = true, bool executable = false, bool includesGuardPages = fals
e); |
| 61 static void decommitAndRelease(void* base, size_t size); | 61 static void decommitAndRelease(void* base, size_t size); |
| 62 | 62 |
| 63 // These methods are akin to reserveAndCommit/decommitAndRelease, above - ho
wever rather than | |
| 64 // committing/decommitting the entire region additional parameters allow a s
ubregion to be | |
| 65 // specified. | |
| 66 static void* reserveAndCommit(size_t reserveSize, size_t commitSize, Usage =
UnknownUsage, bool writable = true, bool executable = false); | |
| 67 static void decommitAndRelease(void* releaseBase, size_t releaseSize, void*
decommitBase, size_t decommitSize); | |
| 68 | |
| 69 // Reallocate an existing, committed allocation. | 63 // Reallocate an existing, committed allocation. |
| 70 // The prior allocation must be fully comitted, and the new size will also b
e fully committed. | 64 // The prior allocation must be fully comitted, and the new size will also b
e fully committed. |
| 71 // This interface is provided since it may be possible to optimize this oper
ation on some platforms. | 65 // This interface is provided since it may be possible to optimize this oper
ation on some platforms. |
| 72 template<typename T> | 66 template<typename T> |
| 73 static T* reallocateCommitted(T*, size_t oldSize, size_t newSize, Usage = Un
knownUsage, bool writable = true, bool executable = false); | 67 static T* reallocateCommitted(T*, size_t oldSize, size_t newSize, Usage = Un
knownUsage, bool writable = true, bool executable = false); |
| 74 }; | 68 }; |
| 75 | 69 |
| 76 inline void* OSAllocator::reserveAndCommit(size_t reserveSize, size_t commitSize
, Usage usage, bool writable, bool executable) | |
| 77 { | |
| 78 void* base = reserveUncommitted(reserveSize, usage, writable, executable); | |
| 79 commit(base, commitSize, writable, executable); | |
| 80 return base; | |
| 81 } | |
| 82 | |
| 83 inline void OSAllocator::decommitAndRelease(void* releaseBase, size_t releaseSiz
e, void* decommitBase, size_t decommitSize) | |
| 84 { | |
| 85 ASSERT(decommitBase >= releaseBase && (static_cast<char*>(decommitBase) + de
commitSize) <= (static_cast<char*>(releaseBase) + releaseSize)); | |
| 86 UNUSED_PARAM(decommitBase); | |
| 87 UNUSED_PARAM(decommitSize); | |
| 88 | |
| 89 releaseDecommitted(releaseBase, releaseSize); | |
| 90 } | |
| 91 | |
| 92 inline void OSAllocator::decommitAndRelease(void* base, size_t size) | 70 inline void OSAllocator::decommitAndRelease(void* base, size_t size) |
| 93 { | 71 { |
| 94 decommitAndRelease(base, size, base, size); | 72 releaseDecommitted(base, size); |
| 95 } | 73 } |
| 96 | 74 |
| 97 template<typename T> | 75 template<typename T> |
| 98 inline T* OSAllocator::reallocateCommitted(T* oldBase, size_t oldSize, size_t ne
wSize, Usage usage, bool writable, bool executable) | 76 inline T* OSAllocator::reallocateCommitted(T* oldBase, size_t oldSize, size_t ne
wSize, Usage usage, bool writable, bool executable) |
| 99 { | 77 { |
| 100 void* newBase = reserveAndCommit(newSize, usage, writable, executable); | 78 void* newBase = reserveAndCommit(newSize, usage, writable, executable); |
| 101 memcpy(newBase, oldBase, std::min(oldSize, newSize)); | 79 memcpy(newBase, oldBase, std::min(oldSize, newSize)); |
| 102 decommitAndRelease(oldBase, oldSize); | 80 decommitAndRelease(oldBase, oldSize); |
| 103 return static_cast<T*>(newBase); | 81 return static_cast<T*>(newBase); |
| 104 } | 82 } |
| 105 | 83 |
| 106 } // namespace WTF | 84 } // namespace WTF |
| 107 | 85 |
| 108 using WTF::OSAllocator; | 86 using WTF::OSAllocator; |
| 109 | 87 |
| 110 #endif // OSAllocator_h | 88 #endif // OSAllocator_h |
| OLD | NEW |