From 3838115b52b17f0eb97ddbca51b40162c0333cdb Mon Sep 17 00:00:00 2001 From: Kamil Rytarowski Date: Fri, 15 Apr 2016 13:23:31 +0200 Subject: [PATCH] NetBSD: Add support for PAL_IsDebuggerPresent() 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 --- src/coreclr/src/pal/src/CMakeLists.txt | 3 +++ src/coreclr/src/pal/src/init/pal.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/coreclr/src/pal/src/CMakeLists.txt b/src/coreclr/src/pal/src/CMakeLists.txt index e8e1655..15dab11 100644 --- a/src/coreclr/src/pal/src/CMakeLists.txt +++ b/src/coreclr/src/pal/src/CMakeLists.txt @@ -271,13 +271,16 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux) 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) diff --git a/src/coreclr/src/pal/src/init/pal.cpp b/src/coreclr/src/pal/src/init/pal.cpp index 0357ad9..afbee79 100644 --- a/src/coreclr/src/pal/src/init/pal.cpp +++ b/src/coreclr/src/pal/src/init/pal.cpp @@ -72,6 +72,13 @@ int CacheLineSize; #include #endif // __APPLE__ +#ifdef __NetBSD__ +#include +#include +#include +#include +#endif + using namespace CorUnix; // @@ -706,6 +713,31 @@ PAL_IsDebuggerPresent() 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 -- 2.7.4