Skip to content

Commit dee4c63

Browse files
pangzhen1xiaomixiaoxiang781216
authored andcommitted
protected build: userspace threads will unexpectly work in privileged mode after syscall
In protected build mode, the syscall returns without setting correct value for the CONTROL register, which causes the userspace threads working in privileged mode after syscall. Signed-off-by: pangzhen1 <[email protected]>
1 parent d59fbfd commit dee4c63

File tree

6 files changed

+9
-0
lines changed

6 files changed

+9
-0
lines changed

arch/arm/include/armv6-m/irq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ struct xcpt_syscall_s
142142
{
143143
uint32_t excreturn; /* The EXC_RETURN value */
144144
uint32_t sysreturn; /* The return PC */
145+
uint32_t ctrlreturn; /* The return CONTROL value */
145146
};
146147
#endif
147148

arch/arm/include/armv7-m/irq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ struct xcpt_syscall_s
202202
{
203203
uint32_t excreturn; /* The EXC_RETURN value */
204204
uint32_t sysreturn; /* The return PC */
205+
uint32_t ctrlreturn; /* The return CONTROL value */
205206
};
206207
#endif
207208

arch/arm/include/armv8-m/irq.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ struct xcpt_syscall_s
213213
{
214214
uint32_t excreturn; /* The EXC_RETURN value */
215215
uint32_t sysreturn; /* The return PC */
216+
uint32_t ctrlreturn; /* The return CONTROL value */
216217
};
217218
#endif
218219

arch/arm/src/armv6-m/arm_svcall.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ int arm_svcall(int irq, void *context, void *arg)
224224

225225
regs[REG_PC] = rtcb->xcp.syscall[index].sysreturn;
226226
regs[REG_EXC_RETURN] = rtcb->xcp.syscall[index].excreturn;
227+
regs[REG_CONTROL] = rtcb->xcp.syscall[index].ctrlreturn;
227228
rtcb->xcp.nsyscalls = index;
228229

229230
/* The return value must be in R0-R1. dispatch_syscall()
@@ -417,6 +418,7 @@ int arm_svcall(int irq, void *context, void *arg)
417418

418419
rtcb->xcp.syscall[index].sysreturn = regs[REG_PC];
419420
rtcb->xcp.syscall[index].excreturn = regs[REG_EXC_RETURN];
421+
rtcb->xcp.syscall[index].ctrlreturn = regs[REG_CONTROL];
420422
rtcb->xcp.nsyscalls = index + 1;
421423

422424
regs[REG_PC] = (uint32_t)dispatch_syscall;

arch/arm/src/armv7-m/arm_svcall.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ int arm_svcall(int irq, void *context, void *arg)
233233

234234
regs[REG_PC] = rtcb->xcp.syscall[index].sysreturn;
235235
regs[REG_EXC_RETURN] = rtcb->xcp.syscall[index].excreturn;
236+
regs[REG_CONTROL] = rtcb->xcp.syscall[index].ctrlreturn;
236237
rtcb->xcp.nsyscalls = index;
237238

238239
/* The return value must be in R0-R1. dispatch_syscall()
@@ -426,6 +427,7 @@ int arm_svcall(int irq, void *context, void *arg)
426427

427428
rtcb->xcp.syscall[index].sysreturn = regs[REG_PC];
428429
rtcb->xcp.syscall[index].excreturn = regs[REG_EXC_RETURN];
430+
rtcb->xcp.syscall[index].ctrlreturn = regs[REG_CONTROL];
429431
rtcb->xcp.nsyscalls = index + 1;
430432

431433
regs[REG_PC] = (uint32_t)dispatch_syscall & ~1;

arch/arm/src/armv8-m/arm_svcall.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ int arm_svcall(int irq, void *context, void *arg)
232232

233233
regs[REG_PC] = rtcb->xcp.syscall[index].sysreturn;
234234
regs[REG_EXC_RETURN] = rtcb->xcp.syscall[index].excreturn;
235+
regs[REG_CONTROL] = rtcb->xcp.syscall[index].ctrlreturn;
235236
rtcb->xcp.nsyscalls = index;
236237

237238
/* The return value must be in R0-R1. dispatch_syscall()
@@ -427,6 +428,7 @@ int arm_svcall(int irq, void *context, void *arg)
427428

428429
rtcb->xcp.syscall[index].sysreturn = regs[REG_PC];
429430
rtcb->xcp.syscall[index].excreturn = regs[REG_EXC_RETURN];
431+
rtcb->xcp.syscall[index].ctrlreturn = regs[REG_CONTROL];
430432
rtcb->xcp.nsyscalls = index + 1;
431433

432434
regs[REG_PC] = (uint32_t)dispatch_syscall & ~1;

0 commit comments

Comments
 (0)