Commit e66e5d4f authored by Charles Jacobsen's avatar Charles Jacobsen Committed by Vikram Narayanan

test-v2: string_example checkpoint: need to fix resource trees.

parent 5bc7d324
......@@ -82,11 +82,12 @@ static int do_grant_and_map_for_mem(cptr_t lcd, struct lcd_create_ctx *ctx,
{
int ret;
cptr_t mo;
unsigned long size;
unsigned long size, offset;
/*
* Look up the cptr for the *creator*
*/
ret = lcd_virt_to_cptr(__gva((unsigned long)mem), &mo, &size);
ret = lcd_virt_to_cptr(__gva((unsigned long)mem), &mo, &size,
&offset);
if (ret) {
LIBLCD_ERR("lookup failed");
goto fail1;
......
......@@ -350,4 +350,9 @@ struct lcd_boot_info {
#define LCD_PRINTK_BUFF_SIZE 512
/* EXTRA ERRORS ------------------------------------------------------------ */
#define EALREADYMAPPED (512)
#endif /* LCD_DOMAINS_TYPES_H */
......@@ -154,7 +154,8 @@ static int mo_in_trees(struct task_struct *t, struct lcd_memory_object *mo)
}
static void mo_remove_from_tree(struct lcd_resource_tree *tree,
struct lcd_memory_object *mo)
struct lcd_memory_object *mo,
cptr_t mo_cptr)
{
struct lcd_resource_node *node;
int ret;
......@@ -292,37 +293,34 @@ static int do_map(struct lcd *lcd, struct lcd_memory_object *mo,
{
int ret;
/*
* Check if it's already in a resource tree
* "Map" in physical address space (this only marks the
* memory as mapped for non-isolated code right now)
*/
if (mo_in_trees(current, mo)) {
LIBLCD_ERR("memory object already mapped");
ret = -EINVAL;
ret = __lcd_do_map_memory_object(lcd, mo, cap_cnode_metadata(cnode),
__gpa(0));
if (ret) {
LIBLCD_ERR("physical map failed");
goto fail1;
}
/*
* No; put it in the correct one, depending on its type
* Insert into proper resource tree, depending on its type
*
* XXX: If the same memory object gets inserted more than
* once, we can end up with duplicates in the trees. This occurs
* when non-isolated code has multiple capabilities to the
* same memory object. This is OK for now (address -> cptr
* translation just needs some cptr, size, offset, etc.).
*/
ret = mo_insert_in_trees(current, mo, mo_cptr);
if (ret) {
LIBLCD_ERR("insert into resource tree failed");
goto fail2;
}
/*
* "Map" in physical address space (this is a no-op for
* non-isolated code right now)
*/
ret = __lcd_do_map_memory_object(lcd, mo, cap_cnode_metadata(cnode),
__gpa(0));
if (ret) {
LIBLCD_ERR("physical map failed");
goto fail3;
}
return 0;
fail3:
mo_remove_from_trees(current, mo);
fail2:
__lcd_do_unmap_memory_object(lcd, mo, cap_cnode_metadata(cnode));
fail1:
return ret;
}
......@@ -344,7 +342,7 @@ static void do_phys_unmap(struct lcd *lcd, struct lcd_memory_object *mo,
/*
* Remove from resource trees
*/
mo_remove_from_trees(current, mo);
mo_remove_from_trees(current, mo, cap_cnode_cptr(mo_cnode));
/*
* "Unmap" from physical address space (this is a no-op for
* non-isolated code right now)
......@@ -940,7 +938,8 @@ int lcd_virt_to_resource_node(gva_t vaddr, struct lcd_resource_node **n)
return virt_to_resource_node(vaddr, n, &unused);
}
int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned long *size_out)
int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned long *size_out,
unsigned long *offset_out)
{
struct lcd_resource_node *n;
int ret;
......
......@@ -154,9 +154,11 @@ int lcd_phys_to_cptr(gpa_t paddr, cptr_t *c_out, unsigned long *size_out,
return 0;
}
int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned long *size_out)
int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned long *size_out,
unsigned long *offset_out)
{
return lcd_phys_to_cptr(lcd_gva2gpa(vaddr), c_out, size_out);
return lcd_phys_to_cptr(lcd_gva2gpa(vaddr), c_out, size_out,
offset_out);
}
/* INIT -------------------------------------------------- */
......
......@@ -489,8 +489,7 @@ int __lcd_do_map_memory_object(struct lcd *lcd,
}
}
if (meta->is_mapped) {
LCD_ERR("memory object already mapped");
ret = -EINVAL;
ret = -EALREADYMAPPED;
goto out;
}
/*
......@@ -508,8 +507,7 @@ int __lcd_do_map_memory_object(struct lcd *lcd,
* physical is available to non-isolated code. Recall that
* this function is about mapping in physical, not virtual.)
*/
ret = 0;
goto out;
break;
default:
LCD_ERR("unrecognized lcd type %d", lcd->type);
ret = -EINVAL;
......@@ -519,6 +517,9 @@ int __lcd_do_map_memory_object(struct lcd *lcd,
goto out;
/*
* Mark page as mapped, and where it's mapped
*
* (So that isolated and non-isolated code have the same semantics
* here, in both cases we indicate the memory object as mapped.)
*/
meta->is_mapped = 1;
meta->where_mapped = base;
......@@ -642,7 +643,7 @@ void __lcd_do_unmap_memory_object(struct lcd *caller,
* physical is available to non-isolated code. Recall that
* this function is about unmapping in physical, not virtual.)
*/
return;
break;
default:
LCD_ERR("unrecognized lcd type %d", caller->type);
return;
......
......@@ -35,7 +35,7 @@ static int do_recv(cptr_t endpoint, char **data)
*/
offset = lcd_r0();
/*
* Map page
* Try to map page
*/
ret = lcd_map_virt(page_cptr, 0, &page);
if (ret) {
......
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