forked from OSchip/llvm-project
[ASan] use internal_{close,read,write} in ASan runtime.
llvm-svn: 157991
This commit is contained in:
parent
03c8b846c4
commit
1b12eda7ec
|
@ -169,10 +169,6 @@ void AsanUnmapOrDie(void *ptr, uptr size);
|
|||
void AsanDisableCoreDumper();
|
||||
void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp);
|
||||
|
||||
uptr AsanRead(int fd, void *buf, uptr count);
|
||||
uptr AsanWrite(int fd, const void *buf, uptr count);
|
||||
int AsanClose(int fd);
|
||||
|
||||
bool AsanInterceptsSignal(int signum);
|
||||
void SetAlternateSignalStack();
|
||||
void UnsetAlternateSignalStack();
|
||||
|
|
|
@ -110,10 +110,6 @@ void AsanUnmapOrDie(void *addr, uptr size) {
|
|||
}
|
||||
}
|
||||
|
||||
uptr AsanWrite(int fd, const void *buf, uptr count) {
|
||||
return (uptr)syscall(__NR_write, fd, buf, count);
|
||||
}
|
||||
|
||||
// Like getenv, but reads env directly from /proc and does not use libc.
|
||||
// This function should be called first inside __asan_init.
|
||||
const char* AsanGetEnv(const char* name) {
|
||||
|
@ -142,20 +138,12 @@ const char* AsanGetEnv(const char* name) {
|
|||
return 0; // Not found.
|
||||
}
|
||||
|
||||
uptr AsanRead(int fd, void *buf, uptr count) {
|
||||
return (uptr)syscall(__NR_read, fd, buf, count);
|
||||
}
|
||||
|
||||
int AsanClose(int fd) {
|
||||
return syscall(__NR_close, fd);
|
||||
}
|
||||
|
||||
AsanProcMaps::AsanProcMaps() {
|
||||
proc_self_maps_buff_len_ =
|
||||
ReadFileToBuffer("/proc/self/maps", &proc_self_maps_buff_,
|
||||
&proc_self_maps_buff_mmaped_size_, 1 << 26);
|
||||
CHECK(proc_self_maps_buff_len_ > 0);
|
||||
// AsanWrite(2, proc_self_maps_buff_, proc_self_maps_buff_len_);
|
||||
// internal_write(2, proc_self_maps_buff_, proc_self_maps_buff_len_);
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
|
|
@ -100,10 +100,6 @@ bool AsanInterceptsSignal(int signum) {
|
|||
return (signum == SIGSEGV || signum == SIGBUS) && FLAG_handle_segv;
|
||||
}
|
||||
|
||||
size_t AsanWrite(int fd, const void *buf, size_t count) {
|
||||
return write(fd, buf, count);
|
||||
}
|
||||
|
||||
void *AsanMmapSomewhereOrDie(size_t size, const char *mem_type) {
|
||||
size = RoundUpTo(size, kPageSize);
|
||||
void *res = internal_mmap(0, size,
|
||||
|
@ -158,14 +154,6 @@ const char *AsanGetEnv(const char *name) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
size_t AsanRead(int fd, void *buf, size_t count) {
|
||||
return read(fd, buf, count);
|
||||
}
|
||||
|
||||
int AsanClose(int fd) {
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
AsanProcMaps::AsanProcMaps() {
|
||||
Reset();
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "asan_procmaps.h"
|
||||
#include "asan_stack.h"
|
||||
#include "asan_thread_registry.h"
|
||||
#include "sanitizer_common/sanitizer_libc.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
|
@ -35,6 +36,8 @@
|
|||
// since most of the stuff here is inlinable.
|
||||
#include <algorithm>
|
||||
|
||||
using namespace __sanitizer;
|
||||
|
||||
static const uptr kAltStackSize = SIGSTKSZ * 4; // SIGSTKSZ is not enough.
|
||||
|
||||
namespace __asan {
|
||||
|
@ -82,7 +85,7 @@ static void MaybeInstallSigaction(int signum,
|
|||
static void ASAN_OnSIGSEGV(int, siginfo_t *siginfo, void *context) {
|
||||
uptr addr = (uptr)siginfo->si_addr;
|
||||
// Write the first message using the bullet-proof write.
|
||||
if (13 != AsanWrite(2, "ASAN:SIGSEGV\n", 13)) AsanDie();
|
||||
if (13 != internal_write(2, "ASAN:SIGSEGV\n", 13)) AsanDie();
|
||||
uptr pc, sp, bp;
|
||||
GetPcSpBp(context, &pc, &sp, &bp);
|
||||
Report("ERROR: AddressSanitizer crashed on unknown address %p"
|
||||
|
|
|
@ -31,8 +31,8 @@ extern uptr error_message_buffer_pos, error_message_buffer_size;
|
|||
void RawWrite(const char *buffer) {
|
||||
static const char *kRawWriteError = "RawWrite can't output requested buffer!";
|
||||
uptr length = (uptr)internal_strlen(buffer);
|
||||
if (length != AsanWrite(2, buffer, length)) {
|
||||
AsanWrite(2, kRawWriteError, internal_strlen(kRawWriteError));
|
||||
if (length != internal_write(2, buffer, length)) {
|
||||
internal_write(2, kRawWriteError, internal_strlen(kRawWriteError));
|
||||
AsanDie();
|
||||
}
|
||||
if (error_message_buffer) {
|
||||
|
|
|
@ -96,14 +96,14 @@ uptr ReadFileToBuffer(const char *file_name, char **buff,
|
|||
read_len = 0;
|
||||
bool reached_eof = false;
|
||||
while (read_len + kPageSize <= size) {
|
||||
uptr just_read = AsanRead(fd, *buff + read_len, kPageSize);
|
||||
uptr just_read = internal_read(fd, *buff + read_len, kPageSize);
|
||||
if (just_read == 0) {
|
||||
reached_eof = true;
|
||||
break;
|
||||
}
|
||||
read_len += just_read;
|
||||
}
|
||||
AsanClose(fd);
|
||||
internal_close(fd);
|
||||
if (reached_eof) // We've read the whole file.
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -53,30 +53,6 @@ void AsanUnmapOrDie(void *addr, uptr size) {
|
|||
CHECK(VirtualFree(addr, size, MEM_DECOMMIT));
|
||||
}
|
||||
|
||||
// ---------------------- IO ---------------- {{{1
|
||||
uptr AsanWrite(int fd, const void *buf, uptr count) {
|
||||
if (fd != 2)
|
||||
UNIMPLEMENTED();
|
||||
|
||||
HANDLE err = GetStdHandle(STD_ERROR_HANDLE);
|
||||
if (err == 0)
|
||||
return 0; // FIXME: this might not work on some apps.
|
||||
DWORD ret;
|
||||
if (!WriteFile(err, buf, count, &ret, 0))
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
// FIXME: Looks like these functions are not needed and are linked in by the
|
||||
// code unreachable on Windows. We should clean this up.
|
||||
uptr AsanRead(int fd, void *buf, uptr count) {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
int AsanClose(int fd) {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
// ---------------------- Stacktraces, symbols, etc. ---------------- {{{1
|
||||
static AsanLock dbghelp_lock(LINKER_INITIALIZED);
|
||||
static bool dbghelp_initialized = false;
|
||||
|
|
Loading…
Reference in New Issue