<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/rust/kernel/lib.rs, branch v6.3</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/
</subtitle>
<id>https://git.shady.money/linux/atom?h=v6.3</id>
<link rel='self' href='https://git.shady.money/linux/atom?h=v6.3'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/'/>
<updated>2023-02-01T12:24:07Z</updated>
<entry>
<title>rust: types: introduce `ForeignOwnable`</title>
<updated>2023-02-01T12:24:07Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>wedsonaf@gmail.com</email>
</author>
<published>2023-01-30T06:44:01Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0fc4424d24a230c7fb539d5d708c81c68aafa9be'/>
<id>urn:sha1:0fc4424d24a230c7fb539d5d708c81c68aafa9be</id>
<content type='text'>
It was originally called `PointerWrapper`. It is used to convert
a Rust object to a pointer representation (void *) that can be
stored on the C side, used, and eventually returned to Rust.

Signed-off-by: Wedson Almeida Filho &lt;wedsonaf@gmail.com&gt;
Reviewed-by: Vincenzo Palazzo &lt;vincenzopalazzodev@gmail.com&gt;
Reviewed-by: Martin Rodriguez Reboredo &lt;yakoyoku@gmail.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Andreas Hindborg &lt;a.hindborg@samsung.com&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: add support for dispatching on Arc and ArcBorrow.</title>
<updated>2023-01-16T22:48:06Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>wedsonaf@gmail.com</email>
</author>
<published>2022-12-28T06:03:46Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0748424aba89811b85e6e0f958b8ccd47f5af47e'/>
<id>urn:sha1:0748424aba89811b85e6e0f958b8ccd47f5af47e</id>
<content type='text'>
Trait objects (`dyn T`) require trait `T` to be "object safe". One of
the requirements for "object safety" is that the receiver have one of
the allowed types. This commit adds `Arc&lt;T&gt;` and `ArcBorrow&lt;'_, T&gt;` to
the list of allowed types.

Signed-off-by: Wedson Almeida Filho &lt;wedsonaf@gmail.com&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Vincenzo Palazzo &lt;vincenzopalazzodev@gmail.com&gt;
Acked-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: allow coercion from `Arc&lt;T&gt;` to `Arc&lt;U&gt;`</title>
<updated>2023-01-16T21:20:24Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>wedsonaf@gmail.com</email>
</author>
<published>2022-12-28T06:03:42Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=f75cb6fce4c91847d3b7cf2c5fc7c8eb4bc2d8f0'/>
<id>urn:sha1:f75cb6fce4c91847d3b7cf2c5fc7c8eb4bc2d8f0</id>
<content type='text'>
The coercion is only allowed if `U` is a compatible dynamically-sized
type (DST). For example, if we have some type `X` that implements trait
`Y`, then this allows `Arc&lt;X&gt;` to be coerced into `Arc&lt;dyn Y&gt;`.

Suggested-by: Gary Guo &lt;gary@garyguo.net&gt;
Signed-off-by: Wedson Almeida Filho &lt;wedsonaf@gmail.com&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Vincenzo Palazzo &lt;vincenzopalazzodev@gmail.com&gt;
Acked-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: allow type of `self` to be `Arc&lt;T&gt;` or variants</title>
<updated>2023-01-16T21:20:18Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>wedsonaf@gmail.com</email>
</author>
<published>2022-12-28T06:03:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=53528772fb5a174c8606cdf0047ac4899ce05be7'/>
<id>urn:sha1:53528772fb5a174c8606cdf0047ac4899ce05be7</id>
<content type='text'>
This allows associated functions whose `self` argument has `Arc&lt;T&gt;` or
variants as their type. This, in turn, allows callers to use the dot
syntax to make calls.

Signed-off-by: Wedson Almeida Filho &lt;wedsonaf@gmail.com&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Vincenzo Palazzo &lt;vincenzopalazzodev@gmail.com&gt;
Acked-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: sync: add `Arc` for ref-counted allocations</title>
<updated>2023-01-16T21:20:03Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>wedsonaf@gmail.com</email>
</author>
<published>2022-12-28T06:03:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=9dc04365500340e6d60a996333d562af747337b1'/>
<id>urn:sha1:9dc04365500340e6d60a996333d562af747337b1</id>
<content type='text'>
This is a basic implementation of `Arc` backed by C's `refcount_t`. It
allows Rust code to idiomatically allocate memory that is ref-counted.

Cc: Will Deacon &lt;will@kernel.org&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Cc: Mark Rutland &lt;mark.rutland@arm.com&gt;
Signed-off-by: Wedson Almeida Filho &lt;wedsonaf@gmail.com&gt;
Reviewed-by: Alice Ryhl &lt;aliceryhl@google.com&gt;
Reviewed-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Vincenzo Palazzo &lt;vincenzopalazzodev@gmail.com&gt;
Acked-by: Boqun Feng &lt;boqun.feng@gmail.com&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: types: add `Either` type</title>
<updated>2022-12-04T00:59:16Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>wedsonaf@gmail.com</email>
</author>
<published>2022-11-10T16:41:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ba20915bae49024dab6ee582abdd4cd8944a3e55'/>
<id>urn:sha1:ba20915bae49024dab6ee582abdd4cd8944a3e55</id>
<content type='text'>
Introduce the new `types` module of the `kernel` crate with
`Either` as its first type.

`Either&lt;L, R&gt;` is a sum type that always holds either a value
of type `L` (`Left` variant) or `R` (`Right` variant).

For instance:

    struct Executor {
        queue: Either&lt;BoxedQueue, &amp;'static Queue&gt;,
    }

Signed-off-by: Wedson Almeida Filho &lt;wedsonaf@gmail.com&gt;
Reviewed-by: Wei Liu &lt;wei.liu@kernel.org&gt;
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: build_assert: add `build_{error,assert}!` macros</title>
<updated>2022-12-04T00:59:16Z</updated>
<author>
<name>Gary Guo</name>
<email>gary@garyguo.net</email>
</author>
<published>2022-11-10T16:41:38Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=0f595bab9d1c1a10c6ab5ff3f9140cfc26600349'/>
<id>urn:sha1:0f595bab9d1c1a10c6ab5ff3f9140cfc26600349</id>
<content type='text'>
Add the `build_error!` and `build_assert!` macros which leverage
the previously introduced `build_error` crate. Do so in a new
module, called `build_assert`.

The former fails the build if the code path calling it can possibly
be executed. The latter asserts that a boolean expression is `true`
at compile time.

In particular, `build_assert!` can be used in some contexts where
`static_assert!` cannot:

    fn f1&lt;const N: usize&gt;() {
        static_assert!(N &gt; 1);` // Error.
        build_assert!(N &gt; 1);   // Build-time check.
        assert!(N &gt; 1);         // Run-time check.
    }

    #[inline]
    fn f2(n: usize) {
        static_assert!(n &gt; 1);  // Error.
        build_assert!(n &gt; 1);   // Build-time check.
        assert!(n &gt; 1);         // Run-time check.
    }

Signed-off-by: Gary Guo &lt;gary@garyguo.net&gt;
Reviewed-by: Wei Liu &lt;wei.liu@kernel.org&gt;
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: static_assert: add `static_assert!` macro</title>
<updated>2022-12-04T00:59:16Z</updated>
<author>
<name>Miguel Ojeda</name>
<email>ojeda@kernel.org</email>
</author>
<published>2022-11-10T16:41:36Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=ef9e37973c3a50497c943e70d577dad10a8e41f2'/>
<id>urn:sha1:ef9e37973c3a50497c943e70d577dad10a8e41f2</id>
<content type='text'>
Add the `static_assert!` macro, which is a compile-time assert, similar
to the C11 `_Static_assert` and C++11 `static_assert` declarations [1,2].
Do so in a new module, called `static_assert`.

For instance:

    static_assert!(42 &gt; 24);
    static_assert!(core::mem::size_of::&lt;u8&gt;() == 1);

    const X: &amp;[u8] = b"bar";
    static_assert!(X[1] == b'a');

    const fn f(x: i32) -&gt; i32 {
        x + 2
    }
    static_assert!(f(40) == 42);

Link: https://en.cppreference.com/w/c/language/_Static_assert [1]
Link: https://en.cppreference.com/w/cpp/language/static_assert [2]
Co-developed-by: Alex Gaynor &lt;alex.gaynor@gmail.com&gt;
Signed-off-by: Alex Gaynor &lt;alex.gaynor@gmail.com&gt;
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: std_vendor: add `dbg!` macro based on `std`'s one</title>
<updated>2022-12-04T00:59:16Z</updated>
<author>
<name>Niklas Mohrin</name>
<email>dev@niklasmohrin.de</email>
</author>
<published>2022-11-10T16:41:35Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=bee1688940b9264a9960e6afdac36a4af35f1f4b'/>
<id>urn:sha1:bee1688940b9264a9960e6afdac36a4af35f1f4b</id>
<content type='text'>
The Rust standard library has a really handy macro, `dbg!` [1,2].
It prints the source location (filename and line) along with the raw
source code that is invoked with and the `Debug` representation
of the given expression, e.g.:

    let a = 2;
    let b = dbg!(a * 2) + 1;
    //      ^-- prints: [src/main.rs:2] a * 2 = 4
    assert_eq!(b, 5);

Port the macro over to the `kernel` crate inside a new module
called `std_vendor`, using `pr_info!` instead of `eprintln!` and
make the rules about committing uses of `dbg!` into version control
more concrete (i.e. tailored for the kernel).

Since the source code for the macro is taken from the standard
library source (with only minor adjustments), the new file is
licensed under `Apache 2.0 OR MIT`, just like the original [3,4].

Link: https://doc.rust-lang.org/std/macro.dbg.html [1]
Link: https://github.com/rust-lang/rust/blob/master/library/std/src/macros.rs#L212 [2]
Link: https://github.com/rust-lang/rust/blob/master/library/std/Cargo.toml [3]
Link: https://github.com/rust-lang/rust/blob/master/COPYRIGHT [4]
Signed-off-by: Niklas Mohrin &lt;dev@niklasmohrin.de&gt;
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
<entry>
<title>rust: error: add `From` implementations for `Error`</title>
<updated>2022-12-04T00:59:15Z</updated>
<author>
<name>Wedson Almeida Filho</name>
<email>wedsonaf@gmail.com</email>
</author>
<published>2022-11-10T16:41:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/linux/commit/?id=76e2c2d9a22a402e816607ae575b1a194cc45a31'/>
<id>urn:sha1:76e2c2d9a22a402e816607ae575b1a194cc45a31</id>
<content type='text'>
Add a set of `From` implementations for the `Error` kernel type.

These implementations allow to easily convert from standard Rust
error types to the usual kernel errors based on one of the `E*`
integer codes.

On top of that, the question mark Rust operator (`?`) implicitly
performs a conversion on the error value using the `From` trait
when propagating. Thus it is extra convenient to use.

For instance, a kernel function that needs to convert a `i64` into
a `i32` and to bubble up the error as a kernel error may write:

    fn f(x: i64) -&gt; Result&lt;...&gt; {
        ...
        let y = i32::try_from(x)?;
        ...
    }

which will transform the `TryFromIntError` into an `Err(EINVAL)`.

Co-developed-by: Adam Bratschi-Kaye &lt;ark.email@gmail.com&gt;
Signed-off-by: Adam Bratschi-Kaye &lt;ark.email@gmail.com&gt;
Co-developed-by: Nándor István Krácser &lt;bonifaido@gmail.com&gt;
Signed-off-by: Nándor István Krácser &lt;bonifaido@gmail.com&gt;
Signed-off-by: Wedson Almeida Filho &lt;wedsonaf@gmail.com&gt;
Reviewed-by: Finn Behrens &lt;me@kloenk.dev&gt;
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda &lt;ojeda@kernel.org&gt;
</content>
</entry>
</feed>
