Commit 5b42e788 authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan

Adjusted cap tests, starting ipc.

parent 72b20241
......@@ -27,46 +27,55 @@ static inline int test_rm_cspace(struct cspace *cspace, int ret_val)
return ret_val;
}
static inline void test_check_cnode(struct cspace *cspace, cptr_t cptr,
static inline int test_check_cnode(struct cspace *cspace, cptr_t cptr,
void *object, enum lcd_cap_type t,
int rights)
{
struct cnode *cnode;
lcd_cap_lock();
int ret;
if (lcd_cap_lock())
return -1;
if (__lcd_cnode_lookup(cspace, cptr, &cnode)) {
LCD_ERR("looking up object at %p in cspace at %p at cptr %d",
object, cspace, cptr);
goto unlock;
goto fail;
}
if (__lcd_cnode_type(cnode) != t) {
LCD_ERR("cnode has type %d, expected %d",
__lcd_cnode_type(cnode), t);
goto unlock;
goto fail;
}
if (__lcd_cnode_rights(cnode) != rights) {
LCD_ERR("cnode has rights %d, expected %d",
__lcd_cnode_rights(cnode), rights);
goto unlock;
goto fail;
}
if (__lcd_cnode_object(cnode) != object) {
LCD_ERR("cnode has object %p, expected %p",
__lcd_cnode_object(cnode), object);
goto unlock;
goto fail;
}
unlock:
lcd_cap_unlock();
return 0;
fail:
lcd_cap_unlock();
return -1;
}
static int test01(void)
{
struct cspace *cspace;
int ret;
if (lcd_mk_cspace(&cspace))
LCD_FAIL("mk cspace");
if (!cspace)
LCD_FAIL("cspace null");
lcd_cap_lock();
if (lcd_cap_lock())
return -1;
__lcd_rm_cspace(&cspace);
lcd_cap_unlock();
......@@ -96,7 +105,8 @@ static int test02(void)
/*
* LOCK cap
*/
lcd_cap_lock();
if (lcd_cap_lock())
goto fail;
if (__lcd_cnode_lookup(cspace, cptr, &cnode)) {
LCD_ERR("lookup");
goto fail_unlock;
......@@ -167,7 +177,8 @@ static int test03(void)
/*
* LOCK cap
*/
lcd_cap_lock();
if (lcd_cap_lock())
goto fail;
if (__lcd_cnode_lookup(cspace, cptr, &cnode)) {
LCD_ERR("lookup");
goto fail_unlock;
......@@ -228,7 +239,8 @@ static int test04(void)
/*
* LOCK cap
*/
lcd_cap_lock();
if (lcd_cap_lock())
goto fail;
if (__lcd_cnode_lookup(cspace, cptr, &cnode)) {
LCD_ERR("lookup");
goto fail_unlock;
......@@ -339,13 +351,16 @@ static int test05(void)
/*
* Check
*/
test_check_cnode(cspace1, cptr1, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_ALL);
test_check_cnode(cspace2, cptr2, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_GRANT |
LCD_CAP_RIGHT_WRITE | LCD_CAP_RIGHT_READ);
test_check_cnode(cspace3, cptr3, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_READ);
if (test_check_cnode(cspace1, cptr1, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_ALL))
goto fail3;
if (test_check_cnode(cspace2, cptr2, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_GRANT |
LCD_CAP_RIGHT_WRITE | LCD_CAP_RIGHT_READ))
goto fail3;
if (test_check_cnode(cspace3, cptr3, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_READ))
goto fail3;
/*
* Revoke read
*/
......@@ -356,16 +371,20 @@ static int test05(void)
/*
* Check
*/
test_check_cnode(cspace1, cptr1, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_ALL);
test_check_cnode(cspace2, cptr2, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_GRANT | LCD_CAP_RIGHT_WRITE);
test_check_cnode(cspace3, cptr3, &x, LCD_CAP_TYPE_SYNC_EP, 0);
if (test_check_cnode(cspace1, cptr1, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_ALL))
goto fail3;
if (test_check_cnode(cspace2, cptr2, &x, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_GRANT | LCD_CAP_RIGHT_WRITE))
goto fail3;
if (test_check_cnode(cspace3, cptr3, &x, LCD_CAP_TYPE_SYNC_EP, 0))
goto fail3;
/*
* Free cap
*/
lcd_cap_lock();
if (lcd_cap_lock())
goto fail3;
if (__lcd_cnode_lookup(cspace1, cptr1, &cnode)) {
LCD_ERR("cspace1 cnode lookup");
goto fail3_unlock;
......@@ -376,9 +395,12 @@ static int test05(void)
/*
* Check
*/
test_check_cnode(cspace1, cptr1, &x, LCD_CAP_TYPE_FREE, 0);
test_check_cnode(cspace2, cptr2, &x, LCD_CAP_TYPE_FREE, 0);
test_check_cnode(cspace3, cptr3, &x, LCD_CAP_TYPE_FREE, 0);
if (test_check_cnode(cspace1, cptr1, &x, LCD_CAP_TYPE_FREE, 0))
goto fail3;
if (test_check_cnode(cspace2, cptr2, &x, LCD_CAP_TYPE_FREE, 0))
goto fail3;
if (test_check_cnode(cspace3, cptr3, &x, LCD_CAP_TYPE_FREE, 0))
goto fail3;
/*
* rm cspaces
......
......@@ -279,13 +279,13 @@ struct sync_endpoint {
/**
* Create a synchronous end point, and install it in t's cspace
* at location c.
* at location cptr.
*/
int lcd_mk_sync_endpoint(struct task_struct *t, cptr_t c);
int lcd_mk_sync_endpoint(struct task_struct *t, cptr_t cptr);
/**
* Remove synchronous end point identified by c in t's cspace.
* Remove synchronous end point identified by cptr in t's cspace.
*/
int lcd_rm_sync_endpoint(struct task_struct *t, cptr_t c);
int lcd_rm_sync_endpoint(struct task_struct *t, cptr_t cptr);
#endif /* LCD_PROTOTYPE_API_DEFS_H */
......@@ -13,8 +13,9 @@
#include "../include/common.h"
#include "defs.h"
int __lcd_send(struct task_struct *from, cptr_t c)
int __lcd_send(struct lcd *lcd, cptr_t c)
{
return -ENOSYS;
}
......@@ -54,62 +55,80 @@ int lcd_mk_sync_endpoint(struct lcd *lcd, cptr_t c)
INIT_LIST_HEAD(&e->receivers);
mutex_init(&e->lock);
/*
* Get the destination node in the cspace
* Insert endpoint into cspace at c
*/
ret = lcd_cnode_lookup(lcd->cspace, c, &cnode);
ret = lcd_cnode_insert(lcd->cspace, c, e, LCD_CAP_TYPE_SYNC_EP,
LCD_CAP_RIGHT_ALL);
if (ret) {
LCD_ERR("cnode lookup at %lld", c);
LCD_ERR("insert endpoint");
goto fail2;
}
if (!CNODE_UNFORMED(cnode)) {
LCD_ERR("cnode occupied at %lld", c);
ret = -EINVAL;
goto fail3;
}
/*
* Install endpoint
*/
cnode->object = e;
cnode->type = CAP_TYPE_SYNC_EP;
lcd_cnode_release(cnode);
return 0;
fail3:
lcd_cnode_release(cnode);
fail2:
kfree(e);
fail1:
return ret;
}
int lcd_rm_sync_endpoint(struct lcd *lcd, cptr_t c)
static int __cleanup_sync_endpoint(struct cnode *cnode)
{
struct sync_endpoint *e;
struct cnode *cnode;
int ret = -EINVAL;
/*
* Check that cnode contains sync ep, and lcd is owner
*/
if (!__lcd_cnode_is_sync_ep(cnode))
return -EINVAL;
if (!__lcd_cnode_is_owner(cnode))
return -EINVAL;
e = __lcd_cnode_object(cnode);
/*
* Remove from cspaces first, so no one can refer to sync ep
*/
__lcd_cnode_free(cnode);
/*
* Free end point
*/
kfree(e);
return 0;
}
static int __lcd_rm_sync_endpoint(struct lcd *lcd, cptr_t cptr)
{
int ret;
/*
* Look up cnode
*/
ret = lcd_cnode_lookup(lcd->cspace, c, &cnode);
ret = __lcd_cnode_lookup(lcd->cspace, c, &cnode);
if (ret) {
LCD_ERR("cnode lookup at %lld", c);
goto fail1;
}
if (!CNODE_SYNC_EP(cnode)) {
LCD_ERR("cnode does not contain sync ep at %lld", c);
ret = -EINVAL;
goto fail2;
return ret;
}
/*
* Free end point
*
* XXX: For now, we assume no one is in line, and no one has
* the lock.
* Remove it from lcd's cspace, and recursively remove from
* any cspaces with derivations
*/
kfree(cnode->object);
return 0;
fail2:
lcd_cnode_release(cnode);
fail1:
return __cleanup_sync_endpoint(cnode);
}
int lcd_rm_sync_endpoint(struct lcd *lcd, cptr_t cptr)
{
struct cnode *cnode;
int ret;
/*
* LOCK cap
*/
ret = lcd_cap_lock();
if (ret)
return ret;
ret = __lcd_rm_sync_endpoint(lcd, cptr);
/*
* UNLOCK cap
*/
lcd_cap_unlock();
return ret;
}
......
......@@ -12,9 +12,7 @@
#define LCD_NUM_BOOT_CPTRS 8
struct cspace;
struct cap_cache;
struct dstore;
struct capability;
typedef u64 cptr_t;
struct lcd {
......@@ -23,7 +21,7 @@ struct lcd {
*/
u64 badge;
struct cspace *cspace;
struct cap_cache *cap_cache;
struct list_head
/*
* Accessible in lcd
*/
......
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