Re: [PATCH v3 4/4] rust: add abstraction for `struct page`

From: Benno Lossin
Date: Tue Mar 19 2024 - 18:29:13 EST


On 3/19/24 23:16, Boqun Feng wrote:
> On Mon, Mar 11, 2024 at 10:47:16AM +0000, Alice Ryhl wrote:
> [...]
>> /* `bindgen` gets confused at certain things. */
>> const size_t RUST_CONST_HELPER_ARCH_SLAB_MINALIGN = ARCH_SLAB_MINALIGN;
>> +const size_t RUST_CONST_HELPER_PAGE_SIZE = PAGE_SIZE;
>> +const size_t RUST_CONST_HELPER_PAGE_MASK = PAGE_MASK;
>
> At least for me, bindgen couldn't work out the macro expansion, and I
> got:
>
> pub const PAGE_SIZE: usize = 4096;
> extern "C" {
> pub static RUST_CONST_HELPER_PAGE_MASK: usize;
> }
>
> in rust/bindings/bindings_generated.rs, which will eventually cause the
> code cannot compile.
>
> I'm using bindgen-cli 0.65.1, libclang (16 or 17), rustc (1.76 or 1.77).
>
> Anyone else sees the same thing?

I also have this problem with bindgen-cli 0.69.1 libclang 16 and rustc 1.760.
For reference, here is the actual compilation error:

error[E0425]: cannot find value `PAGE_MASK` in crate `bindings`
--> rust/kernel/page.rs:17:40
|
17 | pub const PAGE_MASK: usize = bindings::PAGE_MASK as usize;
| ^^^^^^^^^ help: a constant with a similar name exists: `GATE_TASK`
|
::: /home/benno/kernel/review/mem-man-binder/rust/bindings/bindings_generated.rs:12188:1
|
12188 | pub const GATE_TASK: _bindgen_ty_4 = 5;
| ---------------------------------- similarly named constant `GATE_TASK` defined here

error: type `gfp_t` should have an upper camel case name
--> rust/kernel/page.rs:21:14
|
21 | pub type gfp_t = bindings::gfp_t;
| ^^^^^ help: convert the identifier to upper camel case: `GfpT`
|
= note: `-D non-camel-case-types` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(non_camel_case_types)]`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.

@Alice: the second error should be unrelated to this problem.

--
Cheers,
Benno

>
> Regards,
> Boqun
>
>> const gfp_t RUST_CONST_HELPER_GFP_KERNEL = GFP_KERNEL;
>> const gfp_t RUST_CONST_HELPER___GFP_ZERO = __GFP_ZERO;
>> +const gfp_t RUST_CONST_HELPER___GFP_HIGHMEM = ___GFP_HIGHMEM;
> [...]