Commit 4486c47d authored by bmeurer's avatar bmeurer Committed by Commit bot

[clang] Use -Wshorten-64-to-32 to enable warnings about 64bit to 32bit truncations.

Currently only the Win64 bots report this warnings, which adds quite
some overhead to the development process. With this flag we also get
compiler warnings about implicit 64bit to 32bit truncations when
building with clang on Linux/x64 and Mac/x64.

R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/1111733002

Cr-Commit-Position: refs/heads/master@{#28093}
parent ef15f83b
...@@ -243,6 +243,7 @@ ...@@ -243,6 +243,7 @@
'-Wall', '-Wall',
'-Werror', '-Werror',
'-Wextra', '-Wextra',
'-Wshorten-64-to-32',
], ],
'cflags+': [ 'cflags+': [
# Clang considers the `register` keyword as deprecated, but # Clang considers the `register` keyword as deprecated, but
...@@ -389,6 +390,11 @@ ...@@ -389,6 +390,11 @@
'cflags_cc': [ '-Wnon-virtual-dtor', '-fno-rtti', '-std=gnu++0x' ], 'cflags_cc': [ '-Wnon-virtual-dtor', '-fno-rtti', '-std=gnu++0x' ],
'ldflags': [ '-pthread', ], 'ldflags': [ '-pthread', ],
'conditions': [ 'conditions': [
# TODO(arm64): It'd be nice to enable this for arm64 as well,
# but the Assembler requires some serious fixing first.
[ 'clang==1 and v8_target_arch=="x64"', {
'cflags': [ '-Wshorten-64-to-32' ],
}],
[ 'host_arch=="ppc64" and OS!="aix"', { [ 'host_arch=="ppc64" and OS!="aix"', {
'cflags': [ '-mminimal-toc' ], 'cflags': [ '-mminimal-toc' ],
}], }],
......
...@@ -595,18 +595,21 @@ Handle<String> ReadFile(Isolate* isolate, const string& name) { ...@@ -595,18 +595,21 @@ Handle<String> ReadFile(Isolate* isolate, const string& name) {
if (file == NULL) return Handle<String>(); if (file == NULL) return Handle<String>();
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
int size = ftell(file); size_t size = ftell(file);
rewind(file); rewind(file);
char* chars = new char[size + 1]; char* chars = new char[size + 1];
chars[size] = '\0'; chars[size] = '\0';
for (int i = 0; i < size;) { for (size_t i = 0; i < size;) {
int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); i += fread(&chars[i], 1, size - i, file);
i += read; if (ferror(file)) {
fclose(file);
return Handle<String>();
}
} }
fclose(file); fclose(file);
Handle<String> result = Handle<String> result = String::NewFromUtf8(
String::NewFromUtf8(isolate, chars, String::kNormalString, size); isolate, chars, String::kNormalString, static_cast<int>(size));
delete[] chars; delete[] chars;
return result; return result;
} }
......
...@@ -238,18 +238,21 @@ v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) { ...@@ -238,18 +238,21 @@ v8::Handle<v8::String> ReadFile(v8::Isolate* isolate, const char* name) {
if (file == NULL) return v8::Handle<v8::String>(); if (file == NULL) return v8::Handle<v8::String>();
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
int size = ftell(file); size_t size = ftell(file);
rewind(file); rewind(file);
char* chars = new char[size + 1]; char* chars = new char[size + 1];
chars[size] = '\0'; chars[size] = '\0';
for (int i = 0; i < size;) { for (size_t i = 0; i < size;) {
int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); i += fread(&chars[i], 1, size - i, file);
i += read; if (ferror(file)) {
fclose(file);
return v8::Handle<v8::String>();
}
} }
fclose(file); fclose(file);
v8::Handle<v8::String> result = v8::Handle<v8::String> result = v8::String::NewFromUtf8(
v8::String::NewFromUtf8(isolate, chars, v8::String::kNormalString, size); isolate, chars, v8::String::kNormalString, static_cast<int>(size));
delete[] chars; delete[] chars;
return result; return result;
} }
......
...@@ -73,55 +73,6 @@ void* OS::Allocate(const size_t requested, size_t* allocated, bool executable) { ...@@ -73,55 +73,6 @@ void* OS::Allocate(const size_t requested, size_t* allocated, bool executable) {
} }
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
: file_(file), memory_(memory), size_(size) {}
virtual ~PosixMemoryMappedFile();
virtual void* memory() { return memory_; }
virtual int size() { return size_; }
private:
FILE* file_;
void* memory_;
int size_;
};
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
FILE* file = fopen(name, "r+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
int size = ftell(file);
void* memory =
mmapHelper(size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
return new PosixMemoryMappedFile(file, memory, size);
}
OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
void* initial) {
FILE* file = fopen(name, "w+");
if (file == NULL) return NULL;
int result = fwrite(initial, size, 1, file);
if (result < 1) {
fclose(file);
return NULL;
}
void* memory =
mmapHelper(size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
return new PosixMemoryMappedFile(file, memory, size);
}
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
if (memory_) munmap(memory_, size_);
fclose(file_);
}
static unsigned StringToLong(char* buffer) { static unsigned StringToLong(char* buffer) {
return static_cast<unsigned>(strtol(buffer, NULL, 16)); // NOLINT return static_cast<unsigned>(strtol(buffer, NULL, 16)); // NOLINT
} }
......
...@@ -59,54 +59,6 @@ void* OS::Allocate(const size_t requested, ...@@ -59,54 +59,6 @@ void* OS::Allocate(const size_t requested,
} }
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
: file_(file), memory_(memory), size_(size) { }
virtual ~PosixMemoryMappedFile();
virtual void* memory() { return memory_; }
virtual int size() { return size_; }
private:
FILE* file_;
void* memory_;
int size_;
};
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
FILE* file = fopen(name, "r+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
int size = ftell(file);
void* memory =
mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
return new PosixMemoryMappedFile(file, memory, size);
}
OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
void* initial) {
FILE* file = fopen(name, "w+");
if (file == NULL) return NULL;
int result = fwrite(initial, size, 1, file);
if (result < 1) {
fclose(file);
return NULL;
}
void* memory =
mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
return new PosixMemoryMappedFile(file, memory, size);
}
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
if (memory_) munmap(memory_, size_);
fclose(file_);
}
std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddresses> result; std::vector<SharedLibraryAddresses> result;
// This function assumes that the layout of the file is as follows: // This function assumes that the layout of the file is as follows:
......
...@@ -68,54 +68,6 @@ void* OS::Allocate(const size_t requested, ...@@ -68,54 +68,6 @@ void* OS::Allocate(const size_t requested,
} }
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
: file_(file), memory_(memory), size_(size) { }
virtual ~PosixMemoryMappedFile();
virtual void* memory() { return memory_; }
virtual int size() { return size_; }
private:
FILE* file_;
void* memory_;
int size_;
};
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
FILE* file = fopen(name, "r+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
int size = ftell(file);
void* memory =
mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
return new PosixMemoryMappedFile(file, memory, size);
}
OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
void* initial) {
FILE* file = fopen(name, "w+");
if (file == NULL) return NULL;
int result = fwrite(initial, size, 1, file);
if (result < 1) {
fclose(file);
return NULL;
}
void* memory =
mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
return new PosixMemoryMappedFile(file, memory, size);
}
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
if (memory_) munmap(memory_, size_);
fclose(file_);
}
static unsigned StringToLong(char* buffer) { static unsigned StringToLong(char* buffer) {
return static_cast<unsigned>(strtol(buffer, NULL, 16)); // NOLINT return static_cast<unsigned>(strtol(buffer, NULL, 16)); // NOLINT
} }
......
...@@ -142,64 +142,6 @@ void* OS::Allocate(const size_t requested, ...@@ -142,64 +142,6 @@ void* OS::Allocate(const size_t requested,
} }
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
: file_(file), memory_(memory), size_(size) { }
virtual ~PosixMemoryMappedFile();
virtual void* memory() { return memory_; }
virtual int size() { return size_; }
private:
FILE* file_;
void* memory_;
int size_;
};
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
FILE* file = fopen(name, "r+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
int size = ftell(file);
void* memory =
mmap(OS::GetRandomMmapAddr(),
size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
fileno(file),
0);
return new PosixMemoryMappedFile(file, memory, size);
}
OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
void* initial) {
FILE* file = fopen(name, "w+");
if (file == NULL) return NULL;
int result = fwrite(initial, size, 1, file);
if (result < 1) {
fclose(file);
return NULL;
}
void* memory =
mmap(OS::GetRandomMmapAddr(),
size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
fileno(file),
0);
return new PosixMemoryMappedFile(file, memory, size);
}
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
if (memory_) OS::Free(memory_, size_);
fclose(file_);
}
std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> result; std::vector<SharedLibraryAddress> result;
// This function assumes that the layout of the file is as follows: // This function assumes that the layout of the file is as follows:
...@@ -271,7 +213,7 @@ void OS::SignalCodeMovingGC() { ...@@ -271,7 +213,7 @@ void OS::SignalCodeMovingGC() {
// it. This injects a GC marker into the stream of events generated // it. This injects a GC marker into the stream of events generated
// by the kernel and allows us to synchronize V8 code log and the // by the kernel and allows us to synchronize V8 code log and the
// kernel log. // kernel log.
int size = sysconf(_SC_PAGESIZE); long size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int)
FILE* f = fopen(OS::GetGCFakeMMapFile(), "w+"); FILE* f = fopen(OS::GetGCFakeMMapFile(), "w+");
if (f == NULL) { if (f == NULL) {
OS::PrintError("Failed to open %s\n", OS::GetGCFakeMMapFile()); OS::PrintError("Failed to open %s\n", OS::GetGCFakeMMapFile());
...@@ -286,7 +228,7 @@ void OS::SignalCodeMovingGC() { ...@@ -286,7 +228,7 @@ void OS::SignalCodeMovingGC() {
PROT_READ | PROT_EXEC, PROT_READ | PROT_EXEC,
#endif #endif
MAP_PRIVATE, fileno(f), 0); MAP_PRIVATE, fileno(f), 0);
DCHECK(addr != MAP_FAILED); DCHECK_NE(MAP_FAILED, addr);
OS::Free(addr, size); OS::Free(addr, size);
fclose(f); fclose(f);
} }
......
...@@ -68,64 +68,6 @@ void* OS::Allocate(const size_t requested, ...@@ -68,64 +68,6 @@ void* OS::Allocate(const size_t requested,
} }
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
: file_(file), memory_(memory), size_(size) { }
virtual ~PosixMemoryMappedFile();
virtual void* memory() { return memory_; }
virtual int size() { return size_; }
private:
FILE* file_;
void* memory_;
int size_;
};
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
FILE* file = fopen(name, "r+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
int size = ftell(file);
void* memory =
mmap(OS::GetRandomMmapAddr(),
size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
fileno(file),
0);
return new PosixMemoryMappedFile(file, memory, size);
}
OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
void* initial) {
FILE* file = fopen(name, "w+");
if (file == NULL) return NULL;
int result = fwrite(initial, size, 1, file);
if (result < 1) {
fclose(file);
return NULL;
}
void* memory =
mmap(OS::GetRandomMmapAddr(),
size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
fileno(file),
0);
return new PosixMemoryMappedFile(file, memory, size);
}
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
if (memory_) OS::Free(memory_, size_);
fclose(file_);
}
std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> result; std::vector<SharedLibraryAddress> result;
unsigned int images_count = _dyld_image_count(); unsigned int images_count = _dyld_image_count();
......
...@@ -66,54 +66,6 @@ void* OS::Allocate(const size_t requested, ...@@ -66,54 +66,6 @@ void* OS::Allocate(const size_t requested,
} }
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
: file_(file), memory_(memory), size_(size) { }
virtual ~PosixMemoryMappedFile();
virtual void* memory() { return memory_; }
virtual int size() { return size_; }
private:
FILE* file_;
void* memory_;
int size_;
};
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
FILE* file = fopen(name, "r+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
int size = ftell(file);
void* memory =
mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
return new PosixMemoryMappedFile(file, memory, size);
}
OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
void* initial) {
FILE* file = fopen(name, "w+");
if (file == NULL) return NULL;
int result = fwrite(initial, size, 1, file);
if (result < 1) {
fclose(file);
return NULL;
}
void* memory =
mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
return new PosixMemoryMappedFile(file, memory, size);
}
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
if (memory_) OS::Free(memory_, size_);
fclose(file_);
}
std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> result; std::vector<SharedLibraryAddress> result;
// This function assumes that the layout of the file is as follows: // This function assumes that the layout of the file is as follows:
......
...@@ -259,6 +259,65 @@ void OS::DebugBreak() { ...@@ -259,6 +259,65 @@ void OS::DebugBreak() {
} }
class PosixMemoryMappedFile final : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, size_t size)
: file_(file), memory_(memory), size_(size) {}
~PosixMemoryMappedFile() final;
void* memory() const final { return memory_; }
size_t size() const final { return size_; }
private:
FILE* const file_;
void* const memory_;
size_t const size_;
};
// static
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
if (FILE* file = fopen(name, "r+")) {
if (fseek(file, 0, SEEK_END) == 0) {
long size = ftell(file); // NOLINT(runtime/int)
if (size >= 0) {
void* const memory =
mmap(OS::GetRandomMmapAddr(), size, PROT_READ | PROT_WRITE,
MAP_SHARED, fileno(file), 0);
if (memory != MAP_FAILED) {
return new PosixMemoryMappedFile(file, memory, size);
}
}
}
fclose(file);
}
return nullptr;
}
// static
OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name,
size_t size, void* initial) {
if (FILE* file = fopen(name, "w+")) {
size_t result = fwrite(initial, 1, size, file);
if (result == size && !ferror(file)) {
void* memory = mmap(OS::GetRandomMmapAddr(), result,
PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
if (memory != MAP_FAILED) {
return new PosixMemoryMappedFile(file, memory, result);
}
}
fclose(file);
}
return nullptr;
}
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
if (memory_) OS::Free(memory_, size_);
fclose(file_);
}
int OS::GetCurrentProcessId() { int OS::GetCurrentProcessId() {
return static_cast<int>(getpid()); return static_cast<int>(getpid());
} }
...@@ -285,7 +344,7 @@ int OS::GetCurrentThreadId() { ...@@ -285,7 +344,7 @@ int OS::GetCurrentThreadId() {
// POSIX date/time support. // POSIX date/time support.
// //
int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
#if V8_OS_NACL #if V8_OS_NACL
// Optionally used in Logger::ResourceEvent. // Optionally used in Logger::ResourceEvent.
return -1; return -1;
...@@ -293,8 +352,8 @@ int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) { ...@@ -293,8 +352,8 @@ int OS::GetUserTime(uint32_t* secs, uint32_t* usecs) {
struct rusage usage; struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage) < 0) return -1; if (getrusage(RUSAGE_SELF, &usage) < 0) return -1;
*secs = usage.ru_utime.tv_sec; *secs = static_cast<uint32_t>(usage.ru_utime.tv_sec);
*usecs = usage.ru_utime.tv_usec; *usecs = static_cast<uint32_t>(usage.ru_utime.tv_usec);
return 0; return 0;
#endif #endif
} }
......
...@@ -117,64 +117,6 @@ void* OS::Allocate(const size_t requested, ...@@ -117,64 +117,6 @@ void* OS::Allocate(const size_t requested,
} }
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
: file_(file), memory_(memory), size_(size) { }
virtual ~PosixMemoryMappedFile();
virtual void* memory() { return memory_; }
virtual int size() { return size_; }
private:
FILE* file_;
void* memory_;
int size_;
};
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
FILE* file = fopen(name, "r+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
int size = ftell(file);
void* memory =
mmap(OS::GetRandomMmapAddr(),
size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
fileno(file),
0);
return new PosixMemoryMappedFile(file, memory, size);
}
OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
void* initial) {
FILE* file = fopen(name, "w+");
if (file == NULL) return NULL;
int result = fwrite(initial, size, 1, file);
if (result < 1) {
fclose(file);
return NULL;
}
void* memory =
mmap(OS::GetRandomMmapAddr(),
size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
fileno(file),
0);
return new PosixMemoryMappedFile(file, memory, size);
}
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
if (memory_) OS::Free(memory_, size_);
fclose(file_);
}
std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
std::vector<SharedLibraryAddress> result; std::vector<SharedLibraryAddress> result;
procfs_mapinfo *mapinfos = NULL, *mapinfo; procfs_mapinfo *mapinfos = NULL, *mapinfo;
......
...@@ -63,54 +63,6 @@ void* OS::Allocate(const size_t requested, ...@@ -63,54 +63,6 @@ void* OS::Allocate(const size_t requested,
} }
class PosixMemoryMappedFile : public OS::MemoryMappedFile {
public:
PosixMemoryMappedFile(FILE* file, void* memory, int size)
: file_(file), memory_(memory), size_(size) { }
virtual ~PosixMemoryMappedFile();
virtual void* memory() { return memory_; }
virtual int size() { return size_; }
private:
FILE* file_;
void* memory_;
int size_;
};
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
FILE* file = fopen(name, "r+");
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
int size = ftell(file);
void* memory =
mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
return new PosixMemoryMappedFile(file, memory, size);
}
OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
void* initial) {
FILE* file = fopen(name, "w+");
if (file == NULL) return NULL;
int result = fwrite(initial, size, 1, file);
if (result < 1) {
fclose(file);
return NULL;
}
void* memory =
mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fileno(file), 0);
return new PosixMemoryMappedFile(file, memory, size);
}
PosixMemoryMappedFile::~PosixMemoryMappedFile() {
if (memory_) munmap(memory_, size_);
fclose(file_);
}
std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() { std::vector<OS::SharedLibraryAddress> OS::GetSharedLibraryAddresses() {
return std::vector<SharedLibraryAddress>(); return std::vector<SharedLibraryAddress>();
} }
......
...@@ -838,38 +838,38 @@ void OS::DebugBreak() { ...@@ -838,38 +838,38 @@ void OS::DebugBreak() {
} }
class Win32MemoryMappedFile : public OS::MemoryMappedFile { class Win32MemoryMappedFile final : public OS::MemoryMappedFile {
public: public:
Win32MemoryMappedFile(HANDLE file, Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory,
HANDLE file_mapping, size_t size)
void* memory,
int size)
: file_(file), : file_(file),
file_mapping_(file_mapping), file_mapping_(file_mapping),
memory_(memory), memory_(memory),
size_(size) { } size_(size) {}
virtual ~Win32MemoryMappedFile(); ~Win32MemoryMappedFile() final;
virtual void* memory() { return memory_; } void* memory() const final { return memory_; }
virtual int size() { return size_; } size_t size() const final { return size_; }
private: private:
HANDLE file_; HANDLE const file_;
HANDLE file_mapping_; HANDLE const file_mapping_;
void* memory_; void* const memory_;
int size_; size_t const size_;
}; };
// static
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
// Open a physical file // Open a physical file
HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (file == INVALID_HANDLE_VALUE) return NULL; if (file == INVALID_HANDLE_VALUE) return NULL;
int size = static_cast<int>(GetFileSize(file, NULL)); DWORD size = GetFileSize(file, NULL);
// Create a file mapping for the physical file // Create a file mapping for the physical file
HANDLE file_mapping = CreateFileMapping(file, NULL, HANDLE file_mapping =
PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL); CreateFileMapping(file, NULL, PAGE_READWRITE, 0, size, NULL);
if (file_mapping == NULL) return NULL; if (file_mapping == NULL) return NULL;
// Map a view of the file into memory // Map a view of the file into memory
...@@ -878,15 +878,17 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) { ...@@ -878,15 +878,17 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
} }
OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, // static
void* initial) { OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name,
size_t size, void* initial) {
// Open a physical file // Open a physical file
HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE, HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
OPEN_ALWAYS, 0, NULL);
if (file == NULL) return NULL; if (file == NULL) return NULL;
// Create a file mapping for the physical file // Create a file mapping for the physical file
HANDLE file_mapping = CreateFileMapping(file, NULL, HANDLE file_mapping = CreateFileMapping(file, NULL, PAGE_READWRITE, 0,
PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL); static_cast<DWORD>(size), NULL);
if (file_mapping == NULL) return NULL; if (file_mapping == NULL) return NULL;
// Map a view of the file into memory // Map a view of the file into memory
void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size); void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
...@@ -896,8 +898,7 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size, ...@@ -896,8 +898,7 @@ OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
Win32MemoryMappedFile::~Win32MemoryMappedFile() { Win32MemoryMappedFile::~Win32MemoryMappedFile() {
if (memory_ != NULL) if (memory_) UnmapViewOfFile(memory_);
UnmapViewOfFile(memory_);
CloseHandle(file_mapping_); CloseHandle(file_mapping_);
CloseHandle(file_); CloseHandle(file_);
} }
......
...@@ -210,11 +210,13 @@ class OS { ...@@ -210,11 +210,13 @@ class OS {
class MemoryMappedFile { class MemoryMappedFile {
public: public:
virtual ~MemoryMappedFile() {}
virtual void* memory() const = 0;
virtual size_t size() const = 0;
static MemoryMappedFile* open(const char* name); static MemoryMappedFile* open(const char* name);
static MemoryMappedFile* create(const char* name, int size, void* initial); static MemoryMappedFile* create(const char* name, size_t size,
virtual ~MemoryMappedFile() { } void* initial);
virtual void* memory() = 0;
virtual int size() = 0;
}; };
// Safe formatting print. Ensures that str is always null-terminated. // Safe formatting print. Ensures that str is always null-terminated.
......
...@@ -133,7 +133,7 @@ TimeDelta TimeDelta::FromTimespec(struct timespec ts) { ...@@ -133,7 +133,7 @@ TimeDelta TimeDelta::FromTimespec(struct timespec ts) {
struct timespec TimeDelta::ToTimespec() const { struct timespec TimeDelta::ToTimespec() const {
struct timespec ts; struct timespec ts;
ts.tv_sec = delta_ / Time::kMicrosecondsPerSecond; ts.tv_sec = static_cast<time_t>(delta_ / Time::kMicrosecondsPerSecond);
ts.tv_nsec = (delta_ % Time::kMicrosecondsPerSecond) * ts.tv_nsec = (delta_ % Time::kMicrosecondsPerSecond) *
Time::kNanosecondsPerMicrosecond; Time::kNanosecondsPerMicrosecond;
return ts; return ts;
...@@ -292,7 +292,7 @@ struct timespec Time::ToTimespec() const { ...@@ -292,7 +292,7 @@ struct timespec Time::ToTimespec() const {
ts.tv_nsec = static_cast<long>(kNanosecondsPerSecond - 1); // NOLINT ts.tv_nsec = static_cast<long>(kNanosecondsPerSecond - 1); // NOLINT
return ts; return ts;
} }
ts.tv_sec = us_ / kMicrosecondsPerSecond; ts.tv_sec = static_cast<time_t>(us_ / kMicrosecondsPerSecond);
ts.tv_nsec = (us_ % kMicrosecondsPerSecond) * kNanosecondsPerMicrosecond; ts.tv_nsec = (us_ % kMicrosecondsPerSecond) * kNanosecondsPerMicrosecond;
return ts; return ts;
} }
...@@ -324,7 +324,7 @@ struct timeval Time::ToTimeval() const { ...@@ -324,7 +324,7 @@ struct timeval Time::ToTimeval() const {
tv.tv_usec = static_cast<suseconds_t>(kMicrosecondsPerSecond - 1); tv.tv_usec = static_cast<suseconds_t>(kMicrosecondsPerSecond - 1);
return tv; return tv;
} }
tv.tv_sec = us_ / kMicrosecondsPerSecond; tv.tv_sec = static_cast<time_t>(us_ / kMicrosecondsPerSecond);
tv.tv_usec = us_ % kMicrosecondsPerSecond; tv.tv_usec = us_ % kMicrosecondsPerSecond;
return tv; return tv;
} }
......
...@@ -89,8 +89,9 @@ static bool WaitOnFD(int fd, ...@@ -89,8 +89,9 @@ static bool WaitOnFD(int fd,
if (total_timeout != -1) { if (total_timeout != -1) {
struct timeval time_now; struct timeval time_now;
gettimeofday(&time_now, NULL); gettimeofday(&time_now, NULL);
int seconds = time_now.tv_sec - start_time.tv_sec; time_t seconds = time_now.tv_sec - start_time.tv_sec;
gone = seconds * 1000 + (time_now.tv_usec - start_time.tv_usec) / 1000; gone = static_cast<int>(seconds * 1000 +
(time_now.tv_usec - start_time.tv_usec) / 1000);
if (gone >= total_timeout) return false; if (gone >= total_timeout) return false;
} }
FD_ZERO(&readfds); FD_ZERO(&readfds);
...@@ -125,12 +126,12 @@ static bool TimeIsOut(const struct timeval& start_time, const int& total_time) { ...@@ -125,12 +126,12 @@ static bool TimeIsOut(const struct timeval& start_time, const int& total_time) {
struct timeval time_now; struct timeval time_now;
gettimeofday(&time_now, NULL); gettimeofday(&time_now, NULL);
// Careful about overflow. // Careful about overflow.
int seconds = time_now.tv_sec - start_time.tv_sec; int seconds = static_cast<int>(time_now.tv_sec - start_time.tv_sec);
if (seconds > 100) { if (seconds > 100) {
if (seconds * 1000 > total_time) return true; if (seconds * 1000 > total_time) return true;
return false; return false;
} }
int useconds = time_now.tv_usec - start_time.tv_usec; int useconds = static_cast<int>(time_now.tv_usec - start_time.tv_usec);
if (seconds * 1000000 + useconds > total_time * 1000) { if (seconds * 1000000 + useconds > total_time * 1000) {
return true; return true;
} }
...@@ -264,7 +265,7 @@ static void ExecSubprocess(int* exec_error_fds, ...@@ -264,7 +265,7 @@ static void ExecSubprocess(int* exec_error_fds,
// Only get here if the exec failed. Write errno to the parent to tell // Only get here if the exec failed. Write errno to the parent to tell
// them it went wrong. If it went well the pipe is closed. // them it went wrong. If it went well the pipe is closed.
int err = errno; int err = errno;
int bytes_written; ssize_t bytes_written;
do { do {
bytes_written = write(exec_error_fds[kWriteFD], &err, sizeof(err)); bytes_written = write(exec_error_fds[kWriteFD], &err, sizeof(err));
} while (bytes_written == -1 && errno == EINTR); } while (bytes_written == -1 && errno == EINTR);
...@@ -275,7 +276,7 @@ static void ExecSubprocess(int* exec_error_fds, ...@@ -275,7 +276,7 @@ static void ExecSubprocess(int* exec_error_fds,
// Runs in the parent process. Checks that the child was able to exec (closing // Runs in the parent process. Checks that the child was able to exec (closing
// the file desriptor), or reports an error if it failed. // the file desriptor), or reports an error if it failed.
static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) { static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) {
int bytes_read; ssize_t bytes_read;
int err; int err;
do { do {
bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err)); bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err));
...@@ -308,9 +309,8 @@ static Handle<Value> GetStdout(Isolate* isolate, ...@@ -308,9 +309,8 @@ static Handle<Value> GetStdout(Isolate* isolate,
int bytes_read; int bytes_read;
do { do {
bytes_read = read(child_fd, bytes_read = static_cast<int>(
buffer + fullness, read(child_fd, buffer + fullness, kStdoutReadBufferSize - fullness));
kStdoutReadBufferSize - fullness);
if (bytes_read == -1) { if (bytes_read == -1) {
if (errno == EAGAIN) { if (errno == EAGAIN) {
if (!WaitOnFD(child_fd, if (!WaitOnFD(child_fd,
......
...@@ -1113,17 +1113,21 @@ static char* ReadChars(Isolate* isolate, const char* name, int* size_out) { ...@@ -1113,17 +1113,21 @@ static char* ReadChars(Isolate* isolate, const char* name, int* size_out) {
if (file == NULL) return NULL; if (file == NULL) return NULL;
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
int size = ftell(file); size_t size = ftell(file);
rewind(file); rewind(file);
char* chars = new char[size + 1]; char* chars = new char[size + 1];
chars[size] = '\0'; chars[size] = '\0';
for (int i = 0; i < size;) { for (size_t i = 0; i < size;) {
int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); i += fread(&chars[i], 1, size - i, file);
i += read; if (ferror(file)) {
fclose(file);
delete[] chars;
return nullptr;
}
} }
fclose(file); fclose(file);
*size_out = size; *size_out = static_cast<int>(size);
return chars; return chars;
} }
......
...@@ -394,7 +394,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -394,7 +394,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
*flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !is_bool); *flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !is_bool);
break; break;
case Flag::TYPE_INT: case Flag::TYPE_INT:
*flag->int_variable() = strtol(value, &endp, 10); // NOLINT *flag->int_variable() = static_cast<int>(strtol(value, &endp, 10));
break; break;
case Flag::TYPE_FLOAT: case Flag::TYPE_FLOAT:
*flag->float_variable() = strtod(value, &endp); *flag->float_variable() = strtod(value, &endp);
......
...@@ -179,7 +179,7 @@ class DebugSectionBase : public ZoneObject { ...@@ -179,7 +179,7 @@ class DebugSectionBase : public ZoneObject {
uintptr_t start = writer->position(); uintptr_t start = writer->position();
if (WriteBodyInternal(writer)) { if (WriteBodyInternal(writer)) {
uintptr_t end = writer->position(); uintptr_t end = writer->position();
header->offset = start; header->offset = static_cast<uint32_t>(start);
#if defined(__MACH_O) #if defined(__MACH_O)
header->addr = 0; header->addr = 0;
#endif #endif
...@@ -465,7 +465,7 @@ class ELFStringTable : public ELFSection { ...@@ -465,7 +465,7 @@ class ELFStringTable : public ELFSection {
void ELFSection::PopulateHeader(Writer::Slot<ELFSection::Header> header, void ELFSection::PopulateHeader(Writer::Slot<ELFSection::Header> header,
ELFStringTable* strtab) { ELFStringTable* strtab) {
header->name = strtab->Add(name_); header->name = static_cast<uint32_t>(strtab->Add(name_));
header->type = type_; header->type = type_;
header->alignment = align_; header->alignment = align_;
PopulateHeader(header); PopulateHeader(header);
...@@ -813,7 +813,7 @@ class ELFSymbol BASE_EMBEDDED { ...@@ -813,7 +813,7 @@ class ELFSymbol BASE_EMBEDDED {
void Write(Writer::Slot<SerializedLayout> s, ELFStringTable* t) { void Write(Writer::Slot<SerializedLayout> s, ELFStringTable* t) {
// Convert symbol names from strings to indexes in the string table. // Convert symbol names from strings to indexes in the string table.
s->name = t->Add(name); s->name = static_cast<uint32_t>(t->Add(name));
s->value = value; s->value = value;
s->size = size; s->size = size;
s->info = info; s->info = info;
...@@ -1638,7 +1638,7 @@ void UnwindInfoSection::WriteLength(Writer* w, ...@@ -1638,7 +1638,7 @@ void UnwindInfoSection::WriteLength(Writer* w,
} }
DCHECK((w->position() - initial_position) % kPointerSize == 0); DCHECK((w->position() - initial_position) % kPointerSize == 0);
length_slot->set(w->position() - initial_position); length_slot->set(static_cast<uint32_t>(w->position() - initial_position));
} }
...@@ -1653,7 +1653,7 @@ UnwindInfoSection::UnwindInfoSection(CodeDescription* desc) ...@@ -1653,7 +1653,7 @@ UnwindInfoSection::UnwindInfoSection(CodeDescription* desc)
int UnwindInfoSection::WriteCIE(Writer* w) { int UnwindInfoSection::WriteCIE(Writer* w) {
Writer::Slot<uint32_t> cie_length_slot = w->CreateSlotHere<uint32_t>(); Writer::Slot<uint32_t> cie_length_slot = w->CreateSlotHere<uint32_t>();
uint32_t cie_position = w->position(); uint32_t cie_position = static_cast<uint32_t>(w->position());
// Write out the CIE header. Currently no 'common instructions' are // Write out the CIE header. Currently no 'common instructions' are
// emitted onto the CIE; every FDE has its own set of instructions. // emitted onto the CIE; every FDE has its own set of instructions.
...@@ -1674,7 +1674,7 @@ int UnwindInfoSection::WriteCIE(Writer* w) { ...@@ -1674,7 +1674,7 @@ int UnwindInfoSection::WriteCIE(Writer* w) {
void UnwindInfoSection::WriteFDE(Writer* w, int cie_position) { void UnwindInfoSection::WriteFDE(Writer* w, int cie_position) {
// The only FDE for this function. The CFA is the current RBP. // The only FDE for this function. The CFA is the current RBP.
Writer::Slot<uint32_t> fde_length_slot = w->CreateSlotHere<uint32_t>(); Writer::Slot<uint32_t> fde_length_slot = w->CreateSlotHere<uint32_t>();
int fde_position = w->position(); int fde_position = static_cast<uint32_t>(w->position());
w->Write<int32_t>(fde_position - cie_position + 4); w->Write<int32_t>(fde_position - cie_position + 4);
w->Write<uintptr_t>(desc_->CodeStart()); w->Write<uintptr_t>(desc_->CodeStart());
...@@ -2067,7 +2067,8 @@ static void AddJITCodeEntry(CodeMap* map, const AddressRange& range, ...@@ -2067,7 +2067,8 @@ static void AddJITCodeEntry(CodeMap* map, const AddressRange& range,
SNPrintF(Vector<char>(file_name, kMaxFileNameSize), "/tmp/elfdump%s%d.o", SNPrintF(Vector<char>(file_name, kMaxFileNameSize), "/tmp/elfdump%s%d.o",
(name_hint != NULL) ? name_hint : "", file_num++); (name_hint != NULL) ? name_hint : "", file_num++);
WriteBytes(file_name, entry->symfile_addr_, entry->symfile_size_); WriteBytes(file_name, entry->symfile_addr_,
static_cast<int>(entry->symfile_size_));
} }
#endif #endif
......
...@@ -118,13 +118,13 @@ char* GetExtraCode(char* filename) { ...@@ -118,13 +118,13 @@ char* GetExtraCode(char* filename) {
exit(1); exit(1);
} }
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
int size = ftell(file); size_t size = ftell(file);
rewind(file); rewind(file);
char* chars = new char[size + 1]; char* chars = new char[size + 1];
chars[size] = '\0'; chars[size] = '\0';
for (int i = 0; i < size;) { for (size_t i = 0; i < size;) {
int read = static_cast<int>(fread(&chars[i], 1, size - i, file)); size_t read = fread(&chars[i], 1, size - i, file);
if (read < 0) { if (ferror(file)) {
fprintf(stderr, "Failed to read '%s': errno %d\n", filename, errno); fprintf(stderr, "Failed to read '%s': errno %d\n", filename, errno);
exit(1); exit(1);
} }
......
...@@ -203,7 +203,7 @@ char* ReadCharsFromFile(FILE* file, ...@@ -203,7 +203,7 @@ char* ReadCharsFromFile(FILE* file,
} }
// Get the size of the file and rewind it. // Get the size of the file and rewind it.
*size = ftell(file); *size = static_cast<int>(ftell(file));
rewind(file); rewind(file);
char* result = NewArray<char>(*size + extra_space); char* result = NewArray<char>(*size + extra_space);
......
...@@ -128,6 +128,9 @@ struct ParameterTraits<T*> { ...@@ -128,6 +128,9 @@ struct ParameterTraits<T*> {
static uintptr_t Cast(void* r) { return reinterpret_cast<uintptr_t>(r); } static uintptr_t Cast(void* r) { return reinterpret_cast<uintptr_t>(r); }
}; };
#if !V8_TARGET_ARCH_32_BIT
// Additional template specialization required for mips64 to sign-extend // Additional template specialization required for mips64 to sign-extend
// parameters defined by calling convention. // parameters defined by calling convention.
template <> template <>
...@@ -142,6 +145,9 @@ struct ParameterTraits<uint32_t> { ...@@ -142,6 +145,9 @@ struct ParameterTraits<uint32_t> {
} }
}; };
#endif // !V8_TARGET_ARCH_64_BIT
class CallHelper { class CallHelper {
public: public:
explicit CallHelper(Isolate* isolate, MachineSignature* machine_sig) explicit CallHelper(Isolate* isolate, MachineSignature* machine_sig)
......
...@@ -423,7 +423,7 @@ static intptr_t MemoryInUse() { ...@@ -423,7 +423,7 @@ static intptr_t MemoryInUse() {
const int kBufSize = 10000; const int kBufSize = 10000;
char buffer[kBufSize]; char buffer[kBufSize];
int length = read(fd, buffer, kBufSize); ssize_t length = read(fd, buffer, kBufSize);
intptr_t line_start = 0; intptr_t line_start = 0;
CHECK_LT(length, kBufSize); // Make the buffer bigger. CHECK_LT(length, kBufSize); // Make the buffer bigger.
CHECK_GT(length, 0); // We have to find some data in the file. CHECK_GT(length, 0); // We have to find some data in the file.
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
// Utility functions used by parser-shell. // Utility functions used by parser-shell.
#include "src/globals.h"
#include <stdio.h> #include <stdio.h>
namespace v8 { namespace v8 {
...@@ -44,7 +46,7 @@ const byte* ReadFileAndRepeat(const char* name, int* size, int repeat) { ...@@ -44,7 +46,7 @@ const byte* ReadFileAndRepeat(const char* name, int* size, int repeat) {
if (file == NULL) return NULL; if (file == NULL) return NULL;
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
int file_size = ftell(file); int file_size = static_cast<int>(ftell(file));
rewind(file); rewind(file);
*size = file_size * repeat; *size = file_size * repeat;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment