diff options
| author | Kostya Kortchinsky <kostyak@google.com> | 2017-11-09 19:18:55 +0000 |
|---|---|---|
| committer | Kostya Kortchinsky <kostyak@google.com> | 2017-11-09 19:18:55 +0000 |
| commit | 6458216b28fe2c7b2870cd91570f237441a25428 (patch) | |
| tree | 1476365a0fb9b289dc0391507dad025b6e98b423 /compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc | |
| parent | 0bd90044254fedb089c7a4c65f43956e1d5dee47 (diff) | |
| download | bcm5719-llvm-6458216b28fe2c7b2870cd91570f237441a25428.tar.gz bcm5719-llvm-6458216b28fe2c7b2870cd91570f237441a25428.zip | |
[scudo] Make getNumberOfCPUs Fuchsia compliant
Summary: This change allows Fuchsia to boot properly using the Scudo allocator.
Reviewers: cryptoad, alekseyshl, krytarowski
Reviewed By: cryptoad, krytarowski
Subscribers: rnk, krytarowski, kubamracek, llvm-commits
Differential Revision: https://reviews.llvm.org/D39490
llvm-svn: 317822
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc')
| -rw-r--r-- | compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc index 0dc43758516..5f9404eac2f 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -30,6 +30,7 @@ #include <dlfcn.h> // for dlsym() #include <link.h> #include <pthread.h> +#include <sched.h> #include <signal.h> #include <sys/resource.h> #include <syslog.h> @@ -37,9 +38,14 @@ #if SANITIZER_FREEBSD #include <pthread_np.h> #include <osreldate.h> +#include <sys/sysctl.h> #define pthread_getattr_np pthread_attr_get_np #endif +#if SANITIZER_NETBSD +#include <sys/sysctl.h> +#endif + #if SANITIZER_LINUX #include <sys/prctl.h> #endif @@ -538,6 +544,23 @@ uptr GetRSS() { return rss * GetPageSizeCached(); } +// sysconf(_SC_NPROCESSORS_{CONF,ONLN}) cannot be used as they allocate memory. +u32 GetNumberOfCPUs() { +#if SANITIZER_FREEBSD || SANITIZER_NETBSD + u32 ncpu; + int req[2]; + size_t len = sizeof(ncpu); + req[0] = CTL_HW; + req[1] = HW_NCPU; + CHECK_EQ(sysctl(req, 2, &ncpu, &len, NULL, 0), 0); + return ncpu; +#else + cpu_set_t CPUs; + CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0); + return CPU_COUNT(&CPUs); +#endif +} + // 64-bit Android targets don't provide the deprecated __android_log_write. // Starting with the L release, syslog() works and is preferable to // __android_log_write. |

