Changes in uspace/app/tester/mm/common.c [5a6cc679:a35b458] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/mm/common.c
r5a6cc679 ra35b458 72 72 { 73 73 link_t *link; 74 74 75 75 while ((link = list_first(&mem_blocks)) != NULL) { 76 76 mem_block_t *block = list_get_instance(link, mem_block_t, link); 77 77 free_block(block); 78 78 } 79 79 80 80 while ((link = list_first(&mem_areas)) != NULL) { 81 81 mem_area_t *area = list_get_instance(link, mem_area_t, link); … … 89 89 uint8_t *mbeg = (uint8_t *) block; 90 90 uint8_t *mend = (uint8_t *) block + sizeof(mem_block_t); 91 91 92 92 /* Entry block memory <bbeg, bend) */ 93 93 uint8_t *bbeg = (uint8_t *) block->addr; 94 94 uint8_t *bend = (uint8_t *) block->addr + block->size; 95 95 96 96 /* Data block <dbeg, dend) */ 97 97 uint8_t *dbeg = (uint8_t *) addr; 98 98 uint8_t *dend = (uint8_t *) addr + size; 99 99 100 100 /* Check for overlaps */ 101 101 if (((mbeg >= dbeg) && (mbeg < dend)) || … … 104 104 ((bend > dbeg) && (bend <= dend))) 105 105 return true; 106 106 107 107 return false; 108 108 } … … 122 122 { 123 123 bool fnd = false; 124 124 125 125 list_foreach(mem_blocks, link, mem_block_t, block) { 126 126 if (overlap_match(block, addr, size)) { … … 129 129 } 130 130 } 131 131 132 132 return fnd; 133 133 } … … 160 160 { 161 161 void *data; 162 162 163 163 /* Allocate the chunk of memory */ 164 164 data = malloc(size); … … 166 166 if (data == NULL) 167 167 return NULL; 168 168 169 169 /* Check for overlaps with other chunks */ 170 170 if (test_overlap(data, size)) { … … 174 174 error_flag = true; 175 175 } 176 176 177 177 return data; 178 178 } … … 197 197 if (mem_allocated >= MAX_ALLOC) 198 198 return NULL; 199 199 200 200 /* Allocate the block holder */ 201 201 mem_block_t *block = … … 203 203 if (block == NULL) 204 204 return NULL; 205 205 206 206 link_initialize(&block->link); 207 207 208 208 /* Allocate the block memory */ 209 209 block->addr = checked_malloc(size); … … 213 213 return NULL; 214 214 } 215 215 216 216 block->size = size; 217 217 218 218 /* Register the allocated block */ 219 219 list_append(&block->link, &mem_blocks); 220 220 mem_allocated += size + sizeof(mem_block_t); 221 221 mem_blocks_count++; 222 222 223 223 return block; 224 224 } … … 238 238 mem_allocated -= block->size + sizeof(mem_block_t); 239 239 mem_blocks_count--; 240 240 241 241 /* Free the memory */ 242 242 free(block->addr); … … 272 272 pos < end; pos++) 273 273 *pos = block_expected_value(block, pos); 274 274 275 275 check_consistency("fill_block"); 276 276 } … … 308 308 if (mem_blocks_count == 0) 309 309 return NULL; 310 310 311 311 unsigned long idx = rand() % mem_blocks_count; 312 312 link_t *entry = list_nth(&mem_blocks, idx); 313 313 314 314 if (entry == NULL) { 315 315 TPRINTF("\nError: Corrupted list of allocated memory blocks.\n"); … … 317 317 error_flag = true; 318 318 } 319 319 320 320 return list_get_instance(entry, mem_block_t, link); 321 321 } … … 337 337 if (area == NULL) 338 338 return NULL; 339 339 340 340 link_initialize(&area->link); 341 341 342 342 area->addr = as_area_create(AS_AREA_ANY, size, 343 343 AS_AREA_WRITE | AS_AREA_READ | AS_AREA_CACHEABLE, … … 348 348 return NULL; 349 349 } 350 350 351 351 area->size = size; 352 352 353 353 /* Register the allocated area */ 354 354 list_append(&area->link, &mem_areas); 355 355 356 356 return area; 357 357 } … … 369 369 /* Unregister the area */ 370 370 list_remove(&area->link); 371 371 372 372 /* Free the memory */ 373 373 errno_t ret = as_area_destroy(area->addr); 374 374 if (ret != EOK) 375 375 error_flag = true; 376 376 377 377 free(area); 378 378 check_consistency("unmap_area"); … … 405 405 pos < end; pos++) 406 406 *pos = area_expected_value(area, pos); 407 407 408 408 check_consistency("fill_area"); 409 409 }
Note:
See TracChangeset
for help on using the changeset viewer.