Skip to content

Commit

Permalink
Type cleanups to remove reserved _t namings. See #76 (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkohlbre authored May 10, 2019
1 parent 215b544 commit c22b97d
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 54 deletions.
10 changes: 5 additions & 5 deletions lib/edge/include/edge_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ int edge_call_get_ptr_from_offset(edge_data_offset offset, size_t data_len,
int edge_call_get_offset_from_ptr(uintptr_t ptr, size_t data_len,
edge_data_offset* offset);

int edge_call_args_ptr(edge_call_t* edge_call, uintptr_t* ptr);
int edge_call_ret_ptr(edge_call_t* edge_call, uintptr_t* ptr);
int edge_call_args_ptr(struct edge_call* edge_call, uintptr_t* ptr);
int edge_call_ret_ptr(struct edge_call* edge_call, uintptr_t* ptr);
uintptr_t edge_call_data_ptr();
int edge_call_setup_call(edge_call_t* edge_call, void* ptr, size_t size);
int edge_call_setup_ret(edge_call_t* edge_call, void* ptr, size_t size);
int edge_call_setup_wrapped_ret(edge_call_t* edge_call, void* ptr, size_t size);
int edge_call_setup_call(struct edge_call* edge_call, void* ptr, size_t size);
int edge_call_setup_ret(struct edge_call* edge_call, void* ptr, size_t size);
int edge_call_setup_wrapped_ret(struct edge_call* edge_call, void* ptr, size_t size);

void incoming_call_dispatch(void* buffer);

Expand Down
18 changes: 9 additions & 9 deletions lib/edge/include/edge_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ extern uintptr_t _shared_start;
extern size_t _shared_len;

/* Useful type for things like packaged strings, etc */
typedef struct edge_data_t{
struct edge_data{
edge_data_offset offset;
size_t size;
} edge_data_t;
};

typedef struct edge_app_retdata_t {
struct edge_app_retdata {
void* app_ptr;
size_t len;
} edge_app_retdata_t;
};

typedef struct edge_return_t{
struct edge_return{

/* Status variable indicating error/success conditions. Not for data
values. */
Expand All @@ -56,9 +56,9 @@ typedef struct edge_return_t{
* structure for the call. (User/call defined) */
edge_data_offset call_ret_offset;
size_t call_ret_size;
} edge_return_t;
};

typedef struct edge_call_t{
struct edge_call{
/* Similar to syscall number. User-defined call id, handled at the
* edges only */
unsigned long call_id;
Expand All @@ -70,8 +70,8 @@ typedef struct edge_call_t{
size_t call_arg_size;

/* Pre-set location to structure return data */
edge_return_t return_data;
} edge_call_t;
struct edge_return return_data;
};



Expand Down
6 changes: 3 additions & 3 deletions lib/edge/include/edge_syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ extern "C" {
// Special call number
#define EDGECALL_SYSCALL MAX_EDGE_CALL+1

typedef struct edge_syscall_t{
struct edge_syscall{
size_t syscall_num;
unsigned char data[];
} edge_syscall_t;
};

typedef struct sargs_SYS_openat{
int dirfd;
Expand Down Expand Up @@ -64,7 +64,7 @@ typedef struct sargs_SYS_fstatat{
char pathname[];
} sargs_SYS_fstatat;

void incoming_syscall(edge_call_t* buffer);
void incoming_syscall(struct edge_call* buffer);

#ifdef __cplusplus
}
Expand Down
30 changes: 15 additions & 15 deletions lib/edge/src/edge_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,53 +72,53 @@ int edge_call_get_offset_from_ptr(uintptr_t ptr, size_t data_len,
}


int edge_call_args_ptr(edge_call_t* edge_call, uintptr_t* ptr){
int edge_call_args_ptr(struct edge_call* edge_call, uintptr_t* ptr){

return edge_call_get_ptr_from_offset(edge_call->call_arg_offset,
edge_call->call_arg_size, ptr);
}

int edge_call_ret_ptr(edge_call_t* edge_call, uintptr_t* ptr){
int edge_call_ret_ptr(struct edge_call* edge_call, uintptr_t* ptr){
return edge_call_get_ptr_from_offset(edge_call->return_data.call_ret_offset,
edge_call->return_data.call_ret_size, ptr);
}

int edge_call_setup_call(edge_call_t* edge_call, void* ptr, size_t size){
int edge_call_setup_call(struct edge_call* edge_call, void* ptr, size_t size){
edge_call->call_arg_size = size;
return edge_call_get_offset_from_ptr((uintptr_t)ptr, size,
&edge_call->call_arg_offset);
}

int edge_call_setup_ret(edge_call_t* edge_call, void* ptr, size_t size){
int edge_call_setup_ret(struct edge_call* edge_call, void* ptr, size_t size){
edge_call->return_data.call_ret_size = size;
return edge_call_get_offset_from_ptr((uintptr_t)ptr, size,
&edge_call->return_data.call_ret_offset);
}

/* This is only usable for the host */
int edge_call_setup_wrapped_ret(edge_call_t* edge_call, void* ptr, size_t size){
edge_data_t data_wrapper;
int edge_call_setup_wrapped_ret(struct edge_call* edge_call, void* ptr, size_t size){
struct edge_data data_wrapper;
data_wrapper.size = size;
edge_call_get_offset_from_ptr(_shared_start+sizeof(edge_call_t)+sizeof(edge_data_t),
sizeof(edge_data_t),
edge_call_get_offset_from_ptr(_shared_start+sizeof(struct edge_call)+sizeof(struct edge_data),
sizeof(struct edge_data),
&data_wrapper.offset);

memcpy((void*)(_shared_start+sizeof(edge_call_t)+sizeof(edge_data_t)),
memcpy((void*)(_shared_start+sizeof(struct edge_call)+sizeof(struct edge_data)),
ptr,
size);

memcpy((void*)(_shared_start+sizeof(edge_call_t)),
memcpy((void*)(_shared_start+sizeof(struct edge_call)),
&data_wrapper,
sizeof(edge_data_t));
sizeof(struct edge_data));

edge_call->return_data.call_ret_size = sizeof(edge_data_t);
return edge_call_get_offset_from_ptr(_shared_start+sizeof(edge_call_t),
sizeof(edge_data_t),
edge_call->return_data.call_ret_size = sizeof(struct edge_data);
return edge_call_get_offset_from_ptr(_shared_start+sizeof(struct edge_call),
sizeof(struct edge_data),
&edge_call->return_data.call_ret_offset);
}


/* This is temporary until we have a better way to handle multiple things */
uintptr_t edge_call_data_ptr(){
return _shared_start + sizeof(edge_call_t);
return _shared_start + sizeof(struct edge_call);
}
2 changes: 1 addition & 1 deletion lib/edge/src/edge_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edgecallwrapper edge_call_table[MAX_EDGE_CALL];

/* Registered handler for incoming edge calls */
void incoming_call_dispatch(void* buffer){
struct edge_call_t* edge_call = (struct edge_call_t*) buffer;
struct edge_call* edge_call = (struct edge_call*) buffer;

#ifdef IO_SYSCALL_WRAPPING
/* If its a syscall handle it specially */
Expand Down
6 changes: 2 additions & 4 deletions lib/edge/src/edge_syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
#include <unistd.h>
#include <stdio.h>
// Special edge-call handler for syscall proxying
void incoming_syscall(edge_call_t* edge_call){
void incoming_syscall(struct edge_call* edge_call){



edge_syscall_t* syscall_info;
struct edge_syscall* syscall_info;

if( edge_call_args_ptr(edge_call, (uintptr_t*)&syscall_info) != 0)
goto syscall_error;
Expand Down
2 changes: 1 addition & 1 deletion runtime
Submodule runtime updated 12 files
+1 −1 boot.c
+1 −1 freemem.c
+2 −2 freemem.h
+1 −1 interrupt.c
+20 −20 io_wrap.c
+17 −17 mm.c
+3 −3 regs.h
+2 −2 rt_util.c
+1 −1 rt_util.h
+4 −4 syscall.c
+2 −2 syscall.h
+10 −10 vm.h
18 changes: 9 additions & 9 deletions tests/edge_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,30 @@ void print_buffer_wrapper(void* buffer)
{
/* For now we assume the call struct is at the front of the shared
* buffer. This will have to change to allow nested calls. */
struct edge_call_t* edge_call = (struct edge_call_t*)buffer;
struct edge_call* edge_call = (struct edge_call*)buffer;

uintptr_t call_args;
unsigned long ret_val;
if(edge_call_args_ptr(edge_call, &call_args) != 0){
edge_call->return_data.call_status = CALL_STATUS_BAD_OFFSET;
return;
}

ret_val = print_buffer((char*)call_args);

// We are done with the data section for args, use as return region
// TODO safety check?
uintptr_t data_section = edge_call_data_ptr();

memcpy((void*)data_section, &ret_val, sizeof(unsigned long));
memcpy((void*)data_section, &ret_val, sizeof(unsigned long));

if( edge_call_setup_ret(edge_call, (void*) data_section, sizeof(unsigned long))){
edge_call->return_data.call_status = CALL_STATUS_BAD_PTR;
}
else{
edge_call->return_data.call_status = CALL_STATUS_OK;
}

return;

}
Expand All @@ -61,15 +61,15 @@ void print_value_wrapper(void* buffer)
{
/* For now we assume the call struct is at the front of the shared
* buffer. This will have to change to allow nested calls. */
struct edge_call_t* edge_call = (struct edge_call_t*)buffer;
struct edge_call* edge_call = (struct edge_call*)buffer;

uintptr_t call_args;
unsigned long ret_val;
if(edge_call_args_ptr(edge_call, &call_args) != 0){
edge_call->return_data.call_status = CALL_STATUS_BAD_OFFSET;
return;
}

print_value(*(unsigned long*)call_args);

edge_call->return_data.call_status = CALL_STATUS_OK;
Expand All @@ -81,7 +81,7 @@ void copy_report_wrapper(void* buffer)

/* For now we assume the call struct is at the front of the shared
* buffer. This will have to change to allow nested calls. */
struct edge_call_t* edge_call = (struct edge_call_t*)buffer;
struct edge_call* edge_call = (struct edge_call*)buffer;

uintptr_t data_section;
unsigned long ret_val;
Expand All @@ -91,7 +91,7 @@ void copy_report_wrapper(void* buffer)
edge_call->return_data.call_status = CALL_STATUS_BAD_OFFSET;
return;
}

copy_report((void*)data_section);

edge_call->return_data.call_status = CALL_STATUS_OK;
Expand All @@ -104,7 +104,7 @@ void get_host_string_wrapper(void* buffer)

/* For now we assume the call struct is at the front of the shared
* buffer. This will have to change to allow nested calls. */
struct edge_call_t* edge_call = (struct edge_call_t*)buffer;
struct edge_call* edge_call = (struct edge_call*)buffer;

uintptr_t call_args;
unsigned long ret_val;
Expand Down
4 changes: 2 additions & 2 deletions tests/untrusted/edge_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ unsigned long ocall_print_buffer(char* data, size_t data_len){
return retval;
}

void ocall_get_string(edge_data_t* retdata){
ocall(OCALL_GET_STRING, NULL, 0, retdata, sizeof(edge_data_t));
void ocall_get_string(struct edge_data* retdata){
ocall(OCALL_GET_STRING, NULL, 0, retdata, sizeof(struct edge_data));
return;
}
2 changes: 1 addition & 1 deletion tests/untrusted/edge_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ void edge_init();

unsigned long ocall_print_buffer(char* data, size_t data_len);
void ocall_print_value(unsigned long val);
void ocall_get_string(edge_data_t* retdata);
void ocall_get_string(struct edge_data* retdata);
#endif /* _EDGE_WRAPPER_H_ */
8 changes: 4 additions & 4 deletions tests/untrusted/untrusted.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ void EAPP_ENTRY eapp_entry(){

char* msg = "hello world!\n";
char* msg2 = "2nd hello world!\n";

edge_init();

unsigned long ret = ocall_print_buffer(msg, 13);
ocall_print_buffer(msg2, 17);

ocall_print_value(ret);

edge_data_t pkgstr;
struct edge_data pkgstr;
ocall_get_string(&pkgstr);

void* host_str = malloc(pkgstr.size);
Expand All @@ -35,6 +35,6 @@ void EAPP_ENTRY eapp_entry(){
}

ocall_print_value(ct);

EAPP_RETURN(ret);
}

0 comments on commit c22b97d

Please sign in to comment.