0
Fork 0
mirror of https://github.com/Droid-VM/crosvm.git synced 2026-11-17 06:58:03 +00:00
crosvm/common
HuJK 3a8395ae11 virtio-snd: an AAudio backend with named endpoints, and a device that can drop root
crosvm's virtio-snd had no way to reach Android audio, and even with a backend
it could not have made a sound: a stream opened by uid 0 is silenced by the
platform, and crosvm runs as root here. So the backend has two halves.

The device can run somewhere else. `--virtio-snd uid=`/`gid=`/`supp_gids=` forks
and execs `crosvm device snd` under that uid over a socketpair, the way
--shared-dir and --pmem-ext2 already place theirs. exec is mandatory rather than
tidy: binder cannot be inherited across a bare fork, and AAudio is binder. The
PDEATHSIG goes on after the setuid, since the kernel clears it when credentials
change. Privilege is dropped with setresuid, not setuid -- setuid's saved-uid
path under CAP_SETUID updates cred->ucounts but not cred->user, so the process's
NPROC charge is never added yet is subtracted on exit; the counter goes negative
and every later fork by that uid fails, which on Android means the app the VM
belongs to can no longer be launched. A server that has already dropped also
stops trying to become whoever a guest fs request names, since it cannot, and
the attempt takes the whole operation down with EPERM.

Endpoints are named and typed. A card carries a list of PCM devices, each pinned
to one AudioDeviceInfo id, each declaring what it is for; the guest is told the
real device type rather than a generic one, and each endpoint offers only the
formats it can actually open. A float-only device gets no endpoint at all
instead of a broken one -- crosvm's wire format list has no FLOAT, so a device
that supports nothing else has nothing to advertise. The format axis is
otherwise left wide because Windows does not renegotiate a cached one: narrow
it after the guest has looked once and the guest never asks again.

Underruns can hold the last period instead of playing silence
(`underrun=hold`), with WSOLA and LPC variants, and an idle stream releases its
endpoint so the platform can route someone else. Playback position is
interpolated from what has actually been consumed rather than from a free-running
QPC: the two drift, and a WaveRT guest reading the QPC-derived position writes
into a buffer the host has not finished with, which is audible as a tear at the
seam.

One executor bug came out of this and is fixed here rather than around: an
`ex.delay(Duration::ZERO)` arms a timerfd with an all-zero itimerspec, which
*disarms* it -- the descriptor never becomes readable and the task never wakes.
A scheduler pacing against a wall clock reaches zero the moment it falls behind,
so on a phone this was a matter of time, and the symptom was audio going silent
for good after a few minutes.
History 2026-08-30 14:09:31 +08:00
..
audio_streams virtio-snd: an AAudio backend with named endpoints, and a device that can drop root 2026-08-30 14:09:31 +08:00
balloon_control ANDROID: simplify crosvm_defaults 2025-02-10 18:41:03 -08:00
cros_async ANDROID: delete empty TEST_MAPPING files 2023-10-25 14:39:05 -07:00
data_model Merge remote-tracking branch 'aosp/upstream-main' into merge 2025-02-25 18:10:03 +00:00
io_uring ANDROID: delete empty TEST_MAPPING files 2023-10-25 14:39:05 -07:00
sync ANDROID: simplify crosvm_defaults 2025-02-10 18:41:03 -08:00
chromeos_warning.md Add version pin warning to common/ 2022-04-15 19:51:35 +00:00
README.md Revert "ANDROID: Revert "Replace internal p9 with crates.io versio"" 2024-01-30 17:54:40 -08:00

Crosvm General Purpose Libraries

The crates in this folder are general purpose libraries used by other projects in ChromeOS as well.

To make them accessible independendly of crosvm, each of these crates is excluded from the crosvm workspace.