[GSoC2012] MMU / New Arena API ( libarena.h)

Hesham Moustafa heshamelmatary at gmail.com
Tue May 29 18:02:16 UTC 2012

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.

 *   *
 *    * @brief Arena Manager API
 *     */

 *  * Copyright (c) 2012 Hesham AL-Matary
 *         *
 *          * The license and distribution terms for this file may be
 *           * found in the file LICENSE in this distribution or at
 *            * http://www.rtems.com/license/LICENSE.
 *             */


#include <inttypes.h>
#include <rtems/chain.h>
#include <rtems/score/object.h>
#include <rtems/score/thread.h>

 *  * Type for attributes for arena
 *   */
typedef uint32_t arena_attributes;

 *  * arena_attributes bit masks
 *   */

#ifdef __cplusplus
extern "c" {

/* Possible status for Arena_Status type ( to be extended ) */

typedef enum {
  /* Generic operation failure */
  /* Operation done successfully */
  /* Invalid address argument */
  /* Invalid size argumnet */
  /* Invalid attributes pattern */
  /* The maximum number of Arenas per Task is reached */
} Arena_Status;

typedef struct {
  Objects_Control   Object;
  /* starting address of the arena’s memory pool */
  void           *start_address;
  /* size of the arena’s memory pool */
  size_t    size;
  /* memory attributes like w/r/x, cacheable */
  arena_attributes     attributes;
  /* flag to indicate whether arena is active or not */
  bool            is_active;
  /* linked list of tasks that are attached to this arena. Points to
   * an Arena_Per_task structure embedded in a Thread_Control. */
  rtems_chain_control    attached_tasks;
} Arena_Control;

//The TCB would have a pointer to an array of the following struct.
typedef struct {
  /* node of the task in attached_arena->attached_tasks list */
  rtems_chain_node      node;
  /* pointer to a specific Arena which this task is attached to. */
  Arena_Control *attached_arena;
} Arena_Per_Thread;

Arena_Status _Arena_Initialize( ) ;

/* This function will apply setup fields in Arena_Control
 * and apply memory protection attributes using libmmu API.
 * Also initializing an empty list of attached_tasks. */

Arena_Control *_Arena_Create(
  void *start_address,
  size_t  size,
  arena_attributes attributes

/* This function returns attributes of a given Arena  */

arena_attributes _Arena_Get_attributes(
  Arena_Control *arena

/* This function returns the starting address of that Arena in memory */

void *_Arena_Get_start_address(
  Arena_Control *arena

/* This function returns the size of the Arena */

size_t _Arena_Get_size(
  Arena_Control *arena

/* This function update the current attributes for
 * an Arena with new_attributes , could be used for deleting protection */

Arena_Status _Arena_Update_attributes(
  Arena_Control *arena,
  arena_attributes  new_attributes

/* This function create a link between an Arena and a task by adding
 *  a pointer to ACB in TCB’s attached arenas list and By adding a pointer
 *  to TCB in ACB by adding a pointer to attached task list */

Arena_Status _Arena_Attach(
  Arena_Control *arena,
  Thread_Control *task

/* This function cut the link between a given Arena one of its attached
tasks */

Arena_Status _Arena_Detach(
  Arena_Control arena,
  Thread_Control       *task

/* This function mark an Arena as Deactivated when the current
 *  task use it and a context switch happens, so that the next
 *  task can not access this deactivated Arena. */

Arena_Status _Arena_Deactivate(
  Arena_Control *arena

/* This function mark an Arena as Activated when
 *  a context switch happens, and the next task
 *   is attached to that Arena */

Arena_Status _Arena_Activate(
  Arena_Control *arena

/* This function delete the Arena and update the Arena
 *  list in every attached task TCB by deleting the ACB entry
 *   of the deleted Arena */

Arena_Status _Arena_Delete(
  Arena_Control *arena

#ifdef __cplusplus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/devel/attachments/20120529/f9fc7657/attachment.html>

More information about the devel mailing list