Changeset 94795812 in mainline for kernel/generic/src/mm/as.c
- Timestamp:
- 2012-11-05T21:52:35Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2d53cfc, 33c2952, efdfebc
- Parents:
- 0941e9ae
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/mm/as.c
r0941e9ae r94795812 299 299 ASSERT((addr % PAGE_SIZE) == 0); 300 300 ASSERT(mutex_locked(&as->lock)); 301 ASSERT(!overflows_add(addr, P2SZ(count))); 301 302 /* 303 * If the addition of the supposed area address and size overflows, 304 * report conflict. 305 */ 306 if (overflows_into_positive(addr, P2SZ(count))) 307 return false; 302 308 303 309 /* … … 331 337 mutex_lock(&area->lock); 332 338 333 /* If at least one of the two areas are protected 339 /* 340 * If at least one of the two areas are protected 334 341 * by the AS_AREA_GUARD flag then we must be sure 335 342 * that they are separated by at least one unmapped … … 339 346 (area->flags & AS_AREA_GUARD)) ? 1 : 0; 340 347 348 /* 349 * The area comes from the left neighbour node, which 350 * means that there already are some areas in the leaf 351 * node, which in turn means that adding gp is safe and 352 * will not cause an integer overflow. 353 */ 341 354 if (overlaps(addr, P2SZ(count), area->base, 342 355 P2SZ(area->pages + gp))) { … … 354 367 355 368 if (area != avoid) { 369 int gp; 370 356 371 mutex_lock(&area->lock); 357 372 358 int const gp = (guarded || 359 (area->flags & AS_AREA_GUARD)) ? 1 : 0; 373 gp = (guarded || (area->flags & AS_AREA_GUARD)) ? 1 : 0; 374 if (gp && overflows(addr, P2SZ(count))) { 375 /* 376 * Guard page not needed if the supposed area 377 * is adjacent to the end of the address space. 378 * We already know that the following test is 379 * going to fail... 380 */ 381 gp--; 382 } 360 383 361 384 if (overlaps(addr, P2SZ(count + gp), area->base, … … 373 396 for (i = 0; i < leaf->keys; i++) { 374 397 area = (as_area_t *) leaf->value[i]; 398 int agp; 399 int gp; 375 400 376 401 if (area == avoid) … … 379 404 mutex_lock(&area->lock); 380 405 381 int const gp = (guarded || 382 (area->flags & AS_AREA_GUARD)) ? 1 : 0; 406 gp = (guarded || (area->flags & AS_AREA_GUARD)) ? 1 : 0; 407 agp = gp; 408 409 /* 410 * Sanitize the two possible unsigned integer overflows. 411 */ 412 if (gp && overflows(addr, P2SZ(count))) 413 gp--; 414 if (agp && overflows(area->base, P2SZ(area->pages))) 415 agp--; 383 416 384 417 if (overlaps(addr, P2SZ(count + gp), area->base, 385 P2SZ(area->pages + gp))) {418 P2SZ(area->pages + agp))) { 386 419 mutex_unlock(&area->lock); 387 420 return false; … … 533 566 } 534 567 535 if (overflows_ add(*base, size))568 if (overflows_into_positive(*base, size)) 536 569 return NULL; 537 570 … … 816 849 */ 817 850 818 if (overflows_ add(address, P2SZ(pages)))851 if (overflows_into_positive(address, P2SZ(pages))) 819 852 return EINVAL; 820 853
Note:
See TracChangeset
for help on using the changeset viewer.