| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 #elif OS(WIN) | 51 #elif OS(WIN) |
| 52 | 52 |
| 53 #include <windows.h> | 53 #include <windows.h> |
| 54 | 54 |
| 55 #else | 55 #else |
| 56 #error Unknown OS | 56 #error Unknown OS |
| 57 #endif // OS(POSIX) | 57 #endif // OS(POSIX) |
| 58 | 58 |
| 59 namespace WTF { | 59 namespace WTF { |
| 60 | 60 |
| 61 #if OS(WIN) | |
| 62 | |
| 63 static bool shouldUseAddressHint() | |
| 64 { | |
| 65 #if CPU(32BIT) | |
| 66 // When running 32-bit processes under 32-bit Windows, the userspace is | |
| 67 // limited to 2 GB, and we risk fragmenting it badly if we allow further | |
| 68 // randomization via our address hint. On the other hand, if the process | |
| 69 // is running under WOW64, then it has at least 3 GB available (and likely | |
| 70 // 4 GB depending upon the OS version), and we want use the additional | |
| 71 // randomness. | |
| 72 // TODO(tsepez): presently disabled due to IsWow64Process() compatibility. | |
| 73 return true; | |
| 74 #else // CPU(32BIT) | |
| 75 return true; | |
| 76 #endif // CPU(32BIT) | |
| 77 } | |
| 78 | |
| 79 #endif // OS(WIN) | |
| 80 | |
| 81 // This simple internal function wraps the OS-specific page allocation call so | 61 // This simple internal function wraps the OS-specific page allocation call so |
| 82 // that it behaves consistently: the address is a hint and if it cannot be used, | 62 // that it behaves consistently: the address is a hint and if it cannot be used, |
| 83 // the allocation will be placed elsewhere. | 63 // the allocation will be placed elsewhere. |
| 84 static void* systemAllocPages(void* addr, size_t len, PageAccessibilityConfigura
tion pageAccessibility) | 64 static void* systemAllocPages(void* addr, size_t len, PageAccessibilityConfigura
tion pageAccessibility) |
| 85 { | 65 { |
| 86 ASSERT(!(len & kPageAllocationGranularityOffsetMask)); | 66 ASSERT(!(len & kPageAllocationGranularityOffsetMask)); |
| 87 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kPageAllocationGranularityOffse
tMask)); | 67 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kPageAllocationGranularityOffse
tMask)); |
| 88 void* ret = 0; | 68 void* ret; |
| 89 #if OS(WIN) | 69 #if OS(WIN) |
| 90 int accessFlag = pageAccessibility == PageAccessible ? PAGE_READWRITE : PAGE
_NOACCESS; | 70 int accessFlag = pageAccessibility == PageAccessible ? PAGE_READWRITE : PAGE
_NOACCESS; |
| 91 if (shouldUseAddressHint()) | 71 ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, accessFlag); |
| 92 ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, accessFlag); | |
| 93 if (!ret) | 72 if (!ret) |
| 94 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, accessFlag); | 73 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, accessFlag); |
| 95 #else | 74 #else |
| 96 int accessFlag = pageAccessibility == PageAccessible ? (PROT_READ | PROT_WRI
TE) : PROT_NONE; | 75 int accessFlag = pageAccessibility == PageAccessible ? (PROT_READ | PROT_WRI
TE) : PROT_NONE; |
| 97 ret = mmap(addr, len, accessFlag, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); | 76 ret = mmap(addr, len, accessFlag, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); |
| 98 if (ret == MAP_FAILED) | 77 if (ret == MAP_FAILED) |
| 99 ret = 0; | 78 ret = 0; |
| 100 #endif | 79 #endif |
| 101 return ret; | 80 return ret; |
| 102 } | 81 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 ASSERT(!(len & kSystemPageOffsetMask)); | 216 ASSERT(!(len & kSystemPageOffsetMask)); |
| 238 #if OS(POSIX) | 217 #if OS(POSIX) |
| 239 (void) addr; | 218 (void) addr; |
| 240 #else | 219 #else |
| 241 RELEASE_ASSERT(setSystemPagesAccessible(addr, len)); | 220 RELEASE_ASSERT(setSystemPagesAccessible(addr, len)); |
| 242 #endif | 221 #endif |
| 243 } | 222 } |
| 244 | 223 |
| 245 } // namespace WTF | 224 } // namespace WTF |
| 246 | 225 |
| OLD | NEW |