| 107 | } |
| 108 | |
| 109 | void * |
| 110 | extent_alloc_dss(tsdn_t *tsdn, arena_t *arena, void *new_addr, size_t size, |
| 111 | size_t alignment, bool *zero, bool *commit) { |
| 112 | extent_t *gap; |
| 113 | |
| 114 | cassert(have_dss); |
| 115 | assert(size > 0); |
| 116 | assert(alignment > 0); |
| 117 | |
| 118 | /* |
| 119 | * sbrk() uses a signed increment argument, so take care not to |
| 120 | * interpret a large allocation request as a negative increment. |
| 121 | */ |
| 122 | if ((intptr_t)size < 0) { |
| 123 | return NULL; |
| 124 | } |
| 125 | |
| 126 | gap = extent_alloc(tsdn, arena); |
| 127 | if (gap == NULL) { |
| 128 | return NULL; |
| 129 | } |
| 130 | |
| 131 | extent_dss_extending_start(); |
| 132 | if (!atomic_load_b(&dss_exhausted, ATOMIC_ACQUIRE)) { |
| 133 | /* |
| 134 | * The loop is necessary to recover from races with other |
| 135 | * threads that are using the DSS for something other than |
| 136 | * malloc. |
| 137 | */ |
| 138 | while (true) { |
| 139 | void *max_cur = extent_dss_max_update(new_addr); |
| 140 | if (max_cur == NULL) { |
| 141 | goto label_oom; |
| 142 | } |
| 143 | |
| 144 | /* |
| 145 | * Compute how much page-aligned gap space (if any) is |
| 146 | * necessary to satisfy alignment. This space can be |
| 147 | * recycled for later use. |
| 148 | */ |
| 149 | void *gap_addr_page = (void *)(PAGE_CEILING( |
| 150 | (uintptr_t)max_cur)); |
| 151 | void *ret = (void *)ALIGNMENT_CEILING( |
| 152 | (uintptr_t)gap_addr_page, alignment); |
| 153 | size_t gap_size_page = (uintptr_t)ret - |
| 154 | (uintptr_t)gap_addr_page; |
| 155 | if (gap_size_page != 0) { |
| 156 | extent_init(gap, arena, gap_addr_page, |
| 157 | gap_size_page, false, NSIZES, |
| 158 | arena_extent_sn_next(arena), |
| 159 | extent_state_active, false, true, true); |
| 160 | } |
| 161 | /* |
| 162 | * Compute the address just past the end of the desired |
| 163 | * allocation space. |
| 164 | */ |
| 165 | void *dss_next = (void *)((uintptr_t)ret + size); |
| 166 | if ((uintptr_t)ret < (uintptr_t)max_cur || |
no test coverage detected