[PATCH] D82544: [SystemZ][ZOS] Implement getMainExecutable() and is_local_impl()

Kai Nacke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 25 06:20:30 PDT 2020


Kai created this revision.
Kai added reviewers: joerg, thakis, emaste, uweigand, yusra.syeda, kbarton.
Herald added subscribers: llvm-commits, hiraditya, krytarowski.
Herald added a project: LLVM.
Kai added a reviewer: chandlerc.
Kai added a reviewer: JDevlieghere.

Adds implementation of getMainExecutable() and is_local_impl() to Support/Unix/Path.inc.
Both are needed to compile LLVM for z/OS.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82544

Files:
  llvm/lib/Support/Unix/Path.inc


Index: llvm/lib/Support/Unix/Path.inc
===================================================================
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -50,6 +50,10 @@
 #include <sys/mount.h>
 #endif
 
+#ifdef __MVS__
+#include <sys/ps.h>
+#endif
+
 // Both stdio.h and cstdio are included via different paths and
 // stdcxx's cstdio doesn't include stdio.h, so it doesn't #undef the macros
 // either.
@@ -61,6 +65,10 @@
 # define PATH_MAX 4096
 #endif
 
+#if defined(__MVS__) && !defined(PATH_MAX)
+#define PATH_MAX _XOPEN_PATH_MAX
+#endif
+
 #include <sys/types.h>
 #if !defined(__APPLE__) && !defined(__OpenBSD__) && !defined(__FreeBSD__) &&   \
     !defined(__linux__) && !defined(__FreeBSD_kernel__) && !defined(_AIX)
@@ -100,7 +108,8 @@
 #define STATVFS_F_FRSIZE(vfs) static_cast<uint64_t>(vfs.f_bsize)
 #endif
 
-#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__)
+#if defined(__NetBSD__) || defined(__DragonFly__) || defined(__GNU__) || \
+    defined(__MVS__)
 #define STATVFS_F_FLAG(vfs) (vfs).f_flag
 #else
 #define STATVFS_F_FLAG(vfs) (vfs).f_flags
@@ -265,6 +274,26 @@
   // Fall back to the classical detection.
   if (getprogpath(exe_path, argv0))
     return exe_path;
+#elif defined(__MVS__)
+  int token = 0;
+  W_PSPROC buf;
+  char exe_path[PS_PATHBLEN];
+  pid_t pid = getpid();
+
+  memset(&buf, 0, sizeof(buf));
+  buf.ps_pathptr = exe_path;
+  buf.ps_pathlen = sizeof(exe_path);
+
+  while (true) {
+    if ((token = w_getpsent(token, &buf, sizeof(buf))) <= 0)
+      break;
+    if (buf.ps_pid != pid)
+      continue;
+    char real_path[PATH_MAX];
+    if (realpath(exe_path, real_path))
+      return std::string(real_path);
+    break;  // Found entry, but realpath failed.
+  }
 #elif defined(HAVE_DLFCN_H) && defined(HAVE_DLADDR)
   // Use dladdr to get executable path if available.
   Dl_info DLInfo;
@@ -493,6 +522,10 @@
 
   // vmount entry not found; "remote" is the conservative answer.
   return false;
+#elif defined(__MVS__)
+  // The file system can have an arbitrary structure on z/OS; must go with the
+  // conservative answer.
+  return false;
 #else
   return !!(STATVFS_F_FLAG(Vfs) & MNT_LOCAL);
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82544.273319.patch
Type: text/x-patch
Size: 2199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200625/fd45ae3a/attachment-0001.bin>


More information about the llvm-commits mailing list