diff --git a/CMakeLists.txt b/CMakeLists.txt
index 39c35a232c..0cfff39667 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -300,7 +300,14 @@ check_include_files(malloc.h HAVE_MALLOC_H)
check_include_file("sys/prctl.h" HAVE_SYS_PRCTL_H)
check_symbol_exists(PR_SET_DUMPABLE "sys/prctl.h" HAVE_PR_SET_DUMPABLE)
-add_feature_info("prctl-dumpable" HAVE_PR_SET_DUMPABLE "Required for disallow ptrace on kwin_wayland process")
+check_include_file("sys/procctl.h" HAVE_SYS_PROCCTL_H)
+check_symbol_exists(PROC_TRACE_CTL "sys/procctl.h" HAVE_PROC_TRACE_CTL)
+if (HAVE_PR_SET_DUMPABLE OR HAVE_PROC_TRACE_CTL)
+ set(CAN_DISABLE_PTRACE TRUE)
+endif()
+add_feature_info("prctl/procctl tracing control"
+ CAN_DISABLE_PTRACE
+ "Required for disallowing ptrace on kwin_wayland process")
configure_file(config-kwin.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kwin.h )
diff --git a/config-kwin.h.cmake b/config-kwin.h.cmake
index c7d741795e..88c9a03873 100644
--- a/config-kwin.h.cmake
+++ b/config-kwin.h.cmake
@@ -17,6 +17,8 @@
#cmakedefine01 HAVE_WAYLAND_EGL
#cmakedefine01 HAVE_SYS_PRCTL_H
#cmakedefine01 HAVE_PR_SET_DUMPABLE
+#cmakedefine01 HAVE_SYS_PROCCTL_H
+#cmakedefine01 HAVE_PROC_TRACE_CTL
#cmakedefine01 HAVE_BREEZE_DECO
#if HAVE_BREEZE_DECO
#define BREEZE_KDECORATION_PLUGIN_ID "${BREEZE_KDECORATION_PLUGIN_ID}"
diff --git a/main_wayland.cpp b/main_wayland.cpp
index 7d3b71a6b9..add8013a2a 100644
--- a/main_wayland.cpp
+++ b/main_wayland.cpp
@@ -56,6 +56,10 @@ along with this program. If not, see .
#if HAVE_SYS_PRCTL_H
#include
#endif
+#if HAVE_SYS_PROCCTL_H
+#include
+#include
+#endif
#include
#include
@@ -403,6 +407,14 @@ static void disablePtrace()
// disable ptrace in kwin_wayland
prctl(PR_SET_DUMPABLE, 0);
#endif
+#if HAVE_PROC_TRACE_CTL
+ // FreeBSD's rudimentary procfs does not support /proc//exe
+ // We could use the P_TRACED flag of the process to find out
+ // if the process is being debugged ond FreeBSD.
+ int mode = PROC_TRACE_CTL_DISABLE;
+ procctl(P_PID, getpid(), PROC_TRACE_CTL, &mode);
+#endif
+
}
} // namespace