Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Why is libc used?#5507

Answeredbytertsdiepraam
michaelCTS asked this question inQ&A
Discussion options

I have no experience with developing such binaries so please excuse the ignorance. It looks like the usage oflibc introducesunsafe code blocks in the rust code. If I'm not mistaken, it also introduces a dependency onlibc, meaning the correction version has to be present in order for coreutils to run (different versions might make lead to crash).

RedoxOS developers have an incomplete rewrite of libc (relibc), but is libc absolutely necessary? Is libc a shortcut to the implementation of certain features too complicated to implement in rust? Is rewriting those parts of libc out of scope of the project?

You must be logged in to vote

Oh good question! You're gonna get a long answer 😄

We have to do syscalls somewhere, which means that somewhere in our dependency tree, there'sunsafe. Either we useunsafe ourselves or we let some library do it for us.libc is used throughout the Rust ecosystem, even in the standard library. This also means that we are always usinglibc indirectly throughstd already. It is usually the recommended way to deal with low-level stuff, becauselibc standardizes behaviour across many platforms. However, that doesn't mean that we're stuck withlibc! We want to use as many safe abstractions overlibc as possible. Thenix crate, for example, provides safe APIs overlibc. We also (indirectly) user…

Replies: 1 comment 1 reply

Comment options

Oh good question! You're gonna get a long answer 😄

We have to do syscalls somewhere, which means that somewhere in our dependency tree, there'sunsafe. Either we useunsafe ourselves or we let some library do it for us.libc is used throughout the Rust ecosystem, even in the standard library. This also means that we are always usinglibc indirectly throughstd already. It is usually the recommended way to deal with low-level stuff, becauselibc standardizes behaviour across many platforms. However, that doesn't mean that we're stuck withlibc! We want to use as many safe abstractions overlibc as possible. Thenix crate, for example, provides safe APIs overlibc. We also (indirectly) userustix (a libc alternative). Wecould userelibc, but it only supports Linux and Redox at the moment.

Developing a libc alternative is definitely out of scope for this project, but we try to help out a bit with some of the projects I've mentioned when we need them.

Also note thatunsafe for FFI is the most acceptable form ofunsafe. Many of those APIs have no way they can cause unsound behaviour, it's just that the type system doesn't know about them. Still, using safe alternatives would of course be preferable.

You must be logged in to vote
1 reply
@michaelCTS
Comment options

Thank you! That's the detail I was looking for 👍

Answer selected bymichaelCTS
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@michaelCTS@tertsdiepraam

[8]ページ先頭

©2009-2025 Movatter.jp