* vm_map_lookup_entry: [ internal use only ] * * Finds the map entry containing (or * immediately preceding) the specified address * in the given map; the entry is returned * in the "entry" parameter. The boolean * result indicates whether the address is * actually contained in the map. */
| 1558 | * actually contained in the map. |
| 1559 | */ |
| 1560 | boolean_t |
| 1561 | vm_map_lookup_entry( |
| 1562 | vm_map_t map, |
| 1563 | vm_offset_t address, |
| 1564 | vm_map_entry_t *entry) /* OUT */ |
| 1565 | { |
| 1566 | vm_map_entry_t cur, header, lbound, ubound; |
| 1567 | boolean_t locked; |
| 1568 | |
| 1569 | /* |
| 1570 | * If the map is empty, then the map entry immediately preceding |
| 1571 | * "address" is the map's header. |
| 1572 | */ |
| 1573 | header = &map->header; |
| 1574 | cur = map->root; |
| 1575 | if (cur == NULL) { |
| 1576 | *entry = header; |
| 1577 | return (FALSE); |
| 1578 | } |
| 1579 | if (address >= cur->start && cur->end > address) { |
| 1580 | *entry = cur; |
| 1581 | return (TRUE); |
| 1582 | } |
| 1583 | if ((locked = vm_map_locked(map)) || |
| 1584 | sx_try_upgrade(&map->lock)) { |
| 1585 | /* |
| 1586 | * Splay requires a write lock on the map. However, it only |
| 1587 | * restructures the binary search tree; it does not otherwise |
| 1588 | * change the map. Thus, the map's timestamp need not change |
| 1589 | * on a temporary upgrade. |
| 1590 | */ |
| 1591 | cur = vm_map_splay(map, address); |
| 1592 | if (!locked) { |
| 1593 | VM_MAP_UNLOCK_CONSISTENT(map); |
| 1594 | sx_downgrade(&map->lock); |
| 1595 | } |
| 1596 | |
| 1597 | /* |
| 1598 | * If "address" is contained within a map entry, the new root |
| 1599 | * is that map entry. Otherwise, the new root is a map entry |
| 1600 | * immediately before or after "address". |
| 1601 | */ |
| 1602 | if (address < cur->start) { |
| 1603 | *entry = header; |
| 1604 | return (FALSE); |
| 1605 | } |
| 1606 | *entry = cur; |
| 1607 | return (address < cur->end); |
| 1608 | } |
| 1609 | /* |
| 1610 | * Since the map is only locked for read access, perform a |
| 1611 | * standard binary search tree lookup for "address". |
| 1612 | */ |
| 1613 | lbound = ubound = header; |
| 1614 | for (;;) { |
| 1615 | if (address < cur->start) { |
| 1616 | ubound = cur; |
| 1617 | cur = cur->left; |
no test coverage detected