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

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

Issue 157503002: A64: Synchronize with r18444. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 years, 10 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 | « src/platform-posix.cc ('k') | src/platform-win32.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 2013 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Platform specific code for Linux goes here. For the POSIX comaptible parts 28 // Platform-specific code for QNX goes here. For the POSIX-compatible
29 // the implementation is in platform-posix.cc. 29 // parts the implementation is in platform-posix.cc.
30 30
31 #include <pthread.h> 31 #include <pthread.h>
32 #include <semaphore.h> 32 #include <semaphore.h>
33 #include <signal.h> 33 #include <signal.h>
34 #include <sys/prctl.h>
35 #include <sys/time.h> 34 #include <sys/time.h>
36 #include <sys/resource.h> 35 #include <sys/resource.h>
37 #include <sys/syscall.h>
38 #include <sys/types.h> 36 #include <sys/types.h>
39 #include <stdlib.h> 37 #include <stdlib.h>
38 #include <ucontext.h>
39 #include <backtrace.h>
40 40
41 // Ubuntu Dapper requires memory pages to be marked as 41 // QNX requires memory pages to be marked as executable.
42 // executable. Otherwise, OS raises an exception when executing code 42 // Otherwise, the OS raises an exception when executing code in that page.
43 // in that page.
44 #include <sys/types.h> // mmap & munmap 43 #include <sys/types.h> // mmap & munmap
45 #include <sys/mman.h> // mmap & munmap 44 #include <sys/mman.h> // mmap & munmap
46 #include <sys/stat.h> // open 45 #include <sys/stat.h> // open
47 #include <fcntl.h> // open 46 #include <fcntl.h> // open
48 #include <unistd.h> // sysconf 47 #include <unistd.h> // sysconf
49 #include <strings.h> // index 48 #include <strings.h> // index
50 #include <errno.h> 49 #include <errno.h>
51 #include <stdarg.h> 50 #include <stdarg.h>
52 51 #include <sys/procfs.h>
53 // GLibc on ARM defines mcontext_t has a typedef for 'struct sigcontext'.
54 // Old versions of the C library <signal.h> didn't define the type.
55 #if defined(__ANDROID__) && !defined(__BIONIC_HAVE_UCONTEXT_T) && \
56 (defined(__arm__) || defined(__aarch64__)) && \
57 !defined(__BIONIC_HAVE_STRUCT_SIGCONTEXT)
58 #include <asm/sigcontext.h>
59 #endif
60 52
61 #undef MAP_TYPE 53 #undef MAP_TYPE
62 54
63 #include "v8.h" 55 #include "v8.h"
64 56
65 #include "platform.h" 57 #include "platform.h"
66 #include "v8threads.h" 58 #include "v8threads.h"
67 #include "vm-state-inl.h" 59 #include "vm-state-inl.h"
68 60
69 61
70 namespace v8 { 62 namespace v8 {
71 namespace internal { 63 namespace internal {
72 64
65 // 0 is never a valid thread id on Qnx since tids and pids share a
66 // name space and pid 0 is reserved (see man 2 kill).
67 static const pthread_t kNoThread = (pthread_t) 0;
68
73 69
74 #ifdef __arm__ 70 #ifdef __arm__
75 71
76 bool OS::ArmUsingHardFloat() { 72 bool OS::ArmUsingHardFloat() {
77 // GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify 73 // GCC versions 4.6 and above define __ARM_PCS or __ARM_PCS_VFP to specify
78 // the Floating Point ABI used (PCS stands for Procedure Call Standard). 74 // the Floating Point ABI used (PCS stands for Procedure Call Standard).
79 // We use these as well as a couple of other defines to statically determine 75 // We use these as well as a couple of other defines to statically determine
80 // what FP ABI used. 76 // what FP ABI used.
81 // GCC versions 4.4 and below don't support hard-fp. 77 // GCC versions 4.4 and below don't support hard-fp.
82 // GCC versions 4.5 may support hard-fp without defining __ARM_PCS or 78 // GCC versions 4.5 may support hard-fp without defining __ARM_PCS or
(...skipping 21 matching lines...) Expand all
104 #else 100 #else
105 #error "Your version of GCC does not report the FP ABI compiled for." \ 101 #error "Your version of GCC does not report the FP ABI compiled for." \
106 "Please report it on this issue" \ 102 "Please report it on this issue" \
107 "http://code.google.com/p/v8/issues/detail?id=2140" 103 "http://code.google.com/p/v8/issues/detail?id=2140"
108 104
109 #endif 105 #endif
110 #endif 106 #endif
111 #undef GCC_VERSION 107 #undef GCC_VERSION
112 } 108 }
113 109
114 #endif // def __arm__ 110 #endif // __arm__
115 111
116 112
117 const char* OS::LocalTimezone(double time) { 113 const char* OS::LocalTimezone(double time) {
118 if (std::isnan(time)) return ""; 114 if (std::isnan(time)) return "";
119 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); 115 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));
120 struct tm* t = localtime(&tv); 116 struct tm* t = localtime(&tv);
121 if (NULL == t) return ""; 117 if (NULL == t) return "";
122 return t->tm_zone; 118 return t->tm_zone;
123 } 119 }
124 120
125 121
126 double OS::LocalTimeOffset() { 122 double OS::LocalTimeOffset() {
127 time_t tv = time(NULL); 123 time_t tv = time(NULL);
128 struct tm* t = localtime(&tv); 124 struct tm* t = localtime(&tv);
129 // tm_gmtoff includes any daylight savings offset, so subtract it. 125 // tm_gmtoff includes any daylight savings offset, so subtract it.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 197 }
202 198
203 199
204 PosixMemoryMappedFile::~PosixMemoryMappedFile() { 200 PosixMemoryMappedFile::~PosixMemoryMappedFile() {
205 if (memory_) OS::Free(memory_, size_); 201 if (memory_) OS::Free(memory_, size_);
206 fclose(file_); 202 fclose(file_);
207 } 203 }
208 204
209 205
210 void OS::LogSharedLibraryAddresses(Isolate* isolate) { 206 void OS::LogSharedLibraryAddresses(Isolate* isolate) {
211 // This function assumes that the layout of the file is as follows: 207 procfs_mapinfo *mapinfos = NULL, *mapinfo;
212 // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] 208 int proc_fd, num, i;
213 // If we encounter an unexpected situation we abort scanning further entries.
214 FILE* fp = fopen("/proc/self/maps", "r");
215 if (fp == NULL) return;
216 209
217 // Allocate enough room to be able to store a full file name. 210 struct {
218 const int kLibNameLen = FILENAME_MAX + 1; 211 procfs_debuginfo info;
219 char* lib_name = reinterpret_cast<char*>(malloc(kLibNameLen)); 212 char buff[PATH_MAX];
213 } map;
220 214
221 // This loop will terminate once the scanning hits an EOF. 215 char buf[PATH_MAX + 1];
222 while (true) { 216 snprintf(buf, PATH_MAX + 1, "/proc/%d/as", getpid());
223 uintptr_t start, end;
224 char attr_r, attr_w, attr_x, attr_p;
225 // Parse the addresses and permission bits at the beginning of the line.
226 if (fscanf(fp, "%" V8PRIxPTR "-%" V8PRIxPTR, &start, &end) != 2) break;
227 if (fscanf(fp, " %c%c%c%c", &attr_r, &attr_w, &attr_x, &attr_p) != 4) break;
228 217
229 int c; 218 if ((proc_fd = open(buf, O_RDONLY)) == -1) {
230 if (attr_r == 'r' && attr_w != 'w' && attr_x == 'x') { 219 close(proc_fd);
231 // Found a read-only executable entry. Skip characters until we reach 220 return;
232 // the beginning of the filename or the end of the line. 221 }
233 do {
234 c = getc(fp);
235 } while ((c != EOF) && (c != '\n') && (c != '/') && (c != '['));
236 if (c == EOF) break; // EOF: Was unexpected, just exit.
237 222
238 // Process the filename if found. 223 /* Get the number of map entries. */
239 if ((c == '/') || (c == '[')) { 224 if (devctl(proc_fd, DCMD_PROC_MAPINFO, NULL, 0, &num) != EOK) {
240 // Push the '/' or '[' back into the stream to be read below. 225 close(proc_fd);
241 ungetc(c, fp); 226 return;
227 }
242 228
243 // Read to the end of the line. Exit if the read fails. 229 mapinfos = reinterpret_cast<procfs_mapinfo *>(
244 if (fgets(lib_name, kLibNameLen, fp) == NULL) break; 230 malloc(num * sizeof(procfs_mapinfo)));
231 if (mapinfos == NULL) {
232 close(proc_fd);
233 return;
234 }
245 235
246 // Drop the newline character read by fgets. We do not need to check 236 /* Fill the map entries. */
247 // for a zero-length string because we know that we at least read the 237 if (devctl(proc_fd, DCMD_PROC_PAGEDATA,
248 // '/' or '[' character. 238 mapinfos, num * sizeof(procfs_mapinfo), &num) != EOK) {
249 lib_name[strlen(lib_name) - 1] = '\0'; 239 free(mapinfos);
250 } else { 240 close(proc_fd);
251 // No library name found, just record the raw address range. 241 return;
252 snprintf(lib_name, kLibNameLen, 242 }
253 "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end); 243
244 for (i = 0; i < num; i++) {
245 mapinfo = mapinfos + i;
246 if (mapinfo->flags & MAP_ELF) {
247 map.info.vaddr = mapinfo->vaddr;
248 if (devctl(proc_fd, DCMD_PROC_MAPDEBUG, &map, sizeof(map), 0) != EOK) {
249 continue;
254 } 250 }
255 LOG(isolate, SharedLibraryEvent(lib_name, start, end)); 251 LOG(isolate, SharedLibraryEvent(map.info.path,
256 } else { 252 mapinfo->vaddr,
257 // Entry not describing executable data. Skip to end of line to set up 253 mapinfo->vaddr + mapinfo->size));
258 // reading the next entry.
259 do {
260 c = getc(fp);
261 } while ((c != EOF) && (c != '\n'));
262 if (c == EOF) break;
263 } 254 }
264 } 255 }
265 free(lib_name); 256 free(mapinfos);
266 fclose(fp); 257 close(proc_fd);
267 } 258 }
268 259
269 260
270 void OS::SignalCodeMovingGC() { 261 void OS::SignalCodeMovingGC() {
271 // Support for ll_prof.py.
272 //
273 // The Linux profiler built into the kernel logs all mmap's with
274 // PROT_EXEC so that analysis tools can properly attribute ticks. We
275 // do a mmap with a name known by ll_prof.py and immediately munmap
276 // it. This injects a GC marker into the stream of events generated
277 // by the kernel and allows us to synchronize V8 code log and the
278 // kernel log.
279 int size = sysconf(_SC_PAGESIZE);
280 FILE* f = fopen(FLAG_gc_fake_mmap, "w+");
281 if (f == NULL) {
282 OS::PrintError("Failed to open %s\n", FLAG_gc_fake_mmap);
283 OS::Abort();
284 }
285 void* addr = mmap(OS::GetRandomMmapAddr(),
286 size,
287 #if defined(__native_client__)
288 // The Native Client port of V8 uses an interpreter,
289 // so code pages don't need PROT_EXEC.
290 PROT_READ,
291 #else
292 PROT_READ | PROT_EXEC,
293 #endif
294 MAP_PRIVATE,
295 fileno(f),
296 0);
297 ASSERT(addr != MAP_FAILED);
298 OS::Free(addr, size);
299 fclose(f);
300 } 262 }
301 263
302 264
303 // Constants used for mmap. 265 // Constants used for mmap.
304 static const int kMmapFd = -1; 266 static const int kMmapFd = -1;
305 static const int kMmapFdOffset = 0; 267 static const int kMmapFdOffset = 0;
306 268
307 269
308 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } 270 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
309 271
310 272
311 VirtualMemory::VirtualMemory(size_t size) 273 VirtualMemory::VirtualMemory(size_t size)
312 : address_(ReserveRegion(size)), size_(size) { } 274 : address_(ReserveRegion(size)), size_(size) { }
313 275
314 276
315 VirtualMemory::VirtualMemory(size_t size, size_t alignment) 277 VirtualMemory::VirtualMemory(size_t size, size_t alignment)
316 : address_(NULL), size_(0) { 278 : address_(NULL), size_(0) {
317 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); 279 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
318 size_t request_size = RoundUp(size + alignment, 280 size_t request_size = RoundUp(size + alignment,
319 static_cast<intptr_t>(OS::AllocateAlignment())); 281 static_cast<intptr_t>(OS::AllocateAlignment()));
320 void* reservation = mmap(OS::GetRandomMmapAddr(), 282 void* reservation = mmap(OS::GetRandomMmapAddr(),
321 request_size, 283 request_size,
322 PROT_NONE, 284 PROT_NONE,
323 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, 285 MAP_PRIVATE | MAP_ANONYMOUS | MAP_LAZY,
324 kMmapFd, 286 kMmapFd,
325 kMmapFdOffset); 287 kMmapFdOffset);
326 if (reservation == MAP_FAILED) return; 288 if (reservation == MAP_FAILED) return;
327 289
328 Address base = static_cast<Address>(reservation); 290 Address base = static_cast<Address>(reservation);
329 Address aligned_base = RoundUp(base, alignment); 291 Address aligned_base = RoundUp(base, alignment);
330 ASSERT_LE(base, aligned_base); 292 ASSERT_LE(base, aligned_base);
331 293
332 // Unmap extra memory reserved before and after the desired block. 294 // Unmap extra memory reserved before and after the desired block.
333 if (aligned_base != base) { 295 if (aligned_base != base) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 bool VirtualMemory::Guard(void* address) { 347 bool VirtualMemory::Guard(void* address) {
386 OS::Guard(address, OS::CommitPageSize()); 348 OS::Guard(address, OS::CommitPageSize());
387 return true; 349 return true;
388 } 350 }
389 351
390 352
391 void* VirtualMemory::ReserveRegion(size_t size) { 353 void* VirtualMemory::ReserveRegion(size_t size) {
392 void* result = mmap(OS::GetRandomMmapAddr(), 354 void* result = mmap(OS::GetRandomMmapAddr(),
393 size, 355 size,
394 PROT_NONE, 356 PROT_NONE,
395 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, 357 MAP_PRIVATE | MAP_ANONYMOUS | MAP_LAZY,
396 kMmapFd, 358 kMmapFd,
397 kMmapFdOffset); 359 kMmapFdOffset);
398 360
399 if (result == MAP_FAILED) return NULL; 361 if (result == MAP_FAILED) return NULL;
400 362
401 return result; 363 return result;
402 } 364 }
403 365
404 366
405 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { 367 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
406 #if defined(__native_client__)
407 // The Native Client port of V8 uses an interpreter,
408 // so code pages don't need PROT_EXEC.
409 int prot = PROT_READ | PROT_WRITE;
410 #else
411 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 368 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
412 #endif
413 if (MAP_FAILED == mmap(base, 369 if (MAP_FAILED == mmap(base,
414 size, 370 size,
415 prot, 371 prot,
416 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 372 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
417 kMmapFd, 373 kMmapFd,
418 kMmapFdOffset)) { 374 kMmapFdOffset)) {
419 return false; 375 return false;
420 } 376 }
421 377
422 return true; 378 return true;
423 } 379 }
424 380
425 381
426 bool VirtualMemory::UncommitRegion(void* base, size_t size) { 382 bool VirtualMemory::UncommitRegion(void* base, size_t size) {
427 return mmap(base, 383 return mmap(base,
428 size, 384 size,
429 PROT_NONE, 385 PROT_NONE,
430 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED, 386 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED | MAP_LAZY,
431 kMmapFd, 387 kMmapFd,
432 kMmapFdOffset) != MAP_FAILED; 388 kMmapFdOffset) != MAP_FAILED;
433 } 389 }
434 390
435 391
436 bool VirtualMemory::ReleaseRegion(void* base, size_t size) { 392 bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
437 return munmap(base, size) == 0; 393 return munmap(base, size) == 0;
438 } 394 }
439 395
440 396
441 bool VirtualMemory::HasLazyCommits() { 397 bool VirtualMemory::HasLazyCommits() {
442 return true; 398 return false;
443 } 399 }
444 400
445 } } // namespace v8::internal 401 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-posix.cc ('k') | src/platform-win32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698