| 333 | |
| 334 | |
| 335 | static size_t mi_segment_calculate_slices(size_t required, size_t* pre_size, size_t* info_slices) { |
| 336 | size_t page_size = _mi_os_page_size(); |
| 337 | size_t isize = _mi_align_up(sizeof(mi_segment_t), page_size); |
| 338 | size_t guardsize = 0; |
| 339 | |
| 340 | if (MI_SECURE>0) { |
| 341 | // in secure mode, we set up a protected page in between the segment info |
| 342 | // and the page data (and one at the end of the segment) |
| 343 | guardsize = page_size; |
| 344 | if (required > 0) { |
| 345 | required = _mi_align_up(required, MI_SEGMENT_SLICE_SIZE) + page_size; |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | if (pre_size != NULL) *pre_size = isize; |
| 350 | isize = _mi_align_up(isize + guardsize, MI_SEGMENT_SLICE_SIZE); |
| 351 | if (info_slices != NULL) *info_slices = isize / MI_SEGMENT_SLICE_SIZE; |
| 352 | size_t segment_size = (required==0 ? MI_SEGMENT_SIZE : _mi_align_up( required + isize + guardsize, MI_SEGMENT_SLICE_SIZE) ); |
| 353 | mi_assert_internal(segment_size % MI_SEGMENT_SLICE_SIZE == 0); |
| 354 | return (segment_size / MI_SEGMENT_SLICE_SIZE); |
| 355 | } |
| 356 | |
| 357 | |
| 358 | /* ---------------------------------------------------------------------------- |
no test coverage detected