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

Side by Side Diff: src/base/platform/platform-win32.cc

Issue 1111733002: [clang] Use -Wshorten-64-to-32 to enable warnings about 64bit to 32bit truncations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix Win warnings. Created 5 years, 8 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
« no previous file with comments | « src/base/platform/platform-solaris.cc ('k') | src/base/platform/time.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 Win32. 5 // Platform-specific code for Win32.
6 6
7 // Secure API functions are not available using MinGW with msvcrt.dll 7 // Secure API functions are not available using MinGW with msvcrt.dll
8 // on Windows XP. Make sure MINGW_HAS_SECURE_API is not defined to 8 // on Windows XP. Make sure MINGW_HAS_SECURE_API is not defined to
9 // disable definition of secure API functions in standard headers that 9 // disable definition of secure API functions in standard headers that
10 // would conflict with our own implementation. 10 // would conflict with our own implementation.
(...skipping 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 // To avoid Visual Studio runtime support the following code can be used 831 // To avoid Visual Studio runtime support the following code can be used
832 // instead 832 // instead
833 // __asm { int 3 } 833 // __asm { int 3 }
834 __debugbreak(); 834 __debugbreak();
835 #else 835 #else
836 ::DebugBreak(); 836 ::DebugBreak();
837 #endif 837 #endif
838 } 838 }
839 839
840 840
841 class Win32MemoryMappedFile : public OS::MemoryMappedFile { 841 class Win32MemoryMappedFile final : public OS::MemoryMappedFile {
842 public: 842 public:
843 Win32MemoryMappedFile(HANDLE file, 843 Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory,
844 HANDLE file_mapping, 844 size_t size)
845 void* memory,
846 int size)
847 : file_(file), 845 : file_(file),
848 file_mapping_(file_mapping), 846 file_mapping_(file_mapping),
849 memory_(memory), 847 memory_(memory),
850 size_(size) { } 848 size_(size) {}
851 virtual ~Win32MemoryMappedFile(); 849 ~Win32MemoryMappedFile() final;
852 virtual void* memory() { return memory_; } 850 void* memory() const final { return memory_; }
853 virtual int size() { return size_; } 851 size_t size() const final { return size_; }
852
854 private: 853 private:
855 HANDLE file_; 854 HANDLE const file_;
856 HANDLE file_mapping_; 855 HANDLE const file_mapping_;
857 void* memory_; 856 void* const memory_;
858 int size_; 857 size_t const size_;
859 }; 858 };
860 859
861 860
861 // static
862 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { 862 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
863 // Open a physical file 863 // Open a physical file
864 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, 864 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
865 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); 865 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
866 if (file == INVALID_HANDLE_VALUE) return NULL; 866 if (file == INVALID_HANDLE_VALUE) return NULL;
867 867
868 int size = static_cast<int>(GetFileSize(file, NULL)); 868 DWORD size = GetFileSize(file, NULL);
869 869
870 // Create a file mapping for the physical file 870 // Create a file mapping for the physical file
871 HANDLE file_mapping = CreateFileMapping(file, NULL, 871 HANDLE file_mapping =
872 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL); 872 CreateFileMapping(file, NULL, PAGE_READWRITE, 0, size, NULL);
873 if (file_mapping == NULL) return NULL; 873 if (file_mapping == NULL) return NULL;
874 874
875 // Map a view of the file into memory 875 // Map a view of the file into memory
876 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size); 876 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
877 return new Win32MemoryMappedFile(file, file_mapping, memory, size); 877 return new Win32MemoryMappedFile(file, file_mapping, memory, size);
878 } 878 }
879 879
880 880
881 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, 881 // static
882 void* initial) { 882 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name,
883 size_t size, void* initial) {
883 // Open a physical file 884 // Open a physical file
884 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, 885 HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
885 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); 886 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
887 OPEN_ALWAYS, 0, NULL);
886 if (file == NULL) return NULL; 888 if (file == NULL) return NULL;
887 // Create a file mapping for the physical file 889 // Create a file mapping for the physical file
888 HANDLE file_mapping = CreateFileMapping(file, NULL, 890 HANDLE file_mapping = CreateFileMapping(file, NULL, PAGE_READWRITE, 0,
889 PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL); 891 static_cast<DWORD>(size), NULL);
890 if (file_mapping == NULL) return NULL; 892 if (file_mapping == NULL) return NULL;
891 // Map a view of the file into memory 893 // Map a view of the file into memory
892 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size); 894 void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
893 if (memory) memmove(memory, initial, size); 895 if (memory) memmove(memory, initial, size);
894 return new Win32MemoryMappedFile(file, file_mapping, memory, size); 896 return new Win32MemoryMappedFile(file, file_mapping, memory, size);
895 } 897 }
896 898
897 899
898 Win32MemoryMappedFile::~Win32MemoryMappedFile() { 900 Win32MemoryMappedFile::~Win32MemoryMappedFile() {
899 if (memory_ != NULL) 901 if (memory_) UnmapViewOfFile(memory_);
900 UnmapViewOfFile(memory_);
901 CloseHandle(file_mapping_); 902 CloseHandle(file_mapping_);
902 CloseHandle(file_); 903 CloseHandle(file_);
903 } 904 }
904 905
905 906
906 // The following code loads functions defined in DbhHelp.h and TlHelp32.h 907 // The following code loads functions defined in DbhHelp.h and TlHelp32.h
907 // dynamically. This is to avoid being depending on dbghelp.dll and 908 // dynamically. This is to avoid being depending on dbghelp.dll and
908 // tlhelp32.dll when running (the functions in tlhelp32.dll have been moved to 909 // tlhelp32.dll when running (the functions in tlhelp32.dll have been moved to
909 // kernel32.dll at some point so loading functions defines in TlHelp32.h 910 // kernel32.dll at some point so loading functions defines in TlHelp32.h
910 // dynamically might not be necessary any more - for some versions of Windows?). 911 // dynamically might not be necessary any more - for some versions of Windows?).
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 DCHECK(result); 1384 DCHECK(result);
1384 } 1385 }
1385 1386
1386 1387
1387 1388
1388 void Thread::YieldCPU() { 1389 void Thread::YieldCPU() {
1389 Sleep(0); 1390 Sleep(0);
1390 } 1391 }
1391 1392
1392 } } // namespace v8::base 1393 } } // namespace v8::base
OLDNEW
« no previous file with comments | « src/base/platform/platform-solaris.cc ('k') | src/base/platform/time.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698