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

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

Issue 61153009: Add support for the QNX operating system. (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Address latest review comments Created 7 years 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
« no previous file with comments | « src/platform-posix.cc ('k') | src/qnx-math.h » ('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(__BIONIC_HAVE_STRUCT_SIGCONTEXT)
57 #include <asm/sigcontext.h>
58 #endif
59 52
60 #undef MAP_TYPE 53 #undef MAP_TYPE
61 54
62 #include "v8.h" 55 #include "v8.h"
63 56
64 #include "platform.h" 57 #include "platform.h"
65 #include "v8threads.h" 58 #include "v8threads.h"
66 #include "vm-state-inl.h" 59 #include "vm-state-inl.h"
67 60
68 61
69 namespace v8 { 62 namespace v8 {
70 namespace internal { 63 namespace internal {
71 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
72 69
73 #ifdef __arm__ 70 #ifdef __arm__
74 71
75 bool OS::ArmUsingHardFloat() { 72 bool OS::ArmUsingHardFloat() {
76 // 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
77 // the Floating Point ABI used (PCS stands for Procedure Call Standard). 74 // the Floating Point ABI used (PCS stands for Procedure Call Standard).
78 // 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
79 // what FP ABI used. 76 // what FP ABI used.
80 // GCC versions 4.4 and below don't support hard-fp. 77 // GCC versions 4.4 and below don't support hard-fp.
81 // 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
103 #else 100 #else
104 #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." \
105 "Please report it on this issue" \ 102 "Please report it on this issue" \
106 "http://code.google.com/p/v8/issues/detail?id=2140" 103 "http://code.google.com/p/v8/issues/detail?id=2140"
107 104
108 #endif 105 #endif
109 #endif 106 #endif
110 #undef GCC_VERSION 107 #undef GCC_VERSION
111 } 108 }
112 109
113 #endif // def __arm__ 110 #endif // __arm__
114 111
115 112
116 const char* OS::LocalTimezone(double time) { 113 const char* OS::LocalTimezone(double time) {
117 if (std::isnan(time)) return ""; 114 if (std::isnan(time)) return "";
118 time_t tv = static_cast<time_t>(floor(time/msPerSecond)); 115 time_t tv = static_cast<time_t>(std::floor(time/msPerSecond));
119 struct tm* t = localtime(&tv); 116 struct tm* t = localtime(&tv);
120 if (NULL == t) return ""; 117 if (NULL == t) return "";
121 return t->tm_zone; 118 return t->tm_zone;
122 } 119 }
123 120
124 121
125 double OS::LocalTimeOffset() { 122 double OS::LocalTimeOffset() {
126 time_t tv = time(NULL); 123 time_t tv = time(NULL);
127 struct tm* t = localtime(&tv); 124 struct tm* t = localtime(&tv);
128 // 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
200 } 197 }
201 198
202 199
203 PosixMemoryMappedFile::~PosixMemoryMappedFile() { 200 PosixMemoryMappedFile::~PosixMemoryMappedFile() {
204 if (memory_) OS::Free(memory_, size_); 201 if (memory_) OS::Free(memory_, size_);
205 fclose(file_); 202 fclose(file_);
206 } 203 }
207 204
208 205
209 void OS::LogSharedLibraryAddresses(Isolate* isolate) { 206 void OS::LogSharedLibraryAddresses(Isolate* isolate) {
210 // This function assumes that the layout of the file is as follows: 207 procfs_mapinfo *mapinfos = NULL, *mapinfo;
211 // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] 208 int proc_fd, num, i;
212 // If we encounter an unexpected situation we abort scanning further entries.
213 FILE* fp = fopen("/proc/self/maps", "r");
214 if (fp == NULL) return;
215 209
216 // Allocate enough room to be able to store a full file name. 210 struct {
217 const int kLibNameLen = FILENAME_MAX + 1; 211 procfs_debuginfo info;
218 char* lib_name = reinterpret_cast<char*>(malloc(kLibNameLen)); 212 char buff[PATH_MAX];
213 } map;
219 214
220 // This loop will terminate once the scanning hits an EOF. 215 char buf[PATH_MAX + 1];
221 while (true) { 216 snprintf(buf, PATH_MAX + 1, "/proc/%d/as", getpid());
222 uintptr_t start, end;
223 char attr_r, attr_w, attr_x, attr_p;
224 // Parse the addresses and permission bits at the beginning of the line.
225 if (fscanf(fp, "%" V8PRIxPTR "-%" V8PRIxPTR, &start, &end) != 2) break;
226 if (fscanf(fp, " %c%c%c%c", &attr_r, &attr_w, &attr_x, &attr_p) != 4) break;
227 217
228 int c; 218 if ((proc_fd = open(buf, O_RDONLY)) == -1) {
229 if (attr_r == 'r' && attr_w != 'w' && attr_x == 'x') { 219 close(proc_fd);
230 // Found a read-only executable entry. Skip characters until we reach 220 return;
231 // the beginning of the filename or the end of the line. 221 }
232 do {
233 c = getc(fp);
234 } while ((c != EOF) && (c != '\n') && (c != '/') && (c != '['));
235 if (c == EOF) break; // EOF: Was unexpected, just exit.
236 222
237 // Process the filename if found. 223 /* Get the number of map entries. */
238 if ((c == '/') || (c == '[')) { 224 if (devctl(proc_fd, DCMD_PROC_MAPINFO, NULL, 0, &num) != EOK) {
239 // Push the '/' or '[' back into the stream to be read below. 225 close(proc_fd);
240 ungetc(c, fp); 226 return;
227 }
241 228
242 // Read to the end of the line. Exit if the read fails. 229 mapinfos = reinterpret_cast<procfs_mapinfo *>(
243 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 }
244 235
245 // Drop the newline character read by fgets. We do not need to check 236 /* Fill the map entries. */
246 // for a zero-length string because we know that we at least read the 237 if (devctl(proc_fd, DCMD_PROC_PAGEDATA,
247 // '/' or '[' character. 238 mapinfos, num * sizeof(procfs_mapinfo), &num) != EOK) {
248 lib_name[strlen(lib_name) - 1] = '\0'; 239 free(mapinfos);
249 } else { 240 close(proc_fd);
250 // No library name found, just record the raw address range. 241 return;
251 snprintf(lib_name, kLibNameLen, 242 }
252 "%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;
253 } 250 }
254 LOG(isolate, SharedLibraryEvent(lib_name, start, end)); 251 LOG(isolate, SharedLibraryEvent(map.info.path,
255 } else { 252 mapinfo->vaddr,
256 // Entry not describing executable data. Skip to end of line to set up 253 mapinfo->vaddr + mapinfo->size));
257 // reading the next entry.
258 do {
259 c = getc(fp);
260 } while ((c != EOF) && (c != '\n'));
261 if (c == EOF) break;
262 } 254 }
263 } 255 }
264 free(lib_name); 256 free(mapinfos);
265 fclose(fp); 257 close(proc_fd);
266 } 258 }
267 259
268 260
269 void OS::SignalCodeMovingGC() { 261 void OS::SignalCodeMovingGC() {
270 // Support for ll_prof.py.
271 //
272 // The Linux profiler built into the kernel logs all mmap's with
273 // PROT_EXEC so that analysis tools can properly attribute ticks. We
274 // do a mmap with a name known by ll_prof.py and immediately munmap
275 // it. This injects a GC marker into the stream of events generated
276 // by the kernel and allows us to synchronize V8 code log and the
277 // kernel log.
278 int size = sysconf(_SC_PAGESIZE);
279 FILE* f = fopen(FLAG_gc_fake_mmap, "w+");
280 if (f == NULL) {
281 OS::PrintError("Failed to open %s\n", FLAG_gc_fake_mmap);
282 OS::Abort();
283 }
284 void* addr = mmap(OS::GetRandomMmapAddr(),
285 size,
286 #if defined(__native_client__)
287 // The Native Client port of V8 uses an interpreter,
288 // so code pages don't need PROT_EXEC.
289 PROT_READ,
290 #else
291 PROT_READ | PROT_EXEC,
292 #endif
293 MAP_PRIVATE,
294 fileno(f),
295 0);
296 ASSERT(addr != MAP_FAILED);
297 OS::Free(addr, size);
298 fclose(f);
299 } 262 }
300 263
301 264
302 // Constants used for mmap. 265 // Constants used for mmap.
303 static const int kMmapFd = -1; 266 static const int kMmapFd = -1;
304 static const int kMmapFdOffset = 0; 267 static const int kMmapFdOffset = 0;
305 268
306 269
307 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { } 270 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
308 271
309 272
310 VirtualMemory::VirtualMemory(size_t size) 273 VirtualMemory::VirtualMemory(size_t size)
311 : address_(ReserveRegion(size)), size_(size) { } 274 : address_(ReserveRegion(size)), size_(size) { }
312 275
313 276
314 VirtualMemory::VirtualMemory(size_t size, size_t alignment) 277 VirtualMemory::VirtualMemory(size_t size, size_t alignment)
315 : address_(NULL), size_(0) { 278 : address_(NULL), size_(0) {
316 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment()))); 279 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
317 size_t request_size = RoundUp(size + alignment, 280 size_t request_size = RoundUp(size + alignment,
318 static_cast<intptr_t>(OS::AllocateAlignment())); 281 static_cast<intptr_t>(OS::AllocateAlignment()));
319 void* reservation = mmap(OS::GetRandomMmapAddr(), 282 void* reservation = mmap(OS::GetRandomMmapAddr(),
320 request_size, 283 request_size,
321 PROT_NONE, 284 PROT_NONE,
322 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, 285 MAP_PRIVATE | MAP_ANONYMOUS | MAP_LAZY,
323 kMmapFd, 286 kMmapFd,
324 kMmapFdOffset); 287 kMmapFdOffset);
325 if (reservation == MAP_FAILED) return; 288 if (reservation == MAP_FAILED) return;
326 289
327 Address base = static_cast<Address>(reservation); 290 Address base = static_cast<Address>(reservation);
328 Address aligned_base = RoundUp(base, alignment); 291 Address aligned_base = RoundUp(base, alignment);
329 ASSERT_LE(base, aligned_base); 292 ASSERT_LE(base, aligned_base);
330 293
331 // Unmap extra memory reserved before and after the desired block. 294 // Unmap extra memory reserved before and after the desired block.
332 if (aligned_base != base) { 295 if (aligned_base != base) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 bool VirtualMemory::Guard(void* address) { 347 bool VirtualMemory::Guard(void* address) {
385 OS::Guard(address, OS::CommitPageSize()); 348 OS::Guard(address, OS::CommitPageSize());
386 return true; 349 return true;
387 } 350 }
388 351
389 352
390 void* VirtualMemory::ReserveRegion(size_t size) { 353 void* VirtualMemory::ReserveRegion(size_t size) {
391 void* result = mmap(OS::GetRandomMmapAddr(), 354 void* result = mmap(OS::GetRandomMmapAddr(),
392 size, 355 size,
393 PROT_NONE, 356 PROT_NONE,
394 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, 357 MAP_PRIVATE | MAP_ANONYMOUS | MAP_LAZY,
395 kMmapFd, 358 kMmapFd,
396 kMmapFdOffset); 359 kMmapFdOffset);
397 360
398 if (result == MAP_FAILED) return NULL; 361 if (result == MAP_FAILED) return NULL;
399 362
400 return result; 363 return result;
401 } 364 }
402 365
403 366
404 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) { 367 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
405 #if defined(__native_client__)
406 // The Native Client port of V8 uses an interpreter,
407 // so code pages don't need PROT_EXEC.
408 int prot = PROT_READ | PROT_WRITE;
409 #else
410 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 368 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
411 #endif
412 if (MAP_FAILED == mmap(base, 369 if (MAP_FAILED == mmap(base,
413 size, 370 size,
414 prot, 371 prot,
415 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, 372 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
416 kMmapFd, 373 kMmapFd,
417 kMmapFdOffset)) { 374 kMmapFdOffset)) {
418 return false; 375 return false;
419 } 376 }
420 377
421 return true; 378 return true;
422 } 379 }
423 380
424 381
425 bool VirtualMemory::UncommitRegion(void* base, size_t size) { 382 bool VirtualMemory::UncommitRegion(void* base, size_t size) {
426 return mmap(base, 383 return mmap(base,
427 size, 384 size,
428 PROT_NONE, 385 PROT_NONE,
429 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED, 386 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED | MAP_LAZY,
430 kMmapFd, 387 kMmapFd,
431 kMmapFdOffset) != MAP_FAILED; 388 kMmapFdOffset) != MAP_FAILED;
432 } 389 }
433 390
434 391
435 bool VirtualMemory::ReleaseRegion(void* base, size_t size) { 392 bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
436 return munmap(base, size) == 0; 393 return munmap(base, size) == 0;
437 } 394 }
438 395
439 396
440 bool VirtualMemory::HasLazyCommits() { 397 bool VirtualMemory::HasLazyCommits() {
441 return true; 398 return false;
442 } 399 }
443 400
444 } } // namespace v8::internal 401 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-posix.cc ('k') | src/qnx-math.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698