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

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

Issue 53004: Add basic infrastructure for protecting V8's heap when leaving the VM... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 9 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
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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 231 }
232 232
233 233
234 size_t OS::AllocateAlignment() { 234 size_t OS::AllocateAlignment() {
235 return sysconf(_SC_PAGESIZE); 235 return sysconf(_SC_PAGESIZE);
236 } 236 }
237 237
238 238
239 void* OS::Allocate(const size_t requested, 239 void* OS::Allocate(const size_t requested,
240 size_t* allocated, 240 size_t* allocated,
241 bool executable) { 241 bool is_executable) {
242 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE)); 242 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE));
243 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); 243 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
244 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 244 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
245 if (mbase == MAP_FAILED) { 245 if (mbase == MAP_FAILED) {
246 LOG(StringEvent("OS::Allocate", "mmap failed")); 246 LOG(StringEvent("OS::Allocate", "mmap failed"));
247 return NULL; 247 return NULL;
248 } 248 }
249 *allocated = msize; 249 *allocated = msize;
250 UpdateAllocatedSpaceLimits(mbase, msize); 250 UpdateAllocatedSpaceLimits(mbase, msize);
251 return mbase; 251 return mbase;
252 } 252 }
253 253
254 254
255 void OS::Free(void* buf, const size_t length) { 255 void OS::Free(void* address, const size_t size) {
256 // TODO(1240712): munmap has a return value which is ignored here. 256 // TODO(1240712): munmap has a return value which is ignored here.
Søren Thygesen Gjesse 2009/03/24 11:43:55 Move this issue to code.google.com/p/v8.
257 munmap(buf, length); 257 munmap(address, size);
258 } 258 }
259 259
260 260
261 #ifdef ENABLE_HEAP_PROTECTION
262
263 void OS::Protect(void* address, size_t size) {
264 // TODO(1240712): mprotect has a return value which is ignored here.
265 mprotect(address, size, PROT_READ);
266 }
267
268
269 void OS::Unprotect(void* address, size_t size, bool is_executable) {
270 // TODO(1240712): mprotect has a return value which is ignored here.
271 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
272 mprotect(address, size, prot);
273 }
274
275 #endif
276
277
261 void OS::Sleep(int milliseconds) { 278 void OS::Sleep(int milliseconds) {
262 unsigned int ms = static_cast<unsigned int>(milliseconds); 279 unsigned int ms = static_cast<unsigned int>(milliseconds);
263 usleep(1000 * ms); 280 usleep(1000 * ms);
264 } 281 }
265 282
266 283
267 void OS::Abort() { 284 void OS::Abort() {
268 // Redirect to std abort to signal abnormal program termination. 285 // Redirect to std abort to signal abnormal program termination.
269 abort(); 286 abort();
270 } 287 }
271 288
272 289
273 void OS::DebugBreak() { 290 void OS::DebugBreak() {
274 #if defined (__arm__) || defined(__thumb__) 291 #ifdef ARM
275 asm("bkpt 0"); 292 asm("bkpt 0");
276 #else 293 #else
277 asm("int $3"); 294 asm("int $3");
278 #endif 295 #endif
279 } 296 }
280 297
281 298
282 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 299 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
283 public: 300 public:
284 PosixMemoryMappedFile(FILE* file, void* memory, int size) 301 PosixMemoryMappedFile(FILE* file, void* memory, int size)
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (0 == munmap(address(), size())) address_ = MAP_FAILED; 432 if (0 == munmap(address(), size())) address_ = MAP_FAILED;
416 } 433 }
417 } 434 }
418 435
419 436
420 bool VirtualMemory::IsReserved() { 437 bool VirtualMemory::IsReserved() {
421 return address_ != MAP_FAILED; 438 return address_ != MAP_FAILED;
422 } 439 }
423 440
424 441
425 bool VirtualMemory::Commit(void* address, size_t size, bool executable) { 442 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
426 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); 443 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
427 if (MAP_FAILED == mmap(address, size, prot, 444 if (MAP_FAILED == mmap(address, size, prot,
428 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 445 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
429 kMmapFd, kMmapFdOffset)) { 446 kMmapFd, kMmapFdOffset)) {
430 return false; 447 return false;
431 } 448 }
432 449
433 UpdateAllocatedSpaceLimits(address, size); 450 UpdateAllocatedSpaceLimits(address, size);
434 return true; 451 return true;
435 } 452 }
436 453
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
912 } 929 }
913 930
914 // This sampler is no longer the active sampler. 931 // This sampler is no longer the active sampler.
915 active_sampler_ = NULL; 932 active_sampler_ = NULL;
916 active_ = false; 933 active_ = false;
917 } 934 }
918 935
919 #endif // ENABLE_LOGGING_AND_PROFILING 936 #endif // ENABLE_LOGGING_AND_PROFILING
920 937
921 } } // namespace v8::internal 938 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698