Skip to content

Latest commit

 

History

History
13 lines (7 loc) · 486 Bytes

ptr_addr_of.md

File metadata and controls

13 lines (7 loc) · 486 Bytes

addr_of! 宏除了读取 repr(packed) 的结构体我还没想到有什么用

对应 C 语言类似的是 offset_of

container_of

obtain a pointer to the parent structure given a pointer to one of its members

常用于 linux 源码例如 watchdog_context 里面有个 watchdog_devicewatchdog_ops

Rust for Linux 源码中实现了这两个 C 的宏 https://rust-for-linux.github.io/docs/kernel/macro.container_of.html