aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Rytarowski <n54@gmx.com>2018-12-11 18:35:07 +0000
committerKamil Rytarowski <n54@gmx.com>2018-12-11 18:35:07 +0000
commit67d037d373792a37fae0df856ffb4699f8c4b3e5 (patch)
tree8f7e36a56091604ac21bc40527caa2453da9583d
parent97619771cf16ebc88fa06ac031a482ac2e7f9f51 (diff)
Implement __kmp_is_address_mapped() for NetBSD
Summary: Use the sysctl(3) function to check whether an address is mapped into the address space. Reviewers: mgorny, joerg, #openmp Reviewed By: mgorny Subscribers: openmp-commits Tags: #openmp Differential Revision: https://reviews.llvm.org/D55549 git-svn-id: https://llvm.org/svn/llvm-project/openmp/trunk@348874 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--runtime/src/z_Linux_util.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/runtime/src/z_Linux_util.cpp b/runtime/src/z_Linux_util.cpp
index 7b008d7..283a205 100644
--- a/runtime/src/z_Linux_util.cpp
+++ b/runtime/src/z_Linux_util.cpp
@@ -52,6 +52,9 @@
#include <sys/sysctl.h>
#elif KMP_OS_DRAGONFLY || KMP_OS_FREEBSD
#include <pthread_np.h>
+#elif KMP_OS_NETBSD
+#include <sys/types.h>
+#include <sys/sysctl.h>
#endif
#include <ctype.h>
@@ -2015,9 +2018,39 @@ int __kmp_is_address_mapped(void *addr) {
found = 1;
}
-#elif KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD || KMP_OS_OPENBSD
+#elif KMP_OS_NETBSD
+
+ int mib[5];
+ mib[0] = CTL_VM;
+ mib[1] = VM_PROC;
+ mib[2] = VM_PROC_MAP;
+ mib[3] = getpid();
+ mib[4] = sizeof(struct kinfo_vmentry);
+
+ size_t size;
+ rc = sysctl(mib, __arraycount(mib), NULL, &size, NULL, 0);
+ KMP_ASSERT(!rc);
+ KMP_ASSERT(size);
+
+ size = size * 4 / 3;
+ struct kinfo_vmentry *kiv = (struct kinfo_vmentry *)KMP_INTERNAL_MALLOC(size);
+ KMP_ASSERT(kiv);
+
+ rc = sysctl(mib, __arraycount(mib), kiv, &size, NULL, 0);
+ KMP_ASSERT(!rc);
+ KMP_ASSERT(size);
+
+ for (size_t i = 0; i < size; i++) {
+ if (kiv[i].kve_start >= (uint64_t)addr &&
+ kiv[i].kve_end <= (uint64_t)addr) {
+ found = 1;
+ break;
+ }
+ }
+ KMP_INTERNAL_FREE(kiv);
+#elif KMP_OS_DRAGONFLY || KMP_OS_OPENBSD
- // FIXME(DragonFly, FreeBSD, NetBSD, OpenBSD): Implement this
+ // FIXME(DragonFly, OpenBSD): Implement this
found = 1;
#else