The topic can be abstracted out of the question is: Two front open after closed interval Rangea and Rangeb, how to determine whether these two intervals overlap. This problem is very important in the kernel, the division of virtual address space needs it, perf in the construction of Map_group also need it, the following directly gives the solution to the problem:
Find out the case that does not overlap, the other cases are overlapping, perf in the Mmap__overlay function is resolved:
int Map__overlap (struct map *l, struct map *r)
{
if (L->start > R->start) {//First swap, let L point to the left, that is, the map with the smaller starting address "gestures with one axis"
struct map *t = l;
L = r;
R = t;
}
if (L->end > R->start)//Then as long as the end address of the map on the left exceeds the start address of the map on the right, it must overlap
return 1;
return 0;
}
Now that the first problem is solved, the second problem is resolved as follows: Map_groups__fixup_overlappings function parsing:
function prototypes: int map_groups__fixup_overlappings (struct map_groups *mg, struct map *map, FILE *FP)
Parameter: MG, store the registered map, use two tree storage;
Map, the map to be inserted, to adjust the map already registered in MG according to the map;
FP, error output ground.
The function name describes the function: based on overlapping information, the existing map in the map_groups is modified. The principle of correction is to catch up. What do you mean? That is, when the map and MG in a map_registered memory domain conflict, the map at a higher priority, mg_registered to make adjustments.
Two areas overlap is nothing more than the following cases, each of which describes how to adjust:
Perf the judgment of whether the two maps overlap, and the function map_groups__fixup_overlappings code logic