forked from OSchip/llvm-project
[nolibc] Move all platforms to internal_getpid.
Before, we had an unused internal_getpid function for Linux, and a platform-independent GetPid function. To make the naming conventions consistent for syscall-like functions, the GetPid syscall wrapper in sanitizer_posix.cc is moved to sanitizer_mac.cc, and GetPid is renamed to internal_getpid, bringing the Linux variant into use. llvm-svn: 182132
This commit is contained in:
parent
1ac08bbc7e
commit
ffaf2eac4d
|
@ -524,7 +524,7 @@ void __asan_init() {
|
|||
0, true, 0, &create_main_args);
|
||||
CHECK_EQ(0, main_tid);
|
||||
SetCurrentThread(main_thread);
|
||||
main_thread->ThreadStart(GetPid());
|
||||
main_thread->ThreadStart(internal_getpid());
|
||||
force_interface_symbols(); // no-op.
|
||||
|
||||
InitializeAllocator();
|
||||
|
|
|
@ -35,7 +35,7 @@ fd_t report_fd = kStderrFd;
|
|||
static char report_path_prefix[4096]; // Set via __sanitizer_set_report_path.
|
||||
// PID of process that opened |report_fd|. If a fork() occurs, the PID of the
|
||||
// child thread will be different from |report_fd_pid|.
|
||||
static int report_fd_pid = 0;
|
||||
static uptr report_fd_pid = 0;
|
||||
|
||||
static void (*DieCallback)(void);
|
||||
void SetDieCallback(void (*callback)(void)) {
|
||||
|
@ -65,10 +65,10 @@ void NORETURN CheckFailed(const char *file, int line, const char *cond,
|
|||
}
|
||||
|
||||
void MaybeOpenReportFile() {
|
||||
if (!log_to_file || (report_fd_pid == GetPid())) return;
|
||||
if (!log_to_file || (report_fd_pid == internal_getpid())) return;
|
||||
InternalScopedBuffer<char> report_path_full(4096);
|
||||
internal_snprintf(report_path_full.data(), report_path_full.size(),
|
||||
"%s.%d", report_path_prefix, GetPid());
|
||||
"%s.%d", report_path_prefix, internal_getpid());
|
||||
uptr openrv = OpenFile(report_path_full.data(), true);
|
||||
if (internal_iserror(openrv)) {
|
||||
report_fd = kStderrFd;
|
||||
|
@ -81,7 +81,7 @@ void MaybeOpenReportFile() {
|
|||
internal_close(report_fd);
|
||||
}
|
||||
report_fd = openrv;
|
||||
report_fd_pid = GetPid();
|
||||
report_fd_pid = internal_getpid();
|
||||
}
|
||||
|
||||
void RawWrite(const char *buffer) {
|
||||
|
|
|
@ -40,7 +40,6 @@ uptr GetPageSize();
|
|||
uptr GetPageSizeCached();
|
||||
uptr GetMmapGranularity();
|
||||
// Threads
|
||||
int GetPid();
|
||||
uptr GetTid();
|
||||
uptr GetThreadSelf();
|
||||
void GetThreadStackTopAndBottom(bool at_initialization, uptr *stack_top,
|
||||
|
|
|
@ -85,6 +85,7 @@ uptr internal_lseek(fd_t fd, OFF_T offset, int whence);
|
|||
|
||||
uptr internal_ptrace(int request, int pid, void *addr, void *data);
|
||||
uptr internal_waitpid(int pid, int *status, int options);
|
||||
uptr internal_getpid();
|
||||
uptr internal_getppid();
|
||||
|
||||
// Threading
|
||||
|
|
|
@ -115,6 +115,10 @@ void internal__exit(int exitcode) {
|
|||
_exit(exitcode);
|
||||
}
|
||||
|
||||
uptr internal_getpid() {
|
||||
return getpid();
|
||||
}
|
||||
|
||||
// ----------------- sanitizer_common.h
|
||||
bool FileExists(const char *filename) {
|
||||
struct stat st;
|
||||
|
|
|
@ -43,10 +43,6 @@ uptr GetMmapGranularity() {
|
|||
return GetPageSize();
|
||||
}
|
||||
|
||||
int GetPid() {
|
||||
return getpid();
|
||||
}
|
||||
|
||||
u32 GetUid() {
|
||||
return getuid();
|
||||
}
|
||||
|
|
|
@ -218,7 +218,7 @@ static void SharedPrintfCode(bool append_pid, const char *format,
|
|||
}
|
||||
needed_length = 0;
|
||||
if (append_pid) {
|
||||
int pid = GetPid();
|
||||
int pid = internal_getpid();
|
||||
needed_length += internal_snprintf(buffer, buffer_size, "==%d==", pid);
|
||||
if (needed_length >= buffer_size) {
|
||||
// The pid doesn't fit into the current buffer.
|
||||
|
|
|
@ -44,7 +44,7 @@ bool FileExists(const char *filename) {
|
|||
UNIMPLEMENTED();
|
||||
}
|
||||
|
||||
int GetPid() {
|
||||
uptr internal_getpid() {
|
||||
return GetProcessId(GetCurrentProcess());
|
||||
}
|
||||
|
||||
|
|
|
@ -1754,11 +1754,11 @@ TSAN_INTERCEPTOR(int, kill, int pid, int sig) {
|
|||
SignalContext *sctx = SigCtx(thr);
|
||||
CHECK_NE(sctx, 0);
|
||||
int prev = sctx->int_signal_send;
|
||||
if (pid == GetPid()) {
|
||||
if (pid == (int)internal_getpid()) {
|
||||
sctx->int_signal_send = sig;
|
||||
}
|
||||
int res = REAL(kill)(pid, sig);
|
||||
if (pid == GetPid()) {
|
||||
if (pid == (int)internal_getpid()) {
|
||||
CHECK_EQ(sctx->int_signal_send, sig);
|
||||
sctx->int_signal_send = prev;
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@ void PrintMatchedBenignRaces() {
|
|||
&ExpectRace::addcount);
|
||||
if (hit_matched.Size()) {
|
||||
Printf("ThreadSanitizer: Matched %d \"benign\" races (pid=%d):\n",
|
||||
hit_count, GetPid());
|
||||
hit_count, (int)internal_getpid());
|
||||
for (uptr i = 0; i < hit_matched.Size(); i++) {
|
||||
Printf("%d %s:%d %s\n",
|
||||
hit_matched[i].hitcount, hit_matched[i].file,
|
||||
|
@ -206,7 +206,7 @@ void PrintMatchedBenignRaces() {
|
|||
if (hit_matched.Size()) {
|
||||
Printf("ThreadSanitizer: Annotated %d \"benign\" races, %d unique"
|
||||
" (pid=%d):\n",
|
||||
add_count, unique_count, GetPid());
|
||||
add_count, unique_count, (int)internal_getpid());
|
||||
for (uptr i = 0; i < add_matched.Size(); i++) {
|
||||
Printf("%d %s:%d %s\n",
|
||||
add_matched[i].addcount, add_matched[i].file,
|
||||
|
|
|
@ -176,8 +176,8 @@ static void MapRodata() {
|
|||
if (tmpdir == 0)
|
||||
return;
|
||||
char filename[256];
|
||||
internal_snprintf(filename, sizeof(filename), "%s/tsan.rodata.%u",
|
||||
tmpdir, GetPid());
|
||||
internal_snprintf(filename, sizeof(filename), "%s/tsan.rodata.%d",
|
||||
tmpdir, (int)internal_getpid());
|
||||
uptr openrv = internal_open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
|
||||
if (internal_iserror(openrv))
|
||||
return;
|
||||
|
|
|
@ -179,7 +179,8 @@ ReportStack *SkipTsanInternalFrames(ReportStack *ent) {
|
|||
void PrintReport(const ReportDesc *rep) {
|
||||
Printf("==================\n");
|
||||
const char *rep_typ_str = ReportTypeString(rep->typ);
|
||||
Printf("WARNING: ThreadSanitizer: %s (pid=%d)\n", rep_typ_str, GetPid());
|
||||
Printf("WARNING: ThreadSanitizer: %s (pid=%d)\n", rep_typ_str,
|
||||
(int)internal_getpid());
|
||||
|
||||
for (uptr i = 0; i < rep->stacks.Size(); i++) {
|
||||
if (i)
|
||||
|
|
|
@ -120,7 +120,7 @@ static void BackgroundThread(void *arg) {
|
|||
if (flags()->profile_memory && flags()->profile_memory[0]) {
|
||||
InternalScopedBuffer<char> filename(4096);
|
||||
internal_snprintf(filename.data(), filename.size(), "%s.%d",
|
||||
flags()->profile_memory, GetPid());
|
||||
flags()->profile_memory, (int)internal_getpid());
|
||||
uptr openrv = OpenFile(filename.data(), true);
|
||||
if (internal_iserror(openrv)) {
|
||||
Printf("ThreadSanitizer: failed to open memory profile file '%s'\n",
|
||||
|
@ -229,19 +229,19 @@ void Initialize(ThreadState *thr) {
|
|||
|
||||
if (ctx->flags.verbosity)
|
||||
Printf("***** Running under ThreadSanitizer v2 (pid %d) *****\n",
|
||||
GetPid());
|
||||
(int)internal_getpid());
|
||||
|
||||
// Initialize thread 0.
|
||||
int tid = ThreadCreate(thr, 0, 0, true);
|
||||
CHECK_EQ(tid, 0);
|
||||
ThreadStart(thr, tid, GetPid());
|
||||
ThreadStart(thr, tid, internal_getpid());
|
||||
CHECK_EQ(thr->in_rtl, 1);
|
||||
ctx->initialized = true;
|
||||
|
||||
if (flags()->stop_on_start) {
|
||||
Printf("ThreadSanitizer is suspended at startup (pid %d)."
|
||||
" Call __tsan_resume().\n",
|
||||
GetPid());
|
||||
(int)internal_getpid());
|
||||
while (__tsan_resumed == 0) {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ void PrintMatchedSuppressions() {
|
|||
if (hit_count == 0)
|
||||
return;
|
||||
Printf("ThreadSanitizer: Matched %d suppressions (pid=%d):\n",
|
||||
hit_count, GetPid());
|
||||
hit_count, (int)internal_getpid());
|
||||
for (Suppression *supp = g_suppressions; supp; supp = supp->next) {
|
||||
if (supp->hit_count == 0)
|
||||
continue;
|
||||
|
|
|
@ -87,7 +87,8 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) {
|
|||
DlIteratePhdrCtx *ctx = (DlIteratePhdrCtx*)arg;
|
||||
InternalScopedBuffer<char> tmp(128);
|
||||
if (ctx->is_first) {
|
||||
internal_snprintf(tmp.data(), tmp.size(), "/proc/%d/exe", GetPid());
|
||||
internal_snprintf(tmp.data(), tmp.size(), "/proc/%d/exe",
|
||||
(int)internal_getpid());
|
||||
info->dlpi_name = tmp.data();
|
||||
}
|
||||
ctx->is_first = false;
|
||||
|
|
Loading…
Reference in New Issue