diff --git a/common/shlibs b/common/shlibs index fb95180eb90..c2008ed0c7d 100644 --- a/common/shlibs +++ b/common/shlibs @@ -16,6 +16,8 @@ # PLEASE NOTE: when multiple packages provide the same SONAME, the first # one (order top->bottom) is preferred over the next ones. # +libc.so musl1.1-1.1.24_1 armv6l-musl +libc.so musl1.1-1.1.24_1 armv7l-musl libc.so musl-1.2.5_1 libc.so.6 glibc-2.41_1 libm.so.6 glibc-2.41_1 diff --git a/srcpkgs/musl1.1-devel b/srcpkgs/musl1.1-devel new file mode 120000 index 00000000000..dd781133bf8 --- /dev/null +++ b/srcpkgs/musl1.1-devel @@ -0,0 +1 @@ +musl1.1 \ No newline at end of file diff --git a/srcpkgs/musl1.1/files/__stack_chk_fail_local.c b/srcpkgs/musl1.1/files/__stack_chk_fail_local.c new file mode 100644 index 00000000000..2b403a6e046 --- /dev/null +++ b/srcpkgs/musl1.1/files/__stack_chk_fail_local.c @@ -0,0 +1,2 @@ +extern void __stack_chk_fail(void); +void __attribute__((visibility ("hidden"))) __stack_chk_fail_local(void) { __stack_chk_fail(); } diff --git a/srcpkgs/musl1.1/files/getconf.1 b/srcpkgs/musl1.1/files/getconf.1 new file mode 100644 index 00000000000..520a688b428 --- /dev/null +++ b/srcpkgs/musl1.1/files/getconf.1 @@ -0,0 +1,94 @@ +.\" $NetBSD: getconf.1,v 1.13 2014/04/13 01:45:34 snj Exp $ +.\" +.\" Copyright (c) 1996 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by J.T. Conklin. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd August 9, 2011 +.Dt GETCONF 1 +.Os +.Sh NAME +.Nm getconf +.Nd get configuration values +.Sh SYNOPSIS +.Nm +.Ar system_var +.Nm +.Fl a +.Nm +.Ar path_var +.Ar pathname +.Nm +.Fl a +.Ar pathname +.Sh DESCRIPTION +The +.Nm +utility writes the current value of a configurable system limit or +option variable to the standard output. +.Pp +The +.Ar system_var +argument specifies the system variable to be queried. +The names of the system variables are from +.Xr sysconf 3 +with the leading +.Dq Li _SC_ +removed. +.Pp +The +.Ar path_var +argument specifies the pathname variable to be queried for the specified +.Ar pathname +argument. +The names of the pathname variables are from +.Xr pathconf 2 +with the leading +.Dq Li _PC_ +removed. +.Pp +When invoked with the option +.Fl a , +.Nm +writes a list of all applicable variables and their values to the +standard output, in the format +.Do +.Va name += +.Va value +.Dc . +.Sh EXIT STATUS +.Ex -std +.Sh SEE ALSO +.Xr pathconf 2 , +.Xr confstr 3 , +.Xr limits 3 , +.Xr sysconf 3 +.Sh STANDARDS +The +.Nm +utility conforms to +.St -p1003.2-92 . diff --git a/srcpkgs/musl1.1/files/getconf.c b/srcpkgs/musl1.1/files/getconf.c new file mode 100644 index 00000000000..0435e59345e --- /dev/null +++ b/srcpkgs/musl1.1/files/getconf.c @@ -0,0 +1,340 @@ +/*- + * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by J.T. Conklin. + * + * Mostly rewritten to be used in Alpine Linux (with musl c-library) + * by Timo Teräs. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct conf_variable { + const char *name; + enum { SYSCONF, CONFSTR, PATHCONF, CONSTANT, UCONSTANT, NUM_TYPES } type; + long value; +}; + +static const struct conf_variable conf_table[] = { +{ "PATH", CONFSTR, _CS_PATH }, + +/* Utility Limit Minimum Values */ +{ "POSIX2_BC_BASE_MAX", CONSTANT, _POSIX2_BC_BASE_MAX }, +{ "POSIX2_BC_DIM_MAX", CONSTANT, _POSIX2_BC_DIM_MAX }, +{ "POSIX2_BC_SCALE_MAX", CONSTANT, _POSIX2_BC_SCALE_MAX }, +{ "POSIX2_BC_STRING_MAX", CONSTANT, _POSIX2_BC_STRING_MAX }, +{ "POSIX2_COLL_WEIGHTS_MAX", CONSTANT, _POSIX2_COLL_WEIGHTS_MAX }, +{ "POSIX2_EXPR_NEST_MAX", CONSTANT, _POSIX2_EXPR_NEST_MAX }, +{ "POSIX2_LINE_MAX", CONSTANT, _POSIX2_LINE_MAX }, +{ "POSIX2_RE_DUP_MAX", CONSTANT, _POSIX2_RE_DUP_MAX }, +{ "POSIX2_VERSION", CONSTANT, _POSIX2_VERSION }, + +/* POSIX.1 Minimum Values */ +{ "_POSIX_AIO_LISTIO_MAX", CONSTANT, _POSIX_AIO_LISTIO_MAX }, +{ "_POSIX_AIO_MAX", CONSTANT, _POSIX_AIO_MAX }, +{ "_POSIX_ARG_MAX", CONSTANT, _POSIX_ARG_MAX }, +{ "_POSIX_CHILD_MAX", CONSTANT, _POSIX_CHILD_MAX }, +{ "_POSIX_LINK_MAX", CONSTANT, _POSIX_LINK_MAX }, +{ "_POSIX_MAX_CANON", CONSTANT, _POSIX_MAX_CANON }, +{ "_POSIX_MAX_INPUT", CONSTANT, _POSIX_MAX_INPUT }, +{ "_POSIX_MQ_OPEN_MAX", CONSTANT, _POSIX_MQ_OPEN_MAX }, +{ "_POSIX_MQ_PRIO_MAX", CONSTANT, _POSIX_MQ_PRIO_MAX }, +{ "_POSIX_NAME_MAX", CONSTANT, _POSIX_NAME_MAX }, +{ "_POSIX_NGROUPS_MAX", CONSTANT, _POSIX_NGROUPS_MAX }, +{ "_POSIX_OPEN_MAX", CONSTANT, _POSIX_OPEN_MAX }, +{ "_POSIX_PATH_MAX", CONSTANT, _POSIX_PATH_MAX }, +{ "_POSIX_PIPE_BUF", CONSTANT, _POSIX_PIPE_BUF }, +{ "_POSIX_SSIZE_MAX", CONSTANT, _POSIX_SSIZE_MAX }, +{ "_POSIX_STREAM_MAX", CONSTANT, _POSIX_STREAM_MAX }, +{ "_POSIX_TZNAME_MAX", CONSTANT, _POSIX_TZNAME_MAX }, + +/* Symbolic Utility Limits */ +{ "BC_BASE_MAX", SYSCONF, _SC_BC_BASE_MAX }, +{ "BC_DIM_MAX", SYSCONF, _SC_BC_DIM_MAX }, +{ "BC_SCALE_MAX", SYSCONF, _SC_BC_SCALE_MAX }, +{ "BC_STRING_MAX", SYSCONF, _SC_BC_STRING_MAX }, +{ "COLL_WEIGHTS_MAX", SYSCONF, _SC_COLL_WEIGHTS_MAX }, +{ "EXPR_NEST_MAX", SYSCONF, _SC_EXPR_NEST_MAX }, +{ "LINE_MAX", SYSCONF, _SC_LINE_MAX }, +{ "RE_DUP_MAX", SYSCONF, _SC_RE_DUP_MAX }, + +/* Optional Facility Configuration Values */ +{ "_POSIX2_C_BIND", SYSCONF, _SC_2_C_BIND }, +{ "POSIX2_C_DEV", SYSCONF, _SC_2_C_DEV }, +{ "POSIX2_CHAR_TERM", SYSCONF, _SC_2_CHAR_TERM }, +{ "POSIX2_FORT_DEV", SYSCONF, _SC_2_FORT_DEV }, +{ "POSIX2_FORT_RUN", SYSCONF, _SC_2_FORT_RUN }, +{ "POSIX2_LOCALEDEF", SYSCONF, _SC_2_LOCALEDEF }, +{ "POSIX2_SW_DEV", SYSCONF, _SC_2_SW_DEV }, +{ "POSIX2_UPE", SYSCONF, _SC_2_UPE }, + +/* POSIX.1 Configurable System Variables */ +{ "AIO_LISTIO_MAX", SYSCONF, _SC_AIO_LISTIO_MAX }, +{ "AIO_MAX", SYSCONF, _SC_AIO_MAX }, +{ "ARG_MAX", SYSCONF, _SC_ARG_MAX }, +{ "CHILD_MAX", SYSCONF, _SC_CHILD_MAX }, +{ "CLK_TCK", SYSCONF, _SC_CLK_TCK }, +{ "MQ_OPEN_MAX", SYSCONF, _SC_MQ_OPEN_MAX }, +{ "MQ_PRIO_MAX", SYSCONF, _SC_MQ_PRIO_MAX }, +{ "NGROUPS_MAX", SYSCONF, _SC_NGROUPS_MAX }, +{ "OPEN_MAX", SYSCONF, _SC_OPEN_MAX }, +{ "STREAM_MAX", SYSCONF, _SC_STREAM_MAX }, +{ "TZNAME_MAX", SYSCONF, _SC_TZNAME_MAX }, +{ "_POSIX_JOB_CONTROL", SYSCONF, _SC_JOB_CONTROL }, +{ "_POSIX_SAVED_IDS", SYSCONF, _SC_SAVED_IDS }, +{ "_POSIX_VERSION", SYSCONF, _SC_VERSION }, + +{ "LINK_MAX", PATHCONF, _PC_LINK_MAX }, +{ "MAX_CANON", PATHCONF, _PC_MAX_CANON }, +{ "MAX_INPUT", PATHCONF, _PC_MAX_INPUT }, +{ "NAME_MAX", PATHCONF, _PC_NAME_MAX }, +{ "PATH_MAX", PATHCONF, _PC_PATH_MAX }, +{ "PIPE_BUF", PATHCONF, _PC_PIPE_BUF }, +{ "_POSIX_CHOWN_RESTRICTED", PATHCONF, _PC_CHOWN_RESTRICTED }, +{ "_POSIX_NO_TRUNC", PATHCONF, _PC_NO_TRUNC }, +{ "_POSIX_VDISABLE", PATHCONF, _PC_VDISABLE }, + +/* POSIX.1b Configurable System Variables */ +{ "PAGESIZE", SYSCONF, _SC_PAGESIZE }, +{ "_POSIX_ASYNCHRONOUS_IO", SYSCONF, _SC_ASYNCHRONOUS_IO }, +{ "_POSIX_FSYNC", SYSCONF, _SC_FSYNC }, +{ "_POSIX_MAPPED_FILES", SYSCONF, _SC_MAPPED_FILES }, +{ "_POSIX_MEMLOCK", SYSCONF, _SC_MEMLOCK }, +{ "_POSIX_MEMLOCK_RANGE", SYSCONF, _SC_MEMLOCK_RANGE }, +{ "_POSIX_MEMORY_PROTECTION", SYSCONF, _SC_MEMORY_PROTECTION }, +{ "_POSIX_MESSAGE_PASSING", SYSCONF, _SC_MESSAGE_PASSING }, +{ "_POSIX_MONOTONIC_CLOCK", SYSCONF, _SC_MONOTONIC_CLOCK }, +{ "_POSIX_PRIORITY_SCHEDULING", SYSCONF, _SC_PRIORITY_SCHEDULING }, +{ "_POSIX_SEMAPHORES", SYSCONF, _SC_SEMAPHORES }, +{ "_POSIX_SHARED_MEMORY_OBJECTS", SYSCONF, _SC_SHARED_MEMORY_OBJECTS }, +{ "_POSIX_SYNCHRONIZED_IO", SYSCONF, _SC_SYNCHRONIZED_IO }, +{ "_POSIX_TIMERS", SYSCONF, _SC_TIMERS }, + +{ "_POSIX_SYNC_IO", PATHCONF, _PC_SYNC_IO }, + +/* POSIX.1c Configurable System Variables */ +{ "LOGIN_NAME_MAX", SYSCONF, _SC_LOGIN_NAME_MAX }, +{ "_POSIX_THREADS", SYSCONF, _SC_THREADS }, + +/* POSIX.1j Configurable System Variables */ +{ "_POSIX_BARRIERS", SYSCONF, _SC_BARRIERS }, +{ "_POSIX_READER_WRITER_LOCKS", SYSCONF, _SC_READER_WRITER_LOCKS }, +{ "_POSIX_SPIN_LOCKS", SYSCONF, _SC_SPIN_LOCKS }, + +/* XPG4.2 Configurable System Variables */ +{ "IOV_MAX", SYSCONF, _SC_IOV_MAX }, +{ "PAGE_SIZE", SYSCONF, _SC_PAGE_SIZE }, +{ "_XOPEN_SHM", SYSCONF, _SC_XOPEN_SHM }, + +/* X/Open CAE Spec. Issue 5 Version 2 Configurable System Variables */ +{ "FILESIZEBITS", PATHCONF, _PC_FILESIZEBITS }, + +/* POSIX.1-2001 XSI Option Group Configurable System Variables */ +{ "ATEXIT_MAX", SYSCONF, _SC_ATEXIT_MAX }, + +/* POSIX.1-2001 TSF Configurable System Variables */ +{ "GETGR_R_SIZE_MAX", SYSCONF, _SC_GETGR_R_SIZE_MAX }, +{ "GETPW_R_SIZE_MAX", SYSCONF, _SC_GETPW_R_SIZE_MAX }, + +/* Commonly provided extensions */ +{ "_PHYS_PAGES", SYSCONF, _SC_PHYS_PAGES }, +{ "_AVPHYS_PAGES", SYSCONF, _SC_AVPHYS_PAGES }, +{ "_NPROCESSORS_CONF", SYSCONF, _SC_NPROCESSORS_CONF }, +{ "_NPROCESSORS_ONLN", SYSCONF, _SC_NPROCESSORS_ONLN }, +{ "NPROCESSORS_CONF", SYSCONF, _SC_NPROCESSORS_CONF }, +{ "NPROCESSORS_ONLN", SYSCONF, _SC_NPROCESSORS_ONLN }, + +/* Data type related extensions */ +{ "CHAR_BIT", CONSTANT, CHAR_BIT }, +{ "CHAR_MAX", CONSTANT, CHAR_MAX }, +{ "CHAR_MIN", CONSTANT, CHAR_MIN }, +{ "INT_MAX", CONSTANT, INT_MAX }, +{ "INT_MIN", CONSTANT, INT_MIN }, +{ "LONG_BIT", CONSTANT, LONG_BIT }, +{ "LONG_MAX", CONSTANT, LONG_MAX }, +{ "LONG_MIN", CONSTANT, LONG_MIN }, +{ "SCHAR_MAX", CONSTANT, SCHAR_MAX }, +{ "SCHAR_MIN", CONSTANT, SCHAR_MIN }, +{ "SHRT_MAX", CONSTANT, SHRT_MAX }, +{ "SHRT_MIN", CONSTANT, SHRT_MIN }, +{ "SSIZE_MAX", CONSTANT, SSIZE_MAX }, +{ "UCHAR_MAX", UCONSTANT, (long) UCHAR_MAX }, +{ "UINT_MAX", UCONSTANT, (long) UINT_MAX }, +{ "ULONG_MAX", UCONSTANT, (long) ULONG_MAX }, +{ "USHRT_MAX", UCONSTANT, (long) USHRT_MAX }, +{ "WORD_BIT", CONSTANT, WORD_BIT }, + +{ NULL, CONSTANT, 0L } +}; + +static int all = 0; + +static void usage(const char *p) +{ + (void)fprintf(stderr, "Usage: %s system_var\n\t%s -a\n" + "\t%s path_var pathname\n\t%s -a pathname\n", p, p, p, p); + exit(EXIT_FAILURE); +} + +static void print_long(const char *name, long val) +{ + if (all) printf("%s = %ld\n", name, val); + else printf("%ld\n", val); +} + +static void print_ulong(const char *name, unsigned long val) +{ + if (all) printf("%s = %lu\n", name, val); + else printf("%lu\n", val); +} + +static void print_string(const char *name, const char *val) +{ + if (all) printf("%s = %s\n", name, val); + else printf("%s\n", val); +} + +static int print_constant(const struct conf_variable *cp, const char *pathname) +{ + print_long(cp->name, cp->value); + return 0; +} + +static int print_uconstant(const struct conf_variable *cp, const char *pathname) +{ + print_ulong(cp->name, (unsigned long) cp->value); + return 0; +} + +static int print_sysconf(const struct conf_variable *cp, const char *pathname) +{ + long val; + + errno = 0; + if ((val = sysconf((int)cp->value)) == -1) { + if (errno != 0) err(EXIT_FAILURE, "sysconf(%ld)", cp->value); + return -1; + } + print_long(cp->name, val); + return 0; +} + +static int print_confstr(const struct conf_variable *cp, const char *pathname) +{ + size_t len; + char *val; + + errno = 0; + if ((len = confstr((int)cp->value, NULL, 0)) == 0) goto error; + if ((val = malloc(len)) == NULL) err(EXIT_FAILURE, "Can't allocate %zu bytes", len); + errno = 0; + if (confstr((int)cp->value, val, len) == 0) goto error; + print_string(cp->name, val); + free(val); + return 0; +error: + if (errno != EINVAL) err(EXIT_FAILURE, "confstr(%ld)", cp->value); + return -1; +} + +static int print_pathconf(const struct conf_variable *cp, const char *pathname) +{ + long val; + + errno = 0; + if ((val = pathconf(pathname, (int)cp->value)) == -1) { + if (all && errno == EINVAL) return 0; + if (errno != 0) err(EXIT_FAILURE, "pathconf(%s, %ld)", pathname, cp->value); + return -1; + } + print_long(cp->name, val); + return 0; +} + +typedef int (*handler_t)(const struct conf_variable *cp, const char *pathname); +static const handler_t type_handlers[NUM_TYPES] = { + [SYSCONF] = print_sysconf, + [CONFSTR] = print_confstr, + [PATHCONF] = print_pathconf, + [CONSTANT] = print_constant, + [UCONSTANT] = print_uconstant, +}; + +int main(int argc, char **argv) +{ + const char *progname = argv[0]; + const struct conf_variable *cp; + const char *varname, *pathname; + int ch, found = 0; + + (void)setlocale(LC_ALL, ""); + while ((ch = getopt(argc, argv, "a")) != -1) { + switch (ch) { + case 'a': + all = 1; + break; + case '?': + default: + usage(progname); + } + } + argc -= optind; + argv += optind; + + if (!all) { + if (argc == 0) + usage(progname); + varname = argv[0]; + argc--; + argv++; + } else + varname = NULL; + + if (argc > 1) + usage(progname); + pathname = argv[0]; /* may be NULL */ + + for (cp = conf_table; cp->name != NULL; cp++) { + if (!all && strcmp(varname, cp->name) != 0) continue; + if ((cp->type == PATHCONF) == (pathname != NULL)) { + if (type_handlers[cp->type](cp, pathname) < 0) + print_string(cp->name, "undefined"); + found = 1; + } else if (!all) + errx(EXIT_FAILURE, "%s: invalid variable type", cp->name); + } + if (!all && !found) errx(EXIT_FAILURE, "%s: unknown variable", varname); + (void)fflush(stdout); + return ferror(stdout) ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/srcpkgs/musl1.1/files/getent.1 b/srcpkgs/musl1.1/files/getent.1 new file mode 100644 index 00000000000..0e07058e74a --- /dev/null +++ b/srcpkgs/musl1.1/files/getent.1 @@ -0,0 +1,145 @@ +.\" $NetBSD: getent.1,v 1.23 2011/10/11 20:39:40 wiz Exp $ +.\" +.\" Copyright (c) 2004 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Luke Mewburn. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd October 11, 2011 +.Dt GETENT 1 +.Os +.Sh NAME +.Nm getent +.Nd get entries from administrative databases +.Sh SYNOPSIS +.Nm getent +.Ar database +.Op Ar key ... +.Nm getcap +.Ar database +.Op Ar key ... +.Sh DESCRIPTION +The +.Nm +program retrieves and displays entries from the administrative +database specified by +.Ar database , +using the lookup order specified in +.Xr nsswitch.conf 5 . +The display format for a given +.Ar database +is as per the +.Dq traditional +file format for that database. +.Pp +.Ar database +may be one of: +.Bl -column "protocols" "user:passwd:uid:gid:gecos:home_dir:shell" -offset indent -compact +.It Sy Database Ta Sy Display format +.It disktab Ta entry +.It ethers Ta address name +.It gettytab Ta entry +.It group Ta group:passwd:gid:[member[,member]...] +.It hosts Ta address name [alias ...] +.It netgroup Ta (host,user,domain) [...] +.It networks Ta name network [alias ...] +.It passwd Ta user:passwd:uid:gid:gecos:home_dir:shell +.It printcap Ta entry +.It protocols Ta name protocol [alias ...] +.It rpc Ta name number [alias ...] +.It services Ta name port/protocol [alias ...] +.It shells Ta /path/to/shell +.El +.Pp +If one or more +.Ar key +arguments are provided, they will be looked up in +.Ar database +using the appropriate function. +For example, +.Sy passwd +supports a numeric UID or user name; +.Sy hosts +supports an IPv4 address, IPv6 address, or host name; +and +.Sy services +supports a service name, service name/protocol name, numeric port, or +numeric port/protocol name. +.Pp +If no +.Ar key +is provided and +.Ar database +supports enumeration, all entries for +.Ar database +will be retrieved using the appropriate enumeration function and printed. +.Pp +For +.Xr cgetcap 3 +style databases +.Sy ( disktab , +.Sy printcap ) +specifying a key, lists the entry for that key, and specifying more arguments +after the key are used as fields in that key, and only the values of the keys +are returned. +For boolean keys +.Dv true +is returned if the key is found. +If a key is not found, then +.Dv false +is always +returned. +.Sh DIAGNOSTICS +.Nm +exits 0 on success, +1 if there was an error in the command syntax, +2 if one of the specified key names was not found in +.Ar database , +or 3 if there is no support for enumeration on +.Ar database . +.Sh SEE ALSO +.Xr cgetcap 3 , +.Xr disktab 5 , +.Xr ethers 5 , +.Xr gettytab 5 , +.Xr group 5 , +.Xr hosts 5 , +.Xr networks 5 , +.Xr nsswitch.conf 5 , +.Xr passwd 5 , +.Xr printcap 5 , +.Xr protocols 5 , +.Xr rpc 5 , +.Xr services 5 , +.Xr shells 5 +.Sh HISTORY +A +.Nm +command appeared in +.Nx 3.0 . +It was based on the command of the same name in +.Tn Solaris +and +.Tn Linux . diff --git a/srcpkgs/musl1.1/files/getent.c b/srcpkgs/musl1.1/files/getent.c new file mode 100644 index 00000000000..939b46c0878 --- /dev/null +++ b/srcpkgs/musl1.1/files/getent.c @@ -0,0 +1,437 @@ +/*- + * Copyright (c) 2004-2006 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Luke Mewburn. + * Timo Teräs cleaned up the code for use in Alpine Linux with musl libc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +enum { + RV_OK = 0, + RV_USAGE = 1, + RV_NOTFOUND = 2, + RV_NOENUM = 3 +}; + +static int usage(const char *); + +static int parsenum(const char *word, unsigned long *result) +{ + unsigned long num; + char *ep; + + if (!isdigit((unsigned char)word[0])) + return 0; + errno = 0; + num = strtoul(word, &ep, 10); + if (num == ULONG_MAX && errno == ERANGE) + return 0; + if (*ep != '\0') + return 0; + *result = num; + return 1; +} + +/* + * printfmtstrings -- + * vprintf(format, ...), + * then the aliases (beginning with prefix, separated by sep), + * then a newline + */ +__attribute__ ((format (printf, 4, 5))) +static void printfmtstrings(char *strings[], const char *prefix, const char *sep, + const char *fmt, ...) +{ + va_list ap; + const char *curpref; + size_t i; + + va_start(ap, fmt); + (void)vprintf(fmt, ap); + va_end(ap); + + curpref = prefix; + for (i = 0; strings[i] != NULL; i++) { + (void)printf("%s%s", curpref, strings[i]); + curpref = sep; + } + (void)printf("\n"); +} + +static int ethers(int argc, char *argv[]) +{ + char hostname[MAXHOSTNAMELEN + 1], *hp; + struct ether_addr ea, *eap; + int i, rv; + + if (argc == 2) { + warnx("Enumeration not supported on ethers"); + return RV_NOENUM; + } + + rv = RV_OK; + for (i = 2; i < argc; i++) { + if ((eap = ether_aton(argv[i])) == NULL) { + eap = &ea; + hp = argv[i]; + if (ether_hostton(hp, eap) != 0) { + rv = RV_NOTFOUND; + break; + } + } else { + hp = hostname; + if (ether_ntohost(hp, eap) != 0) { + rv = RV_NOTFOUND; + break; + } + } + (void)printf("%-17s %s\n", ether_ntoa(eap), hp); + } + return rv; +} + +static void groupprint(const struct group *gr) +{ + printfmtstrings(gr->gr_mem, ":", ",", "%s:%s:%u", + gr->gr_name, gr->gr_passwd, gr->gr_gid); +} + +static int group(int argc, char *argv[]) +{ + struct group *gr; + unsigned long id; + int i, rv; + + rv = RV_OK; + if (argc == 2) { + while ((gr = getgrent()) != NULL) + groupprint(gr); + } else { + for (i = 2; i < argc; i++) { + if (parsenum(argv[i], &id)) + gr = getgrgid((gid_t)id); + else + gr = getgrnam(argv[i]); + if (gr == NULL) { + rv = RV_NOTFOUND; + break; + } + groupprint(gr); + } + } + endgrent(); + return rv; +} + +static void hostsprint(const struct hostent *he) +{ + char buf[INET6_ADDRSTRLEN]; + + if (inet_ntop(he->h_addrtype, he->h_addr, buf, sizeof(buf)) == NULL) + (void)strlcpy(buf, "# unknown", sizeof(buf)); + printfmtstrings(he->h_aliases, " ", " ", "%-16s %s", buf, he->h_name); +} + +static int hosts(int argc, char *argv[]) +{ + struct hostent *he; + char addr[IN6ADDRSZ]; + int i, rv; + + sethostent(1); + rv = RV_OK; + if (argc == 2) { + while ((he = gethostent()) != NULL) + hostsprint(he); + } else { + for (i = 2; i < argc; i++) { + if (inet_pton(AF_INET6, argv[i], (void *)addr) > 0) + he = gethostbyaddr(addr, IN6ADDRSZ, AF_INET6); + else if (inet_pton(AF_INET, argv[i], (void *)addr) > 0) + he = gethostbyaddr(addr, INADDRSZ, AF_INET); + else + he = gethostbyname(argv[i]); + if (he == NULL) { + rv = RV_NOTFOUND; + break; + } + hostsprint(he); + } + } + endhostent(); + return rv; +} + +static void networksprint(const struct netent *ne) +{ + char buf[INET6_ADDRSTRLEN]; + struct in_addr ianet; + + ianet = inet_makeaddr(ne->n_net, 0); + if (inet_ntop(ne->n_addrtype, &ianet, buf, sizeof(buf)) == NULL) + (void)strlcpy(buf, "# unknown", sizeof(buf)); + printfmtstrings(ne->n_aliases, " ", " ", "%-16s %s", ne->n_name, buf); +} + +static int networks(int argc, char *argv[]) +{ + struct netent *ne; + in_addr_t net; + int i, rv; + + setnetent(1); + rv = RV_OK; + if (argc == 2) { + while ((ne = getnetent()) != NULL) + networksprint(ne); + } else { + for (i = 2; i < argc; i++) { + net = inet_network(argv[i]); + if (net != INADDR_NONE) + ne = getnetbyaddr(net, AF_INET); + else + ne = getnetbyname(argv[i]); + if (ne == NULL) { + rv = RV_NOTFOUND; + break; + } + networksprint(ne); + } + } + endnetent(); + return rv; +} + +static void passwdprint(struct passwd *pw) +{ + (void)printf("%s:%s:%u:%u:%s:%s:%s\n", + pw->pw_name, pw->pw_passwd, pw->pw_uid, + pw->pw_gid, pw->pw_gecos, pw->pw_dir, pw->pw_shell); +} + +static int passwd(int argc, char *argv[]) +{ + struct passwd *pw; + unsigned long id; + int i, rv; + + rv = RV_OK; + if (argc == 2) { + while ((pw = getpwent()) != NULL) + passwdprint(pw); + } else { + for (i = 2; i < argc; i++) { + if (parsenum(argv[i], &id)) + pw = getpwuid((uid_t)id); + else + pw = getpwnam(argv[i]); + if (pw == NULL) { + rv = RV_NOTFOUND; + break; + } + passwdprint(pw); + } + } + endpwent(); + return rv; +} + +static void protocolsprint(struct protoent *pe) +{ + printfmtstrings(pe->p_aliases, " ", " ", + "%-16s %5d", pe->p_name, pe->p_proto); +} + +static int protocols(int argc, char *argv[]) +{ + struct protoent *pe; + unsigned long id; + int i, rv; + + setprotoent(1); + rv = RV_OK; + if (argc == 2) { + while ((pe = getprotoent()) != NULL) + protocolsprint(pe); + } else { + for (i = 2; i < argc; i++) { + if (parsenum(argv[i], &id)) + pe = getprotobynumber((int)id); + else + pe = getprotobyname(argv[i]); + if (pe == NULL) { + rv = RV_NOTFOUND; + break; + } + protocolsprint(pe); + } + } + endprotoent(); + return rv; +} + +static void servicesprint(struct servent *se) +{ + printfmtstrings(se->s_aliases, " ", " ", + "%-16s %5d/%s", + se->s_name, ntohs(se->s_port), se->s_proto); + +} + +static int services(int argc, char *argv[]) +{ + struct servent *se; + unsigned long id; + char *proto; + int i, rv; + + setservent(1); + rv = RV_OK; + if (argc == 2) { + while ((se = getservent()) != NULL) + servicesprint(se); + } else { + for (i = 2; i < argc; i++) { + proto = strchr(argv[i], '/'); + if (proto != NULL) + *proto++ = '\0'; + if (parsenum(argv[i], &id)) + se = getservbyport(htons(id), proto); + else + se = getservbyname(argv[i], proto); + if (se == NULL) { + rv = RV_NOTFOUND; + break; + } + servicesprint(se); + } + } + endservent(); + return rv; +} + +static int shells(int argc, char *argv[]) +{ + const char *sh; + int i, rv; + + setusershell(); + rv = RV_OK; + if (argc == 2) { + while ((sh = getusershell()) != NULL) + (void)printf("%s\n", sh); + } else { + for (i = 2; i < argc; i++) { + setusershell(); + while ((sh = getusershell()) != NULL) { + if (strcmp(sh, argv[i]) == 0) { + (void)printf("%s\n", sh); + break; + } + } + if (sh == NULL) { + rv = RV_NOTFOUND; + break; + } + } + } + endusershell(); + return rv; +} + +static struct getentdb { + const char *name; + int (*callback)(int, char *[]); +} databases[] = { + { "ethers", ethers, }, + { "group", group, }, + { "hosts", hosts, }, + { "networks", networks, }, + { "passwd", passwd, }, + { "protocols", protocols, }, + { "services", services, }, + { "shells", shells, }, + + { NULL, NULL, }, +}; + +static int usage(const char *arg0) +{ + struct getentdb *curdb; + size_t i; + + (void)fprintf(stderr, "Usage: %s database [key ...]\n", arg0); + (void)fprintf(stderr, "\tdatabase may be one of:"); + for (i = 0, curdb = databases; curdb->name != NULL; curdb++, i++) { + if (i % 7 == 0) + (void)fputs("\n\t\t", stderr); + (void)fprintf(stderr, "%s%s", i % 7 == 0 ? "" : " ", + curdb->name); + } + (void)fprintf(stderr, "\n"); + exit(RV_USAGE); + /* NOTREACHED */ +} + +int +main(int argc, char *argv[]) +{ + struct getentdb *curdb; + + if (argc < 2) + usage(argv[0]); + for (curdb = databases; curdb->name != NULL; curdb++) + if (strcmp(curdb->name, argv[1]) == 0) + return (*curdb->callback)(argc, argv); + + warn("Unknown database `%s'", argv[1]); + usage(argv[0]); + /* NOTREACHED */ +} diff --git a/srcpkgs/musl1.1/files/iconv.c b/srcpkgs/musl1.1/files/iconv.c new file mode 100644 index 00000000000..f5d5ce2aa73 --- /dev/null +++ b/srcpkgs/musl1.1/files/iconv.c @@ -0,0 +1,110 @@ +/* + * iconv.c + * Implementation of SUSv4 XCU iconv utility + * Copyright © 2011 Rich Felker + * Licensed under the terms of the GNU General Public License, v2 or later + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + const char *from=0, *to=0; + int b; + iconv_t cd; + char buf[BUFSIZ]; + char outbuf[BUFSIZ*4]; + char *in, *out; + size_t inb; + size_t l; + size_t unitsize=0; + int err=0; + FILE *f; + + while ((b = getopt(argc, argv, "f:t:csl")) != EOF) switch(b) { + case 'l': + puts("UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF32-LE, UCS-2BE, UCS-2LE, WCHAR_T,\n" + "US_ASCII, ISO8859-1, ISO8859-2, ISO8859-3, ISO8859-4, ISO8859-5,\n" + "ISO8859-6, ISO8859-7, ..."); + exit(0); + case 'c': case 's': break; + case 'f': from=optarg; break; + case 't': to=optarg; break; + default: exit(1); + } + + if (!from || !to) { + setlocale(LC_CTYPE, ""); + if (!to) to = nl_langinfo(CODESET); + if (!from) from = nl_langinfo(CODESET); + } + cd = iconv_open(to, from); + if (cd == (iconv_t)-1) { + if (iconv_open(to, "WCHAR_T") == (iconv_t)-1) + fprintf(stderr, "iconv: destination charset %s: ", to); + else + fprintf(stderr, "iconv: source charset %s: ", from); + perror(""); + exit(1); + } + if (optind == argc) argv[argc++] = "-"; + + for (; optind < argc; optind++) { + if (argv[optind][0]=='-' && !argv[optind][1]) { + f = stdin; + argv[optind] = "(stdin)"; + } else if (!(f = fopen(argv[optind], "rb"))) { + fprintf(stderr, "iconv: %s: ", argv[optind]); + perror(""); + err = 1; + continue; + } + inb = 0; + for (;;) { + in = buf; + out = outbuf; + l = fread(buf+inb, 1, sizeof(buf)-inb, f); + inb += l; + if (!inb) break; + if (iconv(cd, &in, &inb, &out, (size_t [1]){sizeof outbuf})==-1 + && errno == EILSEQ) { + if (!unitsize) { + wchar_t wc='0'; + char dummy[4], *dummyp=dummy; + iconv_t cd2 = iconv_open(from, "WCHAR_T"); + if (cd == (iconv_t)-1) { + unitsize = 1; + } else { + iconv(cd2, + (char *[1]){(char *)&wc}, + (size_t[1]){1}, + &dummyp, (size_t[1]){4}); + unitsize = dummyp-dummy; + if (!unitsize) unitsize=1; + } + } + inb-=unitsize; + in+=unitsize; + } + if (inb && !l && errno==EINVAL) break; + if (out>outbuf && !fwrite(outbuf, out-outbuf, 1, stdout)) { + perror("iconv: write error"); + exit(1); + } + if (inb) memmove(buf, in, inb); + } + if (ferror(f)) { + fprintf(stderr, "iconv: %s: ", argv[optind]); + perror(""); + err = 1; + } + } + return err; +} diff --git a/srcpkgs/musl1.1/patches/00-reallocarray.patch b/srcpkgs/musl1.1/patches/00-reallocarray.patch new file mode 100644 index 00000000000..cfaab330e89 --- /dev/null +++ b/srcpkgs/musl1.1/patches/00-reallocarray.patch @@ -0,0 +1,42 @@ +From 821083ac7b54eaa040d5a8ddc67c6206a175e0ca Mon Sep 17 00:00:00 2001 +From: Ariadne Conill +Date: Sat, 1 Aug 2020 08:26:35 -0600 +Subject: [PATCH] implement reallocarray + +reallocarray is an extension introduced by OpenBSD, which introduces +calloc overflow checking to realloc. + +glibc 2.28 introduced support for this function behind _GNU_SOURCE, +while glibc 2.29 allows its usage in _DEFAULT_SOURCE. + +diff --git a/include/stdlib.h b/include/stdlib.h +index 194c2033..b54a051f 100644 +--- a/include/stdlib.h ++++ b/include/stdlib.h +@@ -145,6 +145,7 @@ int getloadavg(double *, int); + int clearenv(void); + #define WCOREDUMP(s) ((s) & 0x80) + #define WIFCONTINUED(s) ((s) == 0xffff) ++void *reallocarray (void *, size_t, size_t); + #endif + + #ifdef _GNU_SOURCE +diff --git a/src/malloc/reallocarray.c b/src/malloc/reallocarray.c +new file mode 100644 +index 00000000..4a6ebe46 +--- /dev/null ++++ b/src/malloc/reallocarray.c +@@ -0,0 +1,13 @@ ++#define _BSD_SOURCE ++#include ++#include ++ ++void *reallocarray(void *ptr, size_t m, size_t n) ++{ ++ if (n && m > -1 / n) { ++ errno = ENOMEM; ++ return 0; ++ } ++ ++ return realloc(ptr, m * n); ++} diff --git a/srcpkgs/musl1.1/patches/0001_reorder_thread_list_unlink_in_pthread_exit_after_all.patch b/srcpkgs/musl1.1/patches/0001_reorder_thread_list_unlink_in_pthread_exit_after_all.patch new file mode 100644 index 00000000000..7c1a55bc85e --- /dev/null +++ b/srcpkgs/musl1.1/patches/0001_reorder_thread_list_unlink_in_pthread_exit_after_all.patch @@ -0,0 +1,56 @@ +>From 4d5aa20a94a2d3fae3e69289dc23ecafbd0c16c4 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Fri, 22 May 2020 17:35:14 -0400 +Subject: [PATCH 1/4] reorder thread list unlink in pthread_exit after all + locks + +since the backend for LOCK() skips locking if single-threaded, it's +unsafe to make the process appear single-threaded before the last use +of lock. + +this fixes potential unsynchronized access to a linked list via +__dl_thread_cleanup. +--- + src/thread/pthread_create.c | 19 +++++++++++-------- + 1 file changed, 11 insertions(+), 8 deletions(-) + +diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c +index 5f491092..6a3b0c21 100644 +--- a/src/thread/pthread_create.c ++++ b/src/thread/pthread_create.c +@@ -90,14 +90,7 @@ _Noreturn void __pthread_exit(void *result) + exit(0); + } + +- /* At this point we are committed to thread termination. Unlink +- * the thread from the list. This change will not be visible +- * until the lock is released, which only happens after SYS_exit +- * has been called, via the exit futex address pointing at the lock. */ +- libc.threads_minus_1--; +- self->next->prev = self->prev; +- self->prev->next = self->next; +- self->prev = self->next = self; ++ /* At this point we are committed to thread termination. */ + + /* Process robust list in userspace to handle non-pshared mutexes + * and the detached thread case where the robust list head will +@@ -121,6 +114,16 @@ _Noreturn void __pthread_exit(void *result) + __do_orphaned_stdio_locks(); + __dl_thread_cleanup(); + ++ /* Last, unlink thread from the list. This change will not be visible ++ * until the lock is released, which only happens after SYS_exit ++ * has been called, via the exit futex address pointing at the lock. ++ * This needs to happen after any possible calls to LOCK() that might ++ * skip locking if libc.threads_minus_1 is zero. */ ++ libc.threads_minus_1--; ++ self->next->prev = self->prev; ++ self->prev->next = self->next; ++ self->prev = self->next = self; ++ + /* This atomic potentially competes with a concurrent pthread_detach + * call; the loser is responsible for freeing thread resources. */ + int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING); +-- +2.21.0 + diff --git a/srcpkgs/musl1.1/patches/0002_don_t_use_libc_threads_minus_1_as_relaxed_atomic_for.patch b/srcpkgs/musl1.1/patches/0002_don_t_use_libc_threads_minus_1_as_relaxed_atomic_for.patch new file mode 100644 index 00000000000..e060762e99a --- /dev/null +++ b/srcpkgs/musl1.1/patches/0002_don_t_use_libc_threads_minus_1_as_relaxed_atomic_for.patch @@ -0,0 +1,78 @@ +>From e01b5939b38aea5ecbe41670643199825874b26c Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Thu, 21 May 2020 23:32:45 -0400 +Subject: [PATCH 2/4] don't use libc.threads_minus_1 as relaxed atomic for + skipping locks + +after all but the last thread exits, the next thread to observe +libc.threads_minus_1==0 and conclude that it can skip locking fails to +synchronize with any changes to memory that were made by the +last-exiting thread. this can produce data races. + +on some archs, at least x86, memory synchronization is unlikely to be +a problem; however, with the inline locks in malloc, skipping the lock +also eliminated the compiler barrier, and caused code that needed to +re-check chunk in-use bits after obtaining the lock to reuse a stale +value, possibly from before the process became single-threaded. this +in turn produced corruption of the heap state. + +some uses of libc.threads_minus_1 remain, especially for allocation of +new TLS in the dynamic linker; otherwise, it could be removed +entirely. it's made non-volatile to reflect that the remaining +accesses are only made under lock on the thread list. + +instead of libc.threads_minus_1, libc.threaded is now used for +skipping locks. the difference is that libc.threaded is permanently +true once an additional thread has been created. this will produce +some performance regression in processes that are mostly +single-threaded but occasionally creating threads. in the future it +may be possible to bring back the full lock-skipping, but more care +needs to be taken to produce a safe design. +--- + src/internal/libc.h | 2 +- + src/malloc/malloc.c | 2 +- + src/thread/__lock.c | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/internal/libc.h b/src/internal/libc.h +index ac97dc7e..c0614852 100644 +--- a/src/internal/libc.h ++++ b/src/internal/libc.h +@@ -21,7 +21,7 @@ struct __libc { + int can_do_threads; + int threaded; + int secure; +- volatile int threads_minus_1; ++ int threads_minus_1; + size_t *auxv; + struct tls_module *tls_head; + size_t tls_size, tls_align, tls_cnt; +diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c +index 96982596..2553a62e 100644 +--- a/src/malloc/malloc.c ++++ b/src/malloc/malloc.c +@@ -26,7 +26,7 @@ int __malloc_replaced; + + static inline void lock(volatile int *lk) + { +- if (libc.threads_minus_1) ++ if (libc.threaded) + while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1); + } + +diff --git a/src/thread/__lock.c b/src/thread/__lock.c +index 45557c88..5b9b144e 100644 +--- a/src/thread/__lock.c ++++ b/src/thread/__lock.c +@@ -18,7 +18,7 @@ + + void __lock(volatile int *l) + { +- if (!libc.threads_minus_1) return; ++ if (!libc.threaded) return; + /* fast path: INT_MIN for the lock, +1 for the congestion */ + int current = a_cas(l, 0, INT_MIN + 1); + if (!current) return; +-- +2.21.0 + diff --git a/srcpkgs/musl1.1/patches/0003_cut_down_size_of_some_libc_struct_members.patch b/srcpkgs/musl1.1/patches/0003_cut_down_size_of_some_libc_struct_members.patch new file mode 100644 index 00000000000..540c5d95019 --- /dev/null +++ b/srcpkgs/musl1.1/patches/0003_cut_down_size_of_some_libc_struct_members.patch @@ -0,0 +1,30 @@ +>From f12888e9eb9eed60cc266b899dcafecb4752964a Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Fri, 22 May 2020 17:25:38 -0400 +Subject: [PATCH 3/4] cut down size of some libc struct members + +these are all flags that can be single-byte values. +--- + src/internal/libc.h | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/internal/libc.h b/src/internal/libc.h +index c0614852..d47f58e0 100644 +--- a/src/internal/libc.h ++++ b/src/internal/libc.h +@@ -18,9 +18,9 @@ struct tls_module { + }; + + struct __libc { +- int can_do_threads; +- int threaded; +- int secure; ++ char can_do_threads; ++ char threaded; ++ char secure; + int threads_minus_1; + size_t *auxv; + struct tls_module *tls_head; +-- +2.21.0 + diff --git a/srcpkgs/musl1.1/patches/0004_restore_lock_skipping_for_processes_that_return_to_s.patch b/srcpkgs/musl1.1/patches/0004_restore_lock_skipping_for_processes_that_return_to_s.patch new file mode 100644 index 00000000000..e703c1f403c --- /dev/null +++ b/srcpkgs/musl1.1/patches/0004_restore_lock_skipping_for_processes_that_return_to_s.patch @@ -0,0 +1,102 @@ +>From 8d81ba8c0bc6fe31136cb15c9c82ef4c24965040 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Fri, 22 May 2020 17:45:47 -0400 +Subject: [PATCH 4/4] restore lock-skipping for processes that return to + single-threaded state + +the design used here relies on the barrier provided by the first lock +operation after the process returns to single-threaded state to +synchronize with actions by the last thread that exited. by storing +the intent to change modes in the same object used to detect whether +locking is needed, it's possible to avoid an extra (possibly costly) +memory load after the lock is taken. +--- + src/internal/libc.h | 1 + + src/malloc/malloc.c | 5 ++++- + src/thread/__lock.c | 4 +++- + src/thread/pthread_create.c | 8 ++++---- + 4 files changed, 12 insertions(+), 6 deletions(-) + +diff --git a/src/internal/libc.h b/src/internal/libc.h +index d47f58e0..619bba86 100644 +--- a/src/internal/libc.h ++++ b/src/internal/libc.h +@@ -21,6 +21,7 @@ struct __libc { + char can_do_threads; + char threaded; + char secure; ++ volatile signed char need_locks; + int threads_minus_1; + size_t *auxv; + struct tls_module *tls_head; +diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c +index 2553a62e..a803d4c9 100644 +--- a/src/malloc/malloc.c ++++ b/src/malloc/malloc.c +@@ -26,8 +26,11 @@ int __malloc_replaced; + + static inline void lock(volatile int *lk) + { +- if (libc.threaded) ++ int need_locks = libc.need_locks; ++ if (need_locks) { + while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1); ++ if (need_locks < 0) libc.need_locks = 0; ++ } + } + + static inline void unlock(volatile int *lk) +diff --git a/src/thread/__lock.c b/src/thread/__lock.c +index 5b9b144e..60eece49 100644 +--- a/src/thread/__lock.c ++++ b/src/thread/__lock.c +@@ -18,9 +18,11 @@ + + void __lock(volatile int *l) + { +- if (!libc.threaded) return; ++ int need_locks = libc.need_locks; ++ if (!need_locks) return; + /* fast path: INT_MIN for the lock, +1 for the congestion */ + int current = a_cas(l, 0, INT_MIN + 1); ++ if (need_locks < 0) libc.need_locks = 0; + if (!current) return; + /* A first spin loop, for medium congestion. */ + for (unsigned i = 0; i < 10; ++i) { +diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c +index 6a3b0c21..6bdfb44f 100644 +--- a/src/thread/pthread_create.c ++++ b/src/thread/pthread_create.c +@@ -118,8 +118,8 @@ _Noreturn void __pthread_exit(void *result) + * until the lock is released, which only happens after SYS_exit + * has been called, via the exit futex address pointing at the lock. + * This needs to happen after any possible calls to LOCK() that might +- * skip locking if libc.threads_minus_1 is zero. */ +- libc.threads_minus_1--; ++ * skip locking if process appears single-threaded. */ ++ if (!--libc.threads_minus_1) libc.need_locks = -1; + self->next->prev = self->prev; + self->prev->next = self->next; + self->prev = self->next = self; +@@ -339,7 +339,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att + ~(1UL<<((SIGCANCEL-1)%(8*sizeof(long)))); + + __tl_lock(); +- libc.threads_minus_1++; ++ if (!libc.threads_minus_1++) libc.need_locks = 1; + ret = __clone((c11 ? start_c11 : start), stack, flags, args, &new->tid, TP_ADJ(new), &__thread_list_lock); + + /* All clone failures translate to EAGAIN. If explicit scheduling +@@ -363,7 +363,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att + new->next->prev = new; + new->prev->next = new; + } else { +- libc.threads_minus_1--; ++ if (!--libc.threads_minus_1) libc.need_locks = 0; + } + __tl_unlock(); + __restore_sigs(&set); +-- +2.21.0 + + diff --git a/srcpkgs/musl1.1/patches/98e688a9da5e7b2925dda17a2d6820dddf1fb287.patch b/srcpkgs/musl1.1/patches/98e688a9da5e7b2925dda17a2d6820dddf1fb287.patch new file mode 100644 index 00000000000..a8bfa66d6c4 --- /dev/null +++ b/srcpkgs/musl1.1/patches/98e688a9da5e7b2925dda17a2d6820dddf1fb287.patch @@ -0,0 +1,139 @@ +From 98e688a9da5e7b2925dda17a2d6820dddf1fb287 Mon Sep 17 00:00:00 2001 +From: Ismael Luceno +Date: Sun, 15 Aug 2021 17:51:57 +0200 +Subject: [PATCH] define NULL as nullptr when used in C++11 or later + +This should be safer for casting and more compatible with existing code +bases that wrongly assume it must be defined as a pointer. +--- + include/locale.h | 4 +++- + include/stddef.h | 4 +++- + include/stdio.h | 4 +++- + include/stdlib.h | 4 +++- + include/string.h | 4 +++- + include/time.h | 4 +++- + include/unistd.h | 4 +++- + include/wchar.h | 4 +++- + 8 files changed, 24 insertions(+), 8 deletions(-) + +diff --git a/include/locale.h b/include/locale.h +index ce384381c..11106fea8 100644 +--- a/include/locale.h ++++ b/include/locale.h +@@ -7,7 +7,9 @@ extern "C" { + + #include + +-#ifdef __cplusplus ++#if __cplusplus >= 201103L ++#define NULL nullptr ++#elif defined(__cplusplus) + #define NULL 0L + #else + #define NULL ((void*)0) +diff --git a/include/stddef.h b/include/stddef.h +index bd7538535..f25b86396 100644 +--- a/include/stddef.h ++++ b/include/stddef.h +@@ -1,7 +1,9 @@ + #ifndef _STDDEF_H + #define _STDDEF_H + +-#ifdef __cplusplus ++#if __cplusplus >= 201103L ++#define NULL nullptr ++#elif defined(__cplusplus) + #define NULL 0L + #else + #define NULL ((void*)0) +diff --git a/include/stdio.h b/include/stdio.h +index 3604198c3..d1ed01f03 100644 +--- a/include/stdio.h ++++ b/include/stdio.h +@@ -25,7 +25,9 @@ extern "C" { + + #include + +-#ifdef __cplusplus ++#if __cplusplus >= 201103L ++#define NULL nullptr ++#elif defined(__cplusplus) + #define NULL 0L + #else + #define NULL ((void*)0) +diff --git a/include/stdlib.h b/include/stdlib.h +index 7af86e3bc..b507ca33b 100644 +--- a/include/stdlib.h ++++ b/include/stdlib.h +@@ -7,7 +7,9 @@ extern "C" { + + #include + +-#ifdef __cplusplus ++#if __cplusplus >= 201103L ++#define NULL nullptr ++#elif defined(__cplusplus) + #define NULL 0L + #else + #define NULL ((void*)0) +diff --git a/include/string.h b/include/string.h +index 795a2abcd..43ad0942e 100644 +--- a/include/string.h ++++ b/include/string.h +@@ -7,7 +7,9 @@ extern "C" { + + #include + +-#ifdef __cplusplus ++#if __cplusplus >= 201103L ++#define NULL nullptr ++#elif defined(__cplusplus) + #define NULL 0L + #else + #define NULL ((void*)0) +diff --git a/include/time.h b/include/time.h +index 5494df183..3d9483720 100644 +--- a/include/time.h ++++ b/include/time.h +@@ -7,7 +7,9 @@ extern "C" { + + #include + +-#ifdef __cplusplus ++#if __cplusplus >= 201103L ++#define NULL nullptr ++#elif defined(__cplusplus) + #define NULL 0L + #else + #define NULL ((void*)0) +diff --git a/include/unistd.h b/include/unistd.h +index 130640260..ee2dbe8af 100644 +--- a/include/unistd.h ++++ b/include/unistd.h +@@ -15,7 +15,9 @@ extern "C" { + #define SEEK_CUR 1 + #define SEEK_END 2 + +-#ifdef __cplusplus ++#if __cplusplus >= 201103L ++#define NULL nullptr ++#elif defined(__cplusplus) + #define NULL 0L + #else + #define NULL ((void*)0) +diff --git a/include/wchar.h b/include/wchar.h +index 88eb55b18..ed5d774df 100644 +--- a/include/wchar.h ++++ b/include/wchar.h +@@ -38,7 +38,9 @@ extern "C" { + #define WCHAR_MIN (-1-0x7fffffff+L'\0') + #endif + +-#ifdef __cplusplus ++#if __cplusplus >= 201103L ++#define NULL nullptr ++#elif defined(__cplusplus) + #define NULL 0L + #else + #define NULL ((void*)0) + diff --git a/srcpkgs/musl1.1/patches/99d5098a885feae3ae8c32b407350d8ca85dd178.patch b/srcpkgs/musl1.1/patches/99d5098a885feae3ae8c32b407350d8ca85dd178.patch new file mode 100644 index 00000000000..4e03ad1607c --- /dev/null +++ b/srcpkgs/musl1.1/patches/99d5098a885feae3ae8c32b407350d8ca85dd178.patch @@ -0,0 +1,113 @@ +From 99d5098a885feae3ae8c32b407350d8ca85dd178 Mon Sep 17 00:00:00 2001 +From: Julien Ramseier +Date: Sun, 18 Oct 2020 12:15:06 -0400 +Subject: update crypt_blowfish to support $2b$ prefix + +Merge changes from Solar Designer's crypt_blowfish v1.3. This makes +crypt_blowfish fully compatible with OpenBSD's bcrypt by adding +support for the $2b$ prefix (which behaves the same as +crypt_blowfish's $2y$). +--- + src/crypt/crypt_blowfish.c | 38 +++++++++++++++++++++++--------------- + 1 file changed, 23 insertions(+), 15 deletions(-) + +(limited to 'src/crypt/crypt_blowfish.c') + +diff --git a/src/crypt/crypt_blowfish.c b/src/crypt/crypt_blowfish.c +index d3f79851..d722607b 100644 +--- a/src/crypt/crypt_blowfish.c ++++ b/src/crypt/crypt_blowfish.c +@@ -15,7 +15,7 @@ + * No copyright is claimed, and the software is hereby placed in the public + * domain. In case this attempt to disclaim copyright and place the software + * in the public domain is deemed null and void, then the software is +- * Copyright (c) 1998-2012 Solar Designer and it is hereby released to the ++ * Copyright (c) 1998-2014 Solar Designer and it is hereby released to the + * general public under the following terms: + * + * Redistribution and use in source and binary forms, with or without +@@ -31,12 +31,12 @@ + * you place this code and any modifications you make under a license + * of your choice. + * +- * This implementation is mostly compatible with OpenBSD's bcrypt.c (prefix +- * "$2a$") by Niels Provos , and uses some of his +- * ideas. The password hashing algorithm was designed by David Mazieres +- * . For more information on the level of compatibility, +- * please refer to the comments in BF_set_key() below and to the included +- * crypt(3) man page. ++ * This implementation is fully compatible with OpenBSD's bcrypt.c for prefix ++ * "$2b$", originally by Niels Provos , and it uses ++ * some of his ideas. The password hashing algorithm was designed by David ++ * Mazieres . For information on the level of ++ * compatibility for bcrypt hash prefixes other than "$2b$", please refer to ++ * the comments in BF_set_key() below and to the included crypt(3) man page. + * + * There's a paper on the algorithm that explains its design decisions: + * +@@ -533,6 +533,7 @@ static void BF_set_key(const char *key, BF_key expanded, BF_key initial, + * Valid combinations of settings are: + * + * Prefix "$2a$": bug = 0, safety = 0x10000 ++ * Prefix "$2b$": bug = 0, safety = 0 + * Prefix "$2x$": bug = 1, safety = 0 + * Prefix "$2y$": bug = 0, safety = 0 + */ +@@ -596,12 +597,14 @@ static void BF_set_key(const char *key, BF_key expanded, BF_key initial, + initial[0] ^= sign; + } + ++static const unsigned char flags_by_subtype[26] = { ++ 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0 ++}; ++ + static char *BF_crypt(const char *key, const char *setting, + char *output, BF_word min) + { +- static const unsigned char flags_by_subtype[26] = +- {2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0}; + struct { + BF_ctx ctx; + BF_key expanded_key; +@@ -746,9 +749,11 @@ char *__crypt_blowfish(const char *key, const char *setting, char *output) + { + const char *test_key = "8b \xd0\xc1\xd2\xcf\xcc\xd8"; + const char *test_setting = "$2a$00$abcdefghijklmnopqrstuu"; +- static const char test_hash[2][34] = +- {"VUrPmXD6q/nVSSp7pNDhCR9071IfIRe\0\x55", /* $2x$ */ +- "i1D709vfamulimlGcq0qq3UvuUasvEa\0\x55"}; /* $2a$, $2y$ */ ++ static const char test_hashes[2][34] = { ++ "i1D709vfamulimlGcq0qq3UvuUasvEa\0\x55", /* 'a', 'b', 'y' */ ++ "VUrPmXD6q/nVSSp7pNDhCR9071IfIRe\0\x55", /* 'x' */ ++ }; ++ const char *test_hash = test_hashes[0]; + char *retval; + const char *p; + int ok; +@@ -768,8 +773,11 @@ char *__crypt_blowfish(const char *key, const char *setting, char *output) + * detected by the self-test. + */ + memcpy(buf.s, test_setting, sizeof(buf.s)); +- if (retval) ++ if (retval) { ++ unsigned int flags = flags_by_subtype[setting[2] - 'a']; ++ test_hash = test_hashes[flags & 1]; + buf.s[2] = setting[2]; ++ } + memset(buf.o, 0x55, sizeof(buf.o)); + buf.o[sizeof(buf.o) - 1] = 0; + p = BF_crypt(test_key, buf.s, buf.o, 1); +@@ -777,7 +785,7 @@ char *__crypt_blowfish(const char *key, const char *setting, char *output) + ok = (p == buf.o && + !memcmp(p, buf.s, 7 + 22) && + !memcmp(p + (7 + 22), +- test_hash[buf.s[2] & 1], ++ test_hash, + 31 + 1 + 1 + 1)); + + { +-- +cgit v1.2.1 + diff --git a/srcpkgs/musl1.1/patches/CVE-2020-28928.patch b/srcpkgs/musl1.1/patches/CVE-2020-28928.patch new file mode 100644 index 00000000000..b3ff3b4ee08 --- /dev/null +++ b/srcpkgs/musl1.1/patches/CVE-2020-28928.patch @@ -0,0 +1,64 @@ +--- a/src/multibyte/wcsnrtombs.c ++++ b/src/multibyte/wcsnrtombs.c +@@ -1,41 +1,33 @@ + #include ++#include ++#include + + size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, size_t n, mbstate_t *restrict st) + { +- size_t l, cnt=0, n2; +- char *s, buf[256]; + const wchar_t *ws = *wcs; +- const wchar_t *tmp_ws; +- +- if (!dst) s = buf, n = sizeof buf; +- else s = dst; +- +- while ( ws && n && ( (n2=wn)>=n || n2>32 ) ) { +- if (n2>=n) n2=n; +- tmp_ws = ws; +- l = wcsrtombs(s, &ws, n2, 0); +- if (!(l+1)) { +- cnt = l; +- n = 0; ++ size_t cnt = 0; ++ if (!dst) n=0; ++ while (ws && wn) { ++ char tmp[MB_LEN_MAX]; ++ size_t l = wcrtomb(nn) break; ++ memcpy(dst, tmp, l); ++ } ++ dst += l; + n -= l; + } +- wn = ws ? wn - (ws - tmp_ws) : 0; +- cnt += l; +- } +- if (ws) while (n && wn) { +- l = wcrtomb(s, *ws, 0); +- if ((l+1)<=1) { +- if (!l) ws = 0; +- else cnt = l; ++ if (!*ws) { ++ ws = 0; + break; + } +- ws++; wn--; +- /* safe - this loop runs fewer than sizeof(buf) times */ +- s+=l; n-=l; ++ ws++; ++ wn--; + cnt += l; + } + if (dst) *wcs = ws; + diff --git a/srcpkgs/musl1.1/patches/aarch64-fregs.patch b/srcpkgs/musl1.1/patches/aarch64-fregs.patch new file mode 100644 index 00000000000..024eed11a8e --- /dev/null +++ b/srcpkgs/musl1.1/patches/aarch64-fregs.patch @@ -0,0 +1,37 @@ +Use types compatible with glibc/kernel headers. + +diff --git a/arch/aarch64/bits/signal.h b/arch/aarch64/bits/signal.h +index b71261f5..5098c734 100644 +--- a/arch/aarch64/bits/signal.h ++++ b/arch/aarch64/bits/signal.h +@@ -11,7 +11,7 @@ typedef unsigned long greg_t; + typedef unsigned long gregset_t[34]; + + typedef struct { +- long double vregs[32]; ++ __uint128_t vregs[32]; + unsigned int fpsr; + unsigned int fpcr; + } fpregset_t; +@@ -34,7 +34,7 @@ struct fpsimd_context { + struct _aarch64_ctx head; + unsigned int fpsr; + unsigned int fpcr; +- long double vregs[32]; ++ __uint128_t vregs[32]; + }; + struct esr_context { + struct _aarch64_ctx head; +diff --git a/arch/aarch64/bits/user.h b/arch/aarch64/bits/user.h +index d12cdf7f..8a1002aa 100644 +--- a/arch/aarch64/bits/user.h ++++ b/arch/aarch64/bits/user.h +@@ -6,7 +6,7 @@ struct user_regs_struct { + }; + + struct user_fpsimd_struct { +- long double vregs[32]; ++ __uint128_t vregs[32]; + unsigned int fpsr; + unsigned int fpcr; + }; diff --git a/srcpkgs/musl1.1/patches/add-preadv2-pwritev2.patch b/srcpkgs/musl1.1/patches/add-preadv2-pwritev2.patch new file mode 100644 index 00000000000..ce76feb91ae --- /dev/null +++ b/srcpkgs/musl1.1/patches/add-preadv2-pwritev2.patch @@ -0,0 +1,77 @@ +From 81cced6ebeb4419a78a8892ec7d7e28f5582d24a Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Thu, 25 Jan 2024 12:02:34 -0500 +Subject: [PATCH] add preadv2 and pwritev2 syscall wrappers, flag value macros + +--- + include/sys/uio.h | 7 +++++++ + src/linux/preadv2.c | 17 +++++++++++++++++ + src/linux/pwritev2.c | 17 +++++++++++++++++ + 3 files changed, 41 insertions(+) + create mode 100644 src/linux/preadv2.c + create mode 100644 src/linux/pwritev2.c + +diff --git a/include/sys/uio.h b/include/sys/uio.h +index 90e5939ed..8b5e3de79 100644 +--- a/include/sys/uio.h ++++ b/include/sys/uio.h +@@ -39,6 +39,13 @@ ssize_t pwritev (int, const struct iovec *, int, off_t); + #ifdef _GNU_SOURCE + ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); + ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); ++ssize_t preadv2 (int, const struct iovec *, int, off_t, int); ++ssize_t pwritev2 (int, const struct iovec *, int, off_t, int); ++#define RWF_HIPRI 0x00000001 ++#define RWF_DSYNC 0x00000002 ++#define RWF_SYNC 0x00000004 ++#define RWF_NOWAIT 0x00000008 ++#define RWF_APPEND 0x00000010 + #endif + + #ifdef __cplusplus +diff --git a/src/linux/preadv2.c b/src/linux/preadv2.c +new file mode 100644 +index 000000000..5e7ab70f1 +--- /dev/null ++++ b/src/linux/preadv2.c +@@ -0,0 +1,17 @@ ++#define _GNU_SOURCE ++#include ++#include ++#include "syscall.h" ++ ++ssize_t preadv2(int fd, const struct iovec *iov, int count, off_t ofs, int flags) ++{ ++#ifdef SYS_preadv ++ if (!flags) { ++ if (ofs==-1) return readv(fd, iov, count); ++ return syscall_cp(SYS_preadv, fd, iov, count, ++ (long)(ofs), (long)(ofs>>32)); ++ } ++#endif ++ return syscall_cp(SYS_preadv2, fd, iov, count, ++ (long)(ofs), (long)(ofs>>32), flags); ++} +diff --git a/src/linux/pwritev2.c b/src/linux/pwritev2.c +new file mode 100644 +index 000000000..ece90d7ca +--- /dev/null ++++ b/src/linux/pwritev2.c +@@ -0,0 +1,17 @@ ++#define _GNU_SOURCE ++#include ++#include ++#include "syscall.h" ++ ++ssize_t pwritev2(int fd, const struct iovec *iov, int count, off_t ofs, int flags) ++{ ++#ifdef SYS_pwritev ++ if (!flags) { ++ if (ofs==-1) return writev(fd, iov, count); ++ return syscall_cp(SYS_pwritev, fd, iov, count, ++ (long)(ofs), (long)(ofs>>32)); ++ } ++#endif ++ return syscall_cp(SYS_pwritev2, fd, iov, count, ++ (long)(ofs), (long)(ofs>>32), flags); ++} diff --git a/srcpkgs/musl1.1/patches/add-pthread_getname.patch b/srcpkgs/musl1.1/patches/add-pthread_getname.patch new file mode 100644 index 00000000000..5853cfa5c34 --- /dev/null +++ b/srcpkgs/musl1.1/patches/add-pthread_getname.patch @@ -0,0 +1,55 @@ +From bd3b9c4ca5e93f10f7fd891b8c07cc0c5dfd198f Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=89rico=20Rolim?= +Date: Tue, 20 Apr 2021 16:15:15 -0300 +Subject: [PATCH] add pthread_getname_np function + +based on the pthread_setname_np implementation +--- + include/pthread.h | 1 + + src/thread/pthread_getname_np.c | 25 +++++++++++++++++++++++++ + 2 files changed, 26 insertions(+) + create mode 100644 src/thread/pthread_getname_np.c + +diff --git a/include/pthread.h b/include/pthread.h +index 0492f26a6..89fd9ff7c 100644 +--- a/include/pthread.h ++++ b/include/pthread.h +@@ -221,6 +221,7 @@ int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *); + int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *); + int pthread_getattr_np(pthread_t, pthread_attr_t *); + int pthread_setname_np(pthread_t, const char *); ++int pthread_getname_np(pthread_t, char *, size_t); + int pthread_getattr_default_np(pthread_attr_t *); + int pthread_setattr_default_np(const pthread_attr_t *); + int pthread_tryjoin_np(pthread_t, void **); +diff --git a/src/thread/pthread_getname_np.c b/src/thread/pthread_getname_np.c +new file mode 100644 +index 000000000..48d1a294f +--- /dev/null ++++ b/src/thread/pthread_getname_np.c +@@ -0,0 +1,25 @@ ++#define _GNU_SOURCE ++#include ++#include ++#include ++ ++#include "pthread_impl.h" ++ ++int pthread_getname_np(pthread_t thread, char *name, size_t len) ++{ ++ int fd, cs, status = 0; ++ char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)]; ++ ++ if (len < 16) return ERANGE; ++ ++ if (thread == pthread_self()) ++ return prctl(PR_GET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0; ++ ++ snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid); ++ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); ++ if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) < 0) status = errno; ++ else name[len-1] = 0; /* remove trailing new line only if successful */ ++ if (fd >= 0) close(fd); ++ pthread_setcancelstate(cs, 0); ++ return status; ++} diff --git a/srcpkgs/musl1.1/patches/add-qsort_r.patch b/srcpkgs/musl1.1/patches/add-qsort_r.patch new file mode 100644 index 00000000000..3d85496afb6 --- /dev/null +++ b/srcpkgs/musl1.1/patches/add-qsort_r.patch @@ -0,0 +1,201 @@ +From b76f37fd5625d038141b52184956fb4b7838e9a5 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=89rico=20Nogueira?= +Date: Tue, 9 Mar 2021 18:02:13 -0300 +Subject: [PATCH] add qsort_r and make qsort a wrapper around it + +we make qsort a wrapper by providing a wrapper_cmp function that uses +the extra argument as a function pointer. should be optimized to a tail +call on most architectures, as long as it's built with +-fomit-frame-pointer, so the performance impact should be minimal. + +to keep the git history clean, for now qsort_r is implemented in qsort.c +and qsort is implemented in qsort_nr.c. qsort.c also received a few +trivial cleanups, including replacing (*cmp)() calls with cmp(). +qsort_nr.c contains only wrapper_cmp and qsort as a qsort_r wrapper +itself. +--- + include/stdlib.h | 1 + + src/include/stdlib.h | 1 + + src/stdlib/qsort.c | 37 ++++++++++++++++++++----------------- + src/stdlib/qsort_nr.c | 14 ++++++++++++++ + 4 files changed, 36 insertions(+), 17 deletions(-) + create mode 100644 src/stdlib/qsort_nr.c + +diff --git a/include/stdlib.h b/include/stdlib.h +index b54a051fe..7af86e3bc 100644 +--- a/include/stdlib.h ++++ b/include/stdlib.h +@@ -146,6 +146,7 @@ int clearenv(void); + #define WCOREDUMP(s) ((s) & 0x80) + #define WIFCONTINUED(s) ((s) == 0xffff) + void *reallocarray (void *, size_t, size_t); ++void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); + #endif + + #ifdef _GNU_SOURCE +diff --git a/src/include/stdlib.h b/src/include/stdlib.h +index e9da20158..812b04de2 100644 +--- a/src/include/stdlib.h ++++ b/src/include/stdlib.h +@@ -8,6 +8,7 @@ hidden void __env_rm_add(char *, char *); + hidden int __mkostemps(char *, int, int); + hidden int __ptsname_r(int, char *, size_t); + hidden char *__randname(char *); ++hidden void __qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); + + hidden void *__libc_malloc(size_t); + hidden void *__libc_malloc_impl(size_t); +diff --git a/src/stdlib/qsort.c b/src/stdlib/qsort.c +index da58fd317..314ddc29d 100644 +--- a/src/stdlib/qsort.c ++++ b/src/stdlib/qsort.c +@@ -24,6 +24,7 @@ + /* Smoothsort, an adaptive variant of Heapsort. Memory usage: O(1). + Run time: Worst case O(n log n), close to O(n) in the mostly-sorted case. */ + ++#define _BSD_SOURCE + #include + #include + #include +@@ -31,7 +32,7 @@ + #include "atomic.h" + #define ntz(x) a_ctz_l((x)) + +-typedef int (*cmpfun)(const void *, const void *); ++typedef int (*cmpfun)(const void *, const void *, void *); + + static inline int pntz(size_t p[2]) { + int r = ntz(p[0] - 1); +@@ -88,7 +89,7 @@ static inline void shr(size_t p[2], int n) + p[1] >>= n; + } + +-static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size_t lp[]) ++static void sift(unsigned char *head, size_t width, cmpfun cmp, void *arg, int pshift, size_t lp[]) + { + unsigned char *rt, *lf; + unsigned char *ar[14 * sizeof(size_t) + 1]; +@@ -99,10 +100,10 @@ static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size + rt = head - width; + lf = head - width - lp[pshift - 2]; + +- if((*cmp)(ar[0], lf) >= 0 && (*cmp)(ar[0], rt) >= 0) { ++ if(cmp(ar[0], lf, arg) >= 0 && cmp(ar[0], rt, arg) >= 0) { + break; + } +- if((*cmp)(lf, rt) >= 0) { ++ if(cmp(lf, rt, arg) >= 0) { + ar[i++] = lf; + head = lf; + pshift -= 1; +@@ -115,7 +116,7 @@ static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size + cycle(width, ar, i); + } + +-static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2], int pshift, int trusty, size_t lp[]) ++static void trinkle(unsigned char *head, size_t width, cmpfun cmp, void *arg, size_t pp[2], int pshift, int trusty, size_t lp[]) + { + unsigned char *stepson, + *rt, *lf; +@@ -130,13 +131,13 @@ static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2], + ar[0] = head; + while(p[0] != 1 || p[1] != 0) { + stepson = head - lp[pshift]; +- if((*cmp)(stepson, ar[0]) <= 0) { ++ if(cmp(stepson, ar[0], arg) <= 0) { + break; + } + if(!trusty && pshift > 1) { + rt = head - width; + lf = head - width - lp[pshift - 2]; +- if((*cmp)(rt, stepson) >= 0 || (*cmp)(lf, stepson) >= 0) { ++ if(cmp(rt, stepson, arg) >= 0 || cmp(lf, stepson, arg) >= 0) { + break; + } + } +@@ -150,11 +151,11 @@ static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2], + } + if(!trusty) { + cycle(width, ar, i); +- sift(head, width, cmp, pshift, lp); ++ sift(head, width, cmp, arg, pshift, lp); + } + } + +-void qsort(void *base, size_t nel, size_t width, cmpfun cmp) ++void __qsort_r(void *base, size_t nel, size_t width, cmpfun cmp, void *arg) + { + size_t lp[12*sizeof(size_t)]; + size_t i, size = width * nel; +@@ -173,16 +174,16 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp) + + while(head < high) { + if((p[0] & 3) == 3) { +- sift(head, width, cmp, pshift, lp); ++ sift(head, width, cmp, arg, pshift, lp); + shr(p, 2); + pshift += 2; + } else { + if(lp[pshift - 1] >= high - head) { +- trinkle(head, width, cmp, p, pshift, 0, lp); ++ trinkle(head, width, cmp, arg, p, pshift, 0, lp); + } else { +- sift(head, width, cmp, pshift, lp); ++ sift(head, width, cmp, arg, pshift, lp); + } +- ++ + if(pshift == 1) { + shl(p, 1); + pshift = 0; +@@ -191,12 +192,12 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp) + pshift = 1; + } + } +- ++ + p[0] |= 1; + head += width; + } + +- trinkle(head, width, cmp, p, pshift, 0, lp); ++ trinkle(head, width, cmp, arg, p, pshift, 0, lp); + + while(pshift != 1 || p[0] != 1 || p[1] != 0) { + if(pshift <= 1) { +@@ -208,11 +209,13 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp) + pshift -= 2; + p[0] ^= 7; + shr(p, 1); +- trinkle(head - lp[pshift] - width, width, cmp, p, pshift + 1, 1, lp); ++ trinkle(head - lp[pshift] - width, width, cmp, arg, p, pshift + 1, 1, lp); + shl(p, 1); + p[0] |= 1; +- trinkle(head - width, width, cmp, p, pshift, 1, lp); ++ trinkle(head - width, width, cmp, arg, p, pshift, 1, lp); + } + head -= width; + } + } ++ ++weak_alias(__qsort_r, qsort_r); +diff --git a/src/stdlib/qsort_nr.c b/src/stdlib/qsort_nr.c +new file mode 100644 +index 000000000..efe7ccecd +--- /dev/null ++++ b/src/stdlib/qsort_nr.c +@@ -0,0 +1,14 @@ ++#define _BSD_SOURCE ++#include ++ ++typedef int (*cmpfun)(const void *, const void *); ++ ++static int wrapper_cmp(const void *v1, const void *v2, void *cmp) ++{ ++ return ((cmpfun)cmp)(v1, v2); ++} ++ ++void qsort(void *base, size_t nel, size_t width, cmpfun cmp) ++{ ++ __qsort_r(base, nel, width, wrapper_cmp, cmp); ++} diff --git a/srcpkgs/musl1.1/patches/add-rlimit-rttime.patch b/srcpkgs/musl1.1/patches/add-rlimit-rttime.patch new file mode 100644 index 00000000000..56afa6b6652 --- /dev/null +++ b/srcpkgs/musl1.1/patches/add-rlimit-rttime.patch @@ -0,0 +1,24 @@ +From 2507e7f5312e79620f6337935d0a6c9045ccba09 Mon Sep 17 00:00:00 2001 +From: Leah Neukirchen +Date: Sat, 11 Jan 2020 20:16:59 +0100 +Subject: [PATCH] define RLIMIT_RTTIME, bump RLIMIT_NLIMITS + +This macro exists since Linux 2.6.25 and is defined in glibc since 2011. +--- + include/sys/resource.h | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/include/sys/resource.h b/include/sys/resource.h +index e0c86ae33..3068328d0 100644 +--- a/include/sys/resource.h ++++ b/include/sys/resource.h +@@ -90,7 +90,8 @@ int prlimit(pid_t, int, const struct rlimit *, struct rlimit *); + #define RLIMIT_MSGQUEUE 12 + #define RLIMIT_NICE 13 + #define RLIMIT_RTPRIO 14 +-#define RLIMIT_NLIMITS 15 ++#define RLIMIT_RTTIME 15 ++#define RLIMIT_NLIMITS 16 + + #define RLIM_NLIMITS RLIMIT_NLIMITS + diff --git a/srcpkgs/musl1.1/patches/add-support-for-SIGEV_THREAD_ID-timers.patch b/srcpkgs/musl1.1/patches/add-support-for-SIGEV_THREAD_ID-timers.patch new file mode 100644 index 00000000000..e20dff5ba0d --- /dev/null +++ b/srcpkgs/musl1.1/patches/add-support-for-SIGEV_THREAD_ID-timers.patch @@ -0,0 +1,74 @@ +From 7c71792e87691451f2a6b76348e83ad1889f1dcb Mon Sep 17 00:00:00 2001 +From: James Y Knight +Date: Sun, 30 Jun 2019 21:55:20 -0400 +Subject: [PATCH] add support for SIGEV_THREAD_ID timers + +This is like SIGEV_SIGNAL, but targeted to a particular thread's +tid, rather than the process. +--- + include/signal.h | 16 +++++++++++++--- + src/time/timer_create.c | 8 ++++++-- + 2 files changed, 19 insertions(+), 5 deletions(-) + +diff --git a/include/signal.h b/include/signal.h +index fbdf667b2..9ed929e4f 100644 +--- a/include/signal.h ++++ b/include/signal.h +@@ -180,14 +180,24 @@ struct sigevent { + union sigval sigev_value; + int sigev_signo; + int sigev_notify; +- void (*sigev_notify_function)(union sigval); +- pthread_attr_t *sigev_notify_attributes; +- char __pad[56-3*sizeof(long)]; ++ union { ++ char __pad[64 - 2*sizeof(int) - sizeof(union sigval)]; ++ pid_t sigev_notify_thread_id; ++ struct { ++ void (*sigev_notify_function)(union sigval); ++ pthread_attr_t *sigev_notify_attributes; ++ } __sev_thread; ++ } __sev_fields; + }; + ++#define sigev_notify_thread_id __sev_fields.sigev_notify_thread_id ++#define sigev_notify_function __sev_fields.__sev_thread.sigev_notify_function ++#define sigev_notify_attributes __sev_fields.__sev_thread.sigev_notify_attributes ++ + #define SIGEV_SIGNAL 0 + #define SIGEV_NONE 1 + #define SIGEV_THREAD 2 ++#define SIGEV_THREAD_ID 4 + + int __libc_current_sigrtmin(void); + int __libc_current_sigrtmax(void); +diff --git a/src/time/timer_create.c b/src/time/timer_create.c +index 5ddfda278..4bef23905 100644 +--- a/src/time/timer_create.c ++++ b/src/time/timer_create.c +@@ -71,11 +71,15 @@ int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict + switch (evp ? evp->sigev_notify : SIGEV_SIGNAL) { + case SIGEV_NONE: + case SIGEV_SIGNAL: ++ case SIGEV_THREAD_ID: + if (evp) { + ksev.sigev_value = evp->sigev_value; + ksev.sigev_signo = evp->sigev_signo; + ksev.sigev_notify = evp->sigev_notify; +- ksev.sigev_tid = 0; ++ if (evp->sigev_notify == SIGEV_THREAD_ID) ++ ksev.sigev_tid = evp->sigev_notify_thread_id; ++ else ++ ksev.sigev_tid = 0; + ksevp = &ksev; + } + if (syscall(SYS_timer_create, clk, ksevp, &timerid) < 0) +@@ -107,7 +111,7 @@ int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict + + ksev.sigev_value.sival_ptr = 0; + ksev.sigev_signo = SIGTIMER; +- ksev.sigev_notify = 4; /* SIGEV_THREAD_ID */ ++ ksev.sigev_notify = SIGEV_THREAD_ID; + ksev.sigev_tid = td->tid; + if (syscall(SYS_timer_create, clk, &ksev, &timerid) < 0) + timerid = -1; diff --git a/srcpkgs/musl1.1/patches/avoid-set-id-setrlimit-misbehavior-and-hang-in-vfork.patch b/srcpkgs/musl1.1/patches/avoid-set-id-setrlimit-misbehavior-and-hang-in-vfork.patch new file mode 100644 index 00000000000..21f236b3a6c --- /dev/null +++ b/srcpkgs/musl1.1/patches/avoid-set-id-setrlimit-misbehavior-and-hang-in-vfork.patch @@ -0,0 +1,49 @@ +From a5aff1972c9e3981566414b09a28e331ccd2be5d Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Thu, 17 Sep 2020 15:09:46 -0400 +Subject: [PATCH 237/513] avoid set*id/setrlimit misbehavior and hang in + vforked/cloned child + +taking the deprecated/dropped vfork spec strictly, doing pretty much +anything but execve in the child is wrong and undefined. however, +these are commonly needed operations to setup the child state before +exec, and historical implementations tolerated them. + +for single-threaded parents, these operations already worked as +expected in the vforked child. however, due to the need for __synccall +to synchronize id/resource limit changes among all threads, calling +these functions in the vforked child of a multithreaded parent caused +a misdirected broadcast signaling of all threads in the parent. these +signals could kill the parent entirely if the synccall signal handler +had never been installed in the parent, or could be ignored if it had, +or could signal/kill one or more utterly wrong processes if the parent +already terminated (due to vfork semantics, only possible via fatal +signal) and the parent tids were recycled. in any case, the expected +number of semaphore posts would never happen, so the child would +permanently hang (with all signals blocked) waiting for them. + +to mitigate this, and also make the normal usage case work as +intended, treat the condition where the caller's actual tid does not +match the tid in its thread structure as single-threaded, and bypass +the entire synccall broadcast operation. +--- + src/thread/synccall.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/src/thread/synccall.c b/src/thread/synccall.c +index 648a6ad4..d58c851f 100644 +--- a/src/thread/synccall.c ++++ b/src/thread/synccall.c +@@ -63,7 +63,8 @@ void __synccall(void (*func)(void *), void *ctx) + sem_init(&target_sem, 0, 0); + sem_init(&caller_sem, 0, 0); + +- if (!libc.threads_minus_1) goto single_threaded; ++ if (!libc.threads_minus_1 || __syscall(SYS_gettid) != self->tid) ++ goto single_threaded; + + callback = func; + context = ctx; +-- +2.41.0 + diff --git a/srcpkgs/musl1.1/patches/c23-basename.patch b/srcpkgs/musl1.1/patches/c23-basename.patch new file mode 100644 index 00000000000..8f95a27d0ef --- /dev/null +++ b/srcpkgs/musl1.1/patches/c23-basename.patch @@ -0,0 +1,44 @@ +From 725e17ed6dff4d0cd22487bb64470881e86a92e7 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Mon, 6 Nov 2023 08:26:19 -0500 +Subject: [PATCH] remove non-prototype declaration of basename from string.h + +commit 37bb3cce4598c19288628e675eaf1cda6e96958f suppressed the +declaration for C++, where it is wrongly interpreted as declaring the +function as taking no arguments. with C23 removing non-prototype +declarations, that problem is now also relevant to C. + +the non-prototype declaration for basename originates with commit +06aec8d7152dfb8360cb7ed9b3d7215ca0b0b500, where it was designed to +avoid conflicts with programs which declare basename with the GNU +signature taking const char *. that change was probably misguided, as +it represents not only misaligned expectations with the caller, but +also undefined behavior (calling a function that's been declared with +the wrong type). + +we could opt to fix the declaration, but since glibc, with the +gratuitously incompatible GNU-basename function, seems to be the only +implementation that declares it in string.h, it seems better to just +remove the declaration. this provides some warning if applications are +being built expecting the GNU behavior but not getting it. if we +declared it here, it would only produce a warning if the caller also +declares it themselves (rare) or if the caller attempts to pass a +const-qualified pointer. +--- + include/string.h | 3 --- + 1 file changed, 3 deletions(-) + +diff --git a/include/string.h b/include/string.h +index db73d2a9..83e2b946 100644 +--- a/include/string.h ++++ b/include/string.h +@@ -95,9 +95,6 @@ char *strchrnul(const char *, int); + char *strcasestr(const char *, const char *); + void *memrchr(const void *, int, size_t); + void *mempcpy(void *, const void *, size_t); +-#ifndef __cplusplus +-char *basename(); +-#endif + #endif + + #ifdef __cplusplus diff --git a/srcpkgs/musl1.1/patches/epoll_cp.patch b/srcpkgs/musl1.1/patches/epoll_cp.patch new file mode 100644 index 00000000000..92f47551ad8 --- /dev/null +++ b/srcpkgs/musl1.1/patches/epoll_cp.patch @@ -0,0 +1,28 @@ +From 2c00f95c1ac7dd50f53d9e361847ebd2513c8da0 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Sat, 3 Apr 2021 21:16:41 -0400 +Subject: [PATCH] make epoll_[p]wait a cancellation point + +this is a Linux-specific function and not covered by POSIX's +requirements for which interfaces are cancellation points, but glibc +makes it one and existing software relies on it being one. + +at some point a review for similar functions that should be made +cancellation points should be done. + +diff --git src/linux/epoll.c src/linux/epoll.c +index deff5b10..93baa814 100644 +--- a/src/linux/epoll.c ++++ b/src/linux/epoll.c +@@ -24,9 +24,9 @@ int epoll_ctl(int fd, int op, int fd2, struct epoll_event *ev) + + int epoll_pwait(int fd, struct epoll_event *ev, int cnt, int to, const sigset_t *sigs) + { +- int r = __syscall(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8); ++ int r = __syscall_cp(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8); + #ifdef SYS_epoll_wait +- if (r==-ENOSYS && !sigs) r = __syscall(SYS_epoll_wait, fd, ev, cnt, to); ++ if (r==-ENOSYS && !sigs) r = __syscall_cp(SYS_epoll_wait, fd, ev, cnt, to); + #endif + return __syscall_ret(r); + } diff --git a/srcpkgs/musl1.1/patches/faccessat.patch b/srcpkgs/musl1.1/patches/faccessat.patch new file mode 100644 index 00000000000..4c1ea8f2b26 --- /dev/null +++ b/srcpkgs/musl1.1/patches/faccessat.patch @@ -0,0 +1,45 @@ +From 55fb9a177316aa46c639d93dd0323d9a9a8c160c Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Wed, 9 Sep 2020 21:55:11 -0400 +Subject: [PATCH] use new SYS_faccessat2 syscall to implement faccessat with + flags + +commit 0a05eace163cee9b08571d2ff9d90f5e82d9c228 implemented AT_EACCESS +for faccessat with a horrible hack, creating a child process to change +switch uid/gid and perform the access probe without making potentially +irreversible changes to the caller's credentials. this was due to the +syscall lacking a flags argument. + +linux 5.8 introduced a new syscall, SYS_faccessat2, fixing this +deficiency. use it if any flags are passed, and fallback to the old +strategy on ENOSYS. continue using the old syscall when there are no +flags. +--- + src/unistd/faccessat.c | 11 ++++++++--- + 1 file changed, 8 insertions(+), 3 deletions(-) + +diff --git a/src/unistd/faccessat.c b/src/unistd/faccessat.c +index 76bbd4c72..557503eb6 100644 +--- a/src/unistd/faccessat.c ++++ b/src/unistd/faccessat.c +@@ -25,12 +25,17 @@ static int checker(void *p) + + int faccessat(int fd, const char *filename, int amode, int flag) + { +- if (!flag || (flag==AT_EACCESS && getuid()==geteuid() && getgid()==getegid())) +- return syscall(SYS_faccessat, fd, filename, amode, flag); ++ if (flag) { ++ int ret = __syscall(SYS_faccessat2, fd, filename, amode, flag); ++ if (ret != -ENOSYS) return __syscall_ret(ret); ++ } + +- if (flag != AT_EACCESS) ++ if (flag & ~AT_EACCESS) + return __syscall_ret(-EINVAL); + ++ if (!flag || (getuid()==geteuid() && getgid()==getegid())) ++ return syscall(SYS_faccessat, fd, filename, amode); ++ + char stack[1024]; + sigset_t set; + pid_t pid; diff --git a/srcpkgs/musl1.1/patches/fgetws.patch b/srcpkgs/musl1.1/patches/fgetws.patch new file mode 100644 index 00000000000..c85c874279e --- /dev/null +++ b/srcpkgs/musl1.1/patches/fgetws.patch @@ -0,0 +1,61 @@ +From f8bdc3048216f41eaaf655524fa286cfb1184a70 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Sun, 20 Feb 2022 20:11:14 -0500 +Subject: [PATCH] fix spurious failures by fgetws when buffer ends with partial + character + +commit a90d9da1d1b14d81c4f93e1a6d1a686c3312e4ba made fgetws look for +changes to errno by fgetwc to detect encoding errors, since ISO C did +not allow the implementation to set the stream's error flag in this +case, and the fgetwc interface did not admit any other way to detect +the error. however, the possibility of fgetwc setting errno to EILSEQ +in the success path was overlooked, and in fact this can happen if the +buffer ends with a partial character, causing mbtowc to be called with +only part of the character available. + +since that change was made, the C standard was amended to specify that +fgetwc set the stream error flag on encoding errors, and commit +511d70738bce11a67219d0132ce725c323d00e4e made it do so. thus, there is +no longer any need for fgetws to poke at errno to handle encoding +errors. + +this commit reverts commit a90d9da1d1b14d81c4f93e1a6d1a686c3312e4ba +and thereby fixes the problem. +--- + src/stdio/fgetws.c | 7 +------ + 1 file changed, 1 insertion(+), 6 deletions(-) + +diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c +index b08b3049..195cb435 100644 +--- a/src/stdio/fgetws.c ++++ b/src/stdio/fgetws.c +@@ -1,6 +1,5 @@ + #include "stdio_impl.h" + #include +-#include + + wint_t __fgetwc_unlocked(FILE *); + +@@ -12,10 +11,6 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) + + FLOCK(f); + +- /* Setup a dummy errno so we can detect EILSEQ. This is +- * the only way to catch encoding errors in the form of a +- * partial character just before EOF. */ +- errno = EAGAIN; + for (; n; n--) { + wint_t c = __fgetwc_unlocked(f); + if (c == WEOF) break; +@@ -23,7 +18,7 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) + if (c == '\n') break; + } + *p = 0; +- if (ferror(f) || errno==EILSEQ) p = s; ++ if (ferror(f)) p = s; + + FUNLOCK(f); + +-- +2.41.0 + diff --git a/srcpkgs/musl1.1/patches/fix-oob-read-processing-time-zone-data.patch b/srcpkgs/musl1.1/patches/fix-oob-read-processing-time-zone-data.patch new file mode 100644 index 00000000000..557cbd7446d --- /dev/null +++ b/srcpkgs/musl1.1/patches/fix-oob-read-processing-time-zone-data.patch @@ -0,0 +1,80 @@ +From 3b7b4155570b4b9054465785be2992c92cb7d7b1 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Wed, 9 Feb 2022 17:48:43 -0500 +Subject: fix out-of-bound read processing time zone data with distant-past + dates + +this bug goes back to commit 1cc81f5cb0df2b66a795ff0c26d7bbc4d16e13c6 +where zoneinfo file support was first added. in scan_trans, which +searches for the appropriate local time/dst rule in effect at a given +time, times prior to the second transition time caused the -1 slot of +the index to be read to determine the previous rule in effect. this +memory was always valid (part of another zoneinfo table in the mapped +file) but the byte value read was then used to index another table, +possibly going outside the bounds of the mmap. most of the time, the +result was limited to misinterpretation of the rule in effect at that +time (pre-1900s), but it could produce a crash if adjacent memory was +not readable. + +the root cause of the problem, however, was that the logic for this +code path was all wrong. as documented in the comment, times before +the first transition should be treated as using the lowest-numbered +non-dst rule, or rule 0 if no non-dst rules exist. if the argument is +in units of local time, however, the rule prior to the first +transition is needed to determine if it falls before or after it, and +that's where the -1 index was wrongly used. + +instead, use the documented logic to find out what rule would be in +effect before the first transition, and apply it as the offset if the +argument was given in local time. + +the new code has not been heavily tested, but no longer performs +potentially out-of-bounds accesses, and successfully handles the 1883 +transition from local mean time to central standard time in the test +case the error was reported for. +--- + src/time/__tz.c | 26 ++++++++++++-------------- + 1 file changed, 12 insertions(+), 14 deletions(-) + +diff --git a/src/time/__tz.c b/src/time/__tz.c +index 3e2fcdcb..c34b3eb7 100644 +--- a/src/time/__tz.c ++++ b/src/time/__tz.c +@@ -293,22 +293,20 @@ static size_t scan_trans(long long t, int local, size_t *alt) + n = (index-trans)>>scale; + if (a == n-1) return -1; + if (a == 0) { +- x = zi_read32(trans + (a< +Date: Mon, 26 Oct 2020 15:56:25 -0400 +Subject: fix pthread_cond_wait paired with with priority-inheritance mutex + +pthread_cond_wait arranged for requeued waiters to wake when the mutex +is unlocked by temporarily adjusting the mutex's waiter count. commit +54ca677983d47529bab8752315ac1a2b49888870 broke this when introducing +PI mutexes by repurposing the waiter count field of the mutex +structure. since then, for PI mutexes, the waiter count adjustment was +misinterpreted by the mutex locking code as indicating that the mutex +is non a non-recoverable state. + +it would be possible to special-case PI mutexes here, but instead just +drop all adjustment of the waiters count, and instead use the lock +word waiters bit for all mutex types. since the mutex is either held +by the caller or in unrecoverable state at the time the bit is set, it +will necessarily still be set at the time of any subsequent valid +unlock operation, and this will produce the desired effect of waking +the next waiter. + +if waiter counts are entirely dropped at some point in the future this +code should still work without modification. +--- + src/thread/pthread_cond_timedwait.c | 11 +++++------ + 1 file changed, 5 insertions(+), 6 deletions(-) + +(limited to 'src/thread/pthread_cond_timedwait.c') + +diff --git a/src/thread/pthread_cond_timedwait.c b/src/thread/pthread_cond_timedwait.c +index d1501240..f5f37af1 100644 +--- a/src/thread/pthread_cond_timedwait.c ++++ b/src/thread/pthread_cond_timedwait.c +@@ -146,14 +146,13 @@ relock: + + if (oldstate == WAITING) goto done; + +- if (!node.next) a_inc(&m->_m_waiters); +- + /* Unlock the barrier that's holding back the next waiter, and + * either wake it or requeue it to the mutex. */ +- if (node.prev) +- unlock_requeue(&node.prev->barrier, &m->_m_lock, m->_m_type & 128); +- else +- a_dec(&m->_m_waiters); ++ if (node.prev) { ++ int val = m->_m_lock; ++ if (val>0) a_cas(&m->_m_lock, val, val|0x80000000); ++ unlock_requeue(&node.prev->barrier, &m->_m_lock, m->_m_type & (8|128)); ++ } + + /* Since a signal was consumed, cancellation is not permitted. */ + if (e == ECANCELED) e = 0; +-- +cgit v1.2.1 + diff --git a/srcpkgs/musl1.1/patches/fix-pi-mutex-cond-2.patch b/srcpkgs/musl1.1/patches/fix-pi-mutex-cond-2.patch new file mode 100644 index 00000000000..b356e38b61f --- /dev/null +++ b/srcpkgs/musl1.1/patches/fix-pi-mutex-cond-2.patch @@ -0,0 +1,48 @@ +From 27b2fc9d6db956359727a66c262f1e69995660aa Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Fri, 30 Oct 2020 11:21:06 -0400 +Subject: fix missing-wake regression in pthread_cond_wait + +the reasoning in commit 2d0bbe6c788938d1332609c014eeebc1dff966ac was +not entirely correct. while it's true that setting the waiters flag +ensures that the next unlock will perform a wake, it's possible that +the wake is consumed by a mutex waiter that has no relationship with +the condvar wait queue being processed, which then takes the mutex. +when that thread subsequently unlocks, it sees no waiters, and leaves +the rest of the condvar queue stuck. + +bring back the waiter count adjustment, but skip it for PI mutexes, +for which a successful lock-after-waiting always sets the waiters bit. +if future changes are made to bring this same waiters-bit contract to +all lock types, this can be reverted. +--- + src/thread/pthread_cond_timedwait.c | 5 +++++ + 1 file changed, 5 insertions(+) + +(limited to 'src/thread/pthread_cond_timedwait.c') + +diff --git a/src/thread/pthread_cond_timedwait.c b/src/thread/pthread_cond_timedwait.c +index f5f37af1..a0cd4904 100644 +--- a/src/thread/pthread_cond_timedwait.c ++++ b/src/thread/pthread_cond_timedwait.c +@@ -146,12 +146,17 @@ relock: + + if (oldstate == WAITING) goto done; + ++ if (!node.next && !(m->_m_type & 8)) ++ a_inc(&m->_m_waiters); ++ + /* Unlock the barrier that's holding back the next waiter, and + * either wake it or requeue it to the mutex. */ + if (node.prev) { + int val = m->_m_lock; + if (val>0) a_cas(&m->_m_lock, val, val|0x80000000); + unlock_requeue(&node.prev->barrier, &m->_m_lock, m->_m_type & (8|128)); ++ } else if (!!(m->_m_type & 8)) { ++ a_dec(&m->_m_waiters); + } + + /* Since a signal was consumed, cancellation is not permitted. */ +-- +cgit v1.2.1 + diff --git a/srcpkgs/musl1.1/patches/fix-pi-mutex-cond-3.patch b/srcpkgs/musl1.1/patches/fix-pi-mutex-cond-3.patch new file mode 100644 index 00000000000..2cc943f26f6 --- /dev/null +++ b/srcpkgs/musl1.1/patches/fix-pi-mutex-cond-3.patch @@ -0,0 +1,28 @@ +From d91a6cf6e369a79587c5665fce9635e5634ca201 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Fri, 30 Oct 2020 16:50:08 -0400 +Subject: fix erroneous pthread_cond_wait mutex waiter count logic due to typo + +introduced in commit 27b2fc9d6db956359727a66c262f1e69995660aa. +--- + src/thread/pthread_cond_timedwait.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +(limited to 'src/thread/pthread_cond_timedwait.c') + +diff --git a/src/thread/pthread_cond_timedwait.c b/src/thread/pthread_cond_timedwait.c +index a0cd4904..6b761455 100644 +--- a/src/thread/pthread_cond_timedwait.c ++++ b/src/thread/pthread_cond_timedwait.c +@@ -155,7 +155,7 @@ relock: + int val = m->_m_lock; + if (val>0) a_cas(&m->_m_lock, val, val|0x80000000); + unlock_requeue(&node.prev->barrier, &m->_m_lock, m->_m_type & (8|128)); +- } else if (!!(m->_m_type & 8)) { ++ } else if (!(m->_m_type & 8)) { + a_dec(&m->_m_waiters); + } + +-- +cgit v1.2.1 + diff --git a/srcpkgs/musl1.1/patches/fix-strverscmp-comparison-of-digit-sequence-with-non.patch.patch b/srcpkgs/musl1.1/patches/fix-strverscmp-comparison-of-digit-sequence-with-non.patch.patch new file mode 100644 index 00000000000..e0f0b8bffff --- /dev/null +++ b/srcpkgs/musl1.1/patches/fix-strverscmp-comparison-of-digit-sequence-with-non.patch.patch @@ -0,0 +1,38 @@ +From b50eb8c36c20f967bd0ed70c0b0db38a450886ba Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Mon, 7 Nov 2022 22:17:55 -0500 +Subject: [PATCH] fix strverscmp comparison of digit sequence with non-digits + +the rule that longest digit sequence not beginning with a zero is +greater only applies when both sequences being compared are +non-degenerate. this is spelled out explicitly in the man page, which +may be deemed authoritative for this nonstandard function: "If one or +both of these is empty, then return what strcmp(3) would have +returned..." + +we were wrongly treating any sequence of digits not beginning with a +zero as greater than a non-digit in the other string. +--- + src/string/strverscmp.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/string/strverscmp.c b/src/string/strverscmp.c +index 4daf276d..16c1da22 100644 +--- a/src/string/strverscmp.c ++++ b/src/string/strverscmp.c +@@ -18,9 +18,9 @@ int strverscmp(const char *l0, const char *r0) + else if (c!='0') z=0; + } + +- if (l[dp]!='0' && r[dp]!='0') { +- /* If we're not looking at a digit sequence that began +- * with a zero, longest digit string is greater. */ ++ if (l[dp]-'1'<9U && r[dp]-'1'<9U) { ++ /* If we're looking at non-degenerate digit sequences starting ++ * with nonzero digits, longest digit string is greater. */ + for (j=i; isdigit(l[j]); j++) + if (!isdigit(r[j])) return 1; + if (isdigit(r[j])) return -1; +-- +2.41.0 + diff --git a/srcpkgs/musl1.1/patches/gettid.patch b/srcpkgs/musl1.1/patches/gettid.patch new file mode 100644 index 00000000000..bb8bf5905b8 --- /dev/null +++ b/srcpkgs/musl1.1/patches/gettid.patch @@ -0,0 +1,49 @@ +From d49cf07541bb54a5ac7aec1feec8514db33db8ea Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Mon, 17 Aug 2020 20:12:53 -0400 +Subject: [PATCH] add gettid function + +this is a prerequisite for addition of other interfaces that use +kernel tids, including futex and SIGEV_THREAD_ID. + +there is some ambiguity as to whether the semantic return type should +be int or pid_t. either way, futex API imposes a contract that the +values fit in int (excluding some upper reserved bits). glibc used +pid_t, so in the interest of not having gratuitous mismatch (the +underlying types are the same anyway), pid_t is used here as well. + +while conceptually this is a syscall, the copy stored in the thread +structure is always valid in all contexts where it's valid to call +libc functions, so it's used to avoid the syscall. +--- + include/unistd.h | 1 + + src/linux/gettid.c | 8 ++++++++ + 2 files changed, 9 insertions(+) + create mode 100644 src/linux/gettid.c + +diff --git a/include/unistd.h b/include/unistd.h +index 7bcbff943..07584a23e 100644 +--- a/include/unistd.h ++++ b/include/unistd.h +@@ -190,6 +190,7 @@ int syncfs(int); + int euidaccess(const char *, int); + int eaccess(const char *, int); + ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned); ++pid_t gettid(void); + #endif + + #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) +diff --git a/src/linux/gettid.c b/src/linux/gettid.c +new file mode 100644 +index 000000000..70767137e +--- /dev/null ++++ b/src/linux/gettid.c +@@ -0,0 +1,8 @@ ++#define _GNU_SOURCE ++#include ++#include "pthread_impl.h" ++ ++pid_t gettid(void) ++{ ++ return __pthread_self()->tid; ++} diff --git a/srcpkgs/musl1.1/patches/iconv_0001-iconv-fix-erroneous-input-validation-in-EUC-KR-decod.patch b/srcpkgs/musl1.1/patches/iconv_0001-iconv-fix-erroneous-input-validation-in-EUC-KR-decod.patch new file mode 100644 index 00000000000..ff92d8ef943 --- /dev/null +++ b/srcpkgs/musl1.1/patches/iconv_0001-iconv-fix-erroneous-input-validation-in-EUC-KR-decod.patch @@ -0,0 +1,38 @@ +From e5adcd97b5196e29991b524237381a0202a60659 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Sun, 9 Feb 2025 10:07:19 -0500 +Subject: [PATCH] iconv: fix erroneous input validation in EUC-KR decoder + +as a result of incorrect bounds checking on the lead byte being +decoded, certain invalid inputs which should produce an encoding +error, such as "\xc8\x41", instead produced out-of-bounds loads from +the ksc table. + +in a worst case, the loaded value may not be a valid unicode scalar +value, in which case, if the output encoding was UTF-8, wctomb would +return (size_t)-1, causing an overflow in the output pointer and +remaining buffer size which could clobber memory outside of the output +buffer. + +bug report was submitted in private by Nick Wellnhofer on account of +potential security implications. +--- + src/locale/iconv.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/locale/iconv.c b/src/locale/iconv.c +index 9605c8e9..008c93f0 100644 +--- a/src/locale/iconv.c ++++ b/src/locale/iconv.c +@@ -502,7 +502,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri + if (c >= 93 || d >= 94) { + c += (0xa1-0x81); + d += 0xa1; +- if (c >= 93 || c>=0xc6-0x81 && d>0x52) ++ if (c > 0xc6-0x81 || c==0xc6-0x81 && d>0x52) + goto ilseq; + if (d-'A'<26) d = d-'A'; + else if (d-'a'<26) d = d-'a'+26; +-- +2.21.0 + diff --git a/srcpkgs/musl1.1/patches/iconv_0002-iconv-harden-UTF-8-output-code-path-against-input-de.patch b/srcpkgs/musl1.1/patches/iconv_0002-iconv-harden-UTF-8-output-code-path-against-input-de.patch new file mode 100644 index 00000000000..d66e66e3f18 --- /dev/null +++ b/srcpkgs/musl1.1/patches/iconv_0002-iconv-harden-UTF-8-output-code-path-against-input-de.patch @@ -0,0 +1,37 @@ +From c47ad25ea3b484e10326f933e927c0bc8cded3da Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Wed, 12 Feb 2025 17:06:30 -0500 +Subject: [PATCH] iconv: harden UTF-8 output code path against input decoder + bugs + +the UTF-8 output code was written assuming an invariant that iconv's +decoders only emit valid Unicode Scalar Values which wctomb can encode +successfully, thereby always returning a value between 1 and 4. + +if this invariant is not satisfied, wctomb returns (size_t)-1, and the +subsequent adjustments to the output buffer pointer and remaining +output byte count overflow, moving the output position backwards, +potentially past the beginning of the buffer, without storing any +bytes. +--- + src/locale/iconv.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/src/locale/iconv.c b/src/locale/iconv.c +index 008c93f0..52178950 100644 +--- a/src/locale/iconv.c ++++ b/src/locale/iconv.c +@@ -545,6 +545,10 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri + if (*outb < k) goto toobig; + memcpy(*out, tmp, k); + } else k = wctomb_utf8(*out, c); ++ /* This failure condition should be unreachable, but ++ * is included to prevent decoder bugs from translating ++ * into advancement outside the output buffer range. */ ++ if (k>4) goto ilseq; + *out += k; + *outb -= k; + break; +-- +2.21.0 + diff --git a/srcpkgs/musl1.1/patches/implement_realpath_directly_instead_of_using_procfs_readlink.patch b/srcpkgs/musl1.1/patches/implement_realpath_directly_instead_of_using_procfs_readlink.patch new file mode 100644 index 00000000000..569a1f52c7c --- /dev/null +++ b/srcpkgs/musl1.1/patches/implement_realpath_directly_instead_of_using_procfs_readlink.patch @@ -0,0 +1,219 @@ +From 29ff7599a448232f2527841c2362643d246cee36 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Mon, 30 Nov 2020 12:14:47 -0500 +Subject: [PATCH] implement realpath directly instead of using procfs readlink + +inability to use realpath in chroot/container without procfs access +and at early boot prior to mount of /proc has been an ongoing issue, +and it turns out realpath was one of the last remaining interfaces +that needed procfs for its core functionality. during investigation +while reimplementing, it was determined that there were also serious +problems with the procfs-based implementation. most seriously it was +unsafe on pre-O_PATH kernels, and unlike other places where O_PATH was +used, the unsafety was hard or impossible to fix because O_NOFOLLOW +can't be used (since the whole purpose was to follow symlinks). + +the new implementation is a direct one, performing readlink on each +path component to resolve it. an explicit stack, as opposed to +recursion, is used to represent the remaining components to be +processed. the stack starts out holding just the input string, and +reading a link pushes the link contents onto the stack. + +unlike many other implementations, this one does not call getcwd +initially for relative pathnames. instead it accumulates initial .. +components to be applied to the working directory if the result is +still a relative path. this avoids calling getcwd (which may fail) at +all when symlink traversal will eventually yield an absolute path. it +also doesn't use any form of stat operation; instead it arranges for +readlink to tell it when a non-directory is used in a context where a +directory is needed. this minimizes the number of syscalls needed, +avoids accessing inodes when the directory table suffices, and reduces +the amount of code pulled in for static linking. +--- + src/misc/realpath.c | 159 +++++++++++++++++++++++++++++++++++++------- + 1 file changed, 136 insertions(+), 23 deletions(-) + +diff --git a/src/misc/realpath.c b/src/misc/realpath.c +index d2708e59d..db8b74dc8 100644 +--- a/src/misc/realpath.c ++++ b/src/misc/realpath.c +@@ -1,43 +1,156 @@ + #include + #include +-#include +-#include + #include + #include + #include +-#include "syscall.h" ++ ++static size_t slash_len(const char *s) ++{ ++ const char *s0 = s; ++ while (*s == '/') s++; ++ return s-s0; ++} + + char *realpath(const char *restrict filename, char *restrict resolved) + { +- int fd; +- ssize_t r; +- struct stat st1, st2; +- char buf[15+3*sizeof(int)]; +- char tmp[PATH_MAX]; ++ char stack[PATH_MAX+1]; ++ char output[PATH_MAX]; ++ size_t p, q, l, l0, cnt=0, nup=0; ++ int check_dir=0; + + if (!filename) { + errno = EINVAL; + return 0; + } ++ l = strnlen(filename, sizeof stack); ++ if (!l) { ++ errno = ENOENT; ++ return 0; ++ } ++ if (l >= PATH_MAX) goto toolong; ++ p = sizeof stack - l - 1; ++ q = 0; ++ memcpy(stack+p, filename, l+1); ++ ++ /* Main loop. Each iteration pops the next part from stack of ++ * remaining path components and consumes any slashes that follow. ++ * If not a link, it's moved to output; if a link, contents are ++ * pushed to the stack. */ ++restart: ++ for (; ; p+=slash_len(stack+p)) { ++ /* If stack starts with /, the whole component is / or // ++ * and the output state must be reset. */ ++ if (stack[p] == '/') { ++ check_dir=0; ++ nup=0; ++ q=0; ++ output[q++] = '/'; ++ p++; ++ /* Initial // is special. */ ++ if (stack[p] == '/' && stack[p+1] != '/') ++ output[q++] = '/'; ++ continue; ++ } ++ ++ char *z = __strchrnul(stack+p, '/'); ++ l0 = l = z-(stack+p); + +- fd = sys_open(filename, O_PATH|O_NONBLOCK|O_CLOEXEC); +- if (fd < 0) return 0; +- __procfdname(buf, fd); ++ if (!l && !check_dir) break; + +- r = readlink(buf, tmp, sizeof tmp - 1); +- if (r < 0) goto err; +- tmp[r] = 0; ++ /* Skip any . component but preserve check_dir status. */ ++ if (l==1 && stack[p]=='.') { ++ p += l; ++ continue; ++ } + +- fstat(fd, &st1); +- r = stat(tmp, &st2); +- if (r<0 || st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) { +- if (!r) errno = ELOOP; +- goto err; ++ /* Copy next component onto output at least temporarily, to ++ * call readlink, but wait to advance output position until ++ * determining it's not a link. */ ++ if (q && output[q-1] != '/') { ++ if (!p) goto toolong; ++ stack[--p] = '/'; ++ l++; ++ } ++ if (q+l >= PATH_MAX) goto toolong; ++ memcpy(output+q, stack+p, l); ++ output[q+l] = 0; ++ p += l; ++ ++ int up = 0; ++ if (l0==2 && stack[p-2]=='.' && stack[p-1]=='.') { ++ up = 1; ++ /* Any non-.. path components we could cancel start ++ * after nup repetitions of the 3-byte string "../"; ++ * if there are none, accumulate .. components to ++ * later apply to cwd, if needed. */ ++ if (q <= 3*nup) { ++ nup++; ++ q += l; ++ continue; ++ } ++ /* When previous components are already known to be ++ * directories, processing .. can skip readlink. */ ++ if (!check_dir) goto skip_readlink; ++ } ++ ssize_t k = readlink(output, stack, p); ++ if (k==p) goto toolong; ++ if (!k) { ++ errno = ENOENT; ++ return 0; ++ } ++ if (k<0) { ++ if (errno != EINVAL) return 0; ++skip_readlink: ++ check_dir = 0; ++ if (up) { ++ while(q && output[q-1]!='/') q--; ++ if (q>1 && (q>2 || output[0]!='/')) q--; ++ continue; ++ } ++ if (l0) q += l; ++ check_dir = stack[p]; ++ continue; ++ } ++ if (++cnt == SYMLOOP_MAX) { ++ errno = ELOOP; ++ return 0; ++ } ++ ++ /* If link contents end in /, strip any slashes already on ++ * stack to avoid /->// or //->/// or spurious toolong. */ ++ if (stack[k-1]=='/') while (stack[p]=='/') p++; ++ p -= k; ++ memmove(stack+p, stack, k); ++ ++ /* Skip the stack advancement in case we have a new ++ * absolute base path. */ ++ goto restart; + } + +- __syscall(SYS_close, fd); +- return resolved ? strcpy(resolved, tmp) : strdup(tmp); +-err: +- __syscall(SYS_close, fd); ++ output[q] = 0; ++ ++ if (output[0] != '/') { ++ if (!getcwd(stack, sizeof stack)) return 0; ++ l = strlen(stack); ++ /* Cancel any initial .. components. */ ++ p = 0; ++ while (nup--) { ++ while(l>1 && stack[l-1]!='/') l--; ++ if (l>1) l--; ++ p += 2; ++ if (p= PATH_MAX) goto toolong; ++ memmove(output + l, output + p, q - p + 1); ++ memcpy(output, stack, l); ++ q = l + q-p; ++ } ++ ++ if (resolved) return memcpy(resolved, output, q+1); ++ else return strdup(output); ++ ++toolong: ++ errno = ENAMETOOLONG; + return 0; + } diff --git a/srcpkgs/musl1.1/patches/isascii.patch b/srcpkgs/musl1.1/patches/isascii.patch new file mode 100644 index 00000000000..6719d2ee188 --- /dev/null +++ b/srcpkgs/musl1.1/patches/isascii.patch @@ -0,0 +1,21 @@ +From e48e99c112246fb580596404074445cb25d7858d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=89rico=20Rolim?= +Date: Mon, 4 Jan 2021 22:48:34 -0300 +Subject: [PATCH] suppress isascii() macro for C++ + +analogous to commit a60457c84a4b59ab564d7f4abb660a70283ba98d. + +diff --git include/ctype.h include/ctype.h +index 7936536f..32bcef4d 100644 +--- a/include/ctype.h ++++ b/include/ctype.h +@@ -64,7 +64,9 @@ int isascii(int); + int toascii(int); + #define _tolower(a) ((a)|0x20) + #define _toupper(a) ((a)&0x5f) ++#ifndef __cplusplus + #define isascii(a) (0 ? isascii(a) : (unsigned)(a) < 128) ++#endif + + #endif + diff --git a/srcpkgs/musl1.1/patches/mo_lookup.patch b/srcpkgs/musl1.1/patches/mo_lookup.patch new file mode 100644 index 00000000000..ae86e33c9c7 --- /dev/null +++ b/srcpkgs/musl1.1/patches/mo_lookup.patch @@ -0,0 +1,19 @@ +Do not crash with a NULL pointer dereference when dcngettext() +is called with NULL msgid[12] arguments. + +Fix for https://github.com/void-linux/void-packages/issues/12042 +and probably others. + + --xtraeme + +--- a/src/locale/__mo_lookup.c.orig 2019-06-26 09:55:36.843012674 +0200 ++++ b/src/locale/__mo_lookup.c 2019-06-26 09:56:11.529443955 +0200 +@@ -13,7 +13,7 @@ const char *__mo_lookup(const void *p, s + uint32_t b = 0, n = swapc(mo[2], sw); + uint32_t o = swapc(mo[3], sw); + uint32_t t = swapc(mo[4], sw); +- if (n>=size/4 || o>=size-4*n || t>=size-4*n || ((o|t)%4)) ++ if (!s || n>=size/4 || o>=size-4*n || t>=size-4*n || ((o|t)%4)) + return 0; + o/=4; + t/=4; diff --git a/srcpkgs/musl1.1/patches/new-syscalls.patch b/srcpkgs/musl1.1/patches/new-syscalls.patch new file mode 100644 index 00000000000..a4ff78c8965 --- /dev/null +++ b/srcpkgs/musl1.1/patches/new-syscalls.patch @@ -0,0 +1,394 @@ +--- a/arch/aarch64/bits/syscall.h.in ++++ b/arch/aarch64/bits/syscall.h.in +@@ -287,4 +287,21 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + +--- a/arch/arm/bits/syscall.h.in ++++ b/arch/arm/bits/syscall.h.in +@@ -387,6 +387,23 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + + #define __ARM_NR_breakpoint 0x0f0001 + #define __ARM_NR_cacheflush 0x0f0002 +--- a/arch/i386/bits/syscall.h.in ++++ b/arch/i386/bits/syscall.h.in +@@ -424,4 +424,22 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_memfd_secret 447 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + +--- a/arch/m68k/bits/syscall.h.in ++++ b/arch/m68k/bits/syscall.h.in +@@ -404,3 +404,21 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 ++ +--- a/arch/microblaze/bits/syscall.h.in ++++ b/arch/microblaze/bits/syscall.h.in +@@ -425,4 +425,21 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + +--- a/arch/mips/bits/syscall.h.in ++++ b/arch/mips/bits/syscall.h.in +@@ -406,4 +406,21 @@ + #define __NR_fsconfig 4431 + #define __NR_fsmount 4432 + #define __NR_fspick 4433 ++#define __NR_pidfd_open 4434 ++#define __NR_clone3 4435 ++#define __NR_close_range 4436 ++#define __NR_openat2 4437 ++#define __NR_pidfd_getfd 4438 ++#define __NR_faccessat2 4439 ++#define __NR_process_madvise 4440 ++#define __NR_epoll_pwait2 4441 ++#define __NR_mount_setattr 4442 ++#define __NR_landlock_create_ruleset 4444 ++#define __NR_landlock_add_rule 4445 ++#define __NR_landlock_restrict_self 4446 ++#define __NR_process_mrelease 4448 ++#define __NR_futex_waitv 4449 ++#define __NR_set_mempolicy_home_node 4450 ++#define __NR_cachestat 4451 ++#define __NR_fchmodat2 4452 + +--- a/arch/mips64/bits/syscall.h.in ++++ b/arch/mips64/bits/syscall.h.in +@@ -336,4 +336,21 @@ + #define __NR_fsconfig 5431 + #define __NR_fsmount 5432 + #define __NR_fspick 5433 ++#define __NR_pidfd_open 5434 ++#define __NR_clone3 5435 ++#define __NR_close_range 5436 ++#define __NR_openat2 5437 ++#define __NR_pidfd_getfd 5438 ++#define __NR_faccessat2 5439 ++#define __NR_process_madvise 5440 ++#define __NR_epoll_pwait2 5441 ++#define __NR_mount_setattr 5442 ++#define __NR_landlock_create_ruleset 5444 ++#define __NR_landlock_add_rule 5445 ++#define __NR_landlock_restrict_self 5446 ++#define __NR_process_mrelease 5448 ++#define __NR_futex_waitv 5449 ++#define __NR_set_mempolicy_home_node 5450 ++#define __NR_cachestat 5451 ++#define __NR_fchmodat2 5452 + +--- a/arch/mipsn32/bits/syscall.h.in ++++ b/arch/mipsn32/bits/syscall.h.in +@@ -360,4 +360,21 @@ + #define __NR_fsconfig 6431 + #define __NR_fsmount 6432 + #define __NR_fspick 6433 ++#define __NR_pidfd_open 6434 ++#define __NR_clone3 6435 ++#define __NR_close_range 6436 ++#define __NR_openat2 6437 ++#define __NR_pidfd_getfd 6438 ++#define __NR_faccessat2 6439 ++#define __NR_process_madvise 6440 ++#define __NR_epoll_pwait2 6441 ++#define __NR_mount_setattr 6442 ++#define __NR_landlock_create_ruleset 6444 ++#define __NR_landlock_add_rule 6445 ++#define __NR_landlock_restrict_self 6446 ++#define __NR_process_mrelease 6448 ++#define __NR_futex_waitv 6449 ++#define __NR_set_mempolicy_home_node 6450 ++#define __NR_cachestat 6451 ++#define __NR_fchmodat2 6452 + +--- a/arch/or1k/bits/syscall.h.in ++++ b/arch/or1k/bits/syscall.h.in +@@ -309,4 +309,21 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + +--- a/arch/powerpc64/bits/syscall.h.in ++++ b/arch/powerpc64/bits/syscall.h.in +@@ -385,4 +385,21 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + +--- a/arch/powerpc/bits/syscall.h.in ++++ b/arch/powerpc/bits/syscall.h.in +@@ -413,4 +413,21 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + +--- a/arch/riscv64/bits/syscall.h.in ++++ b/arch/riscv64/bits/syscall.h.in +@@ -287,6 +287,23 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + + #define __NR_sysriscv __NR_arch_specific_syscall + #define __NR_riscv_flush_icache (__NR_sysriscv + 15) +--- a/arch/s390x/bits/syscall.h.in ++++ b/arch/s390x/bits/syscall.h.in +@@ -350,4 +350,22 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_memfd_secret 447 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + +--- a/arch/sh/bits/syscall.h.in ++++ b/arch/sh/bits/syscall.h.in +@@ -397,4 +397,21 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + +--- a/arch/x32/bits/syscall.h.in ++++ b/arch/x32/bits/syscall.h.in +@@ -296,6 +296,24 @@ + #define __NR_fsconfig (0x40000000 + 431) + #define __NR_fsmount (0x40000000 + 432) + #define __NR_fspick (0x40000000 + 433) ++#define __NR_pidfd_open (0x40000000 + 434) ++#define __NR_clone3 (0x40000000 + 435) ++#define __NR_close_range (0x40000000 + 436) ++#define __NR_openat2 (0x40000000 + 437) ++#define __NR_pidfd_getfd (0x40000000 + 438) ++#define __NR_faccessat2 (0x40000000 + 439) ++#define __NR_process_madvise (0x40000000 + 440) ++#define __NR_epoll_pwait2 (0x40000000 + 441) ++#define __NR_mount_setattr (0x40000000 + 442) ++#define __NR_landlock_create_ruleset (0x40000000 + 444) ++#define __NR_landlock_add_rule (0x40000000 + 445) ++#define __NR_landlock_restrict_self (0x40000000 + 446) ++#define __NR_memfd_secret (0x40000000 + 447) ++#define __NR_process_mrelease (0x40000000 + 448) ++#define __NR_futex_waitv (0x40000000 + 449) ++#define __NR_set_mempolicy_home_node (0x40000000 + 450) ++#define __NR_cachestat (0x40000000 + 451) ++#define __NR_fchmodat2 (0x40000000 + 452) + + #define __NR_rt_sigaction (0x40000000 + 512) + #define __NR_rt_sigreturn (0x40000000 + 513) +--- a/arch/x86_64/bits/syscall.h.in ++++ b/arch/x86_64/bits/syscall.h.in +@@ -343,4 +343,22 @@ + #define __NR_fsconfig 431 + #define __NR_fsmount 432 + #define __NR_fspick 433 ++#define __NR_pidfd_open 434 ++#define __NR_clone3 435 ++#define __NR_close_range 436 ++#define __NR_openat2 437 ++#define __NR_pidfd_getfd 438 ++#define __NR_faccessat2 439 ++#define __NR_process_madvise 440 ++#define __NR_epoll_pwait2 441 ++#define __NR_mount_setattr 442 ++#define __NR_landlock_create_ruleset 444 ++#define __NR_landlock_add_rule 445 ++#define __NR_landlock_restrict_self 446 ++#define __NR_memfd_secret 447 ++#define __NR_process_mrelease 448 ++#define __NR_futex_waitv 449 ++#define __NR_set_mempolicy_home_node 450 ++#define __NR_cachestat 451 ++#define __NR_fchmodat2 452 + diff --git a/srcpkgs/musl1.1/patches/ppc-pt_regs.patch b/srcpkgs/musl1.1/patches/ppc-pt_regs.patch new file mode 100644 index 00000000000..45815321bf0 --- /dev/null +++ b/srcpkgs/musl1.1/patches/ppc-pt_regs.patch @@ -0,0 +1,38 @@ +commit c2518a8efb6507f1b41c3b12e03b06f8f2317a1f +Author: Rich Felker +Date: Sat Oct 19 15:53:43 2019 -0400 + + use struct pt_regs * rather than void * for powerpc[64] sigcontext regs + + this is to match the kernel and glibc interfaces. here, struct pt_regs + is an incomplete type, but that's harmless, and if it's completed by + inclusion of another header then members of the struct pointed to by + the regs member can be accessed directly without going through a cast + or intermediate pointer object. + +diff --git a/arch/powerpc/bits/signal.h b/arch/powerpc/bits/signal.h +index 06efb11c..c1bf3caf 100644 +--- a/arch/powerpc/bits/signal.h ++++ b/arch/powerpc/bits/signal.h +@@ -28,7 +28,7 @@ struct sigcontext { + int signal; + unsigned long handler; + unsigned long oldmask; +- void *regs; ++ struct pt_regs *regs; + }; + + typedef struct { +diff --git a/arch/powerpc64/bits/signal.h b/arch/powerpc64/bits/signal.h +index 4dec22a5..d5493b18 100644 +--- a/arch/powerpc64/bits/signal.h ++++ b/arch/powerpc64/bits/signal.h +@@ -32,7 +32,7 @@ typedef struct sigcontext { + int _pad0; + unsigned long handler; + unsigned long oldmask; +- void *regs; ++ struct pt_regs *regs; + gregset_t gp_regs; + fpregset_t fp_regs; + vrregset_t *v_regs; diff --git a/srcpkgs/musl1.1/patches/ppc64-fpregset_t.patch b/srcpkgs/musl1.1/patches/ppc64-fpregset_t.patch new file mode 100644 index 00000000000..12617ba0ef7 --- /dev/null +++ b/srcpkgs/musl1.1/patches/ppc64-fpregset_t.patch @@ -0,0 +1,31 @@ +commit c9f48cde0a22641ce3daf54596a9ecebdab91435 +Author: Rich Felker +Date: Sat Oct 19 15:39:45 2019 -0400 + + fix fpregset_t type on powerpc64 + + the userspace ucontext API has this as an array rather than a + structure. + + commit 3c59a868956636bc8adafb1b168d090897692532 fixed the + corresponding mistake for vrregset_t, namely that the original + powerpc64 port used a mix of types from 32-bit powerpc and powerpc64 + rather than matching the 64-bit types. + +diff --git a/arch/powerpc64/bits/signal.h b/arch/powerpc64/bits/signal.h +index 2cc0604c..4dec22a5 100644 +--- a/arch/powerpc64/bits/signal.h ++++ b/arch/powerpc64/bits/signal.h +@@ -9,11 +9,7 @@ + #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) + + typedef unsigned long greg_t, gregset_t[48]; +- +-typedef struct { +- double fpregs[32]; +- double fpscr; +-} fpregset_t; ++typedef double fpregset_t[33]; + + typedef struct { + #ifdef __GNUC__ diff --git a/srcpkgs/musl1.1/patches/ppcle.patch b/srcpkgs/musl1.1/patches/ppcle.patch new file mode 100644 index 00000000000..7d49338a5a0 --- /dev/null +++ b/srcpkgs/musl1.1/patches/ppcle.patch @@ -0,0 +1,24 @@ +From 20dfc2002482a21b955b710af119a01aecee784b Mon Sep 17 00:00:00 2001 +From: Daniel Kolesa +Date: Tue, 15 Dec 2020 20:42:17 +0100 +Subject: [PATCH] add ppc32 le subarch + +--- + configure | 1 + + 1 file changed, 1 insertion(+) + +diff --git configure configure +index 8680128..f1ca58e 100755 +--- a/configure ++++ b/configure +@@ -645,6 +645,7 @@ fi + if test "$ARCH" = "powerpc" ; then + trycppif "__NO_FPRS__ && !_SOFT_FLOAT" "$t" && fail \ + "$0: error: compiler's floating point configuration is unsupported" ++trycppif __LITTLE_ENDIAN__ "$t" && SUBARCH=${SUBARCH}le + trycppif _SOFT_FLOAT "$t" && SUBARCH=${SUBARCH}-sf + fi + +-- +2.29.2 + diff --git a/srcpkgs/musl1.1/patches/pthread_0001-deduplicate-TP_ADJ-logic-out-of-each-arch-replace-wi.patch b/srcpkgs/musl1.1/patches/pthread_0001-deduplicate-TP_ADJ-logic-out-of-each-arch-replace-wi.patch new file mode 100644 index 00000000000..61f5e8482d8 --- /dev/null +++ b/srcpkgs/musl1.1/patches/pthread_0001-deduplicate-TP_ADJ-logic-out-of-each-arch-replace-wi.patch @@ -0,0 +1,255 @@ +From ea71a9004e08030a15d45186e263fd2b0c51cc25 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Mon, 24 Aug 2020 22:04:52 -0400 +Subject: [PATCH 3/5] deduplicate TP_ADJ logic out of each arch, replace with + TP_OFFSET + +the only part of TP_ADJ that was not uniquely determined by +TLS_ABOVE_TP was the 0x7000 adjustment used mainly on mips and powerpc +variants. +--- + arch/aarch64/pthread_arch.h | 1 - + arch/arm/pthread_arch.h | 1 - + arch/i386/pthread_arch.h | 2 -- + arch/m68k/pthread_arch.h | 2 +- + arch/microblaze/pthread_arch.h | 2 -- + arch/mips/pthread_arch.h | 2 +- + arch/mips64/pthread_arch.h | 2 +- + arch/mipsn32/pthread_arch.h | 2 +- + arch/or1k/pthread_arch.h | 1 - + arch/powerpc/pthread_arch.h | 2 +- + arch/powerpc64/pthread_arch.h | 2 +- + arch/riscv64/pthread_arch.h | 1 - + arch/s390x/pthread_arch.h | 2 -- + arch/sh/pthread_arch.h | 1 - + arch/x32/pthread_arch.h | 2 -- + arch/x86_64/pthread_arch.h | 2 -- + src/internal/pthread_impl.h | 10 ++++++++++ + 17 files changed, 16 insertions(+), 21 deletions(-) + +diff --git a/arch/aarch64/pthread_arch.h b/arch/aarch64/pthread_arch.h +index e64b126d..f3c005c7 100644 +--- a/arch/aarch64/pthread_arch.h ++++ b/arch/aarch64/pthread_arch.h +@@ -7,6 +7,5 @@ static inline struct pthread *__pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 16 +-#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread)) + + #define MC_PC pc +diff --git a/arch/arm/pthread_arch.h b/arch/arm/pthread_arch.h +index e689ea21..48640985 100644 +--- a/arch/arm/pthread_arch.h ++++ b/arch/arm/pthread_arch.h +@@ -28,6 +28,5 @@ static inline pthread_t __pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 8 +-#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread)) + + #define MC_PC arm_pc +diff --git a/arch/i386/pthread_arch.h b/arch/i386/pthread_arch.h +index 6f600b9e..32570a17 100644 +--- a/arch/i386/pthread_arch.h ++++ b/arch/i386/pthread_arch.h +@@ -5,6 +5,4 @@ static inline struct pthread *__pthread_self() + return self; + } + +-#define TP_ADJ(p) (p) +- + #define MC_PC gregs[REG_EIP] +diff --git a/arch/m68k/pthread_arch.h b/arch/m68k/pthread_arch.h +index 02d5b8a0..7c9990c2 100644 +--- a/arch/m68k/pthread_arch.h ++++ b/arch/m68k/pthread_arch.h +@@ -6,8 +6,8 @@ static inline struct pthread *__pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 0 +-#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) + ++#define TP_OFFSET 0x7000 + #define DTP_OFFSET 0x8000 + + #define MC_PC gregs[R_PC] +diff --git a/arch/microblaze/pthread_arch.h b/arch/microblaze/pthread_arch.h +index f6ba8de9..c327f4eb 100644 +--- a/arch/microblaze/pthread_arch.h ++++ b/arch/microblaze/pthread_arch.h +@@ -5,6 +5,4 @@ static inline struct pthread *__pthread_self() + return self; + } + +-#define TP_ADJ(p) (p) +- + #define MC_PC regs.pc +diff --git a/arch/mips/pthread_arch.h b/arch/mips/pthread_arch.h +index 1e7839ea..c22eb34d 100644 +--- a/arch/mips/pthread_arch.h ++++ b/arch/mips/pthread_arch.h +@@ -12,8 +12,8 @@ static inline struct pthread *__pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 0 +-#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) + ++#define TP_OFFSET 0x7000 + #define DTP_OFFSET 0x8000 + + #define MC_PC pc +diff --git a/arch/mips64/pthread_arch.h b/arch/mips64/pthread_arch.h +index 1e7839ea..c22eb34d 100644 +--- a/arch/mips64/pthread_arch.h ++++ b/arch/mips64/pthread_arch.h +@@ -12,8 +12,8 @@ static inline struct pthread *__pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 0 +-#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) + ++#define TP_OFFSET 0x7000 + #define DTP_OFFSET 0x8000 + + #define MC_PC pc +diff --git a/arch/mipsn32/pthread_arch.h b/arch/mipsn32/pthread_arch.h +index 1e7839ea..c22eb34d 100644 +--- a/arch/mipsn32/pthread_arch.h ++++ b/arch/mipsn32/pthread_arch.h +@@ -12,8 +12,8 @@ static inline struct pthread *__pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 0 +-#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) + ++#define TP_OFFSET 0x7000 + #define DTP_OFFSET 0x8000 + + #define MC_PC pc +diff --git a/arch/or1k/pthread_arch.h b/arch/or1k/pthread_arch.h +index 1b806f89..76d0a8bc 100644 +--- a/arch/or1k/pthread_arch.h ++++ b/arch/or1k/pthread_arch.h +@@ -13,6 +13,5 @@ static inline struct pthread *__pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 0 +-#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread)) + + #define MC_PC regs.pc +diff --git a/arch/powerpc/pthread_arch.h b/arch/powerpc/pthread_arch.h +index ae0f28d6..9697046b 100644 +--- a/arch/powerpc/pthread_arch.h ++++ b/arch/powerpc/pthread_arch.h +@@ -7,8 +7,8 @@ static inline struct pthread *__pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 0 +-#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) + ++#define TP_OFFSET 0x7000 + #define DTP_OFFSET 0x8000 + + // the kernel calls the ip "nip", it's the first saved value after the 32 +diff --git a/arch/powerpc64/pthread_arch.h b/arch/powerpc64/pthread_arch.h +index 79c3ecd8..e9dba43f 100644 +--- a/arch/powerpc64/pthread_arch.h ++++ b/arch/powerpc64/pthread_arch.h +@@ -7,8 +7,8 @@ static inline struct pthread *__pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 0 +-#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) + ++#define TP_OFFSET 0x7000 + #define DTP_OFFSET 0x8000 + + // the kernel calls the ip "nip", it's the first saved value after the 32 +diff --git a/arch/riscv64/pthread_arch.h b/arch/riscv64/pthread_arch.h +index db414b17..50f0868d 100644 +--- a/arch/riscv64/pthread_arch.h ++++ b/arch/riscv64/pthread_arch.h +@@ -7,7 +7,6 @@ static inline struct pthread *__pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 0 +-#define TP_ADJ(p) ((char *)p + sizeof(struct pthread)) + + #define DTP_OFFSET 0x800 + +diff --git a/arch/s390x/pthread_arch.h b/arch/s390x/pthread_arch.h +index e2251f1f..5d22546b 100644 +--- a/arch/s390x/pthread_arch.h ++++ b/arch/s390x/pthread_arch.h +@@ -9,6 +9,4 @@ static inline struct pthread *__pthread_self() + return self; + } + +-#define TP_ADJ(p) (p) +- + #define MC_PC psw.addr +diff --git a/arch/sh/pthread_arch.h b/arch/sh/pthread_arch.h +index 3ee9c1a9..c2252908 100644 +--- a/arch/sh/pthread_arch.h ++++ b/arch/sh/pthread_arch.h +@@ -7,7 +7,6 @@ static inline struct pthread *__pthread_self() + + #define TLS_ABOVE_TP + #define GAP_ABOVE_TP 8 +-#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread)) + + #define MC_PC sc_pc + +diff --git a/arch/x32/pthread_arch.h b/arch/x32/pthread_arch.h +index f640a1a1..fa452839 100644 +--- a/arch/x32/pthread_arch.h ++++ b/arch/x32/pthread_arch.h +@@ -5,8 +5,6 @@ static inline struct pthread *__pthread_self() + return self; + } + +-#define TP_ADJ(p) (p) +- + #define MC_PC gregs[REG_RIP] + + #define CANARY canary2 +diff --git a/arch/x86_64/pthread_arch.h b/arch/x86_64/pthread_arch.h +index 65e880c6..1c64a840 100644 +--- a/arch/x86_64/pthread_arch.h ++++ b/arch/x86_64/pthread_arch.h +@@ -5,6 +5,4 @@ static inline struct pthread *__pthread_self() + return self; + } + +-#define TP_ADJ(p) (p) +- + #define MC_PC gregs[REG_RIP] +diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h +index 5749a336..3c2bd767 100644 +--- a/src/internal/pthread_impl.h ++++ b/src/internal/pthread_impl.h +@@ -105,10 +105,20 @@ struct __timer { + #define CANARY canary + #endif + ++#ifndef TP_OFFSET ++#define TP_OFFSET 0 ++#endif ++ + #ifndef DTP_OFFSET + #define DTP_OFFSET 0 + #endif + ++#ifdef TLS_ABOVE_TP ++#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + TP_OFFSET) ++#else ++#define TP_ADJ(p) (p) ++#endif ++ + #ifndef tls_mod_off_t + #define tls_mod_off_t size_t + #endif +-- +2.47.0 + diff --git a/srcpkgs/musl1.1/patches/pthread_0002-deduplicate-__pthread_self-thread-pointer-adjustment.patch b/srcpkgs/musl1.1/patches/pthread_0002-deduplicate-__pthread_self-thread-pointer-adjustment.patch new file mode 100644 index 00000000000..cdc62a054db --- /dev/null +++ b/srcpkgs/musl1.1/patches/pthread_0002-deduplicate-__pthread_self-thread-pointer-adjustment.patch @@ -0,0 +1,368 @@ +From 3a5b9ae7cf656648c80fe155a5239d9b4fb4c485 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Mon, 24 Aug 2020 22:23:08 -0400 +Subject: [PATCH 1/2] deduplicate __pthread_self thread pointer adjustment out + of each arch + +the adjustment made is entirely a function of TLS_ABOVE_TP and +TP_OFFSET. aside from avoiding repetition of the TP_OFFSET value and +arithmetic, this change makes pthread_arch.h independent of the +definition of struct __pthread from pthread_impl.h. this in turn will +allow inclusion of pthread_arch.h to be moved to the top of +pthread_impl.h so that it can influence the definition of the +structure. + +previously, arch files were very inconsistent about the type used for +the thread pointer. this change unifies the new __get_tp interface to +always use uintptr_t, which is the most correct when performing +arithmetic that may involve addresses outside the actual pointed-to +object (due to TP_OFFSET). +--- + arch/aarch64/pthread_arch.h | 8 ++++---- + arch/arm/pthread_arch.h | 16 ++++++++-------- + arch/i386/pthread_arch.h | 8 ++++---- + arch/m68k/pthread_arch.h | 5 ++--- + arch/microblaze/pthread_arch.h | 8 ++++---- + arch/mips/pthread_arch.h | 8 ++++---- + arch/mips64/pthread_arch.h | 8 ++++---- + arch/mipsn32/pthread_arch.h | 8 ++++---- + arch/or1k/pthread_arch.h | 9 ++++----- + arch/powerpc/pthread_arch.h | 6 +++--- + arch/powerpc64/pthread_arch.h | 6 +++--- + arch/riscv64/pthread_arch.h | 6 +++--- + arch/s390x/pthread_arch.h | 8 ++++---- + arch/sh/pthread_arch.h | 8 ++++---- + arch/x32/pthread_arch.h | 8 ++++---- + arch/x86_64/pthread_arch.h | 8 ++++---- + src/internal/pthread_impl.h | 2 ++ + 17 files changed, 65 insertions(+), 65 deletions(-) + +diff --git a/arch/aarch64/pthread_arch.h b/arch/aarch64/pthread_arch.h +index f3c005c7..3909616c 100644 +--- a/arch/aarch64/pthread_arch.h ++++ b/arch/aarch64/pthread_arch.h +@@ -1,8 +1,8 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- char *self; +- __asm__ ("mrs %0,tpidr_el0" : "=r"(self)); +- return (void*)(self - sizeof(struct pthread)); ++ uintptr_t tp; ++ __asm__ ("mrs %0,tpidr_el0" : "=r"(tp)); ++ return tp; + } + + #define TLS_ABOVE_TP +diff --git a/arch/arm/pthread_arch.h b/arch/arm/pthread_arch.h +index 48640985..157e2eae 100644 +--- a/arch/arm/pthread_arch.h ++++ b/arch/arm/pthread_arch.h +@@ -1,11 +1,11 @@ + #if ((__ARM_ARCH_6K__ || __ARM_ARCH_6KZ__ || __ARM_ARCH_6ZK__) && !__thumb__) \ + || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 + +-static inline pthread_t __pthread_self() ++static inline uintptr_t __get_tp() + { +- char *p; +- __asm__ ( "mrc p15,0,%0,c13,c0,3" : "=r"(p) ); +- return (void *)(p-sizeof(struct pthread)); ++ uintptr_t tp; ++ __asm__ ( "mrc p15,0,%0,c13,c0,3" : "=r"(tp) ); ++ return tp; + } + + #else +@@ -16,12 +16,12 @@ static inline pthread_t __pthread_self() + #define BLX "blx" + #endif + +-static inline pthread_t __pthread_self() ++static inline uintptr_t __get_tp() + { + extern hidden uintptr_t __a_gettp_ptr; +- register uintptr_t p __asm__("r0"); +- __asm__ ( BLX " %1" : "=r"(p) : "r"(__a_gettp_ptr) : "cc", "lr" ); +- return (void *)(p-sizeof(struct pthread)); ++ register uintptr_t tp __asm__("r0"); ++ __asm__ ( BLX " %1" : "=r"(tp) : "r"(__a_gettp_ptr) : "cc", "lr" ); ++ return tp; + } + + #endif +diff --git a/arch/i386/pthread_arch.h b/arch/i386/pthread_arch.h +index 32570a17..a639c382 100644 +--- a/arch/i386/pthread_arch.h ++++ b/arch/i386/pthread_arch.h +@@ -1,8 +1,8 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- struct pthread *self; +- __asm__ ("movl %%gs:0,%0" : "=r" (self) ); +- return self; ++ uintptr_t tp; ++ __asm__ ("movl %%gs:0,%0" : "=r" (tp) ); ++ return tp; + } + + #define MC_PC gregs[REG_EIP] +diff --git a/arch/m68k/pthread_arch.h b/arch/m68k/pthread_arch.h +index 7c9990c2..5bea4e1a 100644 +--- a/arch/m68k/pthread_arch.h ++++ b/arch/m68k/pthread_arch.h +@@ -1,7 +1,6 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- uintptr_t tp = __syscall(SYS_get_thread_area); +- return (pthread_t)(tp - 0x7000 - sizeof(struct pthread)); ++ return __syscall(SYS_get_thread_area); + } + + #define TLS_ABOVE_TP +diff --git a/arch/microblaze/pthread_arch.h b/arch/microblaze/pthread_arch.h +index c327f4eb..ff26624e 100644 +--- a/arch/microblaze/pthread_arch.h ++++ b/arch/microblaze/pthread_arch.h +@@ -1,8 +1,8 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- struct pthread *self; +- __asm__ ("ori %0, r21, 0" : "=r" (self) ); +- return self; ++ uintptr_t tp; ++ __asm__ ("ori %0, r21, 0" : "=r" (tp) ); ++ return tp; + } + + #define MC_PC regs.pc +diff --git a/arch/mips/pthread_arch.h b/arch/mips/pthread_arch.h +index c22eb34d..c45347ab 100644 +--- a/arch/mips/pthread_arch.h ++++ b/arch/mips/pthread_arch.h +@@ -1,13 +1,13 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { + #if __mips_isa_rev < 2 +- register char *tp __asm__("$3"); ++ register uintptr_t tp __asm__("$3"); + __asm__ (".word 0x7c03e83b" : "=r" (tp) ); + #else +- char *tp; ++ uintptr_t tp; + __asm__ ("rdhwr %0, $29" : "=r" (tp) ); + #endif +- return (pthread_t)(tp - 0x7000 - sizeof(struct pthread)); ++ return tp; + } + + #define TLS_ABOVE_TP +diff --git a/arch/mips64/pthread_arch.h b/arch/mips64/pthread_arch.h +index c22eb34d..c45347ab 100644 +--- a/arch/mips64/pthread_arch.h ++++ b/arch/mips64/pthread_arch.h +@@ -1,13 +1,13 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { + #if __mips_isa_rev < 2 +- register char *tp __asm__("$3"); ++ register uintptr_t tp __asm__("$3"); + __asm__ (".word 0x7c03e83b" : "=r" (tp) ); + #else +- char *tp; ++ uintptr_t tp; + __asm__ ("rdhwr %0, $29" : "=r" (tp) ); + #endif +- return (pthread_t)(tp - 0x7000 - sizeof(struct pthread)); ++ return tp; + } + + #define TLS_ABOVE_TP +diff --git a/arch/mipsn32/pthread_arch.h b/arch/mipsn32/pthread_arch.h +index c22eb34d..c45347ab 100644 +--- a/arch/mipsn32/pthread_arch.h ++++ b/arch/mipsn32/pthread_arch.h +@@ -1,13 +1,13 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { + #if __mips_isa_rev < 2 +- register char *tp __asm__("$3"); ++ register uintptr_t tp __asm__("$3"); + __asm__ (".word 0x7c03e83b" : "=r" (tp) ); + #else +- char *tp; ++ uintptr_t tp; + __asm__ ("rdhwr %0, $29" : "=r" (tp) ); + #endif +- return (pthread_t)(tp - 0x7000 - sizeof(struct pthread)); ++ return tp; + } + + #define TLS_ABOVE_TP +diff --git a/arch/or1k/pthread_arch.h b/arch/or1k/pthread_arch.h +index 76d0a8bc..f75ea7e4 100644 +--- a/arch/or1k/pthread_arch.h ++++ b/arch/or1k/pthread_arch.h +@@ -1,14 +1,13 @@ +-/* or1k use variant I, but with the twist that tp points to the end of TCB */ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { + #ifdef __clang__ +- char *tp; ++ uintptr_t tp; + __asm__ ("l.ori %0, r10, 0" : "=r" (tp) ); + #else +- register char *tp __asm__("r10"); ++ register uintptr_t tp __asm__("r10"); + __asm__ ("" : "=r" (tp) ); + #endif +- return (struct pthread *) (tp - sizeof(struct pthread)); ++ return tp; + } + + #define TLS_ABOVE_TP +diff --git a/arch/powerpc/pthread_arch.h b/arch/powerpc/pthread_arch.h +index 9697046b..a0947763 100644 +--- a/arch/powerpc/pthread_arch.h ++++ b/arch/powerpc/pthread_arch.h +@@ -1,8 +1,8 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- register char *tp __asm__("r2"); ++ register uintptr_t tp __asm__("r2"); + __asm__ ("" : "=r" (tp) ); +- return (pthread_t)(tp - 0x7000 - sizeof(struct pthread)); ++ return tp; + } + + #define TLS_ABOVE_TP +diff --git a/arch/powerpc64/pthread_arch.h b/arch/powerpc64/pthread_arch.h +index e9dba43f..08a557d2 100644 +--- a/arch/powerpc64/pthread_arch.h ++++ b/arch/powerpc64/pthread_arch.h +@@ -1,8 +1,8 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- register char *tp __asm__("r13"); ++ register uintptr_t tp __asm__("r13"); + __asm__ ("" : "=r" (tp) ); +- return (pthread_t)(tp - 0x7000 - sizeof(struct pthread)); ++ return tp; + } + + #define TLS_ABOVE_TP +diff --git a/arch/riscv64/pthread_arch.h b/arch/riscv64/pthread_arch.h +index 50f0868d..a20d7fba 100644 +--- a/arch/riscv64/pthread_arch.h ++++ b/arch/riscv64/pthread_arch.h +@@ -1,8 +1,8 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- char *tp; ++ uintptr_t tp; + __asm__ __volatile__("mv %0, tp" : "=r"(tp)); +- return (void *)(tp - sizeof(struct pthread)); ++ return tp; + } + + #define TLS_ABOVE_TP +diff --git a/arch/s390x/pthread_arch.h b/arch/s390x/pthread_arch.h +index 5d22546b..e54fec3f 100644 +--- a/arch/s390x/pthread_arch.h ++++ b/arch/s390x/pthread_arch.h +@@ -1,12 +1,12 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- struct pthread *self; ++ uintptr_t tp; + __asm__ ( + "ear %0, %%a0\n" + "sllg %0, %0, 32\n" + "ear %0, %%a1\n" +- : "=r"(self)); +- return self; ++ : "=r"(tp)); ++ return tp; + } + + #define MC_PC psw.addr +diff --git a/arch/sh/pthread_arch.h b/arch/sh/pthread_arch.h +index c2252908..0fcf70d2 100644 +--- a/arch/sh/pthread_arch.h ++++ b/arch/sh/pthread_arch.h +@@ -1,8 +1,8 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- char *self; +- __asm__ ("stc gbr,%0" : "=r" (self) ); +- return (struct pthread *) (self - sizeof(struct pthread)); ++ uintptr_t tp; ++ __asm__ ("stc gbr,%0" : "=r" (tp) ); ++ return tp; + } + + #define TLS_ABOVE_TP +diff --git a/arch/x32/pthread_arch.h b/arch/x32/pthread_arch.h +index fa452839..6e2495da 100644 +--- a/arch/x32/pthread_arch.h ++++ b/arch/x32/pthread_arch.h +@@ -1,8 +1,8 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- struct pthread *self; +- __asm__ ("mov %%fs:0,%0" : "=r" (self) ); +- return self; ++ uintptr_t tp; ++ __asm__ ("mov %%fs:0,%0" : "=r" (tp) ); ++ return tp; + } + + #define MC_PC gregs[REG_RIP] +diff --git a/arch/x86_64/pthread_arch.h b/arch/x86_64/pthread_arch.h +index 1c64a840..c8c63f2e 100644 +--- a/arch/x86_64/pthread_arch.h ++++ b/arch/x86_64/pthread_arch.h +@@ -1,8 +1,8 @@ +-static inline struct pthread *__pthread_self() ++static inline uintptr_t __get_tp() + { +- struct pthread *self; +- __asm__ ("mov %%fs:0,%0" : "=r" (self) ); +- return self; ++ uintptr_t tp; ++ __asm__ ("mov %%fs:0,%0" : "=r" (tp) ); ++ return tp; + } + + #define MC_PC gregs[REG_RIP] +diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h +index 3c2bd767..58e06136 100644 +--- a/src/internal/pthread_impl.h ++++ b/src/internal/pthread_impl.h +@@ -115,8 +115,10 @@ struct __timer { + + #ifdef TLS_ABOVE_TP + #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + TP_OFFSET) ++#define __pthread_self() ((pthread_t)(__get_tp() - sizeof(struct __pthread) - TP_OFFSET)) + #else + #define TP_ADJ(p) (p) ++#define __pthread_self() ((pthread_t)__get_tp()) + #endif + + #ifndef tls_mod_off_t +-- +2.47.0 + diff --git a/srcpkgs/musl1.1/patches/pthread_0003-remove-redundant-pthread-struct-members-repeated-for.patch b/srcpkgs/musl1.1/patches/pthread_0003-remove-redundant-pthread-struct-members-repeated-for.patch new file mode 100644 index 00000000000..f0616241933 --- /dev/null +++ b/srcpkgs/musl1.1/patches/pthread_0003-remove-redundant-pthread-struct-members-repeated-for.patch @@ -0,0 +1,165 @@ +From 57f6e85c9de417fef5eece2a5b00c1104321f543 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Mon, 24 Aug 2020 22:45:51 -0400 +Subject: [PATCH 2/2] remove redundant pthread struct members repeated for + layout purposes + +dtv_copy, canary2, and canary_at_end existed solely to match multiple +ABI and asm-accessed layouts simultaneously. now that pthread_arch.h +can be included before struct __pthread is defined, the struct layout +can depend on macros defined by pthread_arch.h. +--- + arch/powerpc/pthread_arch.h | 2 -- + arch/powerpc64/pthread_arch.h | 2 -- + arch/x32/pthread_arch.h | 2 +- + ldso/dynlink.c | 2 +- + src/env/__init_tls.c | 2 +- + src/env/__stack_chk_fail.c | 2 +- + src/internal/pthread_impl.h | 23 ++++++++++++++--------- + src/thread/pthread_create.c | 2 +- + 8 files changed, 19 insertions(+), 18 deletions(-) + +diff --git a/arch/powerpc/pthread_arch.h b/arch/powerpc/pthread_arch.h +index a0947763..42e88b07 100644 +--- a/arch/powerpc/pthread_arch.h ++++ b/arch/powerpc/pthread_arch.h +@@ -14,5 +14,3 @@ static inline uintptr_t __get_tp() + // the kernel calls the ip "nip", it's the first saved value after the 32 + // GPRs. + #define MC_PC gregs[32] +- +-#define CANARY canary_at_end +diff --git a/arch/powerpc64/pthread_arch.h b/arch/powerpc64/pthread_arch.h +index 08a557d2..1b7b9079 100644 +--- a/arch/powerpc64/pthread_arch.h ++++ b/arch/powerpc64/pthread_arch.h +@@ -14,5 +14,3 @@ static inline uintptr_t __get_tp() + // the kernel calls the ip "nip", it's the first saved value after the 32 + // GPRs. + #define MC_PC gp_regs[32] +- +-#define CANARY canary_at_end +diff --git a/arch/x32/pthread_arch.h b/arch/x32/pthread_arch.h +index 6e2495da..c1e7716d 100644 +--- a/arch/x32/pthread_arch.h ++++ b/arch/x32/pthread_arch.h +@@ -7,6 +7,6 @@ static inline uintptr_t __get_tp() + + #define MC_PC gregs[REG_RIP] + +-#define CANARY canary2 ++#define CANARY_PAD + + #define tls_mod_off_t unsigned long long +diff --git a/ldso/dynlink.c b/ldso/dynlink.c +index d3d4ddd2..f7474743 100644 +--- a/ldso/dynlink.c ++++ b/ldso/dynlink.c +@@ -1579,7 +1579,7 @@ static void install_new_tls(void) + + /* Install new dtv for each thread. */ + for (j=0, td=self; !j || td!=self; j++, td=td->next) { +- td->dtv = td->dtv_copy = newdtv[j]; ++ td->dtv = newdtv[j]; + } + + __tl_unlock(); +diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c +index 772baba3..a93141ed 100644 +--- a/src/env/__init_tls.c ++++ b/src/env/__init_tls.c +@@ -67,7 +67,7 @@ void *__copy_tls(unsigned char *mem) + } + #endif + dtv[0] = libc.tls_cnt; +- td->dtv = td->dtv_copy = dtv; ++ td->dtv = dtv; + return td; + } + +diff --git a/src/env/__stack_chk_fail.c b/src/env/__stack_chk_fail.c +index e32596d1..bf5a280a 100644 +--- a/src/env/__stack_chk_fail.c ++++ b/src/env/__stack_chk_fail.c +@@ -9,7 +9,7 @@ void __init_ssp(void *entropy) + if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t)); + else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245; + +- __pthread_self()->CANARY = __stack_chk_guard; ++ __pthread_self()->canary = __stack_chk_guard; + } + + void __stack_chk_fail(void) +diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h +index 58e06136..4d709bbc 100644 +--- a/src/internal/pthread_impl.h ++++ b/src/internal/pthread_impl.h +@@ -11,16 +11,25 @@ + #include "atomic.h" + #include "futex.h" + ++#include "pthread_arch.h" ++ + #define pthread __pthread + + struct pthread { + /* Part 1 -- these fields may be external or + * internal (accessed via asm) ABI. Do not change. */ + struct pthread *self; ++#ifndef TLS_ABOVE_TP + uintptr_t *dtv; ++#endif + struct pthread *prev, *next; /* non-ABI */ + uintptr_t sysinfo; +- uintptr_t canary, canary2; ++#ifndef TLS_ABOVE_TP ++#ifdef CANARY_PAD ++ uintptr_t canary_pad; ++#endif ++ uintptr_t canary; ++#endif + + /* Part 2 -- implementation details, non-ABI. */ + int tid; +@@ -52,8 +61,10 @@ struct pthread { + + /* Part 3 -- the positions of these fields relative to + * the end of the structure is external and internal ABI. */ +- uintptr_t canary_at_end; +- uintptr_t *dtv_copy; ++#ifdef TLS_ABOVE_TP ++ uintptr_t canary; ++ uintptr_t *dtv; ++#endif + }; + + enum { +@@ -99,12 +110,6 @@ struct __timer { + #define _b_waiters2 __u.__vi[4] + #define _b_inst __u.__p[3] + +-#include "pthread_arch.h" +- +-#ifndef CANARY +-#define CANARY canary +-#endif +- + #ifndef TP_OFFSET + #define TP_OFFSET 0 + #endif +diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c +index 10f1b7d8..55744155 100644 +--- a/src/thread/pthread_create.c ++++ b/src/thread/pthread_create.c +@@ -314,7 +314,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att + new->detach_state = DT_JOINABLE; + } + new->robust_list.head = &new->robust_list.head; +- new->CANARY = self->CANARY; ++ new->canary = self->canary; + new->sysinfo = self->sysinfo; + + /* Setup argument structure for the new thread on its stack. +-- +2.47.0 + diff --git a/srcpkgs/musl1.1/patches/riscv64-ucontext.patch b/srcpkgs/musl1.1/patches/riscv64-ucontext.patch new file mode 100644 index 00000000000..5afac82b6d2 --- /dev/null +++ b/srcpkgs/musl1.1/patches/riscv64-ucontext.patch @@ -0,0 +1,29 @@ +From 56f0631d9553dc06530ff661527cf1fcd595a0d1 Mon Sep 17 00:00:00 2001 +From: Drew DeVault +Date: Sat, 5 Dec 2020 18:10:06 +0000 +Subject: [PATCH] riscv64: fix inconsistent ucontext_t struct tag + +ucontext.h depends on the internal struct tag name for namespacing +reasons, and the intent was always for it to be consistent across +archs anyway. +--- + arch/riscv64/bits/signal.h | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/arch/riscv64/bits/signal.h b/arch/riscv64/bits/signal.h +index b006334f7..287367db7 100644 +--- a/arch/riscv64/bits/signal.h ++++ b/arch/riscv64/bits/signal.h +@@ -60,10 +60,10 @@ struct sigaltstack { + size_t ss_size; + }; + +-typedef struct ucontext_t ++typedef struct __ucontext + { + unsigned long uc_flags; +- struct ucontext_t *uc_link; ++ struct __ucontext *uc_link; + stack_t uc_stack; + sigset_t uc_sigmask; + mcontext_t uc_mcontext; diff --git a/srcpkgs/musl1.1/patches/statx.patch b/srcpkgs/musl1.1/patches/statx.patch new file mode 100644 index 00000000000..7af4571b08b --- /dev/null +++ b/srcpkgs/musl1.1/patches/statx.patch @@ -0,0 +1,201 @@ +From b817541f1cfd38e4b81257b3215e276ea9d0fc61 Mon Sep 17 00:00:00 2001 +From: Duncan Bellamy +Date: Wed, 31 Aug 2022 20:07:34 +0100 +Subject: [PATCH] add statx interface using syscall, fallback to fstatat + +--- + include/sys/stat.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++ + src/linux/statx.c | 42 +++++++++++++++++++++++++++++++++++ + 2 files changed, 97 insertions(+) + create mode 100644 src/linux/statx.c + +diff --git a/include/sys/stat.h b/include/sys/stat.h +index e6d0049c..6690192d 100644 +--- a/include/sys/stat.h ++++ b/include/sys/stat.h +@@ -18,6 +18,13 @@ extern "C" { + #define __NEED_blkcnt_t + #define __NEED_struct_timespec + ++#ifdef _GNU_SOURCE ++#define __NEED_int64_t ++#define __NEED_uint64_t ++#define __NEED_uint32_t ++#define __NEED_uint16_t ++#endif ++ + #include + + #include +@@ -98,6 +105,54 @@ int lchmod(const char *, mode_t); + #define S_IEXEC S_IXUSR + #endif + ++#if defined(_GNU_SOURCE) ++#define STATX_TYPE 1U ++#define STATX_MODE 2U ++#define STATX_NLINK 4U ++#define STATX_UID 8U ++#define STATX_GID 0x10U ++#define STATX_ATIME 0x20U ++#define STATX_MTIME 0x40U ++#define STATX_CTIME 0x80U ++#define STATX_INO 0x100U ++#define STATX_SIZE 0x200U ++#define STATX_BLOCKS 0x400U ++#define STATX_BASIC_STATS 0x7ffU ++#define STATX_BTIME 0x800U ++#define STATX_ALL 0xfffU ++ ++struct statx_timestamp { ++ int64_t tv_sec; ++ uint32_t tv_nsec, __pad; ++}; ++ ++struct statx { ++ uint32_t stx_mask; ++ uint32_t stx_blksize; ++ uint64_t stx_attributes; ++ uint32_t stx_nlink; ++ uint32_t stx_uid; ++ uint32_t stx_gid; ++ uint16_t stx_mode; ++ uint16_t __pad0[1]; ++ uint64_t stx_ino; ++ uint64_t stx_size; ++ uint64_t stx_blocks; ++ uint64_t stx_attributes_mask; ++ struct statx_timestamp stx_atime; ++ struct statx_timestamp stx_btime; ++ struct statx_timestamp stx_ctime; ++ struct statx_timestamp stx_mtime; ++ uint32_t stx_rdev_major; ++ uint32_t stx_rdev_minor; ++ uint32_t stx_dev_major; ++ uint32_t stx_dev_minor; ++ uint64_t __pad1[14]; ++}; ++ ++int statx(int, const char *__restrict, int, unsigned, struct statx *__restrict); ++#endif ++ + #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) + #define stat64 stat + #define fstat64 fstat +diff --git a/src/linux/statx.c b/src/linux/statx.c +new file mode 100644 +index 00000000..4616bff4 +--- /dev/null ++++ b/src/linux/statx.c +@@ -0,0 +1,42 @@ ++#define _GNU_SOURCE ++#include ++#include ++#include ++#include ++#include ++ ++int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct statx *restrict stx) ++{ ++ int ret = __syscall(SYS_statx, dirfd, path, flags, mask, stx); ++ ++#ifndef SYS_fstatat ++ return __syscall_ret(ret); ++#endif ++ ++ if (ret != -ENOSYS) return __syscall_ret(ret); ++ ++ struct stat st; ++ ret = fstatat(dirfd, path, &st, flags); ++ if (ret) return ret; ++ ++ stx->stx_dev_major = major(st.st_dev); ++ stx->stx_dev_minor = minor(st.st_dev); ++ stx->stx_ino = st.st_ino; ++ stx->stx_mode = st.st_mode; ++ stx->stx_nlink = st.st_nlink; ++ stx->stx_uid = st.st_uid; ++ stx->stx_gid = st.st_gid; ++ stx->stx_size = st.st_size; ++ stx->stx_blksize = st.st_blksize; ++ stx->stx_blocks = st.st_blocks; ++ stx->stx_atime.tv_sec = st.st_atim.tv_sec; ++ stx->stx_atime.tv_nsec = st.st_atim.tv_nsec; ++ stx->stx_mtime.tv_sec = st.st_mtim.tv_sec; ++ stx->stx_mtime.tv_nsec = st.st_mtim.tv_nsec; ++ stx->stx_ctime.tv_sec = st.st_ctim.tv_sec; ++ stx->stx_ctime.tv_nsec = st.st_ctim.tv_nsec; ++ stx->stx_btime = (struct statx_timestamp){.tv_sec=0, .tv_nsec=0}; ++ stx->stx_mask = STATX_BASIC_STATS; ++ ++ return 0; ++} + +From 251cbb6366403a056b39638264932c82d18ec610 Mon Sep 17 00:00:00 2001 +From: Gabriel Ravier +Date: Fri, 13 Sep 2024 22:00:15 +0200 +Subject: [PATCH] statx: fix ENOSYS emulation not setting stx_rdev_* + +The current implementation of the statx function fails to set the +values of stx->stx_rdev_major and stx->stx_rdev_minor if the statx +syscall fails with ENOSYS and thus the statx function has to fall back +on fstatat-based emulation. +--- + src/linux/statx.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/src/linux/statx.c b/src/linux/statx.c +index 4616bff4a..5f6dde923 100644 +--- a/src/linux/statx.c ++++ b/src/linux/statx.c +@@ -21,6 +21,8 @@ int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct + + stx->stx_dev_major = major(st.st_dev); + stx->stx_dev_minor = minor(st.st_dev); ++ stx->stx_rdev_major = major(st.st_rdev); ++ stx->stx_rdev_minor = minor(st.st_rdev); + stx->stx_ino = st.st_ino; + stx->stx_mode = st.st_mode; + stx->stx_nlink = st.st_nlink; + +From 4ca8c267768e371930ef7ec9593a5f8b44a7f810 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Fri, 13 Sep 2024 17:08:11 -0400 +Subject: [PATCH] statx: fix uninitialized attributes/mask in fallback path + +commit b817541f1cfd38e4b81257b3215e276ea9d0fc61 introduced statx with +a fallback using fstatat, but failed to fill in stx_rdev_major/minor +and stx_attributes[_mask]. the rdev omission has been addressed +separately. rather than explicitly zeroing the attributes and their +mask, pre-fill the entire structure with zeros. this will also cover +the padding adjacent to stx_mode, in case it's ever used in the +future. + +explicit zeroing of stx_btime is removed since, with this change, it +will already be pre-zeroed. as an aside, zeroing it was not strictly +necessary, since STATX_BASIC_STATS does not include STATX_BTIME and +thus does not indicate any validity for it. +--- + src/linux/statx.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/linux/statx.c b/src/linux/statx.c +index 5f6dde92..4fb96e4b 100644 +--- a/src/linux/statx.c ++++ b/src/linux/statx.c +@@ -19,6 +19,7 @@ int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct + ret = fstatat(dirfd, path, &st, flags); + if (ret) return ret; + ++ *stx = (struct statx){0}; + stx->stx_dev_major = major(st.st_dev); + stx->stx_dev_minor = minor(st.st_dev); + stx->stx_rdev_major = major(st.st_rdev); +@@ -37,7 +38,6 @@ int statx(int dirfd, const char *restrict path, int flags, unsigned mask, struct + stx->stx_mtime.tv_nsec = st.st_mtim.tv_nsec; + stx->stx_ctime.tv_sec = st.st_ctim.tv_sec; + stx->stx_ctime.tv_nsec = st.st_ctim.tv_nsec; +- stx->stx_btime = (struct statx_timestamp){.tv_sec=0, .tv_nsec=0}; + stx->stx_mask = STATX_BASIC_STATS; + + return 0; diff --git a/srcpkgs/musl1.1/patches/work_around_linux_bug_in_readlink_syscall_with_zero_buffer.patch b/srcpkgs/musl1.1/patches/work_around_linux_bug_in_readlink_syscall_with_zero_buffer.patch new file mode 100644 index 00000000000..3286432ebea --- /dev/null +++ b/srcpkgs/musl1.1/patches/work_around_linux_bug_in_readlink_syscall_with_zero_buffer.patch @@ -0,0 +1,59 @@ +From e2fa720be7024cce4fc489f3877476d35da48ee2 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Mon, 23 Nov 2020 19:44:19 -0500 +Subject: [PATCH] work around linux bug in readlink syscall with zero buffer + size + +linux fails with EINVAL when a zero buffer size is passed to the +syscall. this is non-conforming because POSIX already defines EINVAL +with a significantly different meaning: the target is not a symlink. + +since the request is semantically valid, patch it up by using a dummy +buffer of length one, and truncating the return value to zero if it +succeeds. +--- + src/unistd/readlink.c | 11 +++++++++-- + src/unistd/readlinkat.c | 9 ++++++++- + 2 files changed, 17 insertions(+), 3 deletions(-) + +diff --git a/src/unistd/readlink.c b/src/unistd/readlink.c +index a152d5249..32f4537f9 100644 +--- a/src/unistd/readlink.c ++++ b/src/unistd/readlink.c +@@ -4,9 +4,16 @@ + + ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize) + { ++ char dummy[1]; ++ if (!bufsize) { ++ buf = dummy; ++ bufsize = 1; ++ } + #ifdef SYS_readlink +- return syscall(SYS_readlink, path, buf, bufsize); ++ int r = __syscall(SYS_readlink, path, buf, bufsize); + #else +- return syscall(SYS_readlinkat, AT_FDCWD, path, buf, bufsize); ++ int r = __syscall(SYS_readlinkat, AT_FDCWD, path, buf, bufsize); + #endif ++ if (buf == dummy && r > 0) r = 0; ++ return __syscall_ret(r); + } +diff --git a/src/unistd/readlinkat.c b/src/unistd/readlinkat.c +index 9af45cd5a..f79d3d142 100644 +--- a/src/unistd/readlinkat.c ++++ b/src/unistd/readlinkat.c +@@ -3,5 +3,12 @@ + + ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize) + { +- return syscall(SYS_readlinkat, fd, path, buf, bufsize); ++ char dummy[1]; ++ if (!bufsize) { ++ buf = dummy; ++ bufsize = 1; ++ } ++ int r = __syscall(SYS_readlinkat, fd, path, buf, bufsize); ++ if (buf == dummy && r > 0) r = 0; ++ return __syscall_ret(r); + } diff --git a/srcpkgs/musl1.1/template b/srcpkgs/musl1.1/template new file mode 100644 index 00000000000..d68a162cd58 --- /dev/null +++ b/srcpkgs/musl1.1/template @@ -0,0 +1,68 @@ +# Template file for 'musl1.1' +pkgname=musl1.1 +version=1.1.24 +revision=1 +archs="*-musl" +bootstrap=yes +build_style=gnu-configure +configure_args="--prefix=/usr --disable-gcc-wrapper" +short_desc="Musl C library - version 1.1" +maintainer="Enno Boland " +license="MIT" +homepage="https://musl.libc.org/" +distfiles="https://musl.libc.org/releases/musl-${version}.tar.gz" +checksum=1370c9a812b2cf2a7d92802510cca0058cc37e66a7bedd70051f0a34015022a3 + +replaces="musl>=0" +provides="musl-${version}_${revision}" + +nostrip_files="libc.so" +shlib_provides="libc.so" + +if [ "$XBPS_TARGET_WORDSIZE" -ne 32 ]; then + broken="use musl" +fi + +post_build() { + $CC $CFLAGS $LDFLAGS -fpie ${FILESDIR}/getent.c -o getent + $CC $CFLAGS $LDFLAGS -fpie ${FILESDIR}/getconf.c -o getconf + $CC $CFLAGS $LDFLAGS -fpie ${FILESDIR}/iconv.c -o iconv + $CC $CFLAGS $LDFLAGS -fpie -c ${FILESDIR}/__stack_chk_fail_local.c -o __stack_chk_fail_local.o + $AR r libssp_nonshared.a __stack_chk_fail_local.o +} + +do_install() { + # Move everything to /usr. + vmkdir usr/lib + ln -s usr/lib ${DESTDIR}/lib + make DESTDIR=${DESTDIR} install + rm ${DESTDIR}/lib + # provide ldd + vmkdir usr/bin + ln -s ../lib${XBPS_TARGET_WORDSIZE}/libc.so ${DESTDIR}/usr/bin/ldd + # additional utils from Alpine/NetBSD + vbin iconv + vbin getent + vman ${FILESDIR}/getent.1 + vbin getconf + vman ${FILESDIR}/getconf.1 + # additional symbols from libssp_nonshared (necessary on i386 and PPC) + vinstall libssp_nonshared.a 755 usr/lib + # Fake ldconfig + ln -s true ${DESTDIR}/usr/bin/ldconfig + + vlicense COPYRIGHT +} + +musl1.1-devel_package() { + depends="kernel-libc-headers ${sourcepkg}-${version}_${revision}" + replaces="libssp-devel<=12.2.0_1 musl-devel>=0" + conflicts="libssp-devel<=12.2.0_1" + provides="musl-devel-${version}_${revision}" + short_desc+=" - development files" + pkg_install() { + vmove usr/include + vmove "usr/lib/*.a" + vmove "usr/lib/*.o" + } +}