Skip to content

Commit 08ba670

Browse files
committed
Add initial uvisor release library
1 parent 47025b8 commit 08ba670

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2980
-0
lines changed

features/FEATURE_UVISOR/AUTHORS.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
519 Milosch Meriac
2+
420 Alessandro Angelino
3+
16 Niklas Hauser
4+
15 Jaeden Amero
5+
3 Hugo Vincent
6+
3 JaredCJR
7+
3 Jim Huang
8+
2 tonyyanxuan
9+
1 Aksel Skauge Mellbye
10+
1 Irit Arkin
11+
1 Nathan Chong
12+
1 ccli8

features/FEATURE_UVISOR/VERSION.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v0.9.14-alpha
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __RTX_PROCESS_MALLOC_H__
18+
#define __RTX_PROCESS_MALLOC_H__
19+
20+
#include "secure_allocator.h"
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
/* Allocate memory on the process heap. */
27+
void * malloc_p(size_t size);
28+
/* Reallocate memory on the process heap. */
29+
void * realloc_p(void * ptr, size_t size);
30+
/* Free memory on the process heap. */
31+
void free_p(void * ptr);
32+
33+
#ifdef __cplusplus
34+
} /* extern "C" */
35+
#endif
36+
37+
#endif /* __RTX_PROCESS_MALLOC_H__ */
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __RTX_BOX_INDEX_H__
18+
#define __RTX_BOX_INDEX_H__
19+
20+
#include "cmsis_os.h"
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
typedef struct
27+
{
28+
/* The uvisor box index must be placed at the beginning */
29+
UvisorBoxIndex index;
30+
31+
/* Id of the mutex */
32+
osMutexId mutex_id;
33+
/* Pointer to the data of the mutex */
34+
osMutexDef_t mutex;
35+
/* Internal data of the mutex */
36+
int32_t mutex_data[4];
37+
} RtxBoxIndex;
38+
39+
#ifdef __cplusplus
40+
} /* extern "C" */
41+
#endif
42+
43+
#endif /* __RTX_BOX_INDEX_H__ */
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright (c) 2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __SECURE_ALLOCATOR_H__
18+
#define __SECURE_ALLOCATOR_H__
19+
20+
#include <stdint.h>
21+
#include <stddef.h>
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
/** Contains the allocator data and backing page table. */
28+
typedef void * SecureAllocator;
29+
30+
/** Create an allocator in-place in an existing pool without using pages.
31+
* Use this to turn statically allocated memory into a heap.
32+
* Or allocate a large piece of memory and then turn that into a heap.
33+
*
34+
* @param mem Pointer to the origin of the memory pool
35+
* @param bytes Length of the memory pool in bytes
36+
* @returns the allocator or `NULL` on failure
37+
*/
38+
SecureAllocator secure_allocator_create_with_pool(
39+
void * mem,
40+
size_t bytes);
41+
42+
/** Create an allocator using pages from the page heap.
43+
* Use this to request secure dynamic memory for your process.
44+
* Note that this memory is not guaranteed to be consecutive, therefore you
45+
* must specify the maximum allocation size that you plan to use in this
46+
* allocator. This function will then compute the number and size of required
47+
* pages and request them from the secure page heap.
48+
*
49+
* @param total_size The minimal total size of the heap
50+
* @param maximum_malloc_size The largest size to be allocated in one chunk
51+
* @returns the allocator or `NULL` on failure (out of memory,
52+
* maximum malloc size cannot be fulfilled)
53+
*/
54+
SecureAllocator secure_allocator_create_with_pages(
55+
size_t total_size,
56+
size_t maximum_malloc_size);
57+
58+
/** Destroy the allocator and free the backing pages.
59+
* An attempt to destroy a memory-pool backed allocator will fail and return
60+
* with an error code.
61+
*
62+
* @retval 0 Allocator successfully destroyed.
63+
* @retval -1 Allocator is static (memory-pool), or freeing memory pages failed.
64+
*/
65+
int secure_allocator_destroy(
66+
SecureAllocator allocator);
67+
68+
/** Drop-in for `malloc`. */
69+
void * secure_malloc(
70+
SecureAllocator allocator,
71+
size_t size);
72+
73+
/** Drop-in for `realloc`. */
74+
void * secure_realloc(
75+
SecureAllocator allocator,
76+
void * ptr,
77+
size_t size);
78+
79+
/** Drop-in for `free`. */
80+
void secure_free(
81+
SecureAllocator allocator,
82+
void * ptr);
83+
84+
#ifdef __cplusplus
85+
} /* extern "C" */
86+
#endif
87+
88+
#endif /* __SECURE_ALLOCATOR_H__ */
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2013-2015, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __UVISOR_API_BENCHMARK_H__
18+
#define __UVISOR_API_BENCHMARK_H__
19+
20+
#include "api/inc/uvisor_exports.h"
21+
#include <stdint.h>
22+
23+
UVISOR_EXTERN void uvisor_benchmark_configure(void);
24+
UVISOR_EXTERN void uvisor_benchmark_start(void);
25+
UVISOR_EXTERN uint32_t uvisor_benchmark_stop(void);
26+
27+
#endif /* __UVISOR_API_BENCHMARK_H__ */
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* Copyright (c) 2013-2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __UVISOR_API_BOX_CONFIG_H__
18+
#define __UVISOR_API_BOX_CONFIG_H__
19+
20+
#include "api/inc/uvisor_exports.h"
21+
#include <stddef.h>
22+
#include <stdint.h>
23+
24+
UVISOR_EXTERN const uint32_t __uvisor_mode;
25+
26+
#define UVISOR_DISABLED 0
27+
#define UVISOR_PERMISSIVE 1
28+
#define UVISOR_ENABLED 2
29+
30+
#define UVISOR_SET_MODE(mode) \
31+
UVISOR_SET_MODE_ACL_COUNT(mode, NULL, 0)
32+
33+
#define UVISOR_SET_MODE_ACL(mode, acl_list) \
34+
UVISOR_SET_MODE_ACL_COUNT(mode, acl_list, UVISOR_ARRAY_COUNT(acl_list))
35+
36+
#define UVISOR_SET_MODE_ACL_COUNT(mode, acl_list, acl_list_count) \
37+
uint8_t __attribute__((section(".keep.uvisor.bss.boxes"), aligned(32))) __reserved_stack[UVISOR_STACK_BAND_SIZE]; \
38+
\
39+
UVISOR_EXTERN const uint32_t __uvisor_mode = (mode); \
40+
\
41+
static const __attribute__((section(".keep.uvisor.cfgtbl"), aligned(4))) UvisorBoxConfig main_cfg = { \
42+
UVISOR_BOX_MAGIC, \
43+
UVISOR_BOX_VERSION, \
44+
0, \
45+
sizeof(RtxBoxIndex), \
46+
0, \
47+
0, \
48+
NULL, \
49+
acl_list, \
50+
acl_list_count \
51+
}; \
52+
\
53+
extern const __attribute__((section(".keep.uvisor.cfgtbl_ptr_first"), aligned(4))) void * const main_cfg_ptr = &main_cfg;
54+
55+
/* this macro selects an overloaded macro (variable number of arguments) */
56+
#define __UVISOR_BOX_MACRO(_1, _2, _3, _4, NAME, ...) NAME
57+
58+
#define __UVISOR_BOX_CONFIG(box_name, acl_list, acl_list_count, stack_size, context_size) \
59+
\
60+
uint8_t __attribute__((section(".keep.uvisor.bss.boxes"), aligned(32))) \
61+
box_name ## _reserved[ \
62+
UVISOR_STACK_SIZE_ROUND( \
63+
( \
64+
(UVISOR_MIN_STACK(stack_size) + \
65+
(context_size) + \
66+
(__uvisor_box_heapsize) + \
67+
sizeof(RtxBoxIndex) \
68+
) \
69+
* 8) \
70+
/ 6)]; \
71+
\
72+
static const __attribute__((section(".keep.uvisor.cfgtbl"), aligned(4))) UvisorBoxConfig box_name ## _cfg = { \
73+
UVISOR_BOX_MAGIC, \
74+
UVISOR_BOX_VERSION, \
75+
UVISOR_MIN_STACK(stack_size), \
76+
sizeof(RtxBoxIndex), \
77+
context_size, \
78+
__uvisor_box_heapsize, \
79+
__uvisor_box_namespace, \
80+
acl_list, \
81+
acl_list_count \
82+
}; \
83+
\
84+
extern const __attribute__((section(".keep.uvisor.cfgtbl_ptr"), aligned(4))) void * const box_name ## _cfg_ptr = &box_name ## _cfg;
85+
86+
#define __UVISOR_BOX_CONFIG_NOCONTEXT(box_name, acl_list, stack_size) \
87+
__UVISOR_BOX_CONFIG(box_name, acl_list, UVISOR_ARRAY_COUNT(acl_list), stack_size, 0) \
88+
89+
#define __UVISOR_BOX_CONFIG_CONTEXT(box_name, acl_list, stack_size, context_type) \
90+
__UVISOR_BOX_CONFIG(box_name, acl_list, UVISOR_ARRAY_COUNT(acl_list), stack_size, sizeof(context_type)) \
91+
UVISOR_EXTERN context_type *const *const __uvisor_ps;
92+
93+
#define __UVISOR_BOX_CONFIG_NOACL(box_name, stack_size, context_type) \
94+
__UVISOR_BOX_CONFIG(box_name, NULL, 0, stack_size, sizeof(context_type)) \
95+
UVISOR_EXTERN context_type *const *const __uvisor_ps;
96+
97+
#define __UVISOR_BOX_CONFIG_NOACL_NOCONTEXT(box_name, stack_size) \
98+
__UVISOR_BOX_CONFIG(box_name, NULL, 0, stack_size, 0)
99+
100+
#define UVISOR_BOX_CONFIG_ACL(...) \
101+
__UVISOR_BOX_MACRO(__VA_ARGS__, __UVISOR_BOX_CONFIG_CONTEXT, \
102+
__UVISOR_BOX_CONFIG_NOCONTEXT, \
103+
__UVISOR_BOX_CONFIG_NOACL_NOCONTEXT)(__VA_ARGS__)
104+
105+
#define UVISOR_BOX_CONFIG_CTX(...) \
106+
__UVISOR_BOX_MACRO(__VA_ARGS__, __UVISOR_BOX_CONFIG_CONTEXT, \
107+
__UVISOR_BOX_CONFIG_NOACL, \
108+
__UVISOR_BOX_CONFIG_NOACL_NOCONTEXT)(__VA_ARGS__)
109+
110+
#define UVISOR_BOX_CONFIG(...) \
111+
UVISOR_BOX_CONFIG_ACL(__VA_ARGS__)
112+
113+
/* Use this macro before box defintion (for example, UVISOR_BOX_CONFIG) to
114+
* define the name of your box. If you don't want a name, use this macro with
115+
* box_namespace as NULL. */
116+
#define UVISOR_BOX_NAMESPACE(box_namespace) \
117+
static const char *const __uvisor_box_namespace = box_namespace
118+
119+
#define UVISOR_BOX_HEAPSIZE(heap_size) \
120+
static const uint32_t __uvisor_box_heapsize = heap_size;
121+
122+
#define uvisor_ctx (*__uvisor_ps)
123+
124+
/* Return the numeric box ID of the current box. */
125+
UVISOR_EXTERN int uvisor_box_id_self(void);
126+
127+
/* Return the numeric box ID of the box that is calling through the most recent
128+
* secure gateway. Return -1 if there is no secure gateway calling box. */
129+
UVISOR_EXTERN int uvisor_box_id_caller(void);
130+
131+
/* Copy the box namespace of the specified box ID to the memory provided by
132+
* box_namespace. The box_namespace's length must be at least
133+
* MAX_BOX_NAMESPACE_LENGTH bytes. Return how many bytes were copied into
134+
* box_namespace. Return UVISOR_ERROR_INVALID_BOX_ID if the provided box ID is
135+
* invalid. Return UVISOR_ERROR_BUFFER_TOO_SMALL if the provided box_namespace
136+
* is too small to hold MAX_BOX_NAMESPACE_LENGTH bytes. Return
137+
* UVISOR_ERROR_BOX_NAMESPACE_ANONYMOUS if the box is anonymous. */
138+
UVISOR_EXTERN int uvisor_box_namespace(int box_id, char *box_namespace, size_t length);
139+
140+
#endif /* __UVISOR_API_BOX_CONFIG_H__ */
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2016, ARM Limited, All Rights Reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
* not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#ifndef __UVISOR_CONTEX_EXPORTS_H__
18+
#define __UVISOR_CONTEX_EXPORTS_H__
19+
20+
/** Maximum number of nested context switches.
21+
*
22+
* The same state stack is kept for all kinds of context switches that are bound
23+
* to a function, for which uVisor keeps an internal state. */
24+
#define UVISOR_CONTEXT_MAX_DEPTH 16
25+
26+
#endif /* __UVISOR_CONTEX_EXPORTS_H__ */

0 commit comments

Comments
 (0)