MCPcopy Create free account
hub / github.com/ElementsProject/lightning / get_proc_maps

Function get_proc_maps

ccan/ccan/ptr_valid/ptr_valid.c:77–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75}
76
77static struct ptr_valid_map *get_proc_maps(unsigned int *num)
78{
79 char *buf, *p;
80 struct ptr_valid_map *map;
81 unsigned int max = 16;
82
83 buf = grab("/proc/self/maps");
84 if (!buf) {
85 *num = 0;
86 return NULL;
87 }
88
89 map = malloc(sizeof(*map) * max);
90 if (!map)
91 goto free_buf;
92
93 *num = 0;
94 for (p = buf; p && *p; p = skip_line(p)) {
95 unsigned long start, end;
96 char *endp;
97
98 /* Expect '<start-in-hex>-<end-in-hex> rw... */
99 start = strtoul(p, &endp, 16);
100 if (*endp != '-')
101 goto malformed;
102 end = strtoul(endp+1, &endp, 16);
103 if (*endp != ' ')
104 goto malformed;
105
106 endp++;
107 if (endp[0] != 'r' && endp[0] != '-')
108 goto malformed;
109 if (endp[1] != 'w' && endp[1] != '-')
110 goto malformed;
111
112 /* We only add readable mappings. */
113 if (endp[0] == 'r') {
114 map = add_map(map, num, &max, start, end,
115 endp[1] == 'w');
116 if (!map)
117 goto free_buf;
118 }
119 }
120
121 free(buf);
122 return map;
123
124
125malformed:
126 free(map);
127free_buf:
128 free(buf);
129 *num = 0;
130 return NULL;
131}
132#else
133static struct ptr_valid_map *get_proc_maps(unsigned int *num)
134{

Callers 1

ptr_valid_batch_startFunction · 0.85

Calls 3

grabFunction · 0.85
skip_lineFunction · 0.85
add_mapFunction · 0.85

Tested by

no test coverage detected