From 377fdec495ca14331af4f49cbcce0895226cd557 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sun, 16 Jan 2022 09:11:15 +0000 Subject: [PATCH] Implemented sandbox state cleanup on exit() or exception. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15363 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/sb/host/sbapi.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/os/sb/host/sbapi.c b/os/sb/host/sbapi.c index 0143e9953..ba60aaa2f 100644 --- a/os/sb/host/sbapi.c +++ b/os/sb/host/sbapi.c @@ -941,16 +941,38 @@ static thread_t *sb_msg_wait_timeout_s(sysinterval_t timeout) { return tp; } + +static void sb_cleanup(void) { +#if SB_CFG_ENABLE_VFS == TRUE + sb_class_t *sbp = (sb_class_t *)chThdGetSelfX()->ctx.syscall.p; + unsigned fd; + + /* Closing all file descriptors.*/ + for (fd = 0U; fd < SB_CFG_FD_NUM; fd++) { + if (sbp->io.vfs_nodes[fd] != NULL) { + sbp->io.vfs_nodes[fd]->vmt->release(sbp->io.vfs_nodes[fd]); + sbp->io.vfs_nodes[fd] = NULL; + } + } +#endif +} + /*===========================================================================*/ /* Module exported functions. */ /*===========================================================================*/ void __sb_abort(msg_t msg) { + chSysUnlock(); + + sb_cleanup(); + + chSysLock(); #if CH_CFG_USE_EVENTS == TRUE chEvtBroadcastI(&sb.termination_es); #endif chThdExitS(msg); + chSysHalt("zombies"); } void sb_api_stdio(struct port_extctx *ectxp) { @@ -1002,6 +1024,8 @@ void sb_api_stdio(struct port_extctx *ectxp) { void sb_api_exit(struct port_extctx *ectxp) { + sb_cleanup(); + chSysLock(); #if CH_CFG_USE_EVENTS == TRUE chEvtBroadcastI(&sb.termination_es);