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/base/platform/platform-linux.cc

Issue 521473003: More PNaCL fixes (without GYP/Makefile tweaks) (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 3 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 | src/base/platform/platform-posix.cc » ('j') | 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 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Platform-specific code for Linux goes here. For the POSIX-compatible 5 // Platform-specific code for Linux goes here. For the POSIX-compatible
6 // parts, the implementation is in platform-posix.cc. 6 // parts, the implementation is in platform-posix.cc.
7 7
8 #include <pthread.h> 8 #include <pthread.h>
9 #include <semaphore.h> 9 #include <semaphore.h>
10 #include <signal.h> 10 #include <signal.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
12 #include <sys/prctl.h>
13 #include <sys/resource.h> 12 #include <sys/resource.h>
14 #include <sys/syscall.h>
15 #include <sys/time.h> 13 #include <sys/time.h>
16 #include <sys/types.h> 14 #include <sys/types.h>
17 15
18 // Ubuntu Dapper requires memory pages to be marked as 16 // Ubuntu Dapper requires memory pages to be marked as
19 // executable. Otherwise, OS raises an exception when executing code 17 // executable. Otherwise, OS raises an exception when executing code
20 // in that page. 18 // in that page.
21 #include <errno.h> 19 #include <errno.h>
22 #include <fcntl.h> // open 20 #include <fcntl.h> // open
23 #include <stdarg.h> 21 #include <stdarg.h>
24 #include <strings.h> // index 22 #include <strings.h> // index
(...skipping 14 matching lines...) Expand all
39 #include <sanitizer/lsan_interface.h> 37 #include <sanitizer/lsan_interface.h>
40 #endif 38 #endif
41 39
42 #include <cmath> 40 #include <cmath>
43 41
44 #undef MAP_TYPE 42 #undef MAP_TYPE
45 43
46 #include "src/base/macros.h" 44 #include "src/base/macros.h"
47 #include "src/base/platform/platform.h" 45 #include "src/base/platform/platform.h"
48 46
47 #if V8_OS_NACL
48 #if !defined(MAP_NORESERVE)
49 // PNaCL doesn't have this, so we always grab all of the memory, which is bad.
50 #define MAP_NORESERVE 0
51 #endif
52 #else
53 #include <sys/prctl.h>
54 #include <sys/syscall.h>
55 #endif
49 56
50 namespace v8 { 57 namespace v8 {
51 namespace base { 58 namespace base {
52 59
53 60
54 #ifdef __arm__ 61 #ifdef __arm__
55 62
56 bool OS::ArmUsingHardFloat() { 63 bool OS::ArmUsingHardFloat() {
57 // GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify 64 // GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
58 // the Floating Point ABI used (PCS stands for Procedure Call Standard). 65 // the Floating Point ABI used (PCS stands for Procedure Call Standard).
(...skipping 29 matching lines...) Expand all
88 95
89 #endif 96 #endif
90 #endif 97 #endif
91 #undef GCC_VERSION 98 #undef GCC_VERSION
92 } 99 }
93 100
94 #endif // def __arm__ 101 #endif // def __arm__
95 102
96 103
97 const char* OS::LocalTimezone(double time, TimezoneCache* cache) { 104 const char* OS::LocalTimezone(double time, TimezoneCache* cache) {
105 #if V8_OS_NACL
106 // Missing support for tm_zone field.
107 return "";
108 #else
98 if (std::isnan(time)) return ""; 109 if (std::isnan(time)) return "";
99 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond)); 110 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));
100 struct tm* t = localtime(&tv); 111 struct tm* t = localtime(&tv);
101 if (NULL == t) return ""; 112 if (NULL == t) return "";
102 return t->tm_zone; 113 return t->tm_zone;
114 #endif
103 } 115 }
104 116
105 117
106 double OS::LocalTimeOffset(TimezoneCache* cache) { 118 double OS::LocalTimeOffset(TimezoneCache* cache) {
119 #if V8_OS_NACL
120 // Missing support for tm_zone field.
121 return 0;
122 #else
107 time_t tv = time(NULL); 123 time_t tv = time(NULL);
108 struct tm* t = localtime(&tv); 124 struct tm* t = localtime(&tv);
109 // tm_gmtoff includes any daylight savings offset, so subtract it. 125 // tm_gmtoff includes any daylight savings offset, so subtract it.
110 return static_cast<double>(t->tm_gmtoff * msPerSecond - 126 return static_cast<double>(t->tm_gmtoff * msPerSecond -
111 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0)); 127 (t->tm_isdst > 0 ? 3600 * msPerSecond : 0));
128 #endif
112 } 129 }
113 130
114 131
115 void* OS::Allocate(const size_t requested, 132 void* OS::Allocate(const size_t requested,
116 size_t* allocated, 133 size_t* allocated,
117 bool is_executable) { 134 bool is_executable) {
118 const size_t msize = RoundUp(requested, AllocateAlignment()); 135 const size_t msize = RoundUp(requested, AllocateAlignment());
119 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 136 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
120 void* addr = OS::GetRandomMmapAddr(); 137 void* addr = OS::GetRandomMmapAddr();
121 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 138 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // do a mmap with a name known by ll_prof.py and immediately munmap 270 // do a mmap with a name known by ll_prof.py and immediately munmap
254 // it. This injects a GC marker into the stream of events generated 271 // it. This injects a GC marker into the stream of events generated
255 // by the kernel and allows us to synchronize V8 code log and the 272 // by the kernel and allows us to synchronize V8 code log and the
256 // kernel log. 273 // kernel log.
257 int size = sysconf(_SC_PAGESIZE); 274 int size = sysconf(_SC_PAGESIZE);
258 FILE* f = fopen(OS::GetGCFakeMMapFile(), "w+"); 275 FILE* f = fopen(OS::GetGCFakeMMapFile(), "w+");
259 if (f == NULL) { 276 if (f == NULL) {
260 OS::PrintError("Failed to open %s\n", OS::GetGCFakeMMapFile()); 277 OS::PrintError("Failed to open %s\n", OS::GetGCFakeMMapFile());
261 OS::Abort(); 278 OS::Abort();
262 } 279 }
263 void* addr = mmap(OS::GetRandomMmapAddr(), 280 void* addr = mmap(OS::GetRandomMmapAddr(), size,
264 size, 281 #if V8_OS_NACL
265 #if defined(__native_client__)
266 // The Native Client port of V8 uses an interpreter, 282 // The Native Client port of V8 uses an interpreter,
267 // so code pages don't need PROT_EXEC. 283 // so code pages don't need PROT_EXEC.
268 PROT_READ, 284 PROT_READ,
269 #else 285 #else
270 PROT_READ | PROT_EXEC, 286 PROT_READ | PROT_EXEC,
271 #endif 287 #endif
272 MAP_PRIVATE, 288 MAP_PRIVATE, fileno(f), 0);
273 fileno(f),
274 0);
275 DCHECK(addr != MAP_FAILED); 289 DCHECK(addr != MAP_FAILED);
276 OS::Free(addr, size); 290 OS::Free(addr, size);
277 fclose(f); 291 fclose(f);
278 } 292 }
279 293
280 294
281 // Constants used for mmap. 295 // Constants used for mmap.
282 static const int kMmapFd = -1; 296 static const int kMmapFd = -1;
283 static const int kMmapFdOffset = 0; 297 static const int kMmapFdOffset = 0;
284 298
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 if (result == MAP_FAILED) return NULL; 394 if (result == MAP_FAILED) return NULL;
381 395
382 #if defined(LEAK_SANITIZER) 396 #if defined(LEAK_SANITIZER)
383 __lsan_register_root_region(result, size); 397 __lsan_register_root_region(result, size);
384 #endif 398 #endif
385 return result; 399 return result;
386 } 400 }
387 401
388 402
389 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { 403 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
390 #if defined(__native_client__) 404 #if V8_OS_NACL
391 // The Native Client port of V8 uses an interpreter, 405 // The Native Client port of V8 uses an interpreter,
392 // so code pages don't need PROT_EXEC. 406 // so code pages don't need PROT_EXEC.
393 int prot = PROT_READ | PROT_WRITE; 407 int prot = PROT_READ | PROT_WRITE;
394 #else 408 #else
395 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 409 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
396 #endif 410 #endif
397 if (MAP_FAILED == mmap(base, 411 if (MAP_FAILED == mmap(base,
398 size, 412 size,
399 prot, 413 prot,
400 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 414 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
(...skipping 22 matching lines...) Expand all
423 #endif 437 #endif
424 return munmap(base, size) == 0; 438 return munmap(base, size) == 0;
425 } 439 }
426 440
427 441
428 bool VirtualMemory::HasLazyCommits() { 442 bool VirtualMemory::HasLazyCommits() {
429 return true; 443 return true;
430 } 444 }
431 445
432 } } // namespace v8::base 446 } } // namespace v8::base
OLDNEW
« no previous file with comments | « no previous file | src/base/platform/platform-posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698