Commit f2609e2e authored by Anton Burtsev's avatar Anton Burtsev Committed by Vikram Narayanan

More general introduction code, but still lame

parent 13a4545c
......@@ -13,4 +13,108 @@ int register_server(struct server_interface *server) {
}
/* Callee stubs */
int register_server_callee(struct server_interface *server) {
}
/* Main execution loop */
int execution_loop(void) {
int ret;
capability_t api_cap = current->utcb->boot_info.boot_caps[LCD_BOOT_API_CAP];
capability_t reply_cap = current->utcb->boot_info.boot_caps[LCD_BOOT_REPLY_CAP];
capability_t server = current->utcb->boot_info.boot_caps[LCD_BOOT_FREE_CAP0];
capability_t server_interface;
capability_t server_reply;
struct message_info *msg = &current->utcb->msg_info;
ret = lcd_alloc_cap(&current->cap_cache, &server_interface);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
};
msg->cap_regs[0] = server_interface;
msg->valid_cap_regs = 1;
ret = ipc_recv(server, msg);
if (ret) {
printk(KERN_ERR "client failed to receive from the server:%d\n", ret);
return ret;
};
call = msg->regs[0];
switch (call) {
case LCD_CREATE_SYNC_ENDPOINT:
ret = lcd_api_create_sync_endpoint(lcd_api, reply_cap);
break;
default:
printk(KERN_ERR "lcd_api: invalid call number:%d\n", call);
msg->valid_regs = 0;
msg->valid_cap_regs = 0;
ipc_reply(reply_cap, msg);
lcd_cap_drop(&current->cspace, reply_cap);
};
return 0;
};
struct sync_ipc *client_server_rvp;
int accept_client_introduction(void) {
return lcd_accept_introduction(&client_server_rvp,
&current->utcb->boot_info.boot_caps[LCD_BOOT_FREE_CAP0]);
};
EXPORT_SYMBOL(accept_client_introduction);
int execution_loop_thread(void *p) {
int ret;
ret = lcd_init_current();
if (ret) {
printk(KERN_ERR "Failed to init current thread with LCD:%d\n", ret);
return -EINVAL;
}
ret = lcd_prepare_introduction(lcd_api_cap(),
lcd_api_reply_cap(),
&client_server_rvp,
&current->utcb->boot_info.boot_caps[LCD_BOOT_FREE_CAP0]);
if (ret) {
printk(KERN_ERR "client failed to initialize client-server environtment\n");
return -EINVAL;
}
/* Introduction code */
ret = lcd_prepare_introduction(&client_server_rvp);
if (ret) {
printk(KERN_ERR "client failed to initialize client-server environtment\n");
return -EINVAL;
}
return execution_loop();
};
int execution_loop_thread_init(void) {
struct task_struct *t;
t = kthread_create(execution_loop_thread, NULL, "cs-client");
if (!t) {
printk(KERN_ERR "Failed to create module thread\n");
return -EINVAL;
};
wake_up_process(t);
return 0;
}
struct sync_ipc *rvp;
int lcd_client_server_init_client(void) {
int ret;
capability_t server;
struct cnode *cnode;
ret = lcd_enter();
if (ret) {
printk(KERN_ERR "Failed to enter LCD environment\n");
return ret;
};
ret = lcd_api_connect(lcd_get_api());
if (ret) {
printk(KERN_ERR "Failed to connect to LCD API\n");
return ret;
};
api_cap = current->utcb->boot_info.boot_caps[LCD_BOOT_API_CAP];
reply_cap = current->utcb->boot_info.boot_caps[LCD_BOOT_REPLY_CAP];
ret = lcd_alloc_cap(&current->cap_cache, &server);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
};
ret = lcd_api_create_sync_endpoint(api_cap, reply_cap, server);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
};
current->utcb->boot_info.boot_caps[LCD_BOOT_FREE_CAP0] = server;
cnode = lcd_cnode_lookup(&current->cspace, server);
if(cnode == NULL || cnode->type != LCD_TYPE_SYNC_EP) {
printk(KERN_ERR "Failed to create capability\n");
return -ENOMEM;
};
rvp = cnode->object;
lcd_cnode_release(cnode);
return 0;
};
int lcd_client_server_init_server(void)
{
int ret;
capability_t client;
ret = lcd_enter();
if (ret) {
printk(KERN_ERR "Failed to enter LCD environment\n");
return ret;
};
ret = lcd_api_connect(lcd_get_api());
if (ret) {
printk(KERN_ERR "Failed to connect to LCD API\n");
return ret;
};
ret = lcd_alloc_cap(&current->cap_cache, &client);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
};
lcd_cap_insert_object(&current->cspace, client, rvp, LCD_TYPE_SYNC_EP);
current->utcb->boot_caps[LCD_BOOT_FREE_CAP0] = client;
return 0;
};
EXPORT_SYMBOL(lcd_client_server_init_server);
int module_execution_loop(void) {
int ret;
capability_t api_cap = current->utcb->boot_info.boot_caps[LCD_BOOT_API_CAP];
capability_t reply_cap = current->utcb->boot_info.boot_caps[LCD_BOOT_REPLY_CAP];
capability_t server = current->utcb->boot_info.boot_caps[LCD_BOOT_FREE_CAP0];
capability_t server_interface;
capability_t server_reply;
struct message_info *msg = &current->utcb->msg_info;
ret = lcd_alloc_cap(&current->cap_cache, &server_interface);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
};
msg->cap_regs[0] = server_interface;
msg->valid_cap_regs = 1;
ret = ipc_recv(server, msg);
if (ret) {
printk(KERN_ERR "client failed to receive from the server:%d\n", ret);
return ret;
};
call = msg->regs[0];
switch (call) {
case LCD_CREATE_SYNC_ENDPOINT:
ret = lcd_api_create_sync_endpoint(lcd_api, reply_cap);
break;
default:
printk(KERN_ERR "lcd_api: invalid call number:%d\n", call);
msg->valid_regs = 0;
msg->valid_cap_regs = 0;
ipc_reply(reply_cap, msg);
lcd_cap_drop(&current->cspace, reply_cap);
};
return 0;
};
int lcd_thread(void *p) {
int ret;
ret = lcd_client_server_init_client();
if (ret) {
printk(KERN_ERR "client failed to initialize client-server environtment\n");
return -EINVAL;
}
return lcd_execution_loop();
};
int lcd_thread_init(void) {
struct task_struct *t;
t = kthread_create(lcd_thread, NULL, "cs-client");
if (!t) {
printk(KERN_ERR "Failed to create module thread\n");
return -EINVAL;
};
wake_up_process(t);
return 0;
}
......@@ -9,6 +9,8 @@
#include <lcd/cap.h>
#include <lcd/ipc.h>
#include <lcd/cap-cache.h>
#include <lcd/boot.h>
#include <lcd/sched.h>
struct lcd_api {
bool exit_flag;
......@@ -16,6 +18,13 @@ struct lcd_api {
struct sync_ipc *ep;
};
static inline capability_t lcd_api_cap() {
return current->utcb->boot_info.boot_caps[LCD_BOOT_API_CAP];
};
static inline capability_t lcd_api_reply_cap() {
return current->utcb->boot_info.boot_caps[LCD_BOOT_REPLY_CAP];
};
int lcd_api_init(struct lcd_api *api);
int lcd_api_exit(struct lcd_api *api);
......
/*
* Author: Anton Burtsev <aburtsev@flux.utah.edu>
* Copyright: University of Utah
*
*/
#ifndef _LCD_FACTORY_H_
#define _LCD_FACTORY_H_
#include <lcd/cap.h>
#include <lcd/ipc.h>
int lcd_prepare_introduction(capability_t api_cap, capabiity_t reply_cap, sync_ipc *rvp, capability_t *rvp_cap);
int lcd_accept_introduction(struct sync_ipc *rvp, capability_t *rvp_cap);
#endif
......@@ -105,8 +105,11 @@ int lcd_find_hva_by_gpa(struct lcd *lcd, u64 gpa, u64 *hva);
int lcd_run(struct lcd *lcd);
const char* lcd_exit_reason(int exit_code);
int lcd_enter(void);
int lcd_api_connect(struct lcd_api *api);
struct lcd_api *lcd_get_api(void);
int lcd_init_current(void);
#endif /* LCD_LCD_H */
......@@ -31,6 +31,7 @@ struct lcd_api *lcd_get_api(void) {
};
EXPORT_SYMBOL(lcd_get_api);
int lcd_enter(void) {
int ret;
......@@ -91,6 +92,26 @@ int lcd_api_connect(struct lcd_api *api) {
};
EXPORT_SYMBOL(lcd_api_connect);
int lcd_init_current(void) {
int ret;
struct cnode *cnode;
ret = lcd_enter();
if (ret) {
printk(KERN_ERR "Failed to enter LCD environment\n");
return ret;
};
ret = lcd_api_connect(lcd_get_api());
if (ret) {
printk(KERN_ERR "Failed to connect to LCD API\n");
return ret;
};
return 0;
};
EXPORT_SYMBOL(lcd_init_current);
static long lcd_dev_ioctl(struct file *filp ,
unsigned int ioctl, unsigned long arg)
{
......
/*
* Author: Anton Burtsev <aburtsev@flux.utah.edu>
* Copyright: University of Utah
*
* Factories provide a safe way to create LCDs with a controlled set of
* capabilities. Right now I don't know how the factory code will look. For
* now it's just a couple of dumb introduction functions.
*/
int lcd_prepare_introduction(capability_t api_cap, capabiity_t reply_cap, sync_ipc *rvp, capability_t *rvp_cap) {
ret = lcd_alloc_cap(&current->cap_cache, rvp_cap);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
};
ret = lcd_api_create_sync_endpoint(api_cap, reply_cap, *rvp_cap);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
};
cnode = lcd_cnode_lookup(&current->cspace, server);
if(cnode == NULL || cnode->type != LCD_TYPE_SYNC_EP) {
printk(KERN_ERR "Failed to create capability\n");
return -ENOMEM;
};
rvp = cnode->object;
lcd_cnode_release(cnode);
return 0;
};
int lcd_accept_introduction(struct sync_ipc *rvp, capability_t *rvp_cap) {
int ret;
ret = lcd_alloc_cap(&current->cap_cache, rvp_cap);
if(ret) {
printk(KERN_ERR "Failed to allocate free capability\n");
return -ENOSPC;
};
return lcd_cap_insert_object(&current->cspace, *rvp_cap, rvp, LCD_TYPE_SYNC_EP);
};
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