Support for arguments and environment variables, to be completed.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15353 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
72e49f4a86
commit
f2083ce6d6
|
@ -81,10 +81,12 @@ static const sb_config_t sb_config1 = {
|
|||
.regions = {
|
||||
[0] = {
|
||||
.area = {STARTUP_FLASH1_BASE, STARTUP_FLASH1_SIZE},
|
||||
.used = true,
|
||||
.writeable = false
|
||||
},
|
||||
[1] = {
|
||||
.area = {STARTUP_RAM1_BASE, STARTUP_RAM1_SIZE},
|
||||
.used = true,
|
||||
.writeable = true
|
||||
}
|
||||
},
|
||||
|
@ -98,10 +100,12 @@ static const sb_config_t sb_config2 = {
|
|||
.regions = {
|
||||
[0] = {
|
||||
.area = {STARTUP_FLASH2_BASE, STARTUP_FLASH2_SIZE},
|
||||
.used = true,
|
||||
.writeable = false
|
||||
},
|
||||
[1] = {
|
||||
.area = {STARTUP_RAM2_BASE, STARTUP_RAM2_SIZE},
|
||||
.used = true,
|
||||
.writeable = true
|
||||
}
|
||||
},
|
||||
|
@ -295,16 +299,16 @@ int main(void) {
|
|||
|
||||
/* Starting sandboxed thread 1.*/
|
||||
sb1tp = sbStartThread(&sbx1, "sbx1",
|
||||
waUnprivileged1, sizeof (waUnprivileged1),
|
||||
NORMALPRIO - 1);
|
||||
waUnprivileged1, sizeof (waUnprivileged1), NORMALPRIO - 1,
|
||||
0, NULL, NULL);
|
||||
if (sb1tp == NULL) {
|
||||
chSysHalt("sbx1 failed");
|
||||
}
|
||||
|
||||
/* Starting sandboxed thread 2.*/
|
||||
sb2tp = sbStartThread(&sbx2, "sbx2",
|
||||
waUnprivileged2, sizeof (waUnprivileged2),
|
||||
NORMALPRIO - 1);
|
||||
waUnprivileged2, sizeof (waUnprivileged2), NORMALPRIO - 1,
|
||||
0, NULL, NULL);
|
||||
if (sb2tp == NULL) {
|
||||
chSysHalt("sbx2 failed");
|
||||
}
|
||||
|
|
|
@ -94,12 +94,11 @@
|
|||
.section .sandbox, "ax"
|
||||
|
||||
.align 4
|
||||
.globl _sandbox
|
||||
_sandbox: .long 0xFE9154C0
|
||||
.globl __sandbox
|
||||
__sandbox: .long 0xFE9154C0
|
||||
.long 0x0C4519EF
|
||||
.long 16
|
||||
.long 0
|
||||
b _crt0_entry
|
||||
.long __crt0_entry
|
||||
|
||||
.text
|
||||
/*
|
||||
|
@ -107,8 +106,8 @@ _sandbox: .long 0xFE9154C0
|
|||
*/
|
||||
.align 2
|
||||
.thumb_func
|
||||
.global _crt0_entry
|
||||
_crt0_entry:
|
||||
.global __crt0_entry
|
||||
__crt0_entry:
|
||||
|
||||
/* PSP stack pointers initialization.*/
|
||||
ldr r0, =__user_psp_end__
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* RAM sandbox memory setup.
|
||||
*/
|
||||
|
||||
ENTRY(_crt0_entry)
|
||||
ENTRY(__crt0_entry)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
limitations under the License.
|
||||
*/
|
||||
|
||||
ENTRY(_crt0_entry)
|
||||
ENTRY(__crt0_entry)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
|
|
|
@ -124,15 +124,19 @@ void sbObjectInit(sb_class_t *sbcp, const sb_config_t *config) {
|
|||
* @param[out] wsp pointer to a working area dedicated to the thread stack
|
||||
* @param[in] size size of the working area
|
||||
* @param[in] prio the priority level for the new thread
|
||||
* @param[in] argc number of parameters for the sandbox
|
||||
* @param[in] argv array of parameters for the sandbox
|
||||
* @param[in] envp array of environment variables for the sandbox
|
||||
* @return The thread pointer.
|
||||
* @retval NULL if the sandbox thread creation failed.
|
||||
*/
|
||||
thread_t *sbStartThread(sb_class_t *sbcp, const char *name,
|
||||
void *wsp, size_t size,
|
||||
tprio_t prio) {
|
||||
void *wsp, size_t size, tprio_t prio,
|
||||
int argc, char *argv[], char *envp[]) {
|
||||
thread_t *utp;
|
||||
const sb_header_t *sbhp;
|
||||
const sb_config_t *config = sbcp->config;
|
||||
uint32_t *sp;
|
||||
|
||||
/* Header location.*/
|
||||
sbhp = (const sb_header_t *)(void *)config->regions[config->code_region].area.base;
|
||||
|
@ -147,15 +151,28 @@ thread_t *sbStartThread(sb_class_t *sbcp, const char *name,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Checking header entry point.*/
|
||||
if (!chMemIsSpaceWithinX(&config->regions[config->code_region].area,
|
||||
(const void *)sbhp->hdr_entry,
|
||||
(size_t)2)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Setting up an initial stack for the sandbox.*/
|
||||
sp = (uint32_t *)(void *)(config->regions[config->data_region].area.base +
|
||||
config->regions[config->data_region].area.size);
|
||||
sp -= 3 * sizeof (uint32_t);
|
||||
sp[0] = (uint32_t)argc;
|
||||
sp[1] = (uint32_t)argv;
|
||||
sp[2] = (uint32_t)envp;
|
||||
|
||||
unprivileged_thread_descriptor_t utd = {
|
||||
.name = name,
|
||||
.wbase = (stkalign_t *)wsp,
|
||||
.wend = (stkalign_t *)wsp + (size / sizeof (stkalign_t)),
|
||||
.prio = prio,
|
||||
.u_pc = (uint32_t)(config->regions[config->code_region].area.base +
|
||||
sizeof (sb_header_t)) | 1U,
|
||||
.u_psp = (uint32_t)(config->regions[config->data_region].area.base +
|
||||
config->regions[config->data_region].area.size),
|
||||
.u_pc = sbhp->hdr_entry,
|
||||
.u_psp = (uint32_t)sp,
|
||||
.arg = (void *)sbcp
|
||||
};
|
||||
#if PORT_SWITCHED_REGIONS_NUMBER > 0
|
||||
|
|
|
@ -68,10 +68,14 @@ typedef struct {
|
|||
* @brief Header size, inclusive of magic numbers.
|
||||
*/
|
||||
uint32_t hdr_size;
|
||||
/**
|
||||
* @brief Entry point address.
|
||||
*/
|
||||
uint32_t hdr_entry;
|
||||
/**
|
||||
* @brief Used-defined parameters, defaulted to zero.
|
||||
*/
|
||||
uint32_t user;
|
||||
uint32_t user[4];
|
||||
} sb_header_t;
|
||||
|
||||
/*===========================================================================*/
|
||||
|
@ -93,8 +97,8 @@ extern "C" {
|
|||
bool sb_is_valid_string_range(sb_class_t *sbcp, const char *s, size_t n);
|
||||
void sbObjectInit(sb_class_t *sbcp, const sb_config_t *config);
|
||||
thread_t *sbStartThread(sb_class_t *sbcp, const char *name,
|
||||
void *wsp, size_t size,
|
||||
tprio_t prio);
|
||||
void *wsp, size_t size, tprio_t prio,
|
||||
int argc, char *argv[], char *envp[]);
|
||||
bool sbIsThreadRunningX(sb_class_t *sbcp);
|
||||
#if CH_CFG_USE_WAITEXIT == TRUE
|
||||
msg_t sbWaitThread(sb_class_t *sbcp);
|
||||
|
|
Loading…
Reference in New Issue