2024-08-15 10:30:26 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Non-trivial C macros cannot be used in Rust. Similarly, inlined C functions
|
|
|
|
* cannot be called either. This file explicitly creates functions ("helpers")
|
|
|
|
* that wrap those so that they can be called from Rust.
|
|
|
|
*
|
|
|
|
* Sorted alphabetically.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "blk.c"
|
|
|
|
#include "bug.c"
|
|
|
|
#include "build_assert.c"
|
|
|
|
#include "build_bug.c"
|
2024-09-15 14:31:30 +00:00
|
|
|
#include "cred.c"
|
2024-12-19 18:04:10 +01:00
|
|
|
#include "device.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "err.c"
|
rust: file: add Rust abstraction for `struct file`
This abstraction makes it possible to manipulate the open files for a
process. The new `File` struct wraps the C `struct file`. When accessing
it using the smart pointer `ARef<File>`, the pointer will own a
reference count to the file. When accessing it as `&File`, then the
reference does not own a refcount, but the borrow checker will ensure
that the reference count does not hit zero while the `&File` is live.
Since this is intended to manipulate the open files of a process, we
introduce an `fget` constructor that corresponds to the C `fget`
method. In future patches, it will become possible to create a new fd in
a process and bind it to a `File`. Rust Binder will use these to send
fds from one process to another.
We also provide a method for accessing the file's flags. Rust Binder
will use this to access the flags of the Binder fd to check whether the
non-blocking flag is set, which affects what the Binder ioctl does.
This introduces a struct for the EBADF error type, rather than just
using the Error type directly. This has two advantages:
* `File::fget` returns a `Result<ARef<File>, BadFdError>`, which the
compiler will represent as a single pointer, with null being an error.
This is possible because the compiler understands that `BadFdError`
has only one possible value, and it also understands that the
`ARef<File>` smart pointer is guaranteed non-null.
* Additionally, we promise to users of the method that the method can
only fail with EBADF, which means that they can rely on this promise
without having to inspect its implementation.
That said, there are also two disadvantages:
* Defining additional error types involves boilerplate.
* The question mark operator will only utilize the `From` trait once,
which prevents you from using the question mark operator on
`BadFdError` in methods that return some third error type that the
kernel `Error` is convertible into. (However, it works fine in methods
that return `Error`.)
Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
Co-developed-by: Daniel Xu <dxu@dxuuu.xyz>
Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
Co-developed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240915-alice-file-v10-3-88484f7a3dcf@google.com
Reviewed-by: Gary Guo <gary@garyguo.net>
Signed-off-by: Christian Brauner <brauner@kernel.org>
2024-09-15 14:31:29 +00:00
|
|
|
#include "fs.c"
|
rust: add `io::{Io, IoRaw}` base types
I/O memory is typically either mapped through direct calls to ioremap()
or subsystem / bus specific ones such as pci_iomap().
Even though subsystem / bus specific functions to map I/O memory are
based on ioremap() / iounmap() it is not desirable to re-implement them
in Rust.
Instead, implement a base type for I/O mapped memory, which generically
provides the corresponding accessors, such as `Io::readb` or
`Io:try_readb`.
`Io` supports an optional const generic, such that a driver can indicate
the minimal expected and required size of the mapping at compile time.
Correspondingly, calls to the 'non-try' accessors, support compile time
checks of the I/O memory offset to read / write, while the 'try'
accessors, provide boundary checks on runtime.
`IoRaw` is meant to be embedded into a structure (e.g. pci::Bar or
io::IoMem) which creates the actual I/O memory mapping and initializes
`IoRaw` accordingly.
To ensure that I/O mapped memory can't out-live the device it may be
bound to, subsystems must embed the corresponding I/O memory type (e.g.
pci::Bar) into a `Devres` container, such that it gets revoked once the
device is unbound.
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Tested-by: Daniel Almeida <daniel.almeida@collabora.com>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
Tested-by: Dirk Behme <dirk.behme@de.bosch.com>
Link: https://lore.kernel.org/r/20241219170425.12036-8-dakr@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-12-19 18:04:09 +01:00
|
|
|
#include "io.c"
|
2024-10-30 16:04:24 +00:00
|
|
|
#include "jump_label.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "kunit.c"
|
|
|
|
#include "mutex.c"
|
|
|
|
#include "page.c"
|
2024-12-19 18:04:16 +01:00
|
|
|
#include "platform.c"
|
2024-12-19 18:04:11 +01:00
|
|
|
#include "pci.c"
|
2024-10-02 13:38:10 +02:00
|
|
|
#include "pid_namespace.c"
|
2024-08-22 16:37:53 +00:00
|
|
|
#include "rbtree.c"
|
2024-12-19 18:04:06 +01:00
|
|
|
#include "rcu.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "refcount.c"
|
2024-09-15 14:31:31 +00:00
|
|
|
#include "security.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "signal.c"
|
|
|
|
#include "slab.c"
|
|
|
|
#include "spinlock.c"
|
|
|
|
#include "task.c"
|
|
|
|
#include "uaccess.c"
|
2024-10-04 17:41:12 +02:00
|
|
|
#include "vmalloc.c"
|
2024-08-15 10:30:26 +00:00
|
|
|
#include "wait.c"
|
|
|
|
#include "workqueue.c"
|