OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 QNX goes here. For the POSIX-compatible | 5 // Platform-specific code for QNX 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 <backtrace.h> | 8 #include <backtrace.h> |
9 #include <pthread.h> | 9 #include <pthread.h> |
10 #include <semaphore.h> | 10 #include <semaphore.h> |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 const size_t msize = RoundUp(requested, AllocateAlignment()); | 110 const size_t msize = RoundUp(requested, AllocateAlignment()); |
111 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); | 111 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); |
112 void* addr = OS::GetRandomMmapAddr(); | 112 void* addr = OS::GetRandomMmapAddr(); |
113 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 113 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
114 if (mbase == MAP_FAILED) return NULL; | 114 if (mbase == MAP_FAILED) return NULL; |
115 *allocated = msize; | 115 *allocated = msize; |
116 return mbase; | 116 return mbase; |
117 } | 117 } |
118 | 118 |
119 | 119 |
120 class PosixMemoryMappedFile : public OS::MemoryMappedFile { | |
121 public: | |
122 PosixMemoryMappedFile(FILE* file, void* memory, int size) | |
123 : file_(file), memory_(memory), size_(size) { } | |
124 virtual ~PosixMemoryMappedFile(); | |
125 virtual void* memory() { return memory_; } | |
126 virtual int size() { return size_; } | |
127 private: | |
128 FILE* file_; | |
129 void* memory_; | |
130 int size_; | |
131 }; | |
132 | |
133 | |
134 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { | |
135 FILE* file = fopen(name, "r+"); | |
136 if (file == NULL) return NULL; | |
137 | |
138 fseek(file, 0, SEEK_END); | |
139 int size = ftell(file); | |
140 | |
141 void* memory = | |
142 mmap(OS::GetRandomMmapAddr(), | |
143 size, | |
144 PROT_READ | PROT_WRITE, | |
145 MAP_SHARED, | |
146 fileno(file), | |
147 0); | |
148 return new PosixMemoryMappedFile(file, memory, size); | |
149 } | |
150 | |
151 | |
152 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, | |
153 void* initial) { | |
154 FILE* file = fopen(name, "w+"); | |
155 if (file == NULL) return NULL; | |
156 int result = fwrite(initial, size, 1, file); | |
157 if (result < 1) { | |
158 fclose(file); | |
159 return NULL; | |
160 } | |
161 void* memory = | |
162 mmap(OS::GetRandomMmapAddr(), | |
163 size, | |
164 PROT_READ | PROT_WRITE, | |
165 MAP_SHARED, | |
166 fileno(file), | |
167 0); | |
168 return new PosixMemoryMappedFile(file, memory, size); | |
169 } | |
170 | |
171 | |
172 PosixMemoryMappedFile::~PosixMemoryMappedFile() { | |
173 if (memory_) OS::Free(memory_, size_); | |
174 fclose(file_); | |
175 } | |
176 | |
177 | |
178 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { | 120 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { |
179 std::vector<SharedLibraryAddress> result; | 121 std::vector<SharedLibraryAddress> result; |
180 procfs_mapinfo *mapinfos = NULL, *mapinfo; | 122 procfs_mapinfo *mapinfos = NULL, *mapinfo; |
181 int proc_fd, num, i; | 123 int proc_fd, num, i; |
182 | 124 |
183 struct { | 125 struct { |
184 procfs_debuginfo info; | 126 procfs_debuginfo info; |
185 char buff[PATH_MAX]; | 127 char buff[PATH_MAX]; |
186 } map; | 128 } map; |
187 | 129 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 bool VirtualMemory::ReleaseRegion(void* base, size_t size) { | 307 bool VirtualMemory::ReleaseRegion(void* base, size_t size) { |
366 return munmap(base, size) == 0; | 308 return munmap(base, size) == 0; |
367 } | 309 } |
368 | 310 |
369 | 311 |
370 bool VirtualMemory::HasLazyCommits() { | 312 bool VirtualMemory::HasLazyCommits() { |
371 return false; | 313 return false; |
372 } | 314 } |
373 | 315 |
374 } } // namespace v8::base | 316 } } // namespace v8::base |
OLD | NEW |