| Line | Source | Count |
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | | - |
| 7 | | - |
| 8 | | - |
| 9 | | - |
| 10 | | - |
| 11 | | - |
| 12 | | - |
| 13 | | - |
| 14 | | - |
| 15 | | - |
| 16 | | - |
| 17 | | - |
| 18 | | - |
| 19 | | - |
| 20 | | - |
| 21 | | - |
| 22 | | - |
| 23 | | - |
| 24 | | - |
| 25 | | - |
| 26 | #include "config.h" | - |
| 27 | #include "PageAllocationAligned.h" | - |
| 28 | | - |
| 29 | namespace WTF { | - |
| 30 | | - |
| 31 | PageAllocationAligned PageAllocationAligned::allocate(size_t size, size_t alignment, OSAllocator::Usage usage, bool writable) | - |
| 32 | { | - |
| 33 | ASSERT(isPageAligned(size)); | - |
| 34 | ASSERT(isPageAligned(alignment)); | - |
| 35 | ASSERT(isPowerOfTwo(alignment)); | - |
| 36 | ASSERT(size >= alignment); | - |
| 37 | size_t alignmentMask = alignment - 1; | - |
| 38 | | - |
| 39 | #if OS(DARWIN) | - |
| 40 | int flags = VM_FLAGS_ANYWHERE; | - |
| 41 | if (usage != OSAllocator::UnknownUsage) | - |
| 42 | flags |= usage; | - |
| 43 | int protection = PROT_READ; | - |
| 44 | if (writable) | - |
| 45 | protection |= PROT_WRITE; | - |
| 46 | | - |
| 47 | vm_address_t address = 0; | - |
| 48 | vm_map(current_task(), &address, size, alignmentMask, flags, MEMORY_OBJECT_NULL, 0, FALSE, protection, PROT_READ | PROT_WRITE, VM_INHERIT_DEFAULT); | - |
| 49 | return PageAllocationAligned(reinterpret_cast<void*>(address), size); | - |
| 50 | #else | - |
| 51 | size_t alignmentDelta = alignment - pageSize(); | - |
| 52 | | - |
| 53 | | - |
| 54 | size_t reservationSize = size + alignmentDelta; | - |
| 55 | void* reservationBase = OSAllocator::reserveUncommitted(reservationSize, usage, writable); | - |
| 56 | | - |
| 57 | | - |
| 58 | void* alignedBase = reinterpret_cast<uintptr_t>(reservationBase) & alignmentMask| TRUE | never evaluated | | FALSE | never evaluated |
| 0 |
| 59 | ? reinterpret_cast<void*>((reinterpret_cast<uintptr_t>(reservationBase) & ~alignmentMask) + alignment) | - |
| 60 | : reservationBase; | - |
| 61 | OSAllocator::commit(alignedBase, size, writable, false); | - |
| 62 | | - |
| 63 | return PageAllocationAligned(alignedBase, size, reservationBase, reservationSize); never executed: return PageAllocationAligned(alignedBase, size, reservationBase, reservationSize); | 0 |
| 64 | #endif | - |
| 65 | } | - |
| 66 | | - |
| 67 | void PageAllocationAligned::deallocate() | - |
| 68 | { | - |
| 69 | | - |
| 70 | | - |
| 71 | PageAllocationAligned tmp; | - |
| 72 | std::swap(tmp, *this); | - |
| 73 | | - |
| 74 | ASSERT(tmp); | - |
| 75 | ASSERT(!*this); | - |
| 76 | | - |
| 77 | #if OS(DARWIN) | - |
| 78 | vm_deallocate(current_task(), reinterpret_cast<vm_address_t>(tmp.realBase()), tmp.realSize()); | - |
| 79 | #else | - |
| 80 | ASSERT(tmp.m_reservation.contains(tmp.realBase(), tmp.realSize())); | - |
| 81 | OSAllocator::decommitAndRelease(tmp.m_reservation.realBase(), tmp.m_reservation.realSize(), | - |
| 82 | tmp.realBase(), tmp.realSize()); | - |
| 83 | #endif | - |
| 84 | } never executed: end of block | 0 |
| 85 | | - |
| 86 | } | - |
| | |