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

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

Issue 7352007: Add guard pages in front of platform allocations (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 9 years, 5 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
« src/platform-linux.cc ('K') | « src/platform-macos.cc ('k') | 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 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 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 906
907 // For exectutable pages try and randomize the allocation address 907 // For exectutable pages try and randomize the allocation address
908 if (prot == PAGE_EXECUTE_READWRITE && 908 if (prot == PAGE_EXECUTE_READWRITE &&
909 msize >= static_cast<size_t>(Page::kPageSize)) { 909 msize >= static_cast<size_t>(Page::kPageSize)) {
910 address = (V8::RandomPrivate(Isolate::Current()) << kPageSizeBits) 910 address = (V8::RandomPrivate(Isolate::Current()) << kPageSizeBits)
911 | kAllocationRandomAddressMin; 911 | kAllocationRandomAddressMin;
912 address &= kAllocationRandomAddressMax; 912 address &= kAllocationRandomAddressMax;
913 } 913 }
914 914
915 LPVOID mbase = VirtualAlloc(reinterpret_cast<void *>(address), 915 LPVOID mbase = VirtualAlloc(reinterpret_cast<void *>(address),
916 msize, 916 msize + Page::kPageSize,
Vyacheslav Egorov (Chromium) 2011/07/12 23:23:29 This looks slightly suspicious to me. MemoryAlloc
Cris Neckar 2011/07/14 17:32:28 Done.
917 MEM_COMMIT | MEM_RESERVE, 917 MEM_COMMIT | MEM_RESERVE,
918 prot); 918 prot);
919 if (mbase == NULL && address != 0) 919 if (mbase == NULL && address != 0)
920 mbase = VirtualAlloc(NULL, msize, MEM_COMMIT | MEM_RESERVE, prot); 920 mbase = VirtualAlloc(NULL,
921 msize + Page::kPageSize,
922 MEM_COMMIT | MEM_RESERVE,
923 prot);
921 924
922 if (mbase == NULL) { 925 if (mbase == NULL) {
923 LOG(ISOLATE, StringEvent("OS::Allocate", "VirtualAlloc failed")); 926 LOG(ISOLATE, StringEvent("OS::Allocate", "VirtualAlloc failed"));
924 return NULL; 927 return NULL;
925 } 928 }
926 929
927 ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment())); 930 ASSERT(IsAligned(reinterpret_cast<size_t>(mbase), OS::AllocateAlignment()));
931 *allocated = msize;
928 932
929 *allocated = msize; 933 DWORD old_protect;
934 VirtualProtect(mbase, Page::kPageSize, PAGE_READONLY | PAGE_GUARD, &old_protec t);
935 mbase = static_cast<BYTE*>(mbase) + Page::kPageSize;
936
930 UpdateAllocatedSpaceLimits(mbase, static_cast<int>(msize)); 937 UpdateAllocatedSpaceLimits(mbase, static_cast<int>(msize));
931 return mbase; 938 return mbase;
932 } 939 }
933 940
934 941
935 void OS::Free(void* address, const size_t size) { 942 void OS::Free(void* address, const size_t size) {
936 // TODO(1240712): VirtualFree has a return value which is ignored here. 943 // TODO(1240712): VirtualFree has a return value which is ignored here.
937 VirtualFree(address, 0, MEM_RELEASE); 944 VirtualFree(static_cast<BYTE*>(address) - Page::kPageSize, 0, MEM_RELEASE);
938 USE(size); 945 USE(size);
939 } 946 }
940 947
941 948
942 #ifdef ENABLE_HEAP_PROTECTION 949 #ifdef ENABLE_HEAP_PROTECTION
943 950
944 void OS::Protect(void* address, size_t size) { 951 void OS::Protect(void* address, size_t size) {
945 // TODO(1240712): VirtualProtect has a return value which is ignored here. 952 // TODO(1240712): VirtualProtect has a return value which is ignored here.
946 DWORD old_protect; 953 DWORD old_protect;
947 VirtualProtect(address, size, PAGE_READONLY, &old_protect); 954 VirtualProtect(address, size, PAGE_READONLY, &old_protect);
(...skipping 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
2030 2037
2031 void Sampler::Stop() { 2038 void Sampler::Stop() {
2032 ASSERT(IsActive()); 2039 ASSERT(IsActive());
2033 SamplerThread::RemoveActiveSampler(this); 2040 SamplerThread::RemoveActiveSampler(this);
2034 SetActive(false); 2041 SetActive(false);
2035 } 2042 }
2036 2043
2037 #endif // ENABLE_LOGGING_AND_PROFILING 2044 #endif // ENABLE_LOGGING_AND_PROFILING
2038 2045
2039 } } // namespace v8::internal 2046 } } // namespace v8::internal
OLDNEW
« src/platform-linux.cc ('K') | « src/platform-macos.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698