• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Revision15353 (tree)
Time2022-01-13 19:53:55
Authorgdisirio

Log Message

Support for arguments and environment variables, to be completed.

Change Summary

Incremental Difference

--- trunk/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC/main.c (revision 15352)
+++ trunk/demos/STM32/RT-STM32L4R9-DISCOVERY-SB_HOST_STATIC/main.c (revision 15353)
@@ -81,10 +81,12 @@
8181 .regions = {
8282 [0] = {
8383 .area = {STARTUP_FLASH1_BASE, STARTUP_FLASH1_SIZE},
84+ .used = true,
8485 .writeable = false
8586 },
8687 [1] = {
8788 .area = {STARTUP_RAM1_BASE, STARTUP_RAM1_SIZE},
89+ .used = true,
8890 .writeable = true
8991 }
9092 },
@@ -98,10 +100,12 @@
98100 .regions = {
99101 [0] = {
100102 .area = {STARTUP_FLASH2_BASE, STARTUP_FLASH2_SIZE},
103+ .used = true,
101104 .writeable = false
102105 },
103106 [1] = {
104107 .area = {STARTUP_RAM2_BASE, STARTUP_RAM2_SIZE},
108+ .used = true,
105109 .writeable = true
106110 }
107111 },
@@ -295,8 +299,8 @@
295299
296300 /* Starting sandboxed thread 1.*/
297301 sb1tp = sbStartThread(&sbx1, "sbx1",
298- waUnprivileged1, sizeof (waUnprivileged1),
299- NORMALPRIO - 1);
302+ waUnprivileged1, sizeof (waUnprivileged1), NORMALPRIO - 1,
303+ 0, NULL, NULL);
300304 if (sb1tp == NULL) {
301305 chSysHalt("sbx1 failed");
302306 }
@@ -303,8 +307,8 @@
303307
304308 /* Starting sandboxed thread 2.*/
305309 sb2tp = sbStartThread(&sbx2, "sbx2",
306- waUnprivileged2, sizeof (waUnprivileged2),
307- NORMALPRIO - 1);
310+ waUnprivileged2, sizeof (waUnprivileged2), NORMALPRIO - 1,
311+ 0, NULL, NULL);
308312 if (sb2tp == NULL) {
309313 chSysHalt("sbx2 failed");
310314 }
--- trunk/os/sb/host/sbhost.c (revision 15352)
+++ trunk/os/sb/host/sbhost.c (revision 15353)
@@ -124,15 +124,19 @@
124124 * @param[out] wsp pointer to a working area dedicated to the thread stack
125125 * @param[in] size size of the working area
126126 * @param[in] prio the priority level for the new thread
127+ * @param[in] argc number of parameters for the sandbox
128+ * @param[in] argv array of parameters for the sandbox
129+ * @param[in] envp array of environment variables for the sandbox
127130 * @return The thread pointer.
128131 * @retval NULL if the sandbox thread creation failed.
129132 */
130133 thread_t *sbStartThread(sb_class_t *sbcp, const char *name,
131- void *wsp, size_t size,
132- tprio_t prio) {
134+ void *wsp, size_t size, tprio_t prio,
135+ int argc, char *argv[], char *envp[]) {
133136 thread_t *utp;
134137 const sb_header_t *sbhp;
135138 const sb_config_t *config = sbcp->config;
139+ uint32_t *sp;
136140
137141 /* Header location.*/
138142 sbhp = (const sb_header_t *)(void *)config->regions[config->code_region].area.base;
@@ -147,15 +151,28 @@
147151 return NULL;
148152 }
149153
154+ /* Checking header entry point.*/
155+ if (!chMemIsSpaceWithinX(&config->regions[config->code_region].area,
156+ (const void *)sbhp->hdr_entry,
157+ (size_t)2)) {
158+ return NULL;
159+ }
160+
161+ /* Setting up an initial stack for the sandbox.*/
162+ sp = (uint32_t *)(void *)(config->regions[config->data_region].area.base +
163+ config->regions[config->data_region].area.size);
164+ sp -= 3 * sizeof (uint32_t);
165+ sp[0] = (uint32_t)argc;
166+ sp[1] = (uint32_t)argv;
167+ sp[2] = (uint32_t)envp;
168+
150169 unprivileged_thread_descriptor_t utd = {
151170 .name = name,
152171 .wbase = (stkalign_t *)wsp,
153172 .wend = (stkalign_t *)wsp + (size / sizeof (stkalign_t)),
154173 .prio = prio,
155- .u_pc = (uint32_t)(config->regions[config->code_region].area.base +
156- sizeof (sb_header_t)) | 1U,
157- .u_psp = (uint32_t)(config->regions[config->data_region].area.base +
158- config->regions[config->data_region].area.size),
174+ .u_pc = sbhp->hdr_entry,
175+ .u_psp = (uint32_t)sp,
159176 .arg = (void *)sbcp
160177 };
161178 #if PORT_SWITCHED_REGIONS_NUMBER > 0
--- trunk/os/sb/host/sbhost.h (revision 15352)
+++ trunk/os/sb/host/sbhost.h (revision 15353)
@@ -69,9 +69,13 @@
6969 */
7070 uint32_t hdr_size;
7171 /**
72+ * @brief Entry point address.
73+ */
74+ uint32_t hdr_entry;
75+ /**
7276 * @brief Used-defined parameters, defaulted to zero.
7377 */
74- uint32_t user;
78+ uint32_t user[4];
7579 } sb_header_t;
7680
7781 /*===========================================================================*/
@@ -93,8 +97,8 @@
9397 bool sb_is_valid_string_range(sb_class_t *sbcp, const char *s, size_t n);
9498 void sbObjectInit(sb_class_t *sbcp, const sb_config_t *config);
9599 thread_t *sbStartThread(sb_class_t *sbcp, const char *name,
96- void *wsp, size_t size,
97- tprio_t prio);
100+ void *wsp, size_t size, tprio_t prio,
101+ int argc, char *argv[], char *envp[]);
98102 bool sbIsThreadRunningX(sb_class_t *sbcp);
99103 #if CH_CFG_USE_WAITEXIT == TRUE
100104 msg_t sbWaitThread(sb_class_t *sbcp);
Show on old repository browser