| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 void discardSystemPages(void* addr, size_t len) | 237 void discardSystemPages(void* addr, size_t len) |
| 238 { | 238 { |
| 239 ASSERT(!(len & kSystemPageOffsetMask)); | 239 ASSERT(!(len & kSystemPageOffsetMask)); |
| 240 #if OS(POSIX) | 240 #if OS(POSIX) |
| 241 // On POSIX, the implementation detail is that discard and decommit are the | 241 // On POSIX, the implementation detail is that discard and decommit are the |
| 242 // same, and lead to pages that are returned to the system immediately and | 242 // same, and lead to pages that are returned to the system immediately and |
| 243 // get replaced with zeroed pages when touched. So we just call | 243 // get replaced with zeroed pages when touched. So we just call |
| 244 // decommitSystemPages() here to avoid code duplication. | 244 // decommitSystemPages() here to avoid code duplication. |
| 245 decommitSystemPages(addr, len); | 245 decommitSystemPages(addr, len); |
| 246 #else | 246 #else |
| 247 (void) addr; | 247 // On Windows discarded pages are not returned to the system immediately and |
| 248 (void) len; | 248 // not guaranteed to be zeroed when returned to the application. |
| 249 // TODO(cevans): implement this using MEM_RESET for Windows, once we've | 249 using DiscardVirtualMemoryFunction = DWORD(WINAPI*)(PVOID virtualAddress, SI
ZE_T size); |
| 250 // decided that the semantics are a match. | 250 static DiscardVirtualMemoryFunction discardVirtualMemory = reinterpret_cast<
DiscardVirtualMemoryFunction>(-1); |
| 251 if (discardVirtualMemory == reinterpret_cast<DiscardVirtualMemoryFunction>(-
1)) |
| 252 discardVirtualMemory = reinterpret_cast<DiscardVirtualMemoryFunction>(Ge
tProcAddress(GetModuleHandle(L"Kernel32.dll"), "DiscardVirtualMemory")); |
| 253 // Use DiscardVirtualMemory when available because it releases faster than M
EM_RESET. |
| 254 DWORD ret = 1; |
| 255 if (discardVirtualMemory) |
| 256 ret = discardVirtualMemory(addr, len); |
| 257 // DiscardVirtualMemory is buggy in Win10 SP0, so fall back to MEM_RESET on
failure. |
| 258 if (ret) { |
| 259 void* ret = VirtualAlloc(addr, len, MEM_RESET, PAGE_READWRITE); |
| 260 RELEASE_ASSERT(ret); |
| 261 } |
| 251 #endif | 262 #endif |
| 252 } | 263 } |
| 253 | 264 |
| 254 } // namespace WTF | 265 } // namespace WTF |
| 255 | 266 |
| OLD | NEW |