Commit 88d7b8c9 authored by Josh Kunz's avatar Josh Kunz

Expose cnode metadata in libcap interface

This adds a 'metadata' argument to cap_grant, and cap_insert that allows
the caller to set the `metadata` field of a cnode atomically on
creation.
parent e9f2b41d
Pipeline #928 passed with stage
......@@ -594,7 +594,7 @@ static void __cap_cnode_mark_free(struct cnode * cnode) {
}
int cap_insert(struct cspace *cspace, cptr_t c, void *object, cap_type_t type)
int cap_insert(struct cspace *cspace, cptr_t c, void *object, cap_type_t type, void *metadata)
{
struct cnode *cnode;
int ret;
......@@ -618,7 +618,7 @@ int cap_insert(struct cspace *cspace, cptr_t c, void *object, cap_type_t type)
cnode->cspace = cspace;
cnode->object = object;
cnode->type = type;
//cnode->cptr = c;
cap_cnode_set_metadata(cnode, metadata);
/*
* Set up cdt
......@@ -864,6 +864,11 @@ fail3:
return ret;
}
struct __cap_grant_args {
void * metadata;
cap_type_t * o_type;
};
static void __cap_try_grant_cnode_copy(struct cnode *src, struct cnode *dst,
bool do_list) {
dst->type = src->type;
......@@ -872,7 +877,8 @@ static void __cap_try_grant_cnode_copy(struct cnode *src, struct cnode *dst,
if (do_list) { dst->siblings = src->siblings; }
}
static int __cap_try_grant(struct cnode *src, struct cnode *dst, void * o_type) {
static int __cap_try_grant(struct cnode *src, struct cnode *dst, void * args_) {
struct __cap_grant_args * args = (struct __cap_grant_args *) args_;
int ret;
if (!__cap_cnode_is_used(src)) {
CAP_ERR("bad source cnode, type = %d", src->type);
......@@ -903,12 +909,14 @@ static int __cap_try_grant(struct cnode *src, struct cnode *dst, void * o_type)
__cap_try_grant_cnode_copy(src, dst, false);
cap_cnode_set_metadata(dst, args->metadata);
/* Invoke the grant callback for this cnode type. No additional locking
* of the ts is needed because all ts updated are additive. */
ret = __cap_notify_grant(src, dst);
/* Notify the caller about the type of the granted node */
*((cap_type_t *) o_type) = cap_cnode_type(src);
*args->o_type = cap_cnode_type(src);
if (ret < 0) { /* rollback */
CAP_ERR("grant callback aborted grant. code = %d, type = %d", ret, src->type);
......@@ -1238,8 +1246,13 @@ int cap_derive(struct cspace *cspacesrc, cptr_t c_src,
int cap_grant(struct cspace *cspacesrc, cptr_t c_src,
struct cspace *cspacedst, cptr_t c_dst,
void * dst_metadata,
cap_type_t * type) {
return __cap_cnode_binop(cspacesrc, c_src, cspacedst, c_dst, type,
struct __cap_grant_args args = {
.metadata = dst_metadata,
.o_type = type
};
return __cap_cnode_binop(cspacesrc, c_src, cspacedst, c_dst, (void *) &args,
"cap_grant", __cap_try_grant);
}
......
......@@ -374,7 +374,7 @@ struct cap_type_system* cap_cspace_get_type_system(struct cspace *cspace);
*
* If the slot is already occupied, or @c is invalid, returns non-zero.
*/
int cap_insert(struct cspace *cspace, cptr_t c, void *object, cap_type_t type);
int cap_insert(struct cspace *cspace, cptr_t c, void *object, cap_type_t type, void *metadata);
/**
* cap_delete -- Deletes object data from cspace at cnode pointed at by c
* @cspace: the cspace to delete capability from
......@@ -407,6 +407,7 @@ int cap_derive(struct cspace *cspacesrc, cptr_t c_src,
* @c_src: the cptr to the slot/capability in the source cspace
* @cspacedst: the destination cspace
* @c_dst: the cptr to the slot in the destination cspace to grant to
* @dst_metadata: The metadata for the granted cnode. Can be NULL.
* @type: The type of the granted cptr, this is an output argument.
*
* Copies cnode data in src cnode at c_src to dest cnode at c_dst. The dest
......@@ -414,12 +415,10 @@ int cap_derive(struct cspace *cspacesrc, cptr_t c_src,
*
* IMPORTANT: If the source and destination cspaces have different type
* systems (the check is done for *pointer equality*), then grant fails.
*
* Note: Metadata pointers *are not* carried over to the destination slot (the
* destination slot will start out with NULL metadata).
*/
int cap_grant(struct cspace *cspacesrc, cptr_t c_src,
struct cspace *cspacedst, cptr_t c_dst,
struct cspace *cspacedst, cptr_t c_dst,
void *dst_metadata,
cap_type_t *type);
/**
......
......@@ -84,7 +84,7 @@ int testcase1()
/* Insert capability in cspace */
printf("\nTestCase : Add Capability to Cspace.\n");
ret = cap_insert(csp, slot_out, p, stringobj_type);
ret = cap_insert(csp, slot_out, p, stringobj_type, NULL);
if (ret < 0) {
CAP_ERR("cap insertion failed\n");
......@@ -125,7 +125,7 @@ int testcase1()
* try to insert capability in cspace. Following call should
* return error.
*/
ret = cap_insert(csp, slot_out, p, stringobj_type);
ret = cap_insert(csp, slot_out, p, stringobj_type, NULL);
if (ret)
printf("Cspace Deletion Passed\n");
......@@ -185,7 +185,7 @@ int testcase_grant()
}
p = strdup("testcase_grant");
/* Insert capability in cspace */
ret = cap_insert(scsp, sslot, p, stringobj_type);
ret = cap_insert(scsp, sslot, p, stringobj_type, NULL);
if (ret) {
CAP_ERR("cap insertion failed\n");
goto destroy_scache;
......@@ -220,7 +220,7 @@ int testcase_grant()
goto destroy_dcache;
}
ret = cap_grant(scsp, sslot, dcsp, dslot, &type);
ret = cap_grant(scsp, sslot, dcsp, dslot, NULL, &type);
if (ret < 0) {
printf("Granting capability failed\n");
goto destroy_dcache;
......@@ -272,7 +272,7 @@ int insert(struct cspace *csp, cptr_t slot)
}
snprintf(p,5,"icap");
ret = cap_insert(csp, slot, p, stringobj_type);
ret = cap_insert(csp, slot, p, stringobj_type, NULL);
if (ret < 0) {
CAP_ERR("cap insertion failed\n");
}
......@@ -288,7 +288,7 @@ int grant(struct cspace *scsp, struct cspace *dcsp, cptr_t sslot, cptr_t dslot)
int ret = 0;
cap_type_t type;
ret = cap_grant(scsp, sslot, dcsp, dslot, &type);
ret = cap_grant(scsp, sslot, dcsp, dslot, NULL, &type);
if (ret < 0)
printf("Granting capability failed\n");
......
......@@ -91,7 +91,7 @@ int insert(struct cspace *csp, cptr_t slot)
/* using global could lead to race */
snprintf(p, 32, "stringobj%d", next);
ret = cap_insert(csp, slot, p, stringobj_type);
ret = cap_insert(csp, slot, p, stringobj_type, NULL);
if (ret < 0) {
CAP_ERR("cap insertion failed\n");
return ret;
......@@ -204,7 +204,7 @@ void *thread_grant(void *arg) {
printf("Thread Grant : unstalled cptr slot %d (0x%lx)\n",
i,cptr_val(sslot_arr[i]));
}
ret = cap_grant(scsp, sslot_arr[i], dcsp, dslot, &type);
ret = cap_grant(scsp, sslot_arr[i], dcsp, dslot, NULL, &type);
if (ret < 0) {
printf("Granting capability failed\n");
} else
......
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