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

Side by Side Diff: src/base/platform/platform-cygwin.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, 7 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-aix.cc ('k') | src/base/platform/platform-freebsd.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 Cygwin goes here. For the POSIX-compatible 5 // Platform-specific code for Cygwin goes here. For the POSIX-compatible
6 // parts, the implementation is in platform-posix.cc. 6 // parts, the implementation is in platform-posix.cc.
7 7
8 #include <errno.h> 8 #include <errno.h>
9 #include <pthread.h> 9 #include <pthread.h>
10 #include <semaphore.h> 10 #include <semaphore.h>
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 bool is_executable) { 52 bool is_executable) {
53 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE)); 53 const size_t msize = RoundUp(requested, sysconf(_SC_PAGESIZE));
54 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 54 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
55 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 55 void* mbase = mmap(NULL, msize, prot, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
56 if (mbase == MAP_FAILED) return NULL; 56 if (mbase == MAP_FAILED) return NULL;
57 *allocated = msize; 57 *allocated = msize;
58 return mbase; 58 return mbase;
59 } 59 }
60 60
61 61
62 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
63 public:
64 PosixMemoryMappedFile(FILE* file, void* memory, int size)
65 : file_(file), memory_(memory), size_(size) { }
66 virtual ~PosixMemoryMappedFile();
67 virtual void* memory() { return memory_; }
68 virtual int size() { return size_; }
69 private:
70 FILE* file_;
71 void* memory_;
72 int size_;
73 };
74
75
76 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
77 FILE* file = fopen(name, "r+");
78 if (file == NULL) return NULL;
79
80 fseek(file, 0, SEEK_END);
81 int size = ftell(file);
82
83 void* memory =
84 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
85 return new PosixMemoryMappedFile(file, memory, size);
86 }
87
88
89 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
90 void* initial) {
91 FILE* file = fopen(name, "w+");
92 if (file == NULL) return NULL;
93 int result = fwrite(initial, size, 1, file);
94 if (result < 1) {
95 fclose(file);
96 return NULL;
97 }
98 void* memory =
99 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
100 return new PosixMemoryMappedFile(file, memory, size);
101 }
102
103
104 PosixMemoryMappedFile::~PosixMemoryMappedFile() {
105 if (memory_) munmap(memory_, size_);
106 fclose(file_);
107 }
108
109
110 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { 62 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
111 std::vector<SharedLibraryAddresses> result; 63 std::vector<SharedLibraryAddresses> result;
112 // This function assumes that the layout of the file is as follows: 64 // This function assumes that the layout of the file is as follows:
113 // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] 65 // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name]
114 // If we encounter an unexpected situation we abort scanning further entries. 66 // If we encounter an unexpected situation we abort scanning further entries.
115 FILE* fp = fopen("/proc/self/maps", "r"); 67 FILE* fp = fopen("/proc/self/maps", "r");
116 if (fp == NULL) return result; 68 if (fp == NULL) return result;
117 69
118 // Allocate enough room to be able to store a full file name. 70 // Allocate enough room to be able to store a full file name.
119 const int kLibNameLen = FILENAME_MAX + 1; 71 const int kLibNameLen = FILENAME_MAX + 1;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return VirtualFree(base, 0, MEM_RELEASE) != 0; 246 return VirtualFree(base, 0, MEM_RELEASE) != 0;
295 } 247 }
296 248
297 249
298 bool VirtualMemory::HasLazyCommits() { 250 bool VirtualMemory::HasLazyCommits() {
299 // TODO(alph): implement for the platform. 251 // TODO(alph): implement for the platform.
300 return false; 252 return false;
301 } 253 }
302 254
303 } } // namespace v8::base 255 } } // namespace v8::base
OLDNEW
« no previous file with comments | « src/base/platform/platform-aix.cc ('k') | src/base/platform/platform-freebsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698