• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Revision15623 (tree)
Zeit2022-05-11 18:27:20
Autorgdisirio

Log Message

More VRQ code.

Ändern Zusammenfassung

Diff

--- trunk/os/common/ports/ARMv7-M-ALT/chcore.h (revision 15622)
+++ trunk/os/common/ports/ARMv7-M-ALT/chcore.h (revision 15623)
@@ -723,7 +723,7 @@
723723 * @param[in] tp pointer to the thread
724724 * @param[in] addr new address
725725 */
726-#define __port_syscall_set_u_psp(tp, addr) (tp)->ctx.syscall.u_psp = (addr)
726+#define __port_syscall_set_u_psp(tp, addr) (tp)->ctx.syscall.u_psp = (uint32_t)(addr)
727727
728728 /**
729729 * @brief Updates the stored system PSP address.
@@ -731,7 +731,7 @@
731731 * @param[in] tp pointer to the thread
732732 * @param[in] addr new address
733733 */
734-#define __port_syscall_set_s_psp(tp, addr) (tp)->ctx.syscall.u_ssp = (addr)
734+#define __port_syscall_set_s_psp(tp, addr) (tp)->ctx.syscall.s_psp = (uint32_t)(addr)
735735
736736 /**
737737 * @brief Returns the user PSP address.
--- trunk/os/sb/host/sbvrq.c (revision 15622)
+++ trunk/os/sb/host/sbvrq.c (revision 15623)
@@ -52,20 +52,29 @@
5252 /*===========================================================================*/
5353
5454 __STATIC_FORCEINLINE void vfq_makectx(sb_class_t *sbp,
55- struct port_extctx *ectxp,
55+ struct port_extctx *newctxp,
5656 uint32_t active_mask) {
5757 uint32_t irqn = __CLZ(active_mask);
5858 sbp->vrq_wtmask &= ~(1U << irqn);
5959
6060 /* Building the return context.*/
61- ectxp->r0 = irqn;
62- ectxp->pc = sbp->sbhp->hdr_vfq; /* TODO validate or let it eventually crash? */
63- ectxp->xpsr = 0x01000000U;
61+ newctxp->r0 = irqn;
62+ newctxp->pc = sbp->sbhp->hdr_vfq; /* TODO validate or let it eventually crash? */
63+ newctxp->xpsr = 0x01000000U;
6464 #if CORTEX_USE_FPU == TRUE
65- ectxp->fpscr = FPU->FPDSCR;
65+ newctxp->fpscr = FPU->FPDSCR;
6666 #endif
6767 }
6868
69+/**
70+ * @brief Used as a known privileged address.
71+ */
72+static void vfq_privileged_code(void) {
73+
74+ while (true) {
75+ }
76+}
77+
6978 /*===========================================================================*/
7079 /* Module exported functions. */
7180 /*===========================================================================*/
@@ -77,14 +86,10 @@
7786 *
7887 * @param[in] sbp pointer to a @p sb_class_t structure
7988 * @param[in] vmask mask of VRQs to be activated
80- * @return The operation status.
81- * @retval false if the activation has succeeded.
82- * @retval true in case of sandbox stack overflow.
8389 *
8490 * @special
8591 */
86-bool sbVRQTriggerFromISR(sb_class_t *sbp, sb_vrqmask_t vmask) {
87- struct port_extctx *ectxp;
92+void sbVRQTriggerFromISR(sb_class_t *sbp, sb_vrqmask_t vmask) {
8893
8994 chSysLockFromISR();
9095
@@ -96,47 +101,57 @@
96101 sb_vrqmask_t active_mask = sbp->vrq_wtmask & sbp->vrq_enmask;
97102
98103 if (active_mask != 0U) {
104+ struct port_extctx *ectxp, *newctxp;
99105
100106 /* This IRQ could have preempted the sandbox itself or some other thread,
101107 handling is different.*/
102108 if (sbp->tp->state == CH_STATE_CURRENT) {
103109 /* Sandbox case, getting the current exception frame.*/
104- ectxp = (struct port_extctx *)__get_PSP() - 1;
110+ ectxp = (struct port_extctx *)__get_PSP();
111+ newctxp = ectxp - 1;
105112
106113 /* Checking if the new frame is within the sandbox else failure.*/
107114 if (!sb_is_valid_write_range(sbp,
108- (void *)ectxp,
115+ (void *)newctxp,
109116 sizeof (struct port_extctx))) {
117+ /* Making the sandbox return on a privileged address, this
118+ will cause a fault and sandbox termination.*/
110119 chSysUnlockFromISR();
111-
112- return true;
120+ ectxp->pc = (uint32_t)vfq_privileged_code;
121+ return;
113122 }
114123 }
115124 else {
116- ectxp = sbp->tp->ctx.sp - 1;
125+ /* Other thread case, getting the pointer from the context switch
126+ structure.*/
127+ ectxp = sbp->tp->ctx.sp;
128+ newctxp = ectxp - 1;
117129
118130 /* Checking if the new frame is within the sandbox else failure.*/
119131 if (!sb_is_valid_write_range(sbp,
120- (void *)ectxp,
132+ (void *)newctxp,
121133 sizeof (struct port_extctx))) {
134+ /* Making the sandbox return on a privileged address, this
135+ will cause a fault and sandbox termination.*/
122136 chSysUnlockFromISR();
123-
124- return true;
137+ ectxp->pc = (uint32_t)vfq_privileged_code;
138+ return;
125139 }
126140
127141 /* Preventing leakage of information, clearing all register values, those
128142 would come from outside the sandbox.*/
129- memset((void *)ectxp, 0, sizeof (struct port_extctx));
143+ memset((void *)newctxp, 0, sizeof (struct port_extctx));
130144 }
131145
132146 /* Building the return context.*/
133- vfq_makectx(sbp, ectxp, active_mask);
147+ vfq_makectx(sbp, newctxp, active_mask);
148+ __port_syscall_set_u_psp(sbp->tp, newctxp);
134149 }
135150 }
136151
137152 chSysUnlockFromISR();
138153
139- return false;
154+ return;
140155 }
141156
142157 void sb_vrq_disable(struct port_extctx *ectxp) {
@@ -169,6 +184,7 @@
169184
170185 /* Building the return context.*/
171186 vfq_makectx(sbp, ectxp, active_mask);
187+ __port_syscall_set_u_psp(sbp->tp, ectxp);
172188 }
173189 }
174190 }
@@ -202,6 +218,8 @@
202218 /* Discarding the return current context, returning on the previous one.*/
203219 ectxp++;
204220 }
221+
222+ __port_syscall_set_u_psp(sbp->tp, ectxp);
205223 }
206224
207225 #endif /* SB_CFG_ENABLE_VRQ == TRUE */
--- trunk/os/sb/host/sbvrq.h (revision 15622)
+++ trunk/os/sb/host/sbvrq.h (revision 15623)
@@ -65,7 +65,7 @@
6565 #ifdef __cplusplus
6666 extern "C" {
6767 #endif
68- bool sbVRQTriggerFromISR(sb_class_t *sbp, sb_vrqmask_t vmask);
68+ void sbVRQTriggerFromISR(sb_class_t *sbp, sb_vrqmask_t vmask);
6969 void sb_vrq_disable(struct port_extctx *ectxp);
7070 void sb_vrq_enable(struct port_extctx *ectxp);
7171 void sb_vrq_getisr(struct port_extctx *ectxp);
Show on old repository browser