Determine the segment belonging to a pointer or NULL if it is not in a valid segment.
| 325 | |
| 326 | // Determine the segment belonging to a pointer or NULL if it is not in a valid segment. |
| 327 | static mi_segment_t* _mi_segment_of(const void* p) { |
| 328 | if (p == NULL) return NULL; |
| 329 | mi_segment_t* segment = _mi_ptr_segment(p); |
| 330 | mi_assert_internal(segment != NULL); |
| 331 | size_t bitidx; |
| 332 | size_t index = mi_segment_map_index_of(segment, &bitidx); |
| 333 | // fast path: for any pointer to valid small/medium/large object or first MI_SEGMENT_SIZE in huge |
| 334 | const uintptr_t mask = mi_atomic_load_relaxed(&mi_segment_map[index]); |
| 335 | if mi_likely((mask & ((uintptr_t)1 << bitidx)) != 0) { |
| 336 | return segment; // yes, allocated by us |
| 337 | } |
| 338 | if (index==MI_SEGMENT_MAP_WSIZE) return NULL; |
| 339 | |
| 340 | // TODO: maintain max/min allocated range for efficiency for more efficient rejection of invalid pointers? |
no test coverage detected