전체 글 (187) 썸네일형 리스트형 (glibc 2.26) _int_free (glibc 2.26) _int_malloc글과 동일하게 (glibc 2.23) _int_free글을 이해한 상태라고 가정하고 정리할 것이다 전체 코드는 아래와 같다 더보기 static void _int_free (mstate av, mchunkptr p, int have_lock) { INTERNAL_SIZE_T size; /* its size */ mfastbinptr *fb; /* associated fastbin */ mchunkptr nextchunk; /* next contiguous chunk */ INTERNAL_SIZE_T nextsize; /* its size */ int nextinuse; /* true if nextchunk is used */ INTERNAL_SIZE_T prevs.. (glibc 2.26) _int_malloc glibc 2.23버전에서 malloc의 동작과정을 살펴보았기 때문에 해당 과정에 대한 이해가 있다라고 생각하고 바뀐 코드 위주로 정리할 것이다 각 소제목에 해당되는 상세 설명은 각 리스트 아래 더보기 참고 전체 코드는 아래 더보기 더보기 static void * _int_malloc (mstate av, size_t bytes) { INTERNAL_SIZE_T nb; /* normalized request size */ unsigned int idx; /* associated bin index */ mbinptr bin; /* associated bin */ mchunkptr victim; /* inspected/selected chunk */ INTERNAL_SIZE_T size; /* its siz.. (glibc 2.26) tcache_put /* Caller must ensure that we know tc_idx is valid and there's room for more chunks. */ static void tcache_put (mchunkptr chunk, size_t tc_idx) { tcache_entry *e = (tcache_entry *) chunk2mem (chunk); assert (tc_idx next = tcache->entries[tc_idx]; tcache->entries[tc_idx] = e; ++(tcache->counts[tc_idx]); } tcache에 freed 청크를 넣는 작업을 하는 함수이다 포인터 e에 chunk주소 저장 tc_idx가 TCACHE_MAX.. (glibc 2.26) tcache_get /* 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 entries[tc_idx] > 0); tcache->entries[tc_idx] = e->next; --(tcache->counts[tc_idx]); return (void *) e; } 인자로 들어온 tc_idx 인덱스에 있는 freed chunk를 반환하는 함수이다 get address poi.. Heap / 4. tcache 보호되어 있는 글입니다. (glibc 2.26) tcache_init 전체 코드는 아래와 같다 더보기 static void tcache_init(void) { mstate ar_ptr; void *victim = 0; const size_t bytes = sizeof (tcache_perthread_struct); if (tcache_shutting_down) return; arena_get (ar_ptr, bytes); victim = _int_malloc (ar_ptr, bytes); if (!victim && ar_ptr != NULL) { ar_ptr = arena_get_retry (ar_ptr, bytes); victim = _int_malloc (ar_ptr, bytes); } if (ar_ptr != NULL) __libc_lock_unlock (ar_ptr.. (glibc 2.26) malloc 전체 코드는 아래 더보기 더보기 void * __libc_malloc (size_t bytes) { mstate ar_ptr; void *victim; void *(*hook) (size_t, const void *) = atomic_forced_read (__malloc_hook); if (__builtin_expect (hook != NULL, 0)) return (*hook)(bytes, RETURN_ADDRESS (0)); #if USE_TCACHE /* int_free also calls request2size, be careful to not pad twice. */ size_t tbytes = request2size (bytes); size_t tc_idx = csize2tidx (tbyte.. (glibc 2.23) malloc_consolidate 전체 코드 아래 더보기 더보기 인자 및 변수 static void malloc_consolidate(mstate av) { mfastbinptr* fb; /* current fastbin being consolidated */ mfastbinptr* maxfb; /* last fastbin (for loop control) */ mchunkptr p; /* current chunk being consolidated */ mchunkptr nextp; /* next chunk to consolidate */ mchunkptr unsorted_bin; /* bin header */ mchunkptr first_unsorted; /* chunk to link to */ /* These have same use.. 이전 1 ··· 10 11 12 13 14 15 16 ··· 24 다음