/* Caller must ensure that we know tc_idx is valid and there's
available chunks to remove. */
static void *
tcache_get (size_t tc_idx)
{
tcache_entry *e = tcache->entries[tc_idx];
assert (tc_idx < TCACHE_MAX_BINS);
assert (tcache->entries[tc_idx] > 0);
tcache->entries[tc_idx] = e->next;
--(tcache->counts[tc_idx]);
return (void *) e;
}
인자로 들어온 tc_idx 인덱스에 있는 freed chunk를 반환하는 함수이다
get address pointer
tcache_entry *e = tcache->entries[tc_idx];
포인터 e에 tc_idx에 해당하는 포인터를 저장한다
check
assert (tc_idx < TCACHE_MAX_BINS);
assert (tcache->entries[tc_idx] > 0);
malloc에서 tcache_get를 호출하기 위해 검사한 것을 재검사한다
- tc_idx가 tcache 범위 내에 있는지
- 해당 인덱스에 freed chunk가 존재하는지
return chunk and set
tcache->entries[tc_idx] = e->next;
--(tcache->counts[tc_idx]);
return (void *) e;
재사용할게 될 cache에 대한 갱신을 하게된다
엔트리를 다음 엔트리로 변경하고 count를 1 감소시킨 뒤 포인터 e를 반환한다
'Heap analysis > glibc 2.26' 카테고리의 다른 글
(glibc 2.26) _int_free (0) | 2022.05.02 |
---|---|
(glibc 2.26) _int_malloc (0) | 2022.05.01 |
(glibc 2.26) tcache_put (0) | 2022.05.01 |
(glibc 2.26) tcache_init (0) | 2022.05.01 |
(glibc 2.26) malloc (0) | 2022.05.01 |