Skip to content

Replace printf with private RawSerial #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions source/client_a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

struct box_context {
uint32_t number;
RawSerial * pc;
};

static const UvisorBoxAclItem acl[] = {
Expand Down Expand Up @@ -55,7 +56,7 @@ static void box_async_runner(const void *)
while (1) {
uint32_t ret;
int status = rpc_fncall_wait(result, UVISOR_WAIT_FOREVER, &ret);
printf("%c: %s '0x%08x'\n", (char) uvisor_box_id_self() + '0', (ret == 0) ? "Wrote" : "Failed to write", (unsigned int) number);
uvisor_ctx->pc->printf("%c: %s '0x%08x'\n", (char) uvisor_box_id_self() + '0', (ret == 0) ? "Wrote" : "Failed to write", (unsigned int) number);
/* FIXME: Add better error handling. */
if (!status) {
break;
Expand All @@ -71,14 +72,21 @@ static void box_sync_runner(const void *)
while (1) {
/* Synchronous access to the number. */
const uint32_t number = secure_number_get_number();
printf("%c: Read '0x%08x'\n", (char) uvisor_box_id_self() + '0', (unsigned int) number);
uvisor_ctx->pc->printf("%c: Read '0x%08x'\n", (char) uvisor_box_id_self() + '0', (unsigned int) number);

Thread::wait(7000);
}
}

static void client_a_main(const void *)
{
/* Allocate serial port to ensure that code in this secure box won't touch
* the handle in the default security context when printing. */
uvisor_ctx->pc = new RawSerial(USBTX, USBRX);
if (!uvisor_ctx->pc) {
return;
}

srand(uvisor_box_id_self());
new Thread(box_sync_runner, NULL);
new Thread(box_async_runner, NULL);
Expand Down
12 changes: 10 additions & 2 deletions source/client_b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

struct box_context {
uint32_t number;
RawSerial * pc;
};

static const UvisorBoxAclItem acl[] = {
Expand All @@ -44,6 +45,13 @@ static uint32_t get_a_number()

static void client_b_main(const void *)
{
/* Allocate serial port to ensure that code in this secure box won't touch
* the handle in the default security context when printing. */
uvisor_ctx->pc = new RawSerial(USBTX, USBRX);
if (!uvisor_ctx->pc) {
return;
}

/* The entire box code runs in its main thread. */
while (1) {
uvisor_rpc_result_t result;
Expand All @@ -57,15 +65,15 @@ static void client_b_main(const void *)
while (1) {
uint32_t ret;
int status = rpc_fncall_wait(result, UVISOR_WAIT_FOREVER, &ret);
printf("%c: %s '0x%08x'\n", (char) uvisor_box_id_self() + '0', (ret == 0) ? "Wrote" : "Failed to write", (unsigned int) number);
uvisor_ctx->pc->printf("%c: %s '0x%08x'\n", (char) uvisor_box_id_self() + '0', (ret == 0) ? "Wrote" : "Failed to write", (unsigned int) number);
if (!status) {
break;
}
}

/* Synchronous access to the number. */
number = secure_number_get_number();
printf("%c: Read '0x%08x'\n", (char) uvisor_box_id_self() + '0', (unsigned int) number);
uvisor_ctx->pc->printf("%c: Read '0x%08x'\n", (char) uvisor_box_id_self() + '0', (unsigned int) number);

Thread::wait(3000);
}
Expand Down
12 changes: 10 additions & 2 deletions source/secure_number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct box_context {
int trusted_id;
int previous_box_caller;
int caller_id;
RawSerial * pc;
};

static const UvisorBoxAclItem acl[] = {
Expand Down Expand Up @@ -81,7 +82,7 @@ static int set_number(uint32_t number)
static const char * trusted_namespace = "client_a";
if (memcmp(name, trusted_namespace, sizeof(*trusted_namespace)) == 0) {
uvisor_ctx->trusted_id = id;
printf("Trusted client a has box id %u\n", id);
uvisor_ctx->pc->printf("Trusted client a has box id %u\n", id);
} else {
return 1;
}
Expand All @@ -102,6 +103,13 @@ static int set_number(uint32_t number)

static void number_store_main(const void *)
{
/* Allocate serial port to ensure that code in this secure box won't touch
* the handle in the default security context when printing. */
uvisor_ctx->pc = new RawSerial(USBTX, USBRX);
if (!uvisor_ctx->pc) {
return;
}

/* Today we only allow client a to write to the number. */
uvisor_ctx->trusted_id = -1;

Expand All @@ -118,7 +126,7 @@ static void number_store_main(const void *)
status = rpc_fncall_waitfor(my_fn_array, 2, &uvisor_ctx->caller_id, UVISOR_WAIT_FOREVER);

if (status) {
printf("Failure is not an option.\r\n");
uvisor_ctx->pc->printf("Failure is not an option.\r\n");
uvisor_error(USER_NOT_ALLOWED);
}
}
Expand Down