Changeset View
Changeset View
Standalone View
Standalone View
sys/vm/vm_map.c
| Show First 20 Lines • Show All 1,975 Lines • ▼ Show 20 Lines | |||||
| static const int aslr_pages_rnd_32[2] = {0x100, 0x4}; | static const int aslr_pages_rnd_32[2] = {0x100, 0x4}; | ||||
| static int cluster_anon = 1; | static int cluster_anon = 1; | ||||
| SYSCTL_INT(_vm, OID_AUTO, cluster_anon, CTLFLAG_RW, | SYSCTL_INT(_vm, OID_AUTO, cluster_anon, CTLFLAG_RW, | ||||
| &cluster_anon, 0, | &cluster_anon, 0, | ||||
| "Cluster anonymous mappings: 0 = no, 1 = yes if no hint, 2 = always"); | "Cluster anonymous mappings: 0 = no, 1 = yes if no hint, 2 = always"); | ||||
| static bool | static bool | ||||
| clustering_anon_allowed(vm_offset_t addr) | clustering_anon_allowed(vm_offset_t addr, int cow) | ||||
| { | { | ||||
| switch (cluster_anon) { | switch (cluster_anon) { | ||||
| case 0: | case 0: | ||||
| return (false); | return (false); | ||||
| case 1: | case 1: | ||||
| return (addr == 0); | return (addr == 0 || (cow & MAP_NO_HINT) != 0); | ||||
| case 2: | case 2: | ||||
| default: | default: | ||||
| return (true); | return (true); | ||||
| } | } | ||||
| } | } | ||||
| static long aslr_restarts; | static long aslr_restarts; | ||||
| SYSCTL_LONG(_vm, OID_AUTO, aslr_restarts, CTLFLAG_RD, | SYSCTL_LONG(_vm, OID_AUTO, aslr_restarts, CTLFLAG_RD, | ||||
| ▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Lines | if (find_space == VMFS_OPTIMAL_SPACE && (object == NULL || | ||||
| (object->flags & OBJ_COLORED) == 0)) | (object->flags & OBJ_COLORED) == 0)) | ||||
| find_space = VMFS_ANY_SPACE; | find_space = VMFS_ANY_SPACE; | ||||
| if (find_space >> 8 != 0) { | if (find_space >> 8 != 0) { | ||||
| KASSERT((find_space & 0xff) == 0, ("bad VMFS flags")); | KASSERT((find_space & 0xff) == 0, ("bad VMFS flags")); | ||||
| alignment = (vm_offset_t)1 << (find_space >> 8); | alignment = (vm_offset_t)1 << (find_space >> 8); | ||||
| } else | } else | ||||
| alignment = 0; | alignment = 0; | ||||
| en_aslr = (map->flags & MAP_ASLR) != 0; | en_aslr = (map->flags & MAP_ASLR) != 0; | ||||
| update_anon = cluster = clustering_anon_allowed(*addr) && | update_anon = cluster = clustering_anon_allowed(*addr, cow) && | ||||
| (map->flags & MAP_IS_SUB_MAP) == 0 && max_addr == 0 && | (map->flags & MAP_IS_SUB_MAP) == 0 && max_addr == 0 && | ||||
| find_space != VMFS_NO_SPACE && object == NULL && | find_space != VMFS_NO_SPACE && object == NULL && | ||||
| (cow & (MAP_INHERIT_SHARE | MAP_STACK_GROWS_UP | | (cow & (MAP_INHERIT_SHARE | MAP_STACK_GROWS_UP | | ||||
| MAP_STACK_GROWS_DOWN)) == 0 && prot != PROT_NONE; | MAP_STACK_GROWS_DOWN)) == 0 && prot != PROT_NONE; | ||||
| curr_min_addr = min_addr = *addr; | curr_min_addr = min_addr = *addr; | ||||
| if (en_aslr && min_addr == 0 && !cluster && | if (en_aslr && min_addr == 0 && !cluster && | ||||
| find_space != VMFS_NO_SPACE && | find_space != VMFS_NO_SPACE && | ||||
| (map->flags & MAP_ASLR_IGNSTART) != 0) | (map->flags & MAP_ASLR_IGNSTART) != 0) | ||||
| ▲ Show 20 Lines • Show All 127 Lines • ▼ Show 20 Lines | vm_map_find_min(vm_map_t map, vm_object_t object, vm_ooffset_t offset, | ||||
| vm_offset_t *addr, vm_size_t length, vm_offset_t min_addr, | vm_offset_t *addr, vm_size_t length, vm_offset_t min_addr, | ||||
| vm_offset_t max_addr, int find_space, vm_prot_t prot, vm_prot_t max, | vm_offset_t max_addr, int find_space, vm_prot_t prot, vm_prot_t max, | ||||
| int cow) | int cow) | ||||
| { | { | ||||
| vm_offset_t hint; | vm_offset_t hint; | ||||
| int rv; | int rv; | ||||
| hint = *addr; | hint = *addr; | ||||
| if (hint == 0) | |||||
| cow |= MAP_NO_HINT; | |||||
| if (hint < min_addr) | |||||
| *addr = hint = min_addr; | |||||
| for (;;) { | for (;;) { | ||||
| rv = vm_map_find(map, object, offset, addr, length, max_addr, | rv = vm_map_find(map, object, offset, addr, length, max_addr, | ||||
| find_space, prot, max, cow); | find_space, prot, max, cow); | ||||
| if (rv == KERN_SUCCESS || min_addr >= hint) | if (rv == KERN_SUCCESS || min_addr >= hint) | ||||
| return (rv); | return (rv); | ||||
| *addr = hint = min_addr; | *addr = hint = min_addr; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 3,101 Lines • Show Last 20 Lines | |||||