forked from OSchip/llvm-project
[Sanitizer] add sanity checks for communication with external symbolizer
llvm-svn: 167617
This commit is contained in:
parent
0044e386e9
commit
ae9b18b607
|
@ -117,6 +117,7 @@ void *MapFileToMemory(const char *file_name, uptr *buff_size);
|
|||
// OS
|
||||
void DisableCoreDumper();
|
||||
void DumpProcessMap();
|
||||
bool FileExists(const char *filename);
|
||||
const char *GetEnv(const char *name);
|
||||
const char *GetPwd();
|
||||
void ReExec();
|
||||
|
|
|
@ -94,6 +94,20 @@ int internal_sched_yield() {
|
|||
}
|
||||
|
||||
// ----------------- sanitizer_common.h
|
||||
bool FileExists(const char *filename) {
|
||||
#if __WORDSIZE == 64
|
||||
struct stat st;
|
||||
if (syscall(__NR_stat, filename, &st))
|
||||
return false;
|
||||
#else
|
||||
struct stat64 st;
|
||||
if (syscall(__NR_stat64, filename, &st))
|
||||
return false;
|
||||
#endif
|
||||
// Sanity check: filename is a regular file.
|
||||
return S_ISREG(st.st_mode);
|
||||
}
|
||||
|
||||
uptr GetTid() {
|
||||
return syscall(__NR_gettid);
|
||||
}
|
||||
|
|
|
@ -80,6 +80,14 @@ int internal_sched_yield() {
|
|||
}
|
||||
|
||||
// ----------------- sanitizer_common.h
|
||||
bool FileExists(const char *filename) {
|
||||
struct stat st;
|
||||
if (stat(filename, &st))
|
||||
return false;
|
||||
// Sanity check: filename is a regular file.
|
||||
return S_ISREG(st.st_mode);
|
||||
}
|
||||
|
||||
uptr GetTid() {
|
||||
return reinterpret_cast<uptr>(pthread_self());
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if !defined(__ANDROID__) && !defined(ANDROID)
|
||||
|
@ -31,8 +32,15 @@
|
|||
|
||||
namespace __sanitizer {
|
||||
|
||||
static const int kSymbolizerStartupTimeMillis = 10;
|
||||
|
||||
bool StartSymbolizerSubprocess(const char *path_to_symbolizer,
|
||||
int *input_fd, int *output_fd) {
|
||||
if (!FileExists(path_to_symbolizer)) {
|
||||
Report("WARNING: invalid path to external symbolizer!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
int *infd = NULL;
|
||||
int *outfd = NULL;
|
||||
// The client program may close its stdin and/or stdout and/or stderr
|
||||
|
@ -99,6 +107,17 @@ bool StartSymbolizerSubprocess(const char *path_to_symbolizer,
|
|||
internal_close(infd[1]);
|
||||
*input_fd = infd[0];
|
||||
*output_fd = outfd[1];
|
||||
|
||||
// Check that symbolizer subprocess started successfully.
|
||||
int pid_status;
|
||||
SleepForMillis(kSymbolizerStartupTimeMillis);
|
||||
int exited_pid = waitpid(pid, &pid_status, WNOHANG);
|
||||
if (exited_pid != 0) {
|
||||
// Either waitpid failed, or child has already exited.
|
||||
Report("WARNING: external symbolizer didn't start up correctly!\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@
|
|||
namespace __sanitizer {
|
||||
|
||||
// --------------------- sanitizer_common.h
|
||||
bool FileExists(const char *filename) {
|
||||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
int GetPid() {
|
||||
return GetProcessId(GetCurrentProcess());
|
||||
}
|
||||
|
|
|
@ -197,7 +197,11 @@ void Initialize(ThreadState *thr) {
|
|||
// Initialize external symbolizer before internal threads are started.
|
||||
const char *external_symbolizer = flags()->external_symbolizer_path;
|
||||
if (external_symbolizer != 0 && external_symbolizer[0] != '\0') {
|
||||
InitializeExternalSymbolizer(external_symbolizer);
|
||||
if (!InitializeExternalSymbolizer(external_symbolizer)) {
|
||||
Printf("Failed to start external symbolizer: '%s'\n",
|
||||
external_symbolizer);
|
||||
Die();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
InitializeMemoryProfile();
|
||||
|
|
Loading…
Reference in New Issue