<div dir="ltr">I sent a previous message illustrating Arena Design for my project. This is an initial .h file to be reviewed. Hope to get some feedbacks.<div><br></div><div><div>/**</div><div> *</div><div> * </div><div> * *</div>
<div> * * @brief Arena Manager API</div><div> * */</div><div><br></div><div>/*</div><div> * * Copyright (c) 2012 Hesham AL-Matary</div><div> * *</div><div> * * The license and distribution terms for this file may be</div>
<div> * * found in the file LICENSE in this distribution or at</div><div> * * <a href="http://www.rtems.com/license/LICENSE">http://www.rtems.com/license/LICENSE</a>.</div><div> * */</div>
<div><br></div><div>#ifndef _RTEMS_LIBARENA_H</div><div>#define _RTEMS_LIBARENA_H</div><div><br></div><div>#include <inttypes.h></div><div>#include <rtems/chain.h></div><div>#include <rtems/score/object.h></div>
<div>#include <rtems/score/thread.h></div><div><br></div><div><br></div><div>/**</div><div> * * Type for attributes for arena</div><div> * */</div><div>typedef uint32_t arena_attributes;</div><div><br></div><div>
/**</div><div> * * arena_attributes bit masks</div><div> * */</div><div>#define ARENA_ATTRIBUTES_NO_PERMISSION 0x00</div><div>#define ARENA_ATTRIBUTES_READ_PERMISSION 0x01</div><div>#define ARENA_ATTRIBUTES_WRITE_PERMISSION 0x02</div>
<div>#define ARENA_ATTRIBUTES_EXECUTE_PERMISSION 0x04</div><div>#define ARENA_ATTRIBUTES_CACHEABLE_PERMISSION 0x08</div><div><br></div><div><br></div><div>#ifdef __cplusplus</div><div>extern "c" {</div><div>
#endif</div><div><br></div><div><br></div><div>/* Possible status for Arena_Status type ( to be extended ) */</div><div><br></div><div>typedef enum {</div><div> /* Generic operation failure */</div><div> ARENA_FAILED, </div>
<div> /* Operation done successfully */</div><div> ARENA_SUCCESS,</div><div> /* Invalid address argument */</div><div> ARENA_INVALID_ADDRESS,</div><div> /* Invalid size argumnet */</div><div> ARENA_INVALID_SIZE,</div>
<div> /* Invalid attributes pattern */</div><div> ARENA_INVALID_ATTRIBUTES,</div><div> /* The maximum number of Arenas per Task is reached */</div><div> ARENA_MAX_ARENA_PER_TASK_REACHED</div><div>} Arena_Status;</div>
<div><br></div><div><br></div><div><br></div><div>typedef struct {</div><div> Objects_Control <span class="Apple-tab-span" style="white-space:pre"> </span> Object;</div><div> /* starting address of the arena’s memory pool */</div>
<div> void<span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span>*start_address;</div><div> /* size of the arena’s memory pool */</div><div> size_t<span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> size;</div>
<div> /* memory attributes like w/r/x, cacheable */</div><div> arena_attributes <span class="Apple-tab-span" style="white-space:pre"> </span> attributes;</div><div> /* flag to indicate whether arena is active or not */</div>
<div> bool <span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> is_active;</div><div> /* linked list of tasks that are attached to this arena. Points to</div>
<div> * an Arena_Per_task structure embedded in a Thread_Control. */</div><div> rtems_chain_control attached_tasks;</div><div>} Arena_Control;</div><div><br></div><div><br></div><div><br></div><div>//The TCB would have a pointer to an array of the following struct.</div>
<div>typedef struct {</div><div> /* node of the task in attached_arena->attached_tasks list */</div><div> rtems_chain_node <span class="Apple-tab-span" style="white-space:pre"> </span> node; </div><div> /* pointer to a specific Arena which this task is attached to. */</div>
<div> Arena_Control <span class="Apple-tab-span" style="white-space:pre"> </span>*attached_arena;</div><div>} Arena_Per_Thread;</div><div><br></div><div><br></div><div>Arena_Status _Arena_Initialize( ) ;</div><div><br></div>
<div>/* This function will apply setup fields in Arena_Control</div><div> * and apply memory protection attributes using libmmu API.</div><div> * Also initializing an empty list of attached_tasks. */</div><div><br></div><div>
Arena_Control *_Arena_Create(</div><div> void <span class="Apple-tab-span" style="white-space:pre"> </span>*start_address,</div><div> size_t<span class="Apple-tab-span" style="white-space:pre"> </span> <span class="Apple-tab-span" style="white-space:pre"> </span> size,</div>
<div> arena_attributes<span class="Apple-tab-span" style="white-space:pre"> </span> attributes</div><div>);</div><div><br></div><div> </div><div>/* This function returns attributes of a given Arena */</div><div><br></div>
<div>arena_attributes _Arena_Get_attributes(</div><div> Arena_Control *arena</div><div>);</div><div><br></div><div><br></div><div><br></div><div>/* This function returns the starting address of that Arena in memory */</div>
<div><br></div><div>void *_Arena_Get_start_address(</div><div> Arena_Control *arena</div><div>);</div><div><br></div><div><br></div><div><br></div><div>/* This function returns the size of the Arena */</div><div><br></div>
<div>size_t _Arena_Get_size(</div><div> Arena_Control *arena</div><div>);</div><div><br></div><div><br></div><div><br></div><div>/* This function update the current attributes for</div><div> * an Arena with new_attributes , could be used for deleting protection */</div>
<div><br></div><div>Arena_Status _Arena_Update_attributes(</div><div> Arena_Control<span class="Apple-tab-span" style="white-space:pre"> </span>*arena, </div><div> arena_attributes <span class="Apple-tab-span" style="white-space:pre"> </span> new_attributes</div>
<div>);</div><div><br></div><div><br></div><div><br></div><div>/* This function create a link between an Arena and a task by adding</div><div> * a pointer to ACB in TCB’s attached arenas list and By adding a pointer</div>
<div> * to TCB in ACB by adding a pointer to attached task list */</div><div><br></div><div>Arena_Status _Arena_Attach(</div><div> Arena_Control <span class="Apple-tab-span" style="white-space:pre"> </span>*arena,</div>
<div> Thread_Control <span class="Apple-tab-span" style="white-space:pre"> </span>*task</div><div>);</div><div><br></div><div><br></div><div><br></div><div>/* This function cut the link between a given Arena one of its attached tasks */</div>
<div><br></div><div>Arena_Status _Arena_Detach(</div><div> Arena_Control <span class="Apple-tab-span" style="white-space:pre"> </span>arena,</div><div> Thread_Control *task</div><div>);</div><div><br></div><div><br>
</div><div><br></div><div>/* This function mark an Arena as Deactivated when the current</div><div> * task use it and a context switch happens, so that the next</div><div> * task can not access this deactivated Arena. */</div>
<div><br></div><div>Arena_Status _Arena_Deactivate(</div><div> Arena_Control<span class="Apple-tab-span" style="white-space:pre"> </span>*arena</div><div>); </div><div><br></div><div><br></div><div><br></div><div>/* This function mark an Arena as Activated when</div>
<div> * a context switch happens, and the next task</div><div> * is attached to that Arena */</div><div><br></div><div>Arena_Status _Arena_Activate(</div><div> Arena_Control<span class="Apple-tab-span" style="white-space:pre"> </span>*arena</div>
<div>); </div><div><br></div><div><br></div><div><br></div><div>/* This function delete the Arena and update the Arena</div><div> * list in every attached task TCB by deleting the ACB entry</div><div> * of the deleted Arena */</div>
<div><br></div><div>Arena_Status _Arena_Delete(</div><div> Arena_Control *arena</div><div>);</div><div><br></div><div><br></div><div><br></div><div>#ifdef __cplusplus</div><div>}</div><div>#endif</div><div><br></div><div>
#endif</div></div></div>