authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-19 14:22:17-07:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-06-20 12:55:38-04:00
loga5d8c310eef494594ae29a2319a5baf496c3434f
treefbe66673e85f0115b62191cbb2f4bc224ce9786b
parentcdcfd15d3c7b573dcba21b64ffdf982e26524e50

musl: update src files to v1.2.4


173 files changed, 735 insertions(+), 441 deletions(-)

lib/libc/musl/arch/arm/syscall_arch.h+7
......@@ -101,3 +101,10 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo
101101#define SYSCALL_FADVISE_6_ARG
102102
103103#define SYSCALL_IPC_BROKEN_MODE
104
105#define VDSO_USEFUL
106#define VDSO_CGT32_SYM "__vdso_clock_gettime"
107#define VDSO_CGT32_VER "LINUX_2.6"
108#define VDSO_CGT_SYM "__vdso_clock_gettime64"
109#define VDSO_CGT_VER "LINUX_2.6"
110#define VDSO_CGT_WORKAROUND 1
lib/libc/musl/arch/i386/arch.mak deleted-1
......@@ -1 +0,0 @@
1COMPAT_SRC_DIRS = compat/time32
lib/libc/musl/arch/m68k/arch.mak deleted-1
......@@ -1 +0,0 @@
1COMPAT_SRC_DIRS = compat/time32
lib/libc/musl/arch/mips/arch.mak deleted-1
......@@ -1 +0,0 @@
1COMPAT_SRC_DIRS = compat/time32
lib/libc/musl/arch/mips/bits/signal.h-1
......@@ -66,7 +66,6 @@ typedef struct __ucontext {
6666#define SA_RESTART 0x10000000
6767#define SA_NODEFER 0x40000000
6868#define SA_RESETHAND 0x80000000
69#define SA_RESTORER 0x04000000
7069
7170#undef SIG_BLOCK
7271#undef SIG_UNBLOCK
lib/libc/musl/arch/mips/ksigaction.h+1-4
......@@ -4,10 +4,7 @@ struct k_sigaction {
44 unsigned flags;
55 void (*handler)(int);
66 unsigned long mask[4];
7 /* The following field is past the end of the structure the
8 * kernel will read or write, and exists only to avoid having
9 * mips-specific preprocessor conditionals in sigaction.c. */
10 void (*restorer)();
7 void *unused;
118};
129
1310hidden void __restore(), __restore_rt();
lib/libc/musl/arch/mips/reloc.h+1
......@@ -29,6 +29,7 @@
2929
3030#define NEED_MIPS_GOT_RELOCS 1
3131#define DT_DEBUG_INDIRECT DT_MIPS_RLD_MAP
32#define DT_DEBUG_INDIRECT_REL DT_MIPS_RLD_MAP_REL
3233#define ARCH_SYM_REJECT_UND(s) (!((s)->st_other & STO_MIPS_PLT))
3334
3435#define CRTJMP(pc,sp) __asm__ __volatile__( \
lib/libc/musl/arch/mips64/bits/signal.h-1
......@@ -85,7 +85,6 @@ typedef struct __ucontext {
8585#define SA_RESTART 0x10000000
8686#define SA_NODEFER 0x40000000
8787#define SA_RESETHAND 0x80000000
88#define SA_RESTORER 0x04000000
8988
9089#undef SIG_BLOCK
9190#undef SIG_UNBLOCK
lib/libc/musl/arch/mips64/ksigaction.h+1-1
......@@ -4,7 +4,7 @@ struct k_sigaction {
44 unsigned flags;
55 void (*handler)(int);
66 unsigned long mask[2];
7 void (*restorer)();
7 void *unused;
88};
99
1010hidden void __restore(), __restore_rt();
lib/libc/musl/arch/mips64/reloc.h+1
......@@ -38,6 +38,7 @@
3838
3939#define NEED_MIPS_GOT_RELOCS 1
4040#define DT_DEBUG_INDIRECT DT_MIPS_RLD_MAP
41#define DT_DEBUG_INDIRECT_REL DT_MIPS_RLD_MAP_REL
4142#define ARCH_SYM_REJECT_UND(s) (!((s)->st_other & STO_MIPS_PLT))
4243
4344#define CRTJMP(pc,sp) __asm__ __volatile__( \
lib/libc/musl/arch/powerpc/arch.mak deleted-1
......@@ -1 +0,0 @@
1COMPAT_SRC_DIRS = compat/time32
lib/libc/musl/arch/riscv64/bits/signal.h-1
......@@ -76,7 +76,6 @@ typedef struct __ucontext
7676#define SA_RESTART 0x10000000
7777#define SA_NODEFER 0x40000000
7878#define SA_RESETHAND 0x80000000
79#define SA_RESTORER 0x04000000
8079
8180#endif
8281
lib/libc/musl/compat/time32/__xstat.c+4-4
......@@ -3,22 +3,22 @@
33
44struct stat32;
55
6int __fxstat64(int ver, int fd, struct stat32 *buf)
6int __fxstat(int ver, int fd, struct stat32 *buf)
77{
88 return __fstat_time32(fd, buf);
99}
1010
11int __fxstatat64(int ver, int fd, const char *path, struct stat32 *buf, int flag)
11int __fxstatat(int ver, int fd, const char *path, struct stat32 *buf, int flag)
1212{
1313 return __fstatat_time32(fd, path, buf, flag);
1414}
1515
16int __lxstat64(int ver, const char *path, struct stat32 *buf)
16int __lxstat(int ver, const char *path, struct stat32 *buf)
1717{
1818 return __lstat_time32(path, buf);
1919}
2020
21int __xstat64(int ver, const char *path, struct stat32 *buf)
21int __xstat(int ver, const char *path, struct stat32 *buf)
2222{
2323 return __stat_time32(path, buf);
2424}
lib/libc/musl/compat/time32/aio_suspend_time32.c-2
......@@ -7,5 +7,3 @@ int __aio_suspend_time32(const struct aiocb *const cbs[], int cnt, const struct
77 return aio_suspend(cbs, cnt, ts32 ? (&(struct timespec){
88 .tv_sec = ts32->tv_sec, .tv_nsec = ts32->tv_nsec}) : 0);
99}
10
11weak_alias(aio_suspend, aio_suspend64);
lib/libc/musl/compat/time32/fstat_time32.c-2
......@@ -13,5 +13,3 @@ int __fstat_time32(int fd, struct stat32 *restrict st32)
1313 if (!r) memcpy(st32, &st, offsetof(struct stat, st_atim));
1414 return r;
1515}
16
17weak_alias(fstat, fstat64);
lib/libc/musl/compat/time32/fstatat_time32.c-2
......@@ -13,5 +13,3 @@ int __fstatat_time32(int fd, const char *restrict path, struct stat32 *restrict
1313 if (!r) memcpy(st32, &st, offsetof(struct stat, st_atim));
1414 return r;
1515}
16
17weak_alias(fstatat, fstatat64);
lib/libc/musl/compat/time32/lstat_time32.c-2
......@@ -13,5 +13,3 @@ int __lstat_time32(const char *restrict path, struct stat32 *restrict st32)
1313 if (!r) memcpy(st32, &st, offsetof(struct stat, st_atim));
1414 return r;
1515}
16
17weak_alias(lstat, lstat64);
lib/libc/musl/compat/time32/stat_time32.c-2
......@@ -13,5 +13,3 @@ int __stat_time32(const char *restrict path, struct stat32 *restrict st32)
1313 if (!r) memcpy(st32, &st, offsetof(struct stat, st_atim));
1414 return r;
1515}
16
17weak_alias(stat, stat64);
lib/libc/musl/include/aio.h+1-1
......@@ -49,7 +49,7 @@ int aio_fsync(int, struct aiocb *);
4949
5050int lio_listio(int, struct aiocb *__restrict const *__restrict, int, struct sigevent *__restrict);
5151
52#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
52#if defined(_LARGEFILE64_SOURCE)
5353#define aiocb64 aiocb
5454#define aio_read64 aio_read
5555#define aio_write64 aio_write
lib/libc/musl/include/arpa/nameser.h+71
......@@ -188,6 +188,36 @@ typedef enum __ns_type {
188188 ns_t_sink = 40,
189189 ns_t_opt = 41,
190190 ns_t_apl = 42,
191 ns_t_ds = 43,
192 ns_t_sshfp = 44,
193 ns_t_ipseckey = 45,
194 ns_t_rrsig = 46,
195 ns_t_nsec = 47,
196 ns_t_dnskey = 48,
197 ns_t_dhcid = 49,
198 ns_t_nsec3 = 50,
199 ns_t_nsec3param = 51,
200 ns_t_tlsa = 52,
201 ns_t_smimea = 53,
202 ns_t_hip = 55,
203 ns_t_ninfo = 56,
204 ns_t_rkey = 57,
205 ns_t_talink = 58,
206 ns_t_cds = 59,
207 ns_t_cdnskey = 60,
208 ns_t_openpgpkey = 61,
209 ns_t_csync = 62,
210 ns_t_spf = 99,
211 ns_t_uinfo = 100,
212 ns_t_uid = 101,
213 ns_t_gid = 102,
214 ns_t_unspec = 103,
215 ns_t_nid = 104,
216 ns_t_l32 = 105,
217 ns_t_l64 = 106,
218 ns_t_lp = 107,
219 ns_t_eui48 = 108,
220 ns_t_eui64 = 109,
191221 ns_t_tkey = 249,
192222 ns_t_tsig = 250,
193223 ns_t_ixfr = 251,
......@@ -196,6 +226,11 @@ typedef enum __ns_type {
196226 ns_t_maila = 254,
197227 ns_t_any = 255,
198228 ns_t_zxfr = 256,
229 ns_t_uri = 256,
230 ns_t_caa = 257,
231 ns_t_avc = 258,
232 ns_t_ta = 32768,
233 ns_t_dlv = 32769,
199234 ns_t_max = 65536
200235} ns_type;
201236
......@@ -430,12 +465,48 @@ typedef struct {
430465#define T_NAPTR ns_t_naptr
431466#define T_A6 ns_t_a6
432467#define T_DNAME ns_t_dname
468#define T_DS ns_t_ds
469#define T_SSHFP ns_t_sshfp
470#define T_IPSECKEY ns_t_ipseckey
471#define T_RRSIG ns_t_rrsig
472#define T_NSEC ns_t_nsec
473#define T_DNSKEY ns_t_dnskey
474#define T_DHCID ns_t_dhcid
475#define T_NSEC3 ns_t_nsec3
476#define T_NSEC3PARAM ns_t_nsec3param
477#define T_TLSA ns_t_tlsa
478#define T_SMIMEA ns_t_smimea
479#define T_HIP ns_t_hip
480#define T_NINFO ns_t_ninfo
481#define T_RKEY ns_t_rkey
482#define T_TALINK ns_t_talink
483#define T_CDS ns_t_cds
484#define T_CDNSKEY ns_t_cdnskey
485#define T_OPENPGPKEY ns_t_openpgpkey
486#define T_CSYNC ns_t_csync
487#define T_SPF ns_t_spf
488#define T_UINFO ns_t_uinfo
489#define T_UID ns_t_uid
490#define T_GID ns_t_gid
491#define T_UNSPEC ns_t_unspec
492#define T_NID ns_t_nid
493#define T_L32 ns_t_l32
494#define T_L64 ns_t_l64
495#define T_LP ns_t_lp
496#define T_EUI48 ns_t_eui48
497#define T_EUI64 ns_t_eui64
498#define T_TKEY ns_t_tkey
433499#define T_TSIG ns_t_tsig
434500#define T_IXFR ns_t_ixfr
435501#define T_AXFR ns_t_axfr
436502#define T_MAILB ns_t_mailb
437503#define T_MAILA ns_t_maila
438504#define T_ANY ns_t_any
505#define T_URI ns_t_uri
506#define T_CAA ns_t_caa
507#define T_AVC ns_t_avc
508#define T_TA ns_t_ta
509#define T_DLV ns_t_dlv
439510
440511#define C_IN ns_c_in
441512#define C_CHAOS ns_c_chaos
lib/libc/musl/include/dirent.h+1-1
......@@ -56,7 +56,7 @@ int getdents(int, struct dirent *, size_t);
5656int versionsort(const struct dirent **, const struct dirent **);
5757#endif
5858
59#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
59#if defined(_LARGEFILE64_SOURCE)
6060#define dirent64 dirent
6161#define readdir64 readdir
6262#define readdir64_r readdir_r
lib/libc/musl/include/elf.h+7-2
......@@ -385,7 +385,8 @@ typedef struct {
385385#define SHT_PREINIT_ARRAY 16
386386#define SHT_GROUP 17
387387#define SHT_SYMTAB_SHNDX 18
388#define SHT_NUM 19
388#define SHT_RELR 19
389#define SHT_NUM 20
389390#define SHT_LOOS 0x60000000
390391#define SHT_GNU_ATTRIBUTES 0x6ffffff5
391392#define SHT_GNU_HASH 0x6ffffff6
......@@ -436,6 +437,7 @@ typedef struct {
436437} Elf64_Chdr;
437438
438439#define ELFCOMPRESS_ZLIB 1
440#define ELFCOMPRESS_ZSTD 2
439441#define ELFCOMPRESS_LOOS 0x60000000
440442#define ELFCOMPRESS_HIOS 0x6fffffff
441443#define ELFCOMPRESS_LOPROC 0x70000000
......@@ -754,7 +756,10 @@ typedef struct {
754756#define DT_PREINIT_ARRAY 32
755757#define DT_PREINIT_ARRAYSZ 33
756758#define DT_SYMTAB_SHNDX 34
757#define DT_NUM 35
759#define DT_RELRSZ 35
760#define DT_RELR 36
761#define DT_RELRENT 37
762#define DT_NUM 38
758763#define DT_LOOS 0x6000000d
759764#define DT_HIOS 0x6ffff000
760765#define DT_LOPROC 0x70000000
lib/libc/musl/include/fcntl.h+1-1
......@@ -195,7 +195,7 @@ ssize_t tee(int, int, size_t, unsigned);
195195#define loff_t off_t
196196#endif
197197
198#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
198#if defined(_LARGEFILE64_SOURCE)
199199#define F_GETLK64 F_GETLK
200200#define F_SETLK64 F_SETLK
201201#define F_SETLKW64 F_SETLKW
lib/libc/musl/include/ftw.h+1-1
......@@ -29,7 +29,7 @@ struct FTW {
2929int ftw(const char *, int (*)(const char *, const struct stat *, int), int);
3030int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *), int, int);
3131
32#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
32#if defined(_LARGEFILE64_SOURCE)
3333#define ftw64 ftw
3434#define nftw64 nftw
3535#endif
lib/libc/musl/include/glob.h+1-1
......@@ -39,7 +39,7 @@ void globfree(glob_t *);
3939#define GLOB_NOMATCH 3
4040#define GLOB_NOSYS 4
4141
42#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
42#if defined(_LARGEFILE64_SOURCE)
4343#define glob64 glob
4444#define globfree64 globfree
4545#define glob64_t glob_t
lib/libc/musl/include/netdb.h+1
......@@ -44,6 +44,7 @@ struct addrinfo {
4444#define EAI_NONAME -2
4545#define EAI_AGAIN -3
4646#define EAI_FAIL -4
47#define EAI_NODATA -5
4748#define EAI_FAMILY -6
4849#define EAI_SOCKTYPE -7
4950#define EAI_SERVICE -8
lib/libc/musl/include/sched.h+1-1
......@@ -124,7 +124,7 @@ __CPU_op_func_S(XOR, ^)
124124#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n)))
125125#define CPU_FREE(set) free(set)
126126
127#define CPU_SETSIZE 128
127#define CPU_SETSIZE 1024
128128
129129#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set)
130130#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set)
lib/libc/musl/include/stdio.h+1-1
......@@ -205,7 +205,7 @@ typedef struct _IO_cookie_io_functions_t {
205205FILE *fopencookie(void *, const char *, cookie_io_functions_t);
206206#endif
207207
208#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
208#if defined(_LARGEFILE64_SOURCE)
209209#define tmpfile64 tmpfile
210210#define fopen64 fopen
211211#define freopen64 freopen
lib/libc/musl/include/stdlib.h+2-2
......@@ -95,7 +95,7 @@ size_t __ctype_get_mb_cur_max(void);
9595#define WTERMSIG(s) ((s) & 0x7f)
9696#define WSTOPSIG(s) WEXITSTATUS(s)
9797#define WIFEXITED(s) (!WTERMSIG(s))
98#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00)
98#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001U)>>8) > 0x7f00)
9999#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu)
100100
101101int posix_memalign (void **, size_t, size_t);
......@@ -163,7 +163,7 @@ double strtod_l(const char *__restrict, char **__restrict, struct __locale_struc
163163long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *);
164164#endif
165165
166#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
166#if defined(_LARGEFILE64_SOURCE)
167167#define mkstemp64 mkstemp
168168#define mkostemp64 mkostemp
169169#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
lib/libc/musl/include/string.h+1-1
......@@ -73,6 +73,7 @@ char *strsignal(int);
7373char *strerror_l (int, locale_t);
7474int strcoll_l (const char *, const char *, locale_t);
7575size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t);
76void *memmem(const void *, size_t, const void *, size_t);
7677#endif
7778
7879#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
......@@ -92,7 +93,6 @@ void explicit_bzero (void *, size_t);
9293int strverscmp (const char *, const char *);
9394char *strchrnul(const char *, int);
9495char *strcasestr(const char *, const char *);
95void *memmem(const void *, size_t, const void *, size_t);
9696void *memrchr(const void *, int, size_t);
9797void *mempcpy(void *, const void *, size_t);
9898#ifndef __cplusplus
lib/libc/musl/include/strings.h+1
......@@ -5,6 +5,7 @@
55extern "C" {
66#endif
77
8#include <features.h>
89
910#define __NEED_size_t
1011#define __NEED_locale_t
lib/libc/musl/include/sys/mman.h+1-1
......@@ -141,7 +141,7 @@ int mincore (void *, size_t, unsigned char *);
141141int shm_open (const char *, int, mode_t);
142142int shm_unlink (const char *);
143143
144#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
144#if defined(_LARGEFILE64_SOURCE)
145145#define mmap64 mmap
146146#define off64_t off_t
147147#endif
lib/libc/musl/include/sys/resource.h+1-1
......@@ -95,7 +95,7 @@ int prlimit(pid_t, int, const struct rlimit *, struct rlimit *);
9595
9696#define RLIM_NLIMITS RLIMIT_NLIMITS
9797
98#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
98#if defined(_LARGEFILE64_SOURCE)
9999#define RLIM64_INFINITY RLIM_INFINITY
100100#define RLIM64_SAVED_CUR RLIM_SAVED_CUR
101101#define RLIM64_SAVED_MAX RLIM_SAVED_MAX
lib/libc/musl/include/sys/sendfile.h+1-1
......@@ -10,7 +10,7 @@ extern "C" {
1010
1111ssize_t sendfile(int, int, off_t *, size_t);
1212
13#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
13#if defined(_LARGEFILE64_SOURCE)
1414#define sendfile64 sendfile
1515#define off64_t off_t
1616#endif
lib/libc/musl/include/sys/stat.h+1-1
......@@ -98,7 +98,7 @@ int lchmod(const char *, mode_t);
9898#define S_IEXEC S_IXUSR
9999#endif
100100
101#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
101#if defined(_LARGEFILE64_SOURCE)
102102#define stat64 stat
103103#define fstat64 fstat
104104#define lstat64 lstat
lib/libc/musl/include/sys/statfs.h+1-1
......@@ -18,7 +18,7 @@ typedef struct __fsid_t {
1818int statfs (const char *, struct statfs *);
1919int fstatfs (int, struct statfs *);
2020
21#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
21#if defined(_LARGEFILE64_SOURCE)
2222#define statfs64 statfs
2323#define fstatfs64 fstatfs
2424#define fsblkcnt64_t fsblkcnt_t
lib/libc/musl/include/sys/statvfs.h+1-1
......@@ -42,7 +42,7 @@ int fstatvfs (int, struct statvfs *);
4242#define ST_NODIRATIME 2048
4343#define ST_RELATIME 4096
4444
45#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
45#if defined(_LARGEFILE64_SOURCE)
4646#define statvfs64 statvfs
4747#define fstatvfs64 fstatvfs
4848#define fsblkcnt64_t fsblkcnt_t
lib/libc/musl/include/sys/types.h+1-1
......@@ -71,7 +71,7 @@ typedef unsigned long long u_quad_t;
7171#include <sys/select.h>
7272#endif
7373
74#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
74#if defined(_LARGEFILE64_SOURCE)
7575#define blkcnt64_t blkcnt_t
7676#define fsblkcnt64_t fsblkcnt_t
7777#define fsfilcnt64_t fsfilcnt_t
lib/libc/musl/include/sys/uio.h+1-1
......@@ -29,7 +29,7 @@ ssize_t writev (int, const struct iovec *, int);
2929#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
3030ssize_t preadv (int, const struct iovec *, int, off_t);
3131ssize_t pwritev (int, const struct iovec *, int, off_t);
32#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
32#if defined(_LARGEFILE64_SOURCE)
3333#define preadv64 preadv
3434#define pwritev64 pwritev
3535#define off64_t off_t
lib/libc/musl/include/sys/wait.h+1-1
......@@ -50,7 +50,7 @@ pid_t wait4 (pid_t, int *, int, struct rusage *);
5050#define WSTOPSIG(s) WEXITSTATUS(s)
5151#define WCOREDUMP(s) ((s) & 0x80)
5252#define WIFEXITED(s) (!WTERMSIG(s))
53#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00)
53#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001U)>>8) > 0x7f00)
5454#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu)
5555#define WIFCONTINUED(s) ((s) == 0xffff)
5656
lib/libc/musl/include/unistd.h+5-1
......@@ -198,7 +198,7 @@ ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned);
198198pid_t gettid(void);
199199#endif
200200
201#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
201#if defined(_LARGEFILE64_SOURCE)
202202#define lseek64 lseek
203203#define pread64 pread
204204#define pwrite64 pwrite
......@@ -425,6 +425,8 @@ pid_t gettid(void);
425425#define _SC_XOPEN_STREAMS 246
426426#define _SC_THREAD_ROBUST_PRIO_INHERIT 247
427427#define _SC_THREAD_ROBUST_PRIO_PROTECT 248
428#define _SC_MINSIGSTKSZ 249
429#define _SC_SIGSTKSZ 250
428430
429431#define _CS_PATH 0
430432#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 1
......@@ -467,6 +469,8 @@ pid_t gettid(void);
467469#define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS 1147
468470#define _CS_V6_ENV 1148
469471#define _CS_V7_ENV 1149
472#define _CS_POSIX_V7_THREADS_CFLAGS 1150
473#define _CS_POSIX_V7_THREADS_LDFLAGS 1151
470474
471475#ifdef __cplusplus
472476}
lib/libc/musl/src/aio/aio.c+23-9
......@@ -82,6 +82,8 @@ static size_t io_thread_stack_size;
8282
8383static struct aio_queue *__aio_get_queue(int fd, int need)
8484{
85 sigset_t allmask, origmask;
86 int masked = 0;
8587 if (fd < 0) {
8688 errno = EBADF;
8789 return 0;
......@@ -93,6 +95,9 @@ static struct aio_queue *__aio_get_queue(int fd, int need)
9395 if ((!map || !map[a] || !map[a][b] || !map[a][b][c] || !(q=map[a][b][c][d])) && need) {
9496 pthread_rwlock_unlock(&maplock);
9597 if (fcntl(fd, F_GETFD) < 0) return 0;
98 sigfillset(&allmask);
99 masked = 1;
100 pthread_sigmask(SIG_BLOCK, &allmask, &origmask);
96101 pthread_rwlock_wrlock(&maplock);
97102 if (!io_thread_stack_size) {
98103 unsigned long val = __getauxval(AT_MINSIGSTKSZ);
......@@ -119,6 +124,7 @@ static struct aio_queue *__aio_get_queue(int fd, int need)
119124 if (q) pthread_mutex_lock(&q->lock);
120125out:
121126 pthread_rwlock_unlock(&maplock);
127 if (masked) pthread_sigmask(SIG_SETMASK, &origmask, 0);
122128 return q;
123129}
124130
......@@ -401,18 +407,26 @@ void __aio_atfork(int who)
401407 if (who<0) {
402408 pthread_rwlock_rdlock(&maplock);
403409 return;
410 } else if (!who) {
411 pthread_rwlock_unlock(&maplock);
412 return;
404413 }
405 if (who>0 && map) for (int a=0; a<(-1U/2+1)>>24; a++)
414 aio_fd_cnt = 0;
415 if (pthread_rwlock_tryrdlock(&maplock)) {
416 /* Obtaining lock may fail if _Fork was called nor via
417 * fork. In this case, no further aio is possible from
418 * child and we can just null out map so __aio_close
419 * does not attempt to do anything. */
420 map = 0;
421 return;
422 }
423 if (map) for (int a=0; a<(-1U/2+1)>>24; a++)
406424 if (map[a]) for (int b=0; b<256; b++)
407425 if (map[a][b]) for (int c=0; c<256; c++)
408426 if (map[a][b][c]) for (int d=0; d<256; d++)
409427 map[a][b][c][d] = 0;
410 pthread_rwlock_unlock(&maplock);
428 /* Re-initialize the rwlock rather than unlocking since there
429 * may have been more than one reference on it in the parent.
430 * We are not a lock holder anyway; the thread in the parent was. */
431 pthread_rwlock_init(&maplock, 0);
411432}
412
413weak_alias(aio_cancel, aio_cancel64);
414weak_alias(aio_error, aio_error64);
415weak_alias(aio_fsync, aio_fsync64);
416weak_alias(aio_read, aio_read64);
417weak_alias(aio_write, aio_write64);
418weak_alias(aio_return, aio_return64);
lib/libc/musl/src/aio/aio_suspend.c+1-5
......@@ -9,7 +9,7 @@ int aio_suspend(const struct aiocb *const cbs[], int cnt, const struct timespec
99{
1010 int i, tid = 0, ret, expect = 0;
1111 struct timespec at;
12 volatile int dummy_fut, *pfut;
12 volatile int dummy_fut = 0, *pfut;
1313 int nzcnt = 0;
1414 const struct aiocb *cb = 0;
1515
......@@ -73,7 +73,3 @@ int aio_suspend(const struct aiocb *const cbs[], int cnt, const struct timespec
7373 }
7474 }
7575}
76
77#if !_REDIR_TIME64
78weak_alias(aio_suspend, aio_suspend64);
79#endif
lib/libc/musl/src/aio/lio_listio.c-2
......@@ -139,5 +139,3 @@ int lio_listio(int mode, struct aiocb *restrict const *restrict cbs, int cnt, st
139139
140140 return 0;
141141}
142
143weak_alias(lio_listio, lio_listio64);
lib/libc/musl/src/conf/confstr.c+1-1
......@@ -7,7 +7,7 @@ size_t confstr(int name, char *buf, size_t len)
77 const char *s = "";
88 if (!name) {
99 s = "/bin:/usr/bin";
10 } else if ((name&~4U)!=1 && name-_CS_POSIX_V6_ILP32_OFF32_CFLAGS>33U) {
10 } else if ((name&~4U)!=1 && name-_CS_POSIX_V6_ILP32_OFF32_CFLAGS>35U) {
1111 errno = EINVAL;
1212 return 0;
1313 }
lib/libc/musl/src/conf/sysconf.c+13
......@@ -4,6 +4,7 @@
44#include <sys/resource.h>
55#include <signal.h>
66#include <sys/sysinfo.h>
7#include <sys/auxv.h>
78#include "syscall.h"
89#include "libc.h"
910
......@@ -19,6 +20,8 @@
1920#define JT_AVPHYS_PAGES JT(9)
2021#define JT_ZERO JT(10)
2122#define JT_DELAYTIMER_MAX JT(11)
23#define JT_MINSIGSTKSZ JT(12)
24#define JT_SIGSTKSZ JT(13)
2225
2326#define RLIM(x) (-32768|(RLIMIT_ ## x))
2427
......@@ -165,6 +168,9 @@ long sysconf(int name)
165168 [_SC_XOPEN_STREAMS] = JT_ZERO,
166169 [_SC_THREAD_ROBUST_PRIO_INHERIT] = -1,
167170 [_SC_THREAD_ROBUST_PRIO_PROTECT] = -1,
171
172 [_SC_MINSIGSTKSZ] = JT_MINSIGSTKSZ,
173 [_SC_SIGSTKSZ] = JT_SIGSTKSZ,
168174 };
169175
170176 if (name >= sizeof(values)/sizeof(values[0]) || !values[name]) {
......@@ -212,6 +218,13 @@ long sysconf(int name)
212218 mem *= si.mem_unit;
213219 mem /= PAGE_SIZE;
214220 return (mem > LONG_MAX) ? LONG_MAX : mem;
221 case JT_MINSIGSTKSZ & 255:
222 case JT_SIGSTKSZ & 255: ;
223 long val = __getauxval(AT_MINSIGSTKSZ);
224 if (val < MINSIGSTKSZ) val = MINSIGSTKSZ;
225 if (values[name] == JT_SIGSTKSZ)
226 val += SIGSTKSZ - MINSIGSTKSZ;
227 return val;
215228 case JT_ZERO & 255:
216229 return 0;
217230 }
lib/libc/musl/src/dirent/alphasort.c-2
......@@ -5,5 +5,3 @@ int alphasort(const struct dirent **a, const struct dirent **b)
55{
66 return strcoll((*a)->d_name, (*b)->d_name);
77}
8
9weak_alias(alphasort, alphasort64);
lib/libc/musl/src/dirent/readdir.c-2
......@@ -25,5 +25,3 @@ struct dirent *readdir(DIR *dir)
2525 dir->tell = de->d_off;
2626 return de;
2727}
28
29weak_alias(readdir, readdir64);
lib/libc/musl/src/dirent/readdir_r.c-2
......@@ -25,5 +25,3 @@ int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **re
2525 *result = buf;
2626 return 0;
2727}
28
29weak_alias(readdir_r, readdir64_r);
lib/libc/musl/src/dirent/scandir.c-2
......@@ -43,5 +43,3 @@ int scandir(const char *path, struct dirent ***res,
4343 *res = names;
4444 return cnt;
4545}
46
47weak_alias(scandir, scandir64);
lib/libc/musl/src/dirent/versionsort.c-3
......@@ -6,6 +6,3 @@ int versionsort(const struct dirent **a, const struct dirent **b)
66{
77 return strverscmp((*a)->d_name, (*b)->d_name);
88}
9
10#undef versionsort64
11weak_alias(versionsort, versionsort64);
lib/libc/musl/src/fcntl/creat.c-2
......@@ -4,5 +4,3 @@ int creat(const char *filename, mode_t mode)
44{
55 return open(filename, O_CREAT|O_WRONLY|O_TRUNC, mode);
66}
7
8weak_alias(creat, creat64);
lib/libc/musl/src/fcntl/open.c-2
......@@ -19,5 +19,3 @@ int open(const char *filename, int flags, ...)
1919
2020 return __syscall_ret(fd);
2121}
22
23weak_alias(open, open64);
lib/libc/musl/src/fcntl/openat.c-2
......@@ -15,5 +15,3 @@ int openat(int fd, const char *filename, int flags, ...)
1515
1616 return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode);
1717}
18
19weak_alias(openat, openat64);
lib/libc/musl/src/fcntl/posix_fadvise.c-2
......@@ -14,5 +14,3 @@ int posix_fadvise(int fd, off_t base, off_t len, int advice)
1414 __SYSCALL_LL_E(len), advice);
1515#endif
1616}
17
18weak_alias(posix_fadvise, posix_fadvise64);
lib/libc/musl/src/fcntl/posix_fallocate.c-2
......@@ -6,5 +6,3 @@ int posix_fallocate(int fd, off_t base, off_t len)
66 return -__syscall(SYS_fallocate, fd, 0, __SYSCALL_LL_E(base),
77 __SYSCALL_LL_E(len));
88}
9
10weak_alias(posix_fallocate, posix_fallocate64);
lib/libc/musl/src/include/sys/stat.h created+9
......@@ -0,0 +1,9 @@
1#ifndef SYS_STAT_H
2#define SYS_STAT_H
3
4#include "../../../include/sys/stat.h"
5
6hidden int __fstat(int, struct stat *);
7hidden int __fstatat(int, const char *restrict, struct stat *restrict, int);
8
9#endif
lib/libc/musl/src/internal/dynlink.h+5-1
......@@ -92,8 +92,12 @@ struct fdpic_dummy_loadmap {
9292#define DT_DEBUG_INDIRECT 0
9393#endif
9494
95#ifndef DT_DEBUG_INDIRECT_REL
96#define DT_DEBUG_INDIRECT_REL 0
97#endif
98
9599#define AUX_CNT 32
96#define DYN_CNT 32
100#define DYN_CNT 37
97101
98102typedef void (*stage2_func)(unsigned char *, size_t *);
99103
lib/libc/musl/src/internal/fork_impl.h+1-1
......@@ -2,7 +2,6 @@
22
33extern hidden volatile int *const __at_quick_exit_lockptr;
44extern hidden volatile int *const __atexit_lockptr;
5extern hidden volatile int *const __dlerror_lockptr;
65extern hidden volatile int *const __gettext_lockptr;
76extern hidden volatile int *const __locale_lockptr;
87extern hidden volatile int *const __random_lockptr;
......@@ -17,3 +16,4 @@ extern hidden volatile int *const __vmlock_lockptr;
1716
1817hidden void __malloc_atfork(int);
1918hidden void __ldso_atfork(int);
19hidden void __pthread_key_atfork(int);
lib/libc/musl/src/internal/ksigaction.h+5
......@@ -6,8 +6,13 @@
66struct k_sigaction {
77 void (*handler)(int);
88 unsigned long flags;
9#ifdef SA_RESTORER
910 void (*restorer)(void);
11#endif
1012 unsigned mask[2];
13#ifndef SA_RESTORER
14 void *unused;
15#endif
1116};
1217
1318hidden void __restore(), __restore_rt();
lib/libc/musl/src/internal/syscall.h+13-13
......@@ -58,7 +58,7 @@ hidden long __syscall_ret(unsigned long),
5858#define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__)
5959#define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__))
6060
61static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, long c, long d, long e, long f)
61static inline long __alt_socketcall(int sys, int sock, int cp, syscall_arg_t a, syscall_arg_t b, syscall_arg_t c, syscall_arg_t d, syscall_arg_t e, syscall_arg_t f)
6262{
6363 long r;
6464 if (cp) r = __syscall_cp(sys, a, b, c, d, e, f);
......@@ -71,9 +71,9 @@ static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, l
7171 return r;
7272}
7373#define __socketcall(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 0, \
74 (long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f))
74 __scc(a), __scc(b), __scc(c), __scc(d), __scc(e), __scc(f))
7575#define __socketcall_cp(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 1, \
76 (long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f))
76 __scc(a), __scc(b), __scc(c), __scc(d), __scc(e), __scc(f))
7777
7878/* fixup legacy 16-bit junk */
7979
......@@ -201,43 +201,43 @@ static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, l
201201#define SYS_sendfile SYS_sendfile64
202202#endif
203203
204#ifndef SYS_timer_settime
204#ifdef SYS_timer_settime32
205205#define SYS_timer_settime SYS_timer_settime32
206206#endif
207207
208#ifndef SYS_timer_gettime
208#ifdef SYS_timer_gettime32
209209#define SYS_timer_gettime SYS_timer_gettime32
210210#endif
211211
212#ifndef SYS_timerfd_settime
212#ifdef SYS_timerfd_settime32
213213#define SYS_timerfd_settime SYS_timerfd_settime32
214214#endif
215215
216#ifndef SYS_timerfd_gettime
216#ifdef SYS_timerfd_gettime32
217217#define SYS_timerfd_gettime SYS_timerfd_gettime32
218218#endif
219219
220#ifndef SYS_clock_settime
220#ifdef SYS_clock_settime32
221221#define SYS_clock_settime SYS_clock_settime32
222222#endif
223223
224#ifndef SYS_clock_gettime
224#ifdef SYS_clock_gettime32
225225#define SYS_clock_gettime SYS_clock_gettime32
226226#endif
227227
228#ifndef SYS_clock_getres
228#ifdef SYS_clock_getres_time32
229229#define SYS_clock_getres SYS_clock_getres_time32
230230#endif
231231
232#ifndef SYS_clock_nanosleep
232#ifdef SYS_clock_nanosleep_time32
233233#define SYS_clock_nanosleep SYS_clock_nanosleep_time32
234234#endif
235235
236#ifndef SYS_gettimeofday
236#ifdef SYS_gettimeofday_time32
237237#define SYS_gettimeofday SYS_gettimeofday_time32
238238#endif
239239
240#ifndef SYS_settimeofday
240#ifdef SYS_settimeofday_time32
241241#define SYS_settimeofday SYS_settimeofday_time32
242242#endif
243243
lib/libc/musl/src/internal/version.h+1-1
......@@ -1 +1 @@
1#define VERSION "1.2.3"
1#define VERSION "1.2.4"
lib/libc/musl/src/ipc/semtimedop.c+2-1
......@@ -7,7 +7,8 @@
77#define IS32BIT(x) !((x)+0x80000000ULL>>32)
88#define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63))
99
10#if !defined(SYS_semtimedop) && !defined(SYS_ipc)
10#if !defined(SYS_semtimedop) && !defined(SYS_ipc) || \
11 SYS_semtimedop == SYS_semtimedop_time64
1112#define NO_TIME32 1
1213#else
1314#define NO_TIME32 0
lib/libc/musl/src/ldso/dlerror.c+18-16
......@@ -3,8 +3,7 @@
33#include <stdarg.h>
44#include "pthread_impl.h"
55#include "dynlink.h"
6#include "lock.h"
7#include "fork_impl.h"
6#include "atomic.h"
87
98#define malloc __libc_malloc
109#define calloc __libc_calloc
......@@ -23,28 +22,31 @@ char *dlerror()
2322 return s;
2423}
2524
26static volatile int freebuf_queue_lock[1];
27static void **freebuf_queue;
28volatile int *const __dlerror_lockptr = freebuf_queue_lock;
25/* Atomic singly-linked list, used to store list of thread-local dlerror
26 * buffers for deferred free. They cannot be freed at thread exit time
27 * because, by the time it's known they can be freed, the exiting thread
28 * is in a highly restrictive context where it cannot call (even the
29 * libc-internal) free. It also can't take locks; thus the atomic list. */
30
31static void *volatile freebuf_queue;
2932
3033void __dl_thread_cleanup(void)
3134{
3235 pthread_t self = __pthread_self();
33 if (self->dlerror_buf && self->dlerror_buf != (void *)-1) {
34 LOCK(freebuf_queue_lock);
35 void **p = (void **)self->dlerror_buf;
36 *p = freebuf_queue;
37 freebuf_queue = p;
38 UNLOCK(freebuf_queue_lock);
39 }
36 if (!self->dlerror_buf || self->dlerror_buf == (void *)-1)
37 return;
38 void *h;
39 do {
40 h = freebuf_queue;
41 *(void **)self->dlerror_buf = h;
42 } while (a_cas_p(&freebuf_queue, h, self->dlerror_buf) != h);
4043}
4144
4245hidden void __dl_vseterr(const char *fmt, va_list ap)
4346{
44 LOCK(freebuf_queue_lock);
45 void **q = freebuf_queue;
46 freebuf_queue = 0;
47 UNLOCK(freebuf_queue_lock);
47 void **q;
48 do q = freebuf_queue;
49 while (q && a_cas_p(&freebuf_queue, q, 0) != q);
4850
4951 while (q) {
5052 void **p = *q;
lib/libc/musl/src/legacy/ftw.c-2
......@@ -7,5 +7,3 @@ int ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int
77 * actually undefined, but works on all real-world machines. */
88 return nftw(path, (int (*)())fn, fd_limit, FTW_PHYS);
99}
10
11weak_alias(ftw, ftw64);
lib/libc/musl/src/linux/epoll.c+1
......@@ -5,6 +5,7 @@
55
66int epoll_create(int size)
77{
8 if (size<=0) return __syscall_ret(-EINVAL);
89 return epoll_create1(0);
910}
1011
lib/libc/musl/src/linux/fallocate.c-3
......@@ -7,6 +7,3 @@ int fallocate(int fd, int mode, off_t base, off_t len)
77 return syscall(SYS_fallocate, fd, mode, __SYSCALL_LL_E(base),
88 __SYSCALL_LL_E(len));
99}
10
11#undef fallocate64
12weak_alias(fallocate, fallocate64);
lib/libc/musl/src/linux/getdents.c-2
......@@ -8,5 +8,3 @@ int getdents(int fd, struct dirent *buf, size_t len)
88 if (len>INT_MAX) len = INT_MAX;
99 return syscall(SYS_getdents, fd, buf, len);
1010}
11
12weak_alias(getdents, getdents64);
lib/libc/musl/src/linux/membarrier.c+1-1
......@@ -35,7 +35,7 @@ int __membarrier(int cmd, int flags)
3535 __tl_lock();
3636 sem_init(&barrier_sem, 0, 0);
3737 struct sigaction sa = {
38 .sa_flags = SA_RESTART,
38 .sa_flags = SA_RESTART | SA_ONSTACK,
3939 .sa_handler = bcast_barrier
4040 };
4141 memset(&sa.sa_mask, -1, sizeof sa.sa_mask);
lib/libc/musl/src/linux/prlimit.c-3
......@@ -21,6 +21,3 @@ int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlim
2121 }
2222 return r;
2323}
24
25#undef prlimit64
26weak_alias(prlimit, prlimit64);
lib/libc/musl/src/linux/sendfile.c-2
......@@ -5,5 +5,3 @@ ssize_t sendfile(int out_fd, int in_fd, off_t *ofs, size_t count)
55{
66 return syscall(SYS_sendfile, out_fd, in_fd, ofs, count);
77}
8
9weak_alias(sendfile, sendfile64);
lib/libc/musl/src/linux/wait4.c+1-1
......@@ -12,7 +12,7 @@ pid_t wait4(pid_t pid, int *status, int options, struct rusage *ru)
1212 if (ru) {
1313 long long kru64[18];
1414 r = __syscall(SYS_wait4_time64, pid, status, options, kru64);
15 if (!r) {
15 if (r > 0) {
1616 ru->ru_utime = (struct timeval)
1717 { .tv_sec = kru64[0], .tv_usec = kru64[1] };
1818 ru->ru_stime = (struct timeval)
lib/libc/musl/src/malloc/mallocng/free.c+1-1
......@@ -119,7 +119,7 @@ void free(void *p)
119119 if (((uintptr_t)(start-1) ^ (uintptr_t)end) >= 2*PGSZ && g->last_idx) {
120120 unsigned char *base = start + (-(uintptr_t)start & (PGSZ-1));
121121 size_t len = (end-base) & -PGSZ;
122 if (len) {
122 if (len && USE_MADV_FREE) {
123123 int e = errno;
124124 madvise(base, len, MADV_FREE);
125125 errno = e;
lib/libc/musl/src/malloc/mallocng/glue.h+2
......@@ -24,6 +24,8 @@
2424#define realloc __libc_realloc
2525#define free __libc_free
2626
27#define USE_MADV_FREE 0
28
2729#if USE_REAL_ASSERT
2830#include <assert.h>
2931#else
lib/libc/musl/src/math/logf.c+1-1
......@@ -53,7 +53,7 @@ float logf(float x)
5353 tmp = ix - OFF;
5454 i = (tmp >> (23 - LOGF_TABLE_BITS)) % N;
5555 k = (int32_t)tmp >> 23; /* arithmetic shift */
56 iz = ix - (tmp & 0x1ff << 23);
56 iz = ix - (tmp & 0xff800000);
5757 invc = T[i].invc;
5858 logc = T[i].logc;
5959 z = (double_t)asfloat(iz);
lib/libc/musl/src/misc/getopt.c+2-1
......@@ -87,7 +87,8 @@ int getopt(int argc, char * const argv[], const char *optstring)
8787 if (optstring[i] == ':') {
8888 optarg = 0;
8989 if (optstring[i+1] != ':' || optpos) {
90 optarg = argv[optind++] + optpos;
90 optarg = argv[optind++];
91 if (optpos) optarg += optpos;
9192 optpos = 0;
9293 }
9394 if (optind > argc) {
lib/libc/musl/src/misc/getrlimit.c+5-3
......@@ -6,12 +6,13 @@
66
77int getrlimit(int resource, struct rlimit *rlim)
88{
9 unsigned long k_rlim[2];
109 int ret = syscall(SYS_prlimit64, 0, resource, 0, rlim);
1110 if (!ret) {
1211 FIX(rlim->rlim_cur);
1312 FIX(rlim->rlim_max);
1413 }
14#ifdef SYS_getrlimit
15 unsigned long k_rlim[2];
1516 if (!ret || errno != ENOSYS)
1617 return ret;
1718 if (syscall(SYS_getrlimit, resource, k_rlim) < 0)
......@@ -21,6 +22,7 @@ int getrlimit(int resource, struct rlimit *rlim)
2122 FIX(rlim->rlim_cur);
2223 FIX(rlim->rlim_max);
2324 return 0;
25#else
26 return ret;
27#endif
2428}
25
26weak_alias(getrlimit, getrlimit64);
lib/libc/musl/src/misc/lockf.c-2
......@@ -28,5 +28,3 @@ int lockf(int fd, int op, off_t size)
2828 errno = EINVAL;
2929 return -1;
3030}
31
32weak_alias(lockf, lockf64);
lib/libc/musl/src/misc/mntent.c+9-3
......@@ -2,6 +2,7 @@
22#include <string.h>
33#include <mntent.h>
44#include <errno.h>
5#include <limits.h>
56
67static char *internal_buf;
78static size_t internal_bufsize;
......@@ -21,7 +22,8 @@ int endmntent(FILE *f)
2122
2223struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen)
2324{
24 int cnt, n[8], use_internal = (linebuf == SENTINEL);
25 int n[8], use_internal = (linebuf == SENTINEL);
26 size_t len, i;
2527
2628 mnt->mnt_freq = 0;
2729 mnt->mnt_passno = 0;
......@@ -39,10 +41,14 @@ struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int bufle
3941 errno = ERANGE;
4042 return 0;
4143 }
42 cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
44
45 len = strlen(linebuf);
46 if (len > INT_MAX) continue;
47 for (i = 0; i < sizeof n / sizeof *n; i++) n[i] = len;
48 sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d",
4349 n, n+1, n+2, n+3, n+4, n+5, n+6, n+7,
4450 &mnt->mnt_freq, &mnt->mnt_passno);
45 } while (cnt < 2 || linebuf[n[0]] == '#');
51 } while (linebuf[n[0]] == '#' || n[1]==len);
4652
4753 linebuf[n[1]] = 0;
4854 linebuf[n[3]] = 0;
lib/libc/musl/src/misc/nftw.c+3-3
......@@ -31,6 +31,8 @@ static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int,
3131 int err;
3232 struct FTW lev;
3333
34 st.st_dev = st.st_ino = 0;
35
3436 if ((flags & FTW_PHYS) ? lstat(path, &st) : stat(path, &st) < 0) {
3537 if (!(flags & FTW_PHYS) && errno==ENOENT && !lstat(path, &st))
3638 type = FTW_SLN;
......@@ -46,7 +48,7 @@ static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int,
4648 type = FTW_F;
4749 }
4850
49 if ((flags & FTW_MOUNT) && h && st.st_dev != h->dev)
51 if ((flags & FTW_MOUNT) && h && type != FTW_NS && st.st_dev != h->dev)
5052 return 0;
5153
5254 new.chain = h;
......@@ -138,5 +140,3 @@ int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, str
138140 pthread_setcancelstate(cs, 0);
139141 return r;
140142}
141
142weak_alias(nftw, nftw64);
lib/libc/musl/src/misc/setrlimit.c+6-2
......@@ -12,12 +12,14 @@ struct ctx {
1212 int err;
1313};
1414
15#ifdef SYS_setrlimit
1516static void do_setrlimit(void *p)
1617{
1718 struct ctx *c = p;
1819 if (c->err>0) return;
1920 c->err = -__syscall(SYS_setrlimit, c->res, c->lim);
2021}
22#endif
2123
2224int setrlimit(int resource, const struct rlimit *rlim)
2325{
......@@ -29,6 +31,7 @@ int setrlimit(int resource, const struct rlimit *rlim)
2931 rlim = &tmp;
3032 }
3133 int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0);
34#ifdef SYS_setrlimit
3235 if (ret != -ENOSYS) return __syscall_ret(ret);
3336
3437 struct ctx c = {
......@@ -42,6 +45,7 @@ int setrlimit(int resource, const struct rlimit *rlim)
4245 return -1;
4346 }
4447 return 0;
48#else
49 return __syscall_ret(ret);
50#endif
4551}
46
47weak_alias(setrlimit, setrlimit64);
lib/libc/musl/src/mman/mmap.c-2
......@@ -37,5 +37,3 @@ void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
3737}
3838
3939weak_alias(__mmap, mmap);
40
41weak_alias(mmap, mmap64);
lib/libc/musl/src/mq/mq_notify.c+33-14
......@@ -4,11 +4,14 @@
44#include <sys/socket.h>
55#include <signal.h>
66#include <unistd.h>
7#include <semaphore.h>
78#include "syscall.h"
89
910struct args {
10 pthread_barrier_t barrier;
11 sem_t sem;
1112 int sock;
13 mqd_t mqd;
14 int err;
1215 const struct sigevent *sev;
1316};
1417
......@@ -20,8 +23,19 @@ static void *start(void *p)
2023 int s = args->sock;
2124 void (*func)(union sigval) = args->sev->sigev_notify_function;
2225 union sigval val = args->sev->sigev_value;
26 struct sigevent sev2;
27 static const char zeros[32];
28 int err;
29
30 sev2.sigev_notify = SIGEV_THREAD;
31 sev2.sigev_signo = s;
32 sev2.sigev_value.sival_ptr = (void *)&zeros;
33
34 args->err = err = -__syscall(SYS_mq_notify, args->mqd, &sev2);
35 sem_post(&args->sem);
36 if (err) return 0;
2337
24 pthread_barrier_wait(&args->barrier);
38 pthread_detach(pthread_self());
2539 n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL);
2640 close(s);
2741 if (n==sizeof buf && buf[sizeof buf - 1] == 1)
......@@ -35,8 +49,8 @@ int mq_notify(mqd_t mqd, const struct sigevent *sev)
3549 pthread_attr_t attr;
3650 pthread_t td;
3751 int s;
38 struct sigevent sev2;
39 static const char zeros[32];
52 int cs;
53 sigset_t allmask, origmask;
4054
4155 if (!sev || sev->sigev_notify != SIGEV_THREAD)
4256 return syscall(SYS_mq_notify, mqd, sev);
......@@ -44,30 +58,35 @@ int mq_notify(mqd_t mqd, const struct sigevent *sev)
4458 s = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, 0);
4559 if (s < 0) return -1;
4660 args.sock = s;
61 args.mqd = mqd;
4762
4863 if (sev->sigev_notify_attributes) attr = *sev->sigev_notify_attributes;
4964 else pthread_attr_init(&attr);
50 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
51 pthread_barrier_init(&args.barrier, 0, 2);
65 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
66 sem_init(&args.sem, 0, 0);
5267
68 sigfillset(&allmask);
69 pthread_sigmask(SIG_BLOCK, &allmask, &origmask);
5370 if (pthread_create(&td, &attr, start, &args)) {
5471 __syscall(SYS_close, s);
72 pthread_sigmask(SIG_SETMASK, &origmask, 0);
5573 errno = EAGAIN;
5674 return -1;
5775 }
76 pthread_sigmask(SIG_SETMASK, &origmask, 0);
5877
59 pthread_barrier_wait(&args.barrier);
60 pthread_barrier_destroy(&args.barrier);
61
62 sev2.sigev_notify = SIGEV_THREAD;
63 sev2.sigev_signo = s;
64 sev2.sigev_value.sival_ptr = (void *)&zeros;
78 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
79 sem_wait(&args.sem);
80 sem_destroy(&args.sem);
6581
66 if (syscall(SYS_mq_notify, mqd, &sev2) < 0) {
67 pthread_cancel(td);
82 if (args.err) {
6883 __syscall(SYS_close, s);
84 pthread_join(td, 0);
85 pthread_setcancelstate(cs, 0);
86 errno = args.err;
6987 return -1;
7088 }
7189
90 pthread_setcancelstate(cs, 0);
7291 return 0;
7392}
lib/libc/musl/src/network/accept4.c+4
......@@ -9,6 +9,10 @@ int accept4(int fd, struct sockaddr *restrict addr, socklen_t *restrict len, int
99 if (!flg) return accept(fd, addr, len);
1010 int ret = socketcall_cp(accept4, fd, addr, len, flg, 0, 0);
1111 if (ret>=0 || (errno != ENOSYS && errno != EINVAL)) return ret;
12 if (flg & ~(SOCK_CLOEXEC|SOCK_NONBLOCK)) {
13 errno = EINVAL;
14 return -1;
15 }
1216 ret = accept(fd, addr, len);
1317 if (ret<0) return ret;
1418 if (flg & SOCK_CLOEXEC)
lib/libc/musl/src/network/dns_parse.c+5-5
......@@ -1,7 +1,7 @@
11#include <string.h>
22#include "lookup.h"
33
4int __dns_parse(const unsigned char *r, int rlen, int (*callback)(void *, int, const void *, int, const void *), void *ctx)
4int __dns_parse(const unsigned char *r, int rlen, int (*callback)(void *, int, const void *, int, const void *, int), void *ctx)
55{
66 int qdcount, ancount;
77 const unsigned char *p;
......@@ -15,18 +15,18 @@ int __dns_parse(const unsigned char *r, int rlen, int (*callback)(void *, int, c
1515 if (qdcount+ancount > 64) return -1;
1616 while (qdcount--) {
1717 while (p-r < rlen && *p-1U < 127) p++;
18 if (*p>193 || (*p==193 && p[1]>254) || p>r+rlen-6)
18 if (p>r+rlen-6 || *p>193 || (*p==193 && p[1]>254))
1919 return -1;
2020 p += 5 + !!*p;
2121 }
2222 while (ancount--) {
2323 while (p-r < rlen && *p-1U < 127) p++;
24 if (*p>193 || (*p==193 && p[1]>254) || p>r+rlen-6)
24 if (p>r+rlen-12 || *p>193 || (*p==193 && p[1]>254))
2525 return -1;
2626 p += 1 + !!*p;
2727 len = p[8]*256 + p[9];
28 if (p+len > r+rlen) return -1;
29 if (callback(ctx, p[1], p+10, len, r) < 0) return -1;
28 if (len+10 > r+rlen-p) return -1;
29 if (callback(ctx, p[1], p+10, len, r, rlen) < 0) return -1;
3030 p += 10 + len;
3131 }
3232 return 0;
lib/libc/musl/src/network/gai_strerror.c+1-1
......@@ -6,7 +6,7 @@ static const char msgs[] =
66 "Name does not resolve\0"
77 "Try again\0"
88 "Non-recoverable error\0"
9 "Unknown error\0"
9 "Name has no usable address\0"
1010 "Unrecognized address family or invalid length\0"
1111 "Unrecognized socket type\0"
1212 "Unrecognized service\0"
lib/libc/musl/src/network/getaddrinfo.c+6-1
......@@ -16,6 +16,7 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru
1616 char canon[256], *outcanon;
1717 int nservs, naddrs, nais, canon_len, i, j, k;
1818 int family = AF_UNSPEC, flags = 0, proto = 0, socktype = 0;
19 int no_family = 0;
1920 struct aibuf *out;
2021
2122 if (!host && !serv) return EAI_NONAME;
......@@ -66,9 +67,11 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru
6667 pthread_setcancelstate(
6768 PTHREAD_CANCEL_DISABLE, &cs);
6869 int r = connect(s, ta[i], tl[i]);
70 int saved_errno = errno;
6971 pthread_setcancelstate(cs, 0);
7072 close(s);
7173 if (!r) continue;
74 errno = saved_errno;
7275 }
7376 switch (errno) {
7477 case EADDRNOTAVAIL:
......@@ -80,7 +83,7 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru
8083 default:
8184 return EAI_SYSTEM;
8285 }
83 if (family == tf[i]) return EAI_NONAME;
86 if (family == tf[i]) no_family = 1;
8487 family = tf[1-i];
8588 }
8689 }
......@@ -91,6 +94,8 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru
9194 naddrs = __lookup_name(addrs, canon, host, family, flags);
9295 if (naddrs < 0) return naddrs;
9396
97 if (no_family) return EAI_NODATA;
98
9499 nais = nservs * naddrs;
95100 canon_len = strlen(canon);
96101 out = calloc(1, nais * sizeof(*out) + canon_len + 1);
lib/libc/musl/src/network/gethostbyaddr.c+1-1
......@@ -20,5 +20,5 @@ struct hostent *gethostbyaddr(const void *a, socklen_t l, int af)
2020 err = gethostbyaddr_r(a, l, af, h,
2121 (void *)(h+1), size-sizeof *h, &res, &h_errno);
2222 } while (err == ERANGE);
23 return err ? 0 : h;
23 return res;
2424}
lib/libc/musl/src/network/gethostbyaddr_r.c+3-2
......@@ -54,9 +54,10 @@ int gethostbyaddr_r(const void *a, socklen_t l, int af,
5454 case EAI_OVERFLOW:
5555 return ERANGE;
5656 default:
57 case EAI_MEMORY:
58 case EAI_SYSTEM:
5957 case EAI_FAIL:
58 *err = NO_RECOVERY;
59 return EBADMSG;
60 case EAI_SYSTEM:
6061 *err = NO_RECOVERY;
6162 return errno;
6263 case 0:
lib/libc/musl/src/network/gethostbyname2.c+1-1
......@@ -21,5 +21,5 @@ struct hostent *gethostbyname2(const char *name, int af)
2121 err = gethostbyname2_r(name, af, h,
2222 (void *)(h+1), size-sizeof *h, &res, &h_errno);
2323 } while (err == ERANGE);
24 return err ? 0 : h;
24 return res;
2525}
lib/libc/musl/src/network/gethostbyname2_r.c+4-2
......@@ -22,7 +22,10 @@ int gethostbyname2_r(const char *name, int af,
2222 if (cnt<0) switch (cnt) {
2323 case EAI_NONAME:
2424 *err = HOST_NOT_FOUND;
25 return ENOENT;
25 return 0;
26 case EAI_NODATA:
27 *err = NO_DATA;
28 return 0;
2629 case EAI_AGAIN:
2730 *err = TRY_AGAIN;
2831 return EAGAIN;
......@@ -30,7 +33,6 @@ int gethostbyname2_r(const char *name, int af,
3033 case EAI_FAIL:
3134 *err = NO_RECOVERY;
3235 return EBADMSG;
33 case EAI_MEMORY:
3436 case EAI_SYSTEM:
3537 *err = NO_RECOVERY;
3638 return errno;
lib/libc/musl/src/network/getifaddrs.c+7-7
......@@ -39,8 +39,8 @@ struct ifaddrs_storage {
3939};
4040
4141struct ifaddrs_ctx {
42 struct ifaddrs_storage *first;
43 struct ifaddrs_storage *last;
42 struct ifaddrs *first;
43 struct ifaddrs *last;
4444 struct ifaddrs_storage *hash[IFADDRS_HASH_SIZE];
4545};
4646
......@@ -195,9 +195,9 @@ static int netlink_msg_to_ifaddr(void *pctx, struct nlmsghdr *h)
195195 }
196196
197197 if (ifs->ifa.ifa_name) {
198 if (!ctx->first) ctx->first = ifs;
199 if (ctx->last) ctx->last->ifa.ifa_next = &ifs->ifa;
200 ctx->last = ifs;
198 if (!ctx->first) ctx->first = &ifs->ifa;
199 if (ctx->last) ctx->last->ifa_next = &ifs->ifa;
200 ctx->last = &ifs->ifa;
201201 } else {
202202 free(ifs);
203203 }
......@@ -210,7 +210,7 @@ int getifaddrs(struct ifaddrs **ifap)
210210 int r;
211211 memset(ctx, 0, sizeof *ctx);
212212 r = __rtnetlink_enumerate(AF_UNSPEC, AF_UNSPEC, netlink_msg_to_ifaddr, ctx);
213 if (r == 0) *ifap = &ctx->first->ifa;
214 else freeifaddrs(&ctx->first->ifa);
213 if (r == 0) *ifap = ctx->first;
214 else freeifaddrs(ctx->first);
215215 return r;
216216}
lib/libc/musl/src/network/getnameinfo.c+3-2
......@@ -58,6 +58,7 @@ static void reverse_hosts(char *buf, const unsigned char *a, unsigned scopeid, i
5858 if ((p=strchr(line, '#'))) *p++='\n', *p=0;
5959
6060 for (p=line; *p && !isspace(*p); p++);
61 if (!*p) continue;
6162 *p++ = 0;
6263 if (__lookup_ipliteral(&iplit, line, AF_UNSPEC)<=0)
6364 continue;
......@@ -108,10 +109,10 @@ static void reverse_services(char *buf, int port, int dgram)
108109 __fclose_ca(f);
109110}
110111
111static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet)
112static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet, int plen)
112113{
113114 if (rr != RR_PTR) return 0;
114 if (__dn_expand(packet, (const unsigned char *)packet + 512,
115 if (__dn_expand(packet, (const unsigned char *)packet + plen,
115116 data, c, 256) <= 0)
116117 *(char *)c = 0;
117118 return 0;
lib/libc/musl/src/network/getservbyport_r.c+3-1
......@@ -26,7 +26,7 @@ int getservbyport_r(int port, const char *prots,
2626 /* Align buffer */
2727 i = (uintptr_t)buf & sizeof(char *)-1;
2828 if (!i) i = sizeof(char *);
29 if (buflen < 3*sizeof(char *)-i)
29 if (buflen <= 3*sizeof(char *)-i)
3030 return ERANGE;
3131 buf += sizeof(char *)-i;
3232 buflen -= sizeof(char *)-i;
......@@ -46,6 +46,8 @@ int getservbyport_r(int port, const char *prots,
4646 case EAI_MEMORY:
4747 case EAI_SYSTEM:
4848 return ENOMEM;
49 case EAI_OVERFLOW:
50 return ERANGE;
4951 default:
5052 return ENOENT;
5153 case 0:
lib/libc/musl/src/network/inet_pton.c+1
......@@ -54,6 +54,7 @@ int inet_pton(int af, const char *restrict s, void *restrict a0)
5454 if (s[j]!='.' || (i<6 && brk<0)) return 0;
5555 need_v4=1;
5656 i++;
57 ip[i&7]=0;
5758 break;
5859 }
5960 s += j+1;
lib/libc/musl/src/network/lookup.h+1-1
......@@ -50,6 +50,6 @@ hidden int __lookup_ipliteral(struct address buf[static 1], const char *name, in
5050hidden int __get_resolv_conf(struct resolvconf *, char *, size_t);
5151hidden int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *);
5252
53hidden int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *), void *);
53hidden int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *, int), void *);
5454
5555#endif
lib/libc/musl/src/network/lookup_ipliteral.c+2-2
......@@ -15,7 +15,7 @@ int __lookup_ipliteral(struct address buf[static 1], const char *name, int famil
1515 struct in6_addr a6;
1616 if (__inet_aton(name, &a4) > 0) {
1717 if (family == AF_INET6) /* wrong family */
18 return EAI_NONAME;
18 return EAI_NODATA;
1919 memcpy(&buf[0].addr, &a4, sizeof a4);
2020 buf[0].family = AF_INET;
2121 buf[0].scopeid = 0;
......@@ -34,7 +34,7 @@ int __lookup_ipliteral(struct address buf[static 1], const char *name, int famil
3434 if (inet_pton(AF_INET6, name, &a6) <= 0)
3535 return 0;
3636 if (family == AF_INET) /* wrong family */
37 return EAI_NONAME;
37 return EAI_NODATA;
3838
3939 memcpy(&buf[0].addr, &a6, sizeof a6);
4040 buf[0].family = AF_INET6;
lib/libc/musl/src/network/lookup_name.c+31-19
......@@ -79,7 +79,7 @@ static int name_from_hosts(struct address buf[static MAXADDRS], char canon[stati
7979 case 0:
8080 continue;
8181 default:
82 badfam = EAI_NONAME;
82 badfam = EAI_NODATA;
8383 break;
8484 }
8585
......@@ -102,45 +102,50 @@ struct dpc_ctx {
102102 struct address *addrs;
103103 char *canon;
104104 int cnt;
105 int rrtype;
105106};
106107
107108#define RR_A 1
108109#define RR_CNAME 5
109110#define RR_AAAA 28
110111
111static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet)
112#define ABUF_SIZE 768
113
114static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet, int plen)
112115{
113116 char tmp[256];
117 int family;
114118 struct dpc_ctx *ctx = c;
115 if (ctx->cnt >= MAXADDRS) return -1;
119 if (rr == RR_CNAME) {
120 if (__dn_expand(packet, (const unsigned char *)packet + plen,
121 data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp))
122 strcpy(ctx->canon, tmp);
123 return 0;
124 }
125 if (ctx->cnt >= MAXADDRS) return 0;
126 if (rr != ctx->rrtype) return 0;
116127 switch (rr) {
117128 case RR_A:
118129 if (len != 4) return -1;
119 ctx->addrs[ctx->cnt].family = AF_INET;
120 ctx->addrs[ctx->cnt].scopeid = 0;
121 memcpy(ctx->addrs[ctx->cnt++].addr, data, 4);
130 family = AF_INET;
122131 break;
123132 case RR_AAAA:
124133 if (len != 16) return -1;
125 ctx->addrs[ctx->cnt].family = AF_INET6;
126 ctx->addrs[ctx->cnt].scopeid = 0;
127 memcpy(ctx->addrs[ctx->cnt++].addr, data, 16);
128 break;
129 case RR_CNAME:
130 if (__dn_expand(packet, (const unsigned char *)packet + 512,
131 data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp))
132 strcpy(ctx->canon, tmp);
134 family = AF_INET6;
133135 break;
134136 }
137 ctx->addrs[ctx->cnt].family = family;
138 ctx->addrs[ctx->cnt].scopeid = 0;
139 memcpy(ctx->addrs[ctx->cnt++].addr, data, len);
135140 return 0;
136141}
137142
138143static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf)
139144{
140 unsigned char qbuf[2][280], abuf[2][512];
145 unsigned char qbuf[2][280], abuf[2][ABUF_SIZE];
141146 const unsigned char *qp[2] = { qbuf[0], qbuf[1] };
142147 unsigned char *ap[2] = { abuf[0], abuf[1] };
143 int qlens[2], alens[2];
148 int qlens[2], alens[2], qtypes[2];
144149 int i, nq = 0;
145150 struct dpc_ctx ctx = { .addrs = buf, .canon = canon };
146151 static const struct { int af; int rr; } afrr[2] = {
......@@ -153,8 +158,12 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static
153158 qlens[nq] = __res_mkquery(0, name, 1, afrr[i].rr,
154159 0, 0, 0, qbuf[nq], sizeof *qbuf);
155160 if (qlens[nq] == -1)
156 return EAI_NONAME;
161 return 0;
162 qtypes[nq] = afrr[i].rr;
157163 qbuf[nq][3] = 0; /* don't need AD flag */
164 /* Ensure query IDs are distinct. */
165 if (nq && qbuf[nq][0] == qbuf[0][0])
166 qbuf[nq][0]++;
158167 nq++;
159168 }
160169 }
......@@ -168,11 +177,14 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static
168177 if ((abuf[i][3] & 15) != 0) return EAI_FAIL;
169178 }
170179
171 for (i=0; i<nq; i++)
180 for (i=nq-1; i>=0; i--) {
181 ctx.rrtype = qtypes[i];
182 if (alens[i] > sizeof(abuf[i])) alens[i] = sizeof abuf[i];
172183 __dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx);
184 }
173185
174186 if (ctx.cnt) return ctx.cnt;
175 return EAI_NONAME;
187 return EAI_NODATA;
176188}
177189
178190static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
lib/libc/musl/src/network/netlink.h+1-1
......@@ -86,7 +86,7 @@ struct ifaddrmsg {
8686#define RTA_DATALEN(rta) ((rta)->rta_len-sizeof(struct rtattr))
8787#define RTA_DATAEND(rta) ((char*)(rta)+(rta)->rta_len)
8888#define RTA_NEXT(rta) (struct rtattr*)((char*)(rta)+NETLINK_ALIGN((rta)->rta_len))
89#define RTA_OK(nlh,end) ((char*)(end)-(char*)(rta) >= sizeof(struct rtattr))
89#define RTA_OK(rta,end) ((char*)(end)-(char*)(rta) >= sizeof(struct rtattr))
9090
9191#define NLMSG_RTA(nlh,len) ((void*)((char*)(nlh)+sizeof(struct nlmsghdr)+NETLINK_ALIGN(len)))
9292#define NLMSG_RTAOK(rta,nlh) RTA_OK(rta,NLMSG_DATAEND(nlh))
lib/libc/musl/src/network/res_mkquery.c+1
......@@ -13,6 +13,7 @@ int __res_mkquery(int op, const char *dname, int class, int type,
1313 int n;
1414
1515 if (l && dname[l-1]=='.') l--;
16 if (l && dname[l-1]=='.') return -1;
1617 n = 17+l+!!l;
1718 if (l>253 || buflen<n || op>15u || class>255u || type>255u)
1819 return -1;
lib/libc/musl/src/network/res_msend.c+160-23
......@@ -1,5 +1,6 @@
11#include <sys/socket.h>
22#include <netinet/in.h>
3#include <netinet/tcp.h>
34#include <netdb.h>
45#include <arpa/inet.h>
56#include <stdint.h>
......@@ -16,17 +17,65 @@
1617
1718static void cleanup(void *p)
1819{
19 __syscall(SYS_close, (intptr_t)p);
20 struct pollfd *pfd = p;
21 for (int i=0; pfd[i].fd >= -1; i++)
22 if (pfd[i].fd >= 0) __syscall(SYS_close, pfd[i].fd);
2023}
2124
2225static unsigned long mtime()
2326{
2427 struct timespec ts;
25 clock_gettime(CLOCK_REALTIME, &ts);
28 if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0 && errno == ENOSYS)
29 clock_gettime(CLOCK_REALTIME, &ts);
2630 return (unsigned long)ts.tv_sec * 1000
2731 + ts.tv_nsec / 1000000;
2832}
2933
34static int start_tcp(struct pollfd *pfd, int family, const void *sa, socklen_t sl, const unsigned char *q, int ql)
35{
36 struct msghdr mh = {
37 .msg_name = (void *)sa,
38 .msg_namelen = sl,
39 .msg_iovlen = 2,
40 .msg_iov = (struct iovec [2]){
41 { .iov_base = (uint8_t[]){ ql>>8, ql }, .iov_len = 2 },
42 { .iov_base = (void *)q, .iov_len = ql } }
43 };
44 int r;
45 int fd = socket(family, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
46 pfd->fd = fd;
47 pfd->events = POLLOUT;
48 if (!setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
49 &(int){1}, sizeof(int))) {
50 r = sendmsg(fd, &mh, MSG_FASTOPEN|MSG_NOSIGNAL);
51 if (r == ql+2) pfd->events = POLLIN;
52 if (r >= 0) return r;
53 if (errno == EINPROGRESS) return 0;
54 }
55 r = connect(fd, sa, sl);
56 if (!r || errno == EINPROGRESS) return 0;
57 close(fd);
58 pfd->fd = -1;
59 return -1;
60}
61
62static void step_mh(struct msghdr *mh, size_t n)
63{
64 /* Adjust iovec in msghdr to skip first n bytes. */
65 while (mh->msg_iovlen && n >= mh->msg_iov->iov_len) {
66 n -= mh->msg_iov->iov_len;
67 mh->msg_iov++;
68 mh->msg_iovlen--;
69 }
70 if (!mh->msg_iovlen) return;
71 mh->msg_iov->iov_base = (char *)mh->msg_iov->iov_base + n;
72 mh->msg_iov->iov_len -= n;
73}
74
75/* Internal contract for __res_msend[_rc]: asize must be >=512, nqueries
76 * must be sufficiently small to be safe as VLA size. In practice it's
77 * either 1 or 2, anyway. */
78
3079int __res_msend_rc(int nqueries, const unsigned char *const *queries,
3180 const int *qlens, unsigned char *const *answers, int *alens, int asize,
3281 const struct resolvconf *conf)
......@@ -44,7 +93,10 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
4493 int next;
4594 int i, j;
4695 int cs;
47 struct pollfd pfd;
96 struct pollfd pfd[nqueries+2];
97 int qpos[nqueries], apos[nqueries];
98 unsigned char alen_buf[nqueries][2];
99 int r;
48100 unsigned long t0, t1, t2;
49101
50102 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
......@@ -68,29 +120,22 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
68120 }
69121
70122 /* Get local address and open/bind a socket */
71 sa.sin.sin_family = family;
72123 fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
73124
74125 /* Handle case where system lacks IPv6 support */
75126 if (fd < 0 && family == AF_INET6 && errno == EAFNOSUPPORT) {
127 for (i=0; i<nns && conf->ns[nns].family == AF_INET6; i++);
128 if (i==nns) {
129 pthread_setcancelstate(cs, 0);
130 return -1;
131 }
76132 fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
77133 family = AF_INET;
134 sl = sizeof sa.sin;
78135 }
79 if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) {
80 if (fd >= 0) close(fd);
81 pthread_setcancelstate(cs, 0);
82 return -1;
83 }
84
85 /* Past this point, there are no errors. Each individual query will
86 * yield either no reply (indicated by zero length) or an answer
87 * packet which is up to the caller to interpret. */
88
89 pthread_cleanup_push(cleanup, (void *)(intptr_t)fd);
90 pthread_setcancelstate(cs, 0);
91136
92137 /* Convert any IPv4 addresses in a mixed environment to v4-mapped */
93 if (family == AF_INET6) {
138 if (fd >= 0 && family == AF_INET6) {
94139 setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0);
95140 for (i=0; i<nns; i++) {
96141 if (ns[i].sin.sin_family != AF_INET) continue;
......@@ -104,16 +149,38 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
104149 }
105150 }
106151
152 sa.sin.sin_family = family;
153 if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) {
154 if (fd >= 0) close(fd);
155 pthread_setcancelstate(cs, 0);
156 return -1;
157 }
158
159 /* Past this point, there are no errors. Each individual query will
160 * yield either no reply (indicated by zero length) or an answer
161 * packet which is up to the caller to interpret. */
162
163 for (i=0; i<nqueries; i++) pfd[i].fd = -1;
164 pfd[nqueries].fd = fd;
165 pfd[nqueries].events = POLLIN;
166 pfd[nqueries+1].fd = -2;
167
168 pthread_cleanup_push(cleanup, pfd);
169 pthread_setcancelstate(cs, 0);
170
107171 memset(alens, 0, sizeof *alens * nqueries);
108172
109 pfd.fd = fd;
110 pfd.events = POLLIN;
111173 retry_interval = timeout / attempts;
112174 next = 0;
113175 t0 = t2 = mtime();
114176 t1 = t2 - retry_interval;
115177
116178 for (; t2-t0 < timeout; t2=mtime()) {
179 /* This is the loop exit condition: that all queries
180 * have an accepted answer. */
181 for (i=0; i<nqueries && alens[i]>0; i++);
182 if (i==nqueries) break;
183
117184 if (t2-t1 >= retry_interval) {
118185 /* Query all configured namservers in parallel */
119186 for (i=0; i<nqueries; i++)
......@@ -127,10 +194,20 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
127194 }
128195
129196 /* Wait for a response, or until time to retry */
130 if (poll(&pfd, 1, t1+retry_interval-t2) <= 0) continue;
197 if (poll(pfd, nqueries+1, t1+retry_interval-t2) <= 0) continue;
131198
132 while ((rlen = recvfrom(fd, answers[next], asize, 0,
133 (void *)&sa, (socklen_t[1]){sl})) >= 0) {
199 while (next < nqueries) {
200 struct msghdr mh = {
201 .msg_name = (void *)&sa,
202 .msg_namelen = sl,
203 .msg_iovlen = 1,
204 .msg_iov = (struct iovec []){
205 { .iov_base = (void *)answers[next],
206 .iov_len = asize }
207 }
208 };
209 rlen = recvmsg(fd, &mh, 0);
210 if (rlen < 0) break;
134211
135212 /* Ignore non-identifiable packets */
136213 if (rlen < 4) continue;
......@@ -170,12 +247,72 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
170247 else
171248 memcpy(answers[i], answers[next], rlen);
172249
173 if (next == nqueries) goto out;
250 /* Ignore further UDP if all slots full or TCP-mode */
251 if (next == nqueries) pfd[nqueries].events = 0;
252
253 /* If answer is truncated (TC bit), fallback to TCP */
254 if ((answers[i][2] & 2) || (mh.msg_flags & MSG_TRUNC)) {
255 alens[i] = -1;
256 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);
257 r = start_tcp(pfd+i, family, ns+j, sl, queries[i], qlens[i]);
258 pthread_setcancelstate(cs, 0);
259 if (r >= 0) {
260 qpos[i] = r;
261 apos[i] = 0;
262 }
263 continue;
264 }
265 }
266
267 for (i=0; i<nqueries; i++) if (pfd[i].revents & POLLOUT) {
268 struct msghdr mh = {
269 .msg_iovlen = 2,
270 .msg_iov = (struct iovec [2]){
271 { .iov_base = (uint8_t[]){ qlens[i]>>8, qlens[i] }, .iov_len = 2 },
272 { .iov_base = (void *)queries[i], .iov_len = qlens[i] } }
273 };
274 step_mh(&mh, qpos[i]);
275 r = sendmsg(pfd[i].fd, &mh, MSG_NOSIGNAL);
276 if (r < 0) goto out;
277 qpos[i] += r;
278 if (qpos[i] == qlens[i]+2)
279 pfd[i].events = POLLIN;
280 }
281
282 for (i=0; i<nqueries; i++) if (pfd[i].revents & POLLIN) {
283 struct msghdr mh = {
284 .msg_iovlen = 2,
285 .msg_iov = (struct iovec [2]){
286 { .iov_base = alen_buf[i], .iov_len = 2 },
287 { .iov_base = answers[i], .iov_len = asize } }
288 };
289 step_mh(&mh, apos[i]);
290 r = recvmsg(pfd[i].fd, &mh, 0);
291 if (r <= 0) goto out;
292 apos[i] += r;
293 if (apos[i] < 2) continue;
294 int alen = alen_buf[i][0]*256 + alen_buf[i][1];
295 if (alen < 13) goto out;
296 if (apos[i] < alen+2 && apos[i] < asize+2)
297 continue;
298 int rcode = answers[i][3] & 15;
299 if (rcode != 0 && rcode != 3)
300 goto out;
301
302 /* Storing the length here commits the accepted answer.
303 * Immediately close TCP socket so as not to consume
304 * resources we no longer need. */
305 alens[i] = alen;
306 __syscall(SYS_close, pfd[i].fd);
307 pfd[i].fd = -1;
174308 }
175309 }
176310out:
177311 pthread_cleanup_pop(1);
178312
313 /* Disregard any incomplete TCP results */
314 for (i=0; i<nqueries; i++) if (alens[i]<0) alens[i] = 0;
315
179316 return 0;
180317}
181318
lib/libc/musl/src/network/res_send.c+9-1
......@@ -1,8 +1,16 @@
11#include <resolv.h>
2#include <string.h>
23
34int __res_send(const unsigned char *msg, int msglen, unsigned char *answer, int anslen)
45{
5 int r = __res_msend(1, &msg, &msglen, &answer, &anslen, anslen);
6 int r;
7 if (anslen < 512) {
8 unsigned char buf[512];
9 r = __res_send(msg, msglen, buf, sizeof buf);
10 if (r >= 0) memcpy(answer, buf, r < anslen ? r : anslen);
11 return r;
12 }
13 r = __res_msend(1, &msg, &msglen, &answer, &anslen, anslen);
614 return r<0 || !anslen ? -1 : anslen;
715}
816
lib/libc/musl/src/network/sendmsg.c+5-2
......@@ -8,13 +8,16 @@ ssize_t sendmsg(int fd, const struct msghdr *msg, int flags)
88{
99#if LONG_MAX > INT_MAX
1010 struct msghdr h;
11 struct cmsghdr chbuf[1024/sizeof(struct cmsghdr)+1], *c;
11 /* Kernels before 2.6.38 set SCM_MAX_FD to 255, allocate enough
12 * space to support an SCM_RIGHTS ancillary message with 255 fds.
13 * Kernels since 2.6.38 set SCM_MAX_FD to 253. */
14 struct cmsghdr chbuf[CMSG_SPACE(255*sizeof(int))/sizeof(struct cmsghdr)+1], *c;
1215 if (msg) {
1316 h = *msg;
1417 h.__pad1 = h.__pad2 = 0;
1518 msg = &h;
1619 if (h.msg_controllen) {
17 if (h.msg_controllen > 1024) {
20 if (h.msg_controllen > sizeof chbuf) {
1821 errno = ENOMEM;
1922 return -1;
2023 }
lib/libc/musl/src/process/_Fork.c+1-2
......@@ -14,7 +14,6 @@ pid_t _Fork(void)
1414 pid_t ret;
1515 sigset_t set;
1616 __block_all_sigs(&set);
17 __aio_atfork(-1);
1817 LOCK(__abort_lock);
1918#ifdef SYS_fork
2019 ret = __syscall(SYS_fork);
......@@ -32,7 +31,7 @@ pid_t _Fork(void)
3231 if (libc.need_locks) libc.need_locks = -1;
3332 }
3433 UNLOCK(__abort_lock);
35 __aio_atfork(!ret);
34 if (!ret) __aio_atfork(1);
3635 __restore_sigs(&set);
3736 return __syscall_ret(ret);
3837}
lib/libc/musl/src/process/aarch64/vfork.s created+9
......@@ -0,0 +1,9 @@
1.global vfork
2.type vfork,%function
3vfork:
4 mov x8, 220 // SYS_clone
5 mov x0, 0x4111 // SIGCHLD | CLONE_VM | CLONE_VFORK
6 mov x1, 0
7 svc 0
8 .hidden __syscall_ret
9 b __syscall_ret
lib/libc/musl/src/process/fork.c+6-2
......@@ -9,7 +9,6 @@ static volatile int *const dummy_lockptr = 0;
99
1010weak_alias(dummy_lockptr, __at_quick_exit_lockptr);
1111weak_alias(dummy_lockptr, __atexit_lockptr);
12weak_alias(dummy_lockptr, __dlerror_lockptr);
1312weak_alias(dummy_lockptr, __gettext_lockptr);
1413weak_alias(dummy_lockptr, __locale_lockptr);
1514weak_alias(dummy_lockptr, __random_lockptr);
......@@ -24,7 +23,6 @@ weak_alias(dummy_lockptr, __vmlock_lockptr);
2423static volatile int *const *const atfork_locks[] = {
2524 &__at_quick_exit_lockptr,
2625 &__atexit_lockptr,
27 &__dlerror_lockptr,
2826 &__gettext_lockptr,
2927 &__locale_lockptr,
3028 &__random_lockptr,
......@@ -38,6 +36,8 @@ static volatile int *const *const atfork_locks[] = {
3836static void dummy(int x) { }
3937weak_alias(dummy, __fork_handler);
4038weak_alias(dummy, __malloc_atfork);
39weak_alias(dummy, __aio_atfork);
40weak_alias(dummy, __pthread_key_atfork);
4141weak_alias(dummy, __ldso_atfork);
4242
4343static void dummy_0(void) { }
......@@ -52,6 +52,8 @@ pid_t fork(void)
5252 int need_locks = libc.need_locks > 0;
5353 if (need_locks) {
5454 __ldso_atfork(-1);
55 __pthread_key_atfork(-1);
56 __aio_atfork(-1);
5557 __inhibit_ptc();
5658 for (int i=0; i<sizeof atfork_locks/sizeof *atfork_locks; i++)
5759 if (*atfork_locks[i]) LOCK(*atfork_locks[i]);
......@@ -77,6 +79,8 @@ pid_t fork(void)
7779 if (ret) UNLOCK(*atfork_locks[i]);
7880 else **atfork_locks[i] = 0;
7981 __release_ptc();
82 if (ret) __aio_atfork(0);
83 __pthread_key_atfork(!ret);
8084 __ldso_atfork(!ret);
8185 }
8286 __restore_sigs(&set);
lib/libc/musl/src/process/riscv64/vfork.s created+12
......@@ -0,0 +1,12 @@
1.global vfork
2.type vfork,@function
3vfork:
4 /* riscv does not have SYS_vfork, so we must use clone instead */
5 /* note: riscv's clone = clone(flags, sp, ptidptr, tls, ctidptr) */
6 li a7, 220
7 li a0, 0x100 | 0x4000 | 17 /* flags = CLONE_VM | CLONE_VFORK | SIGCHLD */
8 mv a1, sp
9 /* the other arguments are ignoreable */
10 ecall
11 .hidden __syscall_ret
12 j __syscall_ret
lib/libc/musl/src/regex/glob.c-3
......@@ -306,6 +306,3 @@ void globfree(glob_t *g)
306306 g->gl_pathc = 0;
307307 g->gl_pathv = NULL;
308308}
309
310weak_alias(glob, glob64);
311weak_alias(globfree, globfree64);
lib/libc/musl/src/search/hsearch.c+2-2
......@@ -41,9 +41,9 @@ static int resize(size_t nel, struct hsearch_data *htab)
4141{
4242 size_t newsize;
4343 size_t i, j;
44 size_t oldsize = htab->__tab->mask + 1;
4445 ENTRY *e, *newe;
4546 ENTRY *oldtab = htab->__tab->entries;
46 ENTRY *oldend = htab->__tab->entries + htab->__tab->mask + 1;
4747
4848 if (nel > MAXSIZE)
4949 nel = MAXSIZE;
......@@ -56,7 +56,7 @@ static int resize(size_t nel, struct hsearch_data *htab)
5656 htab->__tab->mask = newsize - 1;
5757 if (!oldtab)
5858 return 1;
59 for (e = oldtab; e < oldend; e++)
59 for (e = oldtab; e < oldtab + oldsize; e++)
6060 if (e->key) {
6161 for (i=keyhash(e->key),j=1; ; i+=j++) {
6262 newe = htab->__tab->entries + (i & htab->__tab->mask);
lib/libc/musl/src/select/poll.c+7-2
......@@ -8,8 +8,13 @@ int poll(struct pollfd *fds, nfds_t n, int timeout)
88#ifdef SYS_poll
99 return syscall_cp(SYS_poll, fds, n, timeout);
1010#else
11#if SYS_ppoll_time64 == SYS_ppoll
12 typedef long long ppoll_ts_t[2];
13#else
14 typedef long ppoll_ts_t[2];
15#endif
1116 return syscall_cp(SYS_ppoll, fds, n, timeout>=0 ?
12 &((struct timespec){ .tv_sec = timeout/1000,
13 .tv_nsec = timeout%1000*1000000 }) : 0, 0, _NSIG/8);
17 ((ppoll_ts_t){ timeout/1000, timeout%1000*1000000 }) : 0,
18 0, _NSIG/8);
1419#endif
1520}
lib/libc/musl/src/select/select.c+1
......@@ -33,6 +33,7 @@ int select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict
3333 ((syscall_arg_t[]){ 0, _NSIG/8 }));
3434 if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS)
3535 return __syscall_ret(r);
36 s = CLAMP(s);
3637#endif
3738#ifdef SYS_select
3839 return syscall_cp(SYS_select, n, rfds, wfds, efds,
lib/libc/musl/src/setjmp/powerpc/longjmp.S+4-4
......@@ -42,10 +42,10 @@ longjmp:
4242 bl 1f
4343 .hidden __hwcap
4444 .long __hwcap-.
451: mflr 4
46 lwz 5, 0(4)
47 lwzx 4, 4, 5
48 andis. 4, 4, 0x80
451: mflr 6
46 lwz 5, 0(6)
47 lwzx 6, 6, 5
48 andis. 6, 6, 0x80
4949 beq 1f
5050 .long 0x11c35b01 /* evldd 14,88(3) */
5151 .long 0x11e36301 /* ... */
lib/libc/musl/src/signal/mips/restore.s deleted-15
......@@ -1,15 +0,0 @@
1.set noreorder
2
3.global __restore_rt
4.hidden __restore_rt
5.type __restore_rt,@function
6__restore_rt:
7 li $2, 4193
8 syscall
9
10.global __restore
11.hidden __restore
12.type __restore,@function
13__restore:
14 li $2, 4119
15 syscall
lib/libc/musl/src/signal/mips64/restore.s deleted-11
......@@ -1,11 +0,0 @@
1.set noreorder
2.global __restore_rt
3.global __restore
4.hidden __restore_rt
5.hidden __restore
6.type __restore_rt,@function
7.type __restore,@function
8__restore_rt:
9__restore:
10 li $2,5211
11 syscall
lib/libc/musl/src/signal/mipsn32/restore.s deleted-11
......@@ -1,11 +0,0 @@
1.set noreorder
2.global __restore_rt
3.global __restore
4.hidden __restore_rt
5.hidden __restore
6.type __restore_rt,@function
7.type __restore,@function
8__restore_rt:
9__restore:
10 li $2,6211
11 syscall
lib/libc/musl/src/signal/sigaction.c+4-1
......@@ -44,8 +44,11 @@ int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigact
4444 }
4545 }
4646 ksa.handler = sa->sa_handler;
47 ksa.flags = sa->sa_flags | SA_RESTORER;
47 ksa.flags = sa->sa_flags;
48#ifdef SA_RESTORER
49 ksa.flags |= SA_RESTORER;
4850 ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore;
51#endif
4952 memcpy(&ksa.mask, &sa->sa_mask, _NSIG/8);
5053 }
5154 int r = __syscall(SYS_rt_sigaction, sig, sa?&ksa:0, old?&ksa_old:0, _NSIG/8);
lib/libc/musl/src/stat/__xstat.c-5
......@@ -22,11 +22,6 @@ int __xstat(int ver, const char *path, struct stat *buf)
2222 return stat(path, buf);
2323}
2424
25weak_alias(__fxstat, __fxstat64);
26weak_alias(__fxstatat, __fxstatat64);
27weak_alias(__lxstat, __lxstat64);
28weak_alias(__xstat, __xstat64);
29
3025#endif
3126
3227int __xmknod(int ver, const char *path, mode_t mode, dev_t *dev)
lib/libc/musl/src/stat/fchmodat.c+7-8
......@@ -2,7 +2,6 @@
22#include <fcntl.h>
33#include <errno.h>
44#include "syscall.h"
5#include "kstat.h"
65
76int fchmodat(int fd, const char *path, mode_t mode, int flag)
87{
......@@ -11,12 +10,12 @@ int fchmodat(int fd, const char *path, mode_t mode, int flag)
1110 if (flag != AT_SYMLINK_NOFOLLOW)
1211 return __syscall_ret(-EINVAL);
1312
14 struct kstat st;
13 struct stat st;
1514 int ret, fd2;
1615 char proc[15+3*sizeof(int)];
1716
18 if ((ret = __syscall(SYS_fstatat, fd, path, &st, flag)))
19 return __syscall_ret(ret);
17 if (fstatat(fd, path, &st, flag))
18 return -1;
2019 if (S_ISLNK(st.st_mode))
2120 return __syscall_ret(-EOPNOTSUPP);
2221
......@@ -27,12 +26,12 @@ int fchmodat(int fd, const char *path, mode_t mode, int flag)
2726 }
2827
2928 __procfdname(proc, fd2);
30 ret = __syscall(SYS_fstatat, AT_FDCWD, proc, &st, 0);
29 ret = stat(proc, &st);
3130 if (!ret) {
32 if (S_ISLNK(st.st_mode)) ret = -EOPNOTSUPP;
33 else ret = __syscall(SYS_fchmodat, AT_FDCWD, proc, mode);
31 if (S_ISLNK(st.st_mode)) ret = __syscall_ret(-EOPNOTSUPP);
32 else ret = syscall(SYS_fchmodat, AT_FDCWD, proc, mode);
3433 }
3534
3635 __syscall(SYS_close, fd2);
37 return __syscall_ret(ret);
36 return ret;
3837}
lib/libc/musl/src/stat/fstat.c+3-5
......@@ -4,12 +4,10 @@
44#include <fcntl.h>
55#include "syscall.h"
66
7int fstat(int fd, struct stat *st)
7int __fstat(int fd, struct stat *st)
88{
99 if (fd<0) return __syscall_ret(-EBADF);
10 return fstatat(fd, "", st, AT_EMPTY_PATH);
10 return __fstatat(fd, "", st, AT_EMPTY_PATH);
1111}
1212
13#if !_REDIR_TIME64
14weak_alias(fstat, fstat64);
15#endif
13weak_alias(__fstat, fstat);
lib/libc/musl/src/stat/fstatat.c+11-5
......@@ -6,7 +6,6 @@
66#include <stdint.h>
77#include <sys/sysmacros.h>
88#include "syscall.h"
9#include "kstat.h"
109
1110struct statx {
1211 uint32_t stx_mask;
......@@ -69,6 +68,10 @@ static int fstatat_statx(int fd, const char *restrict path, struct stat *restric
6968 return 0;
7069}
7170
71#ifdef SYS_fstatat
72
73#include "kstat.h"
74
7275static int fstatat_kstat(int fd, const char *restrict path, struct stat *restrict st, int flag)
7376{
7477 int ret;
......@@ -130,18 +133,21 @@ static int fstatat_kstat(int fd, const char *restrict path, struct stat *restric
130133
131134 return 0;
132135}
136#endif
133137
134int fstatat(int fd, const char *restrict path, struct stat *restrict st, int flag)
138int __fstatat(int fd, const char *restrict path, struct stat *restrict st, int flag)
135139{
136140 int ret;
141#ifdef SYS_fstatat
137142 if (sizeof((struct kstat){0}.st_atime_sec) < sizeof(time_t)) {
138143 ret = fstatat_statx(fd, path, st, flag);
139144 if (ret!=-ENOSYS) return __syscall_ret(ret);
140145 }
141146 ret = fstatat_kstat(fd, path, st, flag);
147#else
148 ret = fstatat_statx(fd, path, st, flag);
149#endif
142150 return __syscall_ret(ret);
143151}
144152
145#if !_REDIR_TIME64
146weak_alias(fstatat, fstatat64);
147#endif
153weak_alias(__fstatat, fstatat);
lib/libc/musl/src/stat/lstat.c-4
......@@ -5,7 +5,3 @@ int lstat(const char *restrict path, struct stat *restrict buf)
55{
66 return fstatat(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
77}
8
9#if !_REDIR_TIME64
10weak_alias(lstat, lstat64);
11#endif
lib/libc/musl/src/stat/stat.c-4
......@@ -5,7 +5,3 @@ int stat(const char *restrict path, struct stat *restrict buf)
55{
66 return fstatat(AT_FDCWD, path, buf, 0);
77}
8
9#if !_REDIR_TIME64
10weak_alias(stat, stat64);
11#endif
lib/libc/musl/src/stat/statvfs.c-5
......@@ -56,8 +56,3 @@ int fstatvfs(int fd, struct statvfs *buf)
5656 fixup(buf, &kbuf);
5757 return 0;
5858}
59
60weak_alias(statvfs, statvfs64);
61weak_alias(statfs, statfs64);
62weak_alias(fstatvfs, fstatvfs64);
63weak_alias(fstatfs, fstatfs64);
lib/libc/musl/src/stdio/fgetpos.c-2
......@@ -7,5 +7,3 @@ int fgetpos(FILE *restrict f, fpos_t *restrict pos)
77 *(long long *)pos = off;
88 return 0;
99}
10
11weak_alias(fgetpos, fgetpos64);
lib/libc/musl/src/stdio/fgets.c+3-2
......@@ -12,13 +12,14 @@ char *fgets(char *restrict s, int n, FILE *restrict f)
1212
1313 FLOCK(f);
1414
15 if (n--<=1) {
15 if (n<=1) {
1616 f->mode |= f->mode-1;
1717 FUNLOCK(f);
18 if (n) return 0;
18 if (n<1) return 0;
1919 *s = 0;
2020 return s;
2121 }
22 n--;
2223
2324 while (n) {
2425 if (f->rpos != f->rend) {
lib/libc/musl/src/stdio/fopen.c-2
......@@ -29,5 +29,3 @@ FILE *fopen(const char *restrict filename, const char *restrict mode)
2929 __syscall(SYS_close, fd);
3030 return 0;
3131}
32
33weak_alias(fopen, fopen64);
lib/libc/musl/src/stdio/freopen.c+2-2
......@@ -40,6 +40,8 @@ FILE *freopen(const char *restrict filename, const char *restrict mode, FILE *re
4040 fclose(f2);
4141 }
4242
43 f->mode = 0;
44 f->locale = 0;
4345 FUNLOCK(f);
4446 return f;
4547
......@@ -49,5 +51,3 @@ fail:
4951 fclose(f);
5052 return NULL;
5153}
52
53weak_alias(freopen, freopen64);
lib/libc/musl/src/stdio/fseek.c-2
......@@ -46,5 +46,3 @@ int fseek(FILE *f, long off, int whence)
4646}
4747
4848weak_alias(__fseeko, fseeko);
49
50weak_alias(fseeko, fseeko64);
lib/libc/musl/src/stdio/fsetpos.c-2
......@@ -4,5 +4,3 @@ int fsetpos(FILE *f, const fpos_t *pos)
44{
55 return __fseeko(f, *(const long long *)pos, SEEK_SET);
66}
7
8weak_alias(fsetpos, fsetpos64);
lib/libc/musl/src/stdio/ftell.c-2
......@@ -37,5 +37,3 @@ long ftell(FILE *f)
3737}
3838
3939weak_alias(__ftello, ftello);
40
41weak_alias(ftello, ftello64);
lib/libc/musl/src/stdio/open_wmemstream.c+5-1
......@@ -40,8 +40,12 @@ fail:
4040static size_t wms_write(FILE *f, const unsigned char *buf, size_t len)
4141{
4242 struct cookie *c = f->cookie;
43 size_t len2;
43 size_t len2 = f->wpos - f->wbase;
4444 wchar_t *newbuf;
45 if (len2) {
46 f->wpos = f->wbase;
47 if (wms_write(f, f->wbase, len2) < len2) return 0;
48 }
4549 if (len + c->pos >= c->space) {
4650 len2 = 2*c->space+1 | c->pos+len+1;
4751 if (len2 > SSIZE_MAX/4) return 0;
lib/libc/musl/src/stdio/tempnam.c+3-5
......@@ -6,7 +6,6 @@
66#include <string.h>
77#include <stdlib.h>
88#include "syscall.h"
9#include "kstat.h"
109
1110#define MAXTRIES 100
1211
......@@ -37,11 +36,10 @@ char *tempnam(const char *dir, const char *pfx)
3736
3837 for (try=0; try<MAXTRIES; try++) {
3938 __randname(s+l-6);
40#ifdef SYS_lstat
41 r = __syscall(SYS_lstat, s, &(struct kstat){0});
39#ifdef SYS_readlink
40 r = __syscall(SYS_readlink, s, (char[1]){0}, 1);
4241#else
43 r = __syscall(SYS_fstatat, AT_FDCWD, s,
44 &(struct kstat){0}, AT_SYMLINK_NOFOLLOW);
42 r = __syscall(SYS_readlinkat, AT_FDCWD, s, (char[1]){0}, 1);
4543#endif
4644 if (r == -ENOENT) return strdup(s);
4745 }
lib/libc/musl/src/stdio/tmpfile.c-2
......@@ -27,5 +27,3 @@ FILE *tmpfile(void)
2727 }
2828 return 0;
2929}
30
31weak_alias(tmpfile, tmpfile64);
lib/libc/musl/src/stdio/tmpnam.c+3-5
......@@ -5,7 +5,6 @@
55#include <string.h>
66#include <stdlib.h>
77#include "syscall.h"
8#include "kstat.h"
98
109#define MAXTRIES 100
1110
......@@ -17,11 +16,10 @@ char *tmpnam(char *buf)
1716 int r;
1817 for (try=0; try<MAXTRIES; try++) {
1918 __randname(s+12);
20#ifdef SYS_lstat
21 r = __syscall(SYS_lstat, s, &(struct kstat){0});
19#ifdef SYS_readlink
20 r = __syscall(SYS_readlink, s, (char[1]){0}, 1);
2221#else
23 r = __syscall(SYS_fstatat, AT_FDCWD, s,
24 &(struct kstat){0}, AT_SYMLINK_NOFOLLOW);
22 r = __syscall(SYS_readlinkat, AT_FDCWD, s, (char[1]){0}, 1);
2523#endif
2624 if (r == -ENOENT) return strcpy(buf ? buf : internal, s);
2725 }
lib/libc/musl/src/stdio/vfprintf.c+14-9
......@@ -132,7 +132,7 @@ static void pop_arg(union arg *arg, int type, va_list *ap)
132132
133133static void out(FILE *f, const char *s, size_t l)
134134{
135 if (!(f->flags & F_ERR)) __fwritex((void *)s, l, f);
135 if (!ferror(f)) __fwritex((void *)s, l, f);
136136}
137137
138138static void pad(FILE *f, char c, int w, int l, int fl)
......@@ -478,8 +478,8 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
478478 if (*s=='*') {
479479 if (isdigit(s[1]) && s[2]=='$') {
480480 l10n=1;
481 nl_type[s[1]-'0'] = INT;
482 w = nl_arg[s[1]-'0'].i;
481 if (!f) nl_type[s[1]-'0'] = INT, w = 0;
482 else w = nl_arg[s[1]-'0'].i;
483483 s+=3;
484484 } else if (!l10n) {
485485 w = f ? va_arg(*ap, int) : 0;
......@@ -491,8 +491,8 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
491491 /* Read precision */
492492 if (*s=='.' && s[1]=='*') {
493493 if (isdigit(s[2]) && s[3]=='$') {
494 nl_type[s[2]-'0'] = INT;
495 p = nl_arg[s[2]-'0'].i;
494 if (!f) nl_type[s[2]-'0'] = INT, p = 0;
495 else p = nl_arg[s[2]-'0'].i;
496496 s+=4;
497497 } else if (!l10n) {
498498 p = f ? va_arg(*ap, int) : 0;
......@@ -521,13 +521,18 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg,
521521 if (st==NOARG) {
522522 if (argpos>=0) goto inval;
523523 } else {
524 if (argpos>=0) nl_type[argpos]=st, arg=nl_arg[argpos];
525 else if (f) pop_arg(&arg, st, ap);
524 if (argpos>=0) {
525 if (!f) nl_type[argpos]=st;
526 else arg=nl_arg[argpos];
527 } else if (f) pop_arg(&arg, st, ap);
526528 else return 0;
527529 }
528530
529531 if (!f) continue;
530532
533 /* Do not process any new directives once in error state. */
534 if (ferror(f)) return -1;
535
531536 z = buf + sizeof(buf);
532537 prefix = "-+ 0X0x";
533538 pl = 0;
......@@ -672,7 +677,7 @@ int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap)
672677
673678 FLOCK(f);
674679 olderr = f->flags & F_ERR;
675 if (f->mode < 1) f->flags &= ~F_ERR;
680 f->flags &= ~F_ERR;
676681 if (!f->buf_size) {
677682 saved_buf = f->buf;
678683 f->buf = internal_buf;
......@@ -688,7 +693,7 @@ int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap)
688693 f->buf_size = 0;
689694 f->wpos = f->wbase = f->wend = 0;
690695 }
691 if (f->flags & F_ERR) ret = -1;
696 if (ferror(f)) ret = -1;
692697 f->flags |= olderr;
693698 FUNLOCK(f);
694699 va_end(ap2);
lib/libc/musl/src/stdio/vfwprintf.c+23-16
......@@ -125,7 +125,13 @@ static void pop_arg(union arg *arg, int type, va_list *ap)
125125
126126static void out(FILE *f, const wchar_t *s, size_t l)
127127{
128 while (l-- && !(f->flags & F_ERR)) fputwc(*s++, f);
128 while (l-- && !ferror(f)) fputwc(*s++, f);
129}
130
131static void pad(FILE *f, int n, int fl)
132{
133 if ((fl & LEFT_ADJ) || !n || ferror(f)) return;
134 fprintf(f, "%*s", n, "");
129135}
130136
131137static int getint(wchar_t **s) {
......@@ -242,6 +248,10 @@ static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_
242248 }
243249
244250 if (!f) continue;
251
252 /* Do not process any new directives once in error state. */
253 if (ferror(f)) return -1;
254
245255 t = s[-1];
246256 if (ps && (t&15)==3) t&=~32;
247257
......@@ -258,25 +268,22 @@ static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_
258268 }
259269 continue;
260270 case 'c':
271 case 'C':
261272 if (w<1) w=1;
262 if (w>1 && !(fl&LEFT_ADJ)) fprintf(f, "%*s", w-1, "");
263 fputwc(btowc(arg.i), f);
264 if (w>1 && (fl&LEFT_ADJ)) fprintf(f, "%*s", w-1, "");
273 pad(f, w-1, fl);
274 out(f, &(wchar_t){t=='C' ? arg.i : btowc(arg.i)}, 1);
275 pad(f, w-1, fl^LEFT_ADJ);
265276 l = w;
266277 continue;
267 case 'C':
268 fputwc(arg.i, f);
269 l = 1;
270 continue;
271278 case 'S':
272279 a = arg.p;
273280 z = a + wcsnlen(a, p<0 ? INT_MAX : p);
274281 if (p<0 && *z) goto overflow;
275282 p = z-a;
276283 if (w<p) w=p;
277 if (!(fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, "");
284 pad(f, w-p, fl);
278285 out(f, a, p);
279 if ((fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, "");
286 pad(f, w-p, fl^LEFT_ADJ);
280287 l=w;
281288 continue;
282289 case 'm':
......@@ -289,14 +296,14 @@ static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_
289296 if (p<0 && *bs) goto overflow;
290297 p=l;
291298 if (w<p) w=p;
292 if (!(fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, "");
299 pad(f, w-p, fl);
293300 bs = arg.p;
294301 while (l--) {
295302 i=mbtowc(&wc, bs, MB_LEN_MAX);
296303 bs+=i;
297 fputwc(wc, f);
304 out(f, &wc, 1);
298305 }
299 if ((fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, "");
306 pad(f, w-p, fl^LEFT_ADJ);
300307 l=w;
301308 continue;
302309 }
......@@ -340,8 +347,8 @@ overflow:
340347int vfwprintf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap)
341348{
342349 va_list ap2;
343 int nl_type[NL_ARGMAX] = {0};
344 union arg nl_arg[NL_ARGMAX];
350 int nl_type[NL_ARGMAX+1] = {0};
351 union arg nl_arg[NL_ARGMAX+1];
345352 int olderr;
346353 int ret;
347354
......@@ -357,7 +364,7 @@ int vfwprintf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap)
357364 olderr = f->flags & F_ERR;
358365 f->flags &= ~F_ERR;
359366 ret = wprintf_core(f, fmt, &ap2, nl_arg, nl_type);
360 if (f->flags & F_ERR) ret = -1;
367 if (ferror(f)) ret = -1;
361368 f->flags |= olderr;
362369 FUNLOCK(f);
363370 va_end(ap2);
lib/libc/musl/src/stdio/vswprintf.c+1
......@@ -18,6 +18,7 @@ static size_t sw_write(FILE *f, const unsigned char *s, size_t l)
1818 if (s!=f->wbase && sw_write(f, f->wbase, f->wpos-f->wbase)==-1)
1919 return -1;
2020 while (c->l && l && (i=mbtowc(c->ws, (void *)s, l))>=0) {
21 if (!i) i=1;
2122 s+=i;
2223 l-=i;
2324 c->l--;
lib/libc/musl/src/stdlib/qsort_nr.c+1-1
......@@ -10,5 +10,5 @@ static int wrapper_cmp(const void *v1, const void *v2, void *cmp)
1010
1111void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
1212{
13 __qsort_r(base, nel, width, wrapper_cmp, cmp);
13 __qsort_r(base, nel, width, wrapper_cmp, (void *)cmp);
1414}
lib/libc/musl/src/string/strverscmp.c+3-3
......@@ -18,9 +18,9 @@ int strverscmp(const char *l0, const char *r0)
1818 else if (c!='0') z=0;
1919 }
2020
21 if (l[dp]!='0' && r[dp]!='0') {
22 /* If we're not looking at a digit sequence that began
23 * with a zero, longest digit string is greater. */
21 if (l[dp]-'1'<9U && r[dp]-'1'<9U) {
22 /* If we're looking at non-degenerate digit sequences starting
23 * with nonzero digits, longest digit string is greater. */
2424 for (j=i; isdigit(l[j]); j++)
2525 if (!isdigit(r[j])) return 1;
2626 if (isdigit(r[j])) return -1;
lib/libc/musl/src/string/wcscmp.c+1-1
......@@ -3,5 +3,5 @@
33int wcscmp(const wchar_t *l, const wchar_t *r)
44{
55 for (; *l==*r && *l && *r; l++, r++);
6 return *l - *r;
6 return *l < *r ? -1 : *l > *r;
77}
lib/libc/musl/src/string/wcsncmp.c+1-1
......@@ -3,5 +3,5 @@
33int wcsncmp(const wchar_t *l, const wchar_t *r, size_t n)
44{
55 for (; n && *l==*r && *l && *r; n--, l++, r++);
6 return n ? *l - *r : 0;
6 return n ? (*l < *r ? -1 : *l > *r) : 0;
77}
lib/libc/musl/src/string/wmemcmp.c+1-1
......@@ -3,5 +3,5 @@
33int wmemcmp(const wchar_t *l, const wchar_t *r, size_t n)
44{
55 for (; n && *l==*r; n--, l++, r++);
6 return n ? *l-*r : 0;
6 return n ? (*l < *r ? -1 : *l > *r) : 0;
77}
lib/libc/musl/src/temp/__randname.c+2-1
......@@ -1,5 +1,6 @@
11#include <time.h>
22#include <stdint.h>
3#include "pthread_impl.h"
34
45/* This assumes that a check for the
56 template size has already been made */
......@@ -10,7 +11,7 @@ char *__randname(char *template)
1011 unsigned long r;
1112
1213 __clock_gettime(CLOCK_REALTIME, &ts);
13 r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)template;
14 r = ts.tv_sec + ts.tv_nsec + __pthread_self()->tid * 65537UL;
1415 for (i=0; i<6; i++, r>>=5)
1516 template[i] = 'A'+(r&15)+(r&16)*2;
1617
lib/libc/musl/src/temp/mkostemp.c-2
......@@ -5,5 +5,3 @@ int mkostemp(char *template, int flags)
55{
66 return __mkostemps(template, 0, flags);
77}
8
9weak_alias(mkostemp, mkostemp64);
lib/libc/musl/src/temp/mkostemps.c-1
......@@ -26,4 +26,3 @@ int __mkostemps(char *template, int len, int flags)
2626}
2727
2828weak_alias(__mkostemps, mkostemps);
29weak_alias(__mkostemps, mkostemps64);
lib/libc/musl/src/temp/mkstemp.c-2
......@@ -4,5 +4,3 @@ int mkstemp(char *template)
44{
55 return __mkostemps(template, 0, 0);
66}
7
8weak_alias(mkstemp, mkstemp64);
lib/libc/musl/src/temp/mkstemps.c-2
......@@ -5,5 +5,3 @@ int mkstemps(char *template, int len)
55{
66 return __mkostemps(template, len, 0);
77}
8
9weak_alias(mkstemps, mkstemps64);
lib/libc/musl/src/thread/pthread_atfork.c+7-1
......@@ -1,7 +1,13 @@
11#include <pthread.h>
2#include <errno.h>
23#include "libc.h"
34#include "lock.h"
45
6#define malloc __libc_malloc
7#define calloc undef
8#define realloc undef
9#define free undef
10
511static struct atfork_funcs {
612 void (*prepare)(void);
713 void (*parent)(void);
......@@ -34,7 +40,7 @@ void __fork_handler(int who)
3440int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
3541{
3642 struct atfork_funcs *new = malloc(sizeof *new);
37 if (!new) return -1;
43 if (!new) return ENOMEM;
3844
3945 LOCK(lock);
4046 new->next = funcs;
lib/libc/musl/src/thread/pthread_cancel.c+7-2
......@@ -56,7 +56,12 @@ static void cancel_handler(int sig, siginfo_t *si, void *ctx)
5656
5757 _sigaddset(&uc->uc_sigmask, SIGCANCEL);
5858
59 if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
59 if (self->cancelasync) {
60 pthread_sigmask(SIG_SETMASK, &uc->uc_sigmask, 0);
61 __cancel();
62 }
63
64 if (pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) {
6065 uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel;
6166#ifdef CANCEL_GOT
6267 uc->uc_mcontext.MC_GOT = CANCEL_GOT;
......@@ -77,7 +82,7 @@ void __testcancel()
7782static void init_cancellation()
7883{
7984 struct sigaction sa = {
80 .sa_flags = SA_SIGINFO | SA_RESTART,
85 .sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK,
8186 .sa_sigaction = cancel_handler
8287 };
8388 memset(&sa.sa_mask, -1, _NSIG/8);
lib/libc/musl/src/thread/pthread_create.c+10-6
......@@ -107,6 +107,16 @@ _Noreturn void __pthread_exit(void *result)
107107
108108 /* At this point we are committed to thread termination. */
109109
110 /* After the kernel thread exits, its tid may be reused. Clear it
111 * to prevent inadvertent use and inform functions that would use
112 * it that it's no longer available. At this point the killlock
113 * may be released, since functions that use it will consistently
114 * see the thread as having exited. Release it now so that no
115 * remaining locks (except thread list) are held if we end up
116 * resetting need_locks below. */
117 self->tid = 0;
118 UNLOCK(self->killlock);
119
110120 /* Process robust list in userspace to handle non-pshared mutexes
111121 * and the detached thread case where the robust list head will
112122 * be invalid when the kernel would process it. */
......@@ -159,12 +169,6 @@ _Noreturn void __pthread_exit(void *result)
159169 a_store(&self->detach_state, DT_EXITED);
160170 __wake(&self->detach_state, 1, 1);
161171
162 /* After the kernel thread exits, its tid may be reused. Clear it
163 * to prevent inadvertent use and inform functions that would use
164 * it that it's no longer available. */
165 self->tid = 0;
166 UNLOCK(self->killlock);
167
168172 for (;;) __syscall(SYS_exit, 0);
169173}
170174
lib/libc/musl/src/thread/pthread_detach.c+6-2
......@@ -5,8 +5,12 @@ static int __pthread_detach(pthread_t t)
55{
66 /* If the cas fails, detach state is either already-detached
77 * or exiting/exited, and pthread_join will trap or cleanup. */
8 if (a_cas(&t->detach_state, DT_JOINABLE, DT_DETACHED) != DT_JOINABLE)
9 return __pthread_join(t, 0);
8 if (a_cas(&t->detach_state, DT_JOINABLE, DT_DETACHED) != DT_JOINABLE) {
9 int cs;
10 __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
11 __pthread_join(t, 0);
12 __pthread_setcancelstate(cs, 0);
13 }
1014 return 0;
1115}
1216
lib/libc/musl/src/thread/pthread_key_create.c+8
......@@ -1,4 +1,5 @@
11#include "pthread_impl.h"
2#include "fork_impl.h"
23
34volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX;
45void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 };
......@@ -20,6 +21,13 @@ static void dummy_0(void)
2021weak_alias(dummy_0, __tl_lock);
2122weak_alias(dummy_0, __tl_unlock);
2223
24void __pthread_key_atfork(int who)
25{
26 if (who<0) __pthread_rwlock_rdlock(&key_lock);
27 else if (!who) __pthread_rwlock_unlock(&key_lock);
28 else key_lock = (pthread_rwlock_t)PTHREAD_RWLOCK_INITIALIZER;
29}
30
2331int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *))
2432{
2533 pthread_t self = __pthread_self();
lib/libc/musl/src/thread/sem_getvalue.c+2-1
......@@ -1,8 +1,9 @@
11#include <semaphore.h>
2#include <limits.h>
23
34int sem_getvalue(sem_t *restrict sem, int *restrict valp)
45{
56 int val = sem->__val[0];
6 *valp = val < 0 ? 0 : val;
7 *valp = val & SEM_VALUE_MAX;
78 return 0;
89}
lib/libc/musl/src/thread/sem_post.c+8-4
......@@ -1,17 +1,21 @@
11#include <semaphore.h>
2#include <limits.h>
23#include "pthread_impl.h"
34
45int sem_post(sem_t *sem)
56{
6 int val, waiters, priv = sem->__val[2];
7 int val, new, waiters, priv = sem->__val[2];
78 do {
89 val = sem->__val[0];
910 waiters = sem->__val[1];
10 if (val == SEM_VALUE_MAX) {
11 if ((val & SEM_VALUE_MAX) == SEM_VALUE_MAX) {
1112 errno = EOVERFLOW;
1213 return -1;
1314 }
14 } while (a_cas(sem->__val, val, val+1+(val<0)) != val);
15 if (val<0 || waiters) __wake(sem->__val, 1, priv);
15 new = val + 1;
16 if (waiters <= 1)
17 new &= ~0x80000000;
18 } while (a_cas(sem->__val, val, new) != val);
19 if (val<0) __wake(sem->__val, waiters>1 ? 1 : -1, priv);
1620 return 0;
1721}
lib/libc/musl/src/thread/sem_timedwait.c+6-4
......@@ -1,4 +1,5 @@
11#include <semaphore.h>
2#include <limits.h>
23#include "pthread_impl.h"
34
45static void cleanup(void *p)
......@@ -13,14 +14,15 @@ int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at)
1314 if (!sem_trywait(sem)) return 0;
1415
1516 int spins = 100;
16 while (spins-- && sem->__val[0] <= 0 && !sem->__val[1]) a_spin();
17 while (spins-- && !(sem->__val[0] & SEM_VALUE_MAX) && !sem->__val[1])
18 a_spin();
1719
1820 while (sem_trywait(sem)) {
19 int r;
21 int r, priv = sem->__val[2];
2022 a_inc(sem->__val+1);
21 a_cas(sem->__val, 0, -1);
23 a_cas(sem->__val, 0, 0x80000000);
2224 pthread_cleanup_push(cleanup, (void *)(sem->__val+1));
23 r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__val[2]);
25 r = __timedwait_cp(sem->__val, 0x80000000, CLOCK_REALTIME, at, priv);
2426 pthread_cleanup_pop(1);
2527 if (r) {
2628 errno = r;
lib/libc/musl/src/thread/sem_trywait.c+3-3
......@@ -1,12 +1,12 @@
11#include <semaphore.h>
2#include <limits.h>
23#include "pthread_impl.h"
34
45int sem_trywait(sem_t *sem)
56{
67 int val;
7 while ((val=sem->__val[0]) > 0) {
8 int new = val-1-(val==1 && sem->__val[1]);
9 if (a_cas(sem->__val, val, new)==val) return 0;
8 while ((val=sem->__val[0]) & SEM_VALUE_MAX) {
9 if (a_cas(sem->__val, val, val-1)==val) return 0;
1010 }
1111 errno = EAGAIN;
1212 return -1;
lib/libc/musl/src/thread/synccall.c+1-1
......@@ -45,7 +45,7 @@ void __synccall(void (*func)(void *), void *ctx)
4545{
4646 sigset_t oldmask;
4747 int cs, i, r;
48 struct sigaction sa = { .sa_flags = SA_RESTART, .sa_handler = handler };
48 struct sigaction sa = { .sa_flags = SA_RESTART | SA_ONSTACK, .sa_handler = handler };
4949 pthread_t self = __pthread_self(), td;
5050 int count = 0;
5151
lib/libc/musl/src/time/__map_file.c+2-3
......@@ -2,15 +2,14 @@
22#include <fcntl.h>
33#include <sys/stat.h>
44#include "syscall.h"
5#include "kstat.h"
65
76const char unsigned *__map_file(const char *pathname, size_t *size)
87{
9 struct kstat st;
8 struct stat st;
109 const unsigned char *map = MAP_FAILED;
1110 int fd = sys_open(pathname, O_RDONLY|O_CLOEXEC|O_NONBLOCK);
1211 if (fd < 0) return 0;
13 if (!syscall(SYS_fstat, fd, &st)) {
12 if (!__fstat(fd, &st)) {
1413 map = __mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
1514 *size = st.st_size;
1615 }
lib/libc/musl/src/time/clock_getcpuclockid.c+1
......@@ -8,6 +8,7 @@ int clock_getcpuclockid(pid_t pid, clockid_t *clk)
88 struct timespec ts;
99 clockid_t id = (-pid-1)*8U + 2;
1010 int ret = __syscall(SYS_clock_getres, id, &ts);
11 if (ret == -EINVAL) ret = -ESRCH;
1112 if (ret) return -ret;
1213 *clk = id;
1314 return 0;
lib/libc/musl/src/time/clock_gettime.c+7
......@@ -42,6 +42,9 @@ static int cgt_init(clockid_t clk, struct timespec *ts)
4242 p = cgt_time32_wrap;
4343 }
4444 }
45#ifdef VDSO_CGT_WORKAROUND
46 if (!__vdsosym(VDSO_CGT32_VER, VDSO_CGT32_SYM)) p = 0;
47#endif
4548#endif
4649 int (*f)(clockid_t, struct timespec *) =
4750 (int (*)(clockid_t, struct timespec *))p;
......@@ -80,10 +83,12 @@ int __clock_gettime(clockid_t clk, struct timespec *ts)
8083 return __syscall_ret(r);
8184 long ts32[2];
8285 r = __syscall(SYS_clock_gettime, clk, ts32);
86#ifdef SYS_gettimeofday
8387 if (r==-ENOSYS && clk==CLOCK_REALTIME) {
8488 r = __syscall(SYS_gettimeofday, ts32, 0);
8589 ts32[1] *= 1000;
8690 }
91#endif
8792 if (!r) {
8893 ts->tv_sec = ts32[0];
8994 ts->tv_nsec = ts32[1];
......@@ -92,6 +97,7 @@ int __clock_gettime(clockid_t clk, struct timespec *ts)
9297 return __syscall_ret(r);
9398#else
9499 r = __syscall(SYS_clock_gettime, clk, ts);
100#ifdef SYS_gettimeofday
95101 if (r == -ENOSYS) {
96102 if (clk == CLOCK_REALTIME) {
97103 __syscall(SYS_gettimeofday, ts, 0);
......@@ -100,6 +106,7 @@ int __clock_gettime(clockid_t clk, struct timespec *ts)
100106 }
101107 r = -EINVAL;
102108 }
109#endif
103110 return __syscall_ret(r);
104111#endif
105112}
lib/libc/musl/src/time/timer_create.c+5-1
......@@ -43,6 +43,8 @@ static void *start(void *arg)
4343 union sigval val = args->sev->sigev_value;
4444
4545 pthread_barrier_wait(&args->b);
46 if (self->cancel)
47 return 0;
4648 for (;;) {
4749 siginfo_t si;
4850 while (sigwaitinfo(SIGTIMER_SET, &si) < 0);
......@@ -113,8 +115,10 @@ int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict
113115 ksev.sigev_signo = SIGTIMER;
114116 ksev.sigev_notify = SIGEV_THREAD_ID;
115117 ksev.sigev_tid = td->tid;
116 if (syscall(SYS_timer_create, clk, &ksev, &timerid) < 0)
118 if (syscall(SYS_timer_create, clk, &ksev, &timerid) < 0) {
117119 timerid = -1;
120 td->cancel = 1;
121 }
118122 td->timer_id = timerid;
119123 pthread_barrier_wait(&args.b);
120124 if (timerid < 0) return -1;
lib/libc/musl/src/unistd/dup3.c+4-2
......@@ -9,12 +9,14 @@ int __dup3(int old, int new, int flags)
99 int r;
1010#ifdef SYS_dup2
1111 if (old==new) return __syscall_ret(-EINVAL);
12 if (flags & O_CLOEXEC) {
12 if (flags) {
1313 while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
1414 if (r!=-ENOSYS) return __syscall_ret(r);
15 if (flags & ~O_CLOEXEC) return __syscall_ret(-EINVAL);
1516 }
1617 while ((r=__syscall(SYS_dup2, old, new))==-EBUSY);
17 if (flags & O_CLOEXEC) __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC);
18 if (r >= 0 && (flags & O_CLOEXEC))
19 __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC);
1820#else
1921 while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY);
2022#endif
lib/libc/musl/src/unistd/ftruncate.c-2
......@@ -5,5 +5,3 @@ int ftruncate(int fd, off_t length)
55{
66 return syscall(SYS_ftruncate, fd, __SYSCALL_LL_O(length));
77}
8
9weak_alias(ftruncate, ftruncate64);
lib/libc/musl/src/unistd/lseek.c-1
......@@ -12,4 +12,3 @@ off_t __lseek(int fd, off_t offset, int whence)
1212}
1313
1414weak_alias(__lseek, lseek);
15weak_alias(__lseek, lseek64);
lib/libc/musl/src/unistd/mipsn32/lseek.c-1
......@@ -17,4 +17,3 @@ off_t __lseek(int fd, off_t offset, int whence)
1717}
1818
1919weak_alias(__lseek, lseek);
20weak_alias(__lseek, lseek64);
lib/libc/musl/src/unistd/pipe2.c+1
......@@ -8,6 +8,7 @@ int pipe2(int fd[2], int flag)
88 if (!flag) return pipe(fd);
99 int ret = __syscall(SYS_pipe2, fd, flag);
1010 if (ret != -ENOSYS) return __syscall_ret(ret);
11 if (flag & ~(O_CLOEXEC|O_NONBLOCK)) return __syscall_ret(-EINVAL);
1112 ret = pipe(fd);
1213 if (ret) return ret;
1314 if (flag & O_CLOEXEC) {
lib/libc/musl/src/unistd/pread.c-2
......@@ -5,5 +5,3 @@ ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
55{
66 return syscall_cp(SYS_pread, fd, buf, size, __SYSCALL_LL_PRW(ofs));
77}
8
9weak_alias(pread, pread64);
lib/libc/musl/src/unistd/preadv.c-2
......@@ -8,5 +8,3 @@ ssize_t preadv(int fd, const struct iovec *iov, int count, off_t ofs)
88 return syscall_cp(SYS_preadv, fd, iov, count,
99 (long)(ofs), (long)(ofs>>32));
1010}
11
12weak_alias(preadv, preadv64);
lib/libc/musl/src/unistd/pwrite.c-2
......@@ -5,5 +5,3 @@ ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
55{
66 return syscall_cp(SYS_pwrite, fd, buf, size, __SYSCALL_LL_PRW(ofs));
77}
8
9weak_alias(pwrite, pwrite64);
lib/libc/musl/src/unistd/pwritev.c-2
......@@ -8,5 +8,3 @@ ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs)
88 return syscall_cp(SYS_pwritev, fd, iov, count,
99 (long)(ofs), (long)(ofs>>32));
1010}
11
12weak_alias(pwritev, pwritev64);
lib/libc/musl/src/unistd/truncate.c-2
......@@ -5,5 +5,3 @@ int truncate(const char *path, off_t length)
55{
66 return syscall(SYS_truncate, path, __SYSCALL_LL_O(length));
77}
8
9weak_alias(truncate, truncate64);
lib/libc/musl/src/unistd/x32/lseek.c-1
......@@ -12,4 +12,3 @@ off_t __lseek(int fd, off_t offset, int whence)
1212}
1313
1414weak_alias(__lseek, lseek);
15weak_alias(__lseek, lseek64);
src/musl.zig+2-3
......@@ -1466,6 +1466,7 @@ const src_files = [_][]const u8{
14661466 "musl/src/prng/seed48.c",
14671467 "musl/src/prng/srand48.c",
14681468 "musl/src/process/_Fork.c",
1469 "musl/src/process/aarch64/vfork.s",
14691470 "musl/src/process/arm/vfork.s",
14701471 "musl/src/process/execl.c",
14711472 "musl/src/process/execle.c",
......@@ -1496,6 +1497,7 @@ const src_files = [_][]const u8{
14961497 "musl/src/process/posix_spawnattr_setsigdefault.c",
14971498 "musl/src/process/posix_spawnattr_setsigmask.c",
14981499 "musl/src/process/posix_spawnp.c",
1500 "musl/src/process/riscv64/vfork.s",
14991501 "musl/src/process/s390x/vfork.s",
15001502 "musl/src/process/sh/vfork.s",
15011503 "musl/src/process/system.c",
......@@ -1579,11 +1581,8 @@ const src_files = [_][]const u8{
15791581 "musl/src/signal/m68k/sigsetjmp.s",
15801582 "musl/src/signal/microblaze/restore.s",
15811583 "musl/src/signal/microblaze/sigsetjmp.s",
1582 "musl/src/signal/mips/restore.s",
15831584 "musl/src/signal/mips/sigsetjmp.s",
1584 "musl/src/signal/mips64/restore.s",
15851585 "musl/src/signal/mips64/sigsetjmp.s",
1586 "musl/src/signal/mipsn32/restore.s",
15871586 "musl/src/signal/mipsn32/sigsetjmp.s",
15881587 "musl/src/signal/or1k/sigsetjmp.s",
15891588 "musl/src/signal/powerpc/restore.s",