summaryrefslogtreecommitdiff
path: root/openmp
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
commita89578fc8fc95c047761da86e0900f002d486b12 (patch)
treeeb9a6e1bb84b2aaf6bb8c9c9bcebb14efd1375b1 /openmp
parent3bd320e8c97d629bd6f79f2bd4dfd13da0047b8e (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
Diffstat (limited to 'openmp')
-rw-r--r--openmp/runtime/src/z_Linux_util.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/openmp/runtime/src/z_Linux_util.cpp b/openmp/runtime/src/z_Linux_util.cpp
index 7b008d74f66..283a20517e7 100644
--- a/openmp/runtime/src/z_Linux_util.cpp
+++ b/openmp/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