code
code copied to clipboard
Ch6 Listing 6.19 Virtual memory inspection in Linux
As a MacOS user, it would be nice to have the alternative version of the same code to inspect the virtual memory in Linux. Having a Linux example based on POSIX seems reasonable.
Personally, showing a Windows-only example felt also a bit out of context to me. Right some lines before, the book was showing a very cool picture of ELF (which AFAIK is Linux-only) and I was intrigued to learn more, then it jumps to Windows code.
I agree, a POSIX example would be nice and would seem to fit better with the rest of the book.
I was able to piece together a native macOS implementation by porting example C code from section 8.7 of Mac OS X Internals by Amit Singh and using the mach crate. This was a satisfying exercise but certainly took some fiddling 😄
On Linux, the same information is present in /proc/<pid>/smaps
(I am not sure there's a POSIX standard for this as it seems different *nix variants do this differently).
procps
(https://gitlab.com/procps-ng/procps), is a C library and a set of programs (e.g. pmap
) to read this data without having to do string parsing etc. I guess it will be a good exercise to use the procps
library from Rust to get data similar to what pmap
provides.
Agree, as the Rust Survey 2019 shows, more than half of rust developers are using Linux, so a Linux demo code would definitely be great:)