[Openmp-commits] [PATCH] D55549: Implement __kmp_is_address_mapped() for NetBSD
Kamil Rytarowski via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Tue Dec 11 01:14:31 PST 2018
krytarowski created this revision.
krytarowski added reviewers: mgorny, joerg, OpenMP.
krytarowski added a project: OpenMP.
Use the sysctl(3) function to check whether an address is mapped
into the address space.
Repository:
rOMP OpenMP
https://reviews.llvm.org/D55549
Files:
runtime/src/z_Linux_util.cpp
Index: runtime/src/z_Linux_util.cpp
===================================================================
--- runtime/src/z_Linux_util.cpp
+++ 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 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D55549.177669.patch
Type: text/x-patch
Size: 1408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20181211/94db840a/attachment.bin>
More information about the Openmp-commits
mailing list