PROC_RWMEM(9)

πŸ’– PROC_RWMEM πŸ’–

okay bestie so this is the manual page for proc_rwmem and friends, straight outta the Kernel Developer's Manual, section 9. kernel devs only, iykyk 🫢


✨ 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 are literally how you read from or write to the address space of the process p. yes, someone else's memory. we're in there. main character energy πŸ’…

proc_rwmem() is the ✨fancy✨ one β€” you, the caller, have to hand it all the I/O deets yourself using a struct uio, which is described over in uio(9). very general, very flexible, very much on you to get right.

proc_readmem() and proc_writemem() are the chill, simpler, less-general-girlie interface πŸ’– they let you read into β€” or write β€” the kernel buffer buf of size len, from or to the memory at offset va inside p's address space. easy. clean. no uio drama.

and the whole operation is done on behalf of the thread td, which ngl will most often just be the current thread.

⚠️ okay important, no skipping: these functions may sleep, so you cannot call them while holding any non-sleepable locks. periodt. and p has to be held by the caller using PHOLD(9). do not forget the PHOLD. do not. πŸ™ˆ

🌈 RETURN VALUES 🌈

proc_rwmem() returns 0 when it slays. if the specified user address is invalid you get EFAULT, and if the target pages could not be faulted in because of a resource shortage you get ENOMEM. rough out there. πŸ’€

proc_readmem() and proc_writemem() return the number of bytes read or written, respectively β€” and heads up, that number may be smaller than the number of bytes you requested. like, for example, if your request spans multiple pages in the process address space and one of them after the first is not mapped. πŸ™ƒ otherwise, you get -1.


πŸ¦‹ SEE ALSO πŸ¦‹


πŸ‘‘ AUTHORS πŸ‘‘

This manual page was written by Mark Johnston <markj@FreeBSD.org>. ty for your service king 🫢


and that's the whole page bestie!! this one shipped on Debian, dated December 7, 2015 β€” a whole vibe, a whole era, and now it's yours. go forth and read some process memory responsibly πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from