contributed by < Kevin-Shih
>
1
當 length 大於等於 LBLOCKSIZE 時
asrc
用於指向欲比較的 src
片段,透過轉型為 unsigned long *
使其每次只能存取一段 LBLOCKSIZE
大小的範圍。 mask
則是完全由要偵測的字元 d
所構成的 unsigned long
,for loop 主要是為了產生對應 32-bit 與 64-bit 兩種不同系統的 mask
。
while loop 顯然是為了每次處理 LBLOCKSIZE
大小的關鍵,當該片段中為偵測到目標字元 d
時 (DETECT_CHAR
回傳 0 時),asrc
會重新指向下個 LBLOCKSIZE
大小的片段,由於型態為 unsigned long *
故直接加 1 即可移至下個片段的位址,而 length
則相應的減去 LBLOCKSIZE
。
2
DDD
: idx++KKK
: mask + 1TTT
: &lfr->ring[tail & mask].idx, __ATOMIC_RELAXEDlfring_enqueue
有 lfr->ring[tail & mask].idx = tail;
的片段,因此推論要檢驗 lfr->ring[tail & mask].idx 與 tail 是否相等。HHH
: head + actualhead + actual
存入 &lfr->head
,又依據 __atomic_compare_exchange_n
在將 desire (HHH
) 寫入*ptr (&lfr->head
) 後會回傳 true ,再加上 NOT
後就會跳出 loop,因此 HHH
= head + actual
。__atomic_compare_exchange_n (type *ptr, type *expected, type desired, bool weak, int success_memorder, int failure_memorder)
If desired is written into *ptr then true is returned
–gcc
修改後的程式碼:
此外,CACHE_LINE
的大小可透過 sysconf(_SC_LEVEL1_DCACHE_LINESIZE)
獲取 L1 dcache line 的大小。
_SC_LEVEL1_DCACHE_LINESIZE
Inquire about the line length of the Level 1 data cache.
On aarch64, the cache line size returned is the minimum data cache line size observable by userspace.
–gnu:Constants for sysconf Parameters
3
修改後的 periodic_routine
程式碼:
kernel 中對於 task_struct
成員 ptraced
及 ptrace_entry
的註釋
結合 is_tracer()
的設計以及 check()
呼叫時的參數 &task->ptraced
可以看出迴圈中的 list
即是某個 task 的 tracee,list_entry(list, struct task_struct, ptrace_entry)
則會回傳該 tracee 對應的 task_struct
(由註解可知 tracer 的 ptraced
會出現在 tracee 的 ptrace_entry
)。 確認該 tracee 的存在後就可以確定該 task 為 tracer 了。 而在 kill_tracee()
中也使用了相同的方式找出該 tracer 所有 tracee 對應的 task_struct
並終止該 task。