Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5499cc7

Browse files
author
Oren Cohen
committedAug 20, 2017
try with a loop
1 parent 826084c commit 5499cc7

File tree

1 file changed

+31
-22
lines changed

1 file changed

+31
-22
lines changed
 

‎core/vmpu/src/mpu_armv8m/vmpu_armv8m_unpriv_access.c

+31-22
Original file line numberDiff line numberDiff line change
@@ -21,32 +21,41 @@
2121
#include "vmpu_mpu.h"
2222
#include "vmpu_unpriv_access.h"
2323

24+
extern int vmpu_fault_recovery_mpu(uint32_t pc, uint32_t sp, uint32_t fault_addr, uint32_t fault_status);
25+
2426
uint32_t vmpu_unpriv_access(uint32_t addr, uint32_t size, uint32_t data)
2527
{
26-
// This operation could be slow since we are scanning all the regions defined for the box
27-
// an implementation using the TTA command is faster but causes misses since it works with the MPU
28-
if (vmpu_buffer_access_is_ok(g_active_box, (const void *) addr, UVISOR_UNPRIV_ACCESS_SIZE(size))){
29-
switch(size) {
30-
case UVISOR_UNPRIV_ACCESS_READ(1):
31-
return *((uint8_t *) addr);
32-
case UVISOR_UNPRIV_ACCESS_READ(2):
33-
return *((uint16_t *) addr);
34-
case UVISOR_UNPRIV_ACCESS_READ(4):
35-
return *((uint32_t *) addr);
36-
case UVISOR_UNPRIV_ACCESS_WRITE(1):
37-
*((uint8_t *) addr) = (uint8_t) data;
38-
return 0;
39-
case UVISOR_UNPRIV_ACCESS_WRITE(2):
40-
*((uint16_t *) addr) = (uint16_t) data;
41-
return 0;
42-
case UVISOR_UNPRIV_ACCESS_WRITE(4):
43-
*((uint32_t *) addr) = data;
44-
return 0;
45-
default:
46-
break;
28+
unsigned int tries = 0;
29+
while(1) {
30+
// This operation could be slow since we are scanning all the regions defined for the box
31+
// an implementation using the TTA command is faster but causes misses since it works with the MPU
32+
if (vmpu_buffer_access_is_ok(g_active_box, (const void *) addr, UVISOR_UNPRIV_ACCESS_SIZE(size))){
33+
switch(size) {
34+
case UVISOR_UNPRIV_ACCESS_READ(1):
35+
return *((uint8_t *) addr);
36+
case UVISOR_UNPRIV_ACCESS_READ(2):
37+
return *((uint16_t *) addr);
38+
case UVISOR_UNPRIV_ACCESS_READ(4):
39+
return *((uint32_t *) addr);
40+
case UVISOR_UNPRIV_ACCESS_WRITE(1):
41+
*((uint8_t *) addr) = (uint8_t) data;
42+
return 0;
43+
case UVISOR_UNPRIV_ACCESS_WRITE(2):
44+
*((uint16_t *) addr) = (uint16_t) data;
45+
return 0;
46+
case UVISOR_UNPRIV_ACCESS_WRITE(4):
47+
*((uint32_t *) addr) = data;
48+
return 0;
49+
default:
50+
break;
51+
}
52+
}
53+
54+
if (++tries > 1 || !vmpu_fault_recovery_mpu(0, 0, addr, 0)) {
55+
break;
4756
}
4857
}
49-
58+
5059
HALT_ERROR(PERMISSION_DENIED, "Access to restricted resource denied");
5160
return 0;
5261
}

0 commit comments

Comments
 (0)
Please sign in to comment.