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

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

Issue 9233002: Fix solaris build (VirtualMemory). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fix libraries in gyp. Created 8 years, 11 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 | tools/gyp/v8.gyp » ('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 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include <ieeefp.h> // finite() 46 #include <ieeefp.h> // finite()
47 #include <signal.h> // sigemptyset(), etc 47 #include <signal.h> // sigemptyset(), etc
48 #include <sys/regset.h> 48 #include <sys/regset.h>
49 49
50 50
51 #undef MAP_TYPE 51 #undef MAP_TYPE
52 52
53 #include "v8.h" 53 #include "v8.h"
54 54
55 #include "platform.h" 55 #include "platform.h"
56 #include "v8threads.h"
56 #include "vm-state-inl.h" 57 #include "vm-state-inl.h"
57 58
58 59
59 // It seems there is a bug in some Solaris distributions (experienced in 60 // It seems there is a bug in some Solaris distributions (experienced in
60 // SunOS 5.10 Generic_141445-09) which make it difficult or impossible to 61 // SunOS 5.10 Generic_141445-09) which make it difficult or impossible to
61 // access signbit() despite the availability of other C99 math functions. 62 // access signbit() despite the availability of other C99 math functions.
62 #ifndef signbit 63 #ifndef signbit
63 // Test sign - usually defined in math.h 64 // Test sign - usually defined in math.h
64 int signbit(double x) { 65 int signbit(double x) {
65 // We need to take care of the special case of both positive and negative 66 // We need to take care of the special case of both positive and negative
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 316
316 return walker.index; 317 return walker.index;
317 } 318 }
318 319
319 320
320 // Constants used for mmap. 321 // Constants used for mmap.
321 static const int kMmapFd = -1; 322 static const int kMmapFd = -1;
322 static const int kMmapFdOffset = 0; 323 static const int kMmapFdOffset = 0;
323 324
324 325
326 VirtualMemory::VirtualMemory() : address_(NULL), size_(0) { }
327
325 VirtualMemory::VirtualMemory(size_t size) { 328 VirtualMemory::VirtualMemory(size_t size) {
326 address_ = mmap(NULL, size, PROT_NONE, 329 address_ = ReserveRegion(size);
327 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
328 kMmapFd, kMmapFdOffset);
329 size_ = size; 330 size_ = size;
330 } 331 }
331 332
332 333
334 VirtualMemory::VirtualMemory(size_t size, size_t alignment)
335 : address_(NULL), size_(0) {
336 ASSERT(IsAligned(alignment, static_cast<intptr_t>(OS::AllocateAlignment())));
337 size_t request_size = RoundUp(size + alignment,
338 static_cast<intptr_t>(OS::AllocateAlignment()));
339 void* reservation = mmap(OS::GetRandomMmapAddr(),
340 request_size,
341 PROT_NONE,
342 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
343 kMmapFd,
344 kMmapFdOffset);
345 if (reservation == MAP_FAILED) return;
346
347 Address base = static_cast<Address>(reservation);
348 Address aligned_base = RoundUp(base, alignment);
349 ASSERT_LE(base, aligned_base);
350
351 // Unmap extra memory reserved before and after the desired block.
352 if (aligned_base != base) {
353 size_t prefix_size = static_cast<size_t>(aligned_base - base);
354 OS::Free(base, prefix_size);
355 request_size -= prefix_size;
356 }
357
358 size_t aligned_size = RoundUp(size, OS::AllocateAlignment());
359 ASSERT_LE(aligned_size, request_size);
360
361 if (aligned_size != request_size) {
362 size_t suffix_size = request_size - aligned_size;
363 OS::Free(aligned_base + aligned_size, suffix_size);
364 request_size -= suffix_size;
365 }
366
367 ASSERT(aligned_size == request_size);
368
369 address_ = static_cast<void*>(aligned_base);
370 size_ = aligned_size;
371 }
372
373
333 VirtualMemory::~VirtualMemory() { 374 VirtualMemory::~VirtualMemory() {
334 if (IsReserved()) { 375 if (IsReserved()) {
335 if (0 == munmap(address(), size())) address_ = MAP_FAILED; 376 bool result = ReleaseRegion(address(), size());
377 ASSERT(result);
378 USE(result);
336 } 379 }
337 } 380 }
338 381
339 382
340 bool VirtualMemory::IsReserved() { 383 bool VirtualMemory::IsReserved() {
341 return address_ != MAP_FAILED; 384 return address_ != NULL;
342 } 385 }
343 386
344 387
345 bool VirtualMemory::Commit(void* address, size_t size, bool executable) { 388 void VirtualMemory::Reset() {
346 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); 389 address_ = NULL;
347 if (MAP_FAILED == mmap(address, size, prot, 390 size_ = 0;
348 MAP_PRIVATE | MAP_ANON | MAP_FIXED, 391 }
349 kMmapFd, kMmapFdOffset)) { 392
393
394 bool VirtualMemory::Commit(void* address, size_t size, bool is_executable) {
395 return CommitRegion(address, size, is_executable);
396 }
397
398
399 bool VirtualMemory::Uncommit(void* address, size_t size) {
400 return UncommitRegion(address, size);
401 }
402
403
404 void* VirtualMemory::ReserveRegion(size_t size) {
405 void* result = mmap(OS::GetRandomMmapAddr(),
406 size,
407 PROT_NONE,
408 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE,
409 kMmapFd,
410 kMmapFdOffset);
411
412 if (result == MAP_FAILED) return NULL;
413
414 return result;
415 }
416
417
418 bool VirtualMemory::CommitRegion(void* base, size_t size, bool is_executable) {
419 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
420 if (MAP_FAILED == mmap(base,
421 size,
422 prot,
423 MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED,
424 kMmapFd,
425 kMmapFdOffset)) {
350 return false; 426 return false;
351 } 427 }
352 428
353 UpdateAllocatedSpaceLimits(address, size); 429 UpdateAllocatedSpaceLimits(base, size);
354 return true; 430 return true;
355 } 431 }
356 432
357 433
358 bool VirtualMemory::Uncommit(void* address, size_t size) { 434 bool VirtualMemory::UncommitRegion(void* base, size_t size) {
359 return mmap(address, size, PROT_NONE, 435 return mmap(base,
360 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE | MAP_FIXED, 436 size,
361 kMmapFd, kMmapFdOffset) != MAP_FAILED; 437 PROT_NONE,
438 MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_FIXED,
439 kMmapFd,
440 kMmapFdOffset) != MAP_FAILED;
362 } 441 }
363 442
364 443
444 bool VirtualMemory::ReleaseRegion(void* base, size_t size) {
445 return munmap(base, size) == 0;
446 }
447
448
365 class Thread::PlatformData : public Malloced { 449 class Thread::PlatformData : public Malloced {
366 public: 450 public:
367 PlatformData() : thread_(kNoThread) { } 451 PlatformData() : thread_(kNoThread) { }
368 452
369 pthread_t thread_; // Thread handle for pthread. 453 pthread_t thread_; // Thread handle for pthread.
370 }; 454 };
371 455
372 Thread::Thread(const Options& options) 456 Thread::Thread(const Options& options)
373 : data_(new PlatformData()), 457 : data_(new PlatformData()),
374 stack_size_(options.stack_size) { 458 stack_size_(options.stack_size) {
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 } 875 }
792 876
793 877
794 void Sampler::Stop() { 878 void Sampler::Stop() {
795 ASSERT(IsActive()); 879 ASSERT(IsActive());
796 SignalSender::RemoveActiveSampler(this); 880 SignalSender::RemoveActiveSampler(this);
797 SetActive(false); 881 SetActive(false);
798 } 882 }
799 883
800 } } // namespace v8::internal 884 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | tools/gyp/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698