2011-09-15 22 views
0

在Linux內核源代碼中的futex.c的futex_wake_op function中,我試圖理解控件如何達到this點。發生這種情況時,在上述函數中,futex_atomic_op_inuser返回-EFAULT,並且但uaddr2是可寫的。互斥代碼演練 - 返回EFAULT

但是從futex_atomic_op_inusersource,我看到它僅在if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))上返回-EFAULT。

反過來futex_atomic_op_inuser調用的__futex_atomic_op宏在那裏我看到在代碼中-EFAULT但我告訴路徑EFAULT不涉及調用__futex_atomic_op

如何控制達到上述點(即如果(!fshared)轉到retry_private;)那麼?

在此先感謝!

+0

這是兩個問題。 EFAULT的路徑不涉及調用'__futex_atomic_op'。 –

+0

@Igor我修改了這個問題。 – itisravi

回答

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,它會禁用正常的插入過程,因此您將遇到硬故障,從__futex_atomic_op返回-EFAULT

總之這一切都意味着,有問題的點將達到,如果:

  1. 地址是無效的,但滑過檢查中access_ok,或
  2. 它是有效的,但目前換出。