Fallback to /proc/$pid/mem when process_vm_readv() is unavailabe#4
Merged
benfred merged 2 commits intobenfred:masterfrom Jan 30, 2021
Merged
Conversation
If the Linux kernel was built without support for process_vm_readv() (CONFIG_CROSS_MEMORY_ATTACH is unset in kernel config) a call to this function will fail with Function not implemented (os error 38) aka ENOSYS. To still support reading process memory on this platform we fallback to reading /proc/$pid/mem.
98110bf to
27863c7
Compare
|
@sebageek CI is green now on |
benfred
approved these changes
Jan 30, 2021
Owner
|
Thanks for this! This helps a lot - I'm surprised how many people hit this problem with py-spy |
|
@benfred Could you please cut a release with this patch? The 0.2.0 crate doesn't have this change. Also, the tags on the GH repo are not in sync :) |
Owner
|
@nehaljwani I've pushed out 0.2.1 to crates.io with this change (and am in the process of getting this change into dependant packages like remoteprocess/py-spy). |
benfred
added a commit
to benfred/rbspy
that referenced
this pull request
Mar 22, 2021
The latest remoteprocess code includes a workaround for the case where the linux kernel was compiled without process_vm_readv support (by falling back to /proc/PID/mem: benfred/read-process-memory#4). Closes rbspy#196
benfred
pushed a commit
that referenced
this pull request
Oct 27, 2021
If the Linux kernel was built without support for process_vm_readv() (CONFIG_CROSS_MEMORY_ATTACH is unset in kernel config) a call to this function will fail with Function not implemented (os error 38) aka ENOSYS. To still support reading process memory on this platform we fallback to reading /proc/$pid/mem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If the Linux kernel was built without support for process_vm_readv()
(CONFIG_CROSS_MEMORY_ATTACH is unset in kernel config) a call to this
function will fail with Function not implemented (os error 38) aka
ENOSYS. To still support reading process memory on this platform we
fallback to reading /proc/$pid/mem.
This is intended as a fix for benfred/py-spy/issues/22. To reproduce this I recompiled my current kernel with
CONFIG_CROSS_MEMORY_ATTACHdisabled.This yielded the
Error: Function not implemented (os error 38). The patch in this PR subsequently fixed this error.I'm still a bit unhappy with the fallback, as each time memory is read an attempt to use
process_vm_readv()is made, which is one extra syscall per read. Additionally the filehandle toprocmemcould be cached per pid, saving two additional syscalls (open, close). This might lead to an API change though, so I wanted to discuss this before wildly implementing something. In any case, the code in this PR shouldn't change the performance for current users of this library. It will only be slower in cases where it would have errored out beforehand.Shoutout to @eqv for rust support!