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

Side by Side Diff: src/base/platform/platform-macos.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-linux.cc ('k') | src/base/platform/platform-openbsd.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 MacOS goes here. For the POSIX-compatible 5 // Platform-specific code for MacOS 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 <dlfcn.h> 8 #include <dlfcn.h>
9 #include <mach/mach_init.h> 9 #include <mach/mach_init.h>
10 #include <mach-o/dyld.h> 10 #include <mach-o/dyld.h>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 prot, 61 prot,
62 MAP_PRIVATE | MAP_ANON, 62 MAP_PRIVATE | MAP_ANON,
63 kMmapFd, 63 kMmapFd,
64 kMmapFdOffset); 64 kMmapFdOffset);
65 if (mbase == MAP_FAILED) return NULL; 65 if (mbase == MAP_FAILED) return NULL;
66 *allocated = msize; 66 *allocated = msize;
67 return mbase; 67 return mbase;
68 } 68 }
69 69
70 70
71 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
72 public:
73 PosixMemoryMappedFile(FILE* file, void* memory, int size)
74 : file_(file), memory_(memory), size_(size) { }
75 virtual ~PosixMemoryMappedFile();
76 virtual void* memory() { return memory_; }
77 virtual int size() { return size_; }
78 private:
79 FILE* file_;
80 void* memory_;
81 int size_;
82 };
83
84
85 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
86 FILE* file = fopen(name, "r+");
87 if (file == NULL) return NULL;
88
89 fseek(file, 0, SEEK_END);
90 int size = ftell(file);
91
92 void* memory =
93 mmap(OS::GetRandomMmapAddr(),
94 size,
95 PROT_READ | PROT_WRITE,
96 MAP_SHARED,
97 fileno(file),
98 0);
99 return new PosixMemoryMappedFile(file, memory, size);
100 }
101
102
103 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
104 void* initial) {
105 FILE* file = fopen(name, "w+");
106 if (file == NULL) return NULL;
107 int result = fwrite(initial, size, 1, file);
108 if (result < 1) {
109 fclose(file);
110 return NULL;
111 }
112 void* memory =
113 mmap(OS::GetRandomMmapAddr(),
114 size,
115 PROT_READ | PROT_WRITE,
116 MAP_SHARED,
117 fileno(file),
118 0);
119 return new PosixMemoryMappedFile(file, memory, size);
120 }
121
122
123 PosixMemoryMappedFile::~PosixMemoryMappedFile() {
124 if (memory_) OS::Free(memory_, size_);
125 fclose(file_);
126 }
127
128
129 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { 71 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
130 std::vector<SharedLibraryAddress> result; 72 std::vector<SharedLibraryAddress> result;
131 unsigned int images_count = _dyld_image_count(); 73 unsigned int images_count = _dyld_image_count();
132 for (unsigned int i = 0; i < images_count; ++i) { 74 for (unsigned int i = 0; i < images_count; ++i) {
133 const mach_header* header = _dyld_get_image_header(i); 75 const mach_header* header = _dyld_get_image_header(i);
134 if (header == NULL) continue; 76 if (header == NULL) continue;
135 #if V8_HOST_ARCH_X64 77 #if V8_HOST_ARCH_X64
136 uint64_t size; 78 uint64_t size;
137 char* code_ptr = getsectdatafromheader_64( 79 char* code_ptr = getsectdatafromheader_64(
138 reinterpret_cast<const mach_header_64*>(header), 80 reinterpret_cast<const mach_header_64*>(header),
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 bool VirtualMemory::ReleaseRegion(void* address, size_t size) { 243 bool VirtualMemory::ReleaseRegion(void* address, size_t size) {
302 return munmap(address, size) == 0; 244 return munmap(address, size) == 0;
303 } 245 }
304 246
305 247
306 bool VirtualMemory::HasLazyCommits() { 248 bool VirtualMemory::HasLazyCommits() {
307 return false; 249 return false;
308 } 250 }
309 251
310 } } // namespace v8::base 252 } } // namespace v8::base
OLDNEW
« no previous file with comments | « src/base/platform/platform-linux.cc ('k') | src/base/platform/platform-openbsd.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698