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

update-glue-example: glue_example runs, but one mysterious bug at end.

parent 1ca6f5fa
......@@ -20,13 +20,14 @@ static struct lcd_resource_tree itree;
static struct lcd_resource_node boot_nodes[LCD_NR_BOOT_RESOURCE_NODES];
static unsigned int boot_nodes_brk;
static int mem_itree_booted;
static struct kmem_cache *node_cache;
static void free_itree_node(struct lcd_resource_node *n)
{
if (n->flags & LCD_RESOURCE_NODE_STATIC)
return; /* node came from boot node array */
else
kfree(n);
kmem_cache_free(node_cache, n);
}
static struct lcd_resource_node *early_alloc_itree_node(void)
......@@ -49,14 +50,22 @@ static struct lcd_resource_node *alloc_itree_node(void)
* here when it is growing itself (alloc'ing fresh
* pages, and inserting the cptr into the resource tree).
* This call to kzalloc may recursively lead *back into*
* the heap to grow a slab cache for kmalloc. This
* recursion is OK because of how the heap maps the
* the heap to grow our kmem_cache. This
* recursion is OK because (1) of how the heap maps the
* new pages (it maps them first *before* inserting them
* into the mem itree). See ram_map.c:_lcd_mmap.
* into the mem itree; see ram_map.c:_lcd_mmap); (2) even
* if this call to zalloc leads to *another* call back in
* here, the recursion should bottom out on the second
* call because the slab cache shouldn't need to grow
* by much.
*
* Furthermore, we are using a slab cache separated from
* the rest of the code (so we can't screw up someone
* else calling kmalloc, etc.).
*/
n = kzalloc(sizeof(struct lcd_resource_node), GFP_KERNEL);
n = kmem_cache_zalloc(node_cache, GFP_KERNEL);
if (!n) {
LIBLCD_ERR("kmalloc failed");
LIBLCD_ERR("alloc failed");
return NULL;
}
n->flags = LCD_RESOURCE_NODE_KMALLOC;
......@@ -148,6 +157,10 @@ int lcd_virt_to_cptr(gva_t vaddr, cptr_t *c_out, unsigned long *size_out)
void __liblcd_mem_itree_booted(void)
{
mem_itree_booted = 1;
/*
* Set up kmem cache
*/
node_cache = KMEM_CACHE(lcd_resource_node, 0);
}
static int add_boot_memory(void)
......
......@@ -459,10 +459,16 @@ static int main_for_lcd(struct lcd *lcd)
*/
for (;;) {
ret = run_once(lcd, &lcd_ret);
if (ret < 0 || should_stop(lcd)) {
if (ret < 0) {
/* ret < 0 means fatal error */
/* lcd_should_stop means our parent told us to die */
LCD_MSG("LCD 0x%p exited with error %d; program counter at exit was: 0x%llx\n",
lcd, lcd_arch_get_pc(lcd->lcd_arch));
return ret;
} else if (should_stop(lcd)) {
/* ret < 0 means fatal error */
LCD_MSG("LCD 0x%p stopped; program counter at exit was: 0x%llx\n",
lcd, lcd_arch_get_pc(lcd->lcd_arch));
return 0;
} else if (ret == 1) {
/* lcd exited */
return lcd_ret;
......
......@@ -5,7 +5,7 @@ export ISOLATE_GLUE_EXAMPLE=y
ifeq ($(ISOLATE_GLUE_EXAMPLE),y)
obj-m += isol_boot/
obj-m += boot/
ISOLATED_CC_FLAGS += -DISOLATE_GLUE_EXAMPLE
endif
......
......@@ -73,14 +73,26 @@ int glue_vfs_init(cptr_t _vfs_channel, struct dispatch_ctx *ctx)
* on it later. */
vfs_chnl = _vfs_channel;
/* Initialize cap code */
ret = vfs_cap_init();
if (ret) {
LIBLCD_ERR("init cap code");
goto fail1;
}
/* Initialize data store. */
ret = vfs_cap_create(&vfs_cspace);
if (ret) {
LIBLCD_ERR("cspace init");
return ret;
goto fail2;
}
return 0;
fail2:
vfs_cap_exit();
fail1:
return ret;
}
/* EXIT -------------------------------------------------- */
......@@ -94,6 +106,9 @@ void glue_vfs_exit(void)
{
/* Free vfs data store. */
vfs_cap_destroy(vfs_cspace);
/* Tear down cap code */
vfs_cap_exit();
}
/* REGISTER_FS -------------------------------------------------- */
......@@ -555,6 +570,8 @@ void rm_file_callee(void)
* from the glue cspace though (it's ok to do this after the
* container was freed). */
printk("glue sizeof file_container is 0x%lx", sizeof(*file_container));
vfs_cap_remove(vfs_cspace, file_ref);
/* IPC MARSHALING ---------------------------------------- */
......
......@@ -32,9 +32,11 @@ static int minix_new_file(int id, struct file **file_out) {
return -EINVAL;
}
printk("sizeof file_container is 0x%lx", sizeof(*file_container));
#ifdef ISOLATE_GLUE_EXAMPLE
f = NULL;
file_container = kmalloc(sizeof(*f), GFP_KERNEL);
file_container = kmalloc(sizeof(*file_container), GFP_KERNEL);
if (file_container)
f = &file_container->file;
#else
......@@ -62,7 +64,6 @@ static void minix_rm_file(struct file *file) {
kfree(file);
return;
}
#ifdef ISOLATE_GLUE_EXAMPLE
......
......@@ -624,14 +624,26 @@ int glue_vfs_init(cptr_t vfs_chnl, struct dispatch_ctx *ctx)
/* Add it to dispatch loop */
loop_add_channel(loop_ctx, &vfs_channel);
/* Initialize cap code */
ret = vfs_cap_init();
if (ret) {
LIBLCD_ERR("init cap code");
goto fail1;
}
/* Initialize minix data store */
ret = vfs_cap_create(&minix_cspace);
if (ret) {
LIBLCD_ERR("cspace init");
return ret;
goto fail2;
}
return 0;
fail2:
vfs_cap_exit();
fail1:
return ret;
}
void glue_vfs_exit(void)
......@@ -642,4 +654,7 @@ void glue_vfs_exit(void)
* it doesn't matter in this simple example. (In general, we
* probably should.) */
loop_rm_channel(loop_ctx, &vfs_channel);
/* Tear down cap code */
vfs_cap_exit();
}
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