[compiler-rt] r234481 - Introduce CloseFile to be used instead of internal_close on non-POSIX
Timur Iskhodzhanov
timurrrr at google.com
Thu Apr 9 05:37:05 PDT 2015
Author: timurrrr
Date: Thu Apr 9 07:37:05 2015
New Revision: 234481
URL: http://llvm.org/viewvc/llvm-project?rev=234481&view=rev
Log:
Introduce CloseFile to be used instead of internal_close on non-POSIX
Modified:
compiler-rt/trunk/lib/dfsan/dfsan.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
Modified: compiler-rt/trunk/lib/dfsan/dfsan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan.cc?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan.cc Thu Apr 9 07:37:05 2015
@@ -350,7 +350,7 @@ static void dfsan_fini() {
Report("INFO: DataFlowSanitizer: dumping labels to %s\n",
flags().dump_labels_at_exit);
dfsan_dump_labels(fd);
- internal_close(fd);
+ CloseFile(fd);
}
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Thu Apr 9 07:37:05 2015
@@ -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 cha
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_n
}
read_len += just_read;
}
- internal_close(fd);
+ CloseFile(fd);
if (reached_eof) // We've read the whole file.
break;
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Thu Apr 9 07:37:05 2015
@@ -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.
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep.cc Thu Apr 9 07:37:05 2015
@@ -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() {
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_mapping_libcdep.cc Thu Apr 9 07:37:05 2015
@@ -113,7 +113,7 @@ void CovUpdateMapping(const char *covera
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",
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_libc.h Thu Apr 9 07:37:05 2015
@@ -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);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.cc Thu Apr 9 07:37:05 2015
@@ -219,6 +219,10 @@ fd_t OpenFile(const char *filename, File
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);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix.h Thu Apr 9 07:37:05 2015
@@ -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,
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cc Thu Apr 9 07:37:05 2015
@@ -395,11 +395,11 @@ static __declspec(allocate(".CRT$XID"))
#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();
}
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc?rev=234481&r1=234480&r2=234481&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_libc_test.cc Thu Apr 9 07:37:05 2015
@@ -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, InternalMmapWithOf
ASSERT_EQ('A', p[0]);
ASSERT_EQ('B', p[1]);
- internal_close(fd);
+ CloseFile(fd);
UnmapOrDie(p, page_size);
internal_unlink(tmpfile);
}
More information about the llvm-commits
mailing list