diff options
Diffstat (limited to 'lib/chibios/os/sb/host/sbhost.h')
-rw-r--r-- | lib/chibios/os/sb/host/sbhost.h | 265 |
1 files changed, 265 insertions, 0 deletions
diff --git a/lib/chibios/os/sb/host/sbhost.h b/lib/chibios/os/sb/host/sbhost.h new file mode 100644 index 000000000..9972d4ec2 --- /dev/null +++ b/lib/chibios/os/sb/host/sbhost.h | |||
@@ -0,0 +1,265 @@ | |||
1 | /* | ||
2 | ChibiOS - Copyright (C) 2006,2007,2008,2009,2010,2011,2012,2013,2014, | ||
3 | 2015,2016,2017,2018,2019,2020,2021 Giovanni Di Sirio. | ||
4 | |||
5 | This file is part of ChibiOS. | ||
6 | |||
7 | ChibiOS is free software; you can redistribute it and/or modify | ||
8 | it under the terms of the GNU General Public License as published by | ||
9 | the Free Software Foundation version 3 of the License. | ||
10 | |||
11 | ChibiOS is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | |||
20 | /** | ||
21 | * @file sb/host/sbhost.h | ||
22 | * @brief ARM sandbox host macros and structures. | ||
23 | * | ||
24 | * @addtogroup ARM_SANDBOX | ||
25 | * @{ | ||
26 | */ | ||
27 | |||
28 | #ifndef SBHOST_H | ||
29 | #define SBHOST_H | ||
30 | |||
31 | #include "sberr.h" | ||
32 | #include "sbapi.h" | ||
33 | |||
34 | /*===========================================================================*/ | ||
35 | /* Module constants. */ | ||
36 | /*===========================================================================*/ | ||
37 | |||
38 | /** | ||
39 | * @brief Magic numbers | ||
40 | * @{ | ||
41 | */ | ||
42 | #define SB_MAGIC1 0xFE9154C0U | ||
43 | #define SB_MAGIC2 0x0C4519EFU | ||
44 | /** @} */ | ||
45 | |||
46 | /*===========================================================================*/ | ||
47 | /* Module pre-compile time settings. */ | ||
48 | /*===========================================================================*/ | ||
49 | |||
50 | /*===========================================================================*/ | ||
51 | /* Derived constants and error checks. */ | ||
52 | /*===========================================================================*/ | ||
53 | |||
54 | /*===========================================================================*/ | ||
55 | /* Module data structures and types. */ | ||
56 | /*===========================================================================*/ | ||
57 | |||
58 | typedef struct { | ||
59 | /** | ||
60 | * @brief Memory range base. | ||
61 | * @note Zero if not used. | ||
62 | */ | ||
63 | uint32_t base; | ||
64 | /** | ||
65 | * @brief Memory range end (non inclusive). | ||
66 | * @note Zero if not used. | ||
67 | */ | ||
68 | uint32_t end; | ||
69 | /** | ||
70 | * @brief Writable memory range. | ||
71 | */ | ||
72 | bool writeable; | ||
73 | } sb_memory_region_t; | ||
74 | |||
75 | /** | ||
76 | * @brief Type of a sandbox configuration structure. | ||
77 | */ | ||
78 | typedef struct { | ||
79 | /** | ||
80 | * @brief Memory region for code. | ||
81 | * @note It is used to locate the startup header. | ||
82 | */ | ||
83 | uint32_t code_region; | ||
84 | /** | ||
85 | * @brief Memory region for data and stack. | ||
86 | * @note It is used for initial PSP placement. | ||
87 | */ | ||
88 | uint32_t data_region; | ||
89 | /** | ||
90 | * @brief SandBox regions. | ||
91 | * @note The following memory regions are used only for pointers | ||
92 | * validation, not for MPU setup. | ||
93 | */ | ||
94 | sb_memory_region_t regions[SB_NUM_REGIONS]; | ||
95 | /** | ||
96 | * @brief Sandbox STDIN stream. | ||
97 | * @note Set this to @p NULL if standard I/O is not needed. | ||
98 | * @note By design you can use HAL streams here, you need to use | ||
99 | * a cast however. | ||
100 | */ | ||
101 | SandboxStream *stdin_stream; | ||
102 | /** | ||
103 | * @brief Sandbox STDOUT stream. | ||
104 | * @note Set this to @p NULL if standard I/O is not needed. | ||
105 | * @note By design you can use HAL streams here, you need to use | ||
106 | * a cast however. | ||
107 | */ | ||
108 | SandboxStream *stdout_stream; | ||
109 | /** | ||
110 | * @brief Sandbox STDERR stream. | ||
111 | * @note Set this to @p NULL if standard I/O is not needed. | ||
112 | * @note By design you can use HAL streams here, you need to use | ||
113 | * a cast however. | ||
114 | */ | ||
115 | SandboxStream *stderr_stream; | ||
116 | } sb_config_t; | ||
117 | |||
118 | /** | ||
119 | * @brief Type of a sandbox object. | ||
120 | */ | ||
121 | typedef struct { | ||
122 | /** | ||
123 | * @brief Pointer to the sandbox configuration data. | ||
124 | */ | ||
125 | const sb_config_t *config; | ||
126 | /** | ||
127 | * @brief Thread running in the sandbox. | ||
128 | */ | ||
129 | thread_t *tp; | ||
130 | #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__) | ||
131 | /** | ||
132 | * @brief Thread sending a message to the sandbox. | ||
133 | */ | ||
134 | thread_t *msg_tp; | ||
135 | #endif | ||
136 | #if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__) | ||
137 | event_source_t es; | ||
138 | #endif | ||
139 | } sb_class_t; | ||
140 | |||
141 | /** | ||
142 | * @brief Type of a sandbox binary image header. | ||
143 | */ | ||
144 | typedef struct { | ||
145 | /** | ||
146 | * @brief Magic number 1. | ||
147 | */ | ||
148 | uint32_t hdr_magic1; | ||
149 | /** | ||
150 | * @brief Magic number 2. | ||
151 | */ | ||
152 | uint32_t hdr_magic2; | ||
153 | /** | ||
154 | * @brief Header size, inclusive of magic numbers. | ||
155 | */ | ||
156 | uint32_t hdr_size; | ||
157 | /** | ||
158 | * @brief Used-defined parameters, defaulted to zero. | ||
159 | */ | ||
160 | uint32_t user; | ||
161 | } sb_header_t; | ||
162 | |||
163 | /*===========================================================================*/ | ||
164 | /* Module macros. */ | ||
165 | /*===========================================================================*/ | ||
166 | |||
167 | /*===========================================================================*/ | ||
168 | /* External declarations. */ | ||
169 | /*===========================================================================*/ | ||
170 | |||
171 | #ifdef __cplusplus | ||
172 | extern "C" { | ||
173 | #endif | ||
174 | void port_syscall(struct port_extctx *ctxp, uint32_t n); | ||
175 | bool sb_is_valid_read_range(sb_class_t *sbcp, const void *start, size_t size); | ||
176 | bool sb_is_valid_write_range(sb_class_t *sbcp, void *start, size_t size); | ||
177 | void sbObjectInit(sb_class_t *sbcp); | ||
178 | void sbStart(sb_class_t *sbcp, const sb_config_t *config); | ||
179 | #ifdef __cplusplus | ||
180 | } | ||
181 | #endif | ||
182 | |||
183 | /*===========================================================================*/ | ||
184 | /* Module inline functions. */ | ||
185 | /*===========================================================================*/ | ||
186 | |||
187 | #if (CH_CFG_USE_WAITEXIT == TRUE) || defined(__DOXYGEN__) | ||
188 | /** | ||
189 | * @brief Blocks the execution of the invoking thread until the sandbox | ||
190 | * thread terminates then the exit code is returned. | ||
191 | * @pre The configuration option @p CH_CFG_USE_WAITEXIT must be enabled in | ||
192 | * order to use this function. | ||
193 | * | ||
194 | * @param[in] sbcp pointer to the sandbox object | ||
195 | * @return The exit code from the terminated thread. | ||
196 | * | ||
197 | * @api | ||
198 | */ | ||
199 | static inline msg_t sbWait(sb_class_t *sbcp) { | ||
200 | |||
201 | return chThdWait(sbcp->tp); | ||
202 | } | ||
203 | #endif /* CH_CFG_USE_WAITEXIT == TRUE */ | ||
204 | |||
205 | #if (CH_CFG_USE_MESSAGES == TRUE) || defined(__DOXYGEN__) | ||
206 | /** | ||
207 | * @brief Sends a message to a sandboxed thread. | ||
208 | * | ||
209 | * @param[in] sbcp pointer to the sandbox object | ||
210 | * @param[in] msg message to be sent | ||
211 | * @return The returned message. | ||
212 | * @retval MSG_RESET Sandboxed thread API usage error, exchange aborted. | ||
213 | * | ||
214 | * @api | ||
215 | */ | ||
216 | static inline msg_t sbSendMessage(sb_class_t *sbcp, msg_t msg) { | ||
217 | |||
218 | return chMsgSend(sbcp->tp, msg); | ||
219 | } | ||
220 | #endif /* CH_CFG_USE_MESSAGES == TRUE */ | ||
221 | |||
222 | #if (CH_CFG_USE_EVENTS == TRUE) || defined(__DOXYGEN__) | ||
223 | /** | ||
224 | * @brief Adds a set of event flags directly to the specified sandbox. | ||
225 | * | ||
226 | * @param[in] sbcp pointer to the sandbox object | ||
227 | * @param[in] events the events set to be ORed | ||
228 | * | ||
229 | * @iclass | ||
230 | */ | ||
231 | static inline void sbEvtSignalI(sb_class_t *sbcp, eventmask_t events) { | ||
232 | |||
233 | chEvtSignalI(sbcp->tp, events); | ||
234 | } | ||
235 | |||
236 | /** | ||
237 | * @brief Adds a set of event flags directly to the specified sandbox. | ||
238 | * | ||
239 | * @param[in] sbcp pointer to the sandbox object | ||
240 | * @param[in] events the events set to be ORed | ||
241 | * | ||
242 | * @api | ||
243 | */ | ||
244 | static inline void sbEvtSignal(sb_class_t *sbcp, eventmask_t events) { | ||
245 | |||
246 | chEvtSignal(sbcp->tp, events); | ||
247 | } | ||
248 | |||
249 | /** | ||
250 | * @brief Returns the sandbox event source object. | ||
251 | * | ||
252 | * @param[in] sbcp pointer to the sandbox object | ||
253 | * @return The pointer to the event source object. | ||
254 | * | ||
255 | * @xclass | ||
256 | */ | ||
257 | static inline event_source_t *sbGetEventSourceX(sb_class_t *sbcp) { | ||
258 | |||
259 | return &sbcp->es; | ||
260 | } | ||
261 | #endif /* CH_CFG_USE_EVENTS == TRUE */ | ||
262 | |||
263 | #endif /* SBHOST_H */ | ||
264 | |||
265 | /** @} */ | ||