From a2b7bcce27997aa77c05288ff6a560ac2f1f677a Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 21 Sep 2025 15:24:06 +0900 Subject: [PATCH 1/7] musl: introduce dummy gshadow header file for userdb Even 'gshadow' meson option is disabled, src/shared/userdb.c and src/shared/user-record-nss.c include gshadow.h unconditionally. Let's introduce dummy header to make them compiled gracefully. --- src/include/musl/gshadow.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/include/musl/gshadow.h diff --git a/src/include/musl/gshadow.h b/src/include/musl/gshadow.h new file mode 100644 index 0000000000..b57c74ca83 --- /dev/null +++ b/src/include/musl/gshadow.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include +#include + +struct sgrp { + char *sg_namp; + char *sg_passwd; + char **sg_adm; + char **sg_mem; +}; + +static inline int getsgnam_r( + const char *__name, + struct sgrp *__result_buf, + char *__buffer, + size_t __buflen, + struct sgrp **__result) { + + return EOPNOTSUPP; /* this function returns positive errno in case of error. */ +} From bc610c70afcfe3cc489ecc18178f5d62d74e0d9b Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 10 Jun 2025 00:40:59 +0900 Subject: [PATCH 2/7] musl: introduce dummy functions for mallinfo(), malloc_info(), and malloc_trim() These functions are not provided by musl. --- src/include/musl/malloc.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/include/musl/malloc.h diff --git a/src/include/musl/malloc.h b/src/include/musl/malloc.h new file mode 100644 index 0000000000..9d15d4bf91 --- /dev/null +++ b/src/include/musl/malloc.h @@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include +#include + +/* struct mallinfo2 will be defined and struct mallinfo is converted to struct mallinfo2 in + * override/malloc.h. Hence, here we define struct mallinfo. */ + +struct mallinfo { + int arena; /* non-mmapped space allocated from system */ + int ordblks; /* number of free chunks */ + int smblks; /* number of fastbin blocks */ + int hblks; /* number of mmapped regions */ + int hblkhd; /* space in mmapped regions */ + int usmblks; /* always 0, preserved for backwards compatibility */ + int fsmblks; /* space available in freed fastbin blocks */ + int uordblks; /* total allocated space */ + int fordblks; /* total free space */ + int keepcost; /* top-most, releasable (via malloc_trim) space */ +}; + +static inline struct mallinfo mallinfo(void) { + return (struct mallinfo) {}; +} + +static inline int malloc_info(int options, FILE *stream) { + if (options != 0) + errno = EINVAL; + else + errno = EOPNOTSUPP; + return -1; +} + +static inline int malloc_trim(size_t pad) { + return 0; +} + +#include_next From 03d0fa4e4f824b725e3f250f70f4725c569c60a4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 8 Jun 2025 10:07:54 +0900 Subject: [PATCH 3/7] musl: introduce dummy function for gnu_get_libc_version() As the header gnu/libc-version.h and gnu_get_libc_version() function are glibc specific, and musl does not provide them. --- src/include/musl/gnu/libc-version.h | 8 ++++++++ src/test/test-condition.c | 26 ++++++++++++++++++++------ 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 src/include/musl/gnu/libc-version.h diff --git a/src/include/musl/gnu/libc-version.h b/src/include/musl/gnu/libc-version.h new file mode 100644 index 0000000000..328b53e166 --- /dev/null +++ b/src/include/musl/gnu/libc-version.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include + +static inline const char* gnu_get_libc_version(void) { + return ""; +} diff --git a/src/test/test-condition.c b/src/test/test-condition.c index 11b3a42418..1bae2e3dd8 100644 --- a/src/test/test-condition.c +++ b/src/test/test-condition.c @@ -669,12 +669,14 @@ TEST(condition_test_version) { condition_free(condition); /* Test glibc version */ + bool has = !isempty(gnu_get_libc_version()); + ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, "glibc > 1", false, false))); - ASSERT_OK_POSITIVE(condition_test(condition, environ)); + ASSERT_OK_EQ(condition_test(condition, environ), has); condition_free(condition); ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, "glibc < 2", false, false))); - ASSERT_OK_ZERO(condition_test(condition, environ)); + ASSERT_OK_EQ(condition_test(condition, environ), !has); condition_free(condition); ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, "glibc < 9999", false, false))); @@ -686,15 +688,27 @@ TEST(condition_test_version) { condition_free(condition); v = strjoina("glibc = ", gnu_get_libc_version()); - ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, v, false, false))); - ASSERT_OK_POSITIVE(condition_test(condition, environ)); + if (has) + ASSERT_OK_POSITIVE(condition_test(condition, environ)); + else + ASSERT_ERROR(condition_test(condition, environ), EINVAL); condition_free(condition); v = strjoina("glibc != ", gnu_get_libc_version()); - ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, v, false, false))); - ASSERT_OK_ZERO(condition_test(condition, environ)); + if (has) + ASSERT_OK_ZERO(condition_test(condition, environ)); + else + ASSERT_ERROR(condition_test(condition, environ), EINVAL); + condition_free(condition); + + ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, "glibc $= ?*", false, false))); + ASSERT_OK_EQ(condition_test(condition, environ), has); + condition_free(condition); + + ASSERT_NOT_NULL((condition = condition_new(CONDITION_VERSION, "glibc !$= ?*", false, false))); + ASSERT_OK_EQ(condition_test(condition, environ), !has); condition_free(condition); } From 6400e8dbd96bb45e88e8e6b4e035fe186a5ab743 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 23 Jun 2025 16:00:21 +0900 Subject: [PATCH 4/7] musl: provide several missing definitions for prctl() --- src/include/musl/sys/prctl.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/include/musl/sys/prctl.h diff --git a/src/include/musl/sys/prctl.h b/src/include/musl/sys/prctl.h new file mode 100644 index 0000000000..0473a706cc --- /dev/null +++ b/src/include/musl/sys/prctl.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include_next /* IWYU pragma: export */ + +/* musl's sys/prctl.h does not include linux/prctl.h, and also we cannot include with linux/prctl.h. + * Hence, we need to provide some missing definitions. */ + +#ifndef PR_SET_MDWE +#define PR_SET_MDWE 65 +#endif + +#ifndef PR_MDWE_REFUSE_EXEC_GAIN +#define PR_MDWE_REFUSE_EXEC_GAIN (1UL << 0) +#endif + +#ifndef PR_SET_MEMORY_MERGE +#define PR_SET_MEMORY_MERGE 67 +#endif From 8324ef421373c84b5034bf47b84fe42d84b1032f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Mon, 23 Jun 2025 16:08:37 +0900 Subject: [PATCH 5/7] musl: replace netinet/if_ether.h with our own implementation musl's netinet/if_ether.h conflicts with linux/if_ether.h. The reimplementation is mostly equivalent with what glibc does. --- src/include/musl/netinet/if_ether.h | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/include/musl/netinet/if_ether.h diff --git a/src/include/musl/netinet/if_ether.h b/src/include/musl/netinet/if_ether.h new file mode 100644 index 0000000000..62f4ac03b3 --- /dev/null +++ b/src/include/musl/netinet/if_ether.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +/* glibc's netinet/if_ether.h does the following: + * - include linux/if_ether.h, net/ethernet.h, and net/if_arp.h, + * - define struct ether_arp, and relevant macros, + * - define ETHER_MAP_IP_MULTICAST() macro (currently we do not use it). + * However, musl's netinet/if_ether.h conflicts with linux/if_ether.h. + * Let's use the same way that glibc uses. */ + +#include /* IWYU pragma: export */ +#include /* IWYU pragma: export */ +#include /* IWYU pragma: export */ + +/* + * Ethernet Address Resolution Protocol. + * + * See RFC 826 for protocol description. Structure below is adapted + * to resolving internet addresses. Field names used correspond to + * RFC 826. + */ +struct ether_arp { + struct arphdr ea_hdr; /* fixed-size header */ + uint8_t arp_sha[ETH_ALEN]; /* sender hardware address */ + uint8_t arp_spa[4]; /* sender protocol address */ + uint8_t arp_tha[ETH_ALEN]; /* target hardware address */ + uint8_t arp_tpa[4]; /* target protocol address */ +}; +#define arp_hrd ea_hdr.ar_hrd +#define arp_pro ea_hdr.ar_pro +#define arp_hln ea_hdr.ar_hln +#define arp_pln ea_hdr.ar_pln +#define arp_op ea_hdr.ar_op From dd102894e7629b3fcbaf5ea3f26ed5f9d4c0cfbb Mon Sep 17 00:00:00 2001 From: Chen Qi Date: Mon, 25 Feb 2019 15:00:06 +0800 Subject: [PATCH 6/7] musl: add missing FTW_CONTINUE macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is to avoid build failures like below for musl. test-recurse-dir.c:23:24: error: ‘FTW_CONTINUE’ undeclared Co-authored-by: Yu Watanabe --- src/include/musl/ftw.h | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/include/musl/ftw.h diff --git a/src/include/musl/ftw.h b/src/include/musl/ftw.h new file mode 100644 index 0000000000..fd153734d0 --- /dev/null +++ b/src/include/musl/ftw.h @@ -0,0 +1,8 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include_next + +#ifndef FTW_CONTINUE +#define FTW_CONTINUE 0 +#endif From 69dd6d94200abf7010bc8c85cfe294e959014058 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 22 Jun 2025 00:38:58 +0900 Subject: [PATCH 7/7] musl: add several missing statx macros glibc's sys/stat.h includes linux/stat.h, and we have copy of it from the latest kernel, hence all new flags are always defined. However, musl's sys/stat.h does not include linux/stat.h, and moreover, they conflict with each other, hence we cannot include both header simultaneously. Let's define missing macros to support musl. --- src/include/musl/sys/stat.h | 66 +++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/include/musl/sys/stat.h diff --git a/src/include/musl/sys/stat.h b/src/include/musl/sys/stat.h new file mode 100644 index 0000000000..610dd3e699 --- /dev/null +++ b/src/include/musl/sys/stat.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include_next + +#include +#include + +/* musl's sys/stat.h does not include linux/stat.h, and unfortunately they conflict with each other. + * Hence, some relatively new macros need to be explicitly defined here. */ + +/* Before 23ab04a8630225371455d5f4538fd078665bb646, statx.stx_mnt_id is not defined. */ +#ifndef STATX_MNT_ID +static_assert(offsetof(struct statx, __pad1) == offsetof(struct statx, stx_dev_minor) + sizeof(uint32_t), ""); +#define stx_mnt_id __pad1[0] +#endif + +#ifndef STATX_MNT_ID +#define STATX_MNT_ID 0x00001000U +#endif +#ifndef STATX_DIOALIGN +#define STATX_DIOALIGN 0x00002000U +#endif +#ifndef STATX_MNT_ID_UNIQUE +#define STATX_MNT_ID_UNIQUE 0x00004000U +#endif +#ifndef STATX_SUBVOL +#define STATX_SUBVOL 0x00008000U +#endif +#ifndef STATX_WRITE_ATOMIC +#define STATX_WRITE_ATOMIC 0x00010000U +#endif +#ifndef STATX_DIO_READ_ALIGN +#define STATX_DIO_READ_ALIGN 0x00020000U +#endif + +#ifndef STATX_ATTR_COMPRESSED +#define STATX_ATTR_COMPRESSED 0x00000004 +#endif +#ifndef STATX_ATTR_IMMUTABLE +#define STATX_ATTR_IMMUTABLE 0x00000010 +#endif +#ifndef STATX_ATTR_APPEND +#define STATX_ATTR_APPEND 0x00000020 +#endif +#ifndef STATX_ATTR_NODUMP +#define STATX_ATTR_NODUMP 0x00000040 +#endif +#ifndef STATX_ATTR_ENCRYPTED +#define STATX_ATTR_ENCRYPTED 0x00000800 +#endif +#ifndef STATX_ATTR_AUTOMOUNT +#define STATX_ATTR_AUTOMOUNT 0x00001000 +#endif +#ifndef STATX_ATTR_MOUNT_ROOT +#define STATX_ATTR_MOUNT_ROOT 0x00002000 +#endif +#ifndef STATX_ATTR_VERITY +#define STATX_ATTR_VERITY 0x00100000 +#endif +#ifndef STATX_ATTR_DAX +#define STATX_ATTR_DAX 0x00200000 +#endif +#ifndef STATX_ATTR_WRITE_ATOMIC +#define STATX_ATTR_WRITE_ATOMIC 0x00400000 +#endif