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

Android: make std thread APIs work #3618

Closed
1 of 2 tasks
RalfJung opened this issue May 19, 2024 · 5 comments · Fixed by #3992
Closed
1 of 2 tasks

Android: make std thread APIs work #3618

RalfJung opened this issue May 19, 2024 · 5 comments · Fixed by #3992
Assignees
Labels
A-shims Area: This affects the external function shims C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement E-good-first-issue A good way to start contributing, mentoring is available

Comments

@RalfJung
Copy link
Member

RalfJung commented May 19, 2024

Basic thread spawning works on Android, but some things are still missing:

  • setting/getting the thread name. This needs prctl commands PR_SET_NAME and PR_GET_NAME.
  • the std synchronization primitives, which are built on futexes. Since Android uses the Linux kernel, futex support can be shared with Linux; this just requires a bit of refactoring to avoid copy-pasting all this.

(Also, we're looking for a target maintainer for Android, so please let us know if you're up to that -- basically someone we'd ping when there are Android questions, and in case std starts using a new Android API we'd hope they would be able to provide a Miri implementation.)

@RalfJung RalfJung added C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement A-shims Area: This affects the external function shims E-good-first-issue A good way to start contributing, mentoring is available labels May 19, 2024
@YohDeadfall
Copy link
Contributor

@rustbot claim

@YohDeadfall
Copy link
Contributor

How should the code be refactored to share the sync module between linux and android? The last one is based on Linux, but has different user space which is compatible in some points. So, at least for me it means that for these places the shared part should be under linux module. Even some parts made for android can be interpreted for linux also like prctl.

How do you see the refactoring?

@RalfJung
Copy link
Member Author

RalfJung commented Oct 5, 2024

The easiest thing to do for futexes seems to be to move the Linux syscall shim into a separate function (still in the linux folder), and call that from Android.

Even some parts made for android can be interpreted for linux also like prctl.

That could do the same, have a function in the linux folder that is called from linux/foreign_items.rs and android/foreign_items.rs. The most tricky part here is how to test this without too much code duplication...

@YohDeadfall
Copy link
Contributor

Got you, thanks!

There's one thing which is unclear to me. How do you decide what Miri should cover and in which cases? Since the issue is about prctl let's take it as an example. That system call is also available for linux, but its libc has prctl in it, but according to the implementation it won't be supported. That makes it's impossible to use prctl with Miri if someone decided to use it directly for whatever reason.

@RalfJung
Copy link
Member Author

RalfJung commented Oct 5, 2024

Generally we want to support what std needs. On top of that if things are widely used out there we'll consider adding support for them (if the API can be implemented and maintained with reasonable effort).

For prctl, given that we anyway have to carry an implementation for Android, we might as well expose it on Linux, too.

bors added a commit that referenced this issue Oct 21, 2024
Android: Added support for prctl handling thread names

Addresses the first part of #3618.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-shims Area: This affects the external function shims C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement E-good-first-issue A good way to start contributing, mentoring is available
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants