Reuse the kvm(3) interface to grab "struct kinfo_proc".
NAME
kvm - kernel memory interface
LIBRARY
Kernel Data Access Library (libkvm, -lkvm)
DESCRIPTION
The kvm library provides a uniform interface for accessing kernel virtual
memory images, including live systems and crash dumps. Access to live
systems is via /dev/mem while crash dumps can be examined via the core
file generated by savecore(8). The interface behaves identically in both
cases. Memory can be read and written, kernel symbol addresses can be
looked up efficiently, and information about user processes can be
gathered.
kvm_open() is first called to obtain a descriptor for all subsequent
calls
Commit migrated from https://github.com/dotnet/coreclr/commit/
06ff0ff180dc0aa512481e5e4885b1f16e785a81
endif(CMAKE_SYSTEM_NAME STREQUAL Linux)
if(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
+ add_definitions(-D_KMEMUSER)
find_library(UNWIND unwind)
find_library(INTL intl)
+ find_library(KVM kvm)
target_link_libraries(coreclrpal
pthread
rt
${UNWIND}
${INTL}
+ ${KVM}
)
endif(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
#include <mach-o/dyld.h>
#endif // __APPLE__
+#ifdef __NetBSD__
+#include <sys/cdefs.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <kvm.h>
+#endif
+
using namespace CorUnix;
//
return ((info.kp_proc.p_flag & P_TRACED) != 0);
return FALSE;
+#elif defined(__NetBSD__)
+ int traced;
+ kvm_t *kd;
+ int cnt;
+
+ struct kinfo_proc *info;
+
+ kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, "kvm_open");
+ if (kd == NULL)
+ return FALSE;
+
+ info = kvm_getprocs(kd, KERN_PROC_PID, getpid(), &cnt);
+ if (info == NULL || cnt < 1)
+ {
+ kvm_close(kd);
+ return FALSE;
+ }
+
+ traced = info->kp_proc.p_slflag & PSL_TRACED;
+ kvm_close(kd);
+
+ if (traced != 0)
+ return TRUE;
+ else
+ return FALSE;
#else
return FALSE;
#endif