Changeset 1b3e854 in mainline
- Timestamp:
- 2011-05-21T14:29:50Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- faeb7cc
- Parents:
- 955f2a5
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/mm/common.c
r955f2a5 r1b3e854 135 135 } 136 136 137 static void check_consistency(const char *loc) 138 { 139 /* Check heap consistency */ 140 void *prob = heap_check(); 141 if (prob != NULL) { 142 TPRINTF("\nError: Heap inconsistency at %p in %s.\n", 143 prob, loc); 144 TSTACKTRACE(); 145 error_flag = true; 146 } 147 } 148 137 149 /** Checked malloc 138 150 * … … 153 165 /* Allocate the chunk of memory */ 154 166 data = malloc(size); 167 check_consistency("checked_malloc"); 155 168 if (data == NULL) 156 169 return NULL; … … 160 173 TPRINTF("\nError: Allocated block overlaps with another " 161 174 "previously allocated block.\n"); 175 TSTACKTRACE(); 162 176 error_flag = true; 163 177 } … … 198 212 if (block->addr == NULL) { 199 213 free(block); 214 check_consistency("alloc_block"); 200 215 return NULL; 201 216 } … … 228 243 /* Free the memory */ 229 244 free(block->addr); 245 check_consistency("free_block (a)"); 230 246 free(block); 247 check_consistency("free_block (b)"); 231 248 } 232 249 … … 257 274 pos < end; pos++) 258 275 *pos = block_expected_value(block, pos); 276 277 check_consistency("fill_block"); 259 278 } 260 279 … … 273 292 if (*pos != block_expected_value(block, pos)) { 274 293 TPRINTF("\nError: Corrupted content of a data block.\n"); 294 TSTACKTRACE(); 275 295 error_flag = true; 276 296 return; … … 296 316 if (entry == NULL) { 297 317 TPRINTF("\nError: Corrupted list of allocated memory blocks.\n"); 318 TSTACKTRACE(); 298 319 error_flag = true; 299 320 } … … 325 346 if (addr == NULL) { 326 347 free(area); 348 check_consistency("map_area (a)"); 327 349 return NULL; 328 350 } … … 331 353 if (area->addr == (void *) -1) { 332 354 free(area); 355 check_consistency("map_area (b)"); 333 356 return NULL; 334 357 } … … 361 384 362 385 free(area); 386 check_consistency("unmap_area"); 363 387 } 364 388 … … 389 413 pos < end; pos++) 390 414 *pos = area_expected_value(area, pos); 391 } 415 416 check_consistency("fill_area"); 417 } -
uspace/app/tester/mm/malloc3.c
r955f2a5 r1b3e854 236 236 mem_area_t *area = map_area(AREA_SIZE); 237 237 RETURN_IF_ERROR; 238 238 239 if (area != NULL) { 239 240 TPRINTF("*"); -
uspace/app/tester/tester.h
r955f2a5 r1b3e854 38 38 #include <sys/types.h> 39 39 #include <bool.h> 40 #include <stacktrace.h> 40 41 41 42 #define IPC_TEST_SERVICE 10240 … … 59 60 if (!test_quiet) { \ 60 61 fprintf(stderr, (format), ##__VA_ARGS__); \ 62 } \ 63 } while (0) 64 65 #define TSTACKTRACE() \ 66 do { \ 67 if (!test_quiet) { \ 68 stacktrace_print(); \ 61 69 } \ 62 70 } while (0) -
uspace/lib/c/generic/malloc.c
r955f2a5 r1b3e854 904 904 } 905 905 906 void *heap_check(void) 907 { 908 futex_down(&malloc_futex); 909 910 if (first_heap_area == NULL) { 911 futex_up(&malloc_futex); 912 return (void *) -1; 913 } 914 915 /* Walk all heap areas */ 916 for (heap_area_t *area = first_heap_area; area != NULL; 917 area = area->next) { 918 919 /* Check heap area consistency */ 920 if ((area->magic != HEAP_AREA_MAGIC) || 921 ((void *) area != area->start) || 922 (area->start >= area->end) || 923 (((uintptr_t) area->start % PAGE_SIZE) != 0) || 924 (((uintptr_t) area->end % PAGE_SIZE) != 0)) { 925 futex_up(&malloc_futex); 926 return (void *) area; 927 } 928 929 /* Walk all heap blocks */ 930 for (heap_block_head_t *head = (heap_block_head_t *) 931 AREA_FIRST_BLOCK_HEAD(area); (void *) head < area->end; 932 head = (heap_block_head_t *) (((void *) head) + head->size)) { 933 934 /* Check heap block consistency */ 935 if (head->magic != HEAP_BLOCK_HEAD_MAGIC) { 936 futex_up(&malloc_futex); 937 return (void *) head; 938 } 939 940 heap_block_foot_t *foot = BLOCK_FOOT(head); 941 942 if ((foot->magic != HEAP_BLOCK_FOOT_MAGIC) || 943 (head->size != foot->size)) { 944 futex_up(&malloc_futex); 945 return (void *) foot; 946 } 947 } 948 } 949 950 futex_up(&malloc_futex); 951 952 return NULL; 953 } 954 906 955 /** @} 907 956 */ -
uspace/lib/c/include/malloc.h
r955f2a5 r1b3e854 46 46 extern void *realloc(const void *addr, const size_t size); 47 47 extern void free(const void *addr); 48 extern void *heap_check(void); 48 49 49 50 #endif
Note:
See TracChangeset
for help on using the changeset viewer.