Re: [PATCH v8 2/2] rust: add dma coherent allocator abstraction.

From: Miguel Ojeda
Date: Thu Jan 09 2025 - 06:19:39 EST


On Thu, Jan 9, 2025 at 12:14 PM Abdiel Janulgue
<abdiel.janulgue@xxxxxxxxx> wrote:
>
> We are interested in the last argument 'attrs'. For some reason it seems
> ffi::c_ulong is defined as usize at least on top of `rust-next` commit
> 0c5928deada15a8d075516e6e0d9ee19011bb000.

We are moving to a custom mapping instead of using `core::ffi`
directly. Please see commit 1bae8729e50a ("rust: map `long` to `isize`
and `char` to `u8`"):

The following FFI types are replaced compared to `core::ffi`:

1. `char` type is now always mapped to `u8`, since kernel uses
`-funsigned-char` on the C code. `core::ffi` maps it to platform
default ABI, which can be either signed or unsigned.

2. `long` is now always mapped to `isize`. It's very common in the
kernel to use `long` to represent a pointer-sized integer, and in
fact `intptr_t` is a typedef of `long` in the kernel. Enforce this
mapping rather than mapping to `i32/i64` depending on platform can
save us a lot of unnecessary casts.

+ // In the kernel, `intptr_t` is defined to be `long` in
all platforms, so we can map the type to
+ // `isize`.
+ c_long = isize;
+ c_ulong = usize;

Cheers,
Miguel