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

Side by Side Diff: src/base/platform/platform-posix.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-openbsd.cc ('k') | src/base/platform/platform-qnx.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 POSIX goes here. This is not a platform on its 5 // Platform-specific code for POSIX goes here. This is not a platform on its
6 // own, but contains the parts which are the same across the POSIX platforms 6 // own, but contains the parts which are the same across the POSIX platforms
7 // Linux, MacOS, FreeBSD, OpenBSD, NetBSD and QNX. 7 // Linux, MacOS, FreeBSD, OpenBSD, NetBSD and QNX.
8 8
9 #include <errno.h> 9 #include <errno.h>
10 #include <limits.h> 10 #include <limits.h>
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 asm("int $3"); 252 asm("int $3");
253 #endif // V8_OS_NACL 253 #endif // V8_OS_NACL
254 #elif V8_HOST_ARCH_X64 254 #elif V8_HOST_ARCH_X64
255 asm("int $3"); 255 asm("int $3");
256 #else 256 #else
257 #error Unsupported host architecture. 257 #error Unsupported host architecture.
258 #endif 258 #endif
259 } 259 }
260 260
261 261
262 class PosixMemoryMappedFile final : public OS::MemoryMappedFile {
263 public:
264 PosixMemoryMappedFile(FILE* file, void* memory, size_t size)
265 : file_(file), memory_(memory), size_(size) {}
266 ~PosixMemoryMappedFile() final;
267 void* memory() const final { return memory_; }
268 size_t size() const final { return size_; }
269
270 private:
271 FILE* const file_;
272 void* const memory_;
273 size_t const size_;
274 };
275
276
277 // static
278 OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
279 if (FILE* file = fopen(name, "r+")) {
280 if (fseek(file, 0, SEEK_END) == 0) {
281 long size = ftell(file); // NOLINT(runtime/int)
282 if (size >= 0) {
283 void* const memory =
284 mmap(OS::GetRandomMmapAddr(), size, PROT_READ | PROT_WRITE,
285 MAP_SHARED, fileno(file), 0);
286 if (memory != MAP_FAILED) {
287 return new PosixMemoryMappedFile(file, memory, size);
288 }
289 }
290 }
291 fclose(file);
292 }
293 return nullptr;
294 }
295
296
297 // static
298 OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name,
299 size_t size, void* initial) {
300 if (FILE* file = fopen(name, "w+")) {
301 size_t result = fwrite(initial, 1, size, file);
302 if (result == size && !ferror(file)) {
303 void* memory = mmap(OS::GetRandomMmapAddr(), result,
304 PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
305 if (memory != MAP_FAILED) {
306 return new PosixMemoryMappedFile(file, memory, result);
307 }
308 }
309 fclose(file);
310 }
311 return nullptr;
312 }
313
314
315 PosixMemoryMappedFile::~PosixMemoryMappedFile() {
316 if (memory_) OS::Free(memory_, size_);
317 fclose(file_);
318 }
319
320
262 int OS::GetCurrentProcessId() { 321 int OS::GetCurrentProcessId() {
263 return static_cast<int>(getpid()); 322 return static_cast<int>(getpid());
264 } 323 }
265 324
266 325
267 int OS::GetCurrentThreadId() { 326 int OS::GetCurrentThreadId() {
268 #if V8_OS_MACOSX || (V8_OS_ANDROID && defined(__APPLE__)) 327 #if V8_OS_MACOSX || (V8_OS_ANDROID && defined(__APPLE__))
269 return static_cast<int>(pthread_mach_thread_np(pthread_self())); 328 return static_cast<int>(pthread_mach_thread_np(pthread_self()));
270 #elif V8_OS_LINUX 329 #elif V8_OS_LINUX
271 return static_cast<int>(syscall(__NR_gettid)); 330 return static_cast<int>(syscall(__NR_gettid));
272 #elif V8_OS_ANDROID 331 #elif V8_OS_ANDROID
273 return static_cast<int>(gettid()); 332 return static_cast<int>(gettid());
274 #elif V8_OS_AIX 333 #elif V8_OS_AIX
275 return static_cast<int>(thread_self()); 334 return static_cast<int>(thread_self());
276 #elif V8_OS_SOLARIS 335 #elif V8_OS_SOLARIS
277 return static_cast<int>(pthread_self()); 336 return static_cast<int>(pthread_self());
278 #else 337 #else
279 return static_cast<int>(reinterpret_cast<intptr_t>(pthread_self())); 338 return static_cast<int>(reinterpret_cast<intptr_t>(pthread_self()));
280 #endif 339 #endif
281 } 340 }
282 341
283 342
284 // ---------------------------------------------------------------------------- 343 // ----------------------------------------------------------------------------
285 // POSIX date/time support. 344 // POSIX date/time support.
286 // 345 //
287 346
288 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { 347 int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
289 #if V8_OS_NACL 348 #if V8_OS_NACL
290 // Optionally used in Logger::ResourceEvent. 349 // Optionally used in Logger::ResourceEvent.
291 return -1; 350 return -1;
292 #else 351 #else
293 struct rusage usage; 352 struct rusage usage;
294 353
295 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1; 354 if (getrusage(RUSAGE_SELF, &usage) < 0) return -1;
296 *secs = usage.ru_utime.tv_sec; 355 *secs = static_cast<uint32_t>(usage.ru_utime.tv_sec);
297 *usecs = usage.ru_utime.tv_usec; 356 *usecs = static_cast<uint32_t>(usage.ru_utime.tv_usec);
298 return 0; 357 return 0;
299 #endif 358 #endif
300 } 359 }
301 360
302 361
303 double OS::TimeCurrentMillis() { 362 double OS::TimeCurrentMillis() {
304 return Time::Now().ToJsTime(); 363 return Time::Now().ToJsTime();
305 } 364 }
306 365
307 366
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 756
698 void Thread::SetThreadLocal(LocalStorageKey key, void* value) { 757 void Thread::SetThreadLocal(LocalStorageKey key, void* value) {
699 pthread_key_t pthread_key = LocalKeyToPthreadKey(key); 758 pthread_key_t pthread_key = LocalKeyToPthreadKey(key);
700 int result = pthread_setspecific(pthread_key, value); 759 int result = pthread_setspecific(pthread_key, value);
701 DCHECK_EQ(0, result); 760 DCHECK_EQ(0, result);
702 USE(result); 761 USE(result);
703 } 762 }
704 763
705 764
706 } } // namespace v8::base 765 } } // namespace v8::base
OLDNEW
« no previous file with comments | « src/base/platform/platform-openbsd.cc ('k') | src/base/platform/platform-qnx.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698