Commit 0ca33457 authored by Charlie Jacobsen's avatar Charlie Jacobsen Committed by Vikram Narayanan
Browse files

libcap-integration: Re-factor basic lcd create code in kliblcd.

Creating empty LCDs, configuring them, running them.
parent f51d50bc
......@@ -75,27 +75,27 @@ int lcd_config_registers(cptr_t lcd, gva_t pc, gva_t sp, gpa_t gva_root,
gpa_t utcb_page);
/**
* lcd_page_grant_and_map -- Grant LCD access to pages, and map it in its
* *guest physical* address space
* lcd_memory_grant_and_map -- Grant LCD access to memory object, and map it
* in its *guest physical* address space
* @lcd: the LCD to configure
* @page: cptr to pages capability in *caller* cspace
* @dest_slot: slot in LCD's cspace where pages capability copied to
* @base: starting guest physical address where chunk of pages mapped
* @mo: cptr to memory object capability in *caller* cspace
* @dest_slot: slot in LCD's cspace where capability copied/granted to
* @base: starting guest physical address where memory should be mapped
*
* This function combines two operations because we want to enforce the
* invariant that an LCD has a page mapped in its address space only if
* it has a capability to that page. (Of course, it can have capabilities
* to pages that aren't mapped.)
* invariant that an LCD has a memory mapped in its address space only if
* it has a capability to that memory. (Of course, it can have capabilities
* to memory that isn't mapped.)
*
* The caller is responsible for knowing what slots are free in the LCD's
* cspace.
*
* If the chunk of pages referenced by the pages capability does not fit
* If the memory referenced by the capability does not fit
* in the LCD's guest physical address space, starting at @base, then
* this function fails.
*/
int lcd_page_grant_and_map(cptr_t lcd, cptr_t page, cptr_t dest_slot,
gpa_t base);
int lcd_memory_grant_and_map(cptr_t lcd, cptr_t mo, cptr_t dest_slot,
gpa_t base);
/**
* lcd_cap_grant -- Grant the LCD a capability (config its cspace)
......
/*
* create.c - Basic code for creating an LCD.
*
* Copyright: University of Utah
*/
#include <liblcd.h>
#include <lcd-domains/liblcd.h>
#include "../microkernel/internal.h"
int lcd_create(cptr_t *lcd)
{
cptr_t slot;
int ret;
/*
* Alloc slot for new object
*/
ret = lcd_cptr_alloc(&slot);
if (ret) {
LIBLCD_ERR("cptr alloc failed");
goto fail1;
}
/*
* Make LCD
*/
ret = __lcd_create(current->lcd, slot);
if (ret) {
LIBLCD_ERR("lcd create failed");
goto fail2;
}
*lcd = slot;
return 0;
fail2:
lcd_cptr_free(slot);
fail1:
return ret;
}
int lcd_create_klcd(cptr_t *klcd)
{
cptr_t slot;
int ret;
/*
* Alloc slot for new object
*/
ret = lcd_cptr_alloc(&slot);
if (ret) {
LIBLCD_ERR("cptr alloc failed");
goto fail1;
}
/*
* Make kLCD
*/
ret = __lcd_create_klcd(current->lcd, slot);
if (ret) {
LIBLCD_ERR("klcd create failed");
goto fail2;
}
*lcd = slot;
return 0;
fail2:
lcd_cptr_free(slot);
fail1:
return ret;
}
int lcd_config_registers(cptr_t lcd, gva_t pc, gva_t sp, gpa_t gva_root,
gpa_t utcb_page)
{
return __lcd_config(current->lcd, lcd, pc, sp, gva_root, utcb_page);
}
int lcd_memory_grant_and_map(cptr_t lcd, cptr_t mo, cptr_t dest_slot,
gpa_t base);
{
return __lcd_memory_grant_and_map(current->lcd, lcd, mo,
dest_slot, base);
}
int lcd_cap_grant(cptr_t lcd, cptr_t src, cptr_t dest)
{
return __lcd_cap_grant(current->lcd, lcd, src, dest);
}
int lcd_run(cptr_t lcd)
{
return __lcd_run(current->lcd, lcd);
}
......@@ -13,6 +13,7 @@ int lcd_enter(void)
int ret;
struct lcd *lcd;
struct cptr_cache *cache;
cptr_t unused;
/*
* This sets up the runtime environment for non-isolated
* threads.
......@@ -48,13 +49,26 @@ int lcd_enter(void)
LCD_ERR("cptr cache init");
goto fail3;
}
/*
* Reserve first two slots for call/reply caps (just alloc them)
*/
ret = cptr_alloc(cache, &unused);
if (ret) {
LCD_ERR("cptr cache alloc1");
goto fail4;
}
ret = cptr_alloc(cache, &unused);
if (ret) {
LCD_ERR("cptr cache alloc2");
goto fail5;
}
/*
* Create our call endpoint (for receiving rpc replies)
*/
ret = __lcd_create_sync_endpoint(current->lcd, LCD_CPTR_CALL_ENDPOINT);
if (ret) {
LCD_ERR("creating call endpoint");
goto fail4;
goto fail6;
}
return 0;
......
......@@ -159,7 +159,7 @@ fail1:
return ret;
}
int __klcd_create_klcd(struct lcd *caller, cptr_t slot)
int __lcd_create_klcd(struct lcd *caller, cptr_t slot)
{
struct lcd *lcd;
int 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