Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: src/platform-win32.cc

Issue 9433051: RandomizedVirtualAlloc should check for isolate presence instead of using Isolate::Current() (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 if (allocate_alignment == 0) { 830 if (allocate_alignment == 0) {
831 SYSTEM_INFO info; 831 SYSTEM_INFO info;
832 GetSystemInfo(&info); 832 GetSystemInfo(&info);
833 allocate_alignment = info.dwAllocationGranularity; 833 allocate_alignment = info.dwAllocationGranularity;
834 } 834 }
835 return allocate_alignment; 835 return allocate_alignment;
836 } 836 }
837 837
838 838
839 static void* GetRandomAddr() { 839 static void* GetRandomAddr() {
840 // The address range used to randomize RWX allocations in OS::Allocate 840 Isolate* isolate = Isolate::UncheckedCurrent();
841 // Try not to map pages into the default range that windows loads DLLs 841 // Note that the current isolate isn't set up in a call path via
842 // Use a multiple of 64k to prevent committing unused memory. 842 // CpuFeatures::Probe. We don't care about randomization in this case because
843 // Note: This does not guarantee RWX regions will be within the 843 // the code page is immediately freed.
844 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax 844 if (isolate != NULL) {
845 // The address range used to randomize RWX allocations in OS::Allocate
846 // Try not to map pages into the default range that windows loads DLLs
847 // Use a multiple of 64k to prevent committing unused memory.
848 // Note: This does not guarantee RWX regions will be within the
849 // range kAllocationRandomAddressMin to kAllocationRandomAddressMax
845 #ifdef V8_HOST_ARCH_64_BIT 850 #ifdef V8_HOST_ARCH_64_BIT
846 static const intptr_t kAllocationRandomAddressMin = 0x0000000080000000; 851 static const intptr_t kAllocationRandomAddressMin = 0x0000000080000000;
847 static const intptr_t kAllocationRandomAddressMax = 0x000003FFFFFF0000; 852 static const intptr_t kAllocationRandomAddressMax = 0x000003FFFFFF0000;
848 #else 853 #else
849 static const intptr_t kAllocationRandomAddressMin = 0x04000000; 854 static const intptr_t kAllocationRandomAddressMin = 0x04000000;
850 static const intptr_t kAllocationRandomAddressMax = 0x3FFF0000; 855 static const intptr_t kAllocationRandomAddressMax = 0x3FFF0000;
851 #endif 856 #endif
852 uintptr_t address = (V8::RandomPrivate(Isolate::Current()) << kPageSizeBits) 857 uintptr_t address = (V8::RandomPrivate(isolate) << kPageSizeBits)
853 | kAllocationRandomAddressMin; 858 | kAllocationRandomAddressMin;
854 address &= kAllocationRandomAddressMax; 859 address &= kAllocationRandomAddressMax;
855 return reinterpret_cast<void *>(address); 860 return reinterpret_cast<void *>(address);
861 }
862 return NULL;
856 } 863 }
857 864
858 865
859 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) { 866 static void* RandomizedVirtualAlloc(size_t size, int action, int protection) {
860 LPVOID base = NULL; 867 LPVOID base = NULL;
861 868
862 if (protection == PAGE_EXECUTE_READWRITE || protection == PAGE_NOACCESS) { 869 if (protection == PAGE_EXECUTE_READWRITE || protection == PAGE_NOACCESS) {
863 // For exectutable pages try and randomize the allocation address 870 // For exectutable pages try and randomize the allocation address
864 for (size_t attempts = 0; base == NULL && attempts < 3; ++attempts) { 871 for (size_t attempts = 0; base == NULL && attempts < 3; ++attempts) {
865 base = VirtualAlloc(GetRandomAddr(), size, action, protection); 872 base = VirtualAlloc(GetRandomAddr(), size, action, protection);
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2051 2058
2052 2059
2053 void Sampler::Stop() { 2060 void Sampler::Stop() {
2054 ASSERT(IsActive()); 2061 ASSERT(IsActive());
2055 SamplerThread::RemoveActiveSampler(this); 2062 SamplerThread::RemoveActiveSampler(this);
2056 SetActive(false); 2063 SetActive(false);
2057 } 2064 }
2058 2065
2059 2066
2060 } } // namespace v8::internal 2067 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698