Commit bbd76def authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

Started simple data store junk.

parent 4ad6d6aa
/*
* dstore.h - lcd-local data store
*
* Author: Charles Jacobsen <charlesj@cs.utah.edu>
* Copyright: University of Utah
*/
#ifndef LCD_PROTOTYPE_DSTORE_H
#define LCD_PROTOTYPE_DSTORE_H
#include <lcd-prototype/lcd.h>
#include "utcb.h"
#include "api-internal.h"
#include "../api/defs.h"
typedef cptr_t dsptr_t;
/**
* Put an object in the current lcd's data store.
*/
int lcd_ds_store(void *object, u64 badge, dsptr_t *out);
/**
* Remove an object (but doesn't free it) from the current
* lcd's data store. Returns the stored object.
*/
void * lcd_ds_drop(u64 badge, dsptr_t ptr);
/**
* Get the object in the data store.
*/
void * lcd_ds_read(u64 badge, dsptr_t out);
#endif /* LCD_PROTOTYPE_DSTORE_H */
/*
* dstore.c - lcd-local data store
*
* Author: Charles Jacobsen <charlesj@cs.utah.edu>
* Copyright: University of Utah
*/
#include "../include/dstore.h"
int lcd_ds_store(void *object, u64 badge, dsptr_t *out)
{
struct cnode *cnode;
struct cspace *cspace;
int ret;
cspace = current_lcd()->cspace;
/* Ignore the badge for now */
ret = lcd_cnode_alloc(cspace, out);
if (ret)
goto fail1;
/* Insert object */
ret = lcd_cnode_insert(cspace, *out, object, LCD_CAP_TYPE_DSTORE,
LCD_CAP_RIGHT_ALL);
if (ret)
goto fail2;
fail2:
ret = lcd_cap_lock();
if (ret)
return ret;
__lcd_cnode_free(cspace, *out);
lcd_cap_unlock();
fail1:
return ret;
}
static void * __lcd_ds_drop(u64 badge, dsptr_t ptr)
{
struct cnode *cnode;
struct cspace *cspace;
void *obj;
int ret;
cspace = current_lcd()->cspace;
ret = __lcd_cnode_lookup(cspace, ptr, &cnode);
if (ret)
return NULL;
if (__lcd_cnode_type(cnode) != LCD_CAP_TYPE_DSTORE)
return NULL;
obj = cnode->object;
__lcd_cnode_free(cnode);
return obj;
}
void * lcd_ds_drop(u64 badge, dsptr_t ptr)
{
int ret;
void *obj;
ret = lcd_cap_lock();
if (ret)
return NULL;
obj = __lcd_ds_drop(badge, ptr);
lcd_cap_unlock();
return obj;
}
static void * __lcd_ds_read(u64 badge, dsptr_t ptr)
{
struct cnode *cnode;
struct cspace *cspace;
int ret;
cspace = current_lcd()->cspace;
ret = __lcd_cnode_lookup(cspace, ptr, &cnode);
if (ret)
return NULL;
if (__lcd_cnode_type(cnode) != LCD_CAP_TYPE_DSTORE)
return NULL;
return cnode->object;
}
void * lcd_ds_read(u64 badge, dsptr_t out)
{
int ret;
void *obj;
ret = lcd_cap_lock();
if (ret)
return NULL;
obj = __lcd_ds_read(badge, ptr);
lcd_cap_unlock();
return obj;
}
#endif /* LCD_PROTOTYPE_DSTORE_H */
Markdown is supported
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