code icon indicating copy to clipboard operation
code copied to clipboard

Ch6 Listing 6.19 Virtual memory inspection in Linux

Open jiayihu opened this issue 4 years ago • 3 comments

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.

jiayihu avatar Aug 06 '20 10:08 jiayihu

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 😄

mgiles avatar Nov 14 '20 17:11 mgiles

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.

ahmedriza avatar Dec 23 '20 13:12 ahmedriza

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:)

SteveLauC avatar Jan 09 '22 02:01 SteveLauC