-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
createdump can read memory with process_vm_readv on Linux #420
Merged
+19
−1
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,23 +9,28 @@ | |
DumpDataTarget::DumpDataTarget(pid_t pid) : | ||
m_ref(1), | ||
m_pid(pid), | ||
#ifndef HAVE_PROCESS_VM_READV | ||
m_fd(-1), | ||
#endif | ||
m_crashInfo(nullptr) | ||
{ | ||
} | ||
|
||
DumpDataTarget::~DumpDataTarget() | ||
{ | ||
#ifndef HAVE_PROCESS_VM_READV | ||
if (m_fd != -1) | ||
{ | ||
close(m_fd); | ||
m_fd = -1; | ||
} | ||
#endif | ||
} | ||
|
||
bool | ||
DumpDataTarget::Initialize(CrashInfo * crashInfo) | ||
{ | ||
#ifndef HAVE_PROCESS_VM_READV | ||
char memPath[128]; | ||
_snprintf_s(memPath, sizeof(memPath), sizeof(memPath), "/proc/%lu/mem", m_pid); | ||
|
||
|
@@ -35,6 +40,7 @@ DumpDataTarget::Initialize(CrashInfo * crashInfo) | |
fprintf(stderr, "open(%s) FAILED %d (%s)\n", memPath, errno, strerror(errno)); | ||
return false; | ||
} | ||
#endif | ||
m_crashInfo = crashInfo; | ||
return true; | ||
} | ||
|
@@ -149,14 +155,20 @@ DumpDataTarget::ReadVirtual( | |
/* [in] */ ULONG32 size, | ||
/* [optional][out] */ ULONG32 *done) | ||
{ | ||
#ifdef HAVE_PROCESS_VM_READV | ||
iovec local{ buffer, size }; | ||
iovec remote{ (void*)(ULONG_PTR)address, size }; | ||
ssize_t read = process_vm_readv(m_pid, &local, 1, &remote, 1, 0); | ||
#else | ||
assert(m_fd != -1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mikem8361 Any reason these are not runtime-like asserts? |
||
ssize_t read = pread64(m_fd, buffer, size, (off64_t)(ULONG_PTR)address); | ||
#endif | ||
if (read == -1) | ||
{ | ||
*done = 0; | ||
return E_FAIL; | ||
} | ||
*done = read; | ||
*done = (ULONG32)read; | ||
return S_OK; | ||
} | ||
|
||
|
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ssize_t
is a signed, 64-bit integer;ULONG32
is an unsigned, 32-bit integer. It's unlikely thatread
will be larger thansize
as that's the quantity passed as a parameter, however assigningread
to*done
will at least generate a warning.(Using 32-bit integers to denote sizes is something we should fix throughout the runtime. It should use
size_t
throughout.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, are there any places where it would be beneficial to pass an
iovec
array rather than just 1 element at a time toprocess_vm_readv()
? (There could be a fallback method to go through each one and read the memory on OSes that do not offer this particular syscall or a similar feature.)It might be a good idea to
#ifdef
this for Linux only, or check if the syscall exist during build-time. For instance, the FreeBSDprocfs
supports/proc/<PID>/mem
but does not have this syscall, so this breakscreatedump
on FreeBSD. On systems withoutprocess_vm_readv()
but with a compatibleprocfs
, you might benefit from usingreadv()
instead ofpread()
and have similar speedups if the suggestion above is possible.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There may even be Linux distros that don't support process_vm_readv so a build-time check (like all the other HAVE_xxxx defines) should be added falling back to the proc//mem code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All supported Linux distros meet the minimum version requirement, so I assume it only needs to check for Linux.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
createdump
doc says/proc
doesn't work on FreeBSD. Can you confirm it? Thanks!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some parallel read operations, but they are invoked on
ICLRDataTarget
instead ofDumpDataTarget
. It's not easy to extend that interface.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote that createdump doc 2 or 3 years ago and at the time, it didn't look like FreeBSD supported /proc//mem but now I'm not sure.