]>
git.proxmox.com Git - mirror_qemu.git/blob - util/selfmap.c
2 * Utility function to get QEMU's own process map
4 * Copyright (c) 2020 Linaro Ltd
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "qemu/osdep.h"
10 #include "qemu/cutils.h"
11 #include "qemu/selfmap.h"
13 GSList
*read_self_maps(void)
16 GSList
*map_info
= NULL
;
18 if (g_file_get_contents("/proc/self/maps", &maps
, NULL
, NULL
)) {
19 gchar
**lines
= g_strsplit(maps
, "\n", 0);
20 int i
, entries
= g_strv_length(lines
);
22 for (i
= 0; i
< entries
; i
++) {
23 gchar
**fields
= g_strsplit(lines
[i
], " ", 6);
24 if (g_strv_length(fields
) > 4) {
25 MapInfo
*e
= g_new0(MapInfo
, 1);
29 errors
= qemu_strtoul(fields
[0], &end
, 16, &e
->start
);
30 errors
+= qemu_strtoul(end
+ 1, NULL
, 16, &e
->end
);
32 e
->is_read
= fields
[1][0] == 'r';
33 e
->is_write
= fields
[1][1] == 'w';
34 e
->is_exec
= fields
[1][2] == 'x';
35 e
->is_priv
= fields
[1][3] == 'p';
37 errors
+= qemu_strtoul(fields
[2], NULL
, 16, &e
->offset
);
38 e
->dev
= g_strdup(fields
[3]);
39 errors
+= qemu_strtou64(fields
[4], NULL
, 10, &e
->inode
);
42 * The last field may have leading spaces which we
45 if (g_strv_length(fields
) == 6) {
46 e
->path
= g_strdup(g_strchug(fields
[5]));
48 map_info
= g_slist_prepend(map_info
, e
);
57 /* ensure the map data is in the same order we collected it */
58 return g_slist_reverse(map_info
);
65 * Free a list of MapInfo structures.
67 static void free_info(gpointer data
)
69 MapInfo
*e
= (MapInfo
*) data
;
75 void free_self_maps(GSList
*info
)
77 g_slist_free_full(info
, &free_info
);