System/FFI/LibC: Round-robin mem_task selection for malloc

This fixes an issue where multiple HTTP requests would arrive
simultaneously, and the subsequent calls to @rsa_import would
end up clobbering the shared mem_task's CHeapCtrl, leading to #GP.

Eventually, we may want to simplify this to only init the CHeapCtrl,
rather than creating the entire CTask, but for now it seems ok.
This commit is contained in:
Alec Murphy 2025-03-10 07:51:19 -04:00
parent 546cbaf18d
commit e982c9584a
2 changed files with 35 additions and 1 deletions

View file

@ -118,11 +118,18 @@ U0 ntohs()
POP_SYSV_REGS
}
U64 @malloc(I64 size)
{
U64 res = MAlloc(size, malloc_mem_task[malloc_current_mem_task % MALLOC_MEM_TASK_COUNT]->code_heap);
malloc_current_mem_task++;
return res;
}
U0 malloc()
{
PUSH_SYSV_REGS
GET_SYSV_ARGS
MAlloc(p0, slon_mem_task->code_heap);
@malloc(p0);
POP_SYSV_REGS
}