| OLD | NEW |
| 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 FreeBSD goes here. For the POSIX-compatible | 5 // Platform-specific code for FreeBSD 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> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 const size_t msize = RoundUp(requested, getpagesize()); | 61 const size_t msize = RoundUp(requested, getpagesize()); |
| 62 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); | 62 int prot = PROT_READ | PROT_WRITE | (executable ? PROT_EXEC : 0); |
| 63 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); | 63 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); |
| 64 | 64 |
| 65 if (mbase == MAP_FAILED) return NULL; | 65 if (mbase == MAP_FAILED) return NULL; |
| 66 *allocated = msize; | 66 *allocated = msize; |
| 67 return mbase; | 67 return mbase; |
| 68 } | 68 } |
| 69 | 69 |
| 70 | 70 |
| 71 class PosixMemoryMappedFile : public OS::MemoryMappedFile { | |
| 72 public: | |
| 73 PosixMemoryMappedFile(FILE* file, void* memory, int size) | |
| 74 : file_(file), memory_(memory), size_(size) { } | |
| 75 virtual ~PosixMemoryMappedFile(); | |
| 76 virtual void* memory() { return memory_; } | |
| 77 virtual int size() { return size_; } | |
| 78 private: | |
| 79 FILE* file_; | |
| 80 void* memory_; | |
| 81 int size_; | |
| 82 }; | |
| 83 | |
| 84 | |
| 85 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { | |
| 86 FILE* file = fopen(name, "r+"); | |
| 87 if (file == NULL) return NULL; | |
| 88 | |
| 89 fseek(file, 0, SEEK_END); | |
| 90 int size = ftell(file); | |
| 91 | |
| 92 void* memory = | |
| 93 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); | |
| 94 return new PosixMemoryMappedFile(file, memory, size); | |
| 95 } | |
| 96 | |
| 97 | |
| 98 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, | |
| 99 void* initial) { | |
| 100 FILE* file = fopen(name, "w+"); | |
| 101 if (file == NULL) return NULL; | |
| 102 int result = fwrite(initial, size, 1, file); | |
| 103 if (result < 1) { | |
| 104 fclose(file); | |
| 105 return NULL; | |
| 106 } | |
| 107 void* memory = | |
| 108 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); | |
| 109 return new PosixMemoryMappedFile(file, memory, size); | |
| 110 } | |
| 111 | |
| 112 | |
| 113 PosixMemoryMappedFile::~PosixMemoryMappedFile() { | |
| 114 if (memory_) munmap(memory_, size_); | |
| 115 fclose(file_); | |
| 116 } | |
| 117 | |
| 118 | |
| 119 static unsigned StringToLong(char* buffer) { | 71 static unsigned StringToLong(char* buffer) { |
| 120 return static_cast<unsigned>(strtol(buffer, NULL, 16)); // NOLINT | 72 return static_cast<unsigned>(strtol(buffer, NULL, 16)); // NOLINT |
| 121 } | 73 } |
| 122 | 74 |
| 123 | 75 |
| 124 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { | 76 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { |
| 125 std::vector<SharedLibraryAddress> result; | 77 std::vector<SharedLibraryAddress> result; |
| 126 static const int MAP_LENGTH = 1024; | 78 static const int MAP_LENGTH = 1024; |
| 127 int fd = open("/proc/self/maps", O_RDONLY); | 79 int fd = open("/proc/self/maps", O_RDONLY); |
| 128 if (fd < 0) return result; | 80 if (fd < 0) return result; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 return munmap(base, size) == 0; | 250 return munmap(base, size) == 0; |
| 299 } | 251 } |
| 300 | 252 |
| 301 | 253 |
| 302 bool VirtualMemory::HasLazyCommits() { | 254 bool VirtualMemory::HasLazyCommits() { |
| 303 // TODO(alph): implement for the platform. | 255 // TODO(alph): implement for the platform. |
| 304 return false; | 256 return false; |
| 305 } | 257 } |
| 306 | 258 |
| 307 } } // namespace v8::base | 259 } } // namespace v8::base |
| OLD | NEW |