mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-18 19:16:43 +00:00
[Sanitizer] make internal_open have the same interface as libc version
llvm-svn: 174187
This commit is contained in:
parent
d6eda1c227
commit
39313b780d
@ -68,7 +68,7 @@ static void MaybeOpenReportFile() {
|
||||
InternalScopedBuffer<char> report_path_full(4096);
|
||||
internal_snprintf(report_path_full.data(), report_path_full.size(),
|
||||
"%s.%d", report_path_prefix, GetPid());
|
||||
fd_t fd = internal_open(report_path_full.data(), true);
|
||||
fd_t fd = OpenFile(report_path_full.data(), true);
|
||||
if (fd == kInvalidFd) {
|
||||
report_fd = kStderrFd;
|
||||
log_to_file = false;
|
||||
@ -107,7 +107,7 @@ uptr ReadFileToBuffer(const char *file_name, char **buff,
|
||||
*buff_size = 0;
|
||||
// The files we usually open are not seekable, so try different buffer sizes.
|
||||
for (uptr size = kMinFileLen; size <= max_len; size *= 2) {
|
||||
fd_t fd = internal_open(file_name, /*write*/ false);
|
||||
fd_t fd = OpenFile(file_name, /*write*/ false);
|
||||
if (fd == kInvalidFd) return 0;
|
||||
UnmapOrDie(*buff, *buff_size);
|
||||
*buff = (char*)MmapOrDie(size, __FUNCTION__);
|
||||
|
@ -107,6 +107,7 @@ void Printf(const char *format, ...);
|
||||
void Report(const char *format, ...);
|
||||
void SetPrintfAndReportCallback(void (*callback)(const char *));
|
||||
|
||||
fd_t OpenFile(const char *filename, bool write);
|
||||
// Opens the file 'file_name" and reads up to 'max_len' bytes.
|
||||
// The resulting buffer is mmaped and stored in '*buff'.
|
||||
// The size of the mmaped region is stored in '*buff_size',
|
||||
|
@ -64,6 +64,8 @@ typedef signed char s8;
|
||||
typedef signed short s16; // NOLINT
|
||||
typedef signed int s32;
|
||||
typedef signed long long s64; // NOLINT
|
||||
typedef int fd_t;
|
||||
typedef u32 mode_t;
|
||||
|
||||
} // namespace __sanitizer
|
||||
|
||||
|
@ -57,14 +57,17 @@ void *internal_mmap(void *addr, uptr length, int prot, int flags,
|
||||
int internal_munmap(void *addr, uptr length);
|
||||
|
||||
// I/O
|
||||
typedef int fd_t;
|
||||
const fd_t kInvalidFd = -1;
|
||||
const fd_t kStdinFd = 0;
|
||||
const fd_t kStdoutFd = 1;
|
||||
const fd_t kStderrFd = 2;
|
||||
int internal_close(fd_t fd);
|
||||
int internal_isatty(fd_t fd);
|
||||
fd_t internal_open(const char *filename, bool write);
|
||||
|
||||
// Use __sanitizer::OpenFile() instead.
|
||||
fd_t internal_open(const char *filename, int flags);
|
||||
fd_t internal_open(const char *filename, int flags, mode_t mode);
|
||||
|
||||
uptr internal_read(fd_t fd, void *buf, uptr count);
|
||||
uptr internal_write(fd_t fd, const void *buf, uptr count);
|
||||
uptr internal_filesize(fd_t fd); // -1 on error.
|
||||
|
@ -68,8 +68,16 @@ int internal_close(fd_t fd) {
|
||||
return syscall(__NR_close, fd);
|
||||
}
|
||||
|
||||
fd_t internal_open(const char *filename, bool write) {
|
||||
return syscall(__NR_open, filename,
|
||||
fd_t internal_open(const char *filename, int flags) {
|
||||
return syscall(__NR_open, filename, flags);
|
||||
}
|
||||
|
||||
fd_t internal_open(const char *filename, int flags, mode_t mode) {
|
||||
return syscall(__NR_open, filename, flags, mode);
|
||||
}
|
||||
|
||||
fd_t OpenFile(const char *filename, bool write) {
|
||||
return internal_open(filename,
|
||||
write ? O_WRONLY | O_CREAT /*| O_CLOEXEC*/ : O_RDONLY, 0660);
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,17 @@ int internal_close(fd_t fd) {
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
fd_t internal_open(const char *filename, bool write) {
|
||||
return open(filename,
|
||||
write ? O_WRONLY | O_CREAT : O_RDONLY, 0660);
|
||||
fd_t internal_open(const char *filename, int flags) {
|
||||
return open(filename, flags);
|
||||
}
|
||||
|
||||
fd_t internal_open(const char *filename, int flags, mode_t mode) {
|
||||
return open(filename, flags, mode);
|
||||
}
|
||||
|
||||
fd_t OpenFile(const char *filename, bool write) {
|
||||
return internal_open(filename,
|
||||
write ? O_WRONLY | O_CREAT : O_RDONLY, 0660);
|
||||
}
|
||||
|
||||
uptr internal_read(fd_t fd, void *buf, uptr count) {
|
||||
|
@ -122,7 +122,7 @@ void FlushUnneededShadowMemory(uptr addr, uptr size) {
|
||||
}
|
||||
|
||||
void *MapFileToMemory(const char *file_name, uptr *buff_size) {
|
||||
fd_t fd = internal_open(file_name, false);
|
||||
fd_t fd = OpenFile(file_name, false);
|
||||
CHECK_NE(fd, kInvalidFd);
|
||||
uptr fsize = internal_filesize(fd);
|
||||
CHECK_NE(fsize, (uptr)-1);
|
||||
|
@ -191,7 +191,15 @@ int internal_isatty(fd_t fd) {
|
||||
return _isatty(fd);
|
||||
}
|
||||
|
||||
fd_t internal_open(const char *filename, bool write) {
|
||||
fd_t internal_open(const char *filename, int flags) {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
fd_t internal_open(const char *filename, int flags, mode_t mode) {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
fd_t OpenFile(const char *filename, bool write) {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ static void InitializeMemoryProfile() {
|
||||
InternalScopedBuffer<char> filename(4096);
|
||||
internal_snprintf(filename.data(), filename.size(), "%s.%d",
|
||||
flags()->profile_memory, GetPid());
|
||||
fd_t fd = internal_open(filename.data(), true);
|
||||
fd_t fd = OpenFile(filename.data(), true);
|
||||
if (fd == kInvalidFd) {
|
||||
Printf("Failed to open memory profile file '%s'\n", &filename[0]);
|
||||
Die();
|
||||
|
@ -38,7 +38,7 @@ static char *ReadFile(const char *filename) {
|
||||
internal_snprintf(tmp.data(), tmp.size(), "%s", filename);
|
||||
else
|
||||
internal_snprintf(tmp.data(), tmp.size(), "%s/%s", GetPwd(), filename);
|
||||
fd_t fd = internal_open(tmp.data(), false);
|
||||
fd_t fd = OpenFile(tmp.data(), false);
|
||||
if (fd == kInvalidFd) {
|
||||
Printf("ThreadSanitizer: failed to open suppressions file '%s'\n",
|
||||
tmp.data());
|
||||
|
@ -67,13 +67,13 @@ TEST(Platform, FileOps) {
|
||||
const char *str2 = "zxcv";
|
||||
uptr len2 = internal_strlen(str2);
|
||||
|
||||
fd_t fd = internal_open("./tsan_test.tmp", true);
|
||||
fd_t fd = OpenFile("./tsan_test.tmp", true);
|
||||
EXPECT_NE(fd, kInvalidFd);
|
||||
EXPECT_EQ(len1, internal_write(fd, str1, len1));
|
||||
EXPECT_EQ(len2, internal_write(fd, str2, len2));
|
||||
internal_close(fd);
|
||||
|
||||
fd = internal_open("./tsan_test.tmp", false);
|
||||
fd = OpenFile("./tsan_test.tmp", false);
|
||||
EXPECT_NE(fd, kInvalidFd);
|
||||
EXPECT_EQ(len1 + len2, internal_filesize(fd));
|
||||
char buf[64] = {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user