|
@@ -104,46 +104,27 @@ void *memalign(size_t alignment, size_t size) {
|
|
|
}
|
|
|
} else { /* A big block has to be created */
|
|
|
|
|
|
- memptr = (void *)create_raw_block(size + extra_size +
|
|
|
- sizeof(raw_block_header_t), BIGBLOCK);
|
|
|
+ memptr = (void *)create_raw_block(size + extra_size, BIGBLOCK);
|
|
|
|
|
|
if(memptr != NULL) {
|
|
|
|
|
|
+#ifdef REQUEST_SIZE_INFO
|
|
|
+ raw_block_header_t *bb_header = (raw_block_header_t *)memptr;
|
|
|
+#endif /* REQUEST_SIZE_INFO */
|
|
|
memptr = (void *)((uintptr_t) memptr + sizeof(raw_block_header_t));
|
|
|
|
|
|
/* Check if alignment is needed */
|
|
|
if(((uintptr_t) memptr) % alignment != 0) {
|
|
|
size_t padding = (- (size_t) memptr) & (alignment - 1);
|
|
|
- while(padding < sizeof(raw_block_header_t)) {
|
|
|
- padding += alignment;
|
|
|
- }
|
|
|
-
|
|
|
- /* Sometimes a deadlock is observed unless the old mutex is
|
|
|
- * destroyed. */
|
|
|
- DESTROY_RAW_BLOCK_LOCK(((raw_block_header_t *) memptr));
|
|
|
-
|
|
|
- /* Copy the raw block's header to the new location */
|
|
|
- memcpy((void *)((uintptr_t) memptr -
|
|
|
- sizeof(raw_block_header_t) + padding),
|
|
|
- (void *)((uintptr_t) memptr -
|
|
|
- sizeof(raw_block_header_t)),
|
|
|
- sizeof(raw_block_header_t)
|
|
|
- );
|
|
|
|
|
|
/* Update *memptr */
|
|
|
memptr = (void *)((uintptr_t) memptr + padding);
|
|
|
|
|
|
- /* Update big block's size and requested size */
|
|
|
- raw_block_header_t *aligned_header =
|
|
|
- (raw_block_header_t *)((uintptr_t) memptr -
|
|
|
- sizeof(raw_block_header_t));
|
|
|
- INIT_RAW_BLOCK_LOCK(aligned_header);
|
|
|
- LOCK_RAW_BLOCK(aligned_header);
|
|
|
- aligned_header->size -= padding;
|
|
|
#ifdef REQUEST_SIZE_INFO
|
|
|
+ LOCK_RAW_BLOCK(aligned_header);
|
|
|
aligned_header->requested_size = size;
|
|
|
-#endif /* REQUEST_SIZE_INFO */
|
|
|
UNLOCK_RAW_BLOCK(aligned_header);
|
|
|
+#endif /* REQUEST_SIZE_INFO */
|
|
|
}
|
|
|
|
|
|
#ifdef WITH_DEBUG
|