void commpage_update_mach_approximate_time(uint64_t abstime) { #ifdef CONFIG_MACH_APPROXIMATE_TIME uint64_t saved_data; char *cp; cp = commPagePtr32; if ( cp ) { cp += (_COMM_PAGE_APPROX_TIME - _COMM_PAGE32_BASE_ADDRESS); saved_data = *(uint64_t *)cp; if (saved_data < abstime) { /* ignoring the success/fail return value assuming that * if the value has been updated since we last read it, * "someone" has a newer timestamp than us and ours is * now invalid. */ OSCompareAndSwap64(saved_data, abstime, (uint64_t *)cp); } } cp = commPagePtr64; if ( cp ) { cp += (_COMM_PAGE_APPROX_TIME - _COMM_PAGE32_START_ADDRESS); saved_data = *(uint64_t *)cp; if (saved_data < abstime) { /* ignoring the success/fail return value assuming that * if the value has been updated since we last read it, * "someone" has a newer timestamp than us and ours is * now invalid. */ OSCompareAndSwap64(saved_data, abstime, (uint64_t *)cp); } } #else #pragma unused (abstime) #endif }
slice_alloc(slice_t *slice, sa_size_t alloc_size) #endif /* !DEBUG */ { if (slice->sa->flags & SMALL_ALLOC) { small_allocatable_row_t *row = slice_small_get_row(slice); if (row) { slice->alloc_count++; } return (void*)(row); } else { #ifdef SLICE_CHECK_THREADS Boolean res = OSCompareAndSwap64(0, 1, &slice->semaphore); if (!res) { REPORT0("slice_alloc - thread already present\n"); } #endif /* SLICE_CHECK_THREADS */ allocatable_row_t *row = slice_get_row(slice); if (row) { #ifdef SLICE_CHECK_ROW_HEADERS if (row->prefix != ROW_HEADER_GUARD || row->suffix != ROW_HEADER_GUARD) { REPORT0("slice_alloc - detected corrupted row " "header\n"); } #endif /* SLICE_CHECK_ROW_HEADERS */ #ifdef SLICE_CHECK_FREE_SIZE row->allocated_bytes = alloc_size; #endif /* SLICE_CHECK_FREE_SIZE */ #ifdef SLICE_CHECK_WRITE_AFTER_FREE if (!slice_row_is_poisoned(slice, row)) { REPORT("slice_alloc - write after free detected - sa " "size %llu\n", slice->sa->max_alloc_size); } #endif /* SLICE_CHECK_WRITE_AFTER_FREE */ #ifdef SLICE_CHECK_BOUNDS_WRITE slice_poison_row(slice, row); #endif /* SLICE_CHECK_BOUNDS_WRITE */ slice->alloc_count++; row++; } #ifdef SLICE_CHECK_THREADS if (res) { OSDecrementAtomic64(&slice->semaphore); } #endif /* SLICE_CHECK_THREADS */ return ((void *)row); } }
slice_free_row(slice_t *slice, allocatable_row_t *row, sa_size_t alloc_size) #endif /* !DEBUG */ { #ifdef SLICE_CHECK_THREADS Boolean res = OSCompareAndSwap64(0, 1, &slice->semaphore); if (!res) { REPORT0("slice_free_row - thread already present\n"); } #endif /* SLICE_CHECK_THREADS */ slice->alloc_count--; #ifdef SLICE_CHECK_ROW_HEADERS if (row->prefix != ROW_HEADER_GUARD || row->suffix != ROW_HEADER_GUARD) { REPORT0("slice_free_row - detected corrupted row header\n"); } #endif /* SLICE_CHECK_ROW_HEADERS */ #ifdef SLICE_CHECK_BOUNDS_WRITE if (!slice_row_is_within_bounds(slice, row)) { REPORT("slice_free_row - write outside of allocated memory " "detected alloc_size = %llu\n", row->allocated_bytes); } #endif /* SLICE_CHECK_BOUNDS_WRITE */ #ifdef SLICE_CHECK_FREE_SIZE if (row->allocated_bytes != alloc_size) { REPORT("slice_free_row - free of %llu bytes when allcated %llu", alloc_size, row->allocated_bytes); } row->allocated_bytes = 0; #endif /* SLICE_CHECK_FREE_SIZE */ #ifdef SLICE_CHECK_WRITE_AFTER_FREE slice_poison_row(slice, row); #endif /* SLICE_CHECK_WRITE_AFTER_FREE */ slice_insert_free_row(slice, row); #ifdef SLICE_CHECK_THREADS if (res) { OSDecrementAtomic64(&slice->semaphore); } #endif /* SLICE_CHECK_THREADS */ }