diff options
| author | Timur Iskhodzhanov <timurrrr@google.com> | 2015-04-09 12:37:05 +0000 |
|---|---|---|
| committer | Timur Iskhodzhanov <timurrrr@google.com> | 2015-04-09 12:37:05 +0000 |
| commit | 864308a78de8d1478386f49c7d87636bf6ccb61b (patch) | |
| tree | b40052c3f9dc9152a162aca3fc45f5fcce8876dc /compiler-rt/lib/sanitizer_common | |
| parent | b49b2d21665c6a66788a17c8b1deae2af55438db (diff) | |
| download | bcm5719-llvm-864308a78de8d1478386f49c7d87636bf6ccb61b.tar.gz bcm5719-llvm-864308a78de8d1478386f49c7d87636bf6ccb61b.zip | |
Introduce CloseFile to be used instead of internal_close on non-POSIX
llvm-svn: 234481
Diffstat (limited to 'compiler-rt/lib/sanitizer_common')
9 files changed, 24 insertions, 19 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index e499de04edc..d2730567991 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -54,7 +54,7 @@ void ReportFile::ReopenIfNecessary() { if (fd_pid == pid) return; else - internal_close(fd); + CloseFile(fd); } internal_snprintf(full_path, kMaxPathLength, "%s.%zu", path_prefix, pid); @@ -81,7 +81,7 @@ void ReportFile::SetReportPath(const char *path) { SpinMutexLock l(mu); if (fd != kStdoutFd && fd != kStderrFd && fd != kInvalidFd) - internal_close(fd); + CloseFile(fd); fd = kInvalidFd; if (internal_strcmp(path, "stdout") == 0) { fd = kStdoutFd; @@ -163,7 +163,7 @@ uptr ReadFileToBuffer(const char *file_name, char **buff, uptr *buff_size, } read_len += just_read; } - internal_close(fd); + CloseFile(fd); if (reached_eof) // We've read the whole file. break; } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index 3e7288286e2..e46ea8186b7 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -199,6 +199,7 @@ enum FileAccessMode { // Returns kInvalidFd on error. fd_t OpenFile(const char *filename, FileAccessMode mode, error_t *errno_p = nullptr); +void CloseFile(fd_t); bool SupportsColoredOutput(fd_t fd); // Opens the file 'file_name" and reads up to 'max_len' bytes. diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc index 64b7e4efbef..b335838ad3b 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_libcdep.cc @@ -245,7 +245,7 @@ void CoverageData::Disable() { tr_event_pointer = nullptr; } if (pc_fd != kInvalidFd) { - internal_close(pc_fd); + CloseFile(pc_fd); pc_fd = kInvalidFd; } } @@ -596,7 +596,7 @@ void CoverageData::DumpTrace() { fd_t fd = CovOpenFile(&path, false, "trace-points"); if (fd == kInvalidFd) return; internal_write(fd, out.data(), out.length()); - internal_close(fd); + CloseFile(fd); fd = CovOpenFile(&path, false, "trace-compunits"); if (fd == kInvalidFd) return; @@ -604,7 +604,7 @@ void CoverageData::DumpTrace() { for (uptr i = 0; i < comp_unit_name_vec.size(); i++) out.append("%s\n", comp_unit_name_vec[i].copied_module_name); internal_write(fd, out.data(), out.length()); - internal_close(fd); + CloseFile(fd); fd = CovOpenFile(&path, false, "trace-events"); if (fd == kInvalidFd) return; @@ -620,7 +620,7 @@ void CoverageData::DumpTrace() { break; } } - internal_close(fd); + CloseFile(fd); VReport(1, " CovDump: Trace: %zd PCs written\n", size()); VReport(1, " CovDump: Trace: %zd Events written\n", max_idx); } @@ -661,7 +661,7 @@ void CoverageData::DumpCallerCalleePairs() { fd_t fd = CovOpenFile(&path, false, "caller-callee"); if (fd == kInvalidFd) return; internal_write(fd, out.data(), out.length()); - internal_close(fd); + CloseFile(fd); VReport(1, " CovDump: %zd caller-callee pairs written\n", total); } @@ -696,7 +696,7 @@ void CoverageData::DumpCounters() { CovOpenFile(&path, /* packed */ false, base_name, "counters-sancov"); if (fd == kInvalidFd) return; internal_write(fd, bitset.data() + r.beg, r.end - r.beg); - internal_close(fd); + CloseFile(fd); VReport(1, " CovDump: %zd counters written for '%s'\n", r.end - r.beg, base_name); } @@ -723,7 +723,7 @@ void CoverageData::DumpAsBitSet() { fd_t fd = CovOpenFile(&path, /* packed */false, base_name, "bitset-sancov"); if (fd == kInvalidFd) return; internal_write(fd, out.data() + r.beg, r.end - r.beg); - internal_close(fd); + CloseFile(fd); VReport(1, " CovDump: bitset of %zd bits written for '%s', %zd bits are set\n", r.end - r.beg, base_name, n_set_bits); @@ -778,12 +778,12 @@ void CoverageData::DumpOffsets() { fd_t fd = CovOpenFile(&path, false /* packed */, module_name); if (fd == kInvalidFd) continue; internal_write(fd, offsets.data(), offsets.size() * sizeof(offsets[0])); - internal_close(fd); + CloseFile(fd); VReport(1, " CovDump: %s: %zd PCs written\n", path.data(), num_offsets); } } if (cov_fd != kInvalidFd) - internal_close(cov_fd); + CloseFile(cov_fd); } void CoverageData::DumpAll() { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc index 96244fedaa8..efb6d626985 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc @@ -113,7 +113,7 @@ void CovUpdateMapping(const char *coverage_dir, uptr caller_pc) { Printf("sancov.map write failed: %d\n", err); Die(); } - internal_close(map_fd); + CloseFile(map_fd); InternalScopedString path(64 + internal_strlen(coverage_dir)); res = internal_snprintf((char *)path.data(), path.size(), "%s/%zd.sancov.map", diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h index 6a05ba66a89..edd92fef489 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h @@ -62,7 +62,6 @@ const fd_t kInvalidFd = -1; const fd_t kStdinFd = 0; const fd_t kStdoutFd = 1; const fd_t kStderrFd = 2; -uptr internal_close(fd_t fd); uptr internal_read(fd_t fd, void *buf, uptr count); uptr internal_write(fd_t fd, const void *buf, uptr count); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc index 77db0daac0f..e0638e84cc3 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc @@ -219,6 +219,10 @@ fd_t OpenFile(const char *filename, FileAccessMode mode, error_t *errno_p) { return res; } +void CloseFile(fd_t fd) { + internal_close(fd); +} + void *MapFileToMemory(const char *file_name, uptr *buff_size) { fd_t fd = OpenFile(file_name, RdOnly); CHECK(fd != kInvalidFd); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_posix.h index 31bbb97992b..63d5f9e3328 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.h @@ -28,6 +28,7 @@ namespace __sanitizer { // Don't use directly, use __sanitizer::OpenFile() instead. uptr internal_open(const char *filename, int flags); uptr internal_open(const char *filename, int flags, u32 mode); +uptr internal_close(fd_t fd); // Memory uptr internal_mmap(void *addr, uptr length, int prot, int flags, diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc index 3a129e38221..7f1b9340b79 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc @@ -395,11 +395,11 @@ static __declspec(allocate(".CRT$XID")) int (*__run_atexit)() = RunAtexit; #endif // ------------------ sanitizer_libc.h -uptr internal_close(fd_t fd) { +fd_t OpenFile(const char *filename, FileAccessMode mode, error_t *last_error) { UNIMPLEMENTED(); } -fd_t OpenFile(const char *filename, FileAccessMode mode, error_t *last_error) { +void CloseFile(fd_t fd) { UNIMPLEMENTED(); } diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc index bf3a93e20f9..14b63fc6c30 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_libc_test.cc @@ -82,7 +82,7 @@ TEST(SanitizerCommon, FileOps) { ASSERT_NE(fd, kInvalidFd); EXPECT_EQ(len1, internal_write(fd, str1, len1)); EXPECT_EQ(len2, internal_write(fd, str2, len2)); - internal_close(fd); + CloseFile(fd); fd = OpenFile(tmpfile, RdOnly); ASSERT_NE(fd, kInvalidFd); @@ -113,7 +113,7 @@ TEST(SanitizerCommon, FileOps) { internal_memset(buf, 0, len1); EXPECT_EQ(len2, internal_read(fd, buf, len2)); EXPECT_EQ(0, internal_memcmp(buf, str2, len2)); - internal_close(fd); + CloseFile(fd); internal_unlink(tmpfile); } #endif @@ -151,7 +151,7 @@ TEST(SanitizerCommon, InternalMmapWithOffset) { ASSERT_EQ('A', p[0]); ASSERT_EQ('B', p[1]); - internal_close(fd); + CloseFile(fd); UnmapOrDie(p, page_size); internal_unlink(tmpfile); } |

