'-Wall',
'-Werror',
'-Wextra',
+ '-Wshorten-64-to-32',
],
'cflags+': [
# Clang considers the `register` keyword as deprecated, but
'cflags_cc': [ '-Wnon-virtual-dtor', '-fno-rtti', '-std=gnu++0x' ],
'ldflags': [ '-pthread', ],
'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"', {
'cflags': [ '-mminimal-toc' ],
}],
if (file == NULL) return Handle<String>();
fseek(file, 0, SEEK_END);
- int size = ftell(file);
+ size_t size = ftell(file);
rewind(file);
char* chars = new char[size + 1];
chars[size] = '\0';
- for (int i = 0; i < size;) {
- int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
- i += read;
+ for (size_t i = 0; i < size;) {
+ i += fread(&chars[i], 1, size - i, file);
+ if (ferror(file)) {
+ fclose(file);
+ return Handle<String>();
+ }
}
fclose(file);
- Handle<String> result =
- String::NewFromUtf8(isolate, chars, String::kNormalString, size);
+ Handle<String> result = String::NewFromUtf8(
+ isolate, chars, String::kNormalString, static_cast<int>(size));
delete[] chars;
return result;
}
if (file == NULL) return v8::Handle<v8::String>();
fseek(file, 0, SEEK_END);
- int size = ftell(file);
+ size_t size = ftell(file);
rewind(file);
char* chars = new char[size + 1];
chars[size] = '\0';
- for (int i = 0; i < size;) {
- int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
- i += read;
+ for (size_t i = 0; i < size;) {
+ i += fread(&chars[i], 1, size - i, file);
+ if (ferror(file)) {
+ fclose(file);
+ return v8::Handle<v8::String>();
+ }
}
fclose(file);
- v8::Handle<v8::String> result =
- v8::String::NewFromUtf8(isolate, chars, v8::String::kNormalString, size);
+ v8::Handle<v8::String> result = v8::String::NewFromUtf8(
+ isolate, chars, v8::String::kNormalString, static_cast<int>(size));
delete[] chars;
return result;
}
}
-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) {
return static_cast<unsigned>(strtol(buffer, NULL, 16)); // NOLINT
}
}
-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<SharedLibraryAddresses> result;
// This function assumes that the layout of the file is as follows:
}
-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) {
return static_cast<unsigned>(strtol(buffer, NULL, 16)); // NOLINT
}
}
-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<SharedLibraryAddress> result;
// This function assumes that the layout of the file is as follows:
// 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
// kernel log.
- int size = sysconf(_SC_PAGESIZE);
+ long size = sysconf(_SC_PAGESIZE); // NOLINT(runtime/int)
FILE* f = fopen(OS::GetGCFakeMMapFile(), "w+");
if (f == NULL) {
OS::PrintError("Failed to open %s\n", OS::GetGCFakeMMapFile());
PROT_READ | PROT_EXEC,
#endif
MAP_PRIVATE, fileno(f), 0);
- DCHECK(addr != MAP_FAILED);
+ DCHECK_NE(MAP_FAILED, addr);
OS::Free(addr, size);
fclose(f);
}
}
-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<SharedLibraryAddress> result;
unsigned int images_count = _dyld_image_count();
}
-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<SharedLibraryAddress> result;
// This function assumes that the layout of the file is as follows:
}
+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() {
return static_cast<int>(getpid());
}
// 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
// Optionally used in Logger::ResourceEvent.
return -1;
struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage) < 0) return -1;
- *secs = usage.ru_utime.tv_sec;
- *usecs = usage.ru_utime.tv_usec;
+ *secs = static_cast<uint32_t>(usage.ru_utime.tv_sec);
+ *usecs = static_cast<uint32_t>(usage.ru_utime.tv_usec);
return 0;
#endif
}
}
-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<SharedLibraryAddress> result;
procfs_mapinfo *mapinfos = NULL, *mapinfo;
}
-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() {
return std::vector<SharedLibraryAddress>();
}
}
-class Win32MemoryMappedFile : public OS::MemoryMappedFile {
+class Win32MemoryMappedFile final : public OS::MemoryMappedFile {
public:
- Win32MemoryMappedFile(HANDLE file,
- HANDLE file_mapping,
- void* memory,
- int size)
+ Win32MemoryMappedFile(HANDLE file, HANDLE file_mapping, void* memory,
+ size_t size)
: file_(file),
file_mapping_(file_mapping),
memory_(memory),
- size_(size) { }
- virtual ~Win32MemoryMappedFile();
- virtual void* memory() { return memory_; }
- virtual int size() { return size_; }
+ size_(size) {}
+ ~Win32MemoryMappedFile() final;
+ void* memory() const final { return memory_; }
+ size_t size() const final { return size_; }
+
private:
- HANDLE file_;
- HANDLE file_mapping_;
- void* memory_;
- int size_;
+ HANDLE const file_;
+ HANDLE const file_mapping_;
+ void* const memory_;
+ size_t const size_;
};
+// static
OS::MemoryMappedFile* OS::MemoryMappedFile::open(const char* name) {
// Open a physical file
HANDLE file = CreateFileA(name, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 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
- HANDLE file_mapping = CreateFileMapping(file, NULL,
- PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL);
+ HANDLE file_mapping =
+ CreateFileMapping(file, NULL, PAGE_READWRITE, 0, size, NULL);
if (file_mapping == NULL) return NULL;
// Map a view of the file into memory
}
-OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name, int size,
- void* initial) {
+// static
+OS::MemoryMappedFile* OS::MemoryMappedFile::create(const char* name,
+ size_t size, void* initial) {
// Open a physical file
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;
// Create a file mapping for the physical file
- HANDLE file_mapping = CreateFileMapping(file, NULL,
- PAGE_READWRITE, 0, static_cast<DWORD>(size), NULL);
+ HANDLE file_mapping = CreateFileMapping(file, NULL, PAGE_READWRITE, 0,
+ static_cast<DWORD>(size), NULL);
if (file_mapping == NULL) return NULL;
// Map a view of the file into memory
void* memory = MapViewOfFile(file_mapping, FILE_MAP_ALL_ACCESS, 0, 0, size);
Win32MemoryMappedFile::~Win32MemoryMappedFile() {
- if (memory_ != NULL)
- UnmapViewOfFile(memory_);
+ if (memory_) UnmapViewOfFile(memory_);
CloseHandle(file_mapping_);
CloseHandle(file_);
}
class MemoryMappedFile {
public:
+ virtual ~MemoryMappedFile() {}
+ virtual void* memory() const = 0;
+ virtual size_t size() const = 0;
+
static MemoryMappedFile* open(const char* name);
- static MemoryMappedFile* create(const char* name, int size, void* initial);
- virtual ~MemoryMappedFile() { }
- virtual void* memory() = 0;
- virtual int size() = 0;
+ static MemoryMappedFile* create(const char* name, size_t size,
+ void* initial);
};
// Safe formatting print. Ensures that str is always null-terminated.
struct timespec TimeDelta::ToTimespec() const {
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) *
Time::kNanosecondsPerMicrosecond;
return ts;
ts.tv_nsec = static_cast<long>(kNanosecondsPerSecond - 1); // NOLINT
return ts;
}
- ts.tv_sec = us_ / kMicrosecondsPerSecond;
+ ts.tv_sec = static_cast<time_t>(us_ / kMicrosecondsPerSecond);
ts.tv_nsec = (us_ % kMicrosecondsPerSecond) * kNanosecondsPerMicrosecond;
return ts;
}
tv.tv_usec = static_cast<suseconds_t>(kMicrosecondsPerSecond - 1);
return tv;
}
- tv.tv_sec = us_ / kMicrosecondsPerSecond;
+ tv.tv_sec = static_cast<time_t>(us_ / kMicrosecondsPerSecond);
tv.tv_usec = us_ % kMicrosecondsPerSecond;
return tv;
}
if (total_timeout != -1) {
struct timeval time_now;
gettimeofday(&time_now, NULL);
- int seconds = time_now.tv_sec - start_time.tv_sec;
- gone = seconds * 1000 + (time_now.tv_usec - start_time.tv_usec) / 1000;
+ time_t seconds = time_now.tv_sec - start_time.tv_sec;
+ gone = static_cast<int>(seconds * 1000 +
+ (time_now.tv_usec - start_time.tv_usec) / 1000);
if (gone >= total_timeout) return false;
}
FD_ZERO(&readfds);
struct timeval time_now;
gettimeofday(&time_now, NULL);
// 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 * 1000 > total_time) return true;
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) {
return true;
}
// 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.
int err = errno;
- int bytes_written;
+ ssize_t bytes_written;
do {
bytes_written = write(exec_error_fds[kWriteFD], &err, sizeof(err));
} while (bytes_written == -1 && errno == EINTR);
// Runs in the parent process. Checks that the child was able to exec (closing
// the file desriptor), or reports an error if it failed.
static bool ChildLaunchedOK(Isolate* isolate, int* exec_error_fds) {
- int bytes_read;
+ ssize_t bytes_read;
int err;
do {
bytes_read = read(exec_error_fds[kReadFD], &err, sizeof(err));
int bytes_read;
do {
- bytes_read = read(child_fd,
- buffer + fullness,
- kStdoutReadBufferSize - fullness);
+ bytes_read = static_cast<int>(
+ read(child_fd, buffer + fullness, kStdoutReadBufferSize - fullness));
if (bytes_read == -1) {
if (errno == EAGAIN) {
if (!WaitOnFD(child_fd,
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
- int size = ftell(file);
+ size_t size = ftell(file);
rewind(file);
char* chars = new char[size + 1];
chars[size] = '\0';
- for (int i = 0; i < size;) {
- int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
- i += read;
+ for (size_t i = 0; i < size;) {
+ i += fread(&chars[i], 1, size - i, file);
+ if (ferror(file)) {
+ fclose(file);
+ delete[] chars;
+ return nullptr;
+ }
}
fclose(file);
- *size_out = size;
+ *size_out = static_cast<int>(size);
return chars;
}
*flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !is_bool);
break;
case Flag::TYPE_INT:
- *flag->int_variable() = strtol(value, &endp, 10); // NOLINT
+ *flag->int_variable() = static_cast<int>(strtol(value, &endp, 10));
break;
case Flag::TYPE_FLOAT:
*flag->float_variable() = strtod(value, &endp);
uintptr_t start = writer->position();
if (WriteBodyInternal(writer)) {
uintptr_t end = writer->position();
- header->offset = start;
+ header->offset = static_cast<uint32_t>(start);
#if defined(__MACH_O)
header->addr = 0;
#endif
void ELFSection::PopulateHeader(Writer::Slot<ELFSection::Header> header,
ELFStringTable* strtab) {
- header->name = strtab->Add(name_);
+ header->name = static_cast<uint32_t>(strtab->Add(name_));
header->type = type_;
header->alignment = align_;
PopulateHeader(header);
void Write(Writer::Slot<SerializedLayout> s, ELFStringTable* t) {
// 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->size = size;
s->info = info;
}
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));
}
int UnwindInfoSection::WriteCIE(Writer* w) {
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
// emitted onto the CIE; every FDE has its own set of instructions.
void UnwindInfoSection::WriteFDE(Writer* w, int cie_position) {
// The only FDE for this function. The CFA is the current RBP.
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<uintptr_t>(desc_->CodeStart());
SNPrintF(Vector<char>(file_name, kMaxFileNameSize), "/tmp/elfdump%s%d.o",
(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
exit(1);
}
fseek(file, 0, SEEK_END);
- int size = ftell(file);
+ size_t size = ftell(file);
rewind(file);
char* chars = new char[size + 1];
chars[size] = '\0';
- for (int i = 0; i < size;) {
- int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
- if (read < 0) {
+ for (size_t i = 0; i < size;) {
+ size_t read = fread(&chars[i], 1, size - i, file);
+ if (ferror(file)) {
fprintf(stderr, "Failed to read '%s': errno %d\n", filename, errno);
exit(1);
}
}
// Get the size of the file and rewind it.
- *size = ftell(file);
+ *size = static_cast<int>(ftell(file));
rewind(file);
char* result = NewArray<char>(*size + extra_space);
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
// parameters defined by calling convention.
template <>
}
};
+#endif // !V8_TARGET_ARCH_64_BIT
+
+
class CallHelper {
public:
explicit CallHelper(Isolate* isolate, MachineSignature* machine_sig)
const int kBufSize = 10000;
char buffer[kBufSize];
- int length = read(fd, buffer, kBufSize);
+ ssize_t length = read(fd, buffer, kBufSize);
intptr_t line_start = 0;
CHECK_LT(length, kBufSize); // Make the buffer bigger.
CHECK_GT(length, 0); // We have to find some data in the file.
// Utility functions used by parser-shell.
+#include "src/globals.h"
+
#include <stdio.h>
namespace v8 {
if (file == NULL) return NULL;
fseek(file, 0, SEEK_END);
- int file_size = ftell(file);
+ int file_size = static_cast<int>(ftell(file));
rewind(file);
*size = file_size * repeat;