Skip to content

Commit 0819303

Browse files
committed
Add a persistent pagemap_fd per Task.
Changes in V2: - Merge open_pagemap_fd and open_pagemap_fd_if_needed into Task::pagemap_fd, returning the fd.
1 parent 9ae19d5 commit 0819303

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

src/AddressSpace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ class AddressSpace : public HasTaskSet {
674674
ScopedFd& mem_fd() { return child_mem_fd; }
675675
void set_mem_fd(ScopedFd&& fd) { child_mem_fd = std::move(fd); }
676676

677+
ScopedFd& pagemap_fd() { return child_pagemap_fd; }
678+
void set_pagemap_fd(ScopedFd&& fd) { child_pagemap_fd = std::move(fd); }
679+
677680
Monkeypatcher& monkeypatcher() {
678681
DEBUG_ASSERT(monkeypatch_state);
679682
return *monkeypatch_state;
@@ -1209,6 +1212,8 @@ class AddressSpace : public HasTaskSet {
12091212
const struct map_iterator_data* data);
12101213

12111214
AddressSpace operator=(const AddressSpace&) = delete;
1215+
1216+
ScopedFd child_pagemap_fd;
12121217
};
12131218

12141219
/**

src/Task.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,6 +2729,18 @@ void Task::open_mem_fd_if_needed() {
27292729
}
27302730
}
27312731

2732+
ScopedFd& Task::pagemap_fd() {
2733+
if (!as->pagemap_fd().is_open()) {
2734+
ScopedFd fd(proc_pagemap_path().c_str(), O_RDONLY);
2735+
if (fd.is_open()) {
2736+
as->set_pagemap_fd(std::move(fd));
2737+
} else {
2738+
LOG(info) << "Can't retrieve pagemap fd for " << tid;
2739+
}
2740+
}
2741+
return as->pagemap_fd();
2742+
}
2743+
27322744
KernelMapping Task::init_syscall_buffer(AutoRemoteSyscalls& remote,
27332745
remote_ptr<void> map_hint) {
27342746
char name[50];

src/Task.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,11 @@ class Task {
820820
*/
821821
void open_mem_fd_if_needed();
822822

823+
/**
824+
* Open /proc/[tid]/pagemap fd for our AddressSpace.
825+
*/
826+
ScopedFd& pagemap_fd();
827+
823828
/**
824829
* Perform a PTRACE_INTERRUPT set up the counter for potential spurious stops
825830
* to be detected in `account_for_potential_ptrace_interrupt_stop`.

src/record_syscall.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5656,7 +5656,7 @@ static void process_execve(RecordTask* t, TaskSyscallState& syscall_state) {
56565656
// The kernel may modify some of the pages in the mapping according to
56575657
// ELF BSS metadata. We use /proc/<pid>/pagemap to observe which pages
56585658
// have been changed and mark them for recording.
5659-
ScopedFd pagemap(t->proc_pagemap_path().c_str(), O_RDONLY, 0);
5659+
ScopedFd& pagemap = t->pagemap_fd();
56605660
ASSERT(t, pagemap.is_open());
56615661
vector<remote_ptr<void>> pages_to_record;
56625662

0 commit comments

Comments
 (0)