简体   繁体   English

ARM C 中的可重入函数是否可能存在寄存器值损坏?

[英]Is register value corruption a possibility on reentrant functions in ARM C?

Maybe I'm overthinking this since I've been researching for a couple of hours.由于我已经研究了几个小时,所以也许我想太多了。 I have the concept and rules of reentrancy pretty clear now but since I'm doing this for ARM (Cortex-M4), another question came to mind that is not touched on the reentrancy resources I've found, nor in its rules.我现在已经很清楚重入的概念和规则了,但是由于我是为 ARM(Cortex-M4)做这件事的,所以我想到了另一个问题,这个问题没有涉及到我发现的重入资源,也没有涉及到它的规则。

I understand that the following function is reentrant from the rules of reentrancy:我了解以下功能可从重入规则中重入:

void foo(int x, int y)
{
    printf("x = %d - y = %d", x, y);
}

The thing here is that, at least on ARM where I've verified this, x and y are passed on registers r2 and r3 and not in foo 's stack.这里的问题是,至少在我已经验证过的 ARM 上, xy在寄存器r2r3上传递,而不是在foo的堆栈中。 If they were passed in the stack then there would not be any confusion for me because I know that is preserved across function calls, however, since x and y are passed in registers, what would happen if a second call to foo is made from another RTOS task context right after the first call has been made?如果它们在堆栈中传递,那么对我来说不会有任何混淆,因为我知道它会在函数调用中保留,但是,由于xy是在寄存器中传递的,如果对foo的第二次调用是从另一个调用会发生什么在第一次调用之后的 RTOS 任务上下文?

void foo(int x, int y)
{ <-------------------------------------------- Second call made here
    printf("x = %d - y = %d\n", x, y);
}

Wouldn't that corrupt r2 and r3 values?那不会破坏r2r3值吗?

I haven't been able to test this because I have no idea how to make it happen.我无法对此进行测试,因为我不知道如何实现它。

每当操作系统切换到另一个线程时,它必须保存旧线程的所有寄存器值并为新线程加载寄存器值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM