Chromium Code Reviews| 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(X86_64) | |
| 66 static bool architectureKnown = false; | |
| 67 static bool useHint = true; | |
| 68 if (!architectureKnown) { | |
| 69 SYSTEM_INFO systemInfo = { 0 }; | |
| 70 ::GetNativeSystemInfo(&systemInfo); | |
| 71 if (systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) | |
|
Chris Evans
2014/07/18 18:03:47
I don't understand this. It sounds from the CL des
Tom Sepez
2014/07/18 18:10:06
Exactly. Will add comment.
| |
| 72 useHint = false; | |
| 73 architectureKnown = true; | |
| 74 } | |
| 75 return useHint; | |
| 76 #else // !CPU(X86_64) | |
| 77 return true; | |
| 78 #endif // !CPU(X86_64) | |
| 79 } | |
| 80 | |
| 81 #endif // OS(WIN) | |
| 82 | |
| 61 // This simple internal function wraps the OS-specific page allocation call so | 83 // This simple internal function wraps the OS-specific page allocation call so |
| 62 // that it behaves consistently: the address is a hint and if it cannot be used, | 84 // that it behaves consistently: the address is a hint and if it cannot be used, |
| 63 // the allocation will be placed elsewhere. | 85 // the allocation will be placed elsewhere. |
| 64 static void* systemAllocPages(void* addr, size_t len) | 86 static void* systemAllocPages(void* addr, size_t len) |
| 65 { | 87 { |
| 66 ASSERT(!(len & kPageAllocationGranularityOffsetMask)); | 88 ASSERT(!(len & kPageAllocationGranularityOffsetMask)); |
| 67 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kPageAllocationGranularityOffse tMask)); | 89 ASSERT(!(reinterpret_cast<uintptr_t>(addr) & kPageAllocationGranularityOffse tMask)); |
| 68 void* ret; | 90 void* ret = 0; |
| 69 #if OS(WIN) | 91 #if OS(WIN) |
| 70 ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | 92 if (shouldUseAddressHint()) |
| 93 ret = VirtualAlloc(addr, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | |
| 71 if (!ret) | 94 if (!ret) |
| 72 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); | 95 ret = VirtualAlloc(0, len, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); |
| 73 #else | 96 #else |
| 74 ret = mmap(addr, len, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, - 1, 0); | 97 ret = mmap(addr, len, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, - 1, 0); |
| 75 if (ret == MAP_FAILED) | 98 if (ret == MAP_FAILED) |
| 76 ret = 0; | 99 ret = 0; |
| 77 #endif | 100 #endif |
| 78 return ret; | 101 return ret; |
| 79 } | 102 } |
| 80 | 103 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 ASSERT(!(len & kSystemPageOffsetMask)); | 239 ASSERT(!(len & kSystemPageOffsetMask)); |
| 217 #if OS(POSIX) | 240 #if OS(POSIX) |
| 218 (void) addr; | 241 (void) addr; |
| 219 #else | 242 #else |
| 220 setSystemPagesAccessible(addr, len); | 243 setSystemPagesAccessible(addr, len); |
| 221 #endif | 244 #endif |
| 222 } | 245 } |
| 223 | 246 |
| 224 } // namespace WTF | 247 } // namespace WTF |
| 225 | 248 |
| OLD | NEW |