[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
problem with memory allocation
- Date: Tue, 3 Aug 1999 10:26:53 -0500 (CDT)
- From: joel at OARcorp.com (joel at OARcorp.com)
- Subject: problem with memory allocation
On Tue, 3 Aug 1999, Emmanuel Raguet wrote:
> Hi Joel, hi everybody
>
> During the port of RDBG on powerPc target, we have seen that a
> problem occured with the socket (unable to bind).
>
> I have investigated and found it seems to be a problem with malloc.
> The returned value is in a memory space which is already allocated.
>
> This happens during the MALLOC located in the function socreate
> (file uipc_socket.c). A pointer in a network stucture is corrupted
> by the bzero because the returned address belongs to the structure.
>
> I have several questions to understand better some mechanism to
> try to solve our problem :
>
> 1 - Where does the memory allocated by a malloc come from :
> the workspace or the heap ?
>
> My heap is from 0x60000 to 0x3f7ffff.
> My workspace is from 3f80000 to the memory end.
>
> When rtems_bsdnet_malloc is called, the returned value is in
> the heap.
> When malloc is called directly (in my dec21140 driver, due to
> undef malloc and free), the returned value is in the workspace.
The heap and workspace are separate entities. rtems_bsdnet_malloc should
be based on malloc and both should return memory from the heap.
> 2 - How does the malloc mechanism work ?
>
> I have seen that the heap is seen as a region. To obtain memory,
> a call to Region_Allocate_Segment is performed, which called
> _Heap_Allocate.
> I have not well understood the Heap management (block, circular
> buffers,... ?)
It's OK. :)
malloc is built on top of Region which is built on top of a Heap.
Workspace is internal to RTEMS and is a heap directly.
> 3 - When is the workspace used ?
During system initialization, task/thread creation (stack and FP
contexts), and message buffer allocation.
> 4 - When is the heap used ?
The workspace is a heap -- so I assume that you mean the "C Program Heap"
aka malloc.
The answer is any time the application allocates memory.
> FYI, all this code works well on pc386, our other target.
Which gives me a nice place to tell you waht is more than likely wrong. :)
The RTEMS Workspace and malloc heap are overlappign for the mcp750 BSP.
Check the calls to RTEMS_Malloc_Initialize( start, length, ...) and the
settings of Configuration.work_space_start and
Configuration.work_space_size.
Also I notice that the bspstart.c code indicates that INIT_STACK_SIZE and
INTR_STACK_SIZE somehow play into the memory layout on this BSP.
My hunch is that these memory areas overlap. When they do, all bets are
off.
--joel