[llvm-commits] [compiler-rt] r158138 - in /compiler-rt/trunk/lib: asan/asan_internal.h asan/asan_rtl.cc sanitizer_common/sanitizer_common.cc sanitizer_common/sanitizer_common.h
Alexey Samsonov
samsonov at google.com
Wed Jun 6 22:38:26 PDT 2012
Author: samsonov
Date: Thu Jun 7 00:38:26 2012
New Revision: 158138
URL: http://llvm.org/viewvc/llvm-project?rev=158138&view=rev
Log:
[Sanitizer] Move ReadFileToBuffer to sanitizer_common.
Modified:
compiler-rt/trunk/lib/asan/asan_internal.h
compiler-rt/trunk/lib/asan/asan_rtl.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=158138&r1=158137&r2=158138&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Thu Jun 7 00:38:26 2012
@@ -146,13 +146,6 @@
void *AsanTSDGet();
void AsanTSDSet(void *tsd);
-// 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',
-// Returns the number of read bytes or 0 if file can not be opened.
-uptr ReadFileToBuffer(const char *file_name, char **buff,
- uptr *buff_size, uptr max_len);
-
void AppendToErrorMessageBuffer(const char *buffer);
// asan_printf.cc
void AsanPrintf(const char *format, ...);
Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=158138&r1=158137&r2=158138&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Thu Jun 7 00:38:26 2012
@@ -109,37 +109,6 @@
AsanPrintf("\n");
}
-uptr ReadFileToBuffer(const char *file_name, char **buff,
- uptr *buff_size, uptr max_len) {
- const uptr kMinFileLen = kPageSize;
- uptr read_len = 0;
- *buff = 0;
- *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);
- if (fd < 0) return 0;
- UnmapOrDie(*buff, *buff_size);
- *buff = (char*)MmapOrDie(size, __FUNCTION__);
- *buff_size = size;
- // Read up to one page at a time.
- read_len = 0;
- bool reached_eof = false;
- while (read_len + kPageSize <= size) {
- uptr just_read = internal_read(fd, *buff + read_len, kPageSize);
- if (just_read == 0) {
- reached_eof = true;
- break;
- }
- read_len += just_read;
- }
- internal_close(fd);
- if (reached_eof) // We've read the whole file.
- break;
- }
- return read_len;
-}
-
void AppendToErrorMessageBuffer(const char *buffer) {
if (error_message_buffer) {
uptr length = (uptr)internal_strlen(buffer);
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=158138&r1=158137&r2=158138&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.cc Thu Jun 7 00:38:26 2012
@@ -25,4 +25,35 @@
}
}
+uptr ReadFileToBuffer(const char *file_name, char **buff,
+ uptr *buff_size, uptr max_len) {
+ const uptr kMinFileLen = kPageSize;
+ uptr read_len = 0;
+ *buff = 0;
+ *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);
+ if (fd == kInvalidFd) return 0;
+ UnmapOrDie(*buff, *buff_size);
+ *buff = (char*)MmapOrDie(size, __FUNCTION__);
+ *buff_size = size;
+ // Read up to one page at a time.
+ read_len = 0;
+ bool reached_eof = false;
+ while (read_len + kPageSize <= size) {
+ uptr just_read = internal_read(fd, *buff + read_len, kPageSize);
+ if (just_read == 0) {
+ reached_eof = true;
+ break;
+ }
+ read_len += just_read;
+ }
+ internal_close(fd);
+ if (reached_eof) // We've read the whole file.
+ break;
+ }
+ return read_len;
+}
+
} // namespace __sanitizer
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=158138&r1=158137&r2=158138&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Thu Jun 7 00:38:26 2012
@@ -37,6 +37,13 @@
int SNPrintf(char *buffer, uptr length, const char *format, ...);
void Report(const char *format, ...);
+// 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',
+// Returns the number of read bytes or 0 if file can not be opened.
+uptr ReadFileToBuffer(const char *file_name, char **buff,
+ uptr *buff_size, uptr max_len);
+
// Bit twiddling.
inline bool IsPowerOfTwo(uptr x) {
return (x & (x - 1)) == 0;
More information about the llvm-commits
mailing list