| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 SYSTEM_INFO info; | 794 SYSTEM_INFO info; |
| 795 GetSystemInfo(&info); | 795 GetSystemInfo(&info); |
| 796 allocate_alignment = info.dwAllocationGranularity; | 796 allocate_alignment = info.dwAllocationGranularity; |
| 797 } | 797 } |
| 798 return allocate_alignment; | 798 return allocate_alignment; |
| 799 } | 799 } |
| 800 | 800 |
| 801 | 801 |
| 802 void* OS::Allocate(const size_t requested, | 802 void* OS::Allocate(const size_t requested, |
| 803 size_t* allocated, | 803 size_t* allocated, |
| 804 bool executable) { | 804 bool is_executable) { |
| 805 // VirtualAlloc rounds allocated size to page size automatically. | 805 // VirtualAlloc rounds allocated size to page size automatically. |
| 806 size_t msize = RoundUp(requested, GetPageSize()); | 806 size_t msize = RoundUp(requested, GetPageSize()); |
| 807 | 807 |
| 808 // Windows XP SP2 allows Data Excution Prevention (DEP). | 808 // Windows XP SP2 allows Data Excution Prevention (DEP). |
| 809 int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; | 809 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
| 810 LPVOID mbase = VirtualAlloc(NULL, msize, MEM_COMMIT | MEM_RESERVE, prot); | 810 LPVOID mbase = VirtualAlloc(NULL, msize, MEM_COMMIT | MEM_RESERVE, prot); |
| 811 if (mbase == NULL) { | 811 if (mbase == NULL) { |
| 812 LOG(StringEvent("OS::Allocate", "VirtualAlloc failed")); | 812 LOG(StringEvent("OS::Allocate", "VirtualAlloc failed")); |
| 813 return NULL; | 813 return NULL; |
| 814 } | 814 } |
| 815 | 815 |
| 816 ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment())); | 816 ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment())); |
| 817 | 817 |
| 818 *allocated = msize; | 818 *allocated = msize; |
| 819 UpdateAllocatedSpaceLimits(mbase, msize); | 819 UpdateAllocatedSpaceLimits(mbase, msize); |
| 820 return mbase; | 820 return mbase; |
| 821 } | 821 } |
| 822 | 822 |
| 823 | 823 |
| 824 void OS::Free(void* buf, const size_t length) { | 824 void OS::Free(void* address, const size_t size) { |
| 825 // TODO(1240712): VirtualFree has a return value which is ignored here. | 825 // TODO(1240712): VirtualFree has a return value which is ignored here. |
| 826 VirtualFree(buf, 0, MEM_RELEASE); | 826 VirtualFree(address, 0, MEM_RELEASE); |
| 827 USE(length); | 827 USE(size); |
| 828 } | 828 } |
| 829 | 829 |
| 830 | 830 |
| 831 #ifdef ENABLE_HEAP_PROTECTION |
| 832 |
| 833 void OS::Protect(void* address, size_t size) { |
| 834 // TODO(1240712): VirtualProtect has a return value which is ignored here. |
| 835 DWORD old_protect; |
| 836 VirtualProtect(address, size, PAGE_READONLY, &old_protect); |
| 837 } |
| 838 |
| 839 |
| 840 void OS::Unprotect(void* address, size_t size, bool is_executable) { |
| 841 // TODO(1240712): VirtualProtect has a return value which is ignored here. |
| 842 DWORD new_protect = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
| 843 DWORD old_protect; |
| 844 VirtualProtect(address, size, new_protect, &old_protect); |
| 845 } |
| 846 |
| 847 #endif |
| 848 |
| 849 |
| 831 void OS::Sleep(int milliseconds) { | 850 void OS::Sleep(int milliseconds) { |
| 832 ::Sleep(milliseconds); | 851 ::Sleep(milliseconds); |
| 833 } | 852 } |
| 834 | 853 |
| 835 | 854 |
| 836 void OS::Abort() { | 855 void OS::Abort() { |
| 837 if (!IsDebuggerPresent()) { | 856 if (!IsDebuggerPresent()) { |
| 838 #ifdef _MSC_VER | 857 #ifdef _MSC_VER |
| 839 // Make the MSVCRT do a silent abort. | 858 // Make the MSVCRT do a silent abort. |
| 840 _set_abort_behavior(0, _WRITE_ABORT_MSG); | 859 _set_abort_behavior(0, _WRITE_ABORT_MSG); |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1292 } | 1311 } |
| 1293 | 1312 |
| 1294 | 1313 |
| 1295 VirtualMemory::~VirtualMemory() { | 1314 VirtualMemory::~VirtualMemory() { |
| 1296 if (IsReserved()) { | 1315 if (IsReserved()) { |
| 1297 if (0 == VirtualFree(address(), 0, MEM_RELEASE)) address_ = NULL; | 1316 if (0 == VirtualFree(address(), 0, MEM_RELEASE)) address_ = NULL; |
| 1298 } | 1317 } |
| 1299 } | 1318 } |
| 1300 | 1319 |
| 1301 | 1320 |
| 1302 bool VirtualMemory::Commit(void* address, size_t size, bool executable) { | 1321 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) { |
| 1303 int prot = executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; | 1322 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
| 1304 if (NULL == VirtualAlloc(address, size, MEM_COMMIT, prot)) { | 1323 if (NULL == VirtualAlloc(address, size, MEM_COMMIT, prot)) { |
| 1305 return false; | 1324 return false; |
| 1306 } | 1325 } |
| 1307 | 1326 |
| 1308 UpdateAllocatedSpaceLimits(address, size); | 1327 UpdateAllocatedSpaceLimits(address, size); |
| 1309 return true; | 1328 return true; |
| 1310 } | 1329 } |
| 1311 | 1330 |
| 1312 | 1331 |
| 1313 bool VirtualMemory::Uncommit(void* address, size_t size) { | 1332 bool VirtualMemory::Uncommit(void* address, size_t size) { |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1829 | 1848 |
| 1830 // Release the thread handles | 1849 // Release the thread handles |
| 1831 CloseHandle(data_->sampler_thread_); | 1850 CloseHandle(data_->sampler_thread_); |
| 1832 CloseHandle(data_->profiled_thread_); | 1851 CloseHandle(data_->profiled_thread_); |
| 1833 } | 1852 } |
| 1834 | 1853 |
| 1835 | 1854 |
| 1836 #endif // ENABLE_LOGGING_AND_PROFILING | 1855 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1837 | 1856 |
| 1838 } } // namespace v8::internal | 1857 } } // namespace v8::internal |
| OLD | NEW |