Bug 216568 - [pcm] SNDCTL_DSP_GETERROR always fails with -m32 on 64bit system
Summary: [pcm] SNDCTL_DSP_GETERROR always fails with -m32 on 64bit system
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Only Me
Assignee: Christos Margiolis
URL:
Keywords: needs-patch
Depends on:
Blocks:
 
Reported: 2017-01-29 07:32 UTC by Jan Beich
Modified: 2025-09-30 09:19 UTC (History)
3 users (show)

See Also:


Attachments
Testcase (5.98 KB, text/plain)
2025-09-13 04:10 UTC, Damjan Jovanovic
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2017-01-29 07:32:26 UTC
$ cat >a.c
#include <sys/soundcard.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <err.h>

int main()
{
    int fd = open("/dev/dsp", O_RDWR, 0);
    audio_errinfo ei;

    if (ioctl(fd, SNDCTL_DSP_GETERROR, &ei) < 0)
	err(1, "SNDCTL_DSP_GETERROR");

    return 0;
}

$ cc -o foo a.c
$ cc -m32 -o bar a.c
$ ./foo
$ ./bar
bar: SNDCTL_DSP_GETERROR: Invalid argument
Comment 1 Konstantin Belousov freebsd_committer freebsd_triage 2017-01-29 09:56:07 UTC
The issue is not limited to DSP_GETERROR only; the sys/dev/sound code lacks COMPAT32 shims at all. The task to add them is not technically complicated but requires patience and understanding what to test.
Comment 2 Damjan Jovanovic 2025-09-12 16:56:03 UTC
(In reply to Konstantin Belousov from comment #1)

It's much easier than it looks: only 5 ioctls and maybe mmap() need COMPAT_FREEBSD32 shims.

In sys/sys/soundcard.h only these 9 structs have "long" fields, whose sizes on 32 vs 64 bit FreeBSD will differ (luckily the vast majority of the OSS API uses "int"):

Struct             | Used in
-------------------+-------------------------------------
snd_chan_param     | AIOGFMT, AIOSFMT
snd_sync_parm      | AIOSYNC
snd_capabilities   | AIOGCAP
struct patch_info  | struct patmgr_info
struct sysex_info  | unused?
struct patmgr_info | SNDCTL_PMGR_ACCESS, SNDCTL_PMGR_IFACE
struct synth_info  | SNDCTL_SYNTH_INFO
struct midi_info   | SNDCTL_MIDI_INFO
audio_errinfo      | SNDCTL_DSP_GETERROR

Also this struct uses a pointer:

typedef struct buffmem_desc {
        caddr_t buffer;
        int size;
} buffmem_desc;

and is used in SNDCTL_DSP_MAPINBUF, SNDCTL_DSP_MAPOUTBUF.

That's a total of 11 ioctls that would have to get COMPAT_FREEBSD32 shims. However FreeBSD doesn't currently implement SNDCTL_PMGR_ACCESS, SNDCTL_PMGR_IFACE, SNDCTL_SYNTH_INFO or SNDCTL_MIDI_INFO in any bitness (in sys/dev/sound/midi/midi.c, midi_ioctl() return ENXIO for everything). FreeBSD doesn't implement SNDCTL_DSP_MAPINBUF or SNDCTL_DSP_MAPOUTBUF either - dsp_ioctl() has a comment saying "undocumented" and returns EINVAL.

11 - 6 = 5 ioctls that needs COMPAT_FREEBSD32 shims:
snd_chan_param     | AIOGFMT, AIOSFMT
snd_sync_parm      | AIOSYNC
snd_capabilities   | AIOGCAP
audio_errinfo      | SNDCTL_DSP_GETERROR
and maybe some mmap() changes.

I am going to try implement this.
Comment 3 Damjan Jovanovic 2025-09-13 04:10:52 UTC
Created attachment 263756 [details]
Testcase

I've implemented a patch for this, please see: https://reviews.freebsd.org/D52509
Only the ioctls were necessary - playing audio over mmap() already works.

The attached test case tests the 32 bit ioctls and plays a 2100 Hz tone through mmap():
cc oss-compat32-test.c -o oss-compat32-test -lm -m32
./oss-compat32-test
(Ctrl+C to exit)
Comment 4 commit-hook freebsd_committer freebsd_triage 2025-09-23 19:00:42 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=749a9266982b8e012b5ec370b2fdfef11f34c0b2

commit 749a9266982b8e012b5ec370b2fdfef11f34c0b2
Author:     Damjan Jovanovic <damjan.jov@gmail.com>
AuthorDate: 2025-09-23 18:59:05 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2025-09-23 18:59:05 +0000

    sound: Implement COMPAT_FREEBSD32 shims

    PR:             216568
    MFC after:      1 week
    Reviewed by:    christos, kib
    Differential Revision:  https://reviews.freebsd.org/D52509

 sys/dev/sound/pcm/dsp.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 118 insertions(+), 1 deletion(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2025-09-30 09:18:29 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=782a376911eb61ee59310bfc779363a2a3939c30

commit 782a376911eb61ee59310bfc779363a2a3939c30
Author:     Damjan Jovanovic <damjan.jov@gmail.com>
AuthorDate: 2025-09-23 18:59:05 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2025-09-30 09:17:26 +0000

    sound: Implement COMPAT_FREEBSD32 shims

    PR:             216568
    MFC after:      1 week
    Reviewed by:    christos, kib
    Differential Revision:  https://reviews.freebsd.org/D52509

    (cherry picked from commit 749a9266982b8e012b5ec370b2fdfef11f34c0b2)

 sys/dev/sound/pcm/dsp.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 118 insertions(+), 1 deletion(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2025-09-30 09:18:31 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=d0e8c94631267f07c90465faf5b47dcce0e232be

commit d0e8c94631267f07c90465faf5b47dcce0e232be
Author:     Damjan Jovanovic <damjan.jov@gmail.com>
AuthorDate: 2025-09-23 18:59:05 +0000
Commit:     Christos Margiolis <christos@FreeBSD.org>
CommitDate: 2025-09-30 09:18:07 +0000

    sound: Implement COMPAT_FREEBSD32 shims

    PR:             216568
    MFC after:      1 week
    Reviewed by:    christos, kib
    Differential Revision:  https://reviews.freebsd.org/D52509

    (cherry picked from commit 749a9266982b8e012b5ec370b2fdfef11f34c0b2)

 sys/dev/sound/pcm/dsp.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 118 insertions(+), 1 deletion(-)