Skip to content

Commit

Permalink
memp: Employ TCP-PCB allocation limit if libc malloc used
Browse files Browse the repository at this point in the history
  • Loading branch information
udoudou authored and david-cermak committed Nov 21, 2024
1 parent 0606eed commit 5be5d89
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/core/memp.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ memp_init(void)
#endif /* MEMP_OVERFLOW_CHECK >= 2 */
}

#if MEMP_MEM_MALLOC && ESP_LWIP && LWIP_TCP
static u32_t num_tcp_pcb = 0;
#endif

static void *
#if !MEMP_OVERFLOW_CHECK
do_memp_malloc_pool(const struct memp_desc *desc)
Expand All @@ -251,6 +255,16 @@ do_memp_malloc_pool_fn(const struct memp_desc *desc, const char *file, const int
SYS_ARCH_DECL_PROTECT(old_level);

#if MEMP_MEM_MALLOC
#if ESP_LWIP
#if LWIP_TCP
if(desc == memp_pools[MEMP_TCP_PCB]){
if(num_tcp_pcb >= MEMP_NUM_TCP_PCB){
return NULL;
}
}
#endif
#endif

memp = (struct memp *)mem_malloc(MEMP_SIZE + MEMP_ALIGN_SIZE(desc->size));
SYS_ARCH_PROTECT(old_level);
#else /* MEMP_MEM_MALLOC */
Expand All @@ -260,6 +274,12 @@ do_memp_malloc_pool_fn(const struct memp_desc *desc, const char *file, const int
#endif /* MEMP_MEM_MALLOC */

if (memp != NULL) {
#if MEMP_MEM_MALLOC && ESP_LWIP && LWIP_TCP
if (desc == memp_pools[MEMP_TCP_PCB]) {
num_tcp_pcb++;
}
#endif

#if !MEMP_MEM_MALLOC
#if MEMP_OVERFLOW_CHECK == 1
memp_overflow_check_element(memp, desc);
Expand Down Expand Up @@ -369,6 +389,12 @@ do_memp_free_pool(const struct memp_desc *desc, void *mem)

SYS_ARCH_PROTECT(old_level);

#if MEMP_MEM_MALLOC && ESP_LWIP && LWIP_TCP
if (desc == memp_pools[MEMP_TCP_PCB]) {
num_tcp_pcb--;
}
#endif

#if MEMP_OVERFLOW_CHECK == 1
memp_overflow_check_element(memp, desc);
#endif /* MEMP_OVERFLOW_CHECK */
Expand Down

0 comments on commit 5be5d89

Please sign in to comment.