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

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

Issue 6240002: Introducing MemoryMappedExternalResource for creating an external... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 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 | « src/platform-linux.cc ('k') | src/platform-nullos.cc » ('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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 asm("int $3"); 189 asm("int $3");
190 } 190 }
191 191
192 192
193 class PosixMemoryMappedFile : public OS::MemoryMappedFile { 193 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
194 public: 194 public:
195 PosixMemoryMappedFile(FILE* file, void* memory, int size) 195 PosixMemoryMappedFile(FILE* file, void* memory, int size)
196 : file_(file), memory_(memory), size_(size) { } 196 : file_(file), memory_(memory), size_(size) { }
197 virtual ~PosixMemoryMappedFile(); 197 virtual ~PosixMemoryMappedFile();
198 virtual void* memory() { return memory_; } 198 virtual void* memory() { return memory_; }
199 virtual int size() { return size_; }
199 private: 200 private:
200 FILE* file_; 201 FILE* file_;
201 void* memory_; 202 void* memory_;
202 int size_; 203 int size_;
203 }; 204 };
204 205
205 206
207 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
208 FILE* file = fopen(name, "w+");
209 if (file == NULL) return NULL;
210
211 fseek(file, 0, SEEK_END);
212 int size = ftell(file);
213
214 void* memory =
215 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
216 return new PosixMemoryMappedFile(file, memory, size);
217 }
218
219
206 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, 220 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
207 void* initial) { 221 void* initial) {
208 FILE* file = fopen(name, "w+"); 222 FILE* file = fopen(name, "w+");
209 if (file == NULL) return NULL; 223 if (file == NULL) return NULL;
210 int result = fwrite(initial, size, 1, file); 224 int result = fwrite(initial, size, 1, file);
211 if (result < 1) { 225 if (result < 1) {
212 fclose(file); 226 fclose(file);
213 return NULL; 227 return NULL;
214 } 228 }
215 void* memory = 229 void* memory =
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 Top::WakeUpRuntimeProfilerThreadBeforeShutdown(); 723 Top::WakeUpRuntimeProfilerThreadBeforeShutdown();
710 pthread_join(data_->sampler_thread_, NULL); 724 pthread_join(data_->sampler_thread_, NULL);
711 725
712 // Deallocate Mach port for thread. 726 // Deallocate Mach port for thread.
713 mach_port_deallocate(data_->task_self_, data_->profiled_thread_); 727 mach_port_deallocate(data_->task_self_, data_->profiled_thread_);
714 } 728 }
715 729
716 #endif // ENABLE_LOGGING_AND_PROFILING 730 #endif // ENABLE_LOGGING_AND_PROFILING
717 731
718 } } // namespace v8::internal 732 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-linux.cc ('k') | src/platform-nullos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698