Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace kernel::str::CStr by core::ffi::CStr #1075

Open
y86-dev opened this issue Apr 12, 2024 · 8 comments
Open

Replace kernel::str::CStr by core::ffi::CStr #1075

y86-dev opened this issue Apr 12, 2024 · 8 comments
Labels
good first issue Good for newcomers • lib Related to the `rust/` library. medium Expected to be an issue of medium difficulty to resolve.

Comments

@y86-dev
Copy link
Member

y86-dev commented Apr 12, 2024

std::ffi::CStr was moved to core::ffi::CStr in rust 1.64, making it available to the kernel. We have our own version of CStr in kernel::str, since the standard library one wasn't available. Rust 1.77 also added C-string literals c"abc" that automatically terminate strings with \0. The kernel has a c_str! macro for this purpose. We should use the types from the standard library and remove our own versions. The things to do would be

  • change uses of kernel::str::CStr to core::ffi::CStr and also change c_str!("...") into c"..."
  • remove kernel::str::CStr and the macro

This requires submitting a proper patch to the LKML and the Rust for Linux mailing list. Please recall to test your changes, to use a proper title for the commit, to sign your commit under the Developer's Certificate of Origin and so on. Please see https://docs.kernel.org/process/submitting-patches.html and https://rust-for-linux.com/contributing for details.

Please take this issue only if you are new to the kernel development process and you would like to use it as a test to submit your first patch to the kernel. Please do not take it if you do not plan to make other contributions to the kernel.

@y86-dev y86-dev added good first issue Good for newcomers • lib Related to the `rust/` library. labels Apr 12, 2024
@vincenzopalazzo
Copy link

I will look into it 😸

@y86-dev
Copy link
Member Author

y86-dev commented Apr 13, 2024

We try to give good-first-issues to people who do not yet have commits in the kernel. It helps folks getting familiar with the kernel development process. We also try to pick easy/trivial fixes as good-first-issues. AFAIK you already submitted a good-first-issue, so it would be best to leave this up to someone else :)

@vincenzopalazzo
Copy link

Make sense!

@vadorovsky
Copy link

I can take it.

@Steffo99
Copy link

Steffo99 commented Jul 9, 2024

Hi!

I'd be interested in taking this issue to both learn to contribute to Rust for Linux and to submit my first patch to the Linux kernel, which is a requirement to pass the Kernel Hacking university course I've been attending.

@vadorovsky, are you still working on it?
(I'm sending you a ping on the Fediverse too as soon as I post this, just to make sure that you see it...)

Can I take this issue?

@Steffo99
Copy link

Got an answer by @vadorovsky on the Fediverse!

Seems like he's still working on it :)

I'll look for another issue!

@vadorovsky
Copy link

Yes, I'm still working on it. Here is my WIP branch: https://gitlab.com/vadorovsky/linux/-/commits/rust-cstr

Before sending it, I still want to polish it a bit. I'm also thinking how to handle the fact that alloc::CString doesn't have any equivalent of try_from_fmt, but my idea for now is to add CStringExt. I'm coding it right now. If I'm happy from the result, I will add it and send it to the ML.

@vadorovsky
Copy link

@ojeda ojeda added the medium Expected to be an issue of medium difficulty to resolve. label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers • lib Related to the `rust/` library. medium Expected to be an issue of medium difficulty to resolve.
Development

No branches or pull requests

5 participants