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 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/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. */ +} 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 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 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 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 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); }