[CRIU] [PATCH 04/13] mem: Add read_pme helper
Pavel Emelyanov
xemul at parallels.com
Thu May 23 07:02:18 EDT 2013
On 05/22/2013 11:09 PM, Cyrill Gorcunov wrote:
>
> Will need it to compare page frame number of vdso areas.
>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
> include/mem.h | 3 +++
> mem.c | 29 +++++++++++++++++++++++++++++
> 2 files changed, 32 insertions(+)
>
> +int read_pme(pid_t pid, unsigned long addr, u64 *pme)
> +{
> + int fd, ret = -1;
> + char path[32];
> + off_t off;
> +
> + snprintf(path, sizeof(path), "/proc/%d/pagemap", pid);
Can we use existing open_proc helper?
> + fd = open(path, O_RDONLY);
Can we open this file once during parasite_fixup_vdso()?
> + if (fd < 0) {
> + pr_perror("Can't open %s", path);
> + return -1;
> + }
> +
> + off = (addr / PAGE_SIZE) * sizeof(u64);
> + if (lseek(fd, off, SEEK_SET) != off) {
> + pr_perror("Failed to seek address %lx\n", addr);
> + goto out;
> + }
> +
> + ret = read(fd, pme, sizeof(*pme));
> + if (ret < 0) {
> + pr_perror("Can't read pme for pid %d", pid);
> + goto out;
> + }
> + ret = 0;
> +out:
> + close(fd);
> + return ret;
> +}
More information about the CRIU
mailing list