Skip to content

Commit 2bb3468

Browse files
committed
Extract UVISOR_BOX_ID_INVALID to vmpu.h
1 parent 37d2c34 commit 2bb3468

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

api/inc/vmpu_exports.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
* terminating NULL. */
2828
#define UVISOR_MAX_BOX_NAMESPACE_LENGTH 37
2929

30+
/** Invalid box id for use in marking objects with invalid ownership. */
31+
#define UVISOR_BOX_ID_INVALID ((uint8_t) -1)
32+
3033
/* supervisor user access modes */
3134
#define UVISOR_TACL_UEXECUTE 0x0001UL
3235
#define UVISOR_TACL_UWRITE 0x0002UL

core/system/inc/page_allocator_config.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444

4545
/* The page box_id is the box id which is 8-bit large. */
4646
typedef uint8_t page_owner_t;
47-
/* Define a unused value for the page table. */
48-
#define UVISOR_PAGE_UNUSED ((page_owner_t) (-1))
4947
/* Contains the total number of available pages. */
5048
extern uint8_t g_page_count_total;
5149
/* Contains the shift of the page owner mask. */

core/system/src/page_allocator.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
* SVC call, which automagically serializes access to it. */
3737
#define UVISOR_PAGE_ALLOCATOR_MUTEX_AQUIRE {}
3838
#define UVISOR_PAGE_ALLOCATOR_MUTEX_RELEASE {}
39+
#define UVISOR_PAGE_UNUSED UVISOR_BOX_ID_INVALID
3940

4041
#endif /* defined(UVISOR_PRESENT) && (UVISOR_PRESENT == 1) */
4142

@@ -73,12 +74,6 @@ uint8_t page_allocator_get_page_from_address(uint32_t address)
7374

7475
void page_allocator_init(void * const heap_start, void * const heap_end, const uint32_t * const page_size)
7576
{
76-
/* Make sure the UVISOR_PAGE_UNUSED is definitely NOT a valid box id. */
77-
if (vmpu_is_box_id_valid(UVISOR_PAGE_UNUSED)) {
78-
HALT_ERROR(SANITY_CHECK_FAILED,
79-
"UVISOR_PAGE_UNUSED (%u) must not be a valid box id!\n",
80-
UVISOR_PAGE_UNUSED);
81-
}
8277
if (!page_size || !vmpu_public_flash_addr((uint32_t) page_size)) {
8378
HALT_ERROR(SANITY_CHECK_FAILED,
8479
"Page size pointer (0x%08x) is not in flash memory.\n",

core/system/src/page_allocator_faults.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
*/
1717

1818
#include <uvisor.h>
19+
#include "api/inc/vmpu_exports.h"
1920
#include "page_allocator.h"
2021
#include "page_allocator_faults.h"
2122
#include "page_allocator_config.h"
2223
#include "context.h"
2324

2425
/* Maps the number of faults to a page. */
2526
uint32_t g_page_fault_table[UVISOR_PAGE_MAX_COUNT];
27+
#define UVISOR_PAGE_UNUSED UVISOR_BOX_ID_INVALID
2628

2729
void page_allocator_reset_faults(uint8_t page)
2830
{

core/vmpu/src/vmpu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ static int vmpu_sanity_checks(void)
4343
&__uvisor_config, __uvisor_config.magic, UVISOR_MAGIC);
4444
}
4545

46+
/* Make sure the UVISOR_BOX_ID_INVALID is definitely NOT a valid box id. */
47+
if (vmpu_is_box_id_valid(UVISOR_BOX_ID_INVALID)) {
48+
HALT_ERROR(SANITY_CHECK_FAILED,
49+
"UVISOR_BOX_ID_INVALID (%u) must not be a valid box id!\n",
50+
UVISOR_BOX_ID_INVALID);
51+
}
52+
4653
/* Verify basic assumptions about vmpu_bits/__builtin_clz. */
4754
assert(__builtin_clz(0) == 32);
4855
assert(__builtin_clz(1UL << 31) == 0);

0 commit comments

Comments
 (0)