Commit fd412019 authored by Pavel Emelyanov's avatar Pavel Emelyanov

restore: Parse /proc/self/maps for self mappings

On restore we only need to know currnet task mappings' start and end
to find where to put the restorer blob. And since the smaps file in
/proc/pid is up to 3 times slower, than the maps one, it makes
perfect sense just to parse the latter one.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 4dbc5f11
...@@ -2231,7 +2231,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core) ...@@ -2231,7 +2231,7 @@ static int sigreturn_restore(pid_t pid, CoreEntry *core)
* this unwanted mapping might get overlapped by the restorer. * this unwanted mapping might get overlapped by the restorer.
*/ */
ret = parse_smaps(pid, &self_vmas, false); ret = parse_self_maps_lite(&self_vmas);
close_proc(); close_proc();
if (ret < 0) if (ret < 0)
goto err; goto err;
......
...@@ -142,6 +142,7 @@ extern struct mount_info *parse_mountinfo(pid_t pid); ...@@ -142,6 +142,7 @@ extern struct mount_info *parse_mountinfo(pid_t pid);
extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s); extern int parse_pid_stat(pid_t pid, struct proc_pid_stat *s);
extern int parse_pid_stat_small(pid_t pid, struct proc_pid_stat_small *s); extern int parse_pid_stat_small(pid_t pid, struct proc_pid_stat_small *s);
extern int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_files); extern int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_files);
extern int parse_self_maps_lite(struct vm_area_list *vms);
extern int parse_pid_status(pid_t pid, struct proc_status_creds *); extern int parse_pid_status(pid_t pid, struct proc_status_creds *);
union fdinfo_entries { union fdinfo_entries {
......
...@@ -212,6 +212,40 @@ static int vma_get_mapfile(struct vma_area *vma, DIR *mfd, ...@@ -212,6 +212,40 @@ static int vma_get_mapfile(struct vma_area *vma, DIR *mfd,
return 0; return 0;
} }
int parse_self_maps_lite(struct vm_area_list *vms)
{
FILE *maps;
vm_area_list_init(vms);
maps = fopen("/proc/self/maps", "r");
if (maps == NULL) {
pr_perror("Can't open self maps");
return -1;
}
while (fgets(buf, BUF_SIZE, maps) != NULL) {
struct vma_area *vma;
char *end;
vma = alloc_vma_area();
if (!vma) {
fclose(maps);
return -1;
}
vma->e->start = strtoul(buf, &end, 16);
vma->e->end = strtoul(end + 1, NULL, 16);
list_add_tail(&vma->list, &vms->h);
vms->nr++;
pr_debug("Parsed %lx-%lx vma\n", vma->e->start, vma->e->end);
}
fclose(maps);
return 0;
}
int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_files) int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_files)
{ {
struct vma_area *vma_area = NULL; struct vma_area *vma_area = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment