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

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

Issue 7377008: Implement mapping randomization for 64-bit Linux. Notes: (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
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
« 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 72
73 double ceiling(double x) { 73 double ceiling(double x) {
74 return ceil(x); 74 return ceil(x);
75 } 75 }
76 76
77 77
78 static Mutex* limit_mutex = NULL; 78 static Mutex* limit_mutex = NULL;
79 79
80 80
81 static void* GetRandomMmapAddr() {
82 Isolate* isolate;
83 // Note that the current isolate isn't set up in a call path via
84 // CpuFeatures::Probe. We don't care about randomization in this case because
85 // the code page is immediately freed.
86 if (sizeof(void*) == 8 && (isolate = Isolate::UncheckedCurrent())) {
Vyacheslav Egorov (Chromium) 2011/07/15 11:36:23 I would prefer conditional compilation based on V8
87 uint32_t rnd1 = V8::RandomPrivate(isolate);
88 uint32_t rnd2 = V8::RandomPrivate(isolate);
89 uint64_t raw_addr = (static_cast<uint64_t>(rnd1) << 33) |
Vyacheslav Egorov (Chromium) 2011/07/15 12:29:39 I think it should be 34 not 33.
William Hesse 2011/07/15 12:43:22 All of the masking can be replaced by raw_addr =
90 (static_cast<uint64_t>(rnd2) << 2);
91 // Mask off the lower 12 and upper 18 bits. (v8 compile options do not
92 // permit the use of a 64-bit constant).
William Hesse 2011/07/15 12:43:22 There are macros in globals.h to enter 64-bit cons
93 raw_addr <<= 18;
Vyacheslav Egorov (Chromium) 2011/07/15 12:29:39 Look into globals.h. There are macroses that allow
94 raw_addr >>= 12 + 18;
95 raw_addr <<= 12;
96 return reinterpret_cast<void*>(raw_addr);
97 } else {
98 return NULL;
99 }
100 }
101
102
81 void OS::Setup() { 103 void OS::Setup() {
82 // Seed the random number generator. 104 // Seed the random number generator.
83 // Convert the current time to a 64-bit integer first, before converting it 105 // Convert the current time to a 64-bit integer first, before converting it
84 // to an unsigned. Going directly can cause an overflow and the seed to be 106 // to an unsigned. Going directly can cause an overflow and the seed to be
85 // set to all ones. The seed will be identical for different instances that 107 // set to all ones. The seed will be identical for different instances that
86 // call this setup code within the same millisecond. 108 // call this setup code within the same millisecond.
William Hesse 2011/07/15 12:43:22 Use XOR, not OR, to combine the overlapping seed s
87 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis()); 109 uint64_t seed = Ticks() | (getpid() << 16);
Vyacheslav Egorov (Chromium) 2011/07/15 11:36:23 I think the comment above needs updating.
88 srandom(static_cast<unsigned int>(seed)); 110 srandom(static_cast<unsigned int>(seed));
89 limit_mutex = CreateMutex(); 111 limit_mutex = CreateMutex();
90 112
91 #ifdef __arm__ 113 #ifdef __arm__
92 // When running on ARM hardware check that the EABI used by V8 and 114 // When running on ARM hardware check that the EABI used by V8 and
93 // by the C code is the same. 115 // by the C code is the same.
94 bool hard_float = OS::ArmUsingHardFloat(); 116 bool hard_float = OS::ArmUsingHardFloat();
95 if (hard_float) { 117 if (hard_float) {
96 #if !USE_EABI_HARDFLOAT 118 #if !USE_EABI_HARDFLOAT
97 PrintF("ERROR: Binary compiled with -mfloat-abi=hard but without " 119 PrintF("ERROR: Binary compiled with -mfloat-abi=hard but without "
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 382
361 383
362 size_t OS::AllocateAlignment() { 384 size_t OS::AllocateAlignment() {
363 return sysconf(_SC_PAGESIZE); 385 return sysconf(_SC_PAGESIZE);
364 } 386 }
365 387
366 388
367 void* OS::Allocate(const size_t requested, 389 void* OS::Allocate(const size_t requested,
368 size_t* allocated, 390 size_t* allocated,
369 bool is_executable) { 391 bool is_executable) {
370 // TODO(805): Port randomization of allocated executable memory to Linux.
371 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE)); 392 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE));
372 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 393 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
373 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 394 void* addr = GetRandomMmapAddr();
395 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
374 if (mbase == MAP_FAILED) { 396 if (mbase == MAP_FAILED) {
William Hesse 2011/07/15 12:43:22 I think you need to add the MAP_VARIABLE flag to t
375 LOG(i::Isolate::Current(), 397 LOG(i::Isolate::Current(),
376 StringEvent("OS::Allocate", "mmap failed")); 398 StringEvent("OS::Allocate", "mmap failed"));
377 return NULL; 399 return NULL;
378 } 400 }
379 *allocated = msize; 401 *allocated = msize;
380 UpdateAllocatedSpaceLimits(mbase, msize); 402 UpdateAllocatedSpaceLimits(mbase, msize);
381 return mbase; 403 return mbase;
382 } 404 }
383 405
384 406
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 #endif // ndef __GLIBC__ 601 #endif // ndef __GLIBC__
580 } 602 }
581 603
582 604
583 // Constants used for mmap. 605 // Constants used for mmap.
584 static const int kMmapFd = -1; 606 static const int kMmapFd = -1;
585 static const int kMmapFdOffset = 0; 607 static const int kMmapFdOffset = 0;
586 608
587 609
588 VirtualMemory::VirtualMemory(size_t size) { 610 VirtualMemory::VirtualMemory(size_t size) {
589 address_ = mmap(NULL, size, PROT_NONE, 611 address_ = mmap(GetRandomMmapAddr(), size, PROT_NONE,
590 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, 612 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
591 kMmapFd, kMmapFdOffset); 613 kMmapFd, kMmapFdOffset);
592 size_ = size; 614 size_ = size;
593 } 615 }
594 616
595 617
596 VirtualMemory::~VirtualMemory() { 618 VirtualMemory::~VirtualMemory() {
597 if (IsReserved()) { 619 if (IsReserved()) {
598 if (0 == munmap(address(), size())) address_ = MAP_FAILED; 620 if (0 == munmap(address(), size())) address_ = MAP_FAILED;
599 } 621 }
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 1142
1121 1143
1122 void Sampler::Stop() { 1144 void Sampler::Stop() {
1123 ASSERT(IsActive()); 1145 ASSERT(IsActive());
1124 SignalSender::RemoveActiveSampler(this); 1146 SignalSender::RemoveActiveSampler(this);
1125 SetActive(false); 1147 SetActive(false);
1126 } 1148 }
1127 1149
1128 1150
1129 } } // namespace v8::internal 1151 } } // 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