diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 26c5b072208c..b4ced16d20d1 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -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(); diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc index 3684e847c812..abbe5f92d1a9 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.cc @@ -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 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) { diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common.h b/compiler-rt/lib/sanitizer_common/sanitizer_common.h index f0208f33333a..d800360169fb 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common.h @@ -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, diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h index 5f77ad1e5cff..82d809a0305a 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_libc.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_libc.h @@ -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 diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc index 0181b69e8026..9d74a48f5356 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_mac.cc @@ -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; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc index 1bc99081a6b4..72dde4cd7e76 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_posix.cc @@ -43,10 +43,6 @@ uptr GetMmapGranularity() { return GetPageSize(); } -int GetPid() { - return getpid(); -} - u32 GetUid() { return getuid(); } diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_printf.cc b/compiler-rt/lib/sanitizer_common/sanitizer_printf.cc index ebb8fa07a131..5935d7f17a5e 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_printf.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_printf.cc @@ -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. diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc index b826cb2f4287..e76f1d1f7fa6 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_win.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_win.cc @@ -44,7 +44,7 @@ bool FileExists(const char *filename) { UNIMPLEMENTED(); } -int GetPid() { +uptr internal_getpid() { return GetProcessId(GetCurrentProcess()); } diff --git a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc index c7651c67bf9e..f18b26f6abe4 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc @@ -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; } diff --git a/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc b/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc index 257afcf8fa35..04b4b455d15e 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_interface_ann.cc @@ -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, diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc index 5ccdc49d37d2..a0d71e8589d6 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc @@ -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; diff --git a/compiler-rt/lib/tsan/rtl/tsan_report.cc b/compiler-rt/lib/tsan/rtl/tsan_report.cc index bfa266021897..c95c5c86be69 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_report.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_report.cc @@ -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) diff --git a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc index c51a5669060e..66b23fe1bc21 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_rtl.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_rtl.cc @@ -120,7 +120,7 @@ static void BackgroundThread(void *arg) { if (flags()->profile_memory && flags()->profile_memory[0]) { InternalScopedBuffer 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) {} } } diff --git a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc index 14b6a3acaccd..6c49355bed88 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc @@ -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; diff --git a/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc b/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc index 76926e2b5aaf..47f9e1fbf418 100644 --- a/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc +++ b/compiler-rt/lib/tsan/rtl/tsan_symbolize_addr2line_linux.cc @@ -87,7 +87,8 @@ static int dl_iterate_phdr_cb(dl_phdr_info *info, size_t size, void *arg) { DlIteratePhdrCtx *ctx = (DlIteratePhdrCtx*)arg; InternalScopedBuffer 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;