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

Side by Side Diff: src/platform-win32.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
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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 FILE* OS::FOpen(const char* path, const char* mode) { 663 FILE* OS::FOpen(const char* path, const char* mode) {
664 FILE* result; 664 FILE* result;
665 if (fopen_s(&result, path, mode) == 0) { 665 if (fopen_s(&result, path, mode) == 0) {
666 return result; 666 return result;
667 } else { 667 } else {
668 return NULL; 668 return NULL;
669 } 669 }
670 } 670 }
671 671
672 672
673 bool OS::Remove(const char* path) {
674 return (DeleteFile(path) != 0);
675 }
676
677
673 // Open log file in binary mode to avoid /n -> /r/n conversion. 678 // Open log file in binary mode to avoid /n -> /r/n conversion.
674 const char* OS::LogFileOpenMode = "wb"; 679 const char* OS::LogFileOpenMode = "wb";
675 680
676 681
677 // Print (debug) message to console. 682 // Print (debug) message to console.
678 void OS::Print(const char* format, ...) { 683 void OS::Print(const char* format, ...) {
679 va_list args; 684 va_list args;
680 va_start(args, format); 685 va_start(args, format);
681 VPrint(format, args); 686 VPrint(format, args);
682 va_end(args); 687 va_end(args);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 #ifdef _MSC_VER 909 #ifdef _MSC_VER
905 __debugbreak(); 910 __debugbreak();
906 #else 911 #else
907 ::DebugBreak(); 912 ::DebugBreak();
908 #endif 913 #endif
909 } 914 }
910 915
911 916
912 class Win32MemoryMappedFile : public OS::MemoryMappedFile { 917 class Win32MemoryMappedFile : public OS::MemoryMappedFile {
913 public: 918 public:
914 Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory) 919 Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory,
mnaganov (inactive) 2011/01/16 10:16:02 Arg per line, please.
marklam 2011/01/18 02:49:02 Done.
915 : file_(file), file_mapping_(file_mapping), memory_(memory) { } 920 int size)
921 : file_(file), file_mapping_(file_mapping), memory_(memory),
922 size_(size) { }
mnaganov (inactive) 2011/01/16 10:16:02 And init-per-line.
marklam 2011/01/18 02:49:02 Done.
916 virtual ~Win32MemoryMappedFile(); 923 virtual ~Win32MemoryMappedFile();
917 virtual void* memory() { return memory_; } 924 virtual void* memory() { return memory_; }
925 virtual void* size() { return size_; }
918 private: 926 private:
919 HANDLE file_; 927 HANDLE file_;
920 HANDLE file_mapping_; 928 HANDLE file_mapping_;
921 void* memory_; 929 void* memory_;
930 int size_;
922 }; 931 };
923 932
924 933
934 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
935 // Open a physical file
936 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
937 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
938 if (file == NULL) return NULL;
939
940 int size = static_cast<int>(GetFileSize(file, NULL));
941
942 // Create a file mapping for the physical file
943 HANDLE file_mapping = CreateFileMapping(file, NULL,
944 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL);
945 if (file_mapping == NULL) return NULL;
946
947 // Map a view of the file into memory
948 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
949 return new Win32MemoryMappedFile(file, file_mapping, memory, size);
950 }
951
952
925 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, 953 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
926 void* initial) { 954 void* initial) {
927 // Open a physical file 955 // Open a physical file
928 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, 956 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
929 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); 957 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL);
930 if (file == NULL) return NULL; 958 if (file == NULL) return NULL;
931 // Create a file mapping for the physical file 959 // Create a file mapping for the physical file
932 HANDLE file_mapping = CreateFileMapping(file, NULL, 960 HANDLE file_mapping = CreateFileMapping(file, NULL,
933 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL); 961 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL);
934 if (file_mapping == NULL) return NULL; 962 if (file_mapping == NULL) return NULL;
935 // Map a view of the file into memory 963 // Map a view of the file into memory
936 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size); 964 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
937 if (memory) memmove(memory, initial, size); 965 if (memory) memmove(memory, initial, size);
938 return new Win32MemoryMappedFile(file, file_mapping, memory); 966 return new Win32MemoryMappedFile(file, file_mapping, memory, size);
939 } 967 }
940 968
941 969
942 Win32MemoryMappedFile::~Win32MemoryMappedFile() { 970 Win32MemoryMappedFile::~Win32MemoryMappedFile() {
943 if (memory_ != NULL) 971 if (memory_ != NULL)
944 UnmapViewOfFile(memory_); 972 UnmapViewOfFile(memory_);
945 CloseHandle(file_mapping_); 973 CloseHandle(file_mapping_);
946 CloseHandle(file_); 974 CloseHandle(file_);
947 } 975 }
948 976
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 1961
1934 // Release the thread handles 1962 // Release the thread handles
1935 CloseHandle(data_->sampler_thread_); 1963 CloseHandle(data_->sampler_thread_);
1936 CloseHandle(data_->profiled_thread_); 1964 CloseHandle(data_->profiled_thread_);
1937 } 1965 }
1938 1966
1939 1967
1940 #endif // ENABLE_LOGGING_AND_PROFILING 1968 #endif // ENABLE_LOGGING_AND_PROFILING
1941 1969
1942 } } // namespace v8::internal 1970 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-solaris.cc ('k') | src/utils.cc » ('j') | src/utils.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698