Ticket #668: allocator.patch

File allocator.patch, 5.5 KB (added by Jakub Jermář, 8 years ago)
  • uspace/Makefile.common

    === modified file 'uspace/Makefile.common'
     
    205205ifeq ($(CONFIG_OPTIMIZE_FOR_SIZE),y)
    206206        OPTIMIZATION = s
    207207else
    208         OPTIMIZATION = 3
     208        OPTIMIZATION = 0
    209209endif
    210210
    211211# PCUT-based unit tests
  • uspace/app/fdisk/fdisk.c

    === modified file 'uspace/app/fdisk/fdisk.c'
     
    10311031
    10321032int main(int argc, char *argv[])
    10331033{
    1034         service_id_t svcid;
     1034        service_id_t svcid = 0;
    10351035        fdisk_dev_t *dev;
    10361036        int rc;
    10371037
  • uspace/lib/c/generic/io/log.c

    === modified file 'uspace/lib/c/generic/io/log.c'
     
    242242        if (message_buffer == NULL)
    243243                return;
    244244
    245         vsnprintf(message_buffer, MESSAGE_BUFFER_SIZE, fmt, args);
     245        int cnt;
     246
     247        cnt = vsnprintf(message_buffer, MESSAGE_BUFFER_SIZE, fmt, args);
     248
     249        assert(cnt <= MESSAGE_BUFFER_SIZE);
    246250        logger_message(logger_session, ctx, level, message_buffer);
    247251        free(message_buffer);
    248252}
  • uspace/lib/c/generic/libc.c

    === modified file 'uspace/lib/c/generic/libc.c'
     
    138138
    139139void abort(void)
    140140{
     141        *(int *)0x123 = 0x456;
    141142        __SYSCALL1(SYS_TASK_EXIT, true);
    142143       
    143144        /* Unreachable */
  • uspace/lib/c/generic/malloc.c

    === modified file 'uspace/lib/c/generic/malloc.c'
     
    296296        head->area = area;
    297297        head->magic = HEAP_BLOCK_HEAD_MAGIC;
    298298       
     299        if (free)
     300                memset((void *) &head[1], 0xee, NET_SIZE(size));
     301
    299302        heap_block_foot_t *foot = BLOCK_FOOT(head);
    300303       
    301304        foot->size = size;
     
    311314 * @param addr Address of the block.
    312315 *
    313316 */
     317#include <io/kio.h>
    314318static void block_check(void *addr)
    315319{
    316320        heap_block_head_t *head = (heap_block_head_t *) addr;
     
    320324        heap_block_foot_t *foot = BLOCK_FOOT(head);
    321325       
    322326        malloc_assert(foot->magic == HEAP_BLOCK_FOOT_MAGIC);
     327        if (head->size != foot->size) {
     328                kio_printf("head=%p, foot=%p, foot-head=%u, head->size=%u, foot->size=%u\n", head, foot, (void *) foot - (void *) head, head->size, foot->size);
     329        }
    323330        malloc_assert(head->size == foot->size);
    324331}
    325332
     
    353360        /* Align the heap area size on page boundary */
    354361        size_t asize = ALIGN_UP(size, PAGE_SIZE);
    355362        void *astart = as_area_create(AS_AREA_ANY, asize,
    356             AS_AREA_WRITE | AS_AREA_READ | AS_AREA_CACHEABLE);
     363            AS_AREA_WRITE | AS_AREA_READ | AS_AREA_CACHEABLE | AS_AREA_GUARD);
    357364        if (astart == AS_MAP_FAILED)
    358365                return false;
    359366       
     
    394401 */
    395402static bool area_grow(heap_area_t *area, size_t size)
    396403{
     404        return false;
    397405        if (size == 0)
    398406                return true;
    399407       
     
    792800         */
    793801        size_t gross_size = GROSS_SIZE(ALIGN_UP(size, BASE_ALIGN));
    794802       
     803#if 0
    795804        /* Try the next fit approach */
    796805        heap_block_head_t *split = next_fit;
    797806       
     
    815824                if (addr != NULL)
    816825                        return addr;
    817826        }
     827#endif
    818828       
    819829        /* Finally, try to grow heap space and allocate in the new area. */
    820830        return heap_grow_and_alloc(gross_size, falign);
     
    851861{
    852862        heap_lock();
    853863        void *block = malloc_internal(size, BASE_ALIGN);
     864        memset(block, 0xde, size);
    854865        heap_unlock();
    855866
    856867        return block;
     
    874885
    875886        heap_lock();
    876887        void *block = malloc_internal(size, palign);
     888        memset(block, 0xde, size);
    877889        heap_unlock();
    878890
    879891        return block;
     
    891903{
    892904        if (addr == NULL)
    893905                return malloc(size);
    894        
    895906        heap_lock();
    896907       
    897908        /* Calculate the position of the header. */
     
    908919        malloc_assert((void *) head < area->end);
    909920       
    910921        void *ptr = NULL;
    911         bool reloc = false;
    912         size_t real_size = GROSS_SIZE(ALIGN_UP(size, BASE_ALIGN));
     922//      bool reloc = false;
     923//      size_t real_size = GROSS_SIZE(ALIGN_UP(size, BASE_ALIGN));
    913924        size_t orig_size = head->size;
     925#if 0   
    914926       
    915927        if (orig_size > real_size) {
    916928                /* Shrink */
     
    949961                        reloc = true;
    950962        }
    951963       
     964#endif
    952965        heap_unlock();
    953        
    954         if (reloc) {
     966//      if (reloc) {
    955967                ptr = malloc(size);
    956968                if (ptr != NULL) {
    957969                        memcpy(ptr, addr, NET_SIZE(orig_size));
    958970                        free(addr);
    959971                }
    960         }
     972//      }
    961973       
    962974        return ptr;
    963975}
  • uspace/srv/devman/devtree.c

    === modified file 'uspace/srv/devman/devtree.c'
     
    4343
    4444static inline size_t handle_key_hash(void *key)
    4545{
    46         devman_handle_t handle = *(devman_handle_t*)key;
     46        devman_handle_t handle = *((devman_handle_t *) key);
    4747        return handle;
    4848}
    4949
     
    6161
    6262static bool devman_devices_key_equal(void *key, const ht_link_t *item)
    6363{
    64         devman_handle_t handle = *(devman_handle_t*)key;
     64        devman_handle_t handle = *((devman_handle_t *) key);
    6565        dev_node_t *dev = hash_table_get_inst(item, dev_node_t, devman_dev);
    6666        return dev->handle == handle;
    6767}
    6868
    6969static bool devman_functions_key_equal(void *key, const ht_link_t *item)
    7070{
    71         devman_handle_t handle = *(devman_handle_t*)key;
     71        devman_handle_t handle = *((devman_handle_t *) key);
    7272        fun_node_t *fun = hash_table_get_inst(item, fun_node_t, devman_fun);
    7373        return fun->handle == handle;
    7474}
    7575
    7676static inline size_t service_id_key_hash(void *key)
    7777{
    78         service_id_t service_id = *(service_id_t*)key;
     78        service_id_t service_id = *((service_id_t *) key);
    7979        return service_id;
    8080}
    8181
     
    8787
    8888static bool loc_functions_key_equal(void *key, const ht_link_t *item)
    8989{
    90         service_id_t service_id = *(service_id_t*)key;
     90        service_id_t service_id = *((service_id_t *) key);
    9191        fun_node_t *fun = hash_table_get_inst(item, fun_node_t, loc_fun);
    9292        return fun->service_id == service_id;
    9393}