0

futex_wake_op functionLinux 内核源代码中的 futex.c 中,我试图了解控件是如何到达这一点的。这发生在上述函数中,futex_atomic_op_inuser返回 -EFAULT,但它uaddr2是可写的。

但是从 的来源futex_atomic_op_inuser我看到它仅在 上返回 -EFAULT if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))

futex_atomic_op_inuser反过来调用__futex_atomic_op宏,我在代码中看到 -EFAULT 但我被告知 EFAULT 的路径不涉及调用__futex_atomic_op

控制如何达到上述点(即if (!fshared)goto retry_private ;)then?

提前致谢!

4

1 回答 1

0

access_ok只是为了检查地址范围是否对给定的访问有效,即使这样它也不能总是给出明确的答案。查看源代码中的评论:

 * Returns true (nonzero) if the memory block may be valid, false (zero)
 * if it is definitely invalid.
 *
 * Note that, depending on architecture, this function probably just
 * checks that the pointer is in the user space range - after calling
 * this function, memory access functions may still return -EFAULT.

接下来,即使该块是有效的,它也可能不存在于内存中(被换出)。futex_atomic_op_inuser调用pagefault_disable,这会禁用正常的换入过程,因此您将遇到硬故障,-EFAULT__futex_atomic_op.

总之,所有这些都意味着,如果满足以下条件,将达到问题点:

  1. 地址无效,但未能通过登记access_ok,或
  2. 它是有效的,但目前已换出。
于 2012-10-19T18:23:42.390 回答