summaryrefslogtreecommitdiff
path: root/samples/rust (follow)
Commit message (Collapse)AuthorAgeFilesLines
* samples: minimal: match upstreamMiguel Ojeda2022-10-181-5/+8
| | | | | | | The minimal sample merged upstream used `Vec` instead of `String` in order to minimize `alloc` further. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* rust: rename `Ref` to `Arc`Wedson Almeida Filho2022-10-053-17/+17
| | | | | | | | | | | When `Ref` was first introduced, we still had `alloc`'s `Arc` being used in the codebase, so we chose a different name. Now that `Arc` is gone, we can reclaim the name, which is desirable because it is consistent with userspace. This is a pure refactor with no functional changes intended. Signed-off-by: Wedson Almeida Filho <wedsonaf@gmail.com>
* Merge pull request #859 from nbdd0121/miscMiguel Ojeda2022-08-051-0/+1
|\ | | | | rust: add missing dependency to rust netfilter sample
| * rust: add missing dependency to rust netfilter sampleGary Guo2022-08-051-0/+1
| | | | | | | | Signed-off-by: Gary Guo <gary@garyguo.net>
* | rust: take str literal instead bstr literal in `module!` macroGary Guo2022-08-0514-58/+58
|/ | | | | | | | | | | For simplicity (avoid parsing), escape sequences and raw string literals are not yet handled. Module names, aliases and license strings are restricted to ASCII only. Link: https://github.com/Rust-for-Linux/linux/issues/252 Link: https://lore.kernel.org/lkml/YukvvPOOu8uZl7+n@yadro.com/ Signed-off-by: Gary Guo <gary@garyguo.net>
* rust: add `module_fs` macroWedson Almeida Filho2022-07-251-14/+2
| | | | | | | This reduces the amount of code needed to implement a module that only implements a file system. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: allow fs driver to initialise new superblocksWedson Almeida Filho2022-07-191-1/+13
| | | | | | | | | | | | They are also allowed to specify the type of superblock keying. With this change, drivers get a new callback, `fill_super`, that they need to implement to initialise new superblocks. In subsequent commits, they'll be able to populate the root with entries, but for now it's empty. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: add support for file system parametersWedson Almeida Filho2022-07-141-0/+15
| | | | | | | This allows file system contexts to be further initialised with parameters from userspace before a fs is mounted or reconfigured. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: change `FileFlags` struct to `flags` moduleWedson Almeida Filho2022-07-121-2/+2
| | | | | | | | This brings it in line with other cases (e.g., `irq::flags`, `fs::flags`, `mm::virt::flags`) and allows users to `use` all constants at once, for example, `use kernel::file::flags::*` if they so choose. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Merge branch 'rust' into file_flags_typeWedson Almeida Filho2022-07-1222-54/+384
|\
| * rust: define fs contextWedson Almeida Filho2022-07-111-0/+13
| | | | | | | | | | | | Also make fs mountable, but empty for now. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
| * sample: rust: Add a selftest moduleBoqun Feng2022-07-083-0/+107
| | | | | | | | | | | | | | This provides a temporary place to put "pure tests" for Rust funtionality and wrappers. Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
| * rust: add ability to register a file systemWedson Almeida Filho2022-07-053-0/+40
| | | | | | | | | | | | | | | | | | Also add sample that uses the new public API. The registered file system cannot be mounted yet, but can be seen in /proc/filesystems. More functionality will be added in subsequent commits. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
| * rust: use `#[vtable]` for `kernel::file::Operations`Gary Guo2022-07-054-9/+5
| | | | | | | | Signed-off-by: Gary Guo <gary@garyguo.net>
| * samples/rust: add echo server sampleWedson Almeida Filho2022-07-013-0/+71
| | | | | | | | | | | | | | This example uses Rust async for the server and a workqueue-based executor to run async tasks. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
| * samples: rust: random: move `module!` macroMiguel Ojeda2022-05-281-8/+8
| | | | | | | | | | | | | | | | | | | | For Rust, the `module!` macro is best placed in the beginning of the file, since it gives general information about the module, nearby the documentation. This also makes it consistent with the other samples. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
| * treewide: use `GPL` as the license string instead of `GPL v2`Miguel Ojeda2022-05-2712-12/+12
| | | | | | | | | | | | | | | | | | | | | | | | Since commit bf7fbeeae6db ("module: Cure the MODULE_LICENSE "GPL" vs. "GPL v2" bogosity"), Documentation/process/license-rules.rst explains that `MODULE_LICENSE` arguments can simply use `GPL` instead of `GPL v2`, because it is not meant to replace the proper licensing information. Since the `license:` field of the `module!` macro is the same as `MODULE_LICENSE`, use the simpler form in Rust too. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
| * samples/rust: add netfilter sampleWedson Almeida Filho2022-03-283-0/+65
| | | | | | | | | | | | | | It just prints the head and total lengths plus the first 10 bytes of the IPv4/IPv6 packets received and sent. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
| * rust: rename `KernelModule` to `Module`Wedson Almeida Filho2022-03-288-8/+8
| | | | | | | | | | | | | | | | Since it's already in the `kernel` crate, prefixing it with `Kernel` is redundant. This is also for consistency with other types (e.g., we renamed `KernelResult` to `Result`). Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
| * rust: move error codes to the `error::code` moduleWedson Almeida Filho2022-03-152-5/+5
| | | | | | | | | | | | | | | | | | | | This is so that we can `use` them with a wildcard (which we do in the prelude), which allows us to simplify expressions like `Err(Error::EINVAL)` to `Err(EINVAL)`. This is a pure refactor, no functional changes are intended. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
| * rust: move `file_operations::FileOperations` into `file::Operations`Wedson Almeida Filho2022-03-154-11/+8
| | | | | | | | | | | | | | | | | | This is to avoid repeating the "file" prefix and for consistency with other modules that also have operations like `power::Operations`. This is a pure refactor, no functional changes are intended. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
| * rust: rename `FileOperations::Wrapper` to `FileOperations::Data`Wedson Almeida Filho2022-03-152-3/+3
| | | | | | | | | | | | | | | | | | | | This is for the associated type to have a clearer meaning, and to bring it in line with other traits like `irq::Chip` and `gpio::Chip` where the context data type is simply `Data`. This is a pure refactor with no functional changes intended. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
| * kbuild: support host programs written in RustMiguel Ojeda2022-03-037-0/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows us to use Rust for any scripts used during compilation as long as Rust is already available, instead of e.g. C, shell scripts or Perl (Python does not seem to be required for compilation, which would be another natural & modern option to consider). After all, Rust is a good language for scripts too and the goal is to have first-class support for Rust in the kernel, so one should be able to write host programs in it too, just like with C. Not to mention the other benefits (e.g. static typing) compared to the currently available options. Eventually, if having a Rust toolchain ever becomes mandatory (whether or not Rust support is optional and/or enabled), this becomes even a better idea. Ideally, other kernel developers will also want to start using Rust for kernel tooling, which may help making that happen. A downside of Rust for this use case is `rustc`'s compilation speed, which may become concerning if e.g. a lot of programs are used. Another downside, shared with C, is the small standard library. I considered adding C object linking support, but it requires creating an archive of the C objects just for linking and a bunch of other bits which become hard to justify when we do not have a current use case for it. Like above, if having a Rust toolchain ever becomes mandatory for kernel compilation, then finding a use case where C code is needed becomes much easier. Or even the other way around, we could take advantage of Rust inside existing C programs, too. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* | rust: file: Remove `is_blocking()` methodDaniel Xu2022-02-221-2/+3
|/ | | | | | | | The previous commit adds a generic way to check file flags. Better not to have two ways to do the same thing, especially when the second way is highly specialized. Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
* rust: miscdev: support names created at runtimeWedson Almeida Filho2022-02-162-2/+2
| | | | | | | | | | | The registration now holds an owned C string while the miscdev is registered, and frees it on drop. Now names are formatted with the `fmt` macro instead of being static C strings. This enables scenarios when the device name is constructed at runtime, i.e., where a static C string does not exist. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Merge pull request #655 from wedsonaf/sample-static-mutexWedson Almeida Filho2022-02-151-0/+15
|\ | | | | samples/rust: add static mutex and condvar to sync sample
| * samples/rust: add static mutex and condvar to sync sampleWedson Almeida Filho2022-02-021-0/+15
| | | | | | | | | | | | | | The sample includes local instances, this patch adds an example of how to use static mutexes and conditional varibles. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* | treewide: update/normalize comment styleMiguel Ojeda2022-02-119-9/+9
|/ | | | | | | | | | | | Includes: capitalization, end of sentence/title periods, list marker and list indentation. Also included a fix for a spurious space and missing code quotes. No change in content intended otherwise. `alloc` is excluded since we try not to diverge from upstream. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* rust: add optional parameters to the registration of misc devicesWedson Almeida Filho2022-01-242-2/+2
| | | | | | | | We introduce the `Options` type that holds the optional paremeters. Users who want to specify them do so by calling methods on the `Options` instance followed by a call to `register` or `register_new`. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: avoid the need of crate attributes in kernel modulesMiguel Ojeda2022-01-2010-31/+0
| | | | | | | | | | | | | | | | | | | | | Instead of enabling the features per-module, do it globally. This removes the need to write boilerplate such as `#![no_std]` in kernel modules, which does not bring much value given the allowed features are constrained anyway. There is the question of whether to enable only the most common ones (`allocator_api` and `global_asm`) in order to easily see uncommon features being used. However, we only have other three features, and they are either going to get stabilized/workarounded/removed at some point and/or they are easy to spot anyway. We are using `-Zcrate-attr` for convenience here, but we do not really depend on it: like for other unstable features, if this was the last feature to get stabilized, we would simply workaround it. Furthermore, it is likely we will change how modules are compiled in a way that makes this not needed. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* samples/rust: add platform device driver sampleWedson Almeida Filho2022-01-133-0/+36
| | | | | | | | This is a minimal sample of registering a driver for a platform device. The driver doesn't really do anything, and serves as a template for future new platform drivers. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: require `Sync` and `Send` on file operations context dataWedson Almeida Filho2022-01-123-6/+7
| | | | | | | | | | | | This is a requirement because a shared reference to the context data can be used in arbitrary threads (requires `Sync`) and it can be destroyed in an arbitrary read (requires `Send`), whenever the refcount on the file goes to zero. We change the default to `()` so that we don't have to impose the same requirements on `Self`. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: simplify file operations by removing `FileOpener`Wedson Almeida Filho2022-01-114-21/+25
| | | | | | | | | | | | It is currently used to allow a single `FileOperations` implementation to be shared by multiple `FileOpener` instances. But Binder is the only intended user I've seen so far. So we have the extra complexity because of a single exceptional case. This commit simplifies things for the majority: they just need to implement `FileOperations::open`. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: add `&File` argument to `open` callback.Wedson Almeida Filho2021-11-292-2/+2
| | | | | | | | This is for cases when drivers need to get information from `File` during `open`, for example, the credentials. Such a need occurs is Binder. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: use generic associated types (GATs) to implement `PointerWrapper`.Wedson Almeida Filho2021-11-172-5/+5
| | | | | | | | | | The feature, although still unstable, is no longer incomplete. It allows us to use a lifetime in the `Borrow` assocciated type, which allows us to simplify some of the code around borrowing the wrapped value and also allows us to wrap raw pointers and integers without violating `Deref` recommendations. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: remove all usages of `try_new_and_init` and `pin_init_and_share`.Wedson Almeida Filho2021-11-152-41/+38
| | | | Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Merge pull request #552 from wedsonaf/pin-refWedson Almeida Filho2021-11-151-7/+7
|\ | | | | rust: remove instances of `Pin<Ref<T>>`.
| * rust: remove instances of `Pin<Ref<T>>`.Wedson Almeida Filho2021-11-151-7/+7
| | | | | | | | | | | | Since `Ref<T>` is already pinned, there is no need to wrap it in `Pin`. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* | rust: add CStr & ThisModule to preludeMilan2021-11-127-10/+4
|/ | | | | | | | Now that the trait signature of KernelModule has changed, we can add the necessary deps to the prelude considering they'll be needed in each non-specialized module init Signed-off-by: Milan <milan@mdaverde.com>
* rust: improve `KernelModule` initialisation.Wedson Almeida Filho2021-11-088-20/+24
| | | | | | | | | | | | | | | These changes allow the init of modules to be implemented in other modules (e.g., the main kernel crate, which isn't a separate module). This, in turn, allows us to define module macros for specific types of modules without procmacros (albeit with the limitation that `type` must be the first parameter). As an example, I redefined `module_misc_device` as a regular macro. This is in preparation for adding macros for pci, amba, and platform modules without the need for more procmacros. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: use `impl` syntactic sugar to simplify read/write.Wedson Almeida Filho2021-08-113-8/+8
| | | | | | | | This removes the need to explicitly declare a generic parameter. Although it is just syntactic sugar, it looks less intimidating to readers not familiar with Rust. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: prelude: graduate `Box`, `Arc`, `Vec`, `Pin` and `Error`Miguel Ojeda2021-07-024-13/+1
| | | | Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* rust: kernel: use the new `try_*` methodsMiguel Ojeda2021-07-011-1/+1
| | | | | | | | | In preparation for enabling `no_global_oom_handling` for `alloc`, we need to stop using methods that will disappear when enabling the configuration option. Instead, we use the new methods we just added. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
* rust: require mutable references when initialising sync primitives.Wedson Almeida Filho2021-06-273-16/+17
| | | | | | | This prevents initialising synchronisation primitives when there are multiple references to them. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: fix bug where unsafe expressions didn't require unsafe block.Wedson Almeida Filho2021-06-261-2/+4
| | | | | | | | | | | In the `init_with_lockdep` macro, the macros were evaluated inside an unsafe block, so they could contain unsafe operations without requiring an explicit unsafe block on the call site. Fixed by evaluating `$obj` and `$name` outside an unsafe block. Reported-by: Sven Van Asbroeck <thesven73@gmail.com> Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: remove `Arc` from rust samples.Wedson Almeida Filho2021-06-252-45/+51
| | | | Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: update `IoctlHandler` to allow arbitrary type as well.Wedson Almeida Filho2021-06-231-4/+6
| | | | | | | | This is similar to a previous change to `FileOperations`. It is in preparation for allowing ioctl handlers to take `&Ref<T>` as the first argument, which will be needed in a subsequent change to `Ref<T>`. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* rust: update `FileOperations` to use arbitrary type from `PointerWrapper`.Wedson Almeida Filho2021-06-233-27/+31
| | | | | | | | | | | | This allows `FileOperations` implementers to have arbitrary (wrapped) values as `private_data` (as opposed to only wrapped `Self`). It also allows wrappers to dictate the borrowed type. For now all wrappers of `T` just borrow `&T`, but in a subsequent PR `Ref<T>` will borrow to `&Ref<T>`, which allows implementations to increment the refcount. Signed-off-by: Wedson Almeida Filho <wedsonaf@google.com>
* Update to a new nightly versionBoris-Chengbiao Zhou2021-05-291-1/+1
| | | | | | | | Includes rust-lang/rust#83592, rust-lang/rust#85276 and rust-lang/rust#85700 which are needed to build correctly again after rustc's upgrade to LLVM 12. Signed-off-by: Boris-Chengbiao Zhou <bobo1239@web.de>
* rust: remove `pr_cont` from preludeGary Guo2021-05-271-0/+1
| | | | | | | `pr_cont` is a discouraged feature. While we still support it in print.rs, remove it from the prelude so it's less likely to get used. Signed-off-by: Gary Guo <gary@garyguo.net>