mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 22:00:10 +00:00
[Sanitizer] Renaming: SNPrintf -> internal_snprintf (and move it to sanitizer libc)
llvm-svn: 158710
This commit is contained in:
parent
a84e2df4f9
commit
e1cb524226
@ -44,7 +44,7 @@ void AsanPrintf(const char *format, ...) {
|
||||
void AsanReport(const char *format, ...) {
|
||||
const int kLen = 1024 * 4;
|
||||
char buffer[kLen];
|
||||
int needed_length = SNPrintf(buffer, kLen, "==%d== ", GetPid());
|
||||
int needed_length = internal_snprintf(buffer, kLen, "==%d== ", GetPid());
|
||||
RAW_CHECK_MSG(needed_length < kLen, "Buffer in Report is too short!\n");
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "asan_internal.h"
|
||||
#include "asan_lock.h"
|
||||
#include "asan_thread.h"
|
||||
#include "sanitizer_common/sanitizer_libc.h"
|
||||
|
||||
namespace __asan {
|
||||
|
||||
@ -85,11 +86,11 @@ bool __asan_WinSymbolize(const void *addr, char *out_buffer, int buffer_size) {
|
||||
out_buffer[0] = '\0';
|
||||
// FIXME: it might be useful to print out 'obj' or 'obj+offset' info too.
|
||||
if (got_fileline) {
|
||||
written += SNPrintf(out_buffer + written, buffer_size - written,
|
||||
written += internal_snprintf(out_buffer + written, buffer_size - written,
|
||||
" %s %s:%d", symbol->Name,
|
||||
info.FileName, info.LineNumber);
|
||||
} else {
|
||||
written += SNPrintf(out_buffer + written, buffer_size - written,
|
||||
written += internal_snprintf(out_buffer + written, buffer_size - written,
|
||||
" %s+0x%p", symbol->Name, offset);
|
||||
}
|
||||
return true;
|
||||
|
@ -52,7 +52,6 @@ void InternalFree(void *addr);
|
||||
// IO
|
||||
void RawWrite(const char *buffer);
|
||||
void Printf(const char *format, ...);
|
||||
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.
|
||||
|
@ -59,6 +59,7 @@ 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.
|
||||
int internal_dup2(int oldfd, int newfd);
|
||||
int internal_snprintf(char *buffer, uptr length, const char *format, ...);
|
||||
int internal_sscanf(const char *str, const char *format, ...);
|
||||
|
||||
// Threading
|
||||
|
@ -158,7 +158,7 @@ void Printf(const char *format, ...) {
|
||||
// Returns the number of symbols that should have been written to buffer
|
||||
// (not including trailing '\0'). Thus, the string is truncated
|
||||
// iff return value is not less than "length".
|
||||
int SNPrintf(char *buffer, uptr length, const char *format, ...) {
|
||||
int internal_snprintf(char *buffer, uptr length, const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
int needed_length = VSNPrintf(buffer, length, format, args);
|
||||
@ -170,7 +170,7 @@ int SNPrintf(char *buffer, uptr length, const char *format, ...) {
|
||||
void Report(const char *format, ...) {
|
||||
const int kLen = 1024 * 4;
|
||||
char *buffer = (char*)MmapOrDie(kLen, __FUNCTION__);
|
||||
int needed_length = SNPrintf(buffer, kLen, "==%d== ", GetPid());
|
||||
int needed_length = internal_snprintf(buffer, kLen, "==%d== ", GetPid());
|
||||
RAW_CHECK_MSG(needed_length < kLen, "Buffer in Report is too short!\n");
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
@ -105,9 +105,9 @@ static void WriteMemoryProfile(char *buf, uptr buf_size, int num) {
|
||||
uptr nsync = 0;
|
||||
uptr syncmem = CTX()->synctab.GetMemoryConsumption(&nsync);
|
||||
|
||||
SNPrintf(buf, buf_size, "%d: shadow=%zuMB"
|
||||
" thread=%zuMB(total=%d/live=%d)"
|
||||
" sync=%zuMB(cnt=%zu)\n",
|
||||
internal_snprintf(buf, buf_size, "%d: shadow=%zuMB"
|
||||
" thread=%zuMB(total=%d/live=%d)"
|
||||
" sync=%zuMB(cnt=%zu)\n",
|
||||
num,
|
||||
shadow >> 20,
|
||||
threadmem >> 20, nthread, nlivethread,
|
||||
@ -129,7 +129,7 @@ static void InitializeMemoryProfile() {
|
||||
if (flags()->profile_memory == 0 || flags()->profile_memory[0] == 0)
|
||||
return;
|
||||
InternalScopedBuf<char> filename(4096);
|
||||
SNPrintf(filename.Ptr(), filename.Size(), "%s.%d",
|
||||
internal_snprintf(filename.Ptr(), filename.Size(), "%s.%d",
|
||||
flags()->profile_memory, GetPid());
|
||||
fd_t fd = internal_open(filename.Ptr(), true);
|
||||
if (fd == kInvalidFd) {
|
||||
|
@ -28,9 +28,9 @@ static char *ReadFile(const char *filename) {
|
||||
return 0;
|
||||
InternalScopedBuf<char> tmp(4*1024);
|
||||
if (filename[0] == '/')
|
||||
SNPrintf(tmp, tmp.Size(), "%s", filename);
|
||||
internal_snprintf(tmp, tmp.Size(), "%s", filename);
|
||||
else
|
||||
SNPrintf(tmp, tmp.Size(), "%s/%s", GetPwd(), filename);
|
||||
internal_snprintf(tmp, tmp.Size(), "%s/%s", GetPwd(), filename);
|
||||
fd_t fd = internal_open(tmp, false);
|
||||
if (fd == kInvalidFd) {
|
||||
TsanPrintf("ThreadSanitizer: failed to open suppressions file '%s'\n",
|
||||
|
@ -85,7 +85,7 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
|
||||
DlIteratePhdrCtx *ctx = (DlIteratePhdrCtx*)arg;
|
||||
InternalScopedBuf<char> tmp(128);
|
||||
if (ctx->is_first) {
|
||||
SNPrintf(tmp.Ptr(), tmp.Size(), "/proc/%d/exe", GetPid());
|
||||
internal_snprintf(tmp.Ptr(), tmp.Size(), "/proc/%d/exe", GetPid());
|
||||
info->dlpi_name = tmp.Ptr();
|
||||
}
|
||||
ctx->is_first = false;
|
||||
@ -159,7 +159,7 @@ ReportStack *SymbolizeCode(uptr addr) {
|
||||
ModuleDesc *m = s->module;
|
||||
uptr offset = addr - m->base;
|
||||
char addrstr[32];
|
||||
SNPrintf(addrstr, sizeof(addrstr), "%p\n", (void*)offset);
|
||||
internal_snprintf(addrstr, sizeof(addrstr), "%p\n", (void*)offset);
|
||||
if (0 >= internal_write(m->out_fd, addrstr, internal_strlen(addrstr))) {
|
||||
TsanPrintf("ThreadSanitizer: can't write from symbolizer (%d, %d)\n",
|
||||
m->out_fd, errno);
|
||||
@ -199,7 +199,7 @@ ReportStack *SymbolizeData(uptr addr) {
|
||||
base = GetImageBase();
|
||||
int res = 0;
|
||||
InternalScopedBuf<char> cmd(1024);
|
||||
SNPrintf(cmd, cmd.Size(),
|
||||
internal_snprintf(cmd, cmd.Size(),
|
||||
"nm -alC %s|grep \"%zx\"|awk '{printf(\"%%s\\n%%s\", $3, $4)}' > tsan.tmp2",
|
||||
exe, (addr - base));
|
||||
if (system(cmd))
|
||||
|
@ -20,7 +20,7 @@ namespace __tsan {
|
||||
|
||||
TEST(Printf, Basic) {
|
||||
char buf[1024];
|
||||
uptr len = SNPrintf(buf, sizeof(buf),
|
||||
uptr len = internal_snprintf(buf, sizeof(buf),
|
||||
"a%db%zdc%ue%zuf%xh%zxq%pe%sr",
|
||||
(int)-1, (long)-2, // NOLINT
|
||||
(unsigned)-4, (unsigned long)5, // NOLINT
|
||||
@ -33,7 +33,7 @@ TEST(Printf, Basic) {
|
||||
|
||||
TEST(Printf, OverflowStr) {
|
||||
char buf[] = "123456789";
|
||||
uptr len = SNPrintf(buf, 4, "%s", "abcdef");
|
||||
uptr len = internal_snprintf(buf, 4, "%s", "abcdef"); // NOLINT
|
||||
EXPECT_EQ(len, (uptr)6);
|
||||
EXPECT_EQ(0, strcmp(buf, "abc"));
|
||||
EXPECT_EQ(buf[3], 0);
|
||||
@ -47,7 +47,7 @@ TEST(Printf, OverflowStr) {
|
||||
|
||||
TEST(Printf, OverflowInt) {
|
||||
char buf[] = "123456789";
|
||||
SNPrintf(buf, 4, "%d", -123456789);
|
||||
internal_snprintf(buf, 4, "%d", -123456789); // NOLINT
|
||||
EXPECT_EQ(0, strcmp(buf, "-12"));
|
||||
EXPECT_EQ(buf[3], 0);
|
||||
EXPECT_EQ(buf[4], '5');
|
||||
@ -60,7 +60,7 @@ TEST(Printf, OverflowInt) {
|
||||
|
||||
TEST(Printf, OverflowUint) {
|
||||
char buf[] = "123456789";
|
||||
SNPrintf(buf, 4, "a%zx", (unsigned long)0x123456789); // NOLINT
|
||||
internal_snprintf(buf, 4, "a%zx", (unsigned long)0x123456789); // NOLINT
|
||||
EXPECT_EQ(0, strcmp(buf, "a12"));
|
||||
EXPECT_EQ(buf[3], 0);
|
||||
EXPECT_EQ(buf[4], '5');
|
||||
@ -73,7 +73,7 @@ TEST(Printf, OverflowUint) {
|
||||
|
||||
TEST(Printf, OverflowPtr) {
|
||||
char buf[] = "123456789";
|
||||
SNPrintf(buf, 4, "%p", (void*)0x123456789);
|
||||
internal_snprintf(buf, 4, "%p", (void*)0x123456789); // NOLINT
|
||||
EXPECT_EQ(0, strcmp(buf, "0x0"));
|
||||
EXPECT_EQ(buf[3], 0);
|
||||
EXPECT_EQ(buf[4], '5');
|
||||
@ -87,7 +87,7 @@ TEST(Printf, OverflowPtr) {
|
||||
template<typename T>
|
||||
static void TestMinMax(const char *fmt, T min, T max) {
|
||||
char buf[1024];
|
||||
uptr len = SNPrintf(buf, sizeof(buf), fmt, min, max);
|
||||
uptr len = internal_snprintf(buf, sizeof(buf), fmt, min, max);
|
||||
char buf2[1024];
|
||||
snprintf(buf2, sizeof(buf2), fmt, min, max);
|
||||
EXPECT_EQ(len, strlen(buf));
|
||||
|
Loading…
Reference in New Issue
Block a user