Futex 代码演练 - 返回 EFAULT
在Linux内核源代码中futex.c的futex_wake_op函数
中,我试图理解控制如何到达this 点。当在上述函数中,futex_atomic_op_inuser
返回时,就会发生这种情况-EFAULT,但 uaddr2
是可写的。
但来自来源的 futex_atomic_op_inuser ,我看到它仅在 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
。
futex_atomic_op_inuser
依次调用 __futex_atomic_op
宏,我在代码中看到 -EFAULT,但我被告知 EFAULT 的路径不涉及调用 __futex_atomic_op
code>
控件是如何到达上述点的(即if (!fshared)goto retry_private;)然后呢?
提前致谢!
In the futex_wake_op function
of futex.c in the Linux kernel source,I was trying to understand how the control reaches this point.This happens when in the above said function,the futex_atomic_op_inuser
returns -EFAULT,and yet the uaddr2
is writable.
But from the source of futex_atomic_op_inuser
, I see that it returns -EFAULT only on if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
.
futex_atomic_op_inuser
in turn calls a the __futex_atomic_op
macro where I see a -EFAULT in the code but I'm told that path to EFAULT does not involve calling __futex_atomic_op
How does the control reach the aforementioned point (i.e.if (!fshared)goto retry_private;)then?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
access_ok
只是为了检查地址范围对于给定的访问是否有效,即使如此,它也不能总是给出明确的答案。请参阅源代码中的注释:接下来,即使该块有效,它也可能不存在于内存中(被交换出)。
futex_atomic_op_inuser
调用pagefault_disable
,这会禁用正常的换入过程,因此您会遇到硬故障,从__futex_atomic_op< 返回
-EFAULT
/代码>。总之,所有这些意味着在以下情况下将到达所讨论的点:
access_ok
中的检查,或者access_ok
is only meant to check if the address range is valid for the given access, and even for that it can not always give a definite answer. See the comments in the source:Next, even if the block is valid, it may not be present in memory (swapped out).
futex_atomic_op_inuser
callspagefault_disable
, which disables the normal swap-in process so you will get a hard fault, returning-EFAULT
from__futex_atomic_op
.In conclusion all this means that the point in question will be reached if:
access_ok
, or