| 459 | } |
| 460 | |
| 461 | void *realloc(void *ptr, size_t size) { |
| 462 | struct call *c; |
| 463 | struct memblock *b; |
| 464 | struct thread_info *ti; |
| 465 | size_t was_size = 0; |
| 466 | |
| 467 | /* record new place we allocated from */ |
| 468 | ti = get_thread_info(); |
| 469 | |
| 470 | init(); |
| 471 | if (in_init) |
| 472 | return dl_realloc(ptr, size); |
| 473 | |
| 474 | |
| 475 | /* this part is identical to free */ |
| 476 | LOCK(&lk) { |
| 477 | if (ptr != NULL) { |
| 478 | /* get back to memblock */ |
| 479 | b = (struct memblock *) ((intptr_t) ptr - offsetof(struct memblock, mem)); |
| 480 | c = b->place_allocated; |
| 481 | c->total_allocated -= b->blocksize; |
| 482 | listc_rfl(&c->blocks, b); |
| 483 | listc_rfl(&blocks, b); |
| 484 | listc_rfl(&b->ti->blocks, b); |
| 485 | was_size = b->blocksize; |
| 486 | } |
| 487 | else |
| 488 | b = NULL; |
| 489 | |
| 490 | /* do the real realloc (include the memblock portion). done under |
| 491 | lock to prevent funny math */ |
| 492 | b = dl_realloc(b, offsetof(struct memblock, mem) + size); |
| 493 | |
| 494 | /* readjust block size */ |
| 495 | b->blocksize = size; |
| 496 | |
| 497 | c = get_call(); |
| 498 | b->place_allocated = c; |
| 499 | c->total_allocated += size; |
| 500 | b->ti = ti; |
| 501 | listc_abl(&c->blocks, b); |
| 502 | listc_abl(&blocks, b); |
| 503 | listc_abl(&ti->blocks, b); |
| 504 | } UNLOCK(&lk); |
| 505 | |
| 506 | return b->mem; |
| 507 | } |
| 508 | |
| 509 | char *strdup(const char *s) { |
| 510 | int sz; |