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

Function get_proc_maps

ccan/ccan/ptr_valid/ptr_valid.c:82–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

ptr_valid_batch_startFunction · 0.85

Calls 3

skip_lineFunction · 0.85
add_mapFunction · 0.85
grabFunction · 0.70

Tested by

no test coverage detected