// Add a IPv4 address to table void add_ipv4(BSP_IPV4_LIST *list, uint32_t addr) { if (search_ipv4(list, addr)) { // Already in list return; } if (!list) { return; } struct bsp_ipv4_item_t *item = bsp_malloc(sizeof(struct bsp_ipv4_item_t)); item->addr = addr; item->next = NULL; int slab_id = ipv4_hash(addr, IPLIST_SIZE); if (!list->slab[slab_id][0] || !list->slab[slab_id][1]) { // Header list->slab[slab_id][0] = item; } else { // Add link list->slab[slab_id][1]->next = item; } list->slab[slab_id][1] = item; trace_msg(TRACE_LEVEL_VERBOSE, "IpList : Add an IPv4 address to list"); return; }
static int new_word_filter(lua_State *s) { if (!s) { return 0; } struct word_filter_t *flt = bsp_malloc(sizeof(struct word_filter_t)); if (!flt) { trace_msg(TRACE_LEVEL_FATAL, "Filter : Alloc new word filter error"); return 0; } flt->node_used = 0; bsp_spin_init(&flt->node_lock); flt->node_list = NULL; flt->node_list_size = 0; // Make root flt->root = _get_new_node(flt); lua_pushlightuserdata(s, (void *) flt); return 1; }
static void buf_handler(int argc, char** argv, uint8_t port) { #ifdef UNIT_TESTS if (argc > 2 && stricmp(argv[1],"test") == 0) { int n = strtoul(argv[2],0,10); if (n == 1) { for (uint16_t size=1; size < 1024; size++) { bsp_termios_printf(port, "malloc %d\r\n", size); uint8_t* buf = (uint8_t*) bsp_malloc(size); memset(buf,0xaa,size); bsp_free(buf); if ((size&0x7f) == 0) OSTimeDly(1); } } else if (n == 2) { for (int i=1; ; i++) { bsp_termios_printf("malloc %d\r\n", i); bsp_malloc(16); if ((i&0x7f) == 0) OSTimeDly(1); } } else if (n == 3) { bsp_malloc(0); } else if (n == 4) { uint8_t* buf = (uint8_t*) bsp_malloc(16); memset(buf,0xaa,17); bsp_free(buf); } else if (n == 5) { uint8_t* buf = (uint8_t*) bsp_malloc(16); memset(buf-1,0xaa,17); bsp_free(buf); } else if (n == 6) { uint8_t* buf = (uint8_t*) bsp_malloc(16); bsp_free(buf); bsp_free(buf); } else if (n == 7) { bsp_free((uint8_t*) 0x12345678); } else if (n == 8) { bsp_free(0); } } #endif bsp_buffer_dump(port); }