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

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
« no previous file with comments | « src/platform-solaris.cc ('k') | src/utils.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 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,
915 : file_(file), file_mapping_(file_mapping), memory_(memory) { } 920 HANDLE file_mapping,
921 void* memory,
922 int size)
923 : file_(file),
924 file_mapping_(file_mapping),
925 memory_(memory),
926 size_(size) { }
916 virtual ~Win32MemoryMappedFile(); 927 virtual ~Win32MemoryMappedFile();
917 virtual void* memory() { return memory_; } 928 virtual void* memory() { return memory_; }
929 virtual void* size() { return size_; }
918 private: 930 private:
919 HANDLE file_; 931 HANDLE file_;
920 HANDLE file_mapping_; 932 HANDLE file_mapping_;
921 void* memory_; 933 void* memory_;
934 int size_;
922 }; 935 };
923 936
924 937
938 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
939 // Open a physical file
940 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
941 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
942 if (file == NULL) return NULL;
943
944 int size = static_cast<int>(GetFileSize(file, NULL));
945
946 // Create a file mapping for the physical file
947 HANDLE file_mapping = CreateFileMapping(file, NULL,
948 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL);
949 if (file_mapping == NULL) return NULL;
950
951 // Map a view of the file into memory
952 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
953 return new Win32MemoryMappedFile(file, file_mapping, memory, size);
954 }
955
956
925 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, 957 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
926 void* initial) { 958 void* initial) {
927 // Open a physical file 959 // Open a physical file
928 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, 960 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
929 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); 961 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL);
930 if (file == NULL) return NULL; 962 if (file == NULL) return NULL;
931 // Create a file mapping for the physical file 963 // Create a file mapping for the physical file
932 HANDLE file_mapping = CreateFileMapping(file, NULL, 964 HANDLE file_mapping = CreateFileMapping(file, NULL,
933 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL); 965 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL);
934 if (file_mapping == NULL) return NULL; 966 if (file_mapping == NULL) return NULL;
935 // Map a view of the file into memory 967 // Map a view of the file into memory
936 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size); 968 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
937 if (memory) memmove(memory, initial, size); 969 if (memory) memmove(memory, initial, size);
938 return new Win32MemoryMappedFile(file, file_mapping, memory); 970 return new Win32MemoryMappedFile(file, file_mapping, memory, size);
939 } 971 }
940 972
941 973
942 Win32MemoryMappedFile::~Win32MemoryMappedFile() { 974 Win32MemoryMappedFile::~Win32MemoryMappedFile() {
943 if (memory_ != NULL) 975 if (memory_ != NULL)
944 UnmapViewOfFile(memory_); 976 UnmapViewOfFile(memory_);
945 CloseHandle(file_mapping_); 977 CloseHandle(file_mapping_);
946 CloseHandle(file_); 978 CloseHandle(file_);
947 } 979 }
948 980
(...skipping 984 matching lines...) Expand 10 before | Expand all | Expand 10 after
1933 1965
1934 // Release the thread handles 1966 // Release the thread handles
1935 CloseHandle(data_->sampler_thread_); 1967 CloseHandle(data_->sampler_thread_);
1936 CloseHandle(data_->profiled_thread_); 1968 CloseHandle(data_->profiled_thread_);
1937 } 1969 }
1938 1970
1939 1971
1940 #endif // ENABLE_LOGGING_AND_PROFILING 1972 #endif // ENABLE_LOGGING_AND_PROFILING
1941 1973
1942 } } // namespace v8::internal 1974 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/platform-solaris.cc ('k') | src/utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698