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

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

Issue 7468023: Revert "Implement mapping randomization for 64-bit Linux." (Closed) Base URL: https://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 = Isolate::UncheckedCurrent();
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 (isolate != NULL) {
87 #ifdef V8_TARGET_ARCH_X64
88 uint64_t rnd1 = V8::RandomPrivate(isolate);
89 uint64_t rnd2 = V8::RandomPrivate(isolate);
90 uint64_t raw_addr = (rnd1 << 32) ^ rnd2;
91 raw_addr &= V8_UINT64_C(0x3ffffffff000);
92 #else
93 uint32_t raw_addr = V8::RandomPrivate(isolate);
94 // The range 0x20000000 - 0x60000000 is relatively unpopulated across a
95 // variety of ASLR modes (PAE kernel, NX compat mode, etc).
96 raw_addr &= 0x3ffff000;
97 raw_addr += 0x20000000;
98 #endif
99 return reinterpret_cast<void*>(raw_addr);
100 }
101 return NULL;
102 }
103
104
105 void OS::Setup() { 81 void OS::Setup() {
106 // Seed the random number generator. We preserve microsecond resolution. 82 // Seed the random number generator.
107 uint64_t seed = Ticks() ^ (getpid() << 16); 83 // 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
85 // set to all ones. The seed will be identical for different instances that
86 // call this setup code within the same millisecond.
87 uint64_t seed = static_cast<uint64_t>(TimeCurrentMillis());
108 srandom(static_cast<unsigned int>(seed)); 88 srandom(static_cast<unsigned int>(seed));
109 limit_mutex = CreateMutex(); 89 limit_mutex = CreateMutex();
110 90
111 #ifdef __arm__ 91 #ifdef __arm__
112 // When running on ARM hardware check that the EABI used by V8 and 92 // When running on ARM hardware check that the EABI used by V8 and
113 // by the C code is the same. 93 // by the C code is the same.
114 bool hard_float = OS::ArmUsingHardFloat(); 94 bool hard_float = OS::ArmUsingHardFloat();
115 if (hard_float) { 95 if (hard_float) {
116 #if !USE_EABI_HARDFLOAT 96 #if !USE_EABI_HARDFLOAT
117 PrintF("ERROR: Binary compiled with -mfloat-abi=hard but without " 97 PrintF("ERROR: Binary compiled with -mfloat-abi=hard but without "
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 360
381 361
382 size_t OS::AllocateAlignment() { 362 size_t OS::AllocateAlignment() {
383 return sysconf(_SC_PAGESIZE); 363 return sysconf(_SC_PAGESIZE);
384 } 364 }
385 365
386 366
387 void* OS::Allocate(const size_t requested, 367 void* OS::Allocate(const size_t requested,
388 size_t* allocated, 368 size_t* allocated,
389 bool is_executable) { 369 bool is_executable) {
370 // TODO(805): Port randomization of allocated executable memory to Linux.
390 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE)); 371 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE));
391 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 372 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
392 void* addr = GetRandomMmapAddr(); 373 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
393 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
394 if (mbase == MAP_FAILED) { 374 if (mbase == MAP_FAILED) {
395 LOG(i::Isolate::Current(), 375 LOG(i::Isolate::Current(),
396 StringEvent("OS::Allocate", "mmap failed")); 376 StringEvent("OS::Allocate", "mmap failed"));
397 return NULL; 377 return NULL;
398 } 378 }
399 *allocated = msize; 379 *allocated = msize;
400 UpdateAllocatedSpaceLimits(mbase, msize); 380 UpdateAllocatedSpaceLimits(mbase, msize);
401 return mbase; 381 return mbase;
402 } 382 }
403 383
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 #endif // ndef __GLIBC__ 579 #endif // ndef __GLIBC__
600 } 580 }
601 581
602 582
603 // Constants used for mmap. 583 // Constants used for mmap.
604 static const int kMmapFd = -1; 584 static const int kMmapFd = -1;
605 static const int kMmapFdOffset = 0; 585 static const int kMmapFdOffset = 0;
606 586
607 587
608 VirtualMemory::VirtualMemory(size_t size) { 588 VirtualMemory::VirtualMemory(size_t size) {
609 address_ = mmap(GetRandomMmapAddr(), size, PROT_NONE, 589 address_ = mmap(NULL, size, PROT_NONE,
610 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, 590 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
611 kMmapFd, kMmapFdOffset); 591 kMmapFd, kMmapFdOffset);
612 size_ = size; 592 size_ = size;
613 } 593 }
614 594
615 595
616 VirtualMemory::~VirtualMemory() { 596 VirtualMemory::~VirtualMemory() {
617 if (IsReserved()) { 597 if (IsReserved()) {
618 if (0 == munmap(address(), size())) address_ = MAP_FAILED; 598 if (0 == munmap(address(), size())) address_ = MAP_FAILED;
619 } 599 }
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 1121
1142 1122
1143 void Sampler::Stop() { 1123 void Sampler::Stop() {
1144 ASSERT(IsActive()); 1124 ASSERT(IsActive());
1145 SignalSender::RemoveActiveSampler(this); 1125 SignalSender::RemoveActiveSampler(this);
1146 SetActive(false); 1126 SetActive(false);
1147 } 1127 }
1148 1128
1149 1129
1150 } } // namespace v8::internal 1130 } } // 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