kvm_write(3)

kvm_write3

Read or write kernel virtual memory

Part of kvm_read(3).

Usage

#include <kvm.h>

ssize_t

kvm_read(kvm_t *kd, unsigned long addr, void *buf, size_t nbytes);

ssize_t

kvm_read2(kvm_t *kd, kvaddr_t addr, void *buf, size_t nbytes);

ssize_t

kvm_write(kvm_t *kd, unsigned long addr, const void *buf, size_t nbytes);

Library

Kernel Data Access Library (libkvm, -lkvm)

Overview

The kvm_read(), kvm_read2(), and kvm_write() functions are used to read and write kernel virtual memory (or a crash dump file). See kvm_open(3) for information regarding opening kernel virtual memory and crash dumps.

The kvm_read() and kvm_read2() functions transfer nbytes bytes of data from the kernel space address addr to buf. Conversely, kvm_write() transfers data from buf to addr. Unlike their SunOS counterparts, these functions cannot be used to read or write process address spaces.

The kvm_read2() function uses a different type (kvaddr_t) for the addr argument to allow use of addresses larger than ULONG_MAX when examining non-native kernel images.

Return values

Upon success, the number of bytes actually transferred is returned. Otherwise, -1 is returned.

Releases

87 releases since FreeBSD 2.0.5-RELEASE; the text changed 43 times.

  1. 2.0.5–2.2.9
  2. 3.0
  3. 3.1–3.4
  4. 3.5–3.5.1
  5. 4.0
  6. 4.1–4.3
  7. 4.4
  8. 4.5–4.11
  9. 5.0–5.2.1
  10. 5.3–6.3
  11. 6.4
  12. 7.0
  13. 7.1
  14. 7.2
  15. 7.3
  16. 7.4
  17. 8.0
  18. 8.1
  19. 8.2
  20. 8.3
  21. 8.4
  22. 9.0
  23. 9.1
  24. 9.2
  25. 9.3
  26. 10.0
  27. 10.1
  28. 10.2
  29. 10.3
  30. 10.4
  31. 11.0
  32. 11.1
  33. 11.2
  34. 11.3
  35. 11.4
  36. 12.0
  37. 12.1
  38. 12.2
  39. 12.3
  40. 12.4
  41. 13.0–13.2
  42. 13.3–13.5
  43. 14.0–14.5
  44. 15.0–16.0

History

The kvm_read2() function first appeared in FreeBSD 11.0.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.