pipewire: remove redundant byteswap.h and sys/mman.h shims
relibc now provides the real <byteswap.h> header and Linux mmap extension flags (MAP_LOCKED, MAP_HUGETLB, etc.) in <sys/mman.h>. Drop the redox_compat/ shim files and the recipe's staging/copy step so PipeWire uses relibc's real headers. memfd_create and pthread_setname_np/thread-name Redox guards remain in the patch because relibc does not yet provide those.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
From 016669f7b92b7e4799a8810246a2f025f0e9dadf Mon Sep 17 00:00:00 2001
|
||||
From: Red Bear OS <vasilito@redbearos.org>
|
||||
Date: Tue, 9 Jun 2026 11:38:13 +0300
|
||||
Subject: [PATCH] pipewire: Redox compat shims (byteswap, mman, memfd, thread name)
|
||||
Subject: [PATCH] pipewire: Redox compat shims (memfd, thread name)
|
||||
MIME-Version: 1.0
|
||||
Content-Type: text/plain; charset=UTF-8
|
||||
Content-Transfer-Encoding: 8bit
|
||||
@@ -37,43 +37,20 @@ Changes (vs upstream 0.3.85):
|
||||
pool expects. The sealing fcntls are accepted as no-ops since
|
||||
ramfs has no sealing primitives.
|
||||
|
||||
* redox_compat/byteswap.h - shim header that exposes the glibc
|
||||
<byteswap.h> API (bswap_16, bswap_32, bswap_64) on top of relibc's
|
||||
<endian.h>. The PipeWire SPA audio plugin source includes
|
||||
<byteswap.h> unconditionally on non-FreeBSD / non-MidnightBSD
|
||||
platforms, and relibc does not yet ship this header.
|
||||
|
||||
* redox_compat/sys/mman.h - shim header that adds the Linux mmap
|
||||
extension flags (MAP_LOCKED, MAP_HUGETLB, MAP_NORESERVE,
|
||||
MAP_POPULATE, MAP_NONBLOCK, MAP_DENYWRITE, MAP_EXECUTABLE,
|
||||
MAP_GROWSDOWN) on top of relibc's <sys/mman.h>. The flag values
|
||||
match the Linux kernel UABI so any downstream code that forwards
|
||||
the flag bits to a real syscall does the right thing; the Redox
|
||||
kernel silently ignores the flags it does not implement, which
|
||||
matches POSIX (best-effort).
|
||||
|
||||
The recipe (local/recipes/libs/pipewire/recipe.toml) stages the
|
||||
redox_compat/ headers into the per-recipe sysroot so they are
|
||||
visible to every meson subproject (spa/plugins/* etc.) - the cross
|
||||
file's c_args are not inherited by subprojects, and this shim
|
||||
folder is the cleanest way to make the headers universally
|
||||
available without per-target c_args plumbing.
|
||||
The previous byteswap.h and sys/mman.h shims have been removed because
|
||||
relibc now provides the real <byteswap.h> and Linux mmap extension flags
|
||||
(MAP_LOCKED, MAP_HUGETLB, etc.) in <sys/mman.h>. See commits adding those
|
||||
headers to local/sources/relibc/.
|
||||
|
||||
These are real implementations, not stubs. memfd_create produces
|
||||
a working fd. bswap_N functions actually perform the byte swap.
|
||||
MAP_LOCKED has the right UABI value. pthread_setname_np is a
|
||||
no-op (the operation is best-effort and the underlying relibc
|
||||
implementation is the actual gap, not the PipeWire glue).
|
||||
a working fd. pthread_setname_np is a no-op (the operation is
|
||||
best-effort and the underlying relibc implementation is the actual gap,
|
||||
not the PipeWire glue).
|
||||
|
||||
Tracking: relibc gaps that remain (and are NOT addressed by these
|
||||
shims):
|
||||
* sys/prctl.h - used by src/pipewire/pipewire.c
|
||||
* sys/mount.h - used by src/pipewire/utils.h
|
||||
* Several Linux-only ioctls and Linux-specific signalfd paths
|
||||
When relibc lands the real headers, the shim headers in
|
||||
redox_compat/ can be removed and the recipe's staging step
|
||||
deleted. The shim guards against the system headers being
|
||||
shadowed only on __redox__ targets.
|
||||
Tracking: relibc gaps that remain (and are NOT addressed by this patch):
|
||||
* sys/prctl.h - used by src/pipewire/pipewire.c
|
||||
* sys/mount.h - used by src/pipewire/utils.h
|
||||
* Several Linux-only ioctls and Linux-specific signalfd paths
|
||||
|
||||
Build state at fork HEAD: meson configuration succeeds, build reaches
|
||||
~24/640 C files compiled before hitting the remaining relibc
|
||||
@@ -81,139 +58,10 @@ gaps. The remaining work is a relibc port, not a PipeWire port -
|
||||
each blocked file is a real missing header in relibc, not a
|
||||
missing porting decision in this patch.
|
||||
---
|
||||
redox_compat/byteswap.h | 56 ++++++++++++++++++++++++++++++++++++++++
|
||||
redox_compat/sys/mman.h | 57 +++++++++++++++++++++++++++++++++++++++++
|
||||
src/pipewire/mem.c | 25 ++++++++++++++++++
|
||||
src/pipewire/thread.c | 26 +++++++++++++++++++
|
||||
4 files changed, 164 insertions(+)
|
||||
create mode 100644 redox_compat/byteswap.h
|
||||
create mode 100644 redox_compat/sys/mman.h
|
||||
2 files changed, 51 insertions(+)
|
||||
|
||||
diff --git a/redox_compat/byteswap.h b/redox_compat/byteswap.h
|
||||
new file mode 100644
|
||||
index 0000000..e9b3520
|
||||
--- /dev/null
|
||||
+++ b/redox_compat/byteswap.h
|
||||
@@ -0,0 +1,56 @@
|
||||
+/*
|
||||
+ * byteswap.h — Redox compatibility shim for the glibc <byteswap.h> header.
|
||||
+ *
|
||||
+ * glibc's <byteswap.h> provides bswap_16, bswap_32, bswap_64, bswap_128
|
||||
+ * inline functions that perform raw byte-swap operations. Redox's relibc
|
||||
+ * provides <endian.h> with the equivalent functionality as htobe* and
|
||||
+ * be*toh macros. This shim exposes the byteswap.h API on top of relibc's
|
||||
+ * endian primitives so that upstream code that includes <byteswap.h> works
|
||||
+ * unchanged on Redox.
|
||||
+ *
|
||||
+ * This shim is part of the Red Bear OS PipeWire source fork. The
|
||||
+ * corresponding upstream PipeWire source includes <byteswap.h> directly
|
||||
+ * on non-FreeBSD / non-MidnightBSD platforms; this shim is reached by
|
||||
+ * adding -I${REDOX_COMPAT_DIR} to CFLAGS in local/recipes/libs/pipewire/
|
||||
+ * recipe.toml. The shim is used *instead of* the system byteswap.h on
|
||||
+ * __redox__ targets.
|
||||
+ *
|
||||
+ * This is a real implementation, not a stub: every bswap_N function
|
||||
+ * actually performs the byte swap, and the function semantics match
|
||||
+ * glibc's byteswap.h (bswap_32(x) returns a 32-bit value with bytes
|
||||
+ * reversed; bswap_64(x) returns a 64-bit value with bytes reversed).
|
||||
+ *
|
||||
+ * Tracking: a real <byteswap.h> is planned for upstream relibc. Once
|
||||
+ * that lands, this shim should be removed and the recipe's CFLAGS
|
||||
+ * adjusted. See local/sources/pipewire/README-redbear.md.
|
||||
+ */
|
||||
+#ifndef REDBEAR_PIPEWIRE_BYTESWAP_H
|
||||
+#define REDBEAR_PIPEWIRE_BYTESWAP_H
|
||||
+
|
||||
+#include <endian.h>
|
||||
+#include <stdint.h>
|
||||
+
|
||||
+static inline uint16_t bswap_16(uint16_t __x)
|
||||
+{
|
||||
+ return (uint16_t)(((uint16_t)(__x & 0x00ff) << 8) | ((__x & 0xff00) >> 8));
|
||||
+}
|
||||
+
|
||||
+static inline uint32_t bswap_32(uint32_t __x)
|
||||
+{
|
||||
+ return ((((__x) & 0xff000000u) >> 24) | (((__x) & 0x00ff0000u) >> 8) |
|
||||
+ (((__x) & 0x0000ff00u) << 8) | (((__x) & 0x000000ffu) << 24));
|
||||
+}
|
||||
+
|
||||
+static inline uint64_t bswap_64(uint64_t __x)
|
||||
+{
|
||||
+ return ((((__x) & 0xff00000000000000ull) >> 56) |
|
||||
+ (((__x) & 0x00ff000000000000ull) >> 40) |
|
||||
+ (((__x) & 0x0000ff0000000000ull) >> 24) |
|
||||
+ (((__x) & 0x000000ff00000000ull) >> 8) |
|
||||
+ (((__x) & 0x00000000ff000000ull) << 8) |
|
||||
+ (((__x) & 0x0000000000ff0000ull) << 24) |
|
||||
+ (((__x) & 0x000000000000ff00ull) << 40) |
|
||||
+ (((__x) & 0x00000000000000ffull) << 56));
|
||||
+}
|
||||
+
|
||||
+#endif /* REDBEAR_PIPEWIRE_BYTESWAP_H */
|
||||
diff --git a/redox_compat/sys/mman.h b/redox_compat/sys/mman.h
|
||||
new file mode 100644
|
||||
index 0000000..4102f79
|
||||
--- /dev/null
|
||||
+++ b/redox_compat/sys/mman.h
|
||||
@@ -0,0 +1,57 @@
|
||||
+/*
|
||||
+ * sys/mman.h — Redox compatibility shim for Linux-specific mmap flags.
|
||||
+ *
|
||||
+ * relibc's <sys/mman.h> provides the POSIX mmap() flags (MAP_SHARED,
|
||||
+ * MAP_PRIVATE, MAP_ANON, MAP_FIXED, etc.) but is missing the Linux
|
||||
+ * extensions (MAP_LOCKED, MAP_HUGETLB, MAP_NORESERVE, MAP_POPULATE,
|
||||
+ * MAP_NONBLOCK, MAP_STACK, MAP_DENYWRITE on older glibc, etc.).
|
||||
+ *
|
||||
+ * This shim pulls in the upstream relibc header first and then adds
|
||||
+ * the Linux extension flags that PipeWire and SPA actually use. The
|
||||
+ * value of MAP_LOCKED matches the Linux kernel's UAPI value (0x2000),
|
||||
+ * which is what the kernel expects on a real mmap call; on Redox
|
||||
+ * where the kernel does not honor MAP_LOCKED, the mmap still succeeds
|
||||
+ * and the memory is simply not pre-locked (POSIX allows this — the
|
||||
+ * call is best-effort and a portable program must tolerate either
|
||||
+ * behavior).
|
||||
+ *
|
||||
+ * This is a real implementation, not a stub: every flag here matches
|
||||
+ * the Linux kernel UABI value, so any downstream code that does a
|
||||
+ * syscall (or a libc call that forwards the flag) will pass the right
|
||||
+ * bit pattern.
|
||||
+ *
|
||||
+ * Tracking: a complete <sys/mman.h> with all Linux extensions is
|
||||
+ * planned for upstream relibc. Once that lands, this shim should be
|
||||
+ * removed. See local/sources/pipewire/README-redbear.md.
|
||||
+ */
|
||||
+#ifndef REDBEAR_PIPEWIRE_SYS_MMAN_H
|
||||
+#define REDBEAR_PIPEWIRE_SYS_MMAN_H
|
||||
+
|
||||
+#include_next <sys/mman.h>
|
||||
+
|
||||
+#ifndef MAP_LOCKED
|
||||
+#define MAP_LOCKED 0x02000
|
||||
+#endif
|
||||
+#ifndef MAP_HUGETLB
|
||||
+#define MAP_HUGETLB 0x40000
|
||||
+#endif
|
||||
+#ifndef MAP_NORESERVE
|
||||
+#define MAP_NORESERVE 0x04000
|
||||
+#endif
|
||||
+#ifndef MAP_POPULATE
|
||||
+#define MAP_POPULATE 0x08000
|
||||
+#endif
|
||||
+#ifndef MAP_NONBLOCK
|
||||
+#define MAP_NONBLOCK 0x10000
|
||||
+#endif
|
||||
+#ifndef MAP_DENYWRITE
|
||||
+#define MAP_DENYWRITE 0x00800
|
||||
+#endif
|
||||
+#ifndef MAP_EXECUTABLE
|
||||
+#define MAP_EXECUTABLE 0x01000
|
||||
+#endif
|
||||
+#ifndef MAP_GROWSDOWN
|
||||
+#define MAP_GROWSDOWN 0x01000
|
||||
+#endif
|
||||
+
|
||||
+#endif /* REDBEAR_PIPEWIRE_SYS_MMAN_H */
|
||||
diff --git a/src/pipewire/mem.c b/src/pipewire/mem.c
|
||||
index 7b63a30..a5f585f 100644
|
||||
--- a/src/pipewire/mem.c
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
# Bear change), and make upstream syncs a `rev = "..."` bump + patch
|
||||
# rebase instead of a full rebase of a Red Bear fork.
|
||||
#
|
||||
# All Red Bear-specific PipeWire changes (redox_compat/ shim headers
|
||||
# for byteswap.h and sys/mman.h, __redox__ guards in mem.c/thread.c
|
||||
# All Red Bear-specific PipeWire changes (__redox__ guards in mem.c/thread.c
|
||||
# for memfd_create / pthread_setname_np / sched_get_priority_*) live
|
||||
# as external patches under local/patches/pipewire/. To add a new
|
||||
# PipeWire change:
|
||||
@@ -96,17 +95,9 @@ export CXX="x86_64-unknown-redox-g++"
|
||||
export AR="x86_64-unknown-redox-ar"
|
||||
export STRIP="x86_64-unknown-redox-strip"
|
||||
export RANLIB="x86_64-unknown-redox-ranlib"
|
||||
export CFLAGS="-I${COOKBOOK_SOURCE}/redox_compat -I${COOKBOOK_SYSROOT}/usr/include --sysroot=${COOKBOOK_SYSROOT} -Wno-error=format-overflow -Wno-error=stringop-truncation -Wno-error=array-bounds -Wno-error=use-after-free -Wno-error=array-parameter -Wno-error=cast-function-type -Wno-error=deprecated-declarations -Wno-error=stringop-overread -Wno-error=dangling-pointer -Wno-error=uninitialized -Wno-error=maybe-uninitialized -Wno-error=incompatible-pointer-types"
|
||||
export CFLAGS="-I${COOKBOOK_SYSROOT}/usr/include --sysroot=${COOKBOOK_SYSROOT} -Wno-error=format-overflow -Wno-error=stringop-truncation -Wno-error=array-bounds -Wno-error=use-after-free -Wno-error=array-parameter -Wno-error=cast-function-type -Wno-error=deprecated-declarations -Wno-error=stringop-overread -Wno-error=dangling-pointer -Wno-error=uninitialized -Wno-error=maybe-uninitialized -Wno-error=incompatible-pointer-types"
|
||||
export LDFLAGS="--sysroot=${COOKBOOK_SYSROOT}"
|
||||
|
||||
# Stage the redox_compat shim headers (added by the external patch) into
|
||||
# the per-recipe sysroot so they are visible to every meson subproject
|
||||
# (spa/plugins/*, etc.) without having to add a per-subproject c_args
|
||||
# entry. Without this step, subprojects do not see the cross file's
|
||||
# c_args and would fail to find byteswap.h / sys/mman.h.
|
||||
mkdir -p "${COOKBOOK_SYSROOT}/usr/include"
|
||||
cp -r "${COOKBOOK_SOURCE}/redox_compat/." "${COOKBOOK_SYSROOT}/usr/include/"
|
||||
|
||||
# Disable everything Linux-specific. We only build the user-space graph core,
|
||||
# the PulseAudio compat shim, the SPA core, and a minimal set of audio-only
|
||||
# SPA support plugins that are pure C with no kernel dependencies beyond
|
||||
|
||||
Reference in New Issue
Block a user