OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 asm("int $3"); | 219 asm("int $3"); |
220 } | 220 } |
221 | 221 |
222 | 222 |
223 class PosixMemoryMappedFile : public OS::MemoryMappedFile { | 223 class PosixMemoryMappedFile : public OS::MemoryMappedFile { |
224 public: | 224 public: |
225 PosixMemoryMappedFile(FILE* file, void* memory, int size) | 225 PosixMemoryMappedFile(FILE* file, void* memory, int size) |
226 : file_(file), memory_(memory), size_(size) { } | 226 : file_(file), memory_(memory), size_(size) { } |
227 virtual ~PosixMemoryMappedFile(); | 227 virtual ~PosixMemoryMappedFile(); |
228 virtual void* memory() { return memory_; } | 228 virtual void* memory() { return memory_; } |
| 229 virtual int size() { return size_; } |
229 private: | 230 private: |
230 FILE* file_; | 231 FILE* file_; |
231 void* memory_; | 232 void* memory_; |
232 int size_; | 233 int size_; |
233 }; | 234 }; |
234 | 235 |
235 | 236 |
| 237 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { |
| 238 FILE* file = fopen(name, "w+"); |
| 239 if (file == NULL) return NULL; |
| 240 |
| 241 fseek(file, 0, SEEK_END); |
| 242 int size = ftell(file); |
| 243 |
| 244 void* memory = |
| 245 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0); |
| 246 return new PosixMemoryMappedFile(file, memory, size); |
| 247 } |
| 248 |
| 249 |
236 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, | 250 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, |
237 void* initial) { | 251 void* initial) { |
238 FILE* file = fopen(name, "w+"); | 252 FILE* file = fopen(name, "w+"); |
239 if (file == NULL) return NULL; | 253 if (file == NULL) return NULL; |
240 int result = fwrite(initial, size, 1, file); | 254 int result = fwrite(initial, size, 1, file); |
241 if (result < 1) { | 255 if (result < 1) { |
242 fclose(file); | 256 fclose(file); |
243 return NULL; | 257 return NULL; |
244 } | 258 } |
245 void* memory = | 259 void* memory = |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 } | 705 } |
692 | 706 |
693 // This sampler is no longer the active sampler. | 707 // This sampler is no longer the active sampler. |
694 active_sampler_ = NULL; | 708 active_sampler_ = NULL; |
695 active_ = false; | 709 active_ = false; |
696 } | 710 } |
697 | 711 |
698 #endif // ENABLE_LOGGING_AND_PROFILING | 712 #endif // ENABLE_LOGGING_AND_PROFILING |
699 | 713 |
700 } } // namespace v8::internal | 714 } } // namespace v8::internal |
OLD | NEW |