PROC_RWMEM(9)
π PROC_RWMEM π β like, the proc_rwmem, proc_readmem, proc_writemem page from section 9 of the Kernel Developer's Manual, bestie π
Okay so picture this: you're deep in kernel land, and you need to peek at β or scribble on β some other process's memory. That's literally what this trio is for. Welcome to the group chat β¨
πΈ NAME πΈ
proc_rwmem, proc_readmem, proc_writemem β read from or write to a process address space π«Ά
β¨ SYNOPSIS β¨
#include <sys/types.h>
#include <sys/ptrace.h>
int
proc_rwmem(struct proc *p, struct uio *uio);
ssize_t
proc_readmem(struct thread *td, struct proc *p, vm_offset_t va,
void *buf, size_t len);
ssize_t
proc_writemem(struct thread *td, struct proc *p, vm_offset_t va,
void *buf, size_t len);
π DESCRIPTION π
So these functions exist so you can read from or write to the address space of the process p. That's the whole vibe π
The proc_rwmem() function is the β¨fancyβ¨ one β it makes you, the caller, spell out the I/O parameters yourself using a struct uio, which is described over in uio(9). Very "do it yourself, main character energy."
Meanwhile proc_readmem() and proc_writemem() are the chill, simpler, less general interface π§ They let the caller read into, or write from, the kernel buffer buf of size len, from or to the memory at offset va in the address space of p. Easy. Iconic. No struct uio required π
The operation is performed on behalf of thread td, which β ngl β will most often be the current thread.
β οΈ Okay important warning time, bestie: these functions may sleep and thus may not be called with any non-sleepable locks held. No cap. And the processpmust be held by the caller usingPHOLD(9)β like, that's not optional, that's the rule π₯
π¦ RETURN VALUES π¦
proc_rwmem()β returns0on success π ReturnsEFAULTif the specified user address is invalid, andENOMEMif the target pages could not be faulted in due to a resource shortage πproc_readmem()andproc_writemem()β return the number of bytes read or written, respectively. Heads up though: this may be smaller than the number of bytes requested β for example, if the request spans multiple pages in the process address space and one of them after the first is not mapped π Otherwise,-1is returned π
π SEE ALSO π
π AUTHORS π
This manual page was written by Mark Johnston <markj@FreeBSD.org> β ty bestie, we love a credited author π«Άβ¨
okay that's the whole page, you ate that π This one's from Debian, dated December 7, 2015 β go forth and read/write memory responsibly, mwah πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2015 Mark Johnston <markj@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms