[Openmp-commits] [PATCH] D69220: [OpenMP] Enable OpenBSD support

David CARLIER via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Sat Oct 19 15:32:23 PDT 2019


devnexen created this revision.
devnexen added reviewers: jdoerfert, Hahnfeld.
devnexen created this object with visibility "All Users".
Herald added subscribers: openmp-commits, guansong.
Herald added a project: OpenMP.

- Implement mapped address lookup.


Repository:
  rOMP OpenMP

https://reviews.llvm.org/D69220

Files:
  openmp/runtime/src/kmp_ftn_entry.h
  openmp/runtime/src/kmp_wrapper_getpid.h
  openmp/runtime/src/z_Linux_util.cpp


Index: openmp/runtime/src/z_Linux_util.cpp
===================================================================
--- openmp/runtime/src/z_Linux_util.cpp
+++ openmp/runtime/src/z_Linux_util.cpp
@@ -54,9 +54,10 @@
 #include <sys/sysctl.h>
 #include <sys/user.h>
 #include <pthread_np.h>
-#elif KMP_OS_NETBSD
+#elif KMP_OS_NETBSD || KMP_OS_OPENBSD
 #include <sys/types.h>
 #include <sys/sysctl.h>
+#elif KMP_OS
 #endif
 
 #include <ctype.h>
@@ -2130,9 +2131,36 @@
     }
   }
   KMP_INTERNAL_FREE(kiv);
-#elif KMP_OS_DRAGONFLY || KMP_OS_OPENBSD
+#elif KMP_OS_OPENBSD
+
+  int mib[3];
+  mib[0] = CTL_KERN;
+  mib[1] = KERN_PROC_VMMAP;
+  mib[2] = getpid();
+
+  size_t size;
+  uint64_t end = 0;
+  rc =sysctl(mib, 3, NULL, &size, NULL, 0);
+  KMP_ASSERT(!rc);
+  KMP_ASSERT(size);
+
+  struct kinfo_vmentry kiv = {.kve_start = 0};
+
+  while ((rc = sysctl(mib, 3, &kiv, &size, NULL, 0)) == 0) {
+  	KMP_ASSERT(size);
+	if (kiv.kve_end == end)
+          break;
+
+	if (kiv.kve_start >= (uint64_t)addr &&
+            kiv.kve_end <= (uint64_t)addr) {
+          found = 1;
+	  break;
+	}
+	kiv.kve_start += 1;
+  }
+#elif KMP_OS_DRAGONFLY
 
-  // FIXME(DragonFly, OpenBSD): Implement this
+  // FIXME(DragonFly): Implement this
   found = 1;
 
 #else
Index: openmp/runtime/src/kmp_wrapper_getpid.h
===================================================================
--- openmp/runtime/src/kmp_wrapper_getpid.h
+++ openmp/runtime/src/kmp_wrapper_getpid.h
@@ -28,7 +28,8 @@
 #define __kmp_gettid() pthread_getthreadid_np()
 #elif KMP_OS_NETBSD
 #include <lwp.h>
-#define __kmp_gettid() _lwp_self()
+#elif KMP_OS_OPENBSD
+#define __kmp_gettid() syscall(SYS_getthrid)
 #elif defined(SYS_gettid)
 // Hopefully other Unix systems define SYS_gettid syscall for getting os thread
 // id
Index: openmp/runtime/src/kmp_ftn_entry.h
===================================================================
--- openmp/runtime/src/kmp_ftn_entry.h
+++ openmp/runtime/src/kmp_ftn_entry.h
@@ -531,7 +531,7 @@
   int gtid;
 
 #if KMP_OS_DARWIN || KMP_OS_DRAGONFLY || KMP_OS_FREEBSD || KMP_OS_NETBSD ||    \
-        KMP_OS_HURD
+        KMP_OS_HURD|| KMP_OS_OPENBSD
   gtid = __kmp_entry_gtid();
 #elif KMP_OS_WINDOWS
   if (!__kmp_init_parallel ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69220.225771.patch
Type: text/x-patch
Size: 2221 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20191019/4daa85ff/attachment.bin>


More information about the Openmp-commits mailing list