[CRIU] [PATCH v2 35/36] proc: Implement find_vma_size()

Kirill Tkhai ktkhai at virtuozzo.com
Fri Feb 3 08:16:46 PST 2017


Helper for getting vma size and start addr by
an addr in the vma.

May be userful to calculate stack sizes,
which are growing.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 criu/include/proc_parse.h |    1 +
 criu/proc_parse.c         |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/criu/include/proc_parse.h b/criu/include/proc_parse.h
index d67ac5e56..612777f99 100644
--- a/criu/include/proc_parse.h
+++ b/criu/include/proc_parse.h
@@ -104,5 +104,6 @@ struct pid;
 extern int parse_threads(int pid, struct pid **_t, int *_n);
 
 int parse_children(pid_t pid, pid_t **_c, int *_n);
+ssize_t find_vma_size(unsigned long *addr);
 
 #endif /* __CR_PROC_PARSE_H__ */
diff --git a/criu/proc_parse.c b/criu/proc_parse.c
index b52135ea5..46cb82b4d 100644
--- a/criu/proc_parse.c
+++ b/criu/proc_parse.c
@@ -2567,3 +2567,37 @@ int parse_children(pid_t pid, pid_t **_c, int *_n)
 	return -1;
 }
 
+ssize_t find_vma_size(unsigned long *addr)
+{
+	unsigned long start, end;
+	ssize_t size = -1;
+	struct bfd f;
+	char *str;
+
+	f.fd = open_proc(PROC_SELF, "maps");
+	if (f.fd < 0) {
+		pr_err("Can't get vma size\n");
+		return -1;
+	}
+
+	if (bfdopenr(&f))
+		goto close;
+	while (1) {
+		str = breadline(&f);
+		if (IS_ERR(str) || !str)
+			goto close;
+		if (sscanf(str, "%lx-%lx", &start, &end) != 2) {
+			pr_err("Can't sscanf\n");
+			goto close;
+		}
+
+		if (start <= *addr && *addr <= end) {
+			*addr = start;
+			size = end - start;
+			break;
+		}
+	}
+close:
+	bclose(&f);
+	return size;
+}



More information about the CRIU mailing list