@@ -88,19 +88,9 @@ privileged optimizespeed struct Map *__maps_floor(const char *addr) {
88
88
return 0 ;
89
89
}
90
90
91
- struct Map * __maps_ceil (const char * addr ) {
92
- struct Tree * node ;
93
- if ((node = tree_ceil (__maps .maps , addr , __maps_search )))
94
- return MAP_TREE_CONTAINER (node );
95
- return 0 ;
96
- }
97
-
98
91
static bool __maps_overlaps (const char * addr , size_t size , int pagesz ) {
99
- ASSERT (!((uintptr_t )addr & (getgransize () - 1 )) && size );
100
- struct Map * map , * ceil , * floor ;
101
- floor = __maps_floor (addr );
102
- ceil = __maps_ceil (addr + size );
103
- for (map = floor ; map && map != ceil ; map = __maps_next (map ))
92
+ struct Map * map , * floor = __maps_floor (addr );
93
+ for (map = floor ; map && map -> addr <= addr + size ; map = __maps_next (map ))
104
94
if (MAX (addr , map -> addr ) <
105
95
MIN (addr + PGUP (size ), map -> addr + PGUP (map -> size )))
106
96
return true;
@@ -138,11 +128,9 @@ static int __muntrack(char *addr, size_t size, int pagesz,
138
128
int rc = 0 ;
139
129
struct Map * map ;
140
130
struct Map * next ;
141
- struct Map * ceil ;
142
131
struct Map * floor ;
143
132
floor = __maps_floor (addr );
144
- ceil = __maps_ceil (addr + size );
145
- for (map = floor ; map && map != ceil ; map = next ) {
133
+ for (map = floor ; map && map -> addr <= addr + size ; map = next ) {
146
134
next = __maps_next (map );
147
135
char * map_addr = map -> addr ;
148
136
size_t map_size = map -> size ;
@@ -252,10 +240,10 @@ static void __maps_insert(struct Map *map) {
252
240
int prot = map -> prot & ~(MAP_FIXED | MAP_FIXED_NOREPLACE );
253
241
int flags = map -> flags ;
254
242
bool coalesced = false;
255
- struct Map * floor , * ceil , * other , * last = 0 ;
256
- floor = __maps_floor (map -> addr );
257
- ceil = __maps_ceil ( map -> addr + map -> size ) ;
258
- for ( other = floor ; other ; last = other , other = __maps_next (other )) {
243
+ struct Map * floor , * other , * last = 0 ;
244
+ for ( other = floor = __maps_floor (map -> addr );
245
+ other && other -> addr <= map -> addr + map -> size ;
246
+ last = other , other = __maps_next (other )) {
259
247
if (prot == other -> prot && flags == other -> flags ) {
260
248
if (!coalesced ) {
261
249
if (map -> addr == other -> addr + other -> size ) {
@@ -282,8 +270,6 @@ static void __maps_insert(struct Map *map) {
282
270
__maps_check ();
283
271
}
284
272
}
285
- if (other == ceil )
286
- break ;
287
273
}
288
274
if (coalesced )
289
275
return ;
@@ -683,10 +669,16 @@ static void *__mremap(char *old_addr, size_t old_size, size_t new_size,
683
669
int pagesz = getpagesize ();
684
670
int gransz = getgransize ();
685
671
686
- // demand kernel support
672
+ // kernel support
687
673
if (!IsLinux () && !IsNetbsd ())
688
674
return (void * )enosys ();
689
675
676
+ // it is not needed
677
+ if (new_size <= old_size )
678
+ if (!(flags & MREMAP_FIXED ))
679
+ if (flags & MREMAP_MAYMOVE )
680
+ flags &= ~MREMAP_MAYMOVE ;
681
+
690
682
// we support these flags
691
683
if (flags & ~(MREMAP_MAYMOVE | MREMAP_FIXED ))
692
684
return (void * )einval ();
0 commit comments