@@ -23,6 +23,7 @@ struct box_context {
23
23
uint32_t secret_number;
24
24
int trusted_id;
25
25
int previous_box_caller;
26
+ int caller_id;
26
27
};
27
28
28
29
static const UvisorBoxAclItem acl[] = {
@@ -42,19 +43,18 @@ UVISOR_BOX_CONFIG(box_number_store, acl, UVISOR_BOX_STACK_SIZE, box_context);
42
43
UVISOR_BOX_RPC_GATEWAY_SYNC (box_number_store, secure_number_get_number, get_number, uint32_t , void );
43
44
UVISOR_BOX_RPC_GATEWAY_ASYNC (box_number_store, secure_number_set_number, set_number, int , uint32_t );
44
45
45
- static int caller_id;
46
-
47
46
static int get_caller_id ()
48
47
{
49
- if (caller_id != uvisor_ctx->previous_box_caller ) {
48
+ if (uvisor_ctx-> caller_id != uvisor_ctx->previous_box_caller ) {
50
49
51
50
led_blue = LED_ON;
52
51
Thread::wait (100 );
53
52
led_blue = LED_OFF;
54
53
55
- uvisor_ctx->previous_box_caller = caller_id;
54
+ uvisor_ctx->previous_box_caller = uvisor_ctx-> caller_id ;
56
55
}
57
- return caller_id;
56
+
57
+ return uvisor_ctx->caller_id ;
58
58
}
59
59
60
60
static uint32_t get_number (void )
@@ -70,6 +70,9 @@ static int set_number(uint32_t number)
70
70
{
71
71
const int id = get_caller_id ();
72
72
73
+ /* Cache the name verification result. This allows future checks to replace
74
+ * a relatively more expensive string compare with a cheaper integer
75
+ * comparison. */
73
76
if (uvisor_ctx->trusted_id == -1 ) {
74
77
char name[UVISOR_MAX_BOX_NAMESPACE_LENGTH];
75
78
memset (name, 0 , sizeof (name));
@@ -112,7 +115,7 @@ static void number_store_main(const void *)
112
115
int status;
113
116
114
117
/* NOTE: This serializes all access to the number store! */
115
- status = rpc_fncall_waitfor (my_fn_array, 2 , &caller_id, UVISOR_WAIT_FOREVER);
118
+ status = rpc_fncall_waitfor (my_fn_array, 2 , &uvisor_ctx-> caller_id , UVISOR_WAIT_FOREVER);
116
119
117
120
if (status) {
118
121
printf (" Failure is not an option.\r\n " );
0 commit comments