Open gvannest opened 4 years ago
[x] check with lldb if the g_mallocptr.tinychk
points towards a free block with a header and a size of 132kb.
check this : https://stackoverflow.com/questions/3875055/how-to-use-gdb-to-explore-the-stack-heap
see command in comments. Yes there is a free block with a free header at the beg of the heap, but could not find the command to get the size of the heap and the first address of the heap
[x] What should we do when requested allocation size is 0? => check true malloc
[x] add footer? how --> a new void *
pointer
[x] split the newly created free block with one allocated chunk of the requested size (512 bytes in current exemple cf main), and one new free block of the remaining free size
[x] complete the ft_tiny
function with the case where there is no need for a new heap (new free chunk allocation)
[x] treat the case where there is a new heap allocation: set the pointer to the new (free chunk list!) of the new heap in the footer of the last one (kind of new g_mallocptr.tinychk
)
[x] do it for small
[x] do the work for large : slightly different because direct mmap allocation, no heap .
[x] show_alloc_mem function (mandatory) .
[x] mettre le begin_free_list a NULL si aucunu free block (a checker au moment de l'alloc) .
[x] Go back on branch temp-header-footer-heap: We cannot assume not munmap because we munmap large chunks. Hence we need to set the footer with END_ZONE_FLAG and pointer to next zone + HEADER with pointer to previous footer
[ ] opti tiny/ small/ large chunks? What does the correction say?
[ ] mutex lock in show alloc mem
>lldb ./ft_malloc_exec
>b main_test:19 => set a breakpoint at line 19 in main_test.c
>r => run the program
{ breakpoint is reach } >memory read 0x1000df000 --count 32 => the address has been printed above during the execution of the program. 32 for 32 bytes
Main issue for the ft_malloc function which deals with the allocation of memory
Note: free is in another issue, please refer to https://github.com/gvannest/ft_malloc/issues/1
Tasks
specific documentation for implementation
analysis of malloc source code https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#malloc_chunk
making a global variable available in several
.c
files: https://stackoverflow.com/questions/1433204/how-do-i-use-extern-to-share-variables-between-source-files https://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration https://www.tutorialspoint.com/extern-keyword-in-cchunk headers: https://reverseengineering.stackexchange.com/questions/19293/heap-chunk-structure-does-not-contain-previous-section-info
malloc minimum chunk size (from malloc source code):
Main decisions on implementation