--- util/oslib-posix.c.orig	2021-06-20 13:31:53 UTC
+++ util/oslib-posix.c
@@ -52,6 +52,13 @@
 #include <libutil.h>
 #endif
 
+#ifdef __DragonFly__
+#include <sys/sysctl.h>
+#include <sys/user.h>
+#include <sys/lwp.h>
+#include <libutil.h>
+#endif
+
 #ifdef __NetBSD__
 #include <sys/sysctl.h>
 #include <lwp.h>
@@ -99,6 +106,8 @@ int qemu_get_thread_id(void)
     long tid;
     thr_self(&tid);
     return (int)tid;
+#elif defined(__DragonFly__)
+    return (int)lwp_gettid();
 #elif defined(__NetBSD__)
     return _lwp_self();
 #elif defined(__OpenBSD__)
@@ -383,10 +392,10 @@ void qemu_init_exec_dir(const char *argv
             p = buf;
         }
     }
-#elif defined(__FreeBSD__) \
+#elif defined(__FreeBSD__) || defined(__DragonFly__) \
       || (defined(__NetBSD__) && defined(KERN_PROC_PATHNAME))
     {
-#if defined(__FreeBSD__)
+#if defined(__FreeBSD__) || defined(__DragonFly__)
         static int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
 #else
         static int mib[4] = {CTL_KERN, KERN_PROC_ARGS, -1, KERN_PROC_PATHNAME};
@@ -606,6 +615,14 @@ char *qemu_get_pid_name(pid_t pid)
         name = g_strdup(proc->ki_comm);
         free(proc);
     }
+#elif defined(__DragonFly__)
+    struct kinfo_proc kp;
+    size_t len = sizeof(kp);
+    int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid };
+
+    if (sysctl(mib, 4, &kp, &len, NULL, 0) == 0) {
+        name = g_strdup(kp.kp_comm);
+    }
 #else
     /* Assume a system with reasonable procfs */
     char *pid_path;
