summaryrefslogtreecommitdiff
path: root/src/pal
diff options
context:
space:
mode:
authorKamil Rytarowski <n54@gmx.com>2016-04-16 02:22:23 +0200
committerKamil Rytarowski <n54@gmx.com>2016-04-18 09:01:21 +0200
commit2aa6bdb773d4a6d181cc2ebde8026908c706ac94 (patch)
tree82dcc2a6dbbb803db90a0715bcd7c8783091caa5 /src/pal
parentf21291a702a4247b1dd1c3219eaf5319e94df061 (diff)
downloadcoreclr-2aa6bdb773d4a6d181cc2ebde8026908c706ac94.tar.gz
coreclr-2aa6bdb773d4a6d181cc2ebde8026908c706ac94.tar.bz2
coreclr-2aa6bdb773d4a6d181cc2ebde8026908c706ac94.zip
Implement GetProcessIdDisambiguationKey() for NetBSD
Make use of the kvm(3) interface to get "struct kinfo_proc2" of the given process. struct kinfo_proc2 { ///.... uint32_t p_ustart_sec; /* STRUCT TIMEVAL: starting time. */ uint32_t p_ustart_usec; /* STRUCT TIMEVAL: starting time. */ ///... }; --- /usr/include/sys/sysctl.h
Diffstat (limited to 'src/pal')
-rw-r--r--src/pal/src/thread/process.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/pal/src/thread/process.cpp b/src/pal/src/thread/process.cpp
index 0de235e59c..df9a28b380 100644
--- a/src/pal/src/thread/process.cpp
+++ b/src/pal/src/thread/process.cpp
@@ -54,6 +54,13 @@ Abstract:
#include <sys/sysctl.h>
#endif
+#ifdef __NetBSD__
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <kvm.h>
+#endif
+
using namespace CorUnix;
SET_DEFAULT_DEBUG_CHANNEL(PROCESS);
@@ -1874,6 +1881,36 @@ GetProcessIdDisambiguationKey(DWORD processId, UINT64 *disambiguationKey)
return FALSE;
}
+#elif defined(__NetBSD__)
+
+ // On NetBSD, we return the process start time expressed in Unix time (the number of seconds
+ // since the start of the Unix epoch).
+ kvm_t *kd;
+ int cnt;
+ struct kinfo_proc2 *info;
+
+ kd = kvm_open(nullptr, nullptr, nullptr, KVM_NO_FILES, "kvm_open");
+ if (kd == nullptr)
+ {
+ _ASSERTE(!"Failed to get start time of a process.");
+ return FALSE;
+ }
+
+ info = kvm_getproc2(kd, KERN_PROC_PID, processId, sizeof(struct kinfo_proc2), &cnt);
+ if (info == nullptr || cnt < 1)
+ {
+ kvm_close(kd);
+ _ASSERTE(!"Failed to get start time of a process.");
+ return FALSE;
+ }
+
+ kvm_close(kd);
+
+ long secondsSinceEpoch = info->p_ustart_sec;
+ *disambiguationKey = secondsSinceEpoch;
+
+ return TRUE;
+
#elif defined(HAVE_PROCFS_CTL)
// Here we read /proc/<pid>/stat file to get the start time for the process.