post
poster: Thetawaves
description: malloc first fit with no recover
language: plain text
[download]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
void *kmalloc(u32 size)
{    
        //4 byte align
    u32 entry_size = ((size+3)&~3);
    
    void *retptr; 
    print("kmalloc\r\n", 0);
    m_entry *info = (m_entry *)malloc_pos;
    
    if (malloc_pos == malloc_start)
        info->prev_block = NULL;
    else
        info->prev_block = (m_entry *)malloc_last;
    
    info->next_block = NULL;
    info->size = ALLOC + entry_size;
    info->checksum = m_chksum(info);
    
    retptr = info + 1;
    
    malloc_last = malloc_pos;
    malloc_pos = malloc_pos + sizeof(m_entry) + entry_size;
malloc_end:

    printframe(info, 8);
    return retptr;
}