Skip to content

Commit

Permalink
procfs: populate maps file with i-node numbers
Browse files Browse the repository at this point in the history
This patch refines the implementation of procfs
to generate maps file that contains correct file i-node
numbers instead of 0s for file VMAs as shown below:

0-0 ---p 00000000 00:00 0
100000000000-100000001000 r--p 00000000 00:00 3 /libvdso.so
100000001000-100000002000 r-xp 00001000 00:00 3 /libvdso.so
100000002000-100000003000 r--p 00002000 00:00 3 /libvdso.so
100000003000-100000004000 r--p 00002000 00:00 3 /libvdso.so
100000004000-100000005000 rw-p 00003000 00:00 3 /libvdso.so
100000005000-100000007000 r--p 00000000 00:00 6 /cat
100000007000-10000000c000 r-xp 00002000 00:00 6 /cat
10000000c000-10000000e000 r--p 00007000 00:00 6 /cat
10000000f000-100000010000 r--p 00009000 00:00 6 /cat
100000010000-100000011000 rw-p 0000a000 00:00 6 /cat
200000000000-200000001000 ---p 00000000 00:00 0
200000001000-200000100000 rw-p 00000000 00:00 0
200000100000-200000101000 ---p 00000000 00:00 0
200000101000-200000200000 rw-p 00000000 00:00 0
800000000000-800000000000 ---p 00000000 00:00 0

It does so by capturing and saving the file i-node number when
constructing file_vma so that it can be used when generating
/proc/self/maps.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
wkozaczuk authored and nyh committed Jul 1, 2019
1 parent 276aa1b commit 6f8d6cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion core/mmu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,14 @@ file_vma::file_vma(addr_range range, unsigned perm, unsigned flags, fileref file
if (err != 0) {
throw make_error(err);
}

struct stat st;
err = _file->stat(&st);
if (err != 0) {
throw make_error(err);
}

_file_inode = st.st_ino;
}

void file_vma::fault(uintptr_t addr, exception_frame *ef)
Expand Down Expand Up @@ -1910,7 +1918,7 @@ std::string procfs_maps()
osv::fprintf(os, "%x-%x %c%c%c%c ", vma.start(), vma.end(), read, write, execute, priv);
if (vma.flags() & mmap_file) {
const file_vma &f_vma = static_cast<file_vma&>(vma);
osv::fprintf(os, "%08x 00:00 0 %s\n", f_vma.offset(), f_vma.file()->f_dentry->d_path);
osv::fprintf(os, "%08x 00:00 %ld %s\n", f_vma.offset(), f_vma.file_inode(), f_vma.file()->f_dentry->d_path);
} else {
osv::fprintf(os, "00000000 00:00 0\n");
}
Expand Down
2 changes: 2 additions & 0 deletions include/osv/mmu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ public:
virtual void fault(uintptr_t addr, exception_frame *ef) override;
fileref file() const { return _file; }
f_offset offset() const { return _offset; }
u64 file_inode() const { return _file_inode; }
private:
f_offset offset(uintptr_t addr);
fileref _file;
f_offset _offset;
u64 _file_inode;
};

ulong map_jvm(unsigned char* addr, size_t size, size_t align, balloon_ptr b);
Expand Down

0 comments on commit 6f8d6cd

Please sign in to comment.