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

Side by Side Diff: src/base/platform/platform-openbsd.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-macos.cc ('k') | src/base/platform/platform-posix.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 OpenBSD and NetBSD goes here. For the 5 // Platform-specific code for OpenBSD and NetBSD goes here. For the
6 // POSIX-compatible parts, the implementation is in platform-posix.cc. 6 // POSIX-compatible parts, the implementation is in platform-posix.cc.
7 7
8 #include <pthread.h> 8 #include <pthread.h>
9 #include <semaphore.h> 9 #include <semaphore.h>
10 #include <signal.h> 10 #include <signal.h>
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 const size_t msize = RoundUp(requested, AllocateAlignment()); 59 const size_t msize = RoundUp(requested, AllocateAlignment());
60 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0); 60 int prot = PROT_READ | PROT_WRITE | (is_executable ? PROT_EXEC : 0);
61 void* addr = OS::GetRandomMmapAddr(); 61 void* addr = OS::GetRandomMmapAddr();
62 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0); 62 void* mbase = mmap(addr, msize, prot, MAP_PRIVATE | MAP_ANON, -1, 0);
63 if (mbase == MAP_FAILED) return NULL; 63 if (mbase == MAP_FAILED) return NULL;
64 *allocated = msize; 64 *allocated = msize;
65 return mbase; 65 return mbase;
66 } 66 }
67 67
68 68
69 class PosixMemoryMappedFile : public OS::MemoryMappedFile {
70 public:
71 PosixMemoryMappedFile(FILE* file, void* memory, int size)
72 : file_(file), memory_(memory), size_(size) { }
73 virtual ~PosixMemoryMappedFile();
74 virtual void* memory() { return memory_; }
75 virtual int size() { return size_; }
76 private:
77 FILE* file_;
78 void* memory_;
79 int size_;
80 };
81
82
83 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
84 FILE* file = fopen(name, "r+");
85 if (file == NULL) return NULL;
86
87 fseek(file, 0, SEEK_END);
88 int size = ftell(file);
89
90 void* memory =
91 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
92 return new PosixMemoryMappedFile(file, memory, size);
93 }
94
95
96 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
97 void* initial) {
98 FILE* file = fopen(name, "w+");
99 if (file == NULL) return NULL;
100 int result = fwrite(initial, size, 1, file);
101 if (result < 1) {
102 fclose(file);
103 return NULL;
104 }
105 void* memory =
106 mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
107 return new PosixMemoryMappedFile(file, memory, size);
108 }
109
110
111 PosixMemoryMappedFile::~PosixMemoryMappedFile() {
112 if (memory_) OS::Free(memory_, size_);
113 fclose(file_);
114 }
115
116
117 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { 69 std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
118 std::vector<SharedLibraryAddress> result; 70 std::vector<SharedLibraryAddress> result;
119 // This function assumes that the layout of the file is as follows: 71 // This function assumes that the layout of the file is as follows:
120 // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name] 72 // hex_start_addr-hex_end_addr rwxp <unused data> [binary_file_name]
121 // If we encounter an unexpected situation we abort scanning further entries. 73 // If we encounter an unexpected situation we abort scanning further entries.
122 FILE* fp = fopen("/proc/self/maps", "r"); 74 FILE* fp = fopen("/proc/self/maps", "r");
123 if (fp == NULL) return result; 75 if (fp == NULL) return result;
124 76
125 // Allocate enough room to be able to store a full file name. 77 // Allocate enough room to be able to store a full file name.
126 const int kLibNameLen = FILENAME_MAX + 1; 78 const int kLibNameLen = FILENAME_MAX + 1;
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 return munmap(base, size) == 0; 281 return munmap(base, size) == 0;
330 } 282 }
331 283
332 284
333 bool VirtualMemory::HasLazyCommits() { 285 bool VirtualMemory::HasLazyCommits() {
334 // TODO(alph): implement for the platform. 286 // TODO(alph): implement for the platform.
335 return false; 287 return false;
336 } 288 }
337 289
338 } } // namespace v8::base 290 } } // namespace v8::base
OLDNEW
« no previous file with comments | « src/base/platform/platform-macos.cc ('k') | src/base/platform/platform-posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698