Commit 37074480 authored by Muktesh Khole's avatar Muktesh Khole Committed by Vikram Narayanan
Browse files

Capability Module

parent 31322383
......@@ -9,7 +9,7 @@
int init_module(void)
{
printk(KERN_INFO "Initializing LCD Module %d\n", PAGE_SIZE);
printk(KERN_INFO "Initializing LCD Module\n");
return 0; // Non-zero return means that the module couldn't be loaded.
}
......@@ -18,4 +18,72 @@ void cleanup_module(void)
printk(KERN_INFO "Cleaning up LCD Module\n");
}
void initialize_freelist(cte *cnode, int size, bool bFirstCNode=false)
{
if (cnode == NULL)
return;
int max_slots = (size / sizeof(cte));
int startid = 1;
if (bFirstCNode)
{
startid = LCD_CapFirstFreeSlot;
}
cnode[0].ctetype = lcd_type_free;
cnode[0].next_free_slot = startid;
cnode[startid].ctetype = lcd_type_free;
for (int i = startid; i < max_slots-1; i++)
{
cnode[i].next_free_slot = i + 1;
cnode[i+1].ctetype = lcd_type_free;
}
}
cap_space * lcd_create_cspace()
{
cap_space *cspace = (cap_space *)vmalloc(sizeof(cap_space));
SAFE_EXIT_IF_ALLOC_FAILED(cspace, alloc_failure);
// initialize semaphore
sema_init(&(cspace->sem_cspace), 1);
// allocate memory for the first cnode.
cspace->root_cnode = (cte *)kmalloc(PAGE_SIZE, GFP_KERNEL);
SAFE_EXIT_IF_ALLOC_FAILED(cspace->root_cnode, alloc_failure);
// initialize the free list
initialize_freelist(cspace->root_cnode, PAGE_SIZE, true);
goto success;
alloc_failure:
if (cspace)
{
if (cspace->root_cnode)
{
kfree(cspace->root_cnode);
cspace->root_cnode = NULL;
}
vfree(cspace);
cspace = NULL;
}
success:
return cspace;
}
cap_id lcd_create_cap(void * ptcb, void * hobject, lcd_cap_rights crights)
{
struct task_struct *tcb = (struct task_struct *)ptcb;
//1. lock the cspace.
//2. walk the cspace to find empty slots.
// if only one empty slot left in cnode, create a new cnode, initialize its free list.
//3. Get the first free slot, set its type to capability.
// set its hObject, and rights.
//4. return the cap_id within this cspace.
}
\ No newline at end of file
......@@ -4,7 +4,7 @@
#include <linux/types.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/slab_def.h>
#include <linux/fs.h>
#include <linux/kthread.h>
#include <linux/sched.h>
......@@ -14,8 +14,17 @@
MODULE_LICENSE("GPL");
MODULE_AUTHOR ("FLUX-LAB University of Utah");
#define LCD_CAPABILITY
#define SAFE_EXIT_IF_ALLOC_FAILED(ptr, label) \
if (ptr == NULL) \
{ \
goto label; \
} \
typedef enum _lcd_cap_type
{
lcd_type_free,
lcd_type_untyped,
lcd_type_cnode,
lcd_type_endpoint
......@@ -28,8 +37,8 @@ enum {
LCD_CapInitThreadCNode = 2, /* initial thread's root CNode cap */
LCD_CapInitThreadPD = 3, /* initial thread' page directory */
LCD_CapIRQControl = 4, /* global IRQ controller */
LCD_CapBootInfoFrame = 9, /* bootinfo frame cap */
LCD_CapInitThreadIPCBuffer = 10 /* initial thread's IPC buffer frame cap */
LCD_CapInitThreadIPCBuffer = 5, /* initial thread's IPC buffer frame cap */
LCD_CapFirstFreeSlot = 6
};
typedef uint32_t lcd_cnode; // a pointer to the cnode
......@@ -51,9 +60,9 @@ typedef uint16_t lcd_cap_rights; // holds the rights associated with a capabil
typedef struct _cap_derivation_list
{
lcd_tcb remote_TCB; // reference to the thread which was granted this capability
void *remote_TCB; // reference to the thread which was granted this capability
cap_id remote_cid; // address in the remote threads capability space where this
// capability is stored.
// capability is stored.
struct _cap_derivation_list *next;
}cap_derivation_list;
......@@ -65,7 +74,7 @@ typedef struct _capability
typedef struct _capability_internal
{
void *hobject; // a pointer to a kernel object
struct cap_derivation_list *cgrant_list; // list of domain ids to whom this capability is granted
struct cap_derivation_list *cdt_list; // list of domain ids to whom this capability is granted
lcd_cap_rights crights; // specifies the rights the domain has over this capability
}capability_internal;
......@@ -77,7 +86,8 @@ typedef struct _cte // capability table entry
union{
struct _cap_node *cnode;
capability_internal *cap;
}u;
int next_free_slot;
};
}cte;
typedef struct _cap_node
......@@ -87,24 +97,24 @@ typedef struct _cap_node
int32_t guard_bits:27; // actual guard bits
int32_t guard_size:5; // number of valid bits in guard_bits
}guard;
uint32_t nfree_slots; /* number of free slots left in this cnode. when this reaches
2 power bits - 1 we must allocate another cnode before insert*/
int max_slots;
cte *cap_entry; /* may point to another cnode or to a capability */
uint16_t bits; /* total slots in this cnode is 2 power bits.
Minimum value must be 5 i.e. 32 slots*/
}cap_node;
typedef struct _cap_space
{
struct cap_node *cnode;
struct semaphore g_cspace;
struct cte *root_cnode;
struct semaphore sem_cspace;
}cap_space;
/* Helper Functions */
// initializes the free slots available in the cnode structure.
void initialize_freelist(cap_node *cnode, int size, bool bFirstCNode=false);
// will be used to search for the cnode which has a free slot available.
// if no such cnode exists will make a call to create lcd_create_cnode to create an
// empty cnode.
......@@ -126,7 +136,7 @@ uint32_t lcd_delete_cnode(cap_id cid);
// one for its cspace
// one for the endpoint.
// the returned value goes into the TCB of the caller.
cap_space * lcd_create_cspace(void * ptcb);
cap_space * lcd_create_cspace();
// creates a new capability, inserts it into cspace of caller and
// returns the capability identifier.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment