| 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 822 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 } | 833 } |
| 834 return allocate_alignment; | 834 return allocate_alignment; |
| 835 } | 835 } |
| 836 | 836 |
| 837 | 837 |
| 838 void* OS::Allocate(const size_t requested, | 838 void* OS::Allocate(const size_t requested, |
| 839 size_t* allocated, | 839 size_t* allocated, |
| 840 bool is_executable) { | 840 bool is_executable) { |
| 841 // VirtualAlloc rounds allocated size to page size automatically. | 841 // VirtualAlloc rounds allocated size to page size automatically. |
| 842 size_t msize = RoundUp(requested, static_cast<int>(GetPageSize())); | 842 size_t msize = RoundUp(requested, static_cast<int>(GetPageSize())); |
| 843 | 843 intptr_t address = NULL; |
| 844 // Windows XP SP2 allows Data Excution Prevention (DEP). | 844 // Windows XP SP2 allows Data Excution Prevention (DEP). |
| 845 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; | 845 int prot = is_executable ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; |
| 846 LPVOID mbase = VirtualAlloc(NULL, msize, MEM_COMMIT | MEM_RESERVE, prot); | 846 // TODO(805): Port to Linux |
| 847 // For exectutable pages try and randomize the allocation address |
| 848 if (prot == PAGE_EXECUTE_READWRITE && msize >= Page::kPageSize) { |
| 849 address = (V8::Random() << kPageSizeBits) | kAllocationRandomAddressMin; |
| 850 address &= kAllocationRandomAddressMax; |
| 851 } |
| 852 |
| 853 LPVOID mbase = VirtualAlloc(reinterpret_cast<void *>(address), |
| 854 msize, |
| 855 MEM_COMMIT | MEM_RESERVE, |
| 856 prot); |
| 857 if (mbase == NULL && address != NULL) |
| 858 mbase = VirtualAlloc(NULL, msize, MEM_COMMIT | MEM_RESERVE, prot); |
| 859 |
| 847 if (mbase == NULL) { | 860 if (mbase == NULL) { |
| 848 LOG(StringEvent("OS::Allocate", "VirtualAlloc failed")); | 861 LOG(StringEvent("OS::Allocate", "VirtualAlloc failed")); |
| 849 return NULL; | 862 return NULL; |
| 850 } | 863 } |
| 851 | 864 |
| 852 ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment())); | 865 ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment())); |
| 853 | 866 |
| 854 *allocated = msize; | 867 *allocated = msize; |
| 855 UpdateAllocatedSpaceLimits(mbase, static_cast<int>(msize)); | 868 UpdateAllocatedSpaceLimits(mbase, static_cast<int>(msize)); |
| 856 return mbase; | 869 return mbase; |
| (...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1902 | 1915 |
| 1903 // Release the thread handles | 1916 // Release the thread handles |
| 1904 CloseHandle(data_->sampler_thread_); | 1917 CloseHandle(data_->sampler_thread_); |
| 1905 CloseHandle(data_->profiled_thread_); | 1918 CloseHandle(data_->profiled_thread_); |
| 1906 } | 1919 } |
| 1907 | 1920 |
| 1908 | 1921 |
| 1909 #endif // ENABLE_LOGGING_AND_PROFILING | 1922 #endif // ENABLE_LOGGING_AND_PROFILING |
| 1910 | 1923 |
| 1911 } } // namespace v8::internal | 1924 } } // namespace v8::internal |
| OLD | NEW |