From a90d9da1d1b14d81c4f93e1a6d1a686c3312e4ba Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 20 Nov 2017 14:23:49 -0500 Subject: [PATCH 001/161] fix treatment by fgetws of encoding errors as eof fgetwc does not set the stream's error indicator on encoding errors, making ferror insufficient to distinguish between error and eof conditions. feof is also insufficient, since it will return true if the file ended with a partial character encoding error. whether fgetwc should be setting the error indicator itself is a question with conflicting answers. the POSIX text for the function states it as a requirement, but the ISO C text seems to require that it not. this may be revisited in the future based on the outcome of Austin Group issue #1170. --- src/stdio/fgetws.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c index 195cb435..b08b3049 100644 --- a/src/stdio/fgetws.c +++ b/src/stdio/fgetws.c @@ -1,5 +1,6 @@ #include "stdio_impl.h" #include +#include wint_t __fgetwc_unlocked(FILE *); @@ -11,6 +12,10 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) FLOCK(f); + /* Setup a dummy errno so we can detect EILSEQ. This is + * the only way to catch encoding errors in the form of a + * partial character just before EOF. */ + errno = EAGAIN; for (; n; n--) { wint_t c = __fgetwc_unlocked(f); if (c == WEOF) break; @@ -18,7 +23,7 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) if (c == '\n') break; } *p = 0; - if (ferror(f)) p = s; + if (ferror(f) || errno==EILSEQ) p = s; FUNLOCK(f); From 4000b0107ddd7fe733fa31d4f078c6fcd35851d6 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 20 Nov 2017 16:25:54 -0500 Subject: [PATCH 002/161] make fgetwc handling of encoding errors consistent with/without buffer previously, fgetwc left all but the first byte of an illegal sequence unread (available for subsequent calls) when reading out of the FILE buffer, but dropped all bytes contibuting to the error when falling back to reading a byte at a time. neither behavior was ideal. in the buffered case, each malformed character produced one error per byte, rather than one per character. in the unbuffered case, consuming the last byte that caused the transition from "incomplete" to "invalid" state potentially dropped (and produced additional spurious encoding errors for) the next valid character. to handle both cases uniformly without duplicate code, revise the buffered case to only cover situations where a complete and valid character is present in the buffer, and fall back to byte-at-a-time for all other cases. this allows using mbtowc (stateless) instead of mbrtowc, which may slightly improve performance too. when an encoding error has been hit in the byte-at-a-time case, leave the final byte that produced the error unread (via ungetc) except in the case of single-byte errors (for UTF-8, bytes c0, c1, f5-ff, and continuation bytes with no lead byte). single-byte errors are fully consumed so as not to leave the caller in an infinite loop repeating the same error. none of these changes are distinguished from a conformance standpoint, since the file position is unspecified after encoding errors. they are intended merely as QoI/consistency improvements. --- src/stdio/fgetwc.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/stdio/fgetwc.c b/src/stdio/fgetwc.c index a00c1a86..07fb6d7c 100644 --- a/src/stdio/fgetwc.c +++ b/src/stdio/fgetwc.c @@ -5,36 +5,36 @@ static wint_t __fgetwc_unlocked_internal(FILE *f) { - mbstate_t st = { 0 }; wchar_t wc; int c; - unsigned char b; size_t l; /* Convert character from buffer if possible */ if (f->rpos < f->rend) { - l = mbrtowc(&wc, (void *)f->rpos, f->rend - f->rpos, &st); - if (l+2 >= 2) { + l = mbtowc(&wc, (void *)f->rpos, f->rend - f->rpos); + if (l+1 >= 1) { f->rpos += l + !l; /* l==0 means 1 byte, null */ return wc; } - if (l == -1) { - f->rpos++; - return WEOF; - } - f->rpos = f->rend; - } else l = -2; + } /* Convert character byte-by-byte */ - while (l == -2) { + mbstate_t st = { 0 }; + unsigned char b; + int first = 1; + do { b = c = getc_unlocked(f); if (c < 0) { - if (!mbsinit(&st)) errno = EILSEQ; + if (!first) errno = EILSEQ; return WEOF; } l = mbrtowc(&wc, (void *)&b, 1, &st); - if (l == -1) return WEOF; - } + if (l == -1) { + if (!first) ungetc(b, f); + return WEOF; + } + first = 0; + } while (l == -2); return wc; } From 061843340fbf2493bb615e20e66f60c5d1ef0455 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 5 Dec 2017 16:04:43 -0500 Subject: [PATCH 003/161] implement the fopencookie extension to stdio notes added by maintainer: this function is a GNU extension. it was chosen over the similar BSD function funopen because the latter depends on fpos_t being an arithmetic type as part of its public API, conflicting with our definition of fpos_t and with the intent that it be an opaque type. it was accepted for inclusion because, despite not being widely used, it is usually very difficult to extricate software using it from the dependency on it. calling pattern for the read and write callbacks is not likely to match glibc or other implementations, but should work with any reasonable callbacks. in particular the read function is never called without at least one byte being needed to satisfy its caller, so that spurious blocking is not introduced. contracts for what callbacks called from inside libc/stdio can do are always complicated, and at some point still need to be specified explicitly. at the very least, the callbacks must return or block indefinitely (they cannot perform nonlocal exits) and they should not make calls to stdio using their own FILE as an argument. --- include/stdio.h | 14 ++++ src/stdio/fopencookie.c | 138 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 src/stdio/fopencookie.c diff --git a/include/stdio.h b/include/stdio.h index 884d2e6a..2932c76f 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -182,6 +182,20 @@ int vasprintf(char **, const char *, __isoc_va_list); #ifdef _GNU_SOURCE char *fgets_unlocked(char *, int, FILE *); int fputs_unlocked(const char *, FILE *); + +typedef ssize_t (cookie_read_function_t)(void *, char *, size_t); +typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); +typedef int (cookie_seek_function_t)(void *, off_t *, int); +typedef int (cookie_close_function_t)(void *); + +typedef struct { + cookie_read_function_t *read; + cookie_write_function_t *write; + cookie_seek_function_t *seek; + cookie_close_function_t *close; +} cookie_io_functions_t; + +FILE *fopencookie(void *, const char *, cookie_io_functions_t); #endif #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) diff --git a/src/stdio/fopencookie.c b/src/stdio/fopencookie.c new file mode 100644 index 00000000..2f46dd53 --- /dev/null +++ b/src/stdio/fopencookie.c @@ -0,0 +1,138 @@ +#define _GNU_SOURCE +#include "stdio_impl.h" +#include +#include +#include +#include +#include + +struct fcookie { + void *cookie; + cookie_io_functions_t iofuncs; +}; + +struct cookie_FILE { + FILE f; + struct fcookie fc; + unsigned char buf[UNGET+BUFSIZ]; +}; + +static size_t cookieread(FILE *f, unsigned char *buf, size_t len) +{ + struct fcookie *fc = f->cookie; + ssize_t ret = -1; + size_t remain = len, readlen = 0; + size_t len2 = len - !!f->buf_size; + + if (!fc->iofuncs.read) goto bail; + + if (len2) { + ret = fc->iofuncs.read(fc->cookie, (char *) buf, len2); + if (ret <= 0) goto bail; + + readlen += ret; + remain -= ret; + } + + if (!f->buf_size || remain > !!f->buf_size) return readlen; + + f->rpos = f->buf; + ret = fc->iofuncs.read(fc->cookie, (char *) f->rpos, f->buf_size); + if (ret <= 0) goto bail; + f->rend = f->rpos + ret; + + buf[readlen++] = *f->rpos++; + + return readlen; + +bail: + f->flags |= ret == 0 ? F_EOF : F_ERR; + f->rpos = f->rend = f->buf; + return readlen; +} + +static size_t cookiewrite(FILE *f, const unsigned char *buf, size_t len) +{ + struct fcookie *fc = f->cookie; + ssize_t ret; + size_t len2 = f->wpos - f->wbase; + if (!fc->iofuncs.write) return len; + if (len2) { + f->wpos = f->wbase; + if (cookiewrite(f, f->wpos, len2) < len2) return 0; + } + ret = fc->iofuncs.write(fc->cookie, (const char *) buf, len); + if (ret < 0) { + f->wpos = f->wbase = f->wend = 0; + f->flags |= F_ERR; + return 0; + } + return ret; +} + +static off_t cookieseek(FILE *f, off_t off, int whence) +{ + struct fcookie *fc = f->cookie; + int res; + if (whence > 2U) { + errno = EINVAL; + return -1; + } + if (!fc->iofuncs.seek) { + errno = ENOTSUP; + return -1; + } + res = fc->iofuncs.seek(fc->cookie, &off, whence); + if (res < 0) + return res; + return off; +} + +static int cookieclose(FILE *f) +{ + struct fcookie *fc = f->cookie; + if (fc->iofuncs.close) return fc->iofuncs.close(fc->cookie); + return 0; +} + +FILE *fopencookie(void *cookie, const char *mode, cookie_io_functions_t iofuncs) +{ + struct cookie_FILE *f; + + /* Check for valid initial mode character */ + if (!strchr("rwa", *mode)) { + errno = EINVAL; + return 0; + } + + /* Allocate FILE+fcookie+buffer or fail */ + if (!(f=malloc(sizeof *f))) return 0; + + /* Zero-fill only the struct, not the buffer */ + memset(&f->f, 0, sizeof f->f); + + /* Impose mode restrictions */ + if (!strchr(mode, '+')) f->f.flags = (*mode == 'r') ? F_NOWR : F_NORD; + + /* Set up our fcookie */ + f->fc.cookie = cookie; + f->fc.iofuncs.read = iofuncs.read; + f->fc.iofuncs.write = iofuncs.write; + f->fc.iofuncs.seek = iofuncs.seek; + f->fc.iofuncs.close = iofuncs.close; + + f->f.fd = -1; + f->f.cookie = &f->fc; + f->f.buf = f->buf + UNGET; + f->f.buf_size = BUFSIZ; + f->f.lbf = EOF; + + /* Initialize op ptrs. No problem if some are unneeded. */ + f->f.read = cookieread; + f->f.write = cookiewrite; + f->f.seek = cookieseek; + f->f.close = cookieclose; + + /* Add new FILE to open file list */ + return __ofl_add(&f->f); +} From 2488d31f5a946e63e40058baf29fd2991343ea6f Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 6 Dec 2017 13:14:22 -0500 Subject: [PATCH 004/161] adjust fopencookie structure tag for ABI-compat stdio types use the struct tag names from glibc libio to match C++ ABI. --- include/stdio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/stdio.h b/include/stdio.h index 2932c76f..7c4f9ee4 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -188,7 +188,7 @@ typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); typedef int (cookie_seek_function_t)(void *, off_t *, int); typedef int (cookie_close_function_t)(void *); -typedef struct { +typedef struct _IO_cookie_io_functions_t { cookie_read_function_t *read; cookie_write_function_t *write; cookie_seek_function_t *seek; From 8a6bd7307da3fc4d08dd6a9277b611ccb4971354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Tue, 22 Nov 2016 10:29:08 +0200 Subject: [PATCH 005/161] implement strftime padding specifier extensions notes added by maintainer: the '-' specifier allows default padding to be suppressed, and '_' allows padding with spaces instead of the default (zeros). these extensions seem to be included in several other implementations including FreeBSD and derivatives, and Solaris. while portable software should not depend on them, time format strings are often exposed to the user for configurable time display. reportedly some python programs also use and depend on them. --- src/time/strftime.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/time/strftime.c b/src/time/strftime.c index a3039204..d1ca7cae 100644 --- a/src/time/strftime.c +++ b/src/time/strftime.c @@ -48,12 +48,12 @@ static int week_num(const struct tm *tm) const char *__tm_to_tzname(const struct tm *); size_t __strftime_l(char *restrict, size_t, const char *restrict, const struct tm *restrict, locale_t); -const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc) +const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc, int pad) { nl_item item; long long val; const char *fmt = "-"; - int width = 2; + int width = 2, def_pad = '0'; switch (f) { case 'a': @@ -79,15 +79,14 @@ const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm * case 'C': val = (1900LL+tm->tm_year) / 100; goto number; + case 'e': + def_pad = '_'; case 'd': val = tm->tm_mday; goto number; case 'D': fmt = "%m/%d/%y"; goto recu_strftime; - case 'e': - *l = snprintf(*s, sizeof *s, "%2d", tm->tm_mday); - return *s; case 'F': fmt = "%Y-%m-%d"; goto recu_strftime; @@ -200,7 +199,12 @@ const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm * return 0; } number: - *l = snprintf(*s, sizeof *s, "%0*lld", width, val); + switch (pad ? pad : def_pad) { + case '-': *l = snprintf(*s, sizeof *s, "%lld", val); break; + case '_': *l = snprintf(*s, sizeof *s, "%*lld", width, val); break; + case '0': + default: *l = snprintf(*s, sizeof *s, "%0*lld", width, val); break; + } return *s; nl_strcat: fmt = __nl_langinfo_l(item, loc); @@ -221,7 +225,7 @@ size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const st char buf[100]; char *p; const char *t; - int plus; + int pad, plus; unsigned long width; for (l=0; l Date: Tue, 12 Dec 2017 13:12:12 -0500 Subject: [PATCH 006/161] add ibm1047 codepage (ebcdic representation of latin1) to iconv --- src/locale/codepages.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/locale/codepages.h b/src/locale/codepages.h index 626d1433..724a846f 100644 --- a/src/locale/codepages.h +++ b/src/locale/codepages.h @@ -286,3 +286,23 @@ "\323\174\103\215\64\365\124\123\213\77\336\150\263\115\66\375\164\363\12\55" "\255\304\42\261\57\266\234\162\17\56\260\240\162\113\56\263\310\62\66\50" +"ibm1047\0" +"cp1047\0" +"\0\1" +"\234\44\140\310\37\227\64\342\310\2\14\64\340\300\3\20\104\40\301\4" +"\235\24\202\300\41\30\144\40\311\43\34\164\340\301\7\200\4\42\310\40" +"\204\50\160\301\6\210\44\242\310\42\214\24\140\300\1\220\104\142\301\44" +"\224\124\142\11\1\230\144\242\311\46\24\124\340\211\6\40\200\42\16\71" +"\340\204\63\116\71\347\304\43\212\13\74\240\260\2\37\46\244\243\316\72" +"\350\264\343\316\73\354\174\23\2\11\52\244\260\203\27\55\274\40\14\61" +"\300\4\63\114\61\307\104\143\12\13\45\174\341\303\17\370\44\243\314\62" +"\310\64\343\314\63\314\200\241\303\10\100\234\320\203\10\330\204\41\306\30" +"\144\224\141\306\31\150\244\261\312\56\360\364\343\117\54\260\250\261\6\33" +"\155\270\361\6\34\161\310\241\212\56\346\340\142\14\51\265\370\61\7\35" +"\165\330\161\7\36\171\350\21\312\57\320\154\341\215\53\254\214\122\312\55" +"\251\234\142\13\57\275\370\322\15\52\257\164\101\313\65\173\4\41\304\20" +"\104\24\141\304\21\110\44\321\12\75\366\310\63\117\75\175\50\261\4\23" +"\115\70\361\4\24\121\110\221\313\76\374\344\243\317\77\134\334\63\5\25" +"\125\130\161\5\26\131\150\41\13\65\326\110\63\115\65\60\304\40\303\14" +"\64\324\140\303\15\70\344\60\313\66\334\144\243\315\47" + From 64303156832bc555d11c181168db1e7834ac7069 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 14 Dec 2017 18:54:54 -0500 Subject: [PATCH 007/161] fix data race in at_quick_exit aside from theoretical arbitrary results due to UB, this could practically cause unbounded overflow of static array if hit, but hitting it depends on having more than 32 calls to at_quick_exit and having them sufficiently often. --- src/exit/at_quick_exit.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/exit/at_quick_exit.c b/src/exit/at_quick_exit.c index 34541bad..ac28dfd9 100644 --- a/src/exit/at_quick_exit.c +++ b/src/exit/at_quick_exit.c @@ -21,9 +21,10 @@ void __funcs_on_quick_exit() int at_quick_exit(void (*func)(void)) { - if (count == 32) return -1; + int r = 0; LOCK(lock); - funcs[count++] = func; + if (count == 32) r = -1; + else funcs[count++] = func; UNLOCK(lock); - return 0; + return r; } From 131276809fe3b7bed6086772bc5e3e9941dc6c6c Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Tue, 12 Dec 2017 10:27:23 +0000 Subject: [PATCH 008/161] fix x32 unistd macros to report as ILP32 not LP64 --- arch/x32/bits/posix.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x32/bits/posix.h b/arch/x32/bits/posix.h index c37b94c1..30a38714 100644 --- a/arch/x32/bits/posix.h +++ b/arch/x32/bits/posix.h @@ -1,2 +1,2 @@ -#define _POSIX_V6_LP64_OFF64 1 -#define _POSIX_V7_LP64_OFF64 1 +#define _POSIX_V6_ILP32_OFFBIG 1 +#define _POSIX_V7_ILP32_OFFBIG 1 From 3ec82877e7783f0706ba3c9e3c815cd2aa34059e Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 7 Dec 2017 23:18:54 +0100 Subject: [PATCH 009/161] fix sysconf for infinite rlimits sysconf should return -1 for infinity, not LONG_MAX. --- src/conf/sysconf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/conf/sysconf.c b/src/conf/sysconf.c index b8b761d0..9ce330a5 100644 --- a/src/conf/sysconf.c +++ b/src/conf/sysconf.c @@ -174,6 +174,8 @@ long sysconf(int name) } else if (values[name] < -256) { struct rlimit lim; getrlimit(values[name]&16383, &lim); + if (lim.rlim_cur == RLIM_INFINITY) + return -1; return lim.rlim_cur > LONG_MAX ? LONG_MAX : lim.rlim_cur; } From eb7f93c4f6fd0b637a9f8d6e112131b88ad2b00f Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Thu, 7 Dec 2017 17:54:07 +0100 Subject: [PATCH 010/161] use the name UTC instead of GMT for UTC timezone notes by maintainer: both C and POSIX use the term UTC to specify related functionality, despite POSIX defining it as something more like UT1 or historical (pre-UTC) GMT without leap seconds. neither specifies the associated string for %Z. old choice of "GMT" violated principle of least surprise for users and some applications/tests. use "UTC" instead. --- src/time/__tz.c | 16 ++++++++-------- src/time/gmtime_r.c | 4 ++-- src/time/timegm.c | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/time/__tz.c b/src/time/__tz.c index ffe8d402..8cc96032 100644 --- a/src/time/__tz.c +++ b/src/time/__tz.c @@ -15,7 +15,7 @@ weak_alias(__tzname, tzname); static char std_name[TZNAME_MAX+1]; static char dst_name[TZNAME_MAX+1]; -const char __gmt[] = "GMT"; +const char __utc[] = "UTC"; static int dst_off; static int r0[5], r1[5]; @@ -126,7 +126,7 @@ static void do_tzset() s = getenv("TZ"); if (!s) s = "/etc/localtime"; - if (!*s) s = __gmt; + if (!*s) s = __utc; if (old_tz && !strcmp(s, old_tz)) return; @@ -136,7 +136,7 @@ static void do_tzset() * free so as not to pull it into static programs. Growth * strategy makes it so free would have minimal benefit anyway. */ i = strlen(s); - if (i > PATH_MAX+1) s = __gmt, i = 3; + if (i > PATH_MAX+1) s = __utc, i = 3; if (i >= old_tz_size) { old_tz_size *= 2; if (i >= old_tz_size) old_tz_size = i+1; @@ -165,12 +165,12 @@ static void do_tzset() } } } - if (!map) s = __gmt; + if (!map) s = __utc; } if (map && (map_size < 44 || memcmp(map, "TZif", 4))) { __munmap((void *)map, map_size); map = 0; - s = __gmt; + s = __utc; } zi = map; @@ -207,7 +207,7 @@ static void do_tzset() } } if (!__tzname[0]) __tzname[0] = __tzname[1]; - if (!__tzname[0]) __tzname[0] = (char *)__gmt; + if (!__tzname[0]) __tzname[0] = (char *)__utc; if (!__daylight) { __tzname[1] = __tzname[0]; dst_off = __timezone; @@ -216,7 +216,7 @@ static void do_tzset() } } - if (!s) s = __gmt; + if (!s) s = __utc; getname(std_name, &s); __tzname[0] = std_name; __timezone = getoff(&s); @@ -413,7 +413,7 @@ const char *__tm_to_tzname(const struct tm *tm) const void *p = tm->__tm_zone; LOCK(lock); do_tzset(); - if (p != __gmt && p != __tzname[0] && p != __tzname[1] && + if (p != __utc && p != __tzname[0] && p != __tzname[1] && (!zi || (uintptr_t)p-(uintptr_t)abbrevs >= abbrevs_end - abbrevs)) p = ""; UNLOCK(lock); diff --git a/src/time/gmtime_r.c b/src/time/gmtime_r.c index 8cbdadcb..cba72447 100644 --- a/src/time/gmtime_r.c +++ b/src/time/gmtime_r.c @@ -2,7 +2,7 @@ #include #include "libc.h" -extern const char __gmt[]; +extern const char __utc[]; struct tm *__gmtime_r(const time_t *restrict t, struct tm *restrict tm) { @@ -12,7 +12,7 @@ struct tm *__gmtime_r(const time_t *restrict t, struct tm *restrict tm) } tm->tm_isdst = 0; tm->__tm_gmtoff = 0; - tm->__tm_zone = __gmt; + tm->__tm_zone = __utc; return tm; } diff --git a/src/time/timegm.c b/src/time/timegm.c index b5dae8b6..f444e76e 100644 --- a/src/time/timegm.c +++ b/src/time/timegm.c @@ -2,7 +2,7 @@ #include "time_impl.h" #include -extern const char __gmt[]; +extern const char __utc[]; time_t timegm(struct tm *tm) { @@ -15,6 +15,6 @@ time_t timegm(struct tm *tm) *tm = new; tm->tm_isdst = 0; tm->__tm_gmtoff = 0; - tm->__tm_zone = __gmt; + tm->__tm_zone = __utc; return t; } From 2a831786f0be3f54c5a7693eb3ae8fdc4c4ecb85 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Thu, 7 Dec 2017 15:55:52 +0000 Subject: [PATCH 011/161] remove unused explicit dependency rules for crti/crtn notes by maintainer: commit 2f853dd6b9a95d5b13ee8f9df762125e0588df5d added these rules because the new system for handling arch-provided replacement files introduced for out-of-tree builds did not apply to the crt tree. commit 63bcda4d8f4074e9d92ae156afd0dced6e64eb65 later adapted the makefile logic so that the crt and ldso trees go through the same replacement logic as everything else, but failed to remove the explicit rules that assumed the arch would always provide asm replacements. in addition to cleaning things up, removing these spurious rules allows crti/crtn asm to be omitted by an arch (thereby using the empty C files instead) if they are not needed. --- Makefile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Makefile b/Makefile index d2e89979..308ddaae 100644 --- a/Makefile +++ b/Makefile @@ -113,10 +113,6 @@ obj/crt/rcrt1.o: $(srcdir)/ldso/dlstart.c obj/crt/Scrt1.o obj/crt/rcrt1.o: CFLAGS_ALL += -fPIC -obj/crt/$(ARCH)/crti.o: $(srcdir)/crt/$(ARCH)/crti.s - -obj/crt/$(ARCH)/crtn.o: $(srcdir)/crt/$(ARCH)/crtn.s - OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(srcdir)/src/%)) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.lo): CFLAGS += -O3 From 14cec8678e742edad82f065dcfe926e45f84d4ac Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Mon, 4 Dec 2017 12:13:06 +0100 Subject: [PATCH 012/161] fix endian errors in arpa/nameser.h due to failure to include endian.h --- include/arpa/nameser.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/arpa/nameser.h b/include/arpa/nameser.h index 581925a4..b315e0f3 100644 --- a/include/arpa/nameser.h +++ b/include/arpa/nameser.h @@ -7,6 +7,7 @@ extern "C" { #include #include +#include #define __NAMESER 19991006 #define NS_PACKETSZ 512 From d5029bb88a4ff91b007a19c7d9efb790aab63246 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 15 Dec 2017 12:58:33 -0500 Subject: [PATCH 013/161] fix endian errors in netinet/icmp6.h due to failure to include endian.h --- include/netinet/icmp6.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/netinet/icmp6.h b/include/netinet/icmp6.h index 01269e7d..cf951d91 100644 --- a/include/netinet/icmp6.h +++ b/include/netinet/icmp6.h @@ -9,6 +9,7 @@ extern "C" { #include #include #include +#include #define ICMP6_FILTER 1 From d3f23337eecf68d085be212167c167f9cc49dbe5 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 18 Dec 2017 18:01:42 -0500 Subject: [PATCH 014/161] reformat ctype tables to be diff-friendly, match tool output the new version of the code used to generate these tables forces a newline every 256 entries, whereas at the time these files were originally generated and committed, it only wrapped them at 80 columns. the new behavior ensures that localized changes to the tables, if they are ever needed, will produce localized diffs. commit d060edf6c569ba9df4b52d6bcd93edde812869c9 made the corresponding changes to the iconv tables. --- src/ctype/alpha.h | 221 +++++++++++++++++++++-------------------- src/ctype/nonspacing.h | 81 +++++++-------- src/ctype/punct.h | 190 ++++++++++++++++++----------------- src/ctype/wide.h | 49 ++++----- 4 files changed, 277 insertions(+), 264 deletions(-) diff --git a/src/ctype/alpha.h b/src/ctype/alpha.h index b318c827..e584e8a8 100644 --- a/src/ctype/alpha.h +++ b/src/ctype/alpha.h @@ -7,119 +7,124 @@ 17,17,17,55,17,17,17,17,56,17,57,58,59,60,61,62,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,63,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,64,65,17,66,67,68,69,70,71,72, -73,16,16,16,74,75,76,77,78,16,16,16,79,80,16,16,16,16,81,16,16,16,16,16,16,16, -16,16,17,17,17,82,83,16,16,16,16,16,16,16,16,16,16,16,17,17,17,17,84,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,64,65,17,66,67, +68,69,70,71,72,73,16,16,16,74,75,76,77,78,16,16,16,79,80,16,16,16,16,81,16,16, +16,16,16,16,16,16,16,17,17,17,82,83,16,16,16,16,16,16,16,16,16,16,16,17,17,17, +17,84,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,85,16, -16,16,16,86,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,17,17,85,16,16,16,16,86,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,87,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,87,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -88,89,90,91,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -92,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255, +16,16,16,16,16,88,89,90,91,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,92,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,0,0,0,0,0,0,0,0,254,255,255,7,254,255,255,7,0,0,0,0,0,4,32,4, -255,255,127,255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,195,255,3,0,31,80,0,0,0,0, -0,0,0,0,0,0,32,0,0,0,0,0,223,60,64,215,255,255,251,255,255,255,255,255,255, -255,255,255,191,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,3,252,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,0,254,255,255,255,127,2,254,255,255,255,255,0,0,0,0,0,255,191,182, -0,255,255,255,7,7,0,0,0,255,7,255,255,255,255,255,255,255,254,255,195,255,255, -255,255,255,255,255,255,255,255,255,255,239,31,254,225,255,159,0,0,255,255, -255,255,255,255,0,224,255,255,255,255,255,255,255,255,255,255,255,255,3,0,255, -255,255,255,255,7,48,4,255,255,255,252,255,31,0,0,255,255,255,1,0,0,0,0,0,0,0, -0,253,31,0,0,0,0,0,0,240,3,255,127,255,255,255,255,255,255,255,239,255,223, -225,255,207,255,254,254,238,159,249,255,255,253,197,227,159,89,128,176,207, -255,3,0,238,135,249,255,255,253,109,195,135,25,2,94,192,255,63,0,238,191,251, -255,255,253,237,227,191,27,1,0,207,255,0,0,238,159,249,255,255,253,237,227, -159,25,192,176,207,255,2,0,236,199,61,214,24,199,255,195,199,29,129,0,192,255, -0,0,238,223,253,255,255,253,239,227,223,29,96,3,207,255,0,0,236,223,253,255, -255,253,239,227,223,29,96,64,207,255,6,0,236,223,253,255,255,255,255,231,223, -93,128,0,207,255,0,252,236,255,127,252,255,255,251,47,127,128,95,255,0,0,12,0, -254,255,255,255,255,127,255,7,63,32,255,3,0,0,0,0,150,37,240,254,174,236,255, -59,95,32,255,243,0,0,0,0,1,0,0,0,255,3,0,0,255,254,255,255,255,31,254,255,3, -255,255,254,255,255,255,31,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,249, -255,3,255,255,231,193,255,255,127,64,255,51,255,255,255,255,191,32,255,255, -255,255,255,247,255,255,255,255,255,255,255,255,255,61,127,61,255,255,255,255, -255,61,255,255,255,255,61,127,61,255,127,255,255,255,255,255,255,255,61,255, -255,255,255,255,255,255,255,135,0,0,0,0,255,255,0,0,255,255,255,255,255,255, -255,255,255,255,31,0,254,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,254,255,255,7,254, +255,255,7,0,0,0,0,0,4,32,4,255,255,127,255,255,255,127,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,159,255,255,254,255,255,7,255, -255,255,255,255,255,255,255,255,199,1,0,255,223,15,0,255,255,15,0,255,255,15, -0,255,223,13,0,255,255,255,255,255,255,207,255,255,1,128,16,255,3,0,0,0,0,255, -3,255,255,255,255,255,255,255,255,255,255,255,0,255,255,255,255,255,7,255,255, -255,255,255,255,255,255,63,0,255,255,255,31,255,15,255,1,192,255,255,255,255, -63,31,0,255,255,255,255,255,15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255, -255,255,255,255,255,255,127,254,255,31,0,255,3,255,3,128,0,0,0,0,0,0,0,0,0,0, -0,255,255,255,255,255,255,239,255,239,15,255,3,0,0,0,0,255,255,255,255,255, -243,255,255,255,255,255,255,191,255,3,0,255,255,255,255,255,255,63,0,255,227, -255,255,255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,222,111,0,255,255,255,255, +255,195,255,3,0,31,80,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,223,60,64,215,255,255, +251,255,255,255,255,255,255,255,255,255,191,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,3,252,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,0,254,255,255,255,127,2,254,255,255, +255,255,0,0,0,0,0,255,191,182,0,255,255,255,7,7,0,0,0,255,7,255,255,255,255, +255,255,255,254,255,195,255,255,255,255,255,255,255,255,255,255,255,255,239, +31,254,225,255, +159,0,0,255,255,255,255,255,255,0,224,255,255,255,255,255,255,255,255,255,255, +255,255,3,0,255,255,255,255,255,7,48,4,255,255,255,252,255,31,0,0,255,255,255, +1,0,0,0,0,0,0,0,0,253,31,0,0,0,0,0,0,240,3,255,127,255,255,255,255,255,255, +255,239,255,223,225,255,207,255,254,254,238,159,249,255,255,253,197,227,159, +89,128,176,207,255,3,0,238,135,249,255,255,253,109,195,135,25,2,94,192,255,63, +0,238,191,251,255,255,253,237,227,191,27,1,0,207,255,0,0,238,159,249,255,255, +253,237,227,159,25,192,176,207,255,2,0,236,199,61,214,24,199,255,195,199,29, +129,0,192,255,0,0,238,223,253,255,255,253,239,227,223,29,96,3,207,255,0,0,236, +223,253,255,255,253,239,227,223,29,96,64,207,255,6,0,236,223,253,255,255,255, +255,231,223,93,128,0,207,255,0,252,236,255,127,252,255,255,251,47,127,128,95, +255,0,0,12,0,254,255,255,255,255,127,255,7,63,32,255,3,0,0,0,0,150,37,240,254, +174,236,255,59,95,32,255,243,0,0,0, +0,1,0,0,0,255,3,0,0,255,254,255,255,255,31,254,255,3,255,255,254,255,255,255, +31,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,249,255,3,255,255,231,193,255, +255,127,64,255,51,255,255,255,255,191,32,255,255,255,255,255,247,255,255,255, +255,255,255,255,255,255,61,127,61,255,255,255,255,255,61,255,255,255,255,61, +127,61,255,127,255,255,255,255,255,255,255,61,255,255,255,255,255,255,255,255, +135,0,0,0,0,255,255,0,0,255,255,255,255,255,255,255,255,255,255,31,0,254,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,0,0,0,0,0,0,0,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255, -63,255,255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255, -243,224,67,0,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,255,255,255,255,255,3,0,0,255,255,255, -255,255,127,255,255,255,255,255,127,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,31,120,12,0,255,255,255,255,191,32,255,255,255,255, -255,255,255,128,0,0,255,255,127,0,127,127,127,127,127,127,127,127,255,255,255, -255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,0,0, -0,254,3,62,31,254,255,255,255,255,255,255,255,255,255,127,224,254,255,255,255, -255,255,255,255,255,255,255,247,224,255,255,255,255,63,254,255,255,255,255, -255,255,255,255,255,255,127,0,0,255,255,255,7,0,0,0,0,0,0,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -63,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,31,0,0,0,0,0,0,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,255, -255,255,255,255,63,255,31,255,255,255,15,0,0,255,255,255,255,255,127,240,143, -255,255,255,128,255,255,255,255,255,255,255,255,255,255,0,0,0,0,128,255,252, -255,255,255,255,255,255,255,255,255,255,255,255,121,15,0,255,7,0,0,0,0,0,0,0, -0,0,255,187,247,255,255,255,0,0,0,255,255,255,255,255,255,15,0,255,255,255, -255,255,255,255,255,15,0,255,3,0,0,252,8,255,255,255,255,255,7,255,255,255, -255,7,0,255,255,255,31,255,255,255,255,255,255,247,255,0,128,255,3,0,0,0,0, -255,255,255,255,255,255,127,0,255,63,255,3,255,255,127,4,255,255,255,255,255, -255,255,127,5,0,0,56,255,255,60,0,126,126,126,0,127,127,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,255,255,255,255,255,7,255,3,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255, -255,255,15,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255, -255,255,255,255,255,255,255,255,255,255,3,0,0,0,0,127,0,248,224,255,253,127, -95,219,255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,0,248,255, -255,255,255,255,255,255,255,255,255,255,255,63,0,0,255,255,255,255,255,255, -255,255,252,255,255,255,255,255,255,0,0,0,0,0,255,15,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,223,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0, -0,255,3,254,255,255,7,254,255,255,7,192,255,255,255,255,255,255,255,255,255, -255,127,252,252,252,28,0,0,0,0,255,239,255,255,127,255,255,183,255,63,255,63, -0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0, -0,0,0,0,255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,255,255,255,1,0,0,0,0,0, -255,255,255,127,0,0,255,255,255,7,0,0,0,0,0,0,255,255,255,63,255,255,255,255, -15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,63,255,3,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255,191, -145,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,63,0,255,255, -255,3,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111,240, -239,254,255,255,15,0,0,0,0,0,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,255,255,255,255,255,255,255,255,63,0,0,0,192,255,0,0,252,255,255, -255,255,255,255,1,0,0,255,255,255,1,255,3,255,255,255,255,255,255,199,255,0,0, -0,0,0,0,0,0,255,255,255,255,255,255,255,255,30,0,255,3,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,63,0,255,3,0,0,0,0,0,0,255,255,255, -255,255,255,255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,255,255,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,255,255,255,255,255,255,255,255,31,0,255,255,255,255,255,127,0,0, -248,255,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255, -255,255,255,255,223,100,222,255,235,239,255,255,255,255,255,255,255,191,231, -223,223,255,255,255,123,95,252,253,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,159,255,255,254,255,255,7,255,255,255,255,255,255,255,255, +255,199,1,0,255,223,15,0,255,255,15,0,255,255,15,0,255,223,13,0,255,255,255, +255,255,255,207,255,255,1,128,16,255,3,0,0,0,0,255,3,255,255,255,255,255,255, +255,255,255,255,255,0,255,255,255,255,255,7,255,255,255,255,255,255,255,255, +63, +0,255,255,255,31,255,15,255,1,192,255,255,255,255,63,31,0,255,255,255,255,255, +15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255,255,255,255,255,255,255,127, +254,255,31,0,255,3,255,3,128,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255, +239,255,239,15,255,3,0,0,0,0,255,255,255,255,255,243,255,255,255,255,255,255, +191,255,3,0,255,255,255,255,255,255,63,0,255,227,255,255,255,255,255,63,0,0,0, +0,0,0,0,0,0,0,0,0,0,222,111,0,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,255,255,63,63, +255,255,255,255,63,63,255,170,255,255,255,63,255,255,255,255,255,255,223,95, +220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,128,0,0,255,31,0,0, +0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255,243,224,67,0,0,255,255,255,255, +255,1,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,255,255,255,255,255,3,0, +0,255,255,255,255,255,127,255,255,255,255,255,127,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,31,120,12,0,255,255,255,255,191,32,255, +255,255,255,255,255,255,128,0,0,255,255,127,0,127,127,127,127,127,127,127,127, +255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,224,0,0,0,254,3,62,31,254,255,255,255,255,255,255,255,255,255,127,224,254, +255,255,255,255,255,255,255,255,255,255,247,224,255,255,255,255,63,254,255, +255,255,255,255,255,255,255,255,255,127,0,0,255,255,255,7,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,253,255,255, -247,255,255,255,247,255,255,223,255,255,255,223,255,255,127,255,255,255,127, -255,255,255,253,255,255,255,253,255,255,247,207,255,255,255,255,255,255,239, -255,255,255,150,254,247,10,132,234,150,170,150,247,247,94,255,251,255,15,238, -251,255,15,0,0,0,0,0,0,0,0, +255,255,255,63,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,0,0,0, +0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0, +0,0,0,0,0,0,255,255,255,255,255,63,255,31,255,255,255,15,0,0,255,255,255,255, +255,127,240,143,255,255,255,128,255,255,255,255,255,255,255,255,255,255,0,0,0, +0,128,255,252,255,255,255,255,255,255,255,255,255,255,255,255,121,15,0,255,7, +0,0,0,0,0,0,0,0,0,255,187,247,255,255,255,0,0,0,255,255,255,255,255,255,15,0, +255,255,255,255,255,255,255,255,15,0,255,3,0,0,252,8,255,255,255,255,255,7, +255,255,255,255,7,0,255,255,255,31,255,255,255,255,255,255,247,255,0,128,255, +3,0,0,0,0,255,255,255,255,255,255,127,0,255,63,255,3,255,255,127,4,255,255, +255,255,255,255,255,127,5,0,0,56,255,255,60,0,126,126,126,0,127,127,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,7,255,3,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248, +255,255,255,255,255, +15,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,255,255, +255,255,255,255,255,255,255,255,3,0,0,0,0,127,0,248,224,255,253,127,95,219, +255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,0,248,255,255,255, +255,255,255,255,255,255,255,255,255,63,0,0,255,255,255,255,255,255,255,255, +252,255,255,255,255,255,255,0,0,0,0,0,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,223, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,255,3, +254,255,255,7,254,255,255,7,192,255,255,255,255,255,255,255,255,255,255,127, +252,252,252,28,0,0,0,0,255,239,255,255,127,255,255,183,255,63,255,63,0,0,0,0, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,255,255,255,1,0,0,0,0, +0,255,255,255,127,0,0,255,255,255,7,0,0,0,0,0,0,255,255,255,63,255,255,255, +255,15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,63,255,3,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255, +191,145,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,63,0,255, +255,255,3,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111, +240,239,254,255,255,15,0,0,0,0,0,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,63,0,0,0,192,255,0,0,252,255, +255,255,255,255,255,1,0,0,255,255,255,1,255, +3,255,255,255,255,255,255,199,255,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255, +255,30,0,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, +255,63,0,255,3,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255, +255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, +255,255,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, +127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, +255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, +255,255,255,31,0,255,255,255,255,255,127,0,0,248,255,0,0,0,0,0,0,0,0,0,0,0,0, +3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,255,255,255, +223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255, +255,123,95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,63,255,255,255,253,255,255,247,255,255,255, +247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,255,253, +255,255,255,253,255,255,247,207,255,255,255,255,255,255,239,255,255,255,150, +254,247,10,132,234,150,170,150,247,247,94,255,251,255,15,238,251,255,15,0,0,0, +0,0,0,0,0, diff --git a/src/ctype/nonspacing.h b/src/ctype/nonspacing.h index 4c25ef51..cd9fec97 100644 --- a/src/ctype/nonspacing.h +++ b/src/ctype/nonspacing.h @@ -7,48 +7,50 @@ 16,16,16,16,16,16,16,16,16,16,44,16,45,46,47,48,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,49,16,16,50,51,16,52,16,16, -16,16,16,16,16,16,53,16,16,16,16,16,54,55,16,16,16,16,56,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,49,16,16,50, +51,16,52,16,16,16,16,16,16,16,16,53,16,16,16,16,16,54,55,16,16,16,16,56,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,57,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,57,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,58,59,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255, +16,16,58,59,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,3,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,255,255,191, -182,0,0,0,0,0,0,0,31,0,255,7,0,0,0,0,0,248,255,255,0,0,1,0,0,0,0,0,0,0,0,0,0, -0,192,191,159,61,0,0,0,128,2,0,0,0,255,255,255,7,0,0,0,0,0,0,0,0,0,0,192,255, -1,0,0,0,0,0,0,248,15,0,0,0,192,251,239,62,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,240,255,255,127,7,0,0,0,0,0,0,20,254,33,254,0,12,0,0,0,2,0,0,0,0,0, -0,16,30,32,0,0,12,0,0,0,6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16, -190,33,0,0,12,0,0,0,2,0,0,0,0,0,0,144,30,32,64,0,12,0,0,0,4,0,0,0,0,0,0,0,1, -32,0,0,0,0,0,0,0,0,0,0,0,0,0,192,193,61,96,0,12,0,0,0,0,0,0,0,0,0,0,144,64,48, -0,0,12,0,0,0,0,0,0,0,0,0,0,0,30,32,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,4,92,0,0,0, -0,0,0,0,0,0,0,0,242,7,128,127,0,0,0,0,0,0,0,0,0,0,0,0,242,27,0,63,0,0,0,0,0,0, -0,0,0,3,0,0,160,2,0,0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0, -0,0,0,0,0,0,0,0,0,224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -28,0,0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,15,32,0,0,0,0,0,56, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,1,4, -14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,1,0,0,0,0,0,0,64, -127,229,31,248,159,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,208,23,4,0,0, -0,0,248,15,0,3,0,0,0,60,11,0,0,0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,255,255,255,255,127,0,0,240,0,248,0,0,0,124,0,0,0,0,0,0,31, -252,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0, -0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,247,63,0,0,0,128,0,0,0,0,0, -0,0,0,0,0,3,0,68,8,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,255, -255,3,0,0,0,0,0,192,63,0,0,128,255,3,0,0,0,0,0,7,0,0,0,0,0,200,19,0,0,0,0,0,0, -0,0,0,0,0,0,0,126,102,0,8,16,0,0,0,0,0,0,0,0,0,0,0,0,157,193,2,0,0,0,0,48,64, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,248,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,254,255,255,255,255,191,182,0,0,0,0,0,0,0,31,0,255,7,0,0,0,0,0,248,255, +255,0,0,1,0,0,0,0,0,0,0,0,0,0,0,192,191,159,61,0,0,0,128,2,0,0,0,255,255,255, +7,0,0,0,0,0,0,0,0,0,0,192,255,1,0,0,0,0,0,0,248,15,0,0,0,192,251,239,62,0,0,0, +0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,255,255, +127,7,0,0,0,0,0,0,20,254,33,254,0,12,0,0,0,2,0,0,0,0,0,0,16,30,32,0,0,12,0,0, +0,6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16,190,33,0,0,12,0,0,0,2, +0,0,0,0,0,0,144,30,32,64,0,12,0,0,0,4,0,0,0,0,0,0,0,1,32,0,0,0,0,0,0,0,0,0,0, +0,0,0,192,193,61,96,0,12,0,0,0,0,0,0,0,0,0,0,144,64,48,0,0,12,0,0,0,0,0,0,0,0, +0,0,0,30,32,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,4,92,0,0,0,0,0,0,0,0,0,0,0,242,7, +128,127,0,0,0,0,0,0,0,0,0,0,0,0,242,27,0,63,0,0,0,0,0,0,0,0,0,3,0,0,160,2,0,0, +0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,0,0,0,0,0,224, +253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0, +0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,15,32,0,0,0,0,0,56,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,1,0,0,0,0,0,0,64,127,229, +31,248,159,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,208,23,4,0,0,0,0,248, +15,0,3,0,0,0,60,11,0,0,0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,255,255,255,255,127,0,0, +240,0,248,0,0,0,124,0,0,0,0,0,0,31,252,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255, +255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0, +0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,128,247,63,0,0,0,128,0,0,0,0,0,0,0,0,0,0,3,0,68,8,0,0,96,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,255,255,3,0,0,0,0,0,192,63,0,0,128,255,3,0,0, +0,0,0,7,0,0,0,0,0,200,19,0,0,0,0,0,0,0,0,0,0,0,0,0,126,102,0,8,16,0,0,0,0,0,0, +0,0,0,0,0,0,157,193,2,0,0,0,0,48,64, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,127,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0, @@ -56,7 +58,8 @@ 0,0,0,0,0,0,0,0,0,0,0,32,110,240,0,0,0,0,0,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,255,127,0,0,0,0,0,0,0,3,0,0,0,0,0,120,38,0,0, 0,0,0,0,0,0,7,0,0,0,128,239,31,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,192,127,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,128,3,248,255,231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,128,3,248,255,231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/src/ctype/punct.h b/src/ctype/punct.h index 466e6b33..a2c52562 100644 --- a/src/ctype/punct.h +++ b/src/ctype/punct.h @@ -7,103 +7,107 @@ 16,16,16,16,16,16,16,16,59,16,60,61,62,63,64,65,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,66,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,67,16,16,68,16,69,70,71,16,72,16,73, -16,16,16,16,74,75,76,77,16,16,78,16,79,80,16,16,16,16,81,16,16,16,16,16,16,16, -16,16,16,16,16,16,82,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,67,16,16,68,16,69,70, +71,16,72,16,73,16,16,16,16,74,75,76,77,16,16,78,16,79,80,16,16,16,16,81,16,16, +16,16,16,16,16,16,16,16,16,16,16,82,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,83,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,83,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,84,85,86,87, -16,16,88,89,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -90,16,91,92,93,94,95,96,97,98,16,16,16,16,16,16,16,16,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,84,85,86,87,16,16,88,89,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,90,16,91,92,93,94,95,96,97,98,16,16,16,16,16,16,16, +16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,0,0,0,0,254,255,0,252,1,0,0,248,1,0,0,120,0,0,0,0,255,251,223, -251,0,0,128,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,60,0, -252,255,224,175,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255, -255,32,64,176,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -252,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0,0,0,134,254, -255,255,255,0,64,73,0,0,0,0,0,24,0,223,255,0,200,0,0,0,0,0,0,0,1,0,60,0,0,0,0, -0,0,0,0,0,0,0,0,16,224,1,30,0,96,255,191,0,0,0,0,0,0,255,7,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,248,207,3,0,0,0,3,0,32,255,127,0,0,0,78,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,0,0,0,16,0,32,30,0,48,0,1,0,0,0,0,0,0,0,0,16, -0,32,0,0,0,0,252,15,0,0,0,0,0,0,0,16,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,32,0, -0,0,0,3,0,0,0,0,0,0,0,0,16,0,32,0,0,0,0,253,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0, -255,7,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,255,0,0,0,0,0,0,0,16,0,32,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,32,0,0,0,0,63,2,0,0,0,0,0,0,0,0,0,4,0,0,0,0,16,0,0,0,0,0,0, -128,0,128,192,223,0,12,0,0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,254,255,255, -255,0,252,255,255,0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,192,255,223,255,7,0,0,0,0,0, -0,0,0,0,0,128,6,0,252,0,0,24,62,0,0,128,191,0,204,0,0,0,0,0,0,0,0,0,0,0,8,0,0, -0,0,0,0,0,0,0,0,0,96,255,255,255,31,0,0,255,3,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, +255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,254,255,0,252,1,0,0,248,1, +0,0,120,0,0,0,0,255,251,223,251,0,0,128,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,60,0,252,255,224,175,255,255,255,255,255,255,255,255, +255,255,223,255,255,255,255,255,32,64,176,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,252,0,0,0,0,0,134,254,255,255,255,0,64,73,0,0,0,0,0,24,0,223,255,0,200, +0,0,0,0,0,0,0,1,0,60,0,0,0,0,0,0,0,0,0,0,0,0,16,224,1,30,0, +96,255,191,0,0,0,0,0,0,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,207,3, +0,0,0,3,0,32,255,127,0,0,0,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0,0,0, +0,0,0,0,16,0,32,30,0,48,0,1,0,0,0,0,0,0,0,0,16,0,32,0,0,0,0,252,15,0,0,0,0,0, +0,0,16,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,32,0,0,0,0,3,0,0,0,0,0,0,0,0,16,0, +32,0,0,0,0,253,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,255,7,0,0,0,0,0,0,0,0,0,32,0,0, +0,0,0,255,0,0,0,0,0,0,0,16,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,63,2, +0,0,0,0,0,0,0,0,0,4,0,0,0,0,16,0,0,0,0,0,0,128,0,128,192,223,0,12,0,0,0,0,0,0, +0,0,0,0,0,0,0,31,0,0,0,0,0, +0,254,255,255,255,0,252,255,255,0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,192,255,223, +255,7,0,0,0,0,0,0,0,0,0,0,128,6,0,252,0,0,24,62,0,0,128,191,0,204,0,0,0,0,0,0, +0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,96,255,255,255,31,0,0,255,3,0,0,0,0,0,0,0,0, +0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,96,0,0,1,0,0,24,0,0,0,0,0,0,0,0,0,56,0,0,0,0,16,0,0,0,112, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,0,0,254,127,47,0,0,255,3,255,127,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,49,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,196,255,255,255, +255,0,0,0,192,0,0,0,0,0,0,0,0,1,0,224,159,0,0,0,0,127,63,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,16,0,16,0,0,252,255,255,255,31,0,0,0,0,0,12,0,0,0,0,0,0,64,0,12, +240,0,0,0,0,0,0,192,248,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0,255,0,255,255,255, +33,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,127,0, +0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,3,224,0,224,0,224,0, +96,128,248,255,255,255,252,255,255,255,255,255,127,31,252,241,127,255,127,0,0, +255,255,255,3,0,0,255,255,255,255,1,0,123,3,208,193,175,66,0,12,31,188,255, +255,0,0,0,0,0,2,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,15, +0,255,255,255,255,127,0,0,0,255,7,0,0,255,255,255,255,255,255,255,255,255,255, +63,0,0,0,0,0,0,252,255,255,254,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,31,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,135,3, +254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, +255,255,255,127,255,15,0,0,0,0,0,0,0,0,255,255,255,251,255,255,255,255,255, +255,255,255,255,255,15,0,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,255,15,30,255, +255,255,1,252,193,224,0,0,0,0,0,0,0,0,0,0,0,30,1,0,0,0,0,0,0,0,0,0,0, +8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,255,255,255,15,0,0, +0,255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,255,255,255,255,255,255,127,0,0,0,0,0,0,192,0,224,0,0,0,0,0,0,0,0, +0,0,0,128,15,112,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,255,127,0,3,0,0,0,0,0, +0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68,8,0,0,0,15,255,3,0,0,0,0,0,0, +240,0,0,0,0,0,0,0,0,0,16,192,0,0,255,255,3,7,0,0,0,0,0,248,0,0,0,0,8,128,0,0, +0,0,0,0,0,0,0,0,8,0,255,63,0,192,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,128,11,0,0,0,0,0,0,0,128,2,0,0,192,0,0,67,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,0,0,1,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,96,0,0,1,0,0,24,0,0,0,0,0,0,0,0,0,56,0,0,0,0,16,0,0,0,112,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,48,0,0,254,127,47,0,0,255,3,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,49,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,196,255,255,255,255,0,0,0,192,0,0,0,0,0,0,0,0,1,0,224,159,0,0,0,0, -127,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,16,0,0,252,255,255,255,31,0,0,0,0, -0,12,0,0,0,0,0,0,64,0,12,240,0,0,0,0,0,0,192,248,0,0,0,0,0,0,0,192,0,0,0,0,0, -0,0,0,255,0,255,255,255,33,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,255,255,255,255,127,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -160,3,224,0,224,0,224,0,96,128,248,255,255,255,252,255,255,255,255,255,127,31, -252,241,127,255,127,0,0,255,255,255,3,0,0,255,255,255,255,1,0,123,3,208,193, -175,66,0,12,31,188,255,255,0,0,0,0,0,2,255,255,255,255,255,255,255,255,255, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,252,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,48,255,255,255,3,127,0,255,255,255,255,247,255,127,15,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,128,254,255,0,252,1,0,0,248,1,0,0,248,63,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,127,127,0, +48,135,255,255,255,255,255,143,255,0,0,0,0,0,0,224,255,255,7,255,15,0,0,0,0,0, +0,255,255,255,255,255,63,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0, +0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,192,143,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,135,255,0,255,1,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,254,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,63, +252,255,63,0,0,0,3,0,0,0,0,0,0,254,3,0,0,0,0,0,0, +0,0,0,0,0,0,0,24,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,225,1,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255,255, -255,255,127,0,0,0,255,7,0,0,255,255,255,255,255,255,255,255,255,255,63,0,0,0, -0,0,0,252,255,255,254,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,31,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,135,3,254,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,1,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, -127,255,15,0,0,0,0,0,0,0,0,255,255,255,251,255,255,255,255,255,255,255,255, -255,255,15,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,63,0,0,0,255,15,30,255,255,255,1,252, -193,224,0,0,0,0,0,0,0,0,0,0,0,30,1,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,255,255,255,15,0,0,0,255,255,255,127,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, -255,255,255,255,127,0,0,0,0,0,0,192,0,224,0,0,0,0,0,0,0,0,0,0,0,128,15,112,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,255,127,0,3,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,68,8,0,0,0,15,255,3,0,0,0,0,0,0,240,0,0,0,0,0,0,0,0,0, -16,192,0,0,255,255,3,7,0,0,0,0,0,248,0,0,0,0,8,128,0,0,0,0,0,0,0,0,0,0,8,0, -255,63,0,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,128,11,0,0,0,0,0,0,0,128,2, -0,0,192,0,0,67,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56, -0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,2,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,252,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,255,255,255,3,127,0,255,255,255,255,247, -255,127,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,254,255,0,252,1,0,0,248,1,0, -0,248,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,127,0,48,135,255,255,255,255,255, -143,255,0,0,0,0,0,0,224,255,255,7,255,15,0,0,0,0,0,0,255,255,255,255,255,63,0, -0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,128,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,143,0,0,0,128, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,255,0,255,1, -0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,0,0,0,255,0,0,0, -255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,127,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,63,252,255,63,0,0,0,3,0,0,0, -0,0,0,254,3,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -225,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,63,0,255,255,255,255,127,254,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,0, -255,255,255,255,255,255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,255,255,255,255,255,255,255,255,255,255,127,0,255,255,3,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,8,0,0,0, -8,0,0,32,0,0,0,32,0,0,128,0,0,0,128,0,0,0,2,0,0,0,2,0,0,8,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,255,255,255,255,255, -15,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255,127,254,127,254, -255,254,255,0,0,0,0,255,7,255,255,255,127,255,255,255,255,255,255,255,15,255, -255,255,255,255,7,0,0,0,0,0,0,0,0,192,255,255,255,7,0,255,255,255,255,255,7, -255,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,1,0,191,255, -255,255,255,255,255,255,255,31,255,255,15,0,255,255,255,255,223,7,0,0,255,255, -1,0,255,255,255,255,255,255,255,127,253,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,30,255,255,255,255,255, -255,255,63,15,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,255,255, -255,255,255,255,255,255,225,255,0,0,0,0,0,0,255,255,255,255,255,255,255,255, -63,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +63,0,255,255,255,255,127,254,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,63,0,0,0,0,255,255,255,255,255,255,255, +255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255, +255,255,255,255,127,0,255,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,8,0,0,0,8,0,0,32,0,0, +0,32,0,0,128,0,0,0,128,0,0,0,2,0,0,0,2,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,255,255,255,255,255,15,255,255, +255,255,255,255,255,255,255,255,255,255,15,0,255,127,254,127,254,255,254,255, +0,0,0,0,255,7,255,255,255,127,255,255,255,255,255,255,255,15,255,255,255,255, +255,7,0,0,0,0,0,0,0,0,192,255,255,255,7,0,255,255,255,255,255,7,255,1,3,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,1,0,191,255,255,255,255, +255,255,255,255,31,255,255,15,0,255,255,255,255,223,7,0,0,255,255,1,0,255,255, +255,255,255,255,255,127,253,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255, +30,255,255,255,255,255,255,255,63,15,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,248,255,255,255,255,255,255,255,255,225,255,0,0,0,0,0,0,255,255,255, +255,255,255,255,255,63,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/src/ctype/wide.h b/src/ctype/wide.h index 125d0ce3..ff08de18 100644 --- a/src/ctype/wide.h +++ b/src/ctype/wide.h @@ -7,36 +7,37 @@ 17,17,17,17,17,17,17,17,26,16,16,16,16,27,16,16,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,28,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,16,16,16,29,30,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,16,16,16,29, +30,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,31,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,31,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,32,16,16,16,16,16,16,16,16,16,16,16,16,16,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255, +16,16,16,16,16,16,16,16,16,32,16,16,16,16,16,16,16,16,16,16,16,16, +16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0, -0,248,0,0,0,0,0,0,0,0,0,0,252,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,251,255,255,255, -255,255,255,255,255,255,255,15,0,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,255,15, -255,255,255,255,255,255,255,127,254,255,255,255,255,255,255,255,255,255,127, -254,255,255,255,255,255,255,255,255,255,255,255,255,224,255,255,255,255,63, -254,255,255,255,255,255,255,255,255,255,255,127,255,255,255,255,255,7,255,255, -255,255,15,0,255,255,255,255,255,127,255,255,255,255,255,0,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,127,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,31,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255, -255,127,248,255,255,255,255,255,15,0,0,255,3,0,0,255,255,255,255,247,255,127, -15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,255,255,255,255,255,255, -255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,255,255,255,255,255,7,255,1,3,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,0,0,0,0,0,0,0,0,248,0,0,0,0,0,0,0,0,0,0,252,0,0,0,0,0,6,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,251,255,255,255,255,255,255,255,255,255,255,15,0,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,63,0,0,0,255,15,255,255,255,255,255,255,255,127,254,255,255,255, +255,255,255,255,255,255,127,254,255,255,255,255,255,255,255,255,255,255,255, +255,224,255,255,255,255,63,254,255,255,255,255,255,255,255,255,255,255,127, +255,255,255,255,255,7,255,255,255,255,15,0,255, +255,255,255,255,127,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,127,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0, +0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +31,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, +255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255, +255,255,15,0,0,255,3,0,0,255,255,255,255,247,255,127,15,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,254,255,255,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,127,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0, +0,7,0,255,255,255,255,255,7,255,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, From c72c1c52bc08aa0c41654bd0a38f6c951634e088 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 18 Dec 2017 18:05:23 -0500 Subject: [PATCH 015/161] update ctype tables to unicode 10.0 --- src/ctype/alpha.h | 169 ++++++++++++++++++++++--------------- src/ctype/nonspacing.h | 94 ++++++++++++--------- src/ctype/punct.h | 184 ++++++++++++++++++++++------------------- src/ctype/wide.h | 78 ++++++++++------- 4 files changed, 305 insertions(+), 220 deletions(-) diff --git a/src/ctype/alpha.h b/src/ctype/alpha.h index e584e8a8..299277c7 100644 --- a/src/ctype/alpha.h +++ b/src/ctype/alpha.h @@ -8,87 +8,88 @@ 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,63,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,64,65,17,66,67, -68,69,70,71,72,73,16,16,16,74,75,76,77,78,16,16,16,79,80,16,16,16,16,81,16,16, -16,16,16,16,16,16,16,17,17,17,82,83,16,16,16,16,16,16,16,16,16,16,16,17,17,17, -17,84,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +68,69,70,71,72,73,74,17,75,76,77,78,79,80,16,16,16,81,82,83,84,85,86,87,88,89, +16,90,16,91,92,16,16,17,17,17,93,94,95,16,16,16,16,16,16,16,16,16,16,17,17,17, +17,96,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,97,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,17,17,85,16,16,16,16,86,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,87,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,88,89,90,91,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,92,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,17,17,98,99,16,16,16,100,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, +17,17,17,17,17,17,17,101,17,17,102,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,103, +104,16,16,16,16,16,16,16,16,16,105,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,106,107,108,109,16,16,16,16,16,16,16,16,110,16,16, +16,16,16,16,16,111,112,16,16,16,16,113,16,16,114,16,16,16,16,16,16,16,16,16, +16,16,16,16, 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,254,255,255,7,254, 255,255,7,0,0,0,0,0,4,32,4,255,255,127,255,255,255,127,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,195,255,3,0,31,80,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,223,60,64,215,255,255, +255,195,255,3,0,31,80,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,223,188,64,215,255,255, 251,255,255,255,255,255,255,255,255,255,191,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,3,252,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,0,254,255,255,255,127,2,254,255,255, +255,255,255,255,255,255,255,255,255,255,255,254,255,255,255,127,2,254,255,255, 255,255,0,0,0,0,0,255,191,182,0,255,255,255,7,7,0,0,0,255,7,255,255,255,255, 255,255,255,254,255,195,255,255,255,255,255,255,255,255,255,255,255,255,239, 31,254,225,255, 159,0,0,255,255,255,255,255,255,0,224,255,255,255,255,255,255,255,255,255,255, 255,255,3,0,255,255,255,255,255,7,48,4,255,255,255,252,255,31,0,0,255,255,255, -1,0,0,0,0,0,0,0,0,253,31,0,0,0,0,0,0,240,3,255,127,255,255,255,255,255,255, -255,239,255,223,225,255,207,255,254,254,238,159,249,255,255,253,197,227,159, -89,128,176,207,255,3,0,238,135,249,255,255,253,109,195,135,25,2,94,192,255,63, -0,238,191,251,255,255,253,237,227,191,27,1,0,207,255,0,0,238,159,249,255,255, -253,237,227,159,25,192,176,207,255,2,0,236,199,61,214,24,199,255,195,199,29, -129,0,192,255,0,0,238,223,253,255,255,253,239,227,223,29,96,3,207,255,0,0,236, -223,253,255,255,253,239,227,223,29,96,64,207,255,6,0,236,223,253,255,255,255, -255,231,223,93,128,0,207,255,0,252,236,255,127,252,255,255,251,47,127,128,95, -255,0,0,12,0,254,255,255,255,255,127,255,7,63,32,255,3,0,0,0,0,150,37,240,254, -174,236,255,59,95,32,255,243,0,0,0, +1,255,7,0,0,0,0,0,0,255,255,223,63,0,0,240,255,248,3,255,255,255,255,255,255, +255,255,255,239,255,223,225,255,207,255,254,255,239,159,249,255,255,253,197, +227,159,89,128,176,207,255,3,16,238,135,249,255,255,253,109,195,135,25,2,94, +192,255,63,0,238,191,251,255,255,253,237,227,191,27,1,0,207,255,0,30,238,159, +249,255,255,253,237,227,159,25,192,176,207,255,2,0,236,199,61,214,24,199,255, +195,199,29,129,0,192,255,0,0,239,223,253,255,255,253,255,227,223,29,96,7,207, +255,0,0,239,223,253,255,255,253,239,227,223,29,96,64,207,255,6,0,239,223,253, +255,255,255,255,231,223,93,240,128,207,255,0,252,236,255,127,252,255,255,251, +47,127,128,95,255,192,255,12,0,254,255,255,255,255,127,255,7,63,32,255,3,0,0, +0,0,150,37,240,254,174,236,255,59,95,32,255,243,0,0,0, 0,1,0,0,0,255,3,0,0,255,254,255,255,255,31,254,255,3,255,255,254,255,255,255, 31,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,249,255,3,255,255,231,193,255, 255,127,64,255,51,255,255,255,255,191,32,255,255,255,255,255,247,255,255,255, 255,255,255,255,255,255,61,127,61,255,255,255,255,255,61,255,255,255,255,61, 127,61,255,127,255,255,255,255,255,255,255,61,255,255,255,255,255,255,255,255, -135,0,0,0,0,255,255,0,0,255,255,255,255,255,255,255,255,255,255,31,0,254,255, +135,0,0,0,0,255,255,0,0,255,255,255,255,255,255,255,255,255,255,63,63,254,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,159,255,255,254,255,255,7,255,255,255,255,255,255,255,255, -255,199,1,0,255,223,15,0,255,255,15,0,255,255,15,0,255,223,13,0,255,255,255, +255,199,255,1,255,223,15,0,255,255,15,0,255,255,15,0,255,223,13,0,255,255,255, 255,255,255,207,255,255,1,128,16,255,3,0,0,0,0,255,3,255,255,255,255,255,255, 255,255,255,255,255,0,255,255,255,255,255,7,255,255,255,255,255,255,255,255, 63, -0,255,255,255,31,255,15,255,1,192,255,255,255,255,63,31,0,255,255,255,255,255, -15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255,255,255,255,255,255,255,127, -254,255,31,0,255,3,255,3,128,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255, -239,255,239,15,255,3,0,0,0,0,255,255,255,255,255,243,255,255,255,255,255,255, -191,255,3,0,255,255,255,255,255,255,63,0,255,227,255,255,255,255,255,63,0,0,0, -0,0,0,0,0,0,0,0,0,0,222,111,0,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,255,255,63,63, -255,255,255,255,63,63,255,170,255,255,255,63,255,255,255,255,255,255,223,95, -220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,128,0,0,255,31,0,0, -0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255,243,224,67,0,0,255,255,255,255, -255,1,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,255,255,255,127,255,15,255,1,192,255,255,255,255,63,31,0,255,255,255,255, +255,15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255,255,255,255,255,255,255, +127,254,255,31,0,255,3,255,3,128,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, +255,239,255,239,15,255,3,0,0,0,0,255,255,255,255,255,243,255,255,255,255,255, +255,191,255,3,0,255,255,255,255,255,255,63,0,255,227,255,255,255,255,255,63, +255,1,0,0,0,0,0,0,0,0,0,0,0,222,111,0,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,128,255,31,0, +255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,255,255,255,255, +255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,128, +0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255,243,224,67,0,0, +255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,255,255,255,255,255,3,0, 0,255,255,255,255,255,127,255,255,255,255,255,127,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,31,120,12,0,255,255,255,255,191,32,255, 255,255,255,255,255,255,128,0,0,255,255,127,0,127,127,127,127,127,127,127,127, 255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,224,0,0,0,254,3,62,31,254,255,255,255,255,255,255,255,255,255,127,224,254, -255,255,255,255,255,255,255,255,255,255,247,224,255,255,255,255,63,254,255, +255,255,255,255,255,255,255,255,255,255,247,224,255,255,255,255,127,254,255, 255,255,255,255,255,255,255,255,255,127,0,0,255,255,255,7,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,63,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,0,0,0, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0, 0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0, 0,0,0,0,0,0,255,255,255,255,255,63,255,31,255,255,255,15,0,0,255,255,255,255, -255,127,240,143,255,255,255,128,255,255,255,255,255,255,255,255,255,255,0,0,0, -0,128,255,252,255,255,255,255,255,255,255,255,255,255,255,255,121,15,0,255,7, -0,0,0,0,0,0,0,0,0,255,187,247,255,255,255,0,0,0,255,255,255,255,255,255,15,0, -255,255,255,255,255,255,255,255,15,0,255,3,0,0,252,8,255,255,255,255,255,7, -255,255,255,255,7,0,255,255,255,31,255,255,255,255,255,255,247,255,0,128,255, -3,0,0,0,0,255,255,255,255,255,255,127,0,255,63,255,3,255,255,127,4,255,255, -255,255,255,255,255,127,5,0,0,56,255,255,60,0,126,126,126,0,127,127,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,7,255,3,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248, -255,255,255,255,255, +255,127,240,143,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0, +0,128,255,252,255,255,255,255,255,255,255,255,255,255,255,255,249,255,255,255, +127,255,0,0,0,0,0,0,0,128,255,187,247,255,255,255,0,0,0,255,255,255,255,255, +255,15,0,255,255,255,255,255,255,255,255,47,0,255,3,0,0,252,40,255,255,255, +255,255,7,255,255,255,255,7,0,255,255,255,31,255,255,255,255,255,255,247,255, +0,128,255,3,223,255,255,127,255,255,255,255,255,255,127,0,255,63,255,3,255, +255,127,196,255,255,255,255,255,255,255,127,5,0,0,56,255,255,60,0,126,126,126, +0,127,127,255,255,255,255,255,247,63,0,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,7,255,3,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255,255,255, 15,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,255,255, 255,255,255,255,255,255,255,255,3,0,0,0,0,127,0,248,224,255,253,127,95,219, 255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,0,248,255,255,255, @@ -100,31 +101,63 @@ 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0, 255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,255,255,255,1,0,0,0,0, -0,255,255,255,127,0,0,255,255,255,7,0,0,0,0,0,0,255,255,255,63,255,255,255, -255,15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,63,255,3,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255, -191,145,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,63,0,255, -255,255,3,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111, -240,239,254,255,255,15,0,0,0,0,0,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,63,0,0,0,192,255,0,0,252,255, -255,255,255,255,255,1,0,0,255,255,255,1,255, -3,255,255,255,255,255,255,199,255,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255, -255,30,0,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, -255,63,0,255,3,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255, -255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, -255,255,255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, -127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, -255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, -255,255,255,31,0,255,255,255,255,255,127,0,0,248,255,0,0,0,0,0,0,0,0,0,0,0,0, -3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,255,255,255, +0,255,255,255,255,0,224,255,255,255,7,255,255,255,255,255,7,255,255,255,63, +255,255,255,255,15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,63,255,3,255,255,255,255,15,255,255,255, +255,15,255,255,255,255,255,0,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,0,255,255,63,0,255,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255,191,145,255,255,63,0,255,255, +127,0,255,255,255,127,0,0,0,0,0,0,0,0,255,255,55,0,255,255,63,0,255,255,255,3, +0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111,240,239, +254,255,255,15,0,0,0,0,0,255,255,255,31,255,255,255,31,0,0,0,0,255,254,255, +255,31,0,0,0,255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,255,255,3, +0,0,0,0,0,0,0,0,0,0,0,0, +0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,255,255,255,255,255,255,7, +0,255,255,255,255,255,255,7,0,255,255,255,255,255,255,255,255,63,0,0,0,192, +255,0,0,252,255,255,255,255,255,255,1,0,0,255,255,255,1,255,3,255,255,255,255, +255,255,199,255,0,0,255,255,255,255,71,0,255,255,255,255,255,255,255,255,30,0, +255,23,0,0,0,0,255,255,251,255,255,255,159,64,0,0,0,0,0,0,0,0,127,189,255,191, +255,1,255,255,255,255,255,255,255,1,255,3,239,159,249,255,255,253,237,227,159, +25,129,224,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255, +255,255,187,7,255,3,0,0,0,0,255,255,255,255,255,255,255,255,179,0,255,3,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,63,127,0,0,0,63,0,0, +0,0,255,255,255,255,255,255,255,127,17,0,255,3,0,0,0,0,255,255,255,255,255, +255,63,0,255,3,0,0,0,0,0, +0,255,255,255,227,255,7,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,3, +0,128,255,255,255,255,255,255,231,127,0,0,255,255,255,255,255,255,207,255,255, +0,0,0,0,0,255,255,255,255,255,255,255,1,255,253,255,255,255,255,127,127,1,0, +255,3,0,0,252,255,255,255,252,255,255,254,127,0,0,0,0,0,0,0,0,0,127,251,255, +255,255,255,127,180,203,0,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0, +0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,127,0, +0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,255,255,255,255,255,255,255,1,255,255,255,127,255,3,0,0,0,0,0,0,0,0,0,0,0, +0,255,255,255,63,0,0,255,255,255,255,255,255,127,0,15,0,255,3,248,255,255,224, +255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,31,0,255, +255,255,255,255,127,0,0,248,255,0,0,0,0,0,0,0,0,3,0,0,0,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,31,0,0,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0, +255,255,255,127,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,15,255,255,255,255,255, +255,255,255,255,255,255,255,255,7,255,31,255,1,255,67,0,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,255,255,255, 223,100,222,255,235,239,255,255,255,255,255,255,255,191,231,223,223,255,255, 255,123,95,252,253,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,63,255,255,255,253,255,255,247,255,255,255, 247,255,255,223,255,255,255,223,255,255,127,255,255,255,127,255,255,255,253, -255,255,255,253,255,255,247,207,255,255,255,255,255,255,239,255,255,255,150, -254,247,10,132,234,150,170,150,247,247,94,255,251,255,15,238,251,255,15,0,0,0, +255,255,255,253,255,255,247,207,255,255,255,255,255,255,127,255,255,249,219,7, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0, 0,0,0,0,0, +0,255,255,255,255,255,255,255,255,143,0,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,239,255,255,255,150,254,247,10,132,234,150,170,150,247,247,94,255,251, +255,15,238,251,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,3,255,255,255,3, +255,255,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/src/ctype/nonspacing.h b/src/ctype/nonspacing.h index cd9fec97..48231e73 100644 --- a/src/ctype/nonspacing.h +++ b/src/ctype/nonspacing.h @@ -8,58 +8,74 @@ 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,49,16,16,50, -51,16,52,16,16,16,16,16,16,16,16,53,16,16,16,16,16,54,55,16,16,16,16,56,16,16, +51,16,52,53,54,16,16,16,16,16,16,55,16,16,16,16,16,56,57,58,59,60,61,62,63,16, +16,64,16,65,66,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,57,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,67,68,16,16,16,69,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,58,59,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,70,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,71,72,16,16,16,16,16,16,16,73,16,16,16,16,16,74,16,16,16,16,16,16,16,75, +76,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,248,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,254,255,255,255,255,191,182,0,0,0,0,0,0,0,31,0,255,7,0,0,0,0,0,248,255, +0,0,0,254,255,255,255,255,191,182,0,0,0,0,0,0,0,63,0,255,23,0,0,0,0,0,248,255, 255,0,0,1,0,0,0,0,0,0,0,0,0,0,0,192,191,159,61,0,0,0,128,2,0,0,0,255,255,255, 7,0,0,0,0,0,0,0,0,0,0,192,255,1,0,0,0,0,0,0,248,15,0,0,0,192,251,239,62,0,0,0, -0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,255,255, -127,7,0,0,0,0,0,0,20,254,33,254,0,12,0,0,0,2,0,0,0,0,0,0,16,30,32,0,0,12,0,0, -0,6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16,190,33,0,0,12,0,0,0,2, -0,0,0,0,0,0,144,30,32,64,0,12,0,0,0,4,0,0,0,0,0,0,0,1,32,0,0,0,0,0,0,0,0,0,0, -0,0,0,192,193,61,96,0,12,0,0,0,0,0,0,0,0,0,0,144,64,48,0,0,12,0,0,0,0,0,0,0,0, -0,0,0,30,32,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,4,92,0,0,0,0,0,0,0,0,0,0,0,242,7, -128,127,0,0,0,0,0,0,0,0,0,0,0,0,242,27,0,63,0,0,0,0,0,0,0,0,0,3,0,0,160,2,0,0, -0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,0,0,0,0,0,224, -253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,0,0,0,0,0,0,0, +0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,255,255,255,255, +255,7,0,0,0,0,0,0,20,254,33,254,0,12,0,0,0,2,0,0,0,0,0,0,16,30,32,0,0,12,0,0, +0,6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16,190,33,0,0,12,0,0,252, +2,0,0,0,0,0,0,144,30,32,64,0,12,0,0,0,4,0,0,0,0,0,0,0,1,32,0,0,0,0,0,0,1,0,0, +0,0,0,0,192,193,61,96,0,12,0,0,0,2,0,0,0,0,0,0,144,64,48,0,0,12,0,0,0,3,0,0,0, +0,0,0,24,30,32,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,4,92,0,0,0,0,0,0,0,0,0,0,0,242, +7,128,127,0,0,0,0,0,0,0,0,0,0,0,0,242,27,0,63,0,0,0,0,0,0,0,0,0,3,0,0,160,2,0, +0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,0,0,0,0,0, +224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0, -0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,15,32,0,0,0,0,0,56,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,1,0,0,0,0,0,0,64,127,229, -31,248,159,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,208,23,4,0,0,0,0,248, -15,0,3,0,0,0,60,11,0,0,0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,255,255,255,255,127,0,0, -240,0,248,0,0,0,124,0,0,0,0,0,0,31,252,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255, +0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,15,32,0,0,0,0,0,120,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,9,0,0,0,0,0,0,64,127, +229,31,248,159,0,0,0,0,0,0,255,127,0,0,0,0,0,0,0,0,15,0,0,0,0,0,208,23,4,0,0, +0,0,248,15,0,3,0,0,0,60,59,0,0,0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255, +251,0,248,0,0,0,124,0,0,0,0,0,0,223,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255, 255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0, 0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,128,247,63,0,0,0,128,0,0,0,0,0,0,0,0,0,0,3,0,68,8,0,0,96,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,0,255,255,3,0,0,0,0,0,192,63,0,0,128,255,3,0,0, -0,0,0,7,0,0,0,0,0,200,19,0,0,0,0,0,0,0,0,0,0,0,0,0,126,102,0,8,16,0,0,0,0,0,0, -0,0,0,0,0,0,157,193,2,0,0,0,0,48,64, +0,0,0,128,247,63,0,0,0,192,0,0,0,0,0,0,0,0,0,0,3,0,68,8,0,0,96,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,48,0,0,0,255,255,3,0,0,0,0,0,192,63,0,0,128,255,3,0,0, +0,0,0,7,0,0,0,0,0,200,19,0,0,0,0,32,0,0,0,0,0,0,0,0,126,102,0,8,16,0,0,0,0,0, +16,0,0,0,0,0,0,157,193,2,0,0,0,0,48,64, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,127,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,32,110,240,0,0,0,0,0,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,255,127,0,0,0,0,0,0,0,3,0,0,0,0,0,120,38,0,0, -0,0,0,0,0,0,7,0,0,0,128,239,31,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,192,127,0,0,0,0, -0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,128,3,248,255,231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,255,255,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,110,240,0,0,0,0,0,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0, +0,2,0,0,0,0,0,0,255,127,0,0,0,0,0,0,128,3,0,0,0,0,0,120,38,0,0,0,0,0,0,0,0,7, +0,0,0,128,239,31,0,0,0,0,0,0,0,8,0,3,0,0,0,0,0,192,127,0,28,0,0,0,0,0,0,0,0,0, +0,0,128,211,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,248,7,0,0,3,0,0,0,0, +0,0,16,1,0,0,0,192,31,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255, +92,0,0,0,0,0,0,0,0,0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,60,176,1,0,0,48,0,0,0,0,0,0,0,0,0,0,248,167,1,0,0,0,0,0,0, +0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,0,0,0,224,188,15,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0, +0,126,6,0,0,0,0,248,121,128,0,126,14,0,0,0,0,0,252,127,3,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,127,191,0,0,0,0,0,0,0,0,0,0,252,255,255,252,109,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,126,180,191,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,0,127, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +96,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,231,15,0,0, +0,60,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, +255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,254,255,0,0,0, +0,0,0,0,0,0,0,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0, +0,0,0,0,0,0,0,240,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/src/ctype/punct.h b/src/ctype/punct.h index a2c52562..7a623940 100644 --- a/src/ctype/punct.h +++ b/src/ctype/punct.h @@ -1,23 +1,24 @@ 18,16,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,16,16,34,35,16,36,37,38,39, -40,41,42,43,16,44,45,46,17,47,48,17,17,49,17,17,17,50,51,52,53,54,55,56,57,17, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,58, +40,41,42,43,16,44,45,46,17,17,47,17,17,17,17,17,17,48,49,50,51,52,53,54,55,17, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,56, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,59,16,60,61,62,63,64,65,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,57,16,58,59,60,61,62,63,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,66,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,67,16,16,68,16,69,70, -71,16,72,16,73,16,16,16,16,74,75,76,77,16,16,78,16,79,80,16,16,16,16,81,16,16, -16,16,16,16,16,16,16,16,16,16,16,82,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,64,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,65,16,16,66,16,67,68, +69,16,70,71,72,16,73,16,16,74,75,76,77,78,16,79,16,80,81,82,83,84,85,86,87,88, +16,89,16,90,91,16,16,16,16,16,16,92,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,83,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,93,94,16,16,16,95,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,84,85,86,87,16,16,88,89,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,90,16,91,92,93,94,95,96,97,98,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,96,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,97,98,99,100,16,16,101,102,17,17,103,16,16,16,16,16,16,16,16,16,16,16,16, +16,104,105,16,16,16,16,106,16,107,108,109,17,17,17,110,111,112,113,16,16,16, +16,16, 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,254,255,0,252,1,0,0,248,1, @@ -25,16 +26,16 @@ 0,0,0,0,0,0,0,0,0,0,0,60,0,252,255,224,175,255,255,255,255,255,255,255,255, 255,255,223,255,255,255,255,255,32,64,176,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,252,0,0,0,0,0,134,254,255,255,255,0,64,73,0,0,0,0,0,24,0,223,255,0,200, +0,0,0,252,0,0,0,0,0,230,254,255,255,255,0,64,73,0,0,0,0,0,24,0,255,255,0,216, 0,0,0,0,0,0,0,1,0,60,0,0,0,0,0,0,0,0,0,0,0,0,16,224,1,30,0, 96,255,191,0,0,0,0,0,0,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,207,3, -0,0,0,3,0,32,255,127,0,0,0,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0,0,0, -0,0,0,0,16,0,32,30,0,48,0,1,0,0,0,0,0,0,0,0,16,0,32,0,0,0,0,252,15,0,0,0,0,0, -0,0,16,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,32,0,0,0,0,3,0,0,0,0,0,0,0,0,16,0, -32,0,0,0,0,253,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,255,7,0,0,0,0,0,0,0,0,0,32,0,0, -0,0,0,255,0,0,0,0,0,0,0,16,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,63,2, -0,0,0,0,0,0,0,0,0,4,0,0,0,0,16,0,0,0,0,0,0,128,0,128,192,223,0,12,0,0,0,0,0,0, -0,0,0,0,0,0,0,31,0,0,0,0,0, +0,0,0,3,0,32,255,127,0,0,0,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,252,0,0,0,0,0, +0,0,0,0,16,0,32,30,0,48,0,1,0,0,0,0,0,0,0,0,16,0,32,0,0,0,0,252,47,0,0,0,0,0, +0,0,16,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,32,0,0,0,0,3,224,0,0,0,0,0,0,0,16, +0,32,0,0,0,0,253,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,255,7,0,0,0,0,0,0,0,0,0,32,0, +0,0,0,0,255,0,0,0,0,0,0,0,16,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,160,0,127,0, +0,255,3,0,0,0,0,0,0,0,0,0,4,0,0,0,0,16,0,0,0,0,0,0,128,0,128,192,223,0,12,0,0, +0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0, 0,254,255,255,255,0,252,255,255,0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,192,255,223, 255,7,0,0,0,0,0,0,0,0,0,0,128,6,0,252,0,0,24,62,0,0,128,191,0,204,0,0,0,0,0,0, 0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,96,255,255,255,31,0,0,255,3,0,0,0,0,0,0,0,0, @@ -43,71 +44,86 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,0,0,254,127,47,0,0,255,3,255,127,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,49,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,196,255,255,255, -255,0,0,0,192,0,0,0,0,0,0,0,0,1,0,224,159,0,0,0,0,127,63,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,16,0,16,0,0,252,255,255,255,31,0,0,0,0,0,12,0,0,0,0,0,0,64,0,12, -240,0,0,0,0,0,0,192,248,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0,255,0,255,255,255, -33,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,127,0, -0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,3,224,0,224,0,224,0, -96,128,248,255,255,255,252,255,255,255,255,255,127,31,252,241,127,255,127,0,0, -255,255,255,3,0,0,255,255,255,255,1,0,123,3,208,193,175,66,0,12,31,188,255, -255,0,0,0,0,0,2,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,0,0,0,192,0,0,0,0,0,0,0,0,1,0,224,159,0,0,0,0,127,63,255,127,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,16,0,16,0,0,252,255,255,255,31,0,0,0,0,0,12,0,0,0,0,0,0,64,0, +12,240,0,0,0,0,0,0,192,248,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0,255,0,255,255, +255,33,144,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +127,0,224,251,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,3,224,0,224,0, +224,0,96,128,248,255,255,255,252,255,255,255,255,255,127,223,255,241,127,255, +127,0,0,255,255,255,255,0,0,255,255,255,255,1,0,123,3,208,193,175,66,0,12,31, +188,255,255,0,0,0,0,0,14,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,127,0,0,0,255,7,0,0,255,255,255,255,255,255,255,255,255, +255,63,0,0,0,0,0,0,252,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,207,255,255,255, +63,255,255,255,255,227,255,253,7,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,224,135,3,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,128,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,127,255,255,255,3,0,0,0,0,0,0, +255,255,255,251,255,255,255,255,255,255,255,255,255,255,15,0,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,15, -0,255,255,255,255,127,0,0,0,255,7,0,0,255,255,255,255,255,255,255,255,255,255, -63,0,0,0,0,0,0,252,255,255,254,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,63,0,0,0,255,15,30,255,255,255,1,252,193,224,0,0,0,0,0,0,0,0,0,0, +0,30,1,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0, +0,0,255,255,255,255,15,0,0,0,255,255,255,127,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,31,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,135,3, -254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, -255,255,255,127,255,15,0,0,0,0,0,0,0,0,255,255,255,251,255,255,255,255,255, -255,255,255,255,255,15,0,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,255,15,30,255, -255,255,1,252,193,224,0,0,0,0,0,0,0,0,0,0,0,30,1,0,0,0,0,0,0,0,0,0,0, -8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0,0,255,255,255,255,15,0,0, -0,255,255,255,127,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,255,255,255,255,255,255,127,0,0,0,0,0,0,192,0,224,0,0,0,0,0,0,0,0, -0,0,0,128,15,112,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,255,255,127,0,3,0,0,0,0,0, -0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68,8,0,0,0,15,255,3,0,0,0,0,0,0, -240,0,0,0,0,0,0,0,0,0,16,192,0,0,255,255,3,7,0,0,0,0,0,248,0,0,0,0,8,128,0,0, -0,0,0,0,0,0,0,0,8,0,255,63,0,192,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,128,11,0,0,0,0,0,0,0,128,2,0,0,192,0,0,67,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,0,0,1,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,252,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,48,255,255,255,3,127,0,255,255,255,255,247,255,127,15,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,128,254,255,0,252,1,0,0,248,1,0,0,248,63,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,127,127,0, -48,135,255,255,255,255,255,143,255,0,0,0,0,0,0,224,255,255,7,255,15,0,0,0,0,0, -0,255,255,255,255,255,63,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0, -0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,192,143,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,135,255,0,255,1,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,254,0,0,0,255,0,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,63, -252,255,63,0,0,0,3,0,0,0,0,0,0,254,3,0,0,0,0,0,0, -0,0,0,0,0,0,0,24,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,225,1,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255, +127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255, +255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,0,0,0, +0,0,0,192,0,224,0,0,0,0,0,0,0,0,0,0,0,128,15,112,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +255,0,255,255,127,0,3,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +68,8,0,0,0,15,255,3,0,0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,16,192,0,0,255,255,3,23, +0,0,0,0,0,248,0,0,0,0,8,128,0,0,0,0,0,0,0,0,0,0,8,0,255,63,0,192,32,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,240,0,0,128,59,0,0,0,0,0,0,0,128,2,0,0,192,0,0,67,0,0,0,0,0, +0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,0, +0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,2,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,252,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,255,255,255,3,255,255,255,255,255,255,247, +255,127,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,254,255,0,252,1,0,0,248,1,0, +0,248,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,127,0,48,135,255,255,255,255,255, +143,255,0,0,0,0,0,0,224,255,255,127,255,15,1,0,0,0,0,0,255,255,255,255,255,63, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255, +15,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +128,255,0,0,128,255,0,0,0,0,128,255,0,0,0,0,0,0,0,0,0,248,0,0,192,143,0,0,0, +128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,255,255,252,255,255,255,255,255,0,0,0,0, +0,0,0,135,255,0,255,1,0,0,0,224,0,0,0,224,0,0,0,0,0,1,0,0,96,248,127,0,0,0,0, +0,0,0,0,254,0,0,0,255,0,0,0,255,0,0,0,30,0,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,0,0,0,0,0, +0,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,192,63,252,255,63,0,0,128,3,0,0,0,0,0,0,254,3,0,0,0,0,0,0,0, +0,0,0,0,0,0,24,0,15,0,0,0,0,0,56,0,0,0,0,0,0,0,0,0,225,63,0,232,254,255,31,0, +0,0,0,0,0,0,96,63,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0, +0,16,0,32,0,0,192,31,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68, +248,0,40,0,0,0,0,0,0,0,0,0,0,0,0,76,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,128,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,128,14,0,0,0,255,31, +0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,252,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,7,0,0,0,0,0,0, +0,24,128,255,0,0,0,0,0,0,0,0,0,0,223,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +128,62,0,0,252,255,31,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,52, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,63,0,0,0,0,0,0,0,128,255,48,0,0,248,3,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,7,0,0,0,0,0,0,0,0,0,0,0, +0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,176,15,0,0,0,0,0,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -63,0,255,255,255,255,127,254,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,63,0,0,0,0,255,255,255,255,255,255,255, -255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255, -255,255,255,255,127,0,255,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,8,0,0,0,8,0,0,32,0,0, -0,32,0,0,128,0,0,0,128,0,0,0,2,0,0,0,2,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,255,255,255,255,255,15,255,255, -255,255,255,255,255,255,255,255,255,255,15,0,255,127,254,127,254,255,254,255, -0,0,0,0,255,7,255,255,255,127,255,255,255,255,255,255,255,15,255,255,255,255, -255,7,0,0,0,0,0,0,0,0,192,255,255,255,7,0,255,255,255,255,255,7,255,1,3,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,1,0,191,255,255,255,255, -255,255,255,255,31,255,255,15,0,255,255,255,255,223,7,0,0,255,255,1,0,255,255, -255,255,255,255,255,127,253,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255, -30,255,255,255,255,255,255,255,63,15,0,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,248,255,255,255,255,255,255,255,255,225,255,0,0,0,0,0,0,255,255,255, -255,255,255,255,255,63,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,255,63,0,255,255,255,255,127,254,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,1,0,0,255,255,255,255,255,255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,127,0,255,255,3,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0, +0,8,0,0,0,8,0,0,32,0,0,0,32,0,0,128,0,0,0,128,0,0,0,2,0,0,0,2,0,0,8,0,0,0,0,0, +0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,0, +248,254,255,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,127,0,0,0,0,0,0,0,0, +0,0,0,0,0,112,7,0,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,255,255,255,255,255,15,255, +255,255,255,255,255,255,255,255,255,255,255,15,0,255,127,254,255,254,255,254, +255,255,255,63,0,255,31,255,255,255,127,0,0,0,252,0,0,0,12,0,0,0,252,255,255, +255,31,0,0,0,0,0,0,192,255,255,255,7,0,255,255,255,255,255,15,255,1,3,0,63,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,255,31, +255,1,255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255,255, +255,255,255,255,255,255,255,255,31,0,0,0,0, +0,255,15,255,255,255,255,255,255,255,0,255,3,255,255,255,255,255,0,255,255, +255,63,0,0,0,0,0,0,0,0,0,0,255,15,255,255,255,255,255,127,255,31,255,255,255, +15,0,0,255,255,255,0,0,0,0,0,1,0,255,255,127,0,0,0, diff --git a/src/ctype/wide.h b/src/ctype/wide.h index ff08de18..e4672b23 100644 --- a/src/ctype/wide.h +++ b/src/ctype/wide.h @@ -1,43 +1,63 @@ 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,18,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,19,16,16,16,16,16,16,16,16,16,16,20,21,22,23,24,17, -17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,25, +16,16,16,16,16,16,16,16,16,19,16,20,21,22,16,16,16,23,16,16,24,25,26,27,28,17, +17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,29, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,17,26,16,16,16,16,27,16,16,17,17,17,17,17,17,17,17,17,17, +17,17,17,17,17,17,17,17,30,16,16,16,16,31,16,16,17,17,17,17,17,17,17,17,17,17, 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, -17,17,17,17,17,17,17,28,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,16,16,16,29, -30,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +17,17,17,17,17,17,17,32,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,16,16,16,33, +34,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,35,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, +17,17,17,17,17,17,36,17,17,37,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,38,39,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,31,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, -16,16,16,16,16,16,16,16,16,32,16,16,16,16,16,16,16,16,16,16,16,16, +16,16,16,16,16,16,16,40,41,42,43,44,45,46,16,16,47,16,16,16,16,16, 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,255,0,0,0,0,0,0,0,0,248,0,0,0,0,0,0,0,0,0,0,252,0,0,0,0,0,6,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -255,255,255,251,255,255,255,255,255,255,255,255,255,255,15,0,255,255,255,255, +255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,6,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,30,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,48,0,0,0,0,0,0,255,15,0,0,0,0,128,0,0,8, +0,2,12,0,96,48,64,16,0,0,4,44,36,32,12,0,0,0,1,0,0,0,80,184,0,0,0,0,0,0,0,224, +0,0,0,1,128,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,33,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,251,255,255,255,255,255,255,255, +255,255,255,15,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,255,15,255,255,255,255, +255,255,255,127,254,255,255,255,255,255,255,255,255,255,127,254,255,255,255, +255,255,255,255,255,255,255,255,255,224,255,255,255,255,127,254,255,255,255, +255,255,255,255,255,255,255,127,255,255,255,255,255,7,255,255,255,255,15,0, +255,255,255,255,255,127,255,255,255,255,255,0,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,127,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0, +0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,31,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255, +255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,255,3,0,0,255,255,255,255,247,255,127,15,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,255,255,255,255,255,255,255,255, +255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0, +0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,7,0,255,255,255,127,0,0,0,0,0,0,0, +0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -255,255,255,63,0,0,0,255,15,255,255,255,255,255,255,255,127,254,255,255,255, -255,255,255,255,255,255,127,254,255,255,255,255,255,255,255,255,255,255,255, -255,224,255,255,255,255,63,254,255,255,255,255,255,255,255,255,255,255,127, -255,255,255,255,255,7,255,255,255,255,15,0,255, -255,255,255,255,127,255,255,255,255,255,0,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,127,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0, -0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, -31,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, -255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255, -255,255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255, -255,255,15,0,0,255,3,0,0,255,255,255,255,247,255,127,15,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,254,255,255,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,127,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0, -0,7,0,255,255,255,255,255,7,255,1,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +255,255,255,255,255,255,255,255,255,255,255,255, +15,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,64,254,7,0,0,0,0,0,0,0,0,0,0,0,0,7,0,255,255,255, +255,255,15,255,1,3,0,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, +1,224,191,255,255,255,255,255,255,255,255,223,255,255,15,0,255,255,255,255, +255,135,15,0,255,255,17,255,255,255,255,255,255,255,255,127,253,255,255,255, +255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, +159,255,255,255,255,255,255,255,63,0,120,255,255,255,0,0,4,0,0,96,0,16,0,0,0, +0,0,0,0,0,0,0,248,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,255,255, +255,255,255,255,255,255,63,16,7,0,0,24,240,1,0,0,255,255,255,255,255,127,255, +31,255,255,255,15,0,0,255,255,255,0,0,0,0,0,1,0,255,255,127,0,0, +0, From 54941eddfd9cf2b40e489258e2fbf4bd1c90311e Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 18 Dec 2017 19:33:56 -0500 Subject: [PATCH 016/161] update case mappings to unicode 10.0 the mapping tables and code are not automatically generated; they were produced by comparing the output of towupper/towlower against the mappings in the UCD, ignoring characters that were previously excluded from case mappings or from alphabetic status (micro sign and circled letters), and adding table entries or code for everything else missing. based very loosely on a patch by Reini Urban. --- src/ctype/towctrans.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/src/ctype/towctrans.c b/src/ctype/towctrans.c index cf13a862..12355af1 100644 --- a/src/ctype/towctrans.c +++ b/src/ctype/towctrans.c @@ -29,7 +29,7 @@ static const struct { CASELACE(0x4c1,0x4cd), CASELACE(0x4d0,0x50e), - CASELACE(0x514,0x526), + CASELACE(0x514,0x52e), CASEMAP(0x531,0x556,0x561), CASELACE(0x01a0,0x01a4), @@ -63,6 +63,10 @@ static const struct { CASEMAP(0x1ff8,0x1ff9,0x1f78), CASEMAP(0x1ffa,0x1ffb,0x1f7c), + CASEMAP(0x13f0,0x13f5,0x13f8), + CASELACE(0xa698,0xa69a), + CASELACE(0xa796,0xa79e), + CASELACE(0x246,0x24e), CASELACE(0x510,0x512), CASEMAP(0x2160,0x216f,0x2170), @@ -82,6 +86,8 @@ static const struct { CASELACE(0xa790,0xa792), CASELACE(0xa7a0,0xa7a8), + CASELACE(0xa7b4,0xa7b6), + CASEMAP(0xff21,0xff3a,0xff41), { 0,0,0 } }; @@ -216,6 +222,26 @@ static const unsigned short pairs[][2] = { { 0x395, 0x3f5 }, { 0x3cf, 0x3d7 }, + { 0xa7ab, 0x25c }, + { 0xa7ac, 0x261 }, + { 0xa7ad, 0x26c }, + { 0xa7ae, 0x26a }, + { 0xa7b0, 0x29e }, + { 0xa7b1, 0x287 }, + { 0xa7b2, 0x29d }, + { 0xa7b3, 0xab53 }, + + /* special cyrillic lowercase forms */ + { 0x412, 0x1c80 }, + { 0x414, 0x1c81 }, + { 0x41e, 0x1c82 }, + { 0x421, 0x1c83 }, + { 0x422, 0x1c84 }, + { 0x422, 0x1c85 }, + { 0x42a, 0x1c86 }, + { 0x462, 0x1c87 }, + { 0xa64a, 0x1c88 }, + { 0,0 } }; @@ -229,7 +255,8 @@ static wchar_t __towcase(wchar_t wc, int lower) if (!iswalpha(wc) || (unsigned)wc - 0x0600 <= 0x0fff-0x0600 || (unsigned)wc - 0x2e00 <= 0xa63f-0x2e00 - || (unsigned)wc - 0xa800 <= 0xfeff-0xa800) + || (unsigned)wc - 0xa800 <= 0xab52-0xa800 + || (unsigned)wc - 0xabc0 <= 0xfeff-0xabc0) return wc; /* special case because the diff between upper/lower is too big */ if (lower && (unsigned)wc - 0x10a0 < 0x2e) @@ -238,6 +265,10 @@ static wchar_t __towcase(wchar_t wc, int lower) if (!lower && (unsigned)wc - 0x2d00 < 0x26) if (wc>0x2d25 && wc != 0x2d27 && wc != 0x2d2d) return wc; else return wc + 0x10a0 - 0x2d00; + if (lower && (unsigned)wc - 0x13a0 < 0x50) + return wc + 0xab70 - 0x13a0; + if (!lower && (unsigned)wc - 0xab70 < 0x50) + return wc + 0x13a0 - 0xab70; for (i=0; casemaps[i].len; i++) { int base = casemaps[i].upper + (lmask & casemaps[i].lower); if ((unsigned)wc-base < casemaps[i].len) { @@ -252,6 +283,14 @@ static wchar_t __towcase(wchar_t wc, int lower) } if ((unsigned)wc - (0x10428 - 0x28*lower) < 0x28) return wc - 0x28 + 0x50*lower; + if ((unsigned)wc - (0x104d8 - 0x28*lower) < 0x24) + return wc - 0x28 + 0x50*lower; + if ((unsigned)wc - (0x10cc0 - 0x40*lower) < 0x33) + return wc - 0x40 + 0x80*lower; + if ((unsigned)wc - (0x118c0 - 0x20*lower) < 0x20) + return wc - 0x20 + 0x40*lower; + if ((unsigned)wc - (0x1e922 - 0x22*lower) < 0x22) + return wc - 0x22 + 0x44*lower; return wc; } From 9d4d0ee41b06acf68dac40332f53be7bfbde7404 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 18 Dec 2017 19:58:41 -0500 Subject: [PATCH 017/161] add cp866 (dos cyrillic) to iconv --- src/locale/codepages.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/locale/codepages.h b/src/locale/codepages.h index 724a846f..4e236ef3 100644 --- a/src/locale/codepages.h +++ b/src/locale/codepages.h @@ -286,6 +286,18 @@ "\323\174\103\215\64\365\124\123\213\77\336\150\263\115\66\375\164\363\12\55" "\255\304\42\261\57\266\234\162\17\56\260\240\162\113\56\263\310\62\66\50" +"cp866\0" +"\0\40" +"\337\201\27\236\170\343\221\127\236\171\347\241\227\236\172" +"\353\261\327\236\173\357\301\27\237\174\363\321\127\237\175" +"\367\341\227\237\176\373\361\327\237\177\377\1\30\240\200\3\22\130\240\201" +"\7\42\230\240\202\13\62\330\240\203\140\207\55\66\315\72\77\15\65\321" +"\103\107\375\163\321\113\53\235\264\315\67\363\274\163\316\63\367\314\164\323" +"\110\13\175\65\325\116\373\254\165\325\126\113\75\365\321\106\3\35\164\326" +"\130\343\134\163\327\134\173\375\365\326\17\102\30\241\204\23\122\130\241\205" +"\27\142\230\241\206\33\162\330\241\207\321\175\110\235\210\327\225\330\335\212" +"\260\240\174\113\312\46\223\62\66\50" + "ibm1047\0" "cp1047\0" "\0\1" From 95c6044e2ae85846330814c4ac5ebf4102dbe02c Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 18 Dec 2017 22:08:54 -0500 Subject: [PATCH 018/161] add support for BOM-determined-endian UCS2, UTF-16, and UTF-32 to iconv previously, the charset names without endianness specified were always interpreted as big endian. unicode specifies that UTF-16 and UTF-32 have BOM-determined endianness if BOM is present, and are otherwise big endian. since commit 5b546faa67544af395d6407553762b37e9711157 added support for stateful encodings, it is now possible to implement BOM support via the conversion descriptor state. for conversions to these charsets, the output is always big endian and does not have a BOM. --- src/locale/iconv.c | 43 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/src/locale/iconv.c b/src/locale/iconv.c index 1784dc9d..c5dd122f 100644 --- a/src/locale/iconv.c +++ b/src/locale/iconv.c @@ -16,6 +16,9 @@ #define WCHAR_T 0306 #define US_ASCII 0307 #define UTF_8 0310 +#define UTF_16 0312 +#define UTF_32 0313 +#define UCS2 0314 #define EUC_JP 0320 #define SHIFT_JIS 0321 #define ISO2022_JP 0322 @@ -35,13 +38,16 @@ static const unsigned char charmaps[] = "utf8\0char\0\0\310" "wchart\0\0\306" -"ucs2\0ucs2be\0\0\304" +"ucs2be\0\0\304" "ucs2le\0\0\305" -"utf16\0utf16be\0\0\302" +"utf16be\0\0\302" "utf16le\0\0\301" -"ucs4\0ucs4be\0utf32\0utf32be\0\0\300" +"ucs4be\0utf32be\0\0\300" "ucs4le\0utf32le\0\0\303" "ascii\0usascii\0iso646\0iso646us\0\0\307" +"utf16\0\0\312" +"ucs4\0utf32\0\0\313" +"ucs2\0\0\314" "eucjp\0\0\320" "shiftjis\0sjis\0\0\321" "iso2022jp\0\0\322" @@ -145,6 +151,9 @@ iconv_t iconv_open(const char *to, const char *from) iconv_t cd = combine_to_from(t, f); switch (charmaps[f]) { + case UTF_16: + case UTF_32: + case UCS2: case ISO2022_JP: scd = malloc(sizeof *scd); if (!scd) return (iconv_t)-1; @@ -285,6 +294,31 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri c = ((c-0xd7c0)<<10) + (d-0xdc00); } break; + case UCS2: + case UTF_16: + l = 0; + if (!scd->state) { + if (*inb < 2) goto starved; + c = get_16((void *)*in, 0); + scd->state = type==UCS2 + ? c==0xfffe ? UCS2LE : UCS2BE + : c==0xfffe ? UTF_16LE : UTF_16BE; + if (c == 0xfffe || c == 0xfeff) + l = 2; + } + type = scd->state; + continue; + case UTF_32: + l = 0; + if (!scd->state) { + if (*inb < 4) goto starved; + c = get_32((void *)*in, 0); + scd->state = c==0xfffe0000 ? UTF_32LE : UTF_32BE; + if (c == 0xfffe0000 || c == 0xfeff) + l = 4; + } + type = scd->state; + continue; case SHIFT_JIS: if (c < 128) break; if (c-0xa1 <= 0xdf-0xa1) { @@ -589,8 +623,11 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri *(*out)++ = 'B'; *outb -= 8; break; + case UCS2: + totype = UCS2BE; case UCS2BE: case UCS2LE: + case UTF_16: case UTF_16BE: case UTF_16LE: if (c < 0x10000 || type-UCS2BE < 2U) { From 628cf979b249fa76a80962e2eefe05073216a4db Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 18 Dec 2017 22:33:51 -0500 Subject: [PATCH 019/161] fix iconv output of surrogate pairs in ucs2 in the unified code for handling utf-16 and ucs2 output, the check for ucs2 wrongly looked at the source charset rather than the destination charset. --- src/locale/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/locale/iconv.c b/src/locale/iconv.c index c5dd122f..d469856c 100644 --- a/src/locale/iconv.c +++ b/src/locale/iconv.c @@ -630,7 +630,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri case UTF_16: case UTF_16BE: case UTF_16LE: - if (c < 0x10000 || type-UCS2BE < 2U) { + if (c < 0x10000 || totype-UCS2BE < 2U) { if (c >= 0x10000) c = 0xFFFD; if (*outb < 2) goto toobig; put_16((void *)*out, c, totype); From b583c5d3b4cc2c54c68eef5eb7855ecfacee8bfc Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Sat, 6 Jan 2018 23:32:52 +0100 Subject: [PATCH 020/161] add additional uapi guards for Linux kernel header files With Linux kernel 4.16 it will be possible to guard more parts of the Linux header files from a libc. Make use of this in musl to guard all the structures and other definitions from the Linux header files which are also defined by the header files provided by musl. This will make it possible to compile source files which include both the libc headers and the kernel userspace headers. This extends the definitions done in commit 04983f227238 ("make netinet/in.h suppress clashing definitions from kernel headers") --- include/net/if.h | 7 +++++++ include/netinet/if_ether.h | 1 + include/sys/xattr.h | 2 ++ 3 files changed, 10 insertions(+) diff --git a/include/net/if.h b/include/net/if.h index 2f2fcc10..774cbff0 100644 --- a/include/net/if.h +++ b/include/net/if.h @@ -125,6 +125,13 @@ struct ifconf { #define ifc_req ifc_ifcu.ifcu_req #define _IOT_ifconf _IOT(_IOTS(struct ifconf),1,0,0,0,0) +#define __UAPI_DEF_IF_IFCONF 0 +#define __UAPI_DEF_IF_IFMAP 0 +#define __UAPI_DEF_IF_IFNAMSIZ 0 +#define __UAPI_DEF_IF_IFREQ 0 +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0 +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 0 + #endif #ifdef __cplusplus diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h index d9a131aa..97134d75 100644 --- a/include/netinet/if_ether.h +++ b/include/netinet/if_ether.h @@ -133,5 +133,6 @@ do { \ (enaddr)[5] = ((uint8_t *)ipaddr)[3]; \ } while(0) +#define __UAPI_DEF_ETHHDR 0 #endif diff --git a/include/sys/xattr.h b/include/sys/xattr.h index 6479fcc6..eeeaafc4 100644 --- a/include/sys/xattr.h +++ b/include/sys/xattr.h @@ -24,6 +24,8 @@ int removexattr(const char *, const char *); int lremovexattr(const char *, const char *); int fremovexattr(int, const char *); +#define __UAPI_DEF_XATTR 0 + #ifdef __cplusplus } #endif From 47d0bcd4762f223364e5b58d5a381aaa0cbd7c38 Mon Sep 17 00:00:00 2001 From: Jens Gustedt Date: Wed, 3 Jan 2018 14:17:12 +0100 Subject: [PATCH 021/161] new lock algorithm with state and congestion count in one atomic int A variant of this new lock algorithm has been presented at SAC'16, see https://hal.inria.fr/hal-01304108. A full version of that paper is available at https://hal.inria.fr/hal-01236734. The main motivation of this is to improve on the safety of the basic lock implementation in musl. This is achieved by squeezing a lock flag and a congestion count (= threads inside the critical section) into a single int. Thereby an unlock operation does exactly one memory transfer (a_fetch_add) and never touches the value again, but still detects if a waiter has to be woken up. This is a fix of a use-after-free bug in pthread_detach that had temporarily been patched. Therefore this patch also reverts c1e27367a9b26b9baac0f37a12349fc36567c8b6 This is also the only place where internal knowledge of the lock algorithm is used. The main price for the improved safety is a little bit larger code. Under high congestion, the scheduling behavior will be different compared to the previous algorithm. In that case, a successful put-to-sleep may appear out of order compared to the arrival in the critical section. --- src/internal/pthread_impl.h | 6 ++++ src/thread/__lock.c | 55 +++++++++++++++++++++++++++++++++---- src/thread/pthread_detach.c | 5 ++-- 3 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index 56e19348..602d6f56 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -136,6 +136,12 @@ static inline void __wake(volatile void *addr, int cnt, int priv) __syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS || __syscall(SYS_futex, addr, FUTEX_WAKE, cnt); } +static inline void __futexwait(volatile void *addr, int val, int priv) +{ + if (priv) priv = FUTEX_PRIVATE; + __syscall(SYS_futex, addr, FUTEX_WAIT|priv, val) != -ENOSYS || + __syscall(SYS_futex, addr, FUTEX_WAIT, val); +} void __acquire_ptc(void); void __release_ptc(void); diff --git a/src/thread/__lock.c b/src/thread/__lock.c index 0874c04a..45557c88 100644 --- a/src/thread/__lock.c +++ b/src/thread/__lock.c @@ -1,15 +1,60 @@ #include "pthread_impl.h" +/* This lock primitive combines a flag (in the sign bit) and a + * congestion count (= threads inside the critical section, CS) in a + * single int that is accessed through atomic operations. The states + * of the int for value x are: + * + * x == 0: unlocked and no thread inside the critical section + * + * x < 0: locked with a congestion of x-INT_MIN, including the thread + * that holds the lock + * + * x > 0: unlocked with a congestion of x + * + * or in an equivalent formulation x is the congestion count or'ed + * with INT_MIN as a lock flag. + */ + void __lock(volatile int *l) { - if (libc.threads_minus_1) - while (a_swap(l, 1)) __wait(l, l+1, 1, 1); + if (!libc.threads_minus_1) return; + /* fast path: INT_MIN for the lock, +1 for the congestion */ + int current = a_cas(l, 0, INT_MIN + 1); + if (!current) return; + /* A first spin loop, for medium congestion. */ + for (unsigned i = 0; i < 10; ++i) { + if (current < 0) current -= INT_MIN + 1; + // assertion: current >= 0 + int val = a_cas(l, current, INT_MIN + (current + 1)); + if (val == current) return; + current = val; + } + // Spinning failed, so mark ourselves as being inside the CS. + current = a_fetch_add(l, 1) + 1; + /* The main lock acquisition loop for heavy congestion. The only + * change to the value performed inside that loop is a successful + * lock via the CAS that acquires the lock. */ + for (;;) { + /* We can only go into wait, if we know that somebody holds the + * lock and will eventually wake us up, again. */ + if (current < 0) { + __futexwait(l, current, 1); + current -= INT_MIN + 1; + } + /* assertion: current > 0, the count includes us already. */ + int val = a_cas(l, current, INT_MIN + current); + if (val == current) return; + current = val; + } } void __unlock(volatile int *l) { - if (l[0]) { - a_store(l, 0); - if (l[1]) __wake(l, 1, 1); + /* Check l[0] to see if we are multi-threaded. */ + if (l[0] < 0) { + if (a_fetch_add(l, -(INT_MIN + 1)) != (INT_MIN + 1)) { + __wake(l, 1, 1); + } } } diff --git a/src/thread/pthread_detach.c b/src/thread/pthread_detach.c index 13482607..d9c90d1c 100644 --- a/src/thread/pthread_detach.c +++ b/src/thread/pthread_detach.c @@ -6,11 +6,10 @@ int __pthread_join(pthread_t, void **); static int __pthread_detach(pthread_t t) { /* Cannot detach a thread that's already exiting */ - if (a_swap(t->exitlock, 1)) + if (a_cas(t->exitlock, 0, INT_MIN + 1)) return __pthread_join(t, 0); t->detached = 2; - a_store(t->exitlock, 0); - __wake(t->exitlock, 1, 1); + __unlock(t->exitlock); return 0; } From c4bc0b1a64e1ef1e105df84401805a16e8dbe82a Mon Sep 17 00:00:00 2001 From: Jens Gustedt Date: Wed, 3 Jan 2018 14:17:12 +0100 Subject: [PATCH 022/161] consistently use the LOCK an UNLOCK macros In some places there has been a direct usage of the functions. Use the macros consistently everywhere, such that it might be easier later on to capture the fast path directly inside the macro and only have the call overhead on the slow path. --- src/thread/pthread_create.c | 6 +++--- src/thread/pthread_detach.c | 2 +- src/thread/pthread_getschedparam.c | 4 ++-- src/thread/pthread_kill.c | 4 ++-- src/thread/pthread_setschedparam.c | 4 ++-- src/thread/pthread_setschedprio.c | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 6cbf85b3..34cd9936 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -37,10 +37,10 @@ _Noreturn void __pthread_exit(void *result) __pthread_tsd_run_dtors(); - __lock(self->exitlock); + LOCK(self->exitlock); /* Mark this thread dead before decrementing count */ - __lock(self->killlock); + LOCK(self->killlock); self->dead = 1; /* Block all signals before decrementing the live thread count. @@ -54,7 +54,7 @@ _Noreturn void __pthread_exit(void *result) * been blocked. This precludes observation of the thread id * as a live thread (with application code running in it) after * the thread was reported dead by ESRCH being returned. */ - __unlock(self->killlock); + UNLOCK(self->killlock); /* It's impossible to determine whether this is "the last thread" * until performing the atomic decrement, since multiple threads diff --git a/src/thread/pthread_detach.c b/src/thread/pthread_detach.c index d9c90d1c..692bbaf9 100644 --- a/src/thread/pthread_detach.c +++ b/src/thread/pthread_detach.c @@ -9,7 +9,7 @@ static int __pthread_detach(pthread_t t) if (a_cas(t->exitlock, 0, INT_MIN + 1)) return __pthread_join(t, 0); t->detached = 2; - __unlock(t->exitlock); + UNLOCK(t->exitlock); return 0; } diff --git a/src/thread/pthread_getschedparam.c b/src/thread/pthread_getschedparam.c index 3053c186..a994b637 100644 --- a/src/thread/pthread_getschedparam.c +++ b/src/thread/pthread_getschedparam.c @@ -3,7 +3,7 @@ int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param *restrict param) { int r; - __lock(t->killlock); + LOCK(t->killlock); if (t->dead) { r = ESRCH; } else { @@ -12,6 +12,6 @@ int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param *policy = __syscall(SYS_sched_getscheduler, t->tid); } } - __unlock(t->killlock); + UNLOCK(t->killlock); return r; } diff --git a/src/thread/pthread_kill.c b/src/thread/pthread_kill.c index acdb1ea6..f0903420 100644 --- a/src/thread/pthread_kill.c +++ b/src/thread/pthread_kill.c @@ -3,8 +3,8 @@ int pthread_kill(pthread_t t, int sig) { int r; - __lock(t->killlock); + LOCK(t->killlock); r = t->dead ? ESRCH : -__syscall(SYS_tkill, t->tid, sig); - __unlock(t->killlock); + UNLOCK(t->killlock); return r; } diff --git a/src/thread/pthread_setschedparam.c b/src/thread/pthread_setschedparam.c index c4738d64..9e2fa456 100644 --- a/src/thread/pthread_setschedparam.c +++ b/src/thread/pthread_setschedparam.c @@ -3,8 +3,8 @@ int pthread_setschedparam(pthread_t t, int policy, const struct sched_param *param) { int r; - __lock(t->killlock); + LOCK(t->killlock); r = t->dead ? ESRCH : -__syscall(SYS_sched_setscheduler, t->tid, policy, param); - __unlock(t->killlock); + UNLOCK(t->killlock); return r; } diff --git a/src/thread/pthread_setschedprio.c b/src/thread/pthread_setschedprio.c index e0bdc03b..dc745b42 100644 --- a/src/thread/pthread_setschedprio.c +++ b/src/thread/pthread_setschedprio.c @@ -3,8 +3,8 @@ int pthread_setschedprio(pthread_t t, int prio) { int r; - __lock(t->killlock); + LOCK(t->killlock); r = t->dead ? ESRCH : -__syscall(SYS_sched_setparam, t->tid, &prio); - __unlock(t->killlock); + UNLOCK(t->killlock); return r; } From 32482f61da7650ff10741bd5aedd66bbc3ea165b Mon Sep 17 00:00:00 2001 From: Jens Gustedt Date: Wed, 3 Jan 2018 14:17:12 +0100 Subject: [PATCH 023/161] revise the definition of multiple basic locks in the code In all cases this is just a change from two volatile int to one. --- src/dirent/__dirent.h | 2 +- src/exit/at_quick_exit.c | 2 +- src/exit/atexit.c | 2 +- src/internal/pthread_impl.h | 4 ++-- src/locale/dcngettext.c | 2 +- src/locale/locale_map.c | 2 +- src/locale/setlocale.c | 2 +- src/malloc/lite_malloc.c | 2 +- src/misc/syslog.c | 2 +- src/prng/random.c | 2 +- src/stdio/ofl.c | 2 +- src/thread/pthread_atfork.c | 2 +- src/thread/sem_open.c | 2 +- src/thread/synccall.c | 2 +- src/time/__tz.c | 2 +- 15 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/dirent/__dirent.h b/src/dirent/__dirent.h index 32871baf..101b0368 100644 --- a/src/dirent/__dirent.h +++ b/src/dirent/__dirent.h @@ -4,6 +4,6 @@ struct __dirstream off_t tell; int buf_pos; int buf_end; - volatile int lock[2]; + volatile int lock[1]; char buf[2048]; }; diff --git a/src/exit/at_quick_exit.c b/src/exit/at_quick_exit.c index ac28dfd9..4079b242 100644 --- a/src/exit/at_quick_exit.c +++ b/src/exit/at_quick_exit.c @@ -5,7 +5,7 @@ static void (*funcs[COUNT])(void); static int count; -static volatile int lock[2]; +static volatile int lock[1]; void __funcs_on_quick_exit() { diff --git a/src/exit/atexit.c b/src/exit/atexit.c index 2b58b8bb..cd3b0a64 100644 --- a/src/exit/atexit.c +++ b/src/exit/atexit.c @@ -13,7 +13,7 @@ static struct fl } builtin, *head; static int slot; -static volatile int lock[2]; +static volatile int lock[1]; void __funcs_on_exit() { diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index 602d6f56..f0b2c20c 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -39,8 +39,8 @@ struct pthread { int unblock_cancel; volatile int timer_id; locale_t locale; - volatile int killlock[2]; - volatile int exitlock[2]; + volatile int killlock[1]; + volatile int exitlock[1]; volatile int startlock[2]; unsigned long sigmask[_NSIG/8/sizeof(long)]; char *dlerror_buf; diff --git a/src/locale/dcngettext.c b/src/locale/dcngettext.c index b79b7010..d8af9603 100644 --- a/src/locale/dcngettext.c +++ b/src/locale/dcngettext.c @@ -34,7 +34,7 @@ static char *gettextdir(const char *domainname, size_t *dirlen) char *bindtextdomain(const char *domainname, const char *dirname) { - static volatile int lock[2]; + static volatile int lock[1]; struct binding *p, *q; if (!domainname) return 0; diff --git a/src/locale/locale_map.c b/src/locale/locale_map.c index 188fcf39..79542310 100644 --- a/src/locale/locale_map.c +++ b/src/locale/locale_map.c @@ -26,7 +26,7 @@ static const char envvars[][12] = { const struct __locale_map *__get_locale(int cat, const char *val) { - static volatile int lock[2]; + static volatile int lock[1]; static void *volatile loc_head; const struct __locale_map *p; struct __locale_map *new = 0; diff --git a/src/locale/setlocale.c b/src/locale/setlocale.c index 623660cc..40bc7ece 100644 --- a/src/locale/setlocale.c +++ b/src/locale/setlocale.c @@ -21,7 +21,7 @@ char *__strchrnul(const char *, int); char *setlocale(int cat, const char *name) { - static volatile int lock[2]; + static volatile int lock[1]; if ((unsigned)cat > LC_ALL) return 0; diff --git a/src/malloc/lite_malloc.c b/src/malloc/lite_malloc.c index a7e4a9f7..701f60b4 100644 --- a/src/malloc/lite_malloc.c +++ b/src/malloc/lite_malloc.c @@ -11,7 +11,7 @@ void *__expand_heap(size_t *); static void *__simple_malloc(size_t n) { static char *cur, *end; - static volatile int lock[2]; + static volatile int lock[1]; size_t align=1, pad; void *p; diff --git a/src/misc/syslog.c b/src/misc/syslog.c index 9dd1ddb5..60e9020f 100644 --- a/src/misc/syslog.c +++ b/src/misc/syslog.c @@ -11,7 +11,7 @@ #include #include "libc.h" -static volatile int lock[2]; +static volatile int lock[1]; static char log_ident[32]; static int log_opt; static int log_facility = LOG_USER; diff --git a/src/prng/random.c b/src/prng/random.c index 7d557d70..13a5e6df 100644 --- a/src/prng/random.c +++ b/src/prng/random.c @@ -22,7 +22,7 @@ static int n = 31; static int i = 3; static int j = 0; static uint32_t *x = init+1; -static volatile int lock[2]; +static volatile int lock[1]; static uint32_t lcg31(uint32_t x) { return (1103515245*x + 12345) & 0x7fffffff; diff --git a/src/stdio/ofl.c b/src/stdio/ofl.c index b143999c..0e3602aa 100644 --- a/src/stdio/ofl.c +++ b/src/stdio/ofl.c @@ -2,7 +2,7 @@ #include "libc.h" static FILE *ofl_head; -static volatile int ofl_lock[2]; +static volatile int ofl_lock[1]; FILE **__ofl_lock() { diff --git a/src/thread/pthread_atfork.c b/src/thread/pthread_atfork.c index a40d7f63..c6f77b3f 100644 --- a/src/thread/pthread_atfork.c +++ b/src/thread/pthread_atfork.c @@ -8,7 +8,7 @@ static struct atfork_funcs { struct atfork_funcs *prev, *next; } *funcs; -static volatile int lock[2]; +static volatile int lock[1]; void __fork_handler(int who) { diff --git a/src/thread/sem_open.c b/src/thread/sem_open.c index fda0acd3..dc0279e8 100644 --- a/src/thread/sem_open.c +++ b/src/thread/sem_open.c @@ -20,7 +20,7 @@ static struct { sem_t *sem; int refcnt; } *semtab; -static volatile int lock[2]; +static volatile int lock[1]; #define FLAGS (O_RDWR|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK) diff --git a/src/thread/synccall.c b/src/thread/synccall.c index f6813576..ba2f258e 100644 --- a/src/thread/synccall.c +++ b/src/thread/synccall.c @@ -14,7 +14,7 @@ static struct chain { sem_t target_sem, caller_sem; } *volatile head; -static volatile int synccall_lock[2]; +static volatile int synccall_lock[1]; static volatile int target_tid; static void (*callback)(void *), *context; static volatile int dummy = 0; diff --git a/src/time/__tz.c b/src/time/__tz.c index 8cc96032..1dbb0b8f 100644 --- a/src/time/__tz.c +++ b/src/time/__tz.c @@ -27,7 +27,7 @@ static char old_tz_buf[32]; static char *old_tz = old_tz_buf; static size_t old_tz_size = sizeof old_tz_buf; -static volatile int lock[2]; +static volatile int lock[1]; static int getint(const char **p) { From b64539ae06aa91a407359238f4e909adb9bfab3d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 10 Jan 2018 20:45:02 -0500 Subject: [PATCH 024/161] fix printf alt-form octal with value 0 and no explicit precision commit 78897b0dc00b7cd5c29af5e0b7eebf2396d8dce0 wrongly simplified Dmitry Levin's original submitted patch fixing alt-form octal with the zero flag and field width present, omitting the special case where the value is zero. as a result, printf("%#o",0) wrongly prints "00" rather than "0". the logic prior to this commit was actually better, in that it was aligned with how the alt-form flag (#) for printf is specified ("it shall increase the precision"). at the time there was no good way to avoid the zero flag issue with the old logic, but commit 167dfe9672c116b315e72e57a55c7769f180dffa added tracking of whether an explicit precision was provided. revert commit 78897b0dc00b7cd5c29af5e0b7eebf2396d8dce0 and switch to using the explicit precision indicator for suppressing the zero flag. --- src/stdio/vfprintf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stdio/vfprintf.c b/src/stdio/vfprintf.c index 15356f53..50fb55c1 100644 --- a/src/stdio/vfprintf.c +++ b/src/stdio/vfprintf.c @@ -559,7 +559,7 @@ static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, if (0) { case 'o': a = fmt_o(arg.i, z); - if ((fl&ALT_FORM) && p=0) fl &= ~ZERO_PAD; + if (xp) fl &= ~ZERO_PAD; if (!arg.i && !p) { a=z; break; From 1bc10ffeaa7c7ce44b3e214e02e302642511c7c7 Mon Sep 17 00:00:00 2001 From: Rostislav Skudnov Date: Fri, 12 Jan 2018 17:06:03 +0000 Subject: [PATCH 025/161] add _DIRENT_HAVE_D_* macros to dirent.h --- include/dirent.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/dirent.h b/include/dirent.h index 88d3c3cf..e0a8fe6a 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -17,6 +17,10 @@ extern "C" { typedef struct __dirstream DIR; +#define _DIRENT_HAVE_D_RECLEN +#define _DIRENT_HAVE_D_OFF +#define _DIRENT_HAVE_D_TYPE + struct dirent { ino_t d_ino; off_t d_off; From 14edadb542848300193b76d2eee7a1eae07f0911 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 31 Jan 2018 23:29:24 +0000 Subject: [PATCH 026/161] aarch64: fix mismatched type of ucontext_t uc_link member --- arch/aarch64/bits/signal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/aarch64/bits/signal.h b/arch/aarch64/bits/signal.h index 5eb3d91f..1c67313d 100644 --- a/arch/aarch64/bits/signal.h +++ b/arch/aarch64/bits/signal.h @@ -59,7 +59,7 @@ struct sigaltstack { typedef struct __ucontext { unsigned long uc_flags; - struct ucontext *uc_link; + struct __ucontext *uc_link; stack_t uc_stack; sigset_t uc_sigmask; mcontext_t uc_mcontext; From f1abc29bd09dde14edd942f5868446aaba77f73f Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Mon, 29 Jan 2018 20:36:41 -0600 Subject: [PATCH 027/161] fix getopt_long arguments to partial matches If we find a partial option name match, we need to keep looking for ambiguous/conflicting options. However, we need to remember the position in the candidate argument to find its option-argument later, if there is one. This fixes e.g. option "foobar" being given as "--fooba=baz". --- src/misc/getopt_long.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index 568ae7ba..0d1501d4 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -58,13 +58,14 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring { int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':'; int i, cnt, match; - char *opt; + char *arg, *opt; for (cnt=i=0; longopts[i].name; i++) { const char *name = longopts[i].name; opt = argv[optind]+1; if (*opt == '-') opt++; for (; *name && *name == *opt; name++, opt++); if (*opt && *opt != '=') continue; + arg = opt; match = i; if (!*name) { cnt = 1; @@ -74,6 +75,7 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring } if (cnt==1) { i = match; + opt = arg; optind++; if (*opt == '=') { if (!longopts[i].has_arg) { From 6f03b61b46d238d480f5b7730ba906e172066e59 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Mon, 29 Jan 2018 20:36:42 -0600 Subject: [PATCH 028/161] getopt_long: accept prefix match of long options containing equals signs Consider the first equals sign found in the option to be the delimiter between it and its argument, even if it matches an equals sign in the option name. This avoids consuming the equals sign, which would prevent finding the argument. Instead, it forces a partial match of the part of the option name before the equals sign. Maintainer's note: GNU getopt_long does not explicitly document this behavior, but it can be seen as a consequence of how partial matches are specified, and at least GNU (bfd) ld is known to make use of it. --- src/misc/getopt_long.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index 0d1501d4..008b747c 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -63,7 +63,8 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring const char *name = longopts[i].name; opt = argv[optind]+1; if (*opt == '-') opt++; - for (; *name && *name == *opt; name++, opt++); + while (*opt && *opt != '=' && *opt == *name) + name++, opt++; if (*opt && *opt != '=') continue; arg = opt; match = i; From b3ae7beabb9f0c219bb8a8b63567a01c6530c1ac Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 2 Feb 2018 12:15:43 -0500 Subject: [PATCH 029/161] adjust dladdr dli_fbase definition to match other implementations the Linux and FreeBSD man pages for dladdr document dli_fbase as the "base address" of the library/module found. normally (e.g. AT_BASE) the term "base" is used to denote the base address relative to which p_vaddr addresses are interpreted; however in the case of dladdr's Dl_info structure, existing implementations define it as the lowest address of the mapping, which makes sense in the context of determining which module's memory range the input address falls within. since this is a nonstandard interface provided to mimic one provided by other implementations, adjust it to match their behavior. --- ldso/dynlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ldso/dynlink.c b/ldso/dynlink.c index 4b4841f9..33802400 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -1961,7 +1961,7 @@ int dladdr(const void *addr, Dl_info *info) best = p->funcdescs + (bestsym - p->syms); info->dli_fname = p->name; - info->dli_fbase = p->base; + info->dli_fbase = p->map; info->dli_sname = strings + bestsym->st_name; info->dli_saddr = best; From 7c709f2d4f9872d1b445f760b0e68da89e256b9e Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Fri, 2 Feb 2018 20:08:55 +0000 Subject: [PATCH 030/161] store pthread stack guard sizes for pthread_getattr_np --- src/internal/pthread_impl.h | 1 + src/thread/pthread_create.c | 3 ++- src/thread/pthread_getattr_np.c | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index f0b2c20c..4a0db987 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -46,6 +46,7 @@ struct pthread { char *dlerror_buf; int dlerror_flag; void *stdio_locks; + size_t guard_size; uintptr_t canary_at_end; void **dtv_copy; }; diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 34cd9936..439ee363 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -232,8 +232,8 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att memset(stack, 0, need); } else { size = ROUND(need); - guard = 0; } + guard = 0; } else { guard = ROUND(attr._a_guardsize); size = guard + ROUND(attr._a_stacksize @@ -265,6 +265,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att new->map_size = size; new->stack = stack; new->stack_size = stack - stack_limit; + new->guard_size = guard; new->start = entry; new->start_arg = arg; new->self = new; diff --git a/src/thread/pthread_getattr_np.c b/src/thread/pthread_getattr_np.c index ae26a5ab..29a209bd 100644 --- a/src/thread/pthread_getattr_np.c +++ b/src/thread/pthread_getattr_np.c @@ -7,6 +7,7 @@ int pthread_getattr_np(pthread_t t, pthread_attr_t *a) { *a = (pthread_attr_t){0}; a->_a_detach = !!t->detached; + a->_a_guardsize = t->guard_size; if (t->stack) { a->_a_stackaddr = (uintptr_t)t->stack; a->_a_stacksize = t->stack_size; From cd0ae687deadbb05ed373d675e59a36f8915c86d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 5 Feb 2018 11:31:11 -0500 Subject: [PATCH 031/161] revert regression in faccessat AT_EACCESS robustness commit f9fb20b42da0e755d93de229a5a737d79a0e8f60 switched from using a pipe for the result to conveying it via the child process exit status. Alexander Monakov pointed out that the latter could fail if the application is not expecting faccessat to produce a child and performs a wait operation with __WCLONE or __WALL, and that it is not clear whether it's guaranteed to work when SIGCHLD's disposition has been set to SIG_IGN. in addition, that commit introduced a bug that caused EACCES to be produced instead of EBUSY due to an exit path that was overlooked when the error channel was changed, and introduced a spurious retry loop around the wait operation. --- src/unistd/faccessat.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/unistd/faccessat.c b/src/unistd/faccessat.c index 33478959..76bbd4c7 100644 --- a/src/unistd/faccessat.c +++ b/src/unistd/faccessat.c @@ -1,6 +1,5 @@ #include #include -#include #include #include "syscall.h" #include "pthread_impl.h" @@ -9,26 +8,19 @@ struct ctx { int fd; const char *filename; int amode; -}; - -static const int errors[] = { - 0, -EACCES, -ELOOP, -ENAMETOOLONG, -ENOENT, -ENOTDIR, - -EROFS, -EBADF, -EINVAL, -ETXTBSY, - -EFAULT, -EIO, -ENOMEM, - -EBUSY + int p; }; static int checker(void *p) { struct ctx *c = p; int ret; - int i; if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1) || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1)) __syscall(SYS_exit, 1); ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0); - for (i=0; i < sizeof errors/sizeof *errors - 1 && ret!=errors[i]; i++); - return i; + __syscall(SYS_write, c->p, &ret, sizeof ret); + return 0; } int faccessat(int fd, const char *filename, int amode, int flag) @@ -42,20 +34,21 @@ int faccessat(int fd, const char *filename, int amode, int flag) char stack[1024]; sigset_t set; pid_t pid; - int ret = -EBUSY; - struct ctx c = { .fd = fd, .filename = filename, .amode = amode }; + int status; + int ret, p[2]; + + if (pipe2(p, O_CLOEXEC)) return __syscall_ret(-EBUSY); + struct ctx c = { .fd = fd, .filename = filename, .amode = amode, .p = p[1] }; __block_all_sigs(&set); pid = __clone(checker, stack+sizeof stack, 0, &c); - if (pid > 0) { - int status; - do { - __syscall(SYS_wait4, pid, &status, __WCLONE, 0); - } while (!WIFEXITED(status) && !WIFSIGNALED(status)); - if (WIFEXITED(status)) - ret = errors[WEXITSTATUS(status)]; - } + __syscall(SYS_close, p[1]); + + if (pid<0 || __syscall(SYS_read, p[0], &ret, sizeof ret) != sizeof(ret)) + ret = -EBUSY; + __syscall(SYS_close, p[0]); + __syscall(SYS_wait4, pid, &status, __WCLONE, 0); __restore_sigs(&set); From e53296f88952dcc6a9343dea53a4aa911f9a9c87 Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Mon, 5 Feb 2018 17:38:37 +0300 Subject: [PATCH 032/161] re-fix child reaping in wordexp Do not retry waitpid if the child was terminated by a signal. Do not examine status: since we are not passing any flags, we will not receive stop or continue notifications. --- src/misc/wordexp.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/misc/wordexp.c b/src/misc/wordexp.c index db39b5b8..d123cf75 100644 --- a/src/misc/wordexp.c +++ b/src/misc/wordexp.c @@ -14,13 +14,7 @@ static void reap(pid_t pid) { int status; - for (;;) { - if (waitpid(pid, &status, 0) < 0) { - if (errno != EINTR) return; - } else { - if (WIFEXITED(status)) return; - } - } + while (waitpid(pid, &status, 0) < 0 && errno == EINTR); } static char *getword(FILE *f) From cc7c300d1af22641b012268a959ac42f15341ed8 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 5 Feb 2018 11:45:52 -0500 Subject: [PATCH 033/161] document pthread structure ABI constraints in comments in the original submission of the patch that became commit 7c709f2d4f9872d1b445f760b0e68da89e256b9e, and in subsequent reading of it by others, it was not clear that the new member had to be inserted before canary_at_end, or that inserting it at that location was safe. add comments to document. --- src/internal/pthread_impl.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index 4a0db987..f6a4f2c2 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -13,11 +13,15 @@ #define pthread __pthread struct pthread { + /* Part 1 -- these fields may be external or + * internal (accessed via asm) ABI. Do not change. */ struct pthread *self; void **dtv, *unused1, *unused2; uintptr_t sysinfo; uintptr_t canary, canary2; pid_t tid, pid; + + /* Part 2 -- implementation details, non-ABI. */ int tsd_used, errno_val; volatile int cancel, canceldisable, cancelasync; int detached; @@ -47,6 +51,9 @@ struct pthread { int dlerror_flag; void *stdio_locks; size_t guard_size; + + /* Part 3 -- the positions of these fields relative to + * the end of the structure is external and internal ABI. */ uintptr_t canary_at_end; void **dtv_copy; }; From 596207aa38b0db33f222c9924a1310fee3de88b5 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 5 Feb 2018 13:36:04 -0500 Subject: [PATCH 034/161] fix strftime field widths with %F format and zero year MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the code to strip initial sign and leading zeros inadvertently stripped all the zeros and the subsequent '-' separating the month. instead, only strip sign characters from the very first position, and only strip zeros when they are followed by another digit. based on testing by Dennis Wölfing. --- src/time/strftime.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/time/strftime.c b/src/time/strftime.c index d1ca7cae..16b3bb21 100644 --- a/src/time/strftime.c +++ b/src/time/strftime.c @@ -251,7 +251,8 @@ size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const st t = __strftime_fmt_1(&buf, &k, *f, tm, loc, pad); if (!t) break; if (width) { - for (; *t=='+' || *t=='-' || (*t=='0'&&t[1]); t++, k--); + if (*t=='+' || *t=='-') t++, k--; + for (; *t=='0' && t[1]-'0'<10U; t++, k--); width--; if (plus && tm->tm_year >= 10000-1900) s[l++] = '+'; From c7f0da4134d4e7f2efd295e7fb738c65c469fbd1 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 6 Feb 2018 12:31:06 -0500 Subject: [PATCH 035/161] adjust strftime + modifier to match apparent intent of POSIX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit it's unclear from the specification whether the word "consumes" in "consumes more than four bytes to represent a year" refers just to significant places or includes leading zeros due to field width padding. however the examples in the rationale indicate that the latter was the intent. in particular, the year 270 is shown being formatted by %+5Y as +0270 rather than 00270. previously '+' prefixing was implemented just by comparing the year against 10000. instead, count the number of significant digits and padding bytes to be added, and use the total to determine whether to apply the '+' prefix. based on testing by Dennis Wölfing. --- src/time/strftime.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/time/strftime.c b/src/time/strftime.c index 16b3bb21..708875ee 100644 --- a/src/time/strftime.c +++ b/src/time/strftime.c @@ -251,15 +251,21 @@ size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const st t = __strftime_fmt_1(&buf, &k, *f, tm, loc, pad); if (!t) break; if (width) { + /* Trim off any sign and leading zeros, then + * count remaining digits to determine behavior + * for the + flag. */ if (*t=='+' || *t=='-') t++, k--; for (; *t=='0' && t[1]-'0'<10U; t++, k--); - width--; - if (plus && tm->tm_year >= 10000-1900) - s[l++] = '+'; - else if (tm->tm_year < -1900) + if (width < k) width = k; + size_t d; + for (d=0; t[d]-'0'<10U; d++); + if (tm->tm_year < -1900) { s[l++] = '-'; - else - width++; + width--; + } else if (plus && d+(width-k) >= (*p=='C'?3:5)) { + s[l++] = '+'; + width--; + } for (; width > k && l < n; width--) s[l++] = '0'; } From f0b235c138d26caafeda44475818508f1911e78e Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 7 Feb 2018 14:27:08 -0500 Subject: [PATCH 036/161] honor rpath $ORIGIN for ldd/ldso command with program in working dir the rpath fixup code assumed any module's name field would contain at least one slash, an invariant which is usually met but not in the case of a main executable loaded from the current working directory by running ldd or ldso as a command. it would be possible to make this invariant always hold, but it has a higher runtime allocation cost and does not seem useful elsewhere, so just patch things up in fixup_rpath instead. --- ldso/dynlink.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ldso/dynlink.c b/ldso/dynlink.c index 33802400..3741c30d 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -807,7 +807,16 @@ static int fixup_rpath(struct dso *p, char *buf, size_t buf_size) origin = p->name; } t = strrchr(origin, '/'); - l = t ? t-origin : 0; + if (t) { + l = t-origin; + } else { + /* Normally p->name will always be an absolute or relative + * pathname containing at least one '/' character, but in the + * case where ldso was invoked as a command to execute a + * program in the working directory, app.name may not. Fix. */ + origin = "."; + l = 1; + } p->rpath = malloc(strlen(p->rpath_orig) + n*l + 1); if (!p->rpath) return -1; From 376b3c54bba7d235e5a8e2839bb333a826b19636 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 7 Feb 2018 14:31:42 -0500 Subject: [PATCH 037/161] disallow non-absolute rpath $ORIGIN for suid/sgid/AT_SECURE processes in theory non-absolute origins can only arise when either the main program is invoked by running ldso as a command (inherently non-suid) or when dlopen was called with a relative pathname containing at least one slash. such usage would be inherently insecure in an suid program anyway, so the old behavior here does not seem to have been insecure. harden against it anyway. --- ldso/dynlink.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ldso/dynlink.c b/ldso/dynlink.c index 3741c30d..9bf6924b 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -817,6 +817,9 @@ static int fixup_rpath(struct dso *p, char *buf, size_t buf_size) origin = "."; l = 1; } + /* Disallow non-absolute origins for suid/sgid/AT_SECURE. */ + if (libc.secure && *origin != '/') + return 0; p->rpath = malloc(strlen(p->rpath_orig) + n*l + 1); if (!p->rpath) return -1; From 23ddab8569ef8ae3488c1d67b6bccaa081c73245 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Fri, 12 Jan 2018 18:12:24 +0300 Subject: [PATCH 038/161] make getcwd fail if it cannot obtain an absolute path Currently getcwd(3) can succeed without returning an absolute path because the underlying getcwd syscall, starting with linux commit v2.6.36-rc1~96^2~2, may succeed without returning an absolute path. This is a conformance issue because "The getcwd() function shall place an absolute pathname of the current working directory in the array pointed to by buf, and return buf". Fix this by checking the path returned by syscall and failing with ENOENT if the path is not absolute. The error code is chosen for consistency with the case when the current directory is unlinked. Similar issue was fixed in glibc recently, see https://sourceware.org/bugzilla/show_bug.cgi?id=22679 --- src/unistd/getcwd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/unistd/getcwd.c b/src/unistd/getcwd.c index a7b925d2..103fbbb5 100644 --- a/src/unistd/getcwd.c +++ b/src/unistd/getcwd.c @@ -14,6 +14,12 @@ char *getcwd(char *buf, size_t size) errno = EINVAL; return 0; } - if (syscall(SYS_getcwd, buf, size) < 0) return 0; + long ret = syscall(SYS_getcwd, buf, size); + if (ret < 0) + return 0; + if (ret == 0 || buf[0] != '/') { + errno = ENOENT; + return 0; + } return buf == tmp ? strdup(buf) : buf; } From 249b621f9efeb8c47f34b698875c54c9c3108df3 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 17 Sep 2017 15:35:55 +0000 Subject: [PATCH 039/161] better configure check for long double support --- configure | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/configure b/configure index 02b736ce..501a7219 100755 --- a/configure +++ b/configure @@ -706,9 +706,8 @@ esac # printf "checking whether compiler's long double definition matches float.h... " echo '#include ' > "$tmpc" -echo '#if LDBL_MANT_DIG == 53' >> "$tmpc" -echo 'typedef char ldcheck[9-(int)sizeof(long double)];' >> "$tmpc" -echo '#endif' >> "$tmpc" +echo '#define C(m,s) (m==LDBL_MANT_DIG && s==sizeof(long double))' >> "$tmpc" +echo 'typedef char ldcheck[(C(53,8)||C(64,12)||C(64,16)||C(113,16))*2-1];' >> "$tmpc" if $CC $CFLAGS_C99FSE \ -I$srcdir/arch/$ARCH -I$srcdir/arch/generic -I$srcdir/include \ $CPPFLAGS $CFLAGS -c -o /dev/null "$tmpc" >/dev/null 2>&1 ; then From 75cba9c67fde03421b96c1bcbaf666b4b348739d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 11 Feb 2018 20:48:14 -0500 Subject: [PATCH 040/161] fix incorrect overflow check for allocation in fmemopen when a null buffer pointer is passed to fmemopen, requesting it allocate its own memory buffer, extremely large size arguments near SIZE_MAX could overflow and result in underallocation. this results from omission of the size of the cookie structure in the overflow check but inclusion of it in the calloc call. instead of accounting for individual small contributions to the total allocation size needed, simply reject sizes larger than PTRDIFF_MAX, which will necessarily fail anyway. then adding arbitrary fixed-size structures is safe without matching up the expressions in the comparison and the allocation. --- src/stdio/fmemopen.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdio/fmemopen.c b/src/stdio/fmemopen.c index 7c193a57..2ce43d32 100644 --- a/src/stdio/fmemopen.c +++ b/src/stdio/fmemopen.c @@ -81,7 +81,7 @@ FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode) return 0; } - if (!buf && size > SIZE_MAX-sizeof(FILE)-BUFSIZ-UNGET) { + if (!buf && size > PTRDIFF_MAX) { errno = ENOMEM; return 0; } From 8e0b38060d7a9916fc2b5de0dd7c166ef60be9c1 Mon Sep 17 00:00:00 2001 From: Przemyslaw Pawelczyk Date: Mon, 23 Oct 2017 00:07:42 +0200 Subject: [PATCH 041/161] fix execvp failing on not-dir entries in PATH. It's better to make execvp continue PATH search on ENOTDIR rather than issuing an error. Bogus entries should not render rest of PATH invalid. Maintainer's note: POSIX seems to require the search to continue like this as part of XBD 8.3 Other Environment Variables. Only errors that conclusively determine non-existence are candidates for continuing; otherwise for consistency we have to report the error. --- src/process/execvp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/process/execvp.c b/src/process/execvp.c index 3a8bbe83..480a85e9 100644 --- a/src/process/execvp.c +++ b/src/process/execvp.c @@ -40,7 +40,7 @@ int __execvpe(const char *file, char *const argv[], char *const envp[]) memcpy(b+(z-p)+(z>p), file, k+1); execve(b, argv, envp); if (errno == EACCES) seen_eacces = 1; - else if (errno != ENOENT) return -1; + else if (errno != ENOENT && errno != ENOTDIR) return -1; if (!*z++) break; } if (seen_eacces) errno = EACCES; From 6d6102427d8d5450bd28788c792f97ef90cce274 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 21 Feb 2018 11:59:34 -0500 Subject: [PATCH 042/161] convert execvp error handling to switch statement this is more extensible if we need to consider additional errors, and more efficient as long as the compiler does not know it can cache the result of __errno_location (a surprisingly complex issue detailed in commit a603a75a72bb469c6be4963ed1b55fabe675fe15). --- src/process/execvp.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/process/execvp.c b/src/process/execvp.c index 480a85e9..2dddeddb 100644 --- a/src/process/execvp.c +++ b/src/process/execvp.c @@ -39,8 +39,15 @@ int __execvpe(const char *file, char *const argv[], char *const envp[]) b[z-p] = '/'; memcpy(b+(z-p)+(z>p), file, k+1); execve(b, argv, envp); - if (errno == EACCES) seen_eacces = 1; - else if (errno != ENOENT && errno != ENOTDIR) return -1; + switch (errno) { + case EACCES: + seen_eacces = 1; + case ENOENT: + case ENOTDIR: + break; + default: + return -1; + } if (!*z++) break; } if (seen_eacces) errno = EACCES; From fcf24b9f388d650a92375079461198f5db3ed88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=BA=C5=A1=20Olek=C5=A1=C3=A1k?= Date: Wed, 21 Feb 2018 12:03:04 -0500 Subject: [PATCH 043/161] fix detection of LIBCC for compiler-rt with clang Maintainer's note: at one point, -lcompiler_rt apparently worked, and may still work and be preferable if one has manually installed the library in a public lib directory. but with current versions of clang, the full pathname to the library file is needed. the original patch removed the -lcompiler_rt check; I have left it in place in case there are users depending on it, and since, when it does work, it's preferable so as not to code a dependency on the specific compiler version and paths in config.mak. --- configure | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure b/configure index 501a7219..1e59c461 100755 --- a/configure +++ b/configure @@ -598,6 +598,8 @@ tryldflag LDFLAGS_AUTO -Wl,-Bsymbolic-functions # Find compiler runtime library test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh test -z "$LIBCC" && tryldflag LIBCC -lcompiler_rt +test -z "$LIBCC" && try_libcc=`$CC -print-libgcc-file-name 2>/dev/null` \ + && tryldflag LIBCC "$try_libcc" test -z "$LIBCC" && try_libcc=`$CC -print-file-name=libpcc.a 2>/dev/null` \ && tryldflag LIBCC "$try_libcc" printf "using compiler runtime libraries: %s\n" "$LIBCC" From 1366b3c5e6d89d5ba90dd41fe5bf0246c5299b84 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 21 Feb 2018 14:19:01 -0500 Subject: [PATCH 044/161] update authors/contributors list these additions were made by scanning git log since the last major update in commit 790580b2fc47bc20e613336cb937a120422a770c. in addition to git-level commit authorship, "patch by" text in the commit message was also scanned. this idiom was used in the past for patches that underwent substantial edits when merging or where the author did not provide a commit message. going forward, my intent is to use commit authorship consistently for attribution. as before my aim was adding everyone with either substantial code contributions or a pattern of ongoing simple patch submission; any omissions are unintentional. --- COPYRIGHT | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/COPYRIGHT b/COPYRIGHT index f0ee3b78..8c3a6d19 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -25,22 +25,31 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Authors/contributors include: +A. Wilcox Alex Dowad Alexander Monakov +Andrew Kelley Anthony G. Basile Arvid Picciani +Bartosz Brachaczek Bobby Bingham Boris Brezillon Brent Cook Chris Spiegel Clément Vasseur Daniel Micay +Daniel Sabogal +Daurnimator +David Edelsohn Denys Vlasenko +Dmitry Ivanov +Dmitry V. Levin Emil Renner Berthing Felix Fietkau Felix Janda Gianluca Anzolin Hauke Mehrtens +He X Hiltjo Posthuma Isaac Dunham Jaydeep Patil @@ -50,22 +59,29 @@ Jo-Philipp Wich Joakim Sindholt John Spencer Josiah Worcester +Julien Ramseier Justin Cormack Khem Raj Kylie McClain +Leah Neukirchen Luca Barbato Luka Perkov M Farkas-Dyck (Strake) Mahesh Bodapati +Masanori Ogino Michael Forney +Mikhail Kremnyov Natanael Copa Nicholas J. Kain orc Pascal Cuoq Petr Hosek +Petr Skocik Pierre Carrier +Reini Urban Rich Felker Richard Pennington +Samuel Holland Shiz sin Solar Designer @@ -75,6 +91,7 @@ Timo Teräs Trutz Behn Valentin Ochs William Haddon +William Pitcock Portions of this software are derived from third-party works licensed under terms compatible with the above MIT license: From 55df09bfccbfe21fc9dd7d8f94550c0ff25ace04 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 22 Feb 2018 13:39:19 -0500 Subject: [PATCH 045/161] release 1.1.19 --- VERSION | 2 +- WHATSNEW | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 852ed67c..4e036596 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.18 +1.1.19 diff --git a/WHATSNEW b/WHATSNEW index 3d2fefa1..fd2a5936 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -1862,3 +1862,48 @@ regression fixes: other bug fixes: - stack overflow in posix_spawnp with large PATH variable in environment + + +1.1.19 release notes + +new features: +- iconv framework for processing stateful encodings +- iconv support for iso-2022-jp +- iconv support for converting to legacy JIS-based Japanese encodings +- iconv support for UTF-16/32 with BOM-determined endianness +- iconv ibm1047 (ebcdic latin1-equivalent) support +- iconv cp866 (dos cyrillic) support +- character data tables & case mappings updated to Unicode 10.0 +- fopencookie stdio extension +- strftime padding character extensions +- header-level support for new linux features through 4.13 + +compatibility: +- UTC timezone is now called UTC instead of GMT +- _DIRENT_HAVE_D_* macros in dirent.h +- dladdr dli_fbase definition now matches other implementations +- pthread_getattr_np now reports guard size +- strftime '+' modifier better matches apparent intent of POSIX +- getopt_long handles long option names containing '=' +- better compatibility with linux uapi headers +- workaround linux bug where getcwd can return non-absolute pathname +- configure logic for finding compiler_rt with clang +- execvp path search now continues after ENOTDIR components + +bugs fixed: +- fgetwc failed when character crossed buffer boundary +- memory corruption after failing to dlopen a second libc +- sysconf reported infinite rlimits incorrectly +- getopt_long --opt=arg did not work with partial matches +- printf was wrong for alt-form octal with value 0, no explicit precision +- endian errors in arpa/nameser.h and netinet/icmp6.h (missing endian.h) +- atfork handler could clobber fork's errno +- iconv could wrongly output surrogate pairs in ucs2 +- fmemopen buffer underallocation with extreme size argument +- getaddrinfo AI_NUMERICSERV wrong error code +- data race in at_quick_exit +- ldd failed to honor rpath $ORIGIN for program in . without "./" prefix + +arch-specfic bugs fixed: +- x32 unistd.h wrongly reported LP64 instead of ILP32 +- aarch64 signal.h had wrong type for ucontext_t uc_link member From 709bbf51758a23e5c85b9247fe2b2a558ed31bbb Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 Nov 2017 22:21:31 +0000 Subject: [PATCH 046/161] sys/socket.h: add PF_SMC from linux v4.11 add AF_SMC and PF_SMC for the IBM shared memory communication protocol. new in linux commit ac7138746e14137a451f8539614cdd349153e0c0 (linux socket.h is not in uapi so this update was missed earlier) --- include/sys/socket.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/sys/socket.h b/include/sys/socket.h index 051d20e0..396a47ad 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -108,7 +108,8 @@ struct linger { #define PF_VSOCK 40 #define PF_KCM 41 #define PF_QIPCRTR 42 -#define PF_MAX 43 +#define PF_SMC 43 +#define PF_MAX 44 #define AF_UNSPEC PF_UNSPEC #define AF_LOCAL PF_LOCAL @@ -156,6 +157,7 @@ struct linger { #define AF_VSOCK PF_VSOCK #define AF_KCM PF_KCM #define AF_QIPCRTR PF_QIPCRTR +#define AF_SMC PF_SMC #define AF_MAX PF_MAX #ifndef SO_DEBUG From 404097a4ef4e5e776d6f7bf16e319e69e880469c Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 Nov 2017 22:34:31 +0000 Subject: [PATCH 047/161] sys/socket.h: add SOL_TLS from linux v4.13 socket option for kernel TLS support new in linux commit 3c4d7559159bfe1e3b94df3a657b2cda3a34e218 --- include/sys/socket.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/sys/socket.h b/include/sys/socket.h index 396a47ad..26d16bdf 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -263,6 +263,7 @@ struct linger { #define SOL_ALG 279 #define SOL_NFC 280 #define SOL_KCM 281 +#define SOL_TLS 282 #define SOMAXCONN 128 From 986bc21713b1c9b38d37356033c02aec188333bf Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 Nov 2017 22:53:48 +0000 Subject: [PATCH 048/161] sys/socket.h: add MSG_ZEROCOPY from linux v4.14 MSG_ZEROCOPY socket send flag avoids copy in the kernel new in linux commit 52267790ef52d7513879238ca9fac22c1733e0e3 SO_ZEROCOPY socket option enables MSG_ZEROCOPY if availale new in linux commit 76851d1212c11365362525e1e2c0a18c97478e6b --- include/sys/socket.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/sys/socket.h b/include/sys/socket.h index 26d16bdf..507da5cc 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -232,6 +232,7 @@ struct linger { #define SO_COOKIE 57 #define SCM_TIMESTAMPING_PKTINFO 58 #define SO_PEERGROUPS 59 +#define SO_ZEROCOPY 60 #ifndef SOL_SOCKET #define SOL_SOCKET 1 @@ -285,6 +286,7 @@ struct linger { #define MSG_MORE 0x8000 #define MSG_WAITFORONE 0x10000 #define MSG_BATCH 0x40000 +#define MSG_ZEROCOPY 0x4000000 #define MSG_FASTOPEN 0x20000000 #define MSG_CMSG_CLOEXEC 0x40000000 From 5431c200402bf0b5a061c585c0b76c099e45a418 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 Nov 2017 21:54:30 +0000 Subject: [PATCH 049/161] sys/mman.h: add MADV_WIPEONFORK from linux v4.14 allows zeroing anonymous private pages inherited by a child process. new in linux commit d2cd9ede6e193dd7d88b6d27399e96229a551b19 --- include/sys/mman.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/sys/mman.h b/include/sys/mman.h index 8a5149c9..12318782 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -72,6 +72,8 @@ extern "C" { #define MADV_NOHUGEPAGE 15 #define MADV_DONTDUMP 16 #define MADV_DODUMP 17 +#define MADV_WIPEONFORK 18 +#define MADV_KEEPONFORK 19 #define MADV_HWPOISON 100 #define MADV_SOFT_OFFLINE 101 #endif From ebd8ef50d5012733d86ed4a6834ca6d776b069ae Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 Nov 2017 23:05:45 +0000 Subject: [PATCH 050/161] aarch64: add HWCAP_DCPOP from linux v4.14 indicates ARMv8.2-DCPoP persistent memory support extension. new in linux commit 7aac405ebb3224037efd56b73d82d181111cdac3 --- arch/aarch64/bits/hwcap.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/aarch64/bits/hwcap.h b/arch/aarch64/bits/hwcap.h index 11396d31..87f71ff3 100644 --- a/arch/aarch64/bits/hwcap.h +++ b/arch/aarch64/bits/hwcap.h @@ -14,3 +14,4 @@ #define HWCAP_JSCVT (1 << 13) #define HWCAP_FCMA (1 << 14) #define HWCAP_LRCPC (1 << 15) +#define HWCAP_DCPOP (1 << 16) From 38e81ddc0440ecc61f6fa9faf9225b91c9c8017c Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 Nov 2017 23:20:38 +0000 Subject: [PATCH 051/161] signal.h: add missing SIGTRAP si_codes TRAP_BRANCH and TRAP_HWBKPT new in linux commit da654b74bda14c45a7d98c731bf3c1a43b6b74e2 --- include/signal.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/signal.h b/include/signal.h index 2c8b3d55..4001ff49 100644 --- a/include/signal.h +++ b/include/signal.h @@ -231,6 +231,8 @@ int sigrelse(int); void (*sigset(int, void (*)(int)))(int); #define TRAP_BRKPT 1 #define TRAP_TRACE 2 +#define TRAP_BRANCH 3 +#define TRAP_HWBKPT 4 #define POLL_IN 1 #define POLL_OUT 2 #define POLL_MSG 3 From 4d4a665799a0ed6dda3deed3d380b72c84d9f4d2 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 Nov 2017 23:26:26 +0000 Subject: [PATCH 052/161] net/if_arp.h: add ARPHRD_RAWIP from linux v4.14 new in linux commmit cdf4969c42a6c1a376dd03a9e846cf638d3cd4b1 --- include/net/if_arp.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/net/if_arp.h b/include/net/if_arp.h index c832ff95..27becc83 100644 --- a/include/net/if_arp.h +++ b/include/net/if_arp.h @@ -59,6 +59,7 @@ struct arphdr { #define ARPHRD_LAPB 516 #define ARPHRD_DDCMP 517 #define ARPHRD_RAWHDLC 518 +#define ARPHRD_RAWIP 519 #define ARPHRD_TUNNEL 768 #define ARPHRD_TUNNEL6 769 From fba3059d72e610944339ab139b01ea0c97d8f7c6 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 Nov 2017 23:36:17 +0000 Subject: [PATCH 053/161] netinet/if_ether.h: add new ETH_P_ macros from linux v4.14 new ethertypes in linux v4.14: ETH_P_ERSPAN new in 84e54fe0a5eaed696dee4019c396f8396f5a908b ETH_P_IFE new in 2804fd3af6ba5ae5737705b27146455eabe2e2f8 ETH_P_NSH new in 155e6f649757c902901e599c268f8b575ddac1f8 ETH_P_MAP new in 7373ae7e8f0bf2c0718422481da986db5058b005 --- include/netinet/if_ether.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h index 97134d75..9007d609 100644 --- a/include/netinet/if_ether.h +++ b/include/netinet/if_ether.h @@ -53,6 +53,7 @@ #define ETH_P_AOE 0x88A2 #define ETH_P_8021AD 0x88A8 #define ETH_P_802_EX1 0x88B5 +#define ETH_P_ERSPAN 0x88BE #define ETH_P_TIPC 0x88CA #define ETH_P_MACSEC 0x88E5 #define ETH_P_8021AH 0x88E7 @@ -66,11 +67,13 @@ #define ETH_P_IBOE 0x8915 #define ETH_P_80221 0x8917 #define ETH_P_HSR 0x892F +#define ETH_P_NSH 0x894F #define ETH_P_LOOPBACK 0x9000 #define ETH_P_QINQ1 0x9100 #define ETH_P_QINQ2 0x9200 #define ETH_P_QINQ3 0x9300 #define ETH_P_EDSA 0xDADA +#define ETH_P_IFE 0xED3E #define ETH_P_AF_IUCV 0xFBFB #define ETH_P_802_3_MIN 0x0600 @@ -100,6 +103,7 @@ #define ETH_P_IEEE802154 0x00F6 #define ETH_P_CAIF 0x00F7 #define ETH_P_XDSA 0x00F8 +#define ETH_P_MAP 0x00F9 struct ethhdr { uint8_t h_dest[ETH_ALEN]; From abdaba8616c29b0814a4dbe726224b6f2c9f8604 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 26 Nov 2017 23:58:25 +0000 Subject: [PATCH 054/161] sys/{mman,shm}.h: add {MAP,SHM}_HUGE_ macros from linux uapi *_HUGE_SHIFT, *_HUGE_2MB, *_HUGE_1GB are documented in the man page, so add all of the *_HUGE_* macros from linux uapi. if MAP_HUGETLB is set, top bits of the mmap flags encode the page size. see the linux commit aafd4562dfee81a40ba21b5ea3cf5e06664bc7f6 if SHM_HUGETLB is set, top bits of the shmget flags encode the page size. see the linux commit 4da243ac1cf6aeb30b7c555d56208982d66d6d33 *_HUGE_16GB is defined unsigned to avoid signed left shift ub. --- include/sys/mman.h | 13 +++++++++++++ include/sys/shm.h | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/sys/mman.h b/include/sys/mman.h index 12318782..d13d4ca3 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -35,6 +35,19 @@ extern "C" { #define MAP_HUGETLB 0x40000 #define MAP_FILE 0 +#define MAP_HUGE_SHIFT 26 +#define MAP_HUGE_MASK 0x3f +#define MAP_HUGE_64KB (16 << 26) +#define MAP_HUGE_512KB (19 << 26) +#define MAP_HUGE_1MB (20 << 26) +#define MAP_HUGE_2MB (21 << 26) +#define MAP_HUGE_8MB (23 << 26) +#define MAP_HUGE_16MB (24 << 26) +#define MAP_HUGE_256MB (28 << 26) +#define MAP_HUGE_1GB (30 << 26) +#define MAP_HUGE_2GB (31 << 26) +#define MAP_HUGE_16GB (34U << 26) + #define PROT_NONE 0 #define PROT_READ 1 #define PROT_WRITE 2 diff --git a/include/sys/shm.h b/include/sys/shm.h index 67be822b..e7d39ff6 100644 --- a/include/sys/shm.h +++ b/include/sys/shm.h @@ -40,6 +40,19 @@ extern "C" { #define SHM_HUGETLB 04000 #define SHM_NORESERVE 010000 +#define SHM_HUGE_SHIFT 26 +#define SHM_HUGE_MASK 0x3f +#define SHM_HUGE_64KB (16 << 26) +#define SHM_HUGE_512KB (19 << 26) +#define SHM_HUGE_1MB (20 << 26) +#define SHM_HUGE_2MB (21 << 26) +#define SHM_HUGE_8MB (23 << 26) +#define SHM_HUGE_16MB (24 << 26) +#define SHM_HUGE_256MB (28 << 26) +#define SHM_HUGE_1GB (30 << 26) +#define SHM_HUGE_2GB (31 << 26) +#define SHM_HUGE_16GB (34U << 26) + typedef unsigned long shmatt_t; void *shmat(int, const void *, int); From e69608700fa5a6920b3c8ba9951f43f5d4ec0eaa Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Mon, 27 Nov 2017 00:22:01 +0000 Subject: [PATCH 055/161] netinet/tcp.h: add tcp_diag_md5sig struct from linux v4.14 for querying tcp md5 signing keys. new in linux commit c03fa9bcacd9ac04595cc13f34f3445f0a5ecf13 --- include/netinet/tcp.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h index 4d20936a..94a4f8e2 100644 --- a/include/netinet/tcp.h +++ b/include/netinet/tcp.h @@ -220,6 +220,14 @@ struct tcp_md5sig { uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; }; +struct tcp_diag_md5sig { + uint8_t tcpm_family; + uint8_t tcpm_prefixlen; + uint16_t tcpm_keylen; + uint32_t tcpm_addr[4]; + uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; +}; + struct tcp_repair_window { uint32_t snd_wl1; uint32_t snd_wnd; From 9eda4dc69c33852c97c6f69176bf45ffc80b522f Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Mon, 27 Nov 2017 01:16:14 +0000 Subject: [PATCH 056/161] mips,powerpc: fix TIOCSER_TEMT in termios.h use the same token to define TIOCSER_TEMT as is used in ioctl.h so when both headers are included there are no redefinition warnings during musl build. --- arch/mips/bits/termios.h | 2 +- arch/mips64/bits/termios.h | 2 +- arch/mipsn32/bits/termios.h | 2 +- arch/powerpc/bits/termios.h | 2 +- arch/powerpc64/bits/termios.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/mips/bits/termios.h b/arch/mips/bits/termios.h index 6a1205d7..692e58be 100644 --- a/arch/mips/bits/termios.h +++ b/arch/mips/bits/termios.h @@ -163,5 +163,5 @@ struct termios { #define EXTPROC 0200000 #define XTABS 0014000 -#define TIOCSER_TEMT 1 +#define TIOCSER_TEMT 0x01 #endif diff --git a/arch/mips64/bits/termios.h b/arch/mips64/bits/termios.h index 6a1205d7..692e58be 100644 --- a/arch/mips64/bits/termios.h +++ b/arch/mips64/bits/termios.h @@ -163,5 +163,5 @@ struct termios { #define EXTPROC 0200000 #define XTABS 0014000 -#define TIOCSER_TEMT 1 +#define TIOCSER_TEMT 0x01 #endif diff --git a/arch/mipsn32/bits/termios.h b/arch/mipsn32/bits/termios.h index 6a1205d7..692e58be 100644 --- a/arch/mipsn32/bits/termios.h +++ b/arch/mipsn32/bits/termios.h @@ -163,5 +163,5 @@ struct termios { #define EXTPROC 0200000 #define XTABS 0014000 -#define TIOCSER_TEMT 1 +#define TIOCSER_TEMT 0x01 #endif diff --git a/arch/powerpc/bits/termios.h b/arch/powerpc/bits/termios.h index 0b09630c..5c2f6bfb 100644 --- a/arch/powerpc/bits/termios.h +++ b/arch/powerpc/bits/termios.h @@ -165,5 +165,5 @@ struct termios { #define EXTPROC 0x10000000 #define XTABS 00006000 -#define TIOCSER_TEMT 1 +#define TIOCSER_TEMT 0x01 #endif diff --git a/arch/powerpc64/bits/termios.h b/arch/powerpc64/bits/termios.h index 0b09630c..5c2f6bfb 100644 --- a/arch/powerpc64/bits/termios.h +++ b/arch/powerpc64/bits/termios.h @@ -165,5 +165,5 @@ struct termios { #define EXTPROC 0x10000000 #define XTABS 00006000 -#define TIOCSER_TEMT 1 +#define TIOCSER_TEMT 0x01 #endif From 9b57db3f958d9adc3b1c7371b5c6723aaee448b7 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 20:10:09 +0000 Subject: [PATCH 057/161] add MAP_SYNC and MAP_SHARED_VALIDATE from linux v4.15 for synchronous page faults, new in linux commit 1c9725974074a047f6080eecc62c50a8e840d050 and b6fb293f2497a9841d94f6b57bd2bb2cd222da43 note that only targets that use asm-generic/mman.h have this new flag defined, so undef it on other targets (mips*, powerpc*). --- arch/mips/bits/mman.h | 1 + arch/mips64/bits/mman.h | 1 + arch/mipsn32/bits/mman.h | 1 + arch/powerpc/bits/mman.h | 1 + arch/powerpc64/bits/mman.h | 1 + include/sys/mman.h | 2 ++ 6 files changed, 7 insertions(+) diff --git a/arch/mips/bits/mman.h b/arch/mips/bits/mman.h index c68aea88..9027bb63 100644 --- a/arch/mips/bits/mman.h +++ b/arch/mips/bits/mman.h @@ -18,6 +18,7 @@ #define MAP_STACK 0x40000 #undef MAP_HUGETLB #define MAP_HUGETLB 0x80000 +#undef MAP_SYNC #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef MADV_SOFT_OFFLINE diff --git a/arch/mips64/bits/mman.h b/arch/mips64/bits/mman.h index c68aea88..9027bb63 100644 --- a/arch/mips64/bits/mman.h +++ b/arch/mips64/bits/mman.h @@ -18,6 +18,7 @@ #define MAP_STACK 0x40000 #undef MAP_HUGETLB #define MAP_HUGETLB 0x80000 +#undef MAP_SYNC #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef MADV_SOFT_OFFLINE diff --git a/arch/mipsn32/bits/mman.h b/arch/mipsn32/bits/mman.h index c68aea88..9027bb63 100644 --- a/arch/mipsn32/bits/mman.h +++ b/arch/mipsn32/bits/mman.h @@ -18,6 +18,7 @@ #define MAP_STACK 0x40000 #undef MAP_HUGETLB #define MAP_HUGETLB 0x80000 +#undef MAP_SYNC #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #undef MADV_SOFT_OFFLINE diff --git a/arch/powerpc/bits/mman.h b/arch/powerpc/bits/mman.h index 95ec4358..b3a675a8 100644 --- a/arch/powerpc/bits/mman.h +++ b/arch/powerpc/bits/mman.h @@ -4,6 +4,7 @@ #define MAP_NORESERVE 0x40 #undef MAP_LOCKED #define MAP_LOCKED 0x80 +#undef MAP_SYNC #undef MCL_CURRENT #define MCL_CURRENT 0x2000 diff --git a/arch/powerpc64/bits/mman.h b/arch/powerpc64/bits/mman.h index 95ec4358..b3a675a8 100644 --- a/arch/powerpc64/bits/mman.h +++ b/arch/powerpc64/bits/mman.h @@ -4,6 +4,7 @@ #define MAP_NORESERVE 0x40 #undef MAP_LOCKED #define MAP_LOCKED 0x80 +#undef MAP_SYNC #undef MCL_CURRENT #define MCL_CURRENT 0x2000 diff --git a/include/sys/mman.h b/include/sys/mman.h index d13d4ca3..302ad134 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -20,6 +20,7 @@ extern "C" { #define MAP_SHARED 0x01 #define MAP_PRIVATE 0x02 +#define MAP_SHARED_VALIDATE 0x03 #define MAP_TYPE 0x0f #define MAP_FIXED 0x10 #define MAP_ANON 0x20 @@ -33,6 +34,7 @@ extern "C" { #define MAP_NONBLOCK 0x10000 #define MAP_STACK 0x20000 #define MAP_HUGETLB 0x40000 +#define MAP_SYNC 0x80000 #define MAP_FILE 0 #define MAP_HUGE_SHIFT 26 From 5f4ff22aa3ad81c59cac46444d01a7ce5b40636f Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 20:19:46 +0000 Subject: [PATCH 058/161] netinet/tcp.h: add TCP_* socket options from linux v4.15 TCP_FASTOPEN_KEY is new in 1fba70e5b6bed53496ba1f1f16127f5be01b5fb6 TCP_FASTOPEN_NO_COOKIE is new in 71c02379c762cb616c00fd5c4ed253fbf6bbe11b --- include/netinet/tcp.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h index 94a4f8e2..2747f4ea 100644 --- a/include/netinet/tcp.h +++ b/include/netinet/tcp.h @@ -34,6 +34,8 @@ #define TCP_FASTOPEN_CONNECT 30 #define TCP_ULP 31 #define TCP_MD5SIG_EXT 32 +#define TCP_FASTOPEN_KEY 33 +#define TCP_FASTOPEN_NO_COOKIE 34 #define TCP_ESTABLISHED 1 #define TCP_SYN_SENT 2 From 4001c51181e04511744c36fcfe2be10efa98c125 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 20:23:04 +0000 Subject: [PATCH 059/161] netinet/in.h: add new IPV6_FREEBIND from linux v4.15 new socekt option for AF_INET6 SOL_RAW sockets, added in linux commit 84e14fe353de7624872e582887712079ba0b2d56 --- include/netinet/in.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/netinet/in.h b/include/netinet/in.h index f18b478d..192679a6 100644 --- a/include/netinet/in.h +++ b/include/netinet/in.h @@ -363,6 +363,7 @@ struct ip6_mtuinfo { #define IPV6_TRANSPARENT 75 #define IPV6_UNICAST_IF 76 #define IPV6_RECVFRAGSIZE 77 +#define IPV6_FREEBIND 78 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP From 4ccd07527e9e8a6c7a1ba86acee462f0affb877a Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 20:27:39 +0000 Subject: [PATCH 060/161] s390x: add s390_sthyi system call from v4.15 to store hypervisor information, added in linux commit 3d8757b87d7fc15a87928bc970f060bc9c6dc618 --- arch/s390x/bits/syscall.h.in | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/s390x/bits/syscall.h.in b/arch/s390x/bits/syscall.h.in index 4fe1a64f..c965664c 100644 --- a/arch/s390x/bits/syscall.h.in +++ b/arch/s390x/bits/syscall.h.in @@ -322,4 +322,5 @@ #define __NR_pwritev2 377 #define __NR_s390_guarded_storage 378 #define __NR_statx 379 +#define __NR_s390_sthyi 380 From 0fc2f098a496bc5c7379e2330421fcc86988c2ba Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 20:38:15 +0000 Subject: [PATCH 061/161] powerpc: update hwcap.h for linux v4.15 PPC_FEATURE2_HTM_NO_SUSPEND is new in linux commit cba6ac4869e45cc93ac5497024d1d49576e82666 PPC_FEATURE2_DARN and PPC_FEATURE2_SCV were new in v4.12 in commit a4700a26107241cc7b9ac8528b2c6714ff99983d --- arch/powerpc/bits/hwcap.h | 3 +++ arch/powerpc64/bits/hwcap.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/arch/powerpc/bits/hwcap.h b/arch/powerpc/bits/hwcap.h index 82c92a93..803de9b5 100644 --- a/arch/powerpc/bits/hwcap.h +++ b/arch/powerpc/bits/hwcap.h @@ -38,3 +38,6 @@ #define PPC_FEATURE2_HTM_NOSC 0x01000000 #define PPC_FEATURE2_ARCH_3_00 0x00800000 #define PPC_FEATURE2_HAS_IEEE128 0x00400000 +#define PPC_FEATURE2_DARN 0x00200000 +#define PPC_FEATURE2_SCV 0x00100000 +#define PPC_FEATURE2_HTM_NO_SUSPEND 0x00080000 diff --git a/arch/powerpc64/bits/hwcap.h b/arch/powerpc64/bits/hwcap.h index 82c92a93..803de9b5 100644 --- a/arch/powerpc64/bits/hwcap.h +++ b/arch/powerpc64/bits/hwcap.h @@ -38,3 +38,6 @@ #define PPC_FEATURE2_HTM_NOSC 0x01000000 #define PPC_FEATURE2_ARCH_3_00 0x00800000 #define PPC_FEATURE2_HAS_IEEE128 0x00400000 +#define PPC_FEATURE2_DARN 0x00200000 +#define PPC_FEATURE2_SCV 0x00100000 +#define PPC_FEATURE2_HTM_NO_SUSPEND 0x00080000 From 8be960d1881ddd4c64a53e611226f8152b97dceb Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 20:42:27 +0000 Subject: [PATCH 062/161] arm: add get_tls syscall from linux v4.15 for systems without tp register or kuser helper, new in linux commit 8fcd6c45f5a65621ec809b7866a3623e9a01d4ed --- arch/arm/bits/syscall.h.in | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm/bits/syscall.h.in b/arch/arm/bits/syscall.h.in index c594152e..1920516a 100644 --- a/arch/arm/bits/syscall.h.in +++ b/arch/arm/bits/syscall.h.in @@ -359,4 +359,5 @@ #define __ARM_NR_usr26 0x0f0003 #define __ARM_NR_usr32 0x0f0004 #define __ARM_NR_set_tls 0x0f0005 +#define __ARM_NR_get_tls 0x0f0006 From 5a4a780ccb864a1e97483fe9c94858f24e1f02a2 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 20:46:45 +0000 Subject: [PATCH 063/161] aarch64: update hwcap.h for linux v4.15 HWCAP_SVE is new in linux commit 43994d824e8443263dc98b151e6326bf677be52e HWCAP_SHA3, HWCAP_SM3, HWCAP_SM4, HWCAP_ASIMDDP and HWCAP_SHA512 are new in f5e035f8694c3bdddc66ea46ecda965ee6853718 --- arch/aarch64/bits/hwcap.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/aarch64/bits/hwcap.h b/arch/aarch64/bits/hwcap.h index 87f71ff3..1727a387 100644 --- a/arch/aarch64/bits/hwcap.h +++ b/arch/aarch64/bits/hwcap.h @@ -15,3 +15,9 @@ #define HWCAP_FCMA (1 << 14) #define HWCAP_LRCPC (1 << 15) #define HWCAP_DCPOP (1 << 16) +#define HWCAP_SHA3 (1 << 17) +#define HWCAP_SM3 (1 << 18) +#define HWCAP_SM4 (1 << 19) +#define HWCAP_ASIMDDP (1 << 20) +#define HWCAP_SHA512 (1 << 21) +#define HWCAP_SVE (1 << 22) From 121d18d2f254fceb7e489d7a99527124f4084b5b Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 21:04:51 +0000 Subject: [PATCH 064/161] sys/prctl.h: add new PR_SVE_* macros from linux v4.15 PR_SVE_SET_VL and PR_SVE_GET_VL controls are new in linux commit 2d2123bc7c7f843aa9db87720de159a049839862 related PR_SVE_* macros were added in 7582e22038a266444eb87bc07c372592ad647439 --- include/sys/prctl.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/sys/prctl.h b/include/sys/prctl.h index 24f4f8bd..aa0c7a88 100644 --- a/include/sys/prctl.h +++ b/include/sys/prctl.h @@ -130,6 +130,12 @@ struct prctl_mm_map { #define PR_CAP_AMBIENT_LOWER 3 #define PR_CAP_AMBIENT_CLEAR_ALL 4 +#define PR_SVE_SET_VL 50 +#define PR_SVE_SET_VL_ONEXEC (1 << 18) +#define PR_SVE_GET_VL 51 +#define PR_SVE_VL_LEN_MASK 0xffff +#define PR_SVE_VL_INHERIT (1 << 17) + int prctl (int, ...); #ifdef __cplusplus From e7bd039df24c0435f8f5c42840e894cb1d2798ac Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 21:13:06 +0000 Subject: [PATCH 065/161] elf.h: add AT_* auxval macros for cache geometry AT_L1I_*, AT_L1D_*, AT_L2_* and AT_L3_* were added in linux v4.11 for powerpc in commit 98a5f361b8625c6f4841d6ba013bbf0e80d08147. --- include/elf.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/elf.h b/include/elf.h index e79915fe..3cebbe4a 100644 --- a/include/elf.h +++ b/include/elf.h @@ -1002,6 +1002,14 @@ typedef struct { #define AT_L2_CACHESHAPE 36 #define AT_L3_CACHESHAPE 37 +#define AT_L1I_CACHESIZE 40 +#define AT_L1I_CACHEGEOMETRY 41 +#define AT_L1D_CACHESIZE 42 +#define AT_L1D_CACHEGEOMETRY 43 +#define AT_L2_CACHESIZE 44 +#define AT_L2_CACHEGEOMETRY 45 +#define AT_L3_CACHESIZE 46 +#define AT_L3_CACHEGEOMETRY 47 From 5024804176dc899b1e700e4effe999ab757694dd Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 21:18:26 +0000 Subject: [PATCH 066/161] elf.h: add PPC64_OPT_LOCALENTRY allows calling extern functions without saving r2, for details see glibc commit 0572433b5beb636de1a49ec6b4fdab830c38cdc5 --- include/elf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/elf.h b/include/elf.h index 3cebbe4a..171805a1 100644 --- a/include/elf.h +++ b/include/elf.h @@ -2241,6 +2241,7 @@ enum #define PPC64_OPT_TLS 1 #define PPC64_OPT_MULTI_TOC 2 +#define PPC64_OPT_LOCALENTRY 4 #define STO_PPC64_LOCAL_BIT 5 #define STO_PPC64_LOCAL_MASK 0xe0 From eef5e4821de4c30b786975bd9aed84243c58db3a Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 21:22:38 +0000 Subject: [PATCH 067/161] elf.h: update NT_* coredump elf notes for linux v4.15 NT_ARM_SVE and NT_S390_RI_CB are new in linux commits 43d4da2c45b2f5d62f8a79ff7c6f95089bb24656 and 262832bc5acda76fd8f901d39f4da1121d951222 the rest are older. musl missed NT_PRFPREG because it followed the glibc api: https://sourceware.org/bugzilla/show_bug.cgi?id=14890 --- include/elf.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/elf.h b/include/elf.h index 171805a1..43f614a1 100644 --- a/include/elf.h +++ b/include/elf.h @@ -623,6 +623,7 @@ typedef struct { #define NT_PRSTATUS 1 +#define NT_PRFPREG 2 #define NT_FPREGSET 2 #define NT_PRPSINFO 3 #define NT_PRXREG 4 @@ -644,6 +645,19 @@ typedef struct { #define NT_PPC_VMX 0x100 #define NT_PPC_SPE 0x101 #define NT_PPC_VSX 0x102 +#define NT_PPC_TAR 0x103 +#define NT_PPC_PPR 0x104 +#define NT_PPC_DSCR 0x105 +#define NT_PPC_EBB 0x106 +#define NT_PPC_PMU 0x107 +#define NT_PPC_TM_CGPR 0x108 +#define NT_PPC_TM_CFPR 0x109 +#define NT_PPC_TM_CVMX 0x10a +#define NT_PPC_TM_CVSX 0x10b +#define NT_PPC_TM_SPR 0x10c +#define NT_PPC_TM_CTAR 0x10d +#define NT_PPC_TM_CPPR 0x10e +#define NT_PPC_TM_CDSCR 0x10f #define NT_386_TLS 0x200 #define NT_386_IOPERM 0x201 #define NT_X86_XSTATE 0x202 @@ -656,14 +670,21 @@ typedef struct { #define NT_S390_LAST_BREAK 0x306 #define NT_S390_SYSTEM_CALL 0x307 #define NT_S390_TDB 0x308 +#define NT_S390_VXRS_LOW 0x309 +#define NT_S390_VXRS_HIGH 0x30a +#define NT_S390_GS_CB 0x30b +#define NT_S390_GS_BC 0x30c +#define NT_S390_RI_CB 0x30d #define NT_ARM_VFP 0x400 #define NT_ARM_TLS 0x401 #define NT_ARM_HW_BREAK 0x402 #define NT_ARM_HW_WATCH 0x403 #define NT_ARM_SYSTEM_CALL 0x404 +#define NT_ARM_SVE 0x405 #define NT_METAG_CBUF 0x500 #define NT_METAG_RPIPE 0x501 #define NT_METAG_TLS 0x502 +#define NT_ARC_V2 0x600 #define NT_VERSION 1 From dfeeeaf5448d96d471b237b5f8a6f780f61445ba Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 21:31:39 +0000 Subject: [PATCH 068/161] elf.h: syncronize DF_1_ flags with binutils DF_1_STUB and DF_1_PIE were added in binutils-gdb commit 5c383f026242d25a3c21fdfda42e5ca218b346c8 --- include/elf.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/elf.h b/include/elf.h index 43f614a1..dab750de 100644 --- a/include/elf.h +++ b/include/elf.h @@ -842,6 +842,8 @@ typedef struct { #define DF_1_SYMINTPOSE 0x00800000 #define DF_1_GLOBAUDIT 0x01000000 #define DF_1_SINGLETON 0x02000000 +#define DF_1_STUB 0x04000000 +#define DF_1_PIE 0x08000000 #define DTF_1_PARINIT 0x00000001 #define DTF_1_CONFEXP 0x00000002 From 74ab4b828475bdd2afa76eb7c9e9808e7c872c1c Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Tue, 6 Feb 2018 22:33:38 +0000 Subject: [PATCH 069/161] elf.h: add DT_SYMTAB_SHNDX it's a recent addition to elf gabi: http://sco.com/developers/gabi/latest/revision.html based on discussions at https://sourceware.org/bugzilla/show_bug.cgi?id=15835 --- include/elf.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/elf.h b/include/elf.h index dab750de..78906f15 100644 --- a/include/elf.h +++ b/include/elf.h @@ -742,7 +742,8 @@ typedef struct { #define DT_ENCODING 32 #define DT_PREINIT_ARRAY 32 #define DT_PREINIT_ARRAYSZ 33 -#define DT_NUM 34 +#define DT_SYMTAB_SHNDX 34 +#define DT_NUM 35 #define DT_LOOS 0x6000000d #define DT_HIOS 0x6ffff000 #define DT_LOPROC 0x70000000 From 9bed82df305f5d1b7ebc36d0ac7a75d4f834e69b Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 2 Feb 2018 20:58:20 +0000 Subject: [PATCH 070/161] aarch64: add sve_context struct and related defines from linux v4.15 signal context definitions for scalable vector extension new in commit d0b8cd3187889476144bd9b13bf36a932c3e7952 --- arch/aarch64/bits/signal.h | 39 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/arch/aarch64/bits/signal.h b/arch/aarch64/bits/signal.h index 1c67313d..b71261f5 100644 --- a/arch/aarch64/bits/signal.h +++ b/arch/aarch64/bits/signal.h @@ -25,6 +25,7 @@ typedef struct sigcontext { #define FPSIMD_MAGIC 0x46508001 #define ESR_MAGIC 0x45535201 #define EXTRA_MAGIC 0x45585401 +#define SVE_MAGIC 0x53564501 struct _aarch64_ctx { unsigned int magic; unsigned int size; @@ -45,6 +46,44 @@ struct extra_context { unsigned int size; unsigned int __reserved[3]; }; +struct sve_context { + struct _aarch64_ctx head; + unsigned short vl; + unsigned short __reserved[3]; +}; +#define SVE_VQ_BYTES 16 +#define SVE_VQ_MIN 1 +#define SVE_VQ_MAX 512 +#define SVE_VL_MIN (SVE_VQ_MIN * SVE_VQ_BYTES) +#define SVE_VL_MAX (SVE_VQ_MAX * SVE_VQ_BYTES) +#define SVE_NUM_ZREGS 32 +#define SVE_NUM_PREGS 16 +#define sve_vl_valid(vl) \ + ((vl) % SVE_VQ_BYTES == 0 && (vl) >= SVE_VL_MIN && (vl) <= SVE_VL_MAX) +#define sve_vq_from_vl(vl) ((vl) / SVE_VQ_BYTES) +#define sve_vl_from_vq(vq) ((vq) * SVE_VQ_BYTES) +#define SVE_SIG_ZREG_SIZE(vq) ((unsigned)(vq) * SVE_VQ_BYTES) +#define SVE_SIG_PREG_SIZE(vq) ((unsigned)(vq) * (SVE_VQ_BYTES / 8)) +#define SVE_SIG_FFR_SIZE(vq) SVE_SIG_PREG_SIZE(vq) +#define SVE_SIG_REGS_OFFSET \ + ((sizeof(struct sve_context) + (SVE_VQ_BYTES - 1)) \ + / SVE_VQ_BYTES * SVE_VQ_BYTES) +#define SVE_SIG_ZREGS_OFFSET SVE_SIG_REGS_OFFSET +#define SVE_SIG_ZREG_OFFSET(vq, n) \ + (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREG_SIZE(vq) * (n)) +#define SVE_SIG_ZREGS_SIZE(vq) \ + (SVE_SIG_ZREG_OFFSET(vq, SVE_NUM_ZREGS) - SVE_SIG_ZREGS_OFFSET) +#define SVE_SIG_PREGS_OFFSET(vq) \ + (SVE_SIG_ZREGS_OFFSET + SVE_SIG_ZREGS_SIZE(vq)) +#define SVE_SIG_PREG_OFFSET(vq, n) \ + (SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREG_SIZE(vq) * (n)) +#define SVE_SIG_PREGS_SIZE(vq) \ + (SVE_SIG_PREG_OFFSET(vq, SVE_NUM_PREGS) - SVE_SIG_PREGS_OFFSET(vq)) +#define SVE_SIG_FFR_OFFSET(vq) \ + (SVE_SIG_PREGS_OFFSET(vq) + SVE_SIG_PREGS_SIZE(vq)) +#define SVE_SIG_REGS_SIZE(vq) \ + (SVE_SIG_FFR_OFFSET(vq) + SVE_SIG_FFR_SIZE(vq) - SVE_SIG_REGS_OFFSET) +#define SVE_SIG_CONTEXT_SIZE(vq) (SVE_SIG_REGS_OFFSET + SVE_SIG_REGS_SIZE(vq)) #else typedef struct { long double __regs[18+256]; From e20658209177667e490c661dfd35b976749ef3f7 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Sat, 6 Jan 2018 23:08:09 +0100 Subject: [PATCH 071/161] add getrandom syscall wrapper This syscall is available since Linux 3.17 and was also implemented in glibc in version 2.25 using the same interfaces. --- include/sys/random.h | 19 +++++++++++++++++++ src/linux/getrandom.c | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 include/sys/random.h create mode 100644 src/linux/getrandom.c diff --git a/include/sys/random.h b/include/sys/random.h new file mode 100644 index 00000000..4ee7bf2c --- /dev/null +++ b/include/sys/random.h @@ -0,0 +1,19 @@ +#ifndef _SYS_RANDOM_H +#define _SYS_RANDOM_H +#ifdef __cplusplus +extern "C" { +#endif + +#define __NEED_size_t +#define __NEED_ssize_t +#include + +#define GRND_NONBLOCK 0x0001 +#define GRND_RANDOM 0x0002 + +ssize_t getrandom(void *, size_t, unsigned); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/linux/getrandom.c b/src/linux/getrandom.c new file mode 100644 index 00000000..6cc6f6b0 --- /dev/null +++ b/src/linux/getrandom.c @@ -0,0 +1,7 @@ +#include +#include "syscall.h" + +ssize_t getrandom(void *buf, size_t buflen, unsigned flags) +{ + return syscall_cp(SYS_getrandom, buf, buflen, flags); +} From 82f176803ae07e34229906d5c7c62889e665dc97 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 23 Feb 2018 02:54:01 -0500 Subject: [PATCH 072/161] add getentropy function based loosely on patch by Hauke Mehrtens; converted to wrap the public API of the underlying getrandom function rather than direct syscalls, so that if/when a fallback implementation of getrandom is added it will automatically get picked up by getentropy too. --- include/unistd.h | 1 + src/misc/getentropy.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/misc/getentropy.c diff --git a/include/unistd.h b/include/unistd.h index 09190af4..c17eace9 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -176,6 +176,7 @@ int acct(const char *); long syscall(long, ...); int execvpe(const char *, char *const [], char *const []); int issetugid(void); +int getentropy(void *, size_t); #endif #ifdef _GNU_SOURCE diff --git a/src/misc/getentropy.c b/src/misc/getentropy.c new file mode 100644 index 00000000..4c61ae26 --- /dev/null +++ b/src/misc/getentropy.c @@ -0,0 +1,31 @@ +#include +#include +#include + +int getentropy(void *buffer, size_t len) +{ + int cs, ret; + char *pos = buffer; + + if (len > 256) { + errno = EIO; + return -1; + } + + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); + + while (len) { + ret = getrandom(pos, len, 0); + if (ret < 0) { + if (errno == EINTR) continue; + else break; + } + pos += ret; + len -= ret; + ret = 0; + } + + pthread_setcancelstate(cs, 0); + + return ret; +} From b123f2395266a44176e49cee251fb776e97f26e1 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Feb 2018 10:26:26 -0500 Subject: [PATCH 073/161] fix getopt wrongly treating colons in optstring as valid option chars the ':' in optstring has special meaning as a flag applying to the previous option character, or to getopt's error handling behavior when it appears at the beginning. don't also accept a "-:" option based on its presence. --- src/misc/getopt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/misc/getopt.c b/src/misc/getopt.c index e9bab41c..e921a60e 100644 --- a/src/misc/getopt.c +++ b/src/misc/getopt.c @@ -77,7 +77,7 @@ int getopt(int argc, char * const argv[], const char *optstring) if (l>0) i+=l; else i++; } while (l && d != c); - if (d != c) { + if (d != c || c == ':') { optopt = c; if (optstring[0] != ':' && opterr) __getopt_msg(argv[0], ": unrecognized option: ", optchar, k); From 9bf9c732f9d39d691e1f8841e7204c9c26321946 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Feb 2018 10:43:13 -0500 Subject: [PATCH 074/161] remove obfuscated flags bit-twiddling logic in __stdio_read replace with simple conditional that doesn't rely on assumption that cnt is either 0 or -1. --- src/stdio/__stdio_read.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c index f8fa6d3b..af50508c 100644 --- a/src/stdio/__stdio_read.c +++ b/src/stdio/__stdio_read.c @@ -11,7 +11,7 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) cnt = syscall(SYS_readv, f->fd, iov, 2); if (cnt <= 0) { - f->flags |= F_EOF ^ ((F_ERR^F_EOF) & cnt); + f->flags |= cnt ? F_ERR : F_EOF; return cnt; } if (cnt <= iov[0].iov_len) return cnt; From f92804188eb464536d638548e51e835b6c49e373 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Feb 2018 10:51:16 -0500 Subject: [PATCH 075/161] consistently return number of bytes read from stdio read backend the stdio FILE read backend's return type is size_t, not ssize_t, and all of the special (non-fd-backed) FILE types already return the number of bytes read (zero) on error or eof. only __stdio_read leaked a syscall error return into its return value. fread had a workaround for this behavior going all the way back to the original check-in. remove the workaround since it's no longer needed. --- src/stdio/__stdio_read.c | 2 +- src/stdio/fread.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c index af50508c..909c36a9 100644 --- a/src/stdio/__stdio_read.c +++ b/src/stdio/__stdio_read.c @@ -12,7 +12,7 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) cnt = syscall(SYS_readv, f->fd, iov, 2); if (cnt <= 0) { f->flags |= cnt ? F_ERR : F_EOF; - return cnt; + return 0; } if (cnt <= iov[0].iov_len) return cnt; cnt -= iov[0].iov_len; diff --git a/src/stdio/fread.c b/src/stdio/fread.c index aef75f73..733d3716 100644 --- a/src/stdio/fread.c +++ b/src/stdio/fread.c @@ -25,7 +25,7 @@ size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f) /* Read the remainder directly */ for (; l; l-=k, dest+=k) { k = __toread(f) ? 0 : f->read(f, dest, l); - if (k+1<=1) { + if (!k) { FUNLOCK(f); return (len-l)/size; } From e7eeeb9f2a4a358fb0bbed81e145ef5538ff60f0 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Feb 2018 11:19:54 -0500 Subject: [PATCH 076/161] avoid use of readv syscall in __stdio_read backend when not needed formally, calling readv with a zero-length first iov component should behave identically to calling read on just the second component, but presence of a zero-length iov component has triggered bugs in some kernels and performs significantly worse than a simple read on some file types. --- src/stdio/__stdio_read.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stdio/__stdio_read.c b/src/stdio/__stdio_read.c index 909c36a9..ea675da3 100644 --- a/src/stdio/__stdio_read.c +++ b/src/stdio/__stdio_read.c @@ -9,7 +9,8 @@ size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) }; ssize_t cnt; - cnt = syscall(SYS_readv, f->fd, iov, 2); + cnt = iov[0].iov_len ? syscall(SYS_readv, f->fd, iov, 2) + : syscall(SYS_read, f->fd, iov[1].iov_base, iov[1].iov_len); if (cnt <= 0) { f->flags |= cnt ? F_ERR : F_EOF; return 0; From 52d42b5888c79fd30d7c16c59941f5ef87f745ad Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Feb 2018 11:33:18 -0500 Subject: [PATCH 077/161] remove useless and confusing parentheses in stdio __towrite function they seem to be relics of e3cd6c5c265cd481db6e0c5b529855d99f0bda30 where this code was refactored from a check that previously masked against (F_ERR|F_NOWR) instead of just F_NOWR. --- src/stdio/__towrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdio/__towrite.c b/src/stdio/__towrite.c index 0a69d926..b022cbca 100644 --- a/src/stdio/__towrite.c +++ b/src/stdio/__towrite.c @@ -3,7 +3,7 @@ int __towrite(FILE *f) { f->mode |= f->mode-1; - if (f->flags & (F_NOWR)) { + if (f->flags & F_NOWR) { f->flags |= F_ERR; return EOF; } From 0fbe53ed3fc0a4f0e3c8c778b3a409e48ed8bea3 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Feb 2018 11:36:00 -0500 Subject: [PATCH 078/161] remove useless null check before call to free in fclose --- src/stdio/fclose.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdio/fclose.c b/src/stdio/fclose.c index d687a877..c675413d 100644 --- a/src/stdio/fclose.c +++ b/src/stdio/fclose.c @@ -24,7 +24,7 @@ int fclose(FILE *f) r = fflush(f); r |= f->close(f); - if (f->getln_buf) free(f->getln_buf); + free(f->getln_buf); if (!perm) free(f); else FUNLOCK(f); From aaa29c26eed4a09625e61c6af31d16b1a4163fc3 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Feb 2018 11:38:53 -0500 Subject: [PATCH 079/161] remove unused MIN macro from getdelim source file --- src/stdio/getdelim.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/stdio/getdelim.c b/src/stdio/getdelim.c index 1ccd8029..d4b23882 100644 --- a/src/stdio/getdelim.c +++ b/src/stdio/getdelim.c @@ -3,8 +3,6 @@ #include #include -#define MIN(a,b) ((a)<(b) ? (a) : (b)) - ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restrict f) { char *tmp; From 7c59d098632e4382c9b674b189edbfd80d327682 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Feb 2018 12:08:30 -0500 Subject: [PATCH 080/161] in vswprintf, initialize the FILE rather than memset-and-assign this is the idiom that's used elsewhere and should be more efficient or at least no worse. --- src/stdio/vswprintf.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/stdio/vswprintf.c b/src/stdio/vswprintf.c index 6eb2f6ac..38efed65 100644 --- a/src/stdio/vswprintf.c +++ b/src/stdio/vswprintf.c @@ -1,6 +1,5 @@ #include "stdio_impl.h" #include -#include #include #include #include @@ -37,17 +36,17 @@ static size_t sw_write(FILE *f, const unsigned char *s, size_t l) int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_list ap) { int r; - FILE f; unsigned char buf[256]; struct cookie c = { s, n-1 }; + FILE f = { + .lbf = EOF, + .write = sw_write, + .lock = -1, + .buf = buf, + .buf_size = sizeof buf, + .cookie = &c, + }; - memset(&f, 0, sizeof(FILE)); - f.lbf = EOF; - f.write = sw_write; - f.buf_size = sizeof buf; - f.buf = buf; - f.lock = -1; - f.cookie = &c; if (!n) { return -1; } else if (n > INT_MAX) { From 455bd824457b3e6cc3998817aac4e500b027cc50 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Feb 2018 12:33:06 -0500 Subject: [PATCH 081/161] use idiomatic safe form for FUNLOCK macro previously this macro used an odd if/else form instead of the more idiomatic do/while(0), making it unsafe against omission of trailing semicolon. the omission would make the following statement conditional instead of producing an error. --- src/internal/stdio_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/stdio_impl.h b/src/internal/stdio_impl.h index 7cdf729d..1127a492 100644 --- a/src/internal/stdio_impl.h +++ b/src/internal/stdio_impl.h @@ -9,7 +9,7 @@ #define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0) #define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0) -#define FUNLOCK(f) if (__need_unlock) __unlockfile((f)); else +#define FUNLOCK(f) do { if (__need_unlock) __unlockfile((f)); } while (0) #define F_PERM 1 #define F_NORD 4 From 2fae10f887b48b809bac56e4ff8a5c3fd4525de3 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Feb 2018 16:45:33 -0500 Subject: [PATCH 082/161] fix aliasing violations in fgetpos/fsetpos add a member of appropriate type to the fpos_t union so that accesses are well-defined. use long long instead of off_t since off_t is not always exposed in stdio.h and there's no namespace-clean alias for it. access is still performed using pointer casts rather than by naming the union member as a matter of style; to the extent possible, the naming of fields in opaque types defined in the public headers is not treated as an API contract with the implementation. access via the pointer cast is valid as long as the union has a member of matching type. --- include/stdio.h | 1 + src/stdio/fgetpos.c | 2 +- src/stdio/fsetpos.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/stdio.h b/include/stdio.h index 7c4f9ee4..afadd912 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -49,6 +49,7 @@ extern "C" { typedef union _G_fpos64_t { char __opaque[16]; + long long __lldata; double __align; } fpos_t; diff --git a/src/stdio/fgetpos.c b/src/stdio/fgetpos.c index c3fa0eb0..6eb361e1 100644 --- a/src/stdio/fgetpos.c +++ b/src/stdio/fgetpos.c @@ -4,7 +4,7 @@ int fgetpos(FILE *restrict f, fpos_t *restrict pos) { off_t off = __ftello(f); if (off < 0) return -1; - *(off_t *)pos = off; + *(long long *)pos = off; return 0; } diff --git a/src/stdio/fsetpos.c b/src/stdio/fsetpos.c index 5d76c8cd..6310424e 100644 --- a/src/stdio/fsetpos.c +++ b/src/stdio/fsetpos.c @@ -2,7 +2,7 @@ int fsetpos(FILE *f, const fpos_t *pos) { - return __fseeko(f, *(const off_t *)pos, SEEK_SET); + return __fseeko(f, *(const long long *)pos, SEEK_SET); } LFS64(fsetpos); From 57b97b42bdecafd81c4967a10aef6eaf43d3fcb8 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sun, 25 Feb 2018 21:13:38 -0500 Subject: [PATCH 083/161] add public interface headers to implementation files general policy is that all source files defining a public API or an ABI mechanism referenced by a public header should include the public header that declares the interface, so that the compiler or analysis tools can check the consistency of the declarations. Alexander Monakov pointed out a number of violations of this principle a few years back. fix them now. --- src/errno/__errno_location.c | 1 + src/misc/gethostid.c | 2 ++ src/signal/sigrtmin.c | 2 ++ src/stdlib/abs.c | 2 ++ src/stdlib/labs.c | 2 ++ src/stdlib/llabs.c | 2 ++ 6 files changed, 11 insertions(+) diff --git a/src/errno/__errno_location.c b/src/errno/__errno_location.c index 7172a1be..ad9f9241 100644 --- a/src/errno/__errno_location.c +++ b/src/errno/__errno_location.c @@ -1,3 +1,4 @@ +#include #include "pthread_impl.h" int *__errno_location(void) diff --git a/src/misc/gethostid.c b/src/misc/gethostid.c index ea65611a..25bb35db 100644 --- a/src/misc/gethostid.c +++ b/src/misc/gethostid.c @@ -1,3 +1,5 @@ +#include + long gethostid() { return 0; diff --git a/src/signal/sigrtmin.c b/src/signal/sigrtmin.c index d0e769bb..c5a1fd92 100644 --- a/src/signal/sigrtmin.c +++ b/src/signal/sigrtmin.c @@ -1,3 +1,5 @@ +#include + int __libc_current_sigrtmin() { return 35; diff --git a/src/stdlib/abs.c b/src/stdlib/abs.c index 4806d629..e721fdc2 100644 --- a/src/stdlib/abs.c +++ b/src/stdlib/abs.c @@ -1,3 +1,5 @@ +#include + int abs(int a) { return a>0 ? a : -a; diff --git a/src/stdlib/labs.c b/src/stdlib/labs.c index 675b95b8..83ddb147 100644 --- a/src/stdlib/labs.c +++ b/src/stdlib/labs.c @@ -1,3 +1,5 @@ +#include + long labs(long a) { return a>0 ? a : -a; diff --git a/src/stdlib/llabs.c b/src/stdlib/llabs.c index bec4a03d..9dfaf5cf 100644 --- a/src/stdlib/llabs.c +++ b/src/stdlib/llabs.c @@ -1,3 +1,5 @@ +#include + long long llabs(long long a) { return a>0 ? a : -a; From 0cf50581ec5f04feeaa77f2eb8b734a4b69ca8ed Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 7 Mar 2018 11:22:38 -0500 Subject: [PATCH 084/161] fix nl_langinfo_l(CODESET, loc) reporting wrong locale's value use of MB_CUR_MAX encoded a hidden dependency on the currently active locale for the calling thread, whereas nl_langinfo_l is supposed to report for the locale passed as an argument. --- src/locale/langinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/locale/langinfo.c b/src/locale/langinfo.c index b16caf44..83be6433 100644 --- a/src/locale/langinfo.c +++ b/src/locale/langinfo.c @@ -33,7 +33,7 @@ char *__nl_langinfo_l(nl_item item, locale_t loc) int idx = item & 65535; const char *str; - if (item == CODESET) return MB_CUR_MAX==1 ? "ASCII" : "UTF-8"; + if (item == CODESET) return loc->cat[LC_CTYPE] ? "UTF-8" : "ASCII"; /* _NL_LOCALE_NAME extension */ if (idx == 65535 && cat < LC_ALL) From c9c2cd3e6955cb1d57b8be01d4b072bf44058762 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 10 Mar 2018 17:47:14 -0500 Subject: [PATCH 085/161] reverse definition dependency between PAGESIZE and PAGE_SIZE PAGESIZE is actually the version defined in POSIX base, with PAGE_SIZE being in the XSI option. use PAGESIZE as the underlying definition to facilitate making exposure of PAGE_SIZE conditional. --- arch/i386/bits/limits.h | 2 +- arch/or1k/bits/limits.h | 2 +- arch/s390x/bits/limits.h | 2 +- arch/sh/bits/limits.h | 2 +- arch/x32/bits/limits.h | 2 +- arch/x86_64/bits/limits.h | 2 +- include/limits.h | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/i386/bits/limits.h b/arch/i386/bits/limits.h index 65a3dd64..c340ceb2 100644 --- a/arch/i386/bits/limits.h +++ b/arch/i386/bits/limits.h @@ -1,6 +1,6 @@ #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define PAGE_SIZE 4096 +#define PAGESIZE 4096 #define LONG_BIT 32 #endif diff --git a/arch/or1k/bits/limits.h b/arch/or1k/bits/limits.h index 483b6749..3a811c99 100644 --- a/arch/or1k/bits/limits.h +++ b/arch/or1k/bits/limits.h @@ -1,6 +1,6 @@ #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define PAGE_SIZE 8192 +#define PAGESIZE 8192 #define LONG_BIT 32 #endif diff --git a/arch/s390x/bits/limits.h b/arch/s390x/bits/limits.h index 792a30b9..86ef7663 100644 --- a/arch/s390x/bits/limits.h +++ b/arch/s390x/bits/limits.h @@ -1,6 +1,6 @@ #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define PAGE_SIZE 4096 +#define PAGESIZE 4096 #define LONG_BIT 64 #endif diff --git a/arch/sh/bits/limits.h b/arch/sh/bits/limits.h index 65a3dd64..c340ceb2 100644 --- a/arch/sh/bits/limits.h +++ b/arch/sh/bits/limits.h @@ -1,6 +1,6 @@ #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define PAGE_SIZE 4096 +#define PAGESIZE 4096 #define LONG_BIT 32 #endif diff --git a/arch/x32/bits/limits.h b/arch/x32/bits/limits.h index 65a3dd64..c340ceb2 100644 --- a/arch/x32/bits/limits.h +++ b/arch/x32/bits/limits.h @@ -1,6 +1,6 @@ #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define PAGE_SIZE 4096 +#define PAGESIZE 4096 #define LONG_BIT 32 #endif diff --git a/arch/x86_64/bits/limits.h b/arch/x86_64/bits/limits.h index 792a30b9..86ef7663 100644 --- a/arch/x86_64/bits/limits.h +++ b/arch/x86_64/bits/limits.h @@ -1,6 +1,6 @@ #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define PAGE_SIZE 4096 +#define PAGESIZE 4096 #define LONG_BIT 64 #endif diff --git a/include/limits.h b/include/limits.h index f9805a1e..3e476093 100644 --- a/include/limits.h +++ b/include/limits.h @@ -40,8 +40,8 @@ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #define PIPE_BUF 4096 -#ifdef PAGE_SIZE -#define PAGESIZE PAGE_SIZE +#ifdef PAGESIZE +#define PAGE_SIZE PAGESIZE #endif #define FILESIZEBITS 64 #define NAME_MAX 255 From 6ecb9c14c429cc73ace937fd7459f58f0b7a8e6e Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 10 Mar 2018 17:49:23 -0500 Subject: [PATCH 086/161] use PAGESIZE rather than PAGE_SIZE in user.h bits align with commit c9c2cd3e6955cb1d57b8be01d4b072bf44058762. --- arch/i386/bits/user.h | 4 ++-- arch/s390x/bits/user.h | 4 ++-- arch/x32/bits/user.h | 4 ++-- arch/x86_64/bits/user.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/i386/bits/user.h b/arch/i386/bits/user.h index 0e343930..33fea986 100644 --- a/arch/i386/bits/user.h +++ b/arch/i386/bits/user.h @@ -37,8 +37,8 @@ struct user { int u_debugreg[8]; }; -#define PAGE_MASK (~(PAGE_SIZE-1)) -#define NBPG PAGE_SIZE +#define PAGE_MASK (~(PAGESIZE-1)) +#define NBPG PAGESIZE #define UPAGES 1 #define HOST_TEXT_START_ADDR (u.start_code) #define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) diff --git a/arch/s390x/bits/user.h b/arch/s390x/bits/user.h index 17bce16f..ff3f0483 100644 --- a/arch/s390x/bits/user.h +++ b/arch/s390x/bits/user.h @@ -54,8 +54,8 @@ struct user { char u_comm[32]; }; -#define PAGE_MASK (~(PAGE_SIZE-1)) -#define NBPG PAGE_SIZE +#define PAGE_MASK (~(PAGESIZE-1)) +#define NBPG PAGESIZE #define UPAGES 1 #define HOST_TEXT_START_ADDR (u.start_code) #define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) diff --git a/arch/x32/bits/user.h b/arch/x32/bits/user.h index 471bb19d..4073cc06 100644 --- a/arch/x32/bits/user.h +++ b/arch/x32/bits/user.h @@ -34,8 +34,8 @@ struct user { unsigned long u_debugreg[8]; }; -#define PAGE_MASK (~(PAGE_SIZE-1)) -#define NBPG PAGE_SIZE +#define PAGE_MASK (~(PAGESIZE-1)) +#define NBPG PAGESIZE #define UPAGES 1 #define HOST_TEXT_START_ADDR (u.start_code) #define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) diff --git a/arch/x86_64/bits/user.h b/arch/x86_64/bits/user.h index 471bb19d..4073cc06 100644 --- a/arch/x86_64/bits/user.h +++ b/arch/x86_64/bits/user.h @@ -34,8 +34,8 @@ struct user { unsigned long u_debugreg[8]; }; -#define PAGE_MASK (~(PAGE_SIZE-1)) -#define NBPG PAGE_SIZE +#define PAGE_MASK (~(PAGESIZE-1)) +#define NBPG PAGESIZE #define UPAGES 1 #define HOST_TEXT_START_ADDR (u.start_code) #define HOST_STACK_END_ADDR (u.start_stack + u.u_ssize * NBPG) From 8e1381be44642523b5cbd1bba4d7ca20ee920b85 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 10 Mar 2018 17:53:27 -0500 Subject: [PATCH 087/161] fix minor namespace issues in limits.h PAGE_SIZE, NZERO, and NL_LANGMAX are XSI-shaded. --- include/limits.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/include/limits.h b/include/limits.h index 3e476093..9cb5426f 100644 --- a/include/limits.h +++ b/include/limits.h @@ -40,14 +40,10 @@ || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #define PIPE_BUF 4096 -#ifdef PAGESIZE -#define PAGE_SIZE PAGESIZE -#endif #define FILESIZEBITS 64 #define NAME_MAX 255 #define SYMLINK_MAX 255 #define PATH_MAX 4096 -#define NZERO 20 #define NGROUPS_MAX 32 #define ARG_MAX 131072 #define IOV_MAX 1024 @@ -82,13 +78,22 @@ #define RE_DUP_MAX 255 #define NL_ARGMAX 9 -#define NL_LANGMAX 32 #define NL_MSGMAX 32767 #define NL_SETMAX 255 #define NL_TEXTMAX 2048 #endif +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) + +#ifdef PAGESIZE +#define PAGE_SIZE PAGESIZE +#endif +#define NZERO 20 +#define NL_LANGMAX 32 + +#endif + #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) From d93c0740d86aaf7043e79b942a6c0b3f576af4c8 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 10 Mar 2018 17:57:44 -0500 Subject: [PATCH 088/161] fix minor namespace issue in tar.h TSVTX is XSI-shaded. --- include/tar.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/tar.h b/include/tar.h index be589842..b3c4ba24 100644 --- a/include/tar.h +++ b/include/tar.h @@ -3,7 +3,9 @@ #define TSUID 04000 #define TSGID 02000 +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) #define TSVTX 01000 +#endif #define TUREAD 00400 #define TUWRITE 00200 #define TUEXEC 00100 From a3f7bcdeaa4cbf8258824b6be4f231ca54a7fdfc Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 10 Mar 2018 18:02:05 -0500 Subject: [PATCH 089/161] fix minor namespace issue in unistd.h the F_* macros associated with the lockf function are XSI-shaded (like the lockf function itself) and should only be exposed when the function is. --- include/unistd.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/unistd.h b/include/unistd.h index c17eace9..9485da7a 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -128,12 +128,11 @@ long fpathconf(int, int); long sysconf(int); size_t confstr(int, char *, size_t); +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #define F_ULOCK 0 #define F_LOCK 1 #define F_TLOCK 2 #define F_TEST 3 - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) int setreuid(uid_t, uid_t); int setregid(gid_t, gid_t); int lockf(int, int, off_t); From f9c2498fee1c94adf00e788863d2d4544d1d1ec0 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 10 Mar 2018 18:03:17 -0500 Subject: [PATCH 090/161] remove spurious const keyword in sigqueue declaration this must have been taken from POSIX without realizing that it was meaningless. the resolution to Austin Group issue #844 removed it from the standard. --- include/signal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/signal.h b/include/signal.h index 4001ff49..a4f85cca 100644 --- a/include/signal.h +++ b/include/signal.h @@ -210,7 +210,7 @@ int sigpending(sigset_t *); int sigwait(const sigset_t *__restrict, int *__restrict); int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); -int sigqueue(pid_t, int, const union sigval); +int sigqueue(pid_t, int, union sigval); int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); int pthread_kill(pthread_t, int); From eb5ae94016f0e3e4fb7d0715346b09335f14655d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 10 Mar 2018 18:08:02 -0500 Subject: [PATCH 091/161] fix minor namespace issues in termios.h the output delay features (NL*, CR*, TAB*, BS*, and VT*) are XSI-shaded. VT* is in the V* namespace reservation but the rest need to be suppressed in base POSIX namespace. unfortunately this change introduces feature test macro checks into another bits header. at some point these checks should be simplified by having features.h handle the "FTM X implies Y" relationships. --- arch/generic/bits/termios.h | 2 ++ arch/mips/bits/termios.h | 2 ++ arch/mips64/bits/termios.h | 2 ++ arch/mipsn32/bits/termios.h | 2 ++ arch/powerpc/bits/termios.h | 2 ++ arch/powerpc64/bits/termios.h | 2 ++ 6 files changed, 12 insertions(+) diff --git a/arch/generic/bits/termios.h b/arch/generic/bits/termios.h index 434c02c8..124f71d2 100644 --- a/arch/generic/bits/termios.h +++ b/arch/generic/bits/termios.h @@ -51,6 +51,7 @@ struct termios { #define ONLRET 0000040 #define OFILL 0000100 #define OFDEL 0000200 +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) #define NLDLY 0000400 #define NL0 0000000 #define NL1 0000400 @@ -70,6 +71,7 @@ struct termios { #define FFDLY 0100000 #define FF0 0000000 #define FF1 0100000 +#endif #define VTDLY 0040000 #define VT0 0000000 diff --git a/arch/mips/bits/termios.h b/arch/mips/bits/termios.h index 692e58be..f7b9dd2e 100644 --- a/arch/mips/bits/termios.h +++ b/arch/mips/bits/termios.h @@ -52,6 +52,7 @@ struct termios { #define ONLRET 0000040 #define OFILL 0000100 #define OFDEL 0000200 +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) #define NLDLY 0000400 #define NL0 0000000 #define NL1 0000400 @@ -71,6 +72,7 @@ struct termios { #define FFDLY 0100000 #define FF0 0000000 #define FF1 0100000 +#endif #define VTDLY 0040000 #define VT0 0000000 diff --git a/arch/mips64/bits/termios.h b/arch/mips64/bits/termios.h index 692e58be..f7b9dd2e 100644 --- a/arch/mips64/bits/termios.h +++ b/arch/mips64/bits/termios.h @@ -52,6 +52,7 @@ struct termios { #define ONLRET 0000040 #define OFILL 0000100 #define OFDEL 0000200 +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) #define NLDLY 0000400 #define NL0 0000000 #define NL1 0000400 @@ -71,6 +72,7 @@ struct termios { #define FFDLY 0100000 #define FF0 0000000 #define FF1 0100000 +#endif #define VTDLY 0040000 #define VT0 0000000 diff --git a/arch/mipsn32/bits/termios.h b/arch/mipsn32/bits/termios.h index 692e58be..f7b9dd2e 100644 --- a/arch/mipsn32/bits/termios.h +++ b/arch/mipsn32/bits/termios.h @@ -52,6 +52,7 @@ struct termios { #define ONLRET 0000040 #define OFILL 0000100 #define OFDEL 0000200 +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) #define NLDLY 0000400 #define NL0 0000000 #define NL1 0000400 @@ -71,6 +72,7 @@ struct termios { #define FFDLY 0100000 #define FF0 0000000 #define FF1 0100000 +#endif #define VTDLY 0040000 #define VT0 0000000 diff --git a/arch/powerpc/bits/termios.h b/arch/powerpc/bits/termios.h index 5c2f6bfb..e3f22e86 100644 --- a/arch/powerpc/bits/termios.h +++ b/arch/powerpc/bits/termios.h @@ -53,6 +53,7 @@ struct termios { #define ONLRET 0000040 #define OFILL 0000100 #define OFDEL 0000200 +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) #define NLDLY 0001400 #define NL0 0000000 #define NL1 0000400 @@ -74,6 +75,7 @@ struct termios { #define BSDLY 0100000 #define BS0 0000000 #define BS1 0100000 +#endif #define VTDLY 0200000 #define VT0 0000000 diff --git a/arch/powerpc64/bits/termios.h b/arch/powerpc64/bits/termios.h index 5c2f6bfb..e3f22e86 100644 --- a/arch/powerpc64/bits/termios.h +++ b/arch/powerpc64/bits/termios.h @@ -53,6 +53,7 @@ struct termios { #define ONLRET 0000040 #define OFILL 0000100 #define OFDEL 0000200 +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) #define NLDLY 0001400 #define NL0 0000000 #define NL1 0000400 @@ -74,6 +75,7 @@ struct termios { #define BSDLY 0100000 #define BS0 0000000 #define BS1 0100000 +#endif #define VTDLY 0200000 #define VT0 0000000 From 919ad8d5fbb1caa18c3719304ffeeb0e0dde1bb5 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 10 Mar 2018 20:45:49 -0500 Subject: [PATCH 092/161] explicitly use signed keyword to define intNN_t and derivative types standing alone, both the signed and int keywords identify the same type, a (signed) int. however the C language has an exception where, when the lone keyword int is used to declare a bitfield, it's implementation-defined whether the bitfield is signed or unsigned. C11 footnote 125 extends this implementation-definedness to typedefs, and DR#315 extends it to other integer types (for which support with bitfields is implementation-defined). while reasonable ABIs (all the ones we support) define bitfields as signed by default, GCC and compatible compilers offer an option -funsigned-bitfields to change the default. while any signed types defined without explicit use of the signed keyword are affected, the stdint.h types, especially intNN_t, have a natural use in bitfields. ensure that bitfields defined with these types always have the correct signedness regardless of compiler & flags used. see also GCC PR 83294. --- include/alltypes.h.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/alltypes.h.in b/include/alltypes.h.in index 6a9c105f..622ca01d 100644 --- a/include/alltypes.h.in +++ b/include/alltypes.h.in @@ -7,10 +7,10 @@ TYPEDEF _Addr regoff_t; TYPEDEF _Reg register_t; TYPEDEF signed char int8_t; -TYPEDEF short int16_t; -TYPEDEF int int32_t; -TYPEDEF _Int64 int64_t; -TYPEDEF _Int64 intmax_t; +TYPEDEF signed short int16_t; +TYPEDEF signed int int32_t; +TYPEDEF signed _Int64 int64_t; +TYPEDEF signed _Int64 intmax_t; TYPEDEF unsigned char uint8_t; TYPEDEF unsigned short uint16_t; TYPEDEF unsigned int uint32_t; From a7c53e0c2cd8fc45eac90c0468e44697019ceda6 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Mar 2018 12:15:43 -0400 Subject: [PATCH 093/161] fix out-of-tree build of crt files with stack protector enabled the makefile logic for these files was wrong in the out-of-tree case, but it likely only affected the "all" level of stack protector. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 308ddaae..46fc91ec 100644 --- a/Makefile +++ b/Makefile @@ -119,7 +119,7 @@ $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.lo): MEMOPS_SRCS = src/string/memcpy.c src/string/memmove.c src/string/memcmp.c src/string/memset.c $(MEMOPS_SRCS:%.c=obj/%.o) $(MEMOPS_SRCS:%.c=obj/%.lo): CFLAGS_ALL += $(CFLAGS_MEMOPS) -NOSSP_SRCS = $(wildcard crt/*.c) \ +NOSSP_SRCS = $(patsubst $(srcdir)/%,%,$(wildcard $(srcdir)/crt/*.c)) \ src/env/__libc_start_main.c src/env/__init_tls.c \ src/env/__stack_chk_fail.c \ src/thread/__set_thread_area.c src/thread/$(ARCH)/__set_thread_area.c \ From c7bb9c41d2e62b7ad1c7858d4d0f2873642e634b Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 24 Mar 2018 22:47:36 -0400 Subject: [PATCH 094/161] adjust makefile target-specific CFLAGS rules to be more robust & complete previously, MEMOPS_SRCS failed to include arch-specific replacement files for memcpy, etc., omitting CFLAGS_MEMOPS and thereby potentially causing build failure if an arch provided C (rather than asm) replacements for these files. instead of trying to explicitly include all the files that might have arch replacements, which is prone to human error, extract final names to be used out of $(LIBC_OBJS), where the rules for arch replacements have already been applied. do the same for NOSSP_OBJS, using CRT_OBJS and LDSO_OBJS rather than repeating ourselves with $(wildcard...) and explicit pathnames again. --- Makefile | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 46fc91ec..e23a8332 100644 --- a/Makefile +++ b/Makefile @@ -116,17 +116,14 @@ obj/crt/Scrt1.o obj/crt/rcrt1.o: CFLAGS_ALL += -fPIC OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(srcdir)/src/%)) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.lo): CFLAGS += -O3 -MEMOPS_SRCS = src/string/memcpy.c src/string/memmove.c src/string/memcmp.c src/string/memset.c -$(MEMOPS_SRCS:%.c=obj/%.o) $(MEMOPS_SRCS:%.c=obj/%.lo): CFLAGS_ALL += $(CFLAGS_MEMOPS) +MEMOPS_OBJS = $(filter %/memcpy.o %/memmove.o %/memcmp.o %/memset.o, $(LIBC_OBJS)) +$(MEMOPS_OBJS) $(MEMOPS_OBJS:%.o=%.lo): CFLAGS_ALL += $(CFLAGS_MEMOPS) -NOSSP_SRCS = $(patsubst $(srcdir)/%,%,$(wildcard $(srcdir)/crt/*.c)) \ - src/env/__libc_start_main.c src/env/__init_tls.c \ - src/env/__stack_chk_fail.c \ - src/thread/__set_thread_area.c src/thread/$(ARCH)/__set_thread_area.c \ - src/string/memset.c src/string/$(ARCH)/memset.c \ - src/string/memcpy.c src/string/$(ARCH)/memcpy.c \ - ldso/dlstart.c ldso/dynlink.c -$(NOSSP_SRCS:%.c=obj/%.o) $(NOSSP_SRCS:%.c=obj/%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP) +NOSSP_OBJS = $(CRT_OBJS) $(LDSO_OBJS) $(filter \ + %/__libc_start_main.o %/__init_tls.o %/__stack_chk_fail.o \ + %/__set_thread_area.o %/memset.o %/memcpy.o \ + , $(LIBC_OBJS)) +$(NOSSP_OBJS) $(NOSSP_OBJS:%.o=%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP) $(CRT_OBJS): CFLAGS_ALL += -DCRT From 729fef0a9358e2f6f1cd8c75a1a0f7ee48b08c95 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 28 Mar 2018 15:53:45 -0400 Subject: [PATCH 095/161] fix default feature profile in tar.h commit d93c0740d86aaf7043e79b942a6c0b3f576af4c8 added use of feature test macros without including features.h, causing a definition that should be exposed in the default profile, TSVTX, to appear only when _XOPEN_SOURCE or higher is explicitly defined. --- include/tar.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/tar.h b/include/tar.h index b3c4ba24..2eba66ec 100644 --- a/include/tar.h +++ b/include/tar.h @@ -1,6 +1,8 @@ #ifndef _TAR_H #define _TAR_H +#include + #define TSUID 04000 #define TSGID 02000 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) From 282b1cd26649d69de038111f5876853df6ddc345 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sun, 1 Apr 2018 20:02:01 +0000 Subject: [PATCH 096/161] fix fmaf wrong result if double precision r=x*y+z is not a half way case between two single precision floats or it is an exact result then fmaf returns (float)r. however the exactness check was wrong when |x*y| < |z| and could cause incorrectly rounded result in nearest rounding mode when r is a half way case. fmaf(-0x1.26524ep-54, -0x1.cb7868p+11, 0x1.d10f5ep-29) was incorrectly rounded up to 0x1.d117ap-29 instead of 0x1.d1179ep-29. (exact result is 0x1.d1179efffffffecp-29, r is 0x1.d1179fp-29) --- src/math/fmaf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/math/fmaf.c b/src/math/fmaf.c index aa57feb6..80f5cd8a 100644 --- a/src/math/fmaf.c +++ b/src/math/fmaf.c @@ -50,7 +50,7 @@ float fmaf(float x, float y, float z) /* Common case: The double precision result is fine. */ if ((u.i & 0x1fffffff) != 0x10000000 || /* not a halfway case */ e == 0x7ff || /* NaN */ - result - xy == z || /* exact */ + (result - xy == z && result - z == xy) || /* exact */ fegetround() != FE_TONEAREST) /* not round-to-nearest */ { /* From 119bc55ba66542a1c2fb7fc1c4e6c85f46b97c57 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 5 Apr 2018 11:04:21 -0400 Subject: [PATCH 097/161] prevent bypass of guarantee that suids start with fd 0/1/2 open it was reported by Erik Bosman that poll fails without setting revents when the nfds argument exceeds the current value for RLIMIT_NOFILE, causing the subsequent open calls to be bypassed. if the rlimit is either 1 or 2, this leaves fd 0 and 1 potentially closed but openable when the application code is reached. based on a brief reading of the poll syscall documentation and code, it may be possible for poll to fail under other attacker-controlled conditions as well. if it turns out these are reasonable conditions that may happen in the real world, we may have to go back and implement fallbacks to probe each fd individually if poll fails, but for now, keep things simple and treat all poll failures as fatal. --- src/env/__libc_start_main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c index 2d758af7..0583f686 100644 --- a/src/env/__libc_start_main.c +++ b/src/env/__libc_start_main.c @@ -42,11 +42,13 @@ void __init_libc(char **envp, char *pn) && !aux[AT_SECURE]) return; struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} }; + int r = #ifdef SYS_poll __syscall(SYS_poll, pfd, 3, 0); #else __syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8); #endif + if (r<0) a_crash(); for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL) if (__sys_open("/dev/null", O_RDWR)<0) a_crash(); From ea81529fb92932a50f06bf7a19cae812ae6cdb59 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sat, 7 Apr 2018 09:47:16 -0500 Subject: [PATCH 098/161] implement wcsftime padding specifier extensions Commit 8a6bd7307da3fc4d08dd6a9277b611ccb4971354 added support for padding specifier extensions to strftime, but did not modify wcsftime. In the process, it added a parameter to __strftime_fmt_1 in strftime.c, but failed to update the prototype in wcsftime.c. This was found by compiling musl with LTO: src/time/wcsftime.c:7:13: warning: type of '__strftime_fmt_1' does \ not match original declaration [-Wlto-type-mismatch] Fix the prototype of __strftime_fmt_1 in wcsftime.c, and generate the 'pad' argument the same way as it is done in strftime. --- src/time/wcsftime.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/time/wcsftime.c b/src/time/wcsftime.c index 638e64f6..23500cc8 100644 --- a/src/time/wcsftime.c +++ b/src/time/wcsftime.c @@ -4,7 +4,7 @@ #include "locale_impl.h" #include "libc.h" -const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc); +const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc, int pad); size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, const struct tm *restrict tm, locale_t loc) { @@ -14,7 +14,7 @@ size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, co wchar_t *p; const char *t_mb; const wchar_t *t; - int plus; + int pad, plus; unsigned long width; for (l=0; l Date: Mon, 9 Apr 2018 12:33:17 -0400 Subject: [PATCH 099/161] fix wrong result in casin and many related complex functions the factor of -i noted in the comment at the top of casin.c was omitted from the actual code, yielding a result rotated 90 degrees and propagating into errors in other functions defined in terms of casin. implement multiplication by -i as a rotation of the real and imaginary parts of the result, rather than by actual multiplication, since the latter cannot be optimized without knowledge that the operand is finite. here, the rotation is the actual intent, anyway. --- src/complex/casin.c | 3 ++- src/complex/casinf.c | 3 ++- src/complex/casinl.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/complex/casin.c b/src/complex/casin.c index dfdda988..01ed6184 100644 --- a/src/complex/casin.c +++ b/src/complex/casin.c @@ -12,5 +12,6 @@ double complex casin(double complex z) x = creal(z); y = cimag(z); w = CMPLX(1.0 - (x - y)*(x + y), -2.0*x*y); - return clog(CMPLX(-y, x) + csqrt(w)); + double complex r = clog(CMPLX(-y, x) + csqrt(w)); + return CMPLX(cimag(r), -creal(r)); } diff --git a/src/complex/casinf.c b/src/complex/casinf.c index 93f0e335..4fcb76fc 100644 --- a/src/complex/casinf.c +++ b/src/complex/casinf.c @@ -10,5 +10,6 @@ float complex casinf(float complex z) x = crealf(z); y = cimagf(z); w = CMPLXF(1.0 - (x - y)*(x + y), -2.0*x*y); - return clogf(CMPLXF(-y, x) + csqrtf(w)); + float complex r = clogf(CMPLXF(-y, x) + csqrtf(w)); + return CMPLXF(cimagf(r), -crealf(r)); } diff --git a/src/complex/casinl.c b/src/complex/casinl.c index 0916c60f..3b7ceba7 100644 --- a/src/complex/casinl.c +++ b/src/complex/casinl.c @@ -15,6 +15,7 @@ long double complex casinl(long double complex z) x = creall(z); y = cimagl(z); w = CMPLXL(1.0 - (x - y)*(x + y), -2.0*x*y); - return clogl(CMPLXL(-y, x) + csqrtl(w)); + long double complex r = clogl(CMPLXL(-y, x) + csqrtl(w)); + return CMPLXL(cimagl(r), -creall(r)); } #endif From 10e4bd3780050e75b72aac5d85c31816419bb17d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 11 Apr 2018 15:05:22 -0400 Subject: [PATCH 100/161] fix incorrect results for catan with some inputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the catan implementation from OpenBSD includes a FIXME-annotated "overflow" branch that produces a meaningless and incorrect large-magnitude result. it was reachable via three paths, corresponding to gotos removed by this commit, in order: 1. pure imaginary argument with imaginary component greater than 1 in magnitude. this case does not seem at all exceptional and is handled (at least with the quality currently expected from our complex math functions) by the existing non-exceptional code path. 2. arguments on the unit circle, including the pure-real argument 1.0. these are not exceptional except for ±i, which should produce results with infinite imaginary component and which lead to computation of atan2(±0,0) in the existing non-exceptional code path. such calls to atan2() however are well-defined by POSIX. 3. the specific argument +i. this route should be unreachable due to the above (2), but subtle rounding effects might have made it possible in rare cases. continuing on the non-exceptional code path in this case would lead to computing the (real) log of an infinite argument, then producing a NAN when multiplying it by I. for now, remove the exceptional code paths entirely. replace the multiplication by I with construction of a complex number using the CMPLX macro so that the NAN issue (3) prevented cannot arise. with these changes, catan should give reasonably correct results for real arguments, and should no longer give completely-wrong results for pure-imaginary arguments outside the interval (-i,+i). --- src/complex/catan.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/complex/catan.c b/src/complex/catan.c index 39ce6cf2..7dc2afeb 100644 --- a/src/complex/catan.c +++ b/src/complex/catan.c @@ -91,29 +91,17 @@ double complex catan(double complex z) x = creal(z); y = cimag(z); - if (x == 0.0 && y > 1.0) - goto ovrf; - x2 = x * x; a = 1.0 - x2 - (y * y); - if (a == 0.0) - goto ovrf; t = 0.5 * atan2(2.0 * x, a); w = _redupi(t); t = y - 1.0; a = x2 + (t * t); - if (a == 0.0) - goto ovrf; t = y + 1.0; a = (x2 + t * t)/a; - w = w + (0.25 * log(a)) * I; - return w; - -ovrf: - // FIXME - w = MAXNUM + MAXNUM * I; + w = CMPLX(w, 0.25 * log(a)); return w; } From 424eab2225ff3f8e3ae9f9eec9dacf2f68b71a2f Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Sat, 16 Dec 2017 14:27:25 +0300 Subject: [PATCH 101/161] optimize malloc0 Implementation of __malloc0 in malloc.c takes care to preserve zero pages by overwriting only non-zero data. However, malloc must have already modified auxiliary heap data just before and beyond the allocated region, so we know that edge pages need not be preserved. For allocations smaller than one page, pass them immediately to memset. Otherwise, use memset to handle partial pages at the head and tail of the allocation, and scan complete pages in the interior. Optimize the scanning loop by processing 16 bytes per iteration and handling rest of page via memset as soon as a non-zero byte is found. --- src/malloc/malloc.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index 9e05e1d6..0a7d5d85 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -366,15 +366,32 @@ void *malloc(size_t n) return CHUNK_TO_MEM(c); } +static size_t mal0_clear(char *p, size_t pagesz, size_t n) +{ +#ifdef __GNUC__ + typedef uint64_t __attribute__((__may_alias__)) T; +#else + typedef unsigned char T; +#endif + char *pp = p + n; + size_t i = (uintptr_t)pp & (pagesz - 1); + for (;;) { + pp = memset(pp - i, 0, i); + if (pp - p < pagesz) return pp - p; + for (i = pagesz; i; i -= 2*sizeof(T), pp -= 2*sizeof(T)) + if (((T *)pp)[-1] | ((T *)pp)[-2]) + break; + } +} + void *__malloc0(size_t n) { void *p = malloc(n); - if (p && !IS_MMAPPED(MEM_TO_CHUNK(p))) { - size_t *z; - n = (n + sizeof *z - 1)/sizeof *z; - for (z=p; n; n--, z++) if (*z) *z=0; - } - return p; + if (!p || IS_MMAPPED(MEM_TO_CHUNK(p))) + return p; + if (n >= PAGE_SIZE) + n = mal0_clear(p, PAGE_SIZE, n); + return memset(p, 0, n); } void *realloc(void *p, size_t n) From 4bf0717e5141518c1d34ac84253d3973be1fa260 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 16 Apr 2018 17:35:43 -0400 Subject: [PATCH 102/161] fix return value of nice function the Linux SYS_nice syscall is unusable because it does not return the newly set priority. always use SYS_setpriority. also avoid overflows in addition of inc by handling large inc values directly without examining the old nice value. --- src/unistd/nice.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/unistd/nice.c b/src/unistd/nice.c index da569967..6c25c8c3 100644 --- a/src/unistd/nice.c +++ b/src/unistd/nice.c @@ -1,12 +1,16 @@ #include #include +#include #include "syscall.h" int nice(int inc) { -#ifdef SYS_nice - return syscall(SYS_nice, inc); -#else - return setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS, 0)+inc); -#endif + int prio = inc; + // Only query old priority if it can affect the result. + // This also avoids issues with integer overflow. + if (inc > -2*NZERO && inc < 2*NZERO) + prio += getpriority(PRIO_PROCESS, 0); + if (prio > NZERO-1) prio = NZERO-1; + if (prio < -NZERO) prio = -NZERO; + return setpriority(PRIO_PROCESS, 0, prio) ? -1 : prio; } From b9410061e2ad6fe91bb3910c3adc7d4a315b7ce9 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 16 Apr 2018 20:12:12 -0400 Subject: [PATCH 103/161] use explicit dynamic-list rather than symbolic-functions for linking we have always bound symbols at libc.so link time rather than runtime to minimize startup-time relocations and overhead of calls through the PLT, and possibly also to preclude interposition that would not work correctly anyway if allowed. historically, binding at link-time was also necessary for the dynamic linker to work, but the dynamic linker bootstrap overhaul in commit f3ddd173806fd5c60b3f034528ca24542aecc5b9 made it unnecessary. our use of -Bsymbolic-functions, rather than -Bsymbolic, was chosen because the latter is incompatible with public global data; it makes it incompatible with copy relocations in the main program. however, not all global data needs to be public. by using --dynamic-list instead with an explicit list, we can reduce the number of symbolic relocations left for runtime. this change will also allow us to permit interposition of specific functions (e.g. the allocator) if/when we want to, by adding them to the dynamic list. --- configure | 10 ++++++---- dynamic.list | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 dynamic.list diff --git a/configure b/configure index 1e59c461..09a0c436 100755 --- a/configure +++ b/configure @@ -590,10 +590,12 @@ tryldflag LDFLAGS_AUTO -Wl,--no-undefined # versions built without shared library support and pcc are broken. tryldflag LDFLAGS_AUTO -Wl,--exclude-libs=ALL -# Linking with -Bsymbolic-functions is no longer mandatory for -# the dynamic linker to work, but enable it if it works as -# a linking optimization. -tryldflag LDFLAGS_AUTO -Wl,-Bsymbolic-functions +# Public data symbols must be interposable to allow for copy +# relocations, but otherwise we want to bind symbols at libc link +# time to eliminate startup relocations and PLT overhead. Use +# --dynamic-list rather than -Bsymbolic-functions for greater +# control over what symbols are left unbound. +tryldflag LDFLAGS_AUTO -Wl,--dynamic-list="$srcdir/dynamic.list" # Find compiler runtime library test -z "$LIBCC" && tryldflag LIBCC -lgcc && tryldflag LIBCC -lgcc_eh diff --git a/dynamic.list b/dynamic.list new file mode 100644 index 00000000..8b4f2366 --- /dev/null +++ b/dynamic.list @@ -0,0 +1,35 @@ +{ +environ; +__environ; + +stdin; +stdout; +stderr; + +timezone; +daylight; +tzname; +__timezone; +__daylight; +__tzname; + +signgam; +__signgam; + +optarg; +optind; +opterr; +optreset; +__optreset; + +getdate_err; + +h_errno; + +program_invocation_name; +program_invocation_short_name; +__progname; +__progname_full; + +__stack_chk_guard; +}; From d889cc3463edc92869676c1eec34a8f52d942adb Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Mon, 16 Apr 2018 20:54:35 +0300 Subject: [PATCH 104/161] malloc: fix an over-allocation bug Fix an instance where realloc code would overallocate by OVERHEAD bytes amount. Manually arrange for reuse of memcpy-free-return exit sequence. --- src/malloc/malloc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index 0a7d5d85..db19bc34 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -414,10 +414,9 @@ void *realloc(void *p, size_t n) size_t newlen = n + extra; /* Crash on realloc of freed chunk */ if (extra & 1) a_crash(); - if (newlen < PAGE_SIZE && (new = malloc(n))) { - memcpy(new, p, n-OVERHEAD); - free(p); - return new; + if (newlen < PAGE_SIZE && (new = malloc(n-OVERHEAD))) { + n0 = n; + goto copy_free_ret; } newlen = (newlen + PAGE_SIZE-1) & -PAGE_SIZE; if (oldlen == newlen) return p; @@ -460,6 +459,7 @@ copy_realloc: /* As a last resort, allocate a new chunk and copy to it. */ new = malloc(n-OVERHEAD); if (!new) return 0; +copy_free_ret: memcpy(new, p, n0-OVERHEAD); free(CHUNK_TO_MEM(self)); return new; From ce7ae11acfd9db8eb92cc6823c132e1825918d92 Mon Sep 17 00:00:00 2001 From: Alexander Monakov Date: Mon, 16 Apr 2018 20:54:36 +0300 Subject: [PATCH 105/161] ldso, malloc: implement reclaim_gaps via __malloc_donate Split 'free' into unmap_chunk and bin_chunk, use the latter to introduce __malloc_donate and use it in reclaim_gaps instead of calling 'free'. --- ldso/dynlink.c | 16 +++--------- src/malloc/malloc.c | 61 ++++++++++++++++++++++++++++++++------------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/ldso/dynlink.c b/ldso/dynlink.c index 9bf6924b..b9ff41bc 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -476,23 +476,15 @@ static void redo_lazy_relocs() /* A huge hack: to make up for the wastefulness of shared libraries * needing at least a page of dirty memory even if they have no global * data, we reclaim the gaps at the beginning and end of writable maps - * and "donate" them to the heap by setting up minimal malloc - * structures and then freeing them. */ + * and "donate" them to the heap. */ static void reclaim(struct dso *dso, size_t start, size_t end) { - size_t *a, *z; + void __malloc_donate(char *, char *); if (start >= dso->relro_start && start < dso->relro_end) start = dso->relro_end; if (end >= dso->relro_start && end < dso->relro_end) end = dso->relro_start; - start = start + 6*sizeof(size_t)-1 & -4*sizeof(size_t); - end = (end & -4*sizeof(size_t)) - 2*sizeof(size_t); - if (start>end || end-start < 4*sizeof(size_t)) return; - a = laddr(dso, start); - z = laddr(dso, end); - a[-2] = 1; - a[-1] = z[0] = end-start + 2*sizeof(size_t) | 1; - z[1] = 1; - free(a); + if (start >= end) return; + __malloc_donate(laddr(dso, start), laddr(dso, end)); } static void reclaim_gaps(struct dso *dso) diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index db19bc34..6605ec3a 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -299,6 +299,8 @@ static int pretrim(struct chunk *self, size_t n, int i, int j) return 1; } +static void bin_chunk(struct chunk *); + static void trim(struct chunk *self, size_t n) { size_t n1 = CHUNK_SIZE(self); @@ -314,7 +316,7 @@ static void trim(struct chunk *self, size_t n) next->psize = n1-n | C_INUSE; self->csize = n | C_INUSE; - free(CHUNK_TO_MEM(split)); + bin_chunk(split); } void *malloc(size_t n) @@ -465,29 +467,14 @@ copy_free_ret: return new; } -void free(void *p) +static void bin_chunk(struct chunk *self) { - struct chunk *self, *next; + struct chunk *next = NEXT_CHUNK(self); size_t final_size, new_size, size; int reclaim=0; int i; - if (!p) return; - - self = MEM_TO_CHUNK(p); - - if (IS_MMAPPED(self)) { - size_t extra = self->psize; - char *base = (char *)self - extra; - size_t len = CHUNK_SIZE(self) + extra; - /* Crash on double free */ - if (extra & 1) a_crash(); - __munmap(base, len); - return; - } - final_size = new_size = CHUNK_SIZE(self); - next = NEXT_CHUNK(self); /* Crash on corrupted footer (likely from buffer overflow) */ if (next->psize != self->csize) a_crash(); @@ -548,3 +535,41 @@ void free(void *p) unlock_bin(i); } + +static void unmap_chunk(struct chunk *self) +{ + size_t extra = self->psize; + char *base = (char *)self - extra; + size_t len = CHUNK_SIZE(self) + extra; + /* Crash on double free */ + if (extra & 1) a_crash(); + __munmap(base, len); +} + +void free(void *p) +{ + if (!p) return; + + struct chunk *self = MEM_TO_CHUNK(p); + + if (IS_MMAPPED(self)) + unmap_chunk(self); + else + bin_chunk(self); +} + +void __malloc_donate(char *start, char *end) +{ + size_t align_start_up = (SIZE_ALIGN-1) & (-(uintptr_t)start - OVERHEAD); + size_t align_end_down = (SIZE_ALIGN-1) & (uintptr_t)end; + + if (end - start <= OVERHEAD + align_start_up + align_end_down) + return; + start += align_start_up + OVERHEAD; + end -= align_end_down; + + struct chunk *c = MEM_TO_CHUNK(start), *n = MEM_TO_CHUNK(end); + c->psize = n->csize = C_INUSE; + c->csize = n->psize = C_INUSE | (end-start); + bin_chunk(c); +} From 14032c30e2d41e5c0dac25d399f7086f74d4e0c8 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 17 Apr 2018 15:18:49 -0400 Subject: [PATCH 106/161] comment __malloc_donate overflow logic --- src/malloc/malloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index 6605ec3a..991300cc 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -563,6 +563,9 @@ void __malloc_donate(char *start, char *end) size_t align_start_up = (SIZE_ALIGN-1) & (-(uintptr_t)start - OVERHEAD); size_t align_end_down = (SIZE_ALIGN-1) & (uintptr_t)end; + /* Getting past this condition ensures that the padding for alignment + * and header overhead will not overflow and will leave a nonzero + * multiple of SIZE_ALIGN bytes between start and end. */ if (end - start <= OVERHEAD + align_start_up + align_end_down) return; start += align_start_up + OVERHEAD; From d610c148554766f2a0e48304fe2550b340f84872 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 17 Apr 2018 15:55:18 -0400 Subject: [PATCH 107/161] enable reclaim_gaps for fdpic the existing laddr function for fdpic cannot translate ELF virtual addresses outside of the LOAD segments to runtime addresses because the fdpic loadmap only covers the logically-mapped part. however the whole point of reclaim_gaps is to recover the slack space up to the page boundaries, so it needs to work with such addresses. add a new laddr_pg function that accepts any address in the page range for the LOAD segment by expanding the loadmap records out to page boundaries. only use the new version for reclaim_gaps, so as not to impact performance of other address lookups. also, only use laddr_pg for the start address of a gap; the end address lies one byte beyond the end, potentially in a different page where it would get mapped differently. instead of mapping end, apply the length (end-start) to the mapped value of start. --- ldso/dynlink.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ldso/dynlink.c b/ldso/dynlink.c index b9ff41bc..63e7b81f 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -158,10 +158,26 @@ static void *laddr(const struct dso *p, size_t v) for (j=0; v-p->loadmap->segs[j].p_vaddr >= p->loadmap->segs[j].p_memsz; j++); return (void *)(v - p->loadmap->segs[j].p_vaddr + p->loadmap->segs[j].addr); } +static void *laddr_pg(const struct dso *p, size_t v) +{ + size_t j=0; + size_t pgsz = PAGE_SIZE; + if (!p->loadmap) return p->base + v; + for (j=0; ; j++) { + size_t a = p->loadmap->segs[j].p_vaddr; + size_t b = a + p->loadmap->segs[j].p_memsz; + a &= -pgsz; + b += pgsz-1; + b &= -pgsz; + if (v-aloadmap->segs[j].p_vaddr + p->loadmap->segs[j].addr); +} #define fpaddr(p, v) ((void (*)())&(struct funcdesc){ \ laddr(p, v), (p)->got }) #else #define laddr(p, v) (void *)((p)->base + (v)) +#define laddr_pg(p, v) laddr(p, v) #define fpaddr(p, v) ((void (*)())laddr(p, v)) #endif @@ -484,7 +500,8 @@ static void reclaim(struct dso *dso, size_t start, size_t end) if (start >= dso->relro_start && start < dso->relro_end) start = dso->relro_end; if (end >= dso->relro_start && end < dso->relro_end) end = dso->relro_start; if (start >= end) return; - __malloc_donate(laddr(dso, start), laddr(dso, end)); + char *base = laddr_pg(dso, start); + __malloc_donate(base, base+(end-start)); } static void reclaim_gaps(struct dso *dso) @@ -492,7 +509,6 @@ static void reclaim_gaps(struct dso *dso) Phdr *ph = dso->phdr; size_t phcnt = dso->phnum; - if (DL_FDPIC) return; // FIXME for (; phcnt--; ph=(void *)((char *)ph+dso->phentsize)) { if (ph->p_type!=PT_LOAD) continue; if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue; From 502027540bafd0681bfc46b0ae28639e51bba6a6 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 17 Apr 2018 16:37:30 -0400 Subject: [PATCH 108/161] remove unused __brk function/source file commit e3bc22f1eff87b8f029a6ab31f1a269d69e4b053 removed all references to __brk. --- src/malloc/__brk.c | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/malloc/__brk.c diff --git a/src/malloc/__brk.c b/src/malloc/__brk.c deleted file mode 100644 index 4c9119b4..00000000 --- a/src/malloc/__brk.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "syscall.h" - -uintptr_t __brk(uintptr_t newbrk) -{ - return __syscall(SYS_brk, newbrk); -} From c21f750727515602a9e84f2a190ee8a0a2aeb2a1 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 17 Apr 2018 23:59:41 -0400 Subject: [PATCH 109/161] fix stdio lock dependency on read-after-free not faulting instead of using a waiters count, add a bit to the lock field indicating that the lock may have waiters. threads which obtain the lock after contending for it will perform a potentially-spurious wake when they release the lock. --- src/stdio/__lockfile.c | 29 +++++++++++++---------------- src/stdio/flockfile.c | 6 +++++- src/stdio/ftrylockfile.c | 9 ++++++--- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/stdio/__lockfile.c b/src/stdio/__lockfile.c index 9d967d6e..2ff75d8a 100644 --- a/src/stdio/__lockfile.c +++ b/src/stdio/__lockfile.c @@ -1,28 +1,25 @@ #include "stdio_impl.h" #include "pthread_impl.h" +#define MAYBE_WAITERS 0x40000000 + int __lockfile(FILE *f) { - int owner, tid = __pthread_self()->tid; - if (f->lock == tid) + int owner = f->lock, tid = __pthread_self()->tid; + if ((owner & ~MAYBE_WAITERS) == tid) return 0; - while ((owner = a_cas(&f->lock, 0, tid))) - __wait(&f->lock, &f->waiters, owner, 1); + for (;;) { + owner = a_cas(&f->lock, 0, tid); + if (!owner) return 1; + if (a_cas(&f->lock, owner, owner|MAYBE_WAITERS)==owner) break; + } + while ((owner = a_cas(&f->lock, 0, tid|MAYBE_WAITERS))) + __futexwait(&f->lock, owner, 1); return 1; } void __unlockfile(FILE *f) { - a_store(&f->lock, 0); - - /* The following read is technically invalid under situations - * of self-synchronized destruction. Another thread may have - * called fclose as soon as the above store has completed. - * Nonetheless, since FILE objects always live in memory - * obtained by malloc from the heap, it's safe to assume - * the dereferences below will not fault. In the worst case, - * a spurious syscall will be made. If the implementation of - * malloc changes, this assumption needs revisiting. */ - - if (f->waiters) __wake(&f->lock, 1, 1); + if (a_swap(&f->lock, 0) & MAYBE_WAITERS) + __wake(&f->lock, 1, 1); } diff --git a/src/stdio/flockfile.c b/src/stdio/flockfile.c index a196c1ef..6b574cf0 100644 --- a/src/stdio/flockfile.c +++ b/src/stdio/flockfile.c @@ -1,10 +1,14 @@ #include "stdio_impl.h" #include "pthread_impl.h" +#define MAYBE_WAITERS 0x40000000 + void flockfile(FILE *f) { while (ftrylockfile(f)) { int owner = f->lock; - if (owner) __wait(&f->lock, &f->waiters, owner, 1); + if (!owner) continue; + a_cas(&f->lock, owner, owner|MAYBE_WAITERS); + __futexwait(&f->lock, owner|MAYBE_WAITERS, 1); } } diff --git a/src/stdio/ftrylockfile.c b/src/stdio/ftrylockfile.c index eb13c839..3b1d5f20 100644 --- a/src/stdio/ftrylockfile.c +++ b/src/stdio/ftrylockfile.c @@ -2,6 +2,8 @@ #include "pthread_impl.h" #include +#define MAYBE_WAITERS 0x40000000 + void __do_orphaned_stdio_locks() { FILE *f; @@ -22,14 +24,15 @@ int ftrylockfile(FILE *f) { pthread_t self = __pthread_self(); int tid = self->tid; - if (f->lock == tid) { + int owner = f->lock; + if ((owner & ~MAYBE_WAITERS) == tid) { if (f->lockcount == LONG_MAX) return -1; f->lockcount++; return 0; } - if (f->lock < 0) f->lock = 0; - if (f->lock || a_cas(&f->lock, 0, tid)) + if (owner < 0) f->lock = owner = 0; + if (owner || a_cas(&f->lock, 0, tid)) return -1; f->lockcount = 1; f->prev_locked = 0; From c1014a812c90bab3c9c989863e4ebb129e987de6 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 18 Apr 2018 00:16:12 -0400 Subject: [PATCH 110/161] refactor flockfile not to duplicate lock mechanism logic --- src/stdio/flockfile.c | 11 ++++------- src/stdio/ftrylockfile.c | 15 ++++++++++----- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/stdio/flockfile.c b/src/stdio/flockfile.c index 6b574cf0..6806cf8b 100644 --- a/src/stdio/flockfile.c +++ b/src/stdio/flockfile.c @@ -1,14 +1,11 @@ #include "stdio_impl.h" #include "pthread_impl.h" -#define MAYBE_WAITERS 0x40000000 +void __register_locked_file(FILE *, pthread_t); void flockfile(FILE *f) { - while (ftrylockfile(f)) { - int owner = f->lock; - if (!owner) continue; - a_cas(&f->lock, owner, owner|MAYBE_WAITERS); - __futexwait(&f->lock, owner|MAYBE_WAITERS, 1); - } + if (!ftrylockfile(f)) return; + __lockfile(f); + __register_locked_file(f, __pthread_self()); } diff --git a/src/stdio/ftrylockfile.c b/src/stdio/ftrylockfile.c index 3b1d5f20..3b97807a 100644 --- a/src/stdio/ftrylockfile.c +++ b/src/stdio/ftrylockfile.c @@ -20,6 +20,15 @@ void __unlist_locked_file(FILE *f) } } +void __register_locked_file(FILE *f, pthread_t self) +{ + f->lockcount = 1; + f->prev_locked = 0; + f->next_locked = self->stdio_locks; + if (f->next_locked) f->next_locked->prev_locked = f; + self->stdio_locks = f; +} + int ftrylockfile(FILE *f) { pthread_t self = __pthread_self(); @@ -34,10 +43,6 @@ int ftrylockfile(FILE *f) if (owner < 0) f->lock = owner = 0; if (owner || a_cas(&f->lock, 0, tid)) return -1; - f->lockcount = 1; - f->prev_locked = 0; - f->next_locked = self->stdio_locks; - if (f->next_locked) f->next_locked->prev_locked = f; - self->stdio_locks = f; + __register_locked_file(f, self); return 0; } From c9f415d7ea2dace5bf77f6518b6afc36bb7a5732 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 17 Apr 2018 18:36:19 -0400 Subject: [PATCH 111/161] allow interposition/replacement of allocator (malloc) replacement is subject to conditions on the replacement functions. they may only call functions which are async-signal-safe, as specified either by POSIX or as an implementation-defined extension. if any allocator functions are replaced, at least malloc, realloc, and free must be provided. if calloc is not provided, it will behave as malloc+memset. any of the memalign-family functions not provided will fail with ENOMEM. in order to implement the above properties, calloc and __memalign check that they are using their own malloc or free, respectively. choice to check malloc or free is based on considerations of supporting __simple_malloc. in order to make this work, calloc is split into separate versions for __simple_malloc and full malloc; commit ba819787ee93ceae94efd274f7849e317c1bff58 already did most of the split anyway, and completing it saves an extra call frame. previously, use of -Bsymbolic-functions made dynamic interposition impossible. now, we are using an explicit dynamic-list, so add allocator functions to the list. most are not referenced anyway, but all are added for completeness. --- dynamic.list | 9 +++++++++ src/malloc/calloc.c | 13 ------------- src/malloc/lite_malloc.c | 12 +++++++++++- src/malloc/malloc.c | 22 +++++++++++++++++----- src/malloc/memalign.c | 6 ++---- 5 files changed, 39 insertions(+), 23 deletions(-) delete mode 100644 src/malloc/calloc.c diff --git a/dynamic.list b/dynamic.list index 8b4f2366..686f8eb4 100644 --- a/dynamic.list +++ b/dynamic.list @@ -6,6 +6,15 @@ stdin; stdout; stderr; +malloc; +calloc; +realloc; +free; +memalign; +posix_memalign; +aligned_alloc; +malloc_usable_size; + timezone; daylight; tzname; diff --git a/src/malloc/calloc.c b/src/malloc/calloc.c deleted file mode 100644 index 436c0b03..00000000 --- a/src/malloc/calloc.c +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include - -void *__malloc0(size_t); - -void *calloc(size_t m, size_t n) -{ - if (n && m > (size_t)-1/n) { - errno = ENOMEM; - return 0; - } - return __malloc0(n * m); -} diff --git a/src/malloc/lite_malloc.c b/src/malloc/lite_malloc.c index 701f60b4..29cccb10 100644 --- a/src/malloc/lite_malloc.c +++ b/src/malloc/lite_malloc.c @@ -47,4 +47,14 @@ static void *__simple_malloc(size_t n) } weak_alias(__simple_malloc, malloc); -weak_alias(__simple_malloc, __malloc0); + +static void *__simple_calloc(size_t m, size_t n) +{ + if (n && m > (size_t)-1/n || malloc != __simple_malloc) { + errno = ENOMEM; + return 0; + } + return __simple_malloc(n * m); +} + +weak_alias(__simple_calloc, calloc); diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index 991300cc..5a56e0c5 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -368,6 +368,8 @@ void *malloc(size_t n) return CHUNK_TO_MEM(c); } +weak_alias(malloc, __internal_malloc); + static size_t mal0_clear(char *p, size_t pagesz, size_t n) { #ifdef __GNUC__ @@ -386,13 +388,21 @@ static size_t mal0_clear(char *p, size_t pagesz, size_t n) } } -void *__malloc0(size_t n) +void *calloc(size_t m, size_t n) { + if (n && m > (size_t)-1/n) { + errno = ENOMEM; + return 0; + } + n *= m; void *p = malloc(n); - if (!p || IS_MMAPPED(MEM_TO_CHUNK(p))) - return p; - if (n >= PAGE_SIZE) - n = mal0_clear(p, PAGE_SIZE, n); + if (!p) return p; + if (malloc == __internal_malloc) { + if (IS_MMAPPED(MEM_TO_CHUNK(p))) + return p; + if (n >= PAGE_SIZE) + n = mal0_clear(p, PAGE_SIZE, n); + } return memset(p, 0, n); } @@ -558,6 +568,8 @@ void free(void *p) bin_chunk(self); } +weak_alias(free, __internal_free); + void __malloc_donate(char *start, char *end) { size_t align_start_up = (SIZE_ALIGN-1) & (-(uintptr_t)start - OVERHEAD); diff --git a/src/malloc/memalign.c b/src/malloc/memalign.c index 006bd21c..35b67599 100644 --- a/src/malloc/memalign.c +++ b/src/malloc/memalign.c @@ -3,9 +3,7 @@ #include #include "libc.h" -/* This function should work with most dlmalloc-like chunk bookkeeping - * systems, but it's only guaranteed to work with the native implementation - * used in this library. */ +void __internal_free(void *); void *__memalign(size_t align, size_t len) { @@ -17,7 +15,7 @@ void *__memalign(size_t align, size_t len) return NULL; } - if (len > SIZE_MAX - align) { + if (len > SIZE_MAX - align || free != __internal_free) { errno = ENOMEM; return NULL; } From 4245a233c147e18a841bc6ccd5aafb65d6bca163 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 18 Apr 2018 14:46:05 -0400 Subject: [PATCH 112/161] minor cleanup in fopencookie assign entire struct rather than member-at-a-time. don't repeat buffer sizes; always use sizeof to ensure consistency. --- src/stdio/fopencookie.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/stdio/fopencookie.c b/src/stdio/fopencookie.c index 2f46dd53..da042fe8 100644 --- a/src/stdio/fopencookie.c +++ b/src/stdio/fopencookie.c @@ -116,15 +116,12 @@ FILE *fopencookie(void *cookie, const char *mode, cookie_io_functions_t iofuncs) /* Set up our fcookie */ f->fc.cookie = cookie; - f->fc.iofuncs.read = iofuncs.read; - f->fc.iofuncs.write = iofuncs.write; - f->fc.iofuncs.seek = iofuncs.seek; - f->fc.iofuncs.close = iofuncs.close; + f->fc.iofuncs = iofuncs; f->f.fd = -1; f->f.cookie = &f->fc; f->f.buf = f->buf + UNGET; - f->f.buf_size = BUFSIZ; + f->f.buf_size = sizeof f->buf - UNGET; f->f.lbf = EOF; /* Initialize op ptrs. No problem if some are unneeded. */ From 0b043c7b70b204c43dc7dbdb50b12aa8fa7981e8 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 18 Apr 2018 14:57:10 -0400 Subject: [PATCH 113/161] clean up allocation/setup logic for fmemopen rather than manually performing pointer arithmetic to carve multiple objects out of one allocation, use a containing struct that encompasses them all. --- src/stdio/fmemopen.c | 52 ++++++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/src/stdio/fmemopen.c b/src/stdio/fmemopen.c index 2ce43d32..fb2656e3 100644 --- a/src/stdio/fmemopen.c +++ b/src/stdio/fmemopen.c @@ -9,6 +9,12 @@ struct cookie { int mode; }; +struct mem_FILE { + FILE f; + struct cookie c; + unsigned char buf[UNGET+BUFSIZ], buf2[]; +}; + static off_t mseek(FILE *f, off_t off, int whence) { ssize_t base; @@ -72,8 +78,7 @@ static int mclose(FILE *m) FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode) { - FILE *f; - struct cookie *c; + struct mem_FILE *f; int plus = !!strchr(mode, '+'); if (!size || !strchr("rwa", *mode)) { @@ -86,29 +91,34 @@ FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode) return 0; } - f = calloc(sizeof *f + sizeof *c + UNGET + BUFSIZ + (buf?0:size), 1); + f = malloc(sizeof *f + (buf?0:size)); if (!f) return 0; - f->cookie = c = (void *)(f+1); - f->fd = -1; - f->lbf = EOF; - f->buf = (unsigned char *)(c+1) + UNGET; - f->buf_size = BUFSIZ; - if (!buf) buf = f->buf + BUFSIZ; + memset(&f->f, 0, sizeof f->f); + f->f.cookie = &f->c; + f->f.fd = -1; + f->f.lbf = EOF; + f->f.buf = f->buf + UNGET; + f->f.buf_size = sizeof f->buf - UNGET; + if (!buf) { + buf = f->buf2;; + memset(buf, 0, size); + } - c->buf = buf; - c->size = size; - c->mode = *mode; + memset(&f->c, 0, sizeof f->c); + f->c.buf = buf; + f->c.size = size; + f->c.mode = *mode; - if (!plus) f->flags = (*mode == 'r') ? F_NOWR : F_NORD; - if (*mode == 'r') c->len = size; - else if (*mode == 'a') c->len = c->pos = strnlen(buf, size); + if (!plus) f->f.flags = (*mode == 'r') ? F_NOWR : F_NORD; + if (*mode == 'r') f->c.len = size; + else if (*mode == 'a') f->c.len = f->c.pos = strnlen(buf, size); - f->read = mread; - f->write = mwrite; - f->seek = mseek; - f->close = mclose; + f->f.read = mread; + f->f.write = mwrite; + f->f.seek = mseek; + f->f.close = mclose; - if (!libc.threaded) f->lock = -1; + if (!libc.threaded) f->f.lock = -1; - return __ofl_add(f); + return __ofl_add(&f->f); } From 6019459251c58426808f207d18014b6b1f250a59 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 18 Apr 2018 15:08:16 -0400 Subject: [PATCH 114/161] clean up allocation/setup logic for open_[w]memstream bring these functions up to date with the current idioms we use/prefer in fmemopen and fopencookie. --- src/stdio/open_memstream.c | 44 +++++++++++++++++++++---------------- src/stdio/open_wmemstream.c | 44 +++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/src/stdio/open_memstream.c b/src/stdio/open_memstream.c index eab024da..ee834234 100644 --- a/src/stdio/open_memstream.c +++ b/src/stdio/open_memstream.c @@ -12,6 +12,12 @@ struct cookie { size_t space; }; +struct ms_FILE { + FILE f; + struct cookie c; + unsigned char buf[BUFSIZ]; +}; + static off_t ms_seek(FILE *f, off_t off, int whence) { ssize_t base; @@ -57,34 +63,34 @@ static int ms_close(FILE *f) FILE *open_memstream(char **bufp, size_t *sizep) { - FILE *f; - struct cookie *c; + struct ms_FILE *f; char *buf; - if (!(f=malloc(sizeof *f + sizeof *c + BUFSIZ))) return 0; + if (!(f=malloc(sizeof *f))) return 0; if (!(buf=malloc(sizeof *buf))) { free(f); return 0; } - memset(f, 0, sizeof *f + sizeof *c); - f->cookie = c = (void *)(f+1); + memset(&f->f, 0, sizeof f->f); + memset(&f->c, 0, sizeof f->c); + f->f.cookie = &f->c; - c->bufp = bufp; - c->sizep = sizep; - c->pos = c->len = c->space = *sizep = 0; - c->buf = *bufp = buf; + f->c.bufp = bufp; + f->c.sizep = sizep; + f->c.pos = f->c.len = f->c.space = *sizep = 0; + f->c.buf = *bufp = buf; *buf = 0; - f->flags = F_NORD; - f->fd = -1; - f->buf = (void *)(c+1); - f->buf_size = BUFSIZ; - f->lbf = EOF; - f->write = ms_write; - f->seek = ms_seek; - f->close = ms_close; + f->f.flags = F_NORD; + f->f.fd = -1; + f->f.buf = f->buf; + f->f.buf_size = sizeof f->buf; + f->f.lbf = EOF; + f->f.write = ms_write; + f->f.seek = ms_seek; + f->f.close = ms_close; - if (!libc.threaded) f->lock = -1; + if (!libc.threaded) f->f.lock = -1; - return __ofl_add(f); + return __ofl_add(&f->f); } diff --git a/src/stdio/open_wmemstream.c b/src/stdio/open_wmemstream.c index 4d90cd97..cb693ea7 100644 --- a/src/stdio/open_wmemstream.c +++ b/src/stdio/open_wmemstream.c @@ -14,6 +14,12 @@ struct cookie { mbstate_t mbs; }; +struct wms_FILE { + FILE f; + struct cookie c; + unsigned char buf[1]; +}; + static off_t wms_seek(FILE *f, off_t off, int whence) { ssize_t base; @@ -59,34 +65,34 @@ static int wms_close(FILE *f) FILE *open_wmemstream(wchar_t **bufp, size_t *sizep) { - FILE *f; - struct cookie *c; + struct wms_FILE *f; wchar_t *buf; - if (!(f=malloc(sizeof *f + sizeof *c))) return 0; + if (!(f=malloc(sizeof *f))) return 0; if (!(buf=malloc(sizeof *buf))) { free(f); return 0; } - memset(f, 0, sizeof *f + sizeof *c); - f->cookie = c = (void *)(f+1); + memset(&f->f, 0, sizeof f->f); + memset(&f->c, 0, sizeof f->c); + f->f.cookie = &f->c; - c->bufp = bufp; - c->sizep = sizep; - c->pos = c->len = c->space = *sizep = 0; - c->buf = *bufp = buf; + f->c.bufp = bufp; + f->c.sizep = sizep; + f->c.pos = f->c.len = f->c.space = *sizep = 0; + f->c.buf = *bufp = buf; *buf = 0; - f->flags = F_NORD; - f->fd = -1; - f->buf = (void *)(c+1); - f->buf_size = 0; - f->lbf = EOF; - f->write = wms_write; - f->seek = wms_seek; - f->close = wms_close; + f->f.flags = F_NORD; + f->f.fd = -1; + f->f.buf = f->buf; + f->f.buf_size = 0; + f->f.lbf = EOF; + f->f.write = wms_write; + f->f.seek = wms_seek; + f->f.close = wms_close; - if (!libc.threaded) f->lock = -1; + if (!libc.threaded) f->f.lock = -1; - return __ofl_add(f); + return __ofl_add(&f->f); } From 0b80a7b0404b6e49b0b724e3e3fe0ed5af3b08ef Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 18 Apr 2018 15:29:18 -0400 Subject: [PATCH 115/161] add support for caller-provided buffers to setvbuf --- src/stdio/setvbuf.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/stdio/setvbuf.c b/src/stdio/setvbuf.c index 541a125f..0a0c139f 100644 --- a/src/stdio/setvbuf.c +++ b/src/stdio/setvbuf.c @@ -1,22 +1,25 @@ #include "stdio_impl.h" -/* This function makes no attempt to protect the user from his/her own - * stupidity. If called any time but when then ISO C standard specifically - * allows it, all hell can and will break loose, especially with threads! - * - * This implementation ignores all arguments except the buffering type, - * and uses the existing buffer allocated alongside the FILE object. - * In the case of stderr where the preexisting buffer is length 1, it - * is not possible to set line buffering or full buffering. */ +/* The behavior of this function is undefined except when it is the first + * operation on the stream, so the presence or absence of lockign is not + * observable in a program whose behavior is defined. Thus no locking is + * performed here. No allocation of buffers is performed, but a buffer + * provided by the caller is used as long as it is suitably sized. */ int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size) { f->lbf = EOF; - if (type == _IONBF) + if (type == _IONBF) { f->buf_size = 0; - else if (type == _IOLBF) - f->lbf = '\n'; + } else { + if (buf && size >= UNGET) { + f->buf = (void *)buf; + f->buf_size = size - UNGET; + } + if (type == _IOLBF && f->buf_size) + f->lbf = '\n'; + } f->flags |= F_SVB; From 3f6dc30470d5751b83645df180a60cad3e7907ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Sun, 11 Mar 2018 09:55:06 +0100 Subject: [PATCH 116/161] fix out of bounds write for zero length buffer in gethostname --- src/unistd/gethostname.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unistd/gethostname.c b/src/unistd/gethostname.c index f984b7dd..633ef571 100644 --- a/src/unistd/gethostname.c +++ b/src/unistd/gethostname.c @@ -8,6 +8,6 @@ int gethostname(char *name, size_t len) if (uname(&uts)) return -1; if (len > sizeof uts.nodename) len = sizeof uts.nodename; for (i=0; i Date: Wed, 18 Apr 2018 17:40:59 -0700 Subject: [PATCH 117/161] remove a_ctz_l from arch specific atomic_arch.h Update atomic.h to provide a_ctz_l in all cases (atomic_arch.h should now only provide a_ctz_32 and/or a_ctz_64). The generic version of a_ctz_32 now takes advantage of a_clz_32 if available and the generic a_ctz_64 now makes use of a_ctz_32. --- arch/i386/atomic_arch.h | 6 +++--- arch/x32/atomic_arch.h | 4 ++-- src/internal/atomic.h | 42 ++++++++++++++++++++++------------------- 3 files changed, 28 insertions(+), 24 deletions(-) diff --git a/arch/i386/atomic_arch.h b/arch/i386/atomic_arch.h index 7d2a48a5..047fb68d 100644 --- a/arch/i386/atomic_arch.h +++ b/arch/i386/atomic_arch.h @@ -92,10 +92,10 @@ static inline int a_ctz_64(uint64_t x) return r; } -#define a_ctz_l a_ctz_l -static inline int a_ctz_l(unsigned long x) +#define a_ctz_32 a_ctz_32 +static inline int a_ctz_32(uint32_t x) { - long r; + int r; __asm__( "bsf %1,%0" : "=r"(r) : "r"(x) ); return r; } diff --git a/arch/x32/atomic_arch.h b/arch/x32/atomic_arch.h index a744c299..918c2d4e 100644 --- a/arch/x32/atomic_arch.h +++ b/arch/x32/atomic_arch.h @@ -106,8 +106,8 @@ static inline int a_ctz_64(uint64_t x) return x; } -#define a_ctz_l a_ctz_l -static inline int a_ctz_l(unsigned long x) +#define a_ctz_32 a_ctz_32 +static inline int a_ctz_32(uint32_t x) { __asm__( "bsf %1,%0" : "=r"(x) : "r"(x) ); return x; diff --git a/src/internal/atomic.h b/src/internal/atomic.h index ab473dd7..f938879b 100644 --- a/src/internal/atomic.h +++ b/src/internal/atomic.h @@ -251,6 +251,22 @@ static inline void a_crash() } #endif +#ifndef a_ctz_32 +#define a_ctz_32 a_ctz_32 +static inline int a_ctz_32(uint32_t x) +{ +#ifdef a_clz_32 + return 31-a_clz_32(x&-x); +#else + static const char debruijn32[32] = { + 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, + 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 + }; + return debruijn32[(x&-x)*0x076be629 >> 27]; +#endif +} +#endif + #ifndef a_ctz_64 #define a_ctz_64 a_ctz_64 static inline int a_ctz_64(uint64_t x) @@ -261,22 +277,23 @@ static inline int a_ctz_64(uint64_t x) 63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, 51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 }; - static const char debruijn32[32] = { - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 - }; if (sizeof(long) < 8) { uint32_t y = x; if (!y) { y = x>>32; - return 32 + debruijn32[(y&-y)*0x076be629 >> 27]; + return 32 + a_ctz_32(y); } - return debruijn32[(y&-y)*0x076be629 >> 27]; + return a_ctz_32(y); } return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58]; } #endif +static inline int a_ctz_l(unsigned long x) +{ + return (sizeof(long) < 8) ? a_ctz_32(x) : a_ctz_64(x); +} + #ifndef a_clz_64 #define a_clz_64 a_clz_64 static inline int a_clz_64(uint64_t x) @@ -298,17 +315,4 @@ static inline int a_clz_64(uint64_t x) } #endif -#ifndef a_ctz_l -#define a_ctz_l a_ctz_l -static inline int a_ctz_l(unsigned long x) -{ - static const char debruijn32[32] = { - 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, - 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 - }; - if (sizeof(long) == 8) return a_ctz_64(x); - return debruijn32[(x&-x)*0x076be629 >> 27]; -} -#endif - #endif From ea489b8b0d89e391455689b7cc397d0c261677c9 Mon Sep 17 00:00:00 2001 From: Andre McCurdy Date: Wed, 18 Apr 2018 17:41:00 -0700 Subject: [PATCH 118/161] provide optimized a_ctz_32 for arm Provide an ARM specific a_ctz_32 helper function for architecture versions for which it can be implemented efficiently via the "rbit" instruction (ie all Thumb-2 capable versions of ARM v6 and above). --- arch/arm/atomic_arch.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/arm/atomic_arch.h b/arch/arm/atomic_arch.h index c5c56f81..72fcddb4 100644 --- a/arch/arm/atomic_arch.h +++ b/arch/arm/atomic_arch.h @@ -91,4 +91,16 @@ static inline int a_clz_32(uint32_t x) return x; } +#if __ARM_ARCH_6T2__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 + +#define a_ctz_32 a_ctz_32 +static inline int a_ctz_32(uint32_t x) +{ + uint32_t xr; + __asm__ ("rbit %0, %1" : "=r"(xr) : "r"(x)); + return a_clz_32(xr); +} + +#endif + #endif From 749a06b4c55d823d8a74b4e3f607c65006db271b Mon Sep 17 00:00:00 2001 From: Andre McCurdy Date: Wed, 18 Apr 2018 18:51:43 -0700 Subject: [PATCH 119/161] arm: respect both __ARM_ARCH_6KZ__ and __ARM_ARCH_6ZK__ macros __ARM_ARCH_6ZK__ is a gcc specific historical typo which may not be defined by other compilers. https://gcc.gnu.org/ml/gcc-patches/2015-07/msg02237.html To avoid unexpected results when building for ARMv6KZ with clang, the correct form of the macro (ie 6KZ) needs to be tested. The incorrect form of the macro (ie 6ZK) still needs to be tested for compatibility with pre-2015 versions of gcc. --- arch/arm/atomic_arch.h | 2 +- arch/arm/pthread_arch.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/atomic_arch.h b/arch/arm/atomic_arch.h index 72fcddb4..5ff1be1b 100644 --- a/arch/arm/atomic_arch.h +++ b/arch/arm/atomic_arch.h @@ -7,7 +7,7 @@ extern uintptr_t __attribute__((__visibility__("hidden"))) __a_cas_ptr, __a_barrier_ptr; -#if ((__ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6ZK__) && !__thumb__) \ +#if ((__ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6KZ__ || __ARM_ARCH_6ZK__) && !__thumb__) \ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 #define a_ll a_ll diff --git a/arch/arm/pthread_arch.h b/arch/arm/pthread_arch.h index 197752ef..6657e198 100644 --- a/arch/arm/pthread_arch.h +++ b/arch/arm/pthread_arch.h @@ -1,4 +1,4 @@ -#if ((__ARM_ARCH_6K__ || __ARM_ARCH_6ZK__) && !__thumb__) \ +#if ((__ARM_ARCH_6K__ || __ARM_ARCH_6KZ__ || __ARM_ARCH_6ZK__) && !__thumb__) \ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 static inline pthread_t __pthread_self() From 8c2943f057c5f69cc6423c360b626bc1ad493230 Mon Sep 17 00:00:00 2001 From: Andre McCurdy Date: Wed, 18 Apr 2018 18:51:44 -0700 Subject: [PATCH 120/161] arm: use a_ll/a_sc atomics when building for ARMv6T2 ARMv6 cores with support for Thumb2 can take advantage of the "ldrex" and "strex" based implementations of a_ll and a_sc. --- arch/arm/atomic_arch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/atomic_arch.h b/arch/arm/atomic_arch.h index 5ff1be1b..62458b45 100644 --- a/arch/arm/atomic_arch.h +++ b/arch/arm/atomic_arch.h @@ -8,7 +8,7 @@ extern uintptr_t __attribute__((__visibility__("hidden"))) __a_cas_ptr, __a_barrier_ptr; #if ((__ARM_ARCH_6__ || __ARM_ARCH_6K__ || __ARM_ARCH_6KZ__ || __ARM_ARCH_6ZK__) && !__thumb__) \ - || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 + || __ARM_ARCH_6T2__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 #define a_ll a_ll static inline int a_ll(volatile int *p) From 3f3cc3e99558501318e2f16ff03bbd68ce5a5e95 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Wed, 18 Apr 2018 16:17:44 -0500 Subject: [PATCH 121/161] setvbuf: minor comment typo fix --- src/stdio/setvbuf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stdio/setvbuf.c b/src/stdio/setvbuf.c index 0a0c139f..b6b9b018 100644 --- a/src/stdio/setvbuf.c +++ b/src/stdio/setvbuf.c @@ -1,7 +1,7 @@ #include "stdio_impl.h" /* The behavior of this function is undefined except when it is the first - * operation on the stream, so the presence or absence of lockign is not + * operation on the stream, so the presence or absence of locking is not * observable in a program whose behavior is defined. Thus no locking is * performed here. No allocation of buffers is performed, but a buffer * provided by the caller is used as long as it is suitably sized. */ From 618b18c78e33acfe54a4434e91aa57b8e171df89 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 19 Apr 2018 15:25:48 -0400 Subject: [PATCH 122/161] revert detection of partially-replaced allocator commit c9f415d7ea2dace5bf77f6518b6afc36bb7a5732 included checks to make calloc fallback to memset if used with a replaced malloc that didn't also replace calloc, and the memalign family fail if free has been replaced. however, the checks gave false positives for replacement whenever malloc or free resolved to a PLT entry in the main program. for now, disable the checks so as not to leave libc in a broken state. this means that the properties documented in the above commit are no longer satisfied; failure to replace calloc and the memalign family along with malloc is unsafe if they are ever called. the calloc checks were correct but useless for static linking. in both cases (simple or full malloc), calloc and malloc are in a source file together, so replacement of one but not the other would give linking errors. the memalign-family check was useful for static linking, but broken for dynamic as described above, and can be replaced with a better link-time check. --- src/malloc/lite_malloc.c | 2 +- src/malloc/malloc.c | 15 ++++----------- src/malloc/memalign.c | 4 +--- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/malloc/lite_malloc.c b/src/malloc/lite_malloc.c index 29cccb10..96c4feac 100644 --- a/src/malloc/lite_malloc.c +++ b/src/malloc/lite_malloc.c @@ -50,7 +50,7 @@ weak_alias(__simple_malloc, malloc); static void *__simple_calloc(size_t m, size_t n) { - if (n && m > (size_t)-1/n || malloc != __simple_malloc) { + if (n && m > (size_t)-1/n) { errno = ENOMEM; return 0; } diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index 5a56e0c5..da775921 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -368,8 +368,6 @@ void *malloc(size_t n) return CHUNK_TO_MEM(c); } -weak_alias(malloc, __internal_malloc); - static size_t mal0_clear(char *p, size_t pagesz, size_t n) { #ifdef __GNUC__ @@ -396,13 +394,10 @@ void *calloc(size_t m, size_t n) } n *= m; void *p = malloc(n); - if (!p) return p; - if (malloc == __internal_malloc) { - if (IS_MMAPPED(MEM_TO_CHUNK(p))) - return p; - if (n >= PAGE_SIZE) - n = mal0_clear(p, PAGE_SIZE, n); - } + if (!p || IS_MMAPPED(MEM_TO_CHUNK(p))) + return p; + if (n >= PAGE_SIZE) + n = mal0_clear(p, PAGE_SIZE, n); return memset(p, 0, n); } @@ -568,8 +563,6 @@ void free(void *p) bin_chunk(self); } -weak_alias(free, __internal_free); - void __malloc_donate(char *start, char *end) { size_t align_start_up = (SIZE_ALIGN-1) & (-(uintptr_t)start - OVERHEAD); diff --git a/src/malloc/memalign.c b/src/malloc/memalign.c index 35b67599..8fb2002c 100644 --- a/src/malloc/memalign.c +++ b/src/malloc/memalign.c @@ -3,8 +3,6 @@ #include #include "libc.h" -void __internal_free(void *); - void *__memalign(size_t align, size_t len) { unsigned char *mem, *new, *end; @@ -15,7 +13,7 @@ void *__memalign(size_t align, size_t len) return NULL; } - if (len > SIZE_MAX - align || free != __internal_free) { + if (len > SIZE_MAX - align) { errno = ENOMEM; return NULL; } From 23389b1988b061e8487c316893a8a8eb77770a2f Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 19 Apr 2018 18:43:05 -0400 Subject: [PATCH 123/161] move malloc implementation types and macros to an internal header --- src/internal/malloc_impl.h | 39 ++++++++++++++++++++++++++++++++++++++ src/malloc/malloc.c | 38 +------------------------------------ 2 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 src/internal/malloc_impl.h diff --git a/src/internal/malloc_impl.h b/src/internal/malloc_impl.h new file mode 100644 index 00000000..1ea0407c --- /dev/null +++ b/src/internal/malloc_impl.h @@ -0,0 +1,39 @@ +#ifndef MALLOC_IMPL_H +#define MALLOC_IMPL_H + +void *__mmap(void *, size_t, int, int, int, off_t); +int __munmap(void *, size_t); +void *__mremap(void *, size_t, size_t, int, ...); +int __madvise(void *, size_t, int); + +struct chunk { + size_t psize, csize; + struct chunk *next, *prev; +}; + +struct bin { + volatile int lock[2]; + struct chunk *head; + struct chunk *tail; +}; + +#define SIZE_ALIGN (4*sizeof(size_t)) +#define SIZE_MASK (-SIZE_ALIGN) +#define OVERHEAD (2*sizeof(size_t)) +#define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN) +#define DONTCARE 16 +#define RECLAIM 163840 + +#define CHUNK_SIZE(c) ((c)->csize & -2) +#define CHUNK_PSIZE(c) ((c)->psize & -2) +#define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c))) +#define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c))) +#define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD) +#define CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD) +#define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head)) + +#define C_INUSE ((size_t)1) + +#define IS_MMAPPED(c) !((c)->csize & (C_INUSE)) + +#endif diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index da775921..c8bc9227 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -8,54 +8,18 @@ #include "libc.h" #include "atomic.h" #include "pthread_impl.h" +#include "malloc_impl.h" #if defined(__GNUC__) && defined(__PIC__) #define inline inline __attribute__((always_inline)) #endif -void *__mmap(void *, size_t, int, int, int, off_t); -int __munmap(void *, size_t); -void *__mremap(void *, size_t, size_t, int, ...); -int __madvise(void *, size_t, int); - -struct chunk { - size_t psize, csize; - struct chunk *next, *prev; -}; - -struct bin { - volatile int lock[2]; - struct chunk *head; - struct chunk *tail; -}; - static struct { volatile uint64_t binmap; struct bin bins[64]; volatile int free_lock[2]; } mal; - -#define SIZE_ALIGN (4*sizeof(size_t)) -#define SIZE_MASK (-SIZE_ALIGN) -#define OVERHEAD (2*sizeof(size_t)) -#define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN) -#define DONTCARE 16 -#define RECLAIM 163840 - -#define CHUNK_SIZE(c) ((c)->csize & -2) -#define CHUNK_PSIZE(c) ((c)->psize & -2) -#define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c))) -#define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c))) -#define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD) -#define CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD) -#define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head)) - -#define C_INUSE ((size_t)1) - -#define IS_MMAPPED(c) !((c)->csize & (C_INUSE)) - - /* Synchronization tools */ static inline void lock(volatile int *lk) From 3c2cbbe7ba8b4486299ae0d5336ae01ab520d116 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 19 Apr 2018 20:45:48 -0400 Subject: [PATCH 124/161] using malloc implementation types/macros/idioms for memalign the generated code should be mostly unchanged, except for explicit use of C_INUSE in place of copying the low bits from existing chunk headers/footers. these changes also remove mild UB due to dubious arithmetic on pointers into imaginary size_t[] arrays. --- src/malloc/memalign.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/src/malloc/memalign.c b/src/malloc/memalign.c index 8fb2002c..9c420229 100644 --- a/src/malloc/memalign.c +++ b/src/malloc/memalign.c @@ -2,49 +2,51 @@ #include #include #include "libc.h" +#include "malloc_impl.h" void *__memalign(size_t align, size_t len) { - unsigned char *mem, *new, *end; - size_t header, footer; + unsigned char *mem, *new; if ((align & -align) != align) { errno = EINVAL; - return NULL; + return 0; } if (len > SIZE_MAX - align) { errno = ENOMEM; - return NULL; + return 0; } - if (align <= 4*sizeof(size_t)) { - if (!(mem = malloc(len))) - return NULL; - return mem; - } + if (align <= SIZE_ALIGN) + return malloc(len); if (!(mem = malloc(len + align-1))) - return NULL; + return 0; new = (void *)((uintptr_t)mem + align-1 & -align); if (new == mem) return mem; - header = ((size_t *)mem)[-1]; + struct chunk *c = MEM_TO_CHUNK(mem); + struct chunk *n = MEM_TO_CHUNK(new); - if (!(header & 7)) { - ((size_t *)new)[-2] = ((size_t *)mem)[-2] + (new-mem); - ((size_t *)new)[-1] = ((size_t *)mem)[-1] - (new-mem); + if (IS_MMAPPED(c)) { + /* Apply difference between aligned and original + * address to the "extra" field of mmapped chunk. */ + n->psize = c->psize + (new-mem); + n->csize = c->csize - (new-mem); return new; } - end = mem + (header & -8); - footer = ((size_t *)end)[-2]; + struct chunk *t = NEXT_CHUNK(c); - ((size_t *)mem)[-1] = header&7 | new-mem; - ((size_t *)new)[-2] = footer&7 | new-mem; - ((size_t *)new)[-1] = header&7 | end-new; - ((size_t *)end)[-2] = footer&7 | end-new; + /* Split the allocated chunk into two chunks. The aligned part + * that will be used has the size in its footer reduced by the + * difference between the aligned and original addresses, and + * the resulting size copied to its header. A new header and + * footer are written for the split-off part to be freed. */ + n->psize = c->csize = C_INUSE | (new-mem); + n->csize = t->psize -= new-mem; free(mem); return new; From 72141795d4edd17f88da192447395a48444afa10 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 19 Apr 2018 20:56:26 -0400 Subject: [PATCH 125/161] return chunks split off by memalign using __bin_chunk instead of free this change serves multiple purposes: 1. it ensures that static linking of memalign-family functions will pull in the system malloc implementation, thereby causing link errors if an attempt is made to link the system memalign functions with a replacement malloc (incomplete allocator replacement). 2. it eliminates calls to free that are unpaired with allocations, which are confusing when setting breakpoints or tracing execution. as a bonus, making __bin_chunk external may discourage aggressive and unnecessary inlining of it. --- src/internal/malloc_impl.h | 3 +++ src/malloc/malloc.c | 10 ++++------ src/malloc/memalign.c | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/internal/malloc_impl.h b/src/internal/malloc_impl.h index 1ea0407c..4c4a4b46 100644 --- a/src/internal/malloc_impl.h +++ b/src/internal/malloc_impl.h @@ -36,4 +36,7 @@ struct bin { #define IS_MMAPPED(c) !((c)->csize & (C_INUSE)) +__attribute__((__visibility__("hidden"))) +void __bin_chunk(struct chunk *); + #endif diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index c8bc9227..239ab9c6 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -263,8 +263,6 @@ static int pretrim(struct chunk *self, size_t n, int i, int j) return 1; } -static void bin_chunk(struct chunk *); - static void trim(struct chunk *self, size_t n) { size_t n1 = CHUNK_SIZE(self); @@ -280,7 +278,7 @@ static void trim(struct chunk *self, size_t n) next->psize = n1-n | C_INUSE; self->csize = n | C_INUSE; - bin_chunk(split); + __bin_chunk(split); } void *malloc(size_t n) @@ -436,7 +434,7 @@ copy_free_ret: return new; } -static void bin_chunk(struct chunk *self) +void __bin_chunk(struct chunk *self) { struct chunk *next = NEXT_CHUNK(self); size_t final_size, new_size, size; @@ -524,7 +522,7 @@ void free(void *p) if (IS_MMAPPED(self)) unmap_chunk(self); else - bin_chunk(self); + __bin_chunk(self); } void __malloc_donate(char *start, char *end) @@ -543,5 +541,5 @@ void __malloc_donate(char *start, char *end) struct chunk *c = MEM_TO_CHUNK(start), *n = MEM_TO_CHUNK(end); c->psize = n->csize = C_INUSE; c->csize = n->psize = C_INUSE | (end-start); - bin_chunk(c); + __bin_chunk(c); } diff --git a/src/malloc/memalign.c b/src/malloc/memalign.c index 9c420229..7246a99b 100644 --- a/src/malloc/memalign.c +++ b/src/malloc/memalign.c @@ -48,7 +48,7 @@ void *__memalign(size_t align, size_t len) n->psize = c->csize = C_INUSE | (new-mem); n->csize = t->psize -= new-mem; - free(mem); + __bin_chunk(c); return new; } From b4b1e10364c8737a632be61582e05a8d3acf5690 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 19 Apr 2018 22:19:29 -0400 Subject: [PATCH 126/161] reintroduce hardening against partially-replaced allocator commit 618b18c78e33acfe54a4434e91aa57b8e171df89 removed the previous detection and hardening since it was incorrect. commit 72141795d4edd17f88da192447395a48444afa10 already handled all that remained for hardening the static-linked case. in the dynamic-linked case, have the dynamic linker check whether malloc was replaced and make that information available. with these changes, the properties documented in commit c9f415d7ea2dace5bf77f6518b6afc36bb7a5732 are restored: if calloc is not provided, it will behave as malloc+memset, and any of the memalign-family functions not provided will fail with ENOMEM. --- ldso/dynlink.c | 9 +++++++++ src/internal/malloc_impl.h | 3 +++ src/malloc/malloc.c | 13 +++++++++---- src/malloc/memalign.c | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ldso/dynlink.c b/ldso/dynlink.c index 63e7b81f..cea5f452 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -133,6 +133,9 @@ static struct dso *const nodeps_dummy; struct debug *_dl_debug_addr = &debug; +__attribute__((__visibility__("hidden"))) +extern int __malloc_replaced; + __attribute__((__visibility__("hidden"))) void (*const __init_array_start)(void)=0, (*const __fini_array_start)(void)=0; @@ -1691,6 +1694,12 @@ _Noreturn void __dls3(size_t *sp) if (ldso_fail) _exit(127); if (ldd_mode) _exit(0); + /* Determine if malloc was interposed by a replacement implementation + * so that calloc and the memalign family can harden against the + * possibility of incomplete replacement. */ + if (find_sym(head, "malloc", 1).dso != &ldso) + __malloc_replaced = 1; + /* Switch to runtime mode: any further failures in the dynamic * linker are a reportable failure rather than a fatal startup * error. */ diff --git a/src/internal/malloc_impl.h b/src/internal/malloc_impl.h index 4c4a4b46..5d025b06 100644 --- a/src/internal/malloc_impl.h +++ b/src/internal/malloc_impl.h @@ -39,4 +39,7 @@ struct bin { __attribute__((__visibility__("hidden"))) void __bin_chunk(struct chunk *); +__attribute__((__visibility__("hidden"))) +extern int __malloc_replaced; + #endif diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index 239ab9c6..d72883e1 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -20,6 +20,8 @@ static struct { volatile int free_lock[2]; } mal; +int __malloc_replaced; + /* Synchronization tools */ static inline void lock(volatile int *lk) @@ -356,10 +358,13 @@ void *calloc(size_t m, size_t n) } n *= m; void *p = malloc(n); - if (!p || IS_MMAPPED(MEM_TO_CHUNK(p))) - return p; - if (n >= PAGE_SIZE) - n = mal0_clear(p, PAGE_SIZE, n); + if (!p) return p; + if (!__malloc_replaced) { + if (IS_MMAPPED(MEM_TO_CHUNK(p))) + return p; + if (n >= PAGE_SIZE) + n = mal0_clear(p, PAGE_SIZE, n); + } return memset(p, 0, n); } diff --git a/src/malloc/memalign.c b/src/malloc/memalign.c index 7246a99b..8a6152f4 100644 --- a/src/malloc/memalign.c +++ b/src/malloc/memalign.c @@ -13,7 +13,7 @@ void *__memalign(size_t align, size_t len) return 0; } - if (len > SIZE_MAX - align) { + if (len > SIZE_MAX - align || __malloc_replaced) { errno = ENOMEM; return 0; } From 9be4ed5d89ecca80123311a4ec73781e5cc97a9c Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 27 Apr 2018 11:22:39 -0400 Subject: [PATCH 127/161] getopt_long_only: don't prefix-match long-options that match short ones for getopt_long, partial (prefix) matches of long options always begin with "--" and thus can never be ambiguous with a short option. for getopt_long_only, though, a single-character option can match both a short option and as a prefix for a long option. in this case, we wrongly interpreted it as a prefix for the long option. introduce a new pass, only in long-only mode, to check the prefix match against short options before accepting it. the only reason there's a slightly nontrivial loop being introduced rather than strchr is that our getopt already supports multibyte short options, and getopt_long_long should handle them consistently. a temp buffer and strstr could have been used, but the code to set it up would be just as large as what's introduced here and it would unnecessarily pull in relatively large code for strstr. --- src/misc/getopt_long.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/misc/getopt_long.c b/src/misc/getopt_long.c index 008b747c..ddcef949 100644 --- a/src/misc/getopt_long.c +++ b/src/misc/getopt_long.c @@ -1,5 +1,7 @@ #define _GNU_SOURCE #include +#include +#include #include #include #include @@ -58,10 +60,10 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring { int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':'; int i, cnt, match; - char *arg, *opt; + char *arg, *opt, *start = argv[optind]+1; for (cnt=i=0; longopts[i].name; i++) { const char *name = longopts[i].name; - opt = argv[optind]+1; + opt = start; if (*opt == '-') opt++; while (*opt && *opt != '=' && *opt == *name) name++, opt++; @@ -74,6 +76,17 @@ static int __getopt_long_core(int argc, char *const *argv, const char *optstring } cnt++; } + if (cnt==1 && longonly && arg-start == mblen(start, MB_LEN_MAX)) { + int l = arg-start; + for (i=0; optstring[i]; i++) { + int j; + for (j=0; j Date: Tue, 1 May 2018 14:34:22 -0400 Subject: [PATCH 128/161] work around arm gcc's rejection of r7 asm constraints in thumb mode in thumb mode, r7 is the ABI frame pointer register, and unless frame pointer is disabled, gcc insists on treating it as a fixed register, refusing to spill it to satisfy constraints. unfortunately, r7 is also used in the syscall ABI for passing the syscall number. up til now we just treated this as a requirement to disable frame pointer when generating code as thumb, but it turns out gcc forcibly enables frame pointer, and the fixed register constraint that goes with it, for functions which contain VLAs. this produces an unacceptable arch-specific constraint that (non-arm-specific) source files making syscalls cannot use VLAs. as a workaround, avoid r7 register constraints when producing thumb code and instead save/restore r7 in a temp register as part of the asm block. at some point we may want/need to support armv6-m/thumb1, so the asm has been tweaked to be thumb1-compatible while also near-optimal for thumb2: it allows the temp and/or syscall number to be in high registers (necessary since r0-r5 may all be used for syscalll args) and in thumb2 mode allows the syscall number to be an 8-bit immediate. --- arch/arm/syscall_arch.h | 53 ++++++++++++++++++++++++++++++----------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/arch/arm/syscall_arch.h b/arch/arm/syscall_arch.h index 6023303b..4db7d152 100644 --- a/arch/arm/syscall_arch.h +++ b/arch/arm/syscall_arch.h @@ -3,74 +3,99 @@ ((union { long long ll; long l[2]; }){ .ll = x }).l[1] #define __SYSCALL_LL_O(x) 0, __SYSCALL_LL_E((x)) +#ifdef __thumb__ + +/* Avoid use of r7 in asm constraints when producing thumb code, + * since it's reserved as frame pointer and might not be supported. */ +#define __ASM____R7__ +#define __asm_syscall(...) do { \ + __asm__ __volatile__ ( "mov %1,r7 ; mov r7,%2 ; svc 0 ; mov r7,%1" \ + : "=r"(r0), "=&r"((int){0}) : __VA_ARGS__ : "memory"); \ + return r0; \ + } while (0) + +#else + +#define __ASM____R7__ __asm__("r7") #define __asm_syscall(...) do { \ __asm__ __volatile__ ( "svc 0" \ : "=r"(r0) : __VA_ARGS__ : "memory"); \ return r0; \ } while (0) +#endif + +/* For thumb2, we can allow 8-bit immediate syscall numbers, saving a + * register in the above dance around r7. Does not work for thumb1 where + * only movs, not mov, supports immediates, and we can't use movs because + * it doesn't support high regs. */ +#ifdef __thumb2__ +#define R7_OPERAND "rI"(r7) +#else +#define R7_OPERAND "r"(r7) +#endif static inline long __syscall0(long n) { - register long r7 __asm__("r7") = n; + register long r7 __ASM____R7__ = n; register long r0 __asm__("r0"); - __asm_syscall("r"(r7)); + __asm_syscall(R7_OPERAND); } static inline long __syscall1(long n, long a) { - register long r7 __asm__("r7") = n; + register long r7 __ASM____R7__ = n; register long r0 __asm__("r0") = a; - __asm_syscall("r"(r7), "0"(r0)); + __asm_syscall(R7_OPERAND, "0"(r0)); } static inline long __syscall2(long n, long a, long b) { - register long r7 __asm__("r7") = n; + register long r7 __ASM____R7__ = n; register long r0 __asm__("r0") = a; register long r1 __asm__("r1") = b; - __asm_syscall("r"(r7), "0"(r0), "r"(r1)); + __asm_syscall(R7_OPERAND, "0"(r0), "r"(r1)); } static inline long __syscall3(long n, long a, long b, long c) { - register long r7 __asm__("r7") = n; + register long r7 __ASM____R7__ = n; register long r0 __asm__("r0") = a; register long r1 __asm__("r1") = b; register long r2 __asm__("r2") = c; - __asm_syscall("r"(r7), "0"(r0), "r"(r1), "r"(r2)); + __asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2)); } static inline long __syscall4(long n, long a, long b, long c, long d) { - register long r7 __asm__("r7") = n; + register long r7 __ASM____R7__ = n; register long r0 __asm__("r0") = a; register long r1 __asm__("r1") = b; register long r2 __asm__("r2") = c; register long r3 __asm__("r3") = d; - __asm_syscall("r"(r7), "0"(r0), "r"(r1), "r"(r2), "r"(r3)); + __asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2), "r"(r3)); } static inline long __syscall5(long n, long a, long b, long c, long d, long e) { - register long r7 __asm__("r7") = n; + register long r7 __ASM____R7__ = n; register long r0 __asm__("r0") = a; register long r1 __asm__("r1") = b; register long r2 __asm__("r2") = c; register long r3 __asm__("r3") = d; register long r4 __asm__("r4") = e; - __asm_syscall("r"(r7), "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4)); + __asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4)); } static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) { - register long r7 __asm__("r7") = n; + register long r7 __ASM____R7__ = n; register long r0 __asm__("r0") = a; register long r1 __asm__("r1") = b; register long r2 __asm__("r2") = c; register long r3 __asm__("r3") = d; register long r4 __asm__("r4") = e; register long r5 __asm__("r5") = f; - __asm_syscall("r"(r7), "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4), "r"(r5)); + __asm_syscall(R7_OPERAND, "0"(r0), "r"(r1), "r"(r2), "r"(r3), "r"(r4), "r"(r5)); } #define VDSO_USEFUL From 375840c7d8e1f58a9bf40ced72fbe82635f49489 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 1 May 2018 14:46:59 -0400 Subject: [PATCH 129/161] avoid excessive stack usage in getcwd to support the GNU extension of allocating a buffer for getcwd's result when a null pointer is passed without incurring a link dependency on free, we use a PATH_MAX-sized buffer on the stack and only duplicate it to allocated storage after the operation succeeds. unfortunately this imposed excessive stack usage on all callers, including those not making use of the GNU extension. instead, use a VLA to make stack allocation conditional. --- src/unistd/getcwd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unistd/getcwd.c b/src/unistd/getcwd.c index 103fbbb5..f407ffe0 100644 --- a/src/unistd/getcwd.c +++ b/src/unistd/getcwd.c @@ -6,10 +6,10 @@ char *getcwd(char *buf, size_t size) { - char tmp[PATH_MAX]; + char tmp[buf ? 1 : PATH_MAX]; if (!buf) { buf = tmp; - size = PATH_MAX; + size = sizeof tmp; } else if (!size) { errno = EINVAL; return 0; From 941bd884cc0221d051840ce6d21650339e711863 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 1 May 2018 16:56:02 -0400 Subject: [PATCH 130/161] optimize sigisemptyset the static const zero set ended up getting put in bss instead of rodata, wasting writable memory, and the call to memcmp was size-inefficient. generally for nonstandard extension functions we try to avoid poking at any internals directly, but the way the zero set was setup was arguably already doing so. --- src/signal/sigisemptyset.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/signal/sigisemptyset.c b/src/signal/sigisemptyset.c index 312c66cf..68b86624 100644 --- a/src/signal/sigisemptyset.c +++ b/src/signal/sigisemptyset.c @@ -4,6 +4,7 @@ int sigisemptyset(const sigset_t *set) { - static const unsigned long zeroset[_NSIG/8/sizeof(long)]; - return !memcmp(set, &zeroset, _NSIG/8); + for (size_t i=0; i<_NSIG/8/sizeof *set->__bits; i++) + if (set->__bits[i]) return 0; + return 1; } From 9e2d820a555e150df462f88c901fcbe25d692a8b Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 2 May 2018 12:13:43 -0400 Subject: [PATCH 131/161] use a dedicated futex object for pthread_join instead of tid field the tid field in the pthread structure is not volatile, and really shouldn't be, so as not to limit the compiler's ability to reorder, merge, or split loads in code paths that may be relevant to performance (like controlling lock ownership). however, use of objects which are not volatile or atomic with futex wait is inherently broken, since the compiler is free to transform a single load into multiple loads, thereby using a different value for the controlling expression of the loop and the value passed to the futex syscall, leading the syscall to block instead of returning. reportedly glibc's pthread_join was actually affected by an equivalent issue in glibc on s390. add a separate, dedicated join_futex object for pthread_join to use. --- src/env/__init_tls.c | 3 ++- src/internal/pthread_impl.h | 1 + src/thread/pthread_create.c | 3 ++- src/thread/pthread_join.c | 6 +++--- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c index b125eb1f..80044960 100644 --- a/src/env/__init_tls.c +++ b/src/env/__init_tls.c @@ -15,7 +15,8 @@ int __init_tp(void *p) int r = __set_thread_area(TP_ADJ(p)); if (r < 0) return -1; if (!r) libc.can_do_threads = 1; - td->tid = __syscall(SYS_set_tid_address, &td->tid); + td->join_futex = -1; + td->tid = __syscall(SYS_set_tid_address, &td->join_futex); td->locale = &libc.global_locale; td->robust_list.head = &td->robust_list.head; return 0; diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index f6a4f2c2..f2805b89 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -43,6 +43,7 @@ struct pthread { int unblock_cancel; volatile int timer_id; locale_t locale; + volatile int join_futex; volatile int killlock[1]; volatile int exitlock[1]; volatile int startlock[2]; diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 439ee363..ac06d7a7 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -282,9 +282,10 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att new->robust_list.head = &new->robust_list.head; new->unblock_cancel = self->cancel; new->CANARY = self->CANARY; + new->join_futex = -1; a_inc(&libc.threads_minus_1); - ret = __clone((c11 ? start_c11 : start), stack, flags, new, &new->tid, TP_ADJ(new), &new->tid); + ret = __clone((c11 ? start_c11 : start), stack, flags, new, &new->tid, TP_ADJ(new), &new->join_futex); __release_ptc(); diff --git a/src/thread/pthread_join.c b/src/thread/pthread_join.c index b7175c09..67eaf9d8 100644 --- a/src/thread/pthread_join.c +++ b/src/thread/pthread_join.c @@ -12,8 +12,8 @@ int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at) __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); if (cs == PTHREAD_CANCEL_ENABLE) __pthread_setcancelstate(cs, 0); if (t->detached) a_crash(); - while ((tmp = t->tid) && r != ETIMEDOUT && r != EINVAL) - r = __timedwait_cp(&t->tid, tmp, CLOCK_REALTIME, at, 0); + while ((tmp = t->join_futex) && r != ETIMEDOUT && r != EINVAL) + r = __timedwait_cp(&t->join_futex, tmp, CLOCK_REALTIME, at, 0); __pthread_setcancelstate(cs, 0); if (r == ETIMEDOUT || r == EINVAL) return r; a_barrier(); @@ -29,7 +29,7 @@ int __pthread_join(pthread_t t, void **res) int __pthread_tryjoin_np(pthread_t t, void **res) { - return t->tid ? EBUSY : __pthread_join(t, res); + return t->join_futex ? EBUSY : __pthread_join(t, res); } weak_alias(__pthread_tryjoin_np, pthread_tryjoin_np); From 4df42163511182bfd6fc55e85250b93786dcce7e Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 4 May 2018 13:18:51 -0400 Subject: [PATCH 132/161] remove incorrect ESRCH error from pthread_kill posix documents in the rationale and future directions for pthread_kill that, since the lifetime of the thread id for a joinable thread lasts until it is joined, ESRCH is not a correct error for pthread_kill to produce when the target thread has exited but not yet been joined, and that conforming applications cannot attempt to detect this state. future versions of the standard may explicitly require that ESRCH not be returned for this case. --- src/thread/pthread_kill.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/thread/pthread_kill.c b/src/thread/pthread_kill.c index f0903420..0a139231 100644 --- a/src/thread/pthread_kill.c +++ b/src/thread/pthread_kill.c @@ -4,7 +4,8 @@ int pthread_kill(pthread_t t, int sig) { int r; LOCK(t->killlock); - r = t->dead ? ESRCH : -__syscall(SYS_tkill, t->tid, sig); + r = t->dead ? (sig+0U >= _NSIG ? EINVAL : 0) + : -__syscall(SYS_tkill, t->tid, sig); UNLOCK(t->killlock); return r; } From 526e64f54d729947b35fd39129bc86cbc0b5f098 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 4 May 2018 14:26:31 -0400 Subject: [PATCH 133/161] improve pthread_exit synchronization with functions targeting tid if the last thread exited via pthread_exit, the logic that marked it dead did not account for the possibility of it targeting itself via atexit handlers. for example, an atexit handler calling pthread_kill(pthread_self(), SIGKILL) would return success (previously, ESRCH) rather than causing termination via the signal. move the release of killlock after the determination is made whether the exiting thread is the last thread. in the case where it's not, move the release all the way to the end of the function. this way we can clear the tid rather than spending storage on a dedicated dead-flag. clearing the tid is also preferable in that it hardens against inadvertent use of the value after the thread has terminated but before it is joined. --- src/internal/pthread_impl.h | 1 - src/thread/pthread_create.c | 24 +++++++++++++----------- src/thread/pthread_getschedparam.c | 2 +- src/thread/pthread_kill.c | 4 ++-- src/thread/pthread_setschedparam.c | 2 +- src/thread/pthread_setschedprio.c | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index f2805b89..3b4ad94d 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -34,7 +34,6 @@ struct pthread { void *result; struct __ptcb *cancelbuf; void **tsd; - volatile int dead; struct { volatile void *volatile head; long off; diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index ac06d7a7..a86b5e1b 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -39,9 +39,11 @@ _Noreturn void __pthread_exit(void *result) LOCK(self->exitlock); - /* Mark this thread dead before decrementing count */ + /* Access to target the exiting thread with syscalls that use + * its kernel tid is controlled by killlock. For detached threads, + * any use past this point would have undefined behavior, but for + * joinable threads it's a valid usage that must be handled. */ LOCK(self->killlock); - self->dead = 1; /* Block all signals before decrementing the live thread count. * This is important to ensure that dynamically allocated TLS @@ -49,20 +51,14 @@ _Noreturn void __pthread_exit(void *result) * reasons as well. */ __block_all_sigs(&set); - /* Wait to unlock the kill lock, which governs functions like - * pthread_kill which target a thread id, until signals have - * been blocked. This precludes observation of the thread id - * as a live thread (with application code running in it) after - * the thread was reported dead by ESRCH being returned. */ - UNLOCK(self->killlock); - /* It's impossible to determine whether this is "the last thread" * until performing the atomic decrement, since multiple threads * could exit at the same time. For the last thread, revert the - * decrement and unblock signals to give the atexit handlers and - * stdio cleanup code a consistent state. */ + * decrement, restore the tid, and unblock signals to give the + * atexit handlers and stdio cleanup code a consistent state. */ if (a_fetch_add(&libc.threads_minus_1, -1)==0) { libc.threads_minus_1 = 0; + UNLOCK(self->killlock); __restore_sigs(&set); exit(0); } @@ -113,6 +109,12 @@ _Noreturn void __pthread_exit(void *result) __unmapself(self->map_base, self->map_size); } + /* After the kernel thread exits, its tid may be reused. Clear it + * to prevent inadvertent use and inform functions that would use + * it that it's no longer available. */ + self->tid = 0; + UNLOCK(self->killlock); + for (;;) __syscall(SYS_exit, 0); } diff --git a/src/thread/pthread_getschedparam.c b/src/thread/pthread_getschedparam.c index a994b637..05be4242 100644 --- a/src/thread/pthread_getschedparam.c +++ b/src/thread/pthread_getschedparam.c @@ -4,7 +4,7 @@ int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param { int r; LOCK(t->killlock); - if (t->dead) { + if (!t->tid) { r = ESRCH; } else { r = -__syscall(SYS_sched_getparam, t->tid, param); diff --git a/src/thread/pthread_kill.c b/src/thread/pthread_kill.c index 0a139231..6d70e626 100644 --- a/src/thread/pthread_kill.c +++ b/src/thread/pthread_kill.c @@ -4,8 +4,8 @@ int pthread_kill(pthread_t t, int sig) { int r; LOCK(t->killlock); - r = t->dead ? (sig+0U >= _NSIG ? EINVAL : 0) - : -__syscall(SYS_tkill, t->tid, sig); + r = t->tid ? -__syscall(SYS_tkill, t->tid, sig) + : (sig+0U >= _NSIG ? EINVAL : 0); UNLOCK(t->killlock); return r; } diff --git a/src/thread/pthread_setschedparam.c b/src/thread/pthread_setschedparam.c index 9e2fa456..ab45f2ff 100644 --- a/src/thread/pthread_setschedparam.c +++ b/src/thread/pthread_setschedparam.c @@ -4,7 +4,7 @@ int pthread_setschedparam(pthread_t t, int policy, const struct sched_param *par { int r; LOCK(t->killlock); - r = t->dead ? ESRCH : -__syscall(SYS_sched_setscheduler, t->tid, policy, param); + r = !t->tid ? ESRCH : -__syscall(SYS_sched_setscheduler, t->tid, policy, param); UNLOCK(t->killlock); return r; } diff --git a/src/thread/pthread_setschedprio.c b/src/thread/pthread_setschedprio.c index dc745b42..c353f6b5 100644 --- a/src/thread/pthread_setschedprio.c +++ b/src/thread/pthread_setschedprio.c @@ -4,7 +4,7 @@ int pthread_setschedprio(pthread_t t, int prio) { int r; LOCK(t->killlock); - r = t->dead ? ESRCH : -__syscall(SYS_sched_setparam, t->tid, &prio); + r = !t->tid ? ESRCH : -__syscall(SYS_sched_setparam, t->tid, &prio); UNLOCK(t->killlock); return r; } From cdba6b2562bc5c2078e0e1e6f86c8835a42ae4ff Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Sat, 5 May 2018 21:33:58 -0400 Subject: [PATCH 134/161] improve joinable/detached thread state handling previously, some accesses to the detached state (from pthread_join and pthread_getattr_np) were unsynchronized; they were harmless in programs with well-defined behavior, but ugly. other accesses (in pthread_exit and pthread_detach) were synchronized by a poorly named "exitlock", with an ad-hoc trylock operation on it open-coded in pthread_detach, whose only purpose was establishing protocol for which thread is responsible for deallocation of detached-thread resources. instead, use an atomic detach_state and unify it with the futex used to wait for thread exit. this eliminates 2 members from the pthread structure, gets rid of the hackish lock usage, and makes rigorous the trap added in commit 80bf5952551c002cf12d96deb145629765272db0 for catching attempts to join detached threads. it should also make attempt to detach an already-detached thread reliably trap. --- src/env/__init_tls.c | 4 ++-- src/internal/pthread_impl.h | 12 +++++++++--- src/thread/pthread_create.c | 21 ++++++++++++--------- src/thread/pthread_detach.c | 7 +++---- src/thread/pthread_getattr_np.c | 2 +- src/thread/pthread_join.c | 11 ++++++----- 6 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c index 80044960..1c5d98a0 100644 --- a/src/env/__init_tls.c +++ b/src/env/__init_tls.c @@ -15,8 +15,8 @@ int __init_tp(void *p) int r = __set_thread_area(TP_ADJ(p)); if (r < 0) return -1; if (!r) libc.can_do_threads = 1; - td->join_futex = -1; - td->tid = __syscall(SYS_set_tid_address, &td->join_futex); + td->detach_state = DT_JOINABLE; + td->tid = __syscall(SYS_set_tid_address, &td->detach_state); td->locale = &libc.global_locale; td->robust_list.head = &td->robust_list.head; return 0; diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index 3b4ad94d..0a65fa37 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -24,7 +24,7 @@ struct pthread { /* Part 2 -- implementation details, non-ABI. */ int tsd_used, errno_val; volatile int cancel, canceldisable, cancelasync; - int detached; + volatile int detach_state; unsigned char *map_base; size_t map_size; void *stack; @@ -42,9 +42,7 @@ struct pthread { int unblock_cancel; volatile int timer_id; locale_t locale; - volatile int join_futex; volatile int killlock[1]; - volatile int exitlock[1]; volatile int startlock[2]; unsigned long sigmask[_NSIG/8/sizeof(long)]; char *dlerror_buf; @@ -58,6 +56,14 @@ struct pthread { void **dtv_copy; }; +enum { + DT_EXITED = 0, + DT_EXITING, + DT_JOINABLE, + DT_DETACHED, + DT_DYNAMIC, +}; + struct __timer { int timerid; pthread_t thread; diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index a86b5e1b..e07d29e3 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -37,8 +37,6 @@ _Noreturn void __pthread_exit(void *result) __pthread_tsd_run_dtors(); - LOCK(self->exitlock); - /* Access to target the exiting thread with syscalls that use * its kernel tid is controlled by killlock. For detached threads, * any use past this point would have undefined behavior, but for @@ -85,15 +83,19 @@ _Noreturn void __pthread_exit(void *result) __do_orphaned_stdio_locks(); __dl_thread_cleanup(); - if (self->detached && self->map_base) { + /* This atomic potentially competes with a concurrent pthread_detach + * call; the loser is responsible for freeing thread resources. */ + int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING); + + if (state>=DT_DETACHED && self->map_base) { /* Detached threads must avoid the kernel clear_child_tid * feature, since the virtual address will have been * unmapped and possibly already reused by a new mapping * at the time the kernel would perform the write. In * the case of threads that started out detached, the * initial clone flags are correct, but if the thread was - * detached later (== 2), we need to clear it here. */ - if (self->detached == 2) __syscall(SYS_set_tid_address, 0); + * detached later, we need to clear it here. */ + if (state == DT_DYNAMIC) __syscall(SYS_set_tid_address, 0); /* Robust list will no longer be valid, and was already * processed above, so unregister it with the kernel. */ @@ -141,7 +143,7 @@ static int start(void *p) if (self->startlock[0]) { __wait(self->startlock, 0, 1, 1); if (self->startlock[0] == 2) { - self->detached = 2; + self->detach_state = DT_DYNAMIC; pthread_exit(0); } __restore_sigs(self->sigmask); @@ -274,8 +276,10 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att new->tsd = (void *)tsd; new->locale = &libc.global_locale; if (attr._a_detach) { - new->detached = 1; + new->detach_state = DT_DETACHED; flags -= CLONE_CHILD_CLEARTID; + } else { + new->detach_state = DT_JOINABLE; } if (attr._a_sched) { do_sched = new->startlock[0] = 1; @@ -284,10 +288,9 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att new->robust_list.head = &new->robust_list.head; new->unblock_cancel = self->cancel; new->CANARY = self->CANARY; - new->join_futex = -1; a_inc(&libc.threads_minus_1); - ret = __clone((c11 ? start_c11 : start), stack, flags, new, &new->tid, TP_ADJ(new), &new->join_futex); + ret = __clone((c11 ? start_c11 : start), stack, flags, new, &new->tid, TP_ADJ(new), &new->detach_state); __release_ptc(); diff --git a/src/thread/pthread_detach.c b/src/thread/pthread_detach.c index 692bbaf9..9cee7a89 100644 --- a/src/thread/pthread_detach.c +++ b/src/thread/pthread_detach.c @@ -5,11 +5,10 @@ int __pthread_join(pthread_t, void **); static int __pthread_detach(pthread_t t) { - /* Cannot detach a thread that's already exiting */ - if (a_cas(t->exitlock, 0, INT_MIN + 1)) + /* If the cas fails, detach state is either already-detached + * or exiting/exited, and pthread_join will trap or cleanup. */ + if (a_cas(&t->detach_state, DT_JOINABLE, DT_DYNAMIC) != DT_JOINABLE) return __pthread_join(t, 0); - t->detached = 2; - UNLOCK(t->exitlock); return 0; } diff --git a/src/thread/pthread_getattr_np.c b/src/thread/pthread_getattr_np.c index 29a209bd..2881831f 100644 --- a/src/thread/pthread_getattr_np.c +++ b/src/thread/pthread_getattr_np.c @@ -6,7 +6,7 @@ int pthread_getattr_np(pthread_t t, pthread_attr_t *a) { *a = (pthread_attr_t){0}; - a->_a_detach = !!t->detached; + a->_a_detach = t->detach_state>=DT_DETACHED; a->_a_guardsize = t->guard_size; if (t->stack) { a->_a_stackaddr = (uintptr_t)t->stack; diff --git a/src/thread/pthread_join.c b/src/thread/pthread_join.c index 67eaf9d8..18264da6 100644 --- a/src/thread/pthread_join.c +++ b/src/thread/pthread_join.c @@ -7,13 +7,14 @@ int __pthread_setcancelstate(int, int *); int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at) { - int tmp, cs, r = 0; + int state, cs, r = 0; __pthread_testcancel(); __pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); if (cs == PTHREAD_CANCEL_ENABLE) __pthread_setcancelstate(cs, 0); - if (t->detached) a_crash(); - while ((tmp = t->join_futex) && r != ETIMEDOUT && r != EINVAL) - r = __timedwait_cp(&t->join_futex, tmp, CLOCK_REALTIME, at, 0); + while ((state = t->detach_state) && r != ETIMEDOUT && r != EINVAL) { + if (state >= DT_DETACHED) a_crash(); + r = __timedwait_cp(&t->detach_state, state, CLOCK_REALTIME, at, 0); + } __pthread_setcancelstate(cs, 0); if (r == ETIMEDOUT || r == EINVAL) return r; a_barrier(); @@ -29,7 +30,7 @@ int __pthread_join(pthread_t t, void **res) int __pthread_tryjoin_np(pthread_t t, void **res) { - return t->join_futex ? EBUSY : __pthread_join(t, res); + return t->detach_state==DT_JOINABLE ? EBUSY : __pthread_join(t, res); } weak_alias(__pthread_tryjoin_np, pthread_tryjoin_np); From 1db9a35569d51155eb7f2ccf26d420ae4e42e416 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 7 May 2018 22:39:07 -0400 Subject: [PATCH 135/161] clean up and reduce size of internal pthread structure over time the pthread structure has accumulated a lot of cruft taking up size. this commit removes unused fields and packs booleans and other small data more efficiently. changes which would also require changing code are not included at this time. non-volatile booleans are packed as unsigned char bitfield members. the canceldisable and cancelasync fields need volatile qualification due to how they're accessed from the cancellation signal handler and cancellable syscalls called from signal handlers. since volatile bitfield semantics are not clearly defined, discrete char objects are used instead. the pid field is completely removed; it has been unused since commit 83dc6eb087633abcf5608ad651d3b525ca2ec35e. the tid field's type is changed to int because its use is as a value in futexes, which are defined as plain int. it has no conceptual relationship to pid_t. also, its position is not ABI. startlock is reduced to a length-1 array. the second element was presumably intended as a waiter count, but it was never used and made no sense, since there is at most one waiter. --- src/internal/pthread_impl.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index 0a65fa37..fc2def63 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -19,16 +19,21 @@ struct pthread { void **dtv, *unused1, *unused2; uintptr_t sysinfo; uintptr_t canary, canary2; - pid_t tid, pid; /* Part 2 -- implementation details, non-ABI. */ - int tsd_used, errno_val; - volatile int cancel, canceldisable, cancelasync; + int tid; + int errno_val; volatile int detach_state; + volatile int cancel; + volatile unsigned char canceldisable, cancelasync; + unsigned char tsd_used:1; + unsigned char unblock_cancel:1; + unsigned char dlerror_flag:1; unsigned char *map_base; size_t map_size; void *stack; size_t stack_size; + size_t guard_size; void *start_arg; void *(*start)(void *); void *result; @@ -39,16 +44,13 @@ struct pthread { long off; volatile void *volatile pending; } robust_list; - int unblock_cancel; volatile int timer_id; locale_t locale; volatile int killlock[1]; - volatile int startlock[2]; + volatile int startlock[1]; unsigned long sigmask[_NSIG/8/sizeof(long)]; char *dlerror_buf; - int dlerror_flag; void *stdio_locks; - size_t guard_size; /* Part 3 -- the positions of these fields relative to * the end of the structure is external and internal ABI. */ From b8742f32602add243ee2ce74d804015463726899 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 9 May 2018 00:14:13 -0400 Subject: [PATCH 136/161] improve design of thread-start with explicit scheduling attributes eliminate the awkward startlock mechanism and corresponding fields of the pthread structure that were only used at startup. instead of having pthread_create perform the scheduling operations and having the new thread wait for them to be completed, start the new thread with a wrapper start function that performs its own scheduling, sending the result code back via a futex. this way the new thread can use storage from the calling thread's stack rather than permanent fields in the pthread structure. --- src/internal/pthread_impl.h | 2 -- src/thread/pthread_create.c | 60 ++++++++++++++++++++++++------------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index fc2def63..69352ef2 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -47,8 +47,6 @@ struct pthread { volatile int timer_id; locale_t locale; volatile int killlock[1]; - volatile int startlock[1]; - unsigned long sigmask[_NSIG/8/sizeof(long)]; char *dlerror_buf; void *stdio_locks; diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index e07d29e3..5f07ab49 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -132,22 +132,36 @@ void __do_cleanup_pop(struct __ptcb *cb) __pthread_self()->cancelbuf = cb->__next; } +struct start_sched_args { + void *start_arg; + void *(*start_fn)(void *); + sigset_t mask; + pthread_attr_t *attr; + volatile int futex; +}; + +static void *start_sched(void *p) +{ + struct start_sched_args *ssa = p; + void *start_arg = ssa->start_arg; + void *(*start_fn)(void *) = ssa->start_fn; + pthread_t self = __pthread_self(); + + int ret = -__syscall(SYS_sched_setscheduler, self->tid, + ssa->attr->_a_policy, &ssa->attr->_a_prio); + if (!ret) __restore_sigs(&ssa->mask); + a_store(&ssa->futex, ret); + __wake(&ssa->futex, 1, 1); + if (ret) { + self->detach_state = DT_DYNAMIC; + return 0; + } + return start_fn(start_arg); +} + static int start(void *p) { pthread_t self = p; - /* States for startlock: - * 0 = no need for start sync - * 1 = waiting for parent to do work - * 2 = failure in parent, child must abort - * 3 = success in parent, child must restore sigmask */ - if (self->startlock[0]) { - __wait(self->startlock, 0, 1, 1); - if (self->startlock[0] == 2) { - self->detach_state = DT_DYNAMIC; - pthread_exit(0); - } - __restore_sigs(self->sigmask); - } if (self->unblock_cancel) __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, _NSIG/8); @@ -198,6 +212,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED; int do_sched = 0; pthread_attr_t attr = { 0 }; + struct start_sched_args ssa; if (!libc.can_do_threads) return ENOSYS; self = __pthread_self(); @@ -282,8 +297,14 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att new->detach_state = DT_JOINABLE; } if (attr._a_sched) { - do_sched = new->startlock[0] = 1; - __block_app_sigs(new->sigmask); + do_sched = 1; + ssa.futex = -1; + ssa.start_fn = new->start; + ssa.start_arg = new->start_arg; + ssa.attr = &attr; + new->start = start_sched; + new->start_arg = &ssa; + __block_app_sigs(&ssa.mask); } new->robust_list.head = &new->robust_list.head; new->unblock_cancel = self->cancel; @@ -295,7 +316,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att __release_ptc(); if (do_sched) { - __restore_sigs(new->sigmask); + __restore_sigs(&ssa.mask); } if (ret < 0) { @@ -305,11 +326,8 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att } if (do_sched) { - ret = __syscall(SYS_sched_setscheduler, new->tid, - attr._a_policy, &attr._a_prio); - a_store(new->startlock, ret<0 ? 2 : 3); - __wake(new->startlock, 1, 1); - if (ret < 0) return -ret; + __futexwait(&ssa.futex, -1, 1); + if (ret) return ret; } *res = new; From 40bae2d32fd6f3ffea437fa745ad38a1fe77b27e Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 9 May 2018 00:33:54 -0400 Subject: [PATCH 137/161] make linking of thread-start with explicit scheduling conditional the wrapper start function that performs scheduling operations is unreachable if pthread_attr_setinheritsched is never called, so move it there rather than the pthread_create source file, saving some code size for static-linked programs. --- src/internal/pthread_impl.h | 8 ++++++ src/thread/pthread_attr_setinheritsched.c | 21 ++++++++++++++ src/thread/pthread_create.c | 35 +++++------------------ 3 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/internal/pthread_impl.h b/src/internal/pthread_impl.h index 69352ef2..c2deffb9 100644 --- a/src/internal/pthread_impl.h +++ b/src/internal/pthread_impl.h @@ -56,6 +56,14 @@ struct pthread { void **dtv_copy; }; +struct start_sched_args { + void *start_arg; + void *(*start_fn)(void *); + sigset_t mask; + pthread_attr_t *attr; + volatile int futex; +}; + enum { DT_EXITED = 0, DT_EXITING, diff --git a/src/thread/pthread_attr_setinheritsched.c b/src/thread/pthread_attr_setinheritsched.c index c91d8f83..e540e846 100644 --- a/src/thread/pthread_attr_setinheritsched.c +++ b/src/thread/pthread_attr_setinheritsched.c @@ -1,4 +1,25 @@ #include "pthread_impl.h" +#include "syscall.h" + +__attribute__((__visibility__("hidden"))) +void *__start_sched(void *p) +{ + struct start_sched_args *ssa = p; + void *start_arg = ssa->start_arg; + void *(*start_fn)(void *) = ssa->start_fn; + pthread_t self = __pthread_self(); + + int ret = -__syscall(SYS_sched_setscheduler, self->tid, + ssa->attr->_a_policy, &ssa->attr->_a_prio); + if (!ret) __restore_sigs(&ssa->mask); + a_store(&ssa->futex, ret); + __wake(&ssa->futex, 1, 1); + if (ret) { + self->detach_state = DT_DYNAMIC; + return 0; + } + return start_fn(start_arg); +} int pthread_attr_setinheritsched(pthread_attr_t *a, int inherit) { diff --git a/src/thread/pthread_create.c b/src/thread/pthread_create.c index 5f07ab49..2c066cff 100644 --- a/src/thread/pthread_create.c +++ b/src/thread/pthread_create.c @@ -19,6 +19,12 @@ weak_alias(dummy_0, __pthread_tsd_run_dtors); weak_alias(dummy_0, __do_orphaned_stdio_locks); weak_alias(dummy_0, __dl_thread_cleanup); +static void *dummy_1(void *p) +{ + return 0; +} +weak_alias(dummy_1, __start_sched); + _Noreturn void __pthread_exit(void *result) { pthread_t self = __pthread_self(); @@ -132,33 +138,6 @@ void __do_cleanup_pop(struct __ptcb *cb) __pthread_self()->cancelbuf = cb->__next; } -struct start_sched_args { - void *start_arg; - void *(*start_fn)(void *); - sigset_t mask; - pthread_attr_t *attr; - volatile int futex; -}; - -static void *start_sched(void *p) -{ - struct start_sched_args *ssa = p; - void *start_arg = ssa->start_arg; - void *(*start_fn)(void *) = ssa->start_fn; - pthread_t self = __pthread_self(); - - int ret = -__syscall(SYS_sched_setscheduler, self->tid, - ssa->attr->_a_policy, &ssa->attr->_a_prio); - if (!ret) __restore_sigs(&ssa->mask); - a_store(&ssa->futex, ret); - __wake(&ssa->futex, 1, 1); - if (ret) { - self->detach_state = DT_DYNAMIC; - return 0; - } - return start_fn(start_arg); -} - static int start(void *p) { pthread_t self = p; @@ -302,7 +281,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att ssa.start_fn = new->start; ssa.start_arg = new->start_arg; ssa.attr = &attr; - new->start = start_sched; + new->start = __start_sched; new->start_arg = &ssa; __block_app_sigs(&ssa.mask); } From 55a661ff5ec5c8192091ec0bd74424500761b08d Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Tue, 1 May 2018 14:16:44 -0500 Subject: [PATCH 138/161] fix iconv buffer overflow converting to legacy JIS-based encodings maintainer's notes: commit a223dbd27ae36fe53f9f67f86caf685b729593fc added the reverse conversions to JIS-based encodings, but omitted the check for remining buffer space in the case where the next character to be written was single-byte, allowing conversion to continue past the end of the destination buffer. --- src/locale/iconv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/locale/iconv.c b/src/locale/iconv.c index d469856c..3c1f4dd2 100644 --- a/src/locale/iconv.c +++ b/src/locale/iconv.c @@ -539,6 +539,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri if (*outb < 1) goto toobig; if (c<256 && c==legacy_map(tomap, c)) { revout: + if (*outb < 1) goto toobig; *(*out)++ = c; *outb -= 1; break; From 99f4237a691349b24afbed29abf33124b89c1ea3 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Thu, 3 May 2018 13:44:53 -0500 Subject: [PATCH 139/161] fix iconv conversion to UTF-32 with implicit (big) endianness maintainer's notes: commit 95c6044e2ae85846330814c4ac5ebf4102dbe02c split UTF-32 and UTF-32BE but neglected to add a case for the former as a destination encoding, resulting in it wrongly being handled by the default case. the intent was that the value of the macro be chosen to encode "big endian" in the low bits, so that no code would be needed, but this was botched; instead, handle it the way UCS2 is handled. --- src/locale/iconv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/locale/iconv.c b/src/locale/iconv.c index 3c1f4dd2..3a34395c 100644 --- a/src/locale/iconv.c +++ b/src/locale/iconv.c @@ -646,6 +646,8 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri *out += 4; *outb -= 4; break; + case UTF_32: + totype = UTF_32BE; case UTF_32BE: case UTF_32LE: if (*outb < 4) goto toobig; From 165a1e37a570422c3f3f816a734bfea0366982e5 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 1 Jun 2018 21:50:17 -0400 Subject: [PATCH 140/161] fix iconv mapping of big5-hkscs characters that map to two unicode chars this case is handled with a recursive call to iconv using a specially-constructed conversion descriptor. the constant 0 was used as the offset for utf-8, since utf-8 appears first in the charmaps table, but the offset used needs to point into the charmap entry, past the name/aliases at the beginning, to the byte identifying the encoding. as a result of this error, junk was produced. instead, call find_charmap so we don't have to hard-code a nontrivial offset. with this change, the code has been tested and found to work in the case of converting the affected hkscs characters to utf-8. --- src/locale/iconv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/locale/iconv.c b/src/locale/iconv.c index 3a34395c..05d42095 100644 --- a/src/locale/iconv.c +++ b/src/locale/iconv.c @@ -461,7 +461,7 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri if (totype-0300U > 8) k = 2; else k = "\10\4\4\10\4\4\10\2\4"[totype-0300]; if (k > *outb) goto toobig; - x += iconv(combine_to_from(to, 0), + x += iconv(combine_to_from(to, find_charmap("utf8")), &(char *){"\303\212\314\204" "\303\212\314\214" "\303\252\314\204" From 029c622a89bf8cc15fd9fd56e8e88465ca6130cf Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Fri, 1 Jun 2018 22:05:48 -0400 Subject: [PATCH 141/161] fix output size handling for multi-unicode-char big5-hkscs characters since this iconv implementation's output is stateless, it's necessary to know before writing anything to the output buffer whether the conversion of the current input character will fit. previously we used a hard-coded table of the output size needed for each supported output encoding, but failed to update the table when adding support for conversion to jis-based encodings and again when adding separate encoding identifiers for implicit-endianness utf-16/32 and ucs-2/4 variants, resulting in out-of-bound table reads and incorrect size checks. no buffer overflow was possible, but the affected characters could be converted incorrectly, and iconv could potentially produce an incorrect return value as a result. remove the hard-coded table, and instead perform the recursive iconv conversion to a temporary buffer, measuring the output size and transferring it to the actual output buffer only if the whole converted result fits. --- src/locale/iconv.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/locale/iconv.c b/src/locale/iconv.c index 05d42095..3047c27b 100644 --- a/src/locale/iconv.c +++ b/src/locale/iconv.c @@ -458,16 +458,24 @@ size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restri * range in the hkscs table then hard-coded * here. Ugly, yes. */ if (c/256 == 0xdc) { - if (totype-0300U > 8) k = 2; - else k = "\10\4\4\10\4\4\10\2\4"[totype-0300]; - if (k > *outb) goto toobig; - x += iconv(combine_to_from(to, find_charmap("utf8")), + union { + char c[8]; + wchar_t wc[2]; + } tmp; + char *ptmp = tmp.c; + size_t tmpx = iconv(combine_to_from(to, find_charmap("utf8")), &(char *){"\303\212\314\204" "\303\212\314\214" "\303\252\314\204" "\303\252\314\214" +c%256}, &(size_t){4}, - out, outb); + &ptmp, &(size_t){sizeof tmp}); + size_t tmplen = ptmp - tmp.c; + if (tmplen > *outb) goto toobig; + if (tmpx) x++; + memcpy(*out, &tmp, tmplen); + *out += tmplen; + *outb -= tmplen; continue; } if (!c) goto ilseq; From 610c5a8524c3d6cd3ac5a5f1231422e7648a3791 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 2 Jun 2018 01:52:01 +0200 Subject: [PATCH 142/161] fix TLS layout of TLS variant I when there is a gap above TP In TLS variant I the TLS is above TP (or above a fixed offset from TP) but on some targets there is a reserved gap above TP before TLS starts. This matters for the local-exec tls access model when the offsets of TLS variables from the TP are hard coded by the linker into the executable, so the libc must compute these offsets the same way as the linker. The tls offset of the main module has to be alignup(GAP_ABOVE_TP, main_tls_align). If there is no TLS in the main module then the gap can be ignored since musl does not use it and the tls access models of shared libraries are not affected. The previous setup only worked if (tls_align & -GAP_ABOVE_TP) == 0 (i.e. TLS did not require large alignment) because the gap was treated as a fixed offset from TP. Now the TP points at the end of the pthread struct (which is aligned) and there is a gap above it (which may also need alignment). The fix required changing TP_ADJ and __pthread_self on affected targets (aarch64, arm and sh) and in the tlsdesc asm the offset to access the dtv changed too. --- arch/aarch64/pthread_arch.h | 5 +++-- arch/aarch64/reloc.h | 2 +- arch/arm/pthread_arch.h | 7 ++++--- arch/arm/reloc.h | 2 +- arch/mips/pthread_arch.h | 1 + arch/mips64/pthread_arch.h | 1 + arch/mipsn32/pthread_arch.h | 1 + arch/or1k/pthread_arch.h | 1 + arch/powerpc/pthread_arch.h | 1 + arch/powerpc64/pthread_arch.h | 1 + arch/sh/pthread_arch.h | 5 +++-- arch/sh/reloc.h | 2 +- ldso/dynlink.c | 5 +++-- src/env/__init_tls.c | 10 ++++++++-- src/ldso/aarch64/tlsdesc.s | 5 ++--- 15 files changed, 32 insertions(+), 17 deletions(-) diff --git a/arch/aarch64/pthread_arch.h b/arch/aarch64/pthread_arch.h index b2e2d8f1..e8499d8e 100644 --- a/arch/aarch64/pthread_arch.h +++ b/arch/aarch64/pthread_arch.h @@ -2,10 +2,11 @@ static inline struct pthread *__pthread_self() { char *self; __asm__ __volatile__ ("mrs %0,tpidr_el0" : "=r"(self)); - return (void*)(self + 16 - sizeof(struct pthread)); + return (void*)(self - sizeof(struct pthread)); } #define TLS_ABOVE_TP -#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 16) +#define GAP_ABOVE_TP 16 +#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread)) #define MC_PC pc diff --git a/arch/aarch64/reloc.h b/arch/aarch64/reloc.h index 51b66e23..40cf0b28 100644 --- a/arch/aarch64/reloc.h +++ b/arch/aarch64/reloc.h @@ -10,7 +10,7 @@ #define NO_LEGACY_INITFINI -#define TPOFF_K 16 +#define TPOFF_K 0 #define REL_SYMBOLIC R_AARCH64_ABS64 #define REL_GOT R_AARCH64_GLOB_DAT diff --git a/arch/arm/pthread_arch.h b/arch/arm/pthread_arch.h index 6657e198..8f2ae8f8 100644 --- a/arch/arm/pthread_arch.h +++ b/arch/arm/pthread_arch.h @@ -5,7 +5,7 @@ static inline pthread_t __pthread_self() { char *p; __asm__ __volatile__ ( "mrc p15,0,%0,c13,c0,3" : "=r"(p) ); - return (void *)(p+8-sizeof(struct pthread)); + return (void *)(p-sizeof(struct pthread)); } #else @@ -21,12 +21,13 @@ static inline pthread_t __pthread_self() extern uintptr_t __attribute__((__visibility__("hidden"))) __a_gettp_ptr; register uintptr_t p __asm__("r0"); __asm__ __volatile__ ( BLX " %1" : "=r"(p) : "r"(__a_gettp_ptr) : "cc", "lr" ); - return (void *)(p+8-sizeof(struct pthread)); + return (void *)(p-sizeof(struct pthread)); } #endif #define TLS_ABOVE_TP -#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 8) +#define GAP_ABOVE_TP 8 +#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread)) #define MC_PC arm_pc diff --git a/arch/arm/reloc.h b/arch/arm/reloc.h index b175711d..4b00bf64 100644 --- a/arch/arm/reloc.h +++ b/arch/arm/reloc.h @@ -16,7 +16,7 @@ #define NO_LEGACY_INITFINI -#define TPOFF_K 8 +#define TPOFF_K 0 #define REL_SYMBOLIC R_ARM_ABS32 #define REL_GOT R_ARM_GLOB_DAT diff --git a/arch/mips/pthread_arch.h b/arch/mips/pthread_arch.h index e5812655..5fea15ad 100644 --- a/arch/mips/pthread_arch.h +++ b/arch/mips/pthread_arch.h @@ -11,6 +11,7 @@ static inline struct pthread *__pthread_self() } #define TLS_ABOVE_TP +#define GAP_ABOVE_TP 0 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) #define DTP_OFFSET 0x8000 diff --git a/arch/mips64/pthread_arch.h b/arch/mips64/pthread_arch.h index e5812655..5fea15ad 100644 --- a/arch/mips64/pthread_arch.h +++ b/arch/mips64/pthread_arch.h @@ -11,6 +11,7 @@ static inline struct pthread *__pthread_self() } #define TLS_ABOVE_TP +#define GAP_ABOVE_TP 0 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) #define DTP_OFFSET 0x8000 diff --git a/arch/mipsn32/pthread_arch.h b/arch/mipsn32/pthread_arch.h index e5812655..5fea15ad 100644 --- a/arch/mipsn32/pthread_arch.h +++ b/arch/mipsn32/pthread_arch.h @@ -11,6 +11,7 @@ static inline struct pthread *__pthread_self() } #define TLS_ABOVE_TP +#define GAP_ABOVE_TP 0 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) #define DTP_OFFSET 0x8000 diff --git a/arch/or1k/pthread_arch.h b/arch/or1k/pthread_arch.h index 7decd769..521b9c53 100644 --- a/arch/or1k/pthread_arch.h +++ b/arch/or1k/pthread_arch.h @@ -12,6 +12,7 @@ static inline struct pthread *__pthread_self() } #define TLS_ABOVE_TP +#define GAP_ABOVE_TP 0 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread)) #define MC_PC regs.pc diff --git a/arch/powerpc/pthread_arch.h b/arch/powerpc/pthread_arch.h index 7c5c4fad..79e5a09f 100644 --- a/arch/powerpc/pthread_arch.h +++ b/arch/powerpc/pthread_arch.h @@ -11,6 +11,7 @@ static inline struct pthread *__pthread_self() } #define TLS_ABOVE_TP +#define GAP_ABOVE_TP 0 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) #define DTP_OFFSET 0x8000 diff --git a/arch/powerpc64/pthread_arch.h b/arch/powerpc64/pthread_arch.h index 2f976fe2..37b75e29 100644 --- a/arch/powerpc64/pthread_arch.h +++ b/arch/powerpc64/pthread_arch.h @@ -6,6 +6,7 @@ static inline struct pthread *__pthread_self() } #define TLS_ABOVE_TP +#define GAP_ABOVE_TP 0 #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) #define DTP_OFFSET 0x8000 diff --git a/arch/sh/pthread_arch.h b/arch/sh/pthread_arch.h index 2756e7ec..41fefacf 100644 --- a/arch/sh/pthread_arch.h +++ b/arch/sh/pthread_arch.h @@ -2,10 +2,11 @@ static inline struct pthread *__pthread_self() { char *self; __asm__ __volatile__ ("stc gbr,%0" : "=r" (self) ); - return (struct pthread *) (self + 8 - sizeof(struct pthread)); + return (struct pthread *) (self - sizeof(struct pthread)); } #define TLS_ABOVE_TP -#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) - 8) +#define GAP_ABOVE_TP 8 +#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread)) #define MC_PC sc_pc diff --git a/arch/sh/reloc.h b/arch/sh/reloc.h index 0238ce07..a1f16cb1 100644 --- a/arch/sh/reloc.h +++ b/arch/sh/reloc.h @@ -20,7 +20,7 @@ #define LDSO_ARCH "sh" ENDIAN_SUFFIX FP_SUFFIX ABI_SUFFIX -#define TPOFF_K 8 +#define TPOFF_K 0 #define REL_SYMBOLIC R_SH_DIR32 #define REL_OFFSET R_SH_REL32 diff --git a/ldso/dynlink.c b/ldso/dynlink.c index cea5f452..c6216b7c 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -1594,8 +1594,9 @@ _Noreturn void __dls3(size_t *sp) libc.tls_head = tls_tail = &app.tls; app.tls_id = tls_cnt = 1; #ifdef TLS_ABOVE_TP - app.tls.offset = 0; - tls_offset = app.tls.size + app.tls.offset = GAP_ABOVE_TP; + app.tls.offset += -GAP_ABOVE_TP & (app.tls.align-1); + tls_offset = app.tls.offset + app.tls.size + ( -((uintptr_t)app.tls.image + app.tls.size) & (app.tls.align-1) ); #else diff --git a/src/env/__init_tls.c b/src/env/__init_tls.c index 1c5d98a0..31d324a8 100644 --- a/src/env/__init_tls.c +++ b/src/env/__init_tls.c @@ -104,13 +104,19 @@ static void static_init_tls(size_t *aux) main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) & (main_tls.align-1); - if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN; -#ifndef TLS_ABOVE_TP +#ifdef TLS_ABOVE_TP + main_tls.offset = GAP_ABOVE_TP; + main_tls.offset += -GAP_ABOVE_TP & (main_tls.align-1); +#else main_tls.offset = main_tls.size; #endif + if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN; libc.tls_align = main_tls.align; libc.tls_size = 2*sizeof(void *) + sizeof(struct pthread) +#ifdef TLS_ABOVE_TP + + main_tls.offset +#endif + main_tls.size + main_tls.align + MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN; diff --git a/src/ldso/aarch64/tlsdesc.s b/src/ldso/aarch64/tlsdesc.s index 8ed5c267..8e4004d7 100644 --- a/src/ldso/aarch64/tlsdesc.s +++ b/src/ldso/aarch64/tlsdesc.s @@ -14,7 +14,7 @@ __tlsdesc_static: // size_t __tlsdesc_dynamic(size_t *a) // { // struct {size_t modidx,off;} *p = (void*)a[1]; -// size_t *dtv = *(size_t**)(tp + 16 - 8); +// size_t *dtv = *(size_t**)(tp - 8); // if (p->modidx <= dtv[0]) // return dtv[p->modidx] + p->off - tp; // return __tls_get_new(p) - tp; @@ -28,8 +28,7 @@ __tlsdesc_dynamic: mrs x1,tpidr_el0 // tp ldr x0,[x0,#8] // p ldr x2,[x0] // p->modidx - add x3,x1,#8 - ldr x3,[x3] // dtv + ldr x3,[x1,#-8] // dtv ldr x4,[x3] // dtv[0] cmp x2,x4 b.hi 1f From d5e55ba3320c30310ca1d8938925d5424a652422 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Tue, 12 Jun 2018 17:02:21 -0400 Subject: [PATCH 143/161] add missing m68k relocation types in elf.h --- include/elf.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/include/elf.h b/include/elf.h index 78906f15..c2297353 100644 --- a/include/elf.h +++ b/include/elf.h @@ -1129,7 +1129,25 @@ typedef struct { #define R_68K_GLOB_DAT 20 #define R_68K_JMP_SLOT 21 #define R_68K_RELATIVE 22 -#define R_68K_NUM 23 +#define R_68K_TLS_GD32 25 +#define R_68K_TLS_GD16 26 +#define R_68K_TLS_GD8 27 +#define R_68K_TLS_LDM32 28 +#define R_68K_TLS_LDM16 29 +#define R_68K_TLS_LDM8 30 +#define R_68K_TLS_LDO32 31 +#define R_68K_TLS_LDO16 32 +#define R_68K_TLS_LDO8 33 +#define R_68K_TLS_IE32 34 +#define R_68K_TLS_IE16 35 +#define R_68K_TLS_IE8 36 +#define R_68K_TLS_LE32 37 +#define R_68K_TLS_LE16 38 +#define R_68K_TLS_LE8 39 +#define R_68K_TLS_DTPMOD32 40 +#define R_68K_TLS_DTPREL32 41 +#define R_68K_TLS_TPREL32 42 +#define R_68K_NUM 43 #define R_386_NONE 0 #define R_386_32 1 From 18f02c42a2b5397e8541f4663eb6ca00c1a806dd Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 14 Jun 2018 11:00:58 -0400 Subject: [PATCH 144/161] add support for m68k 80-bit long double variant since x86 and m68k are the only archs with 80-bit long double and each has mandatory endianness, select the variant via endianness. differences are minor: apparently just byte order and representation of infinities. the m68k format is not well-documented anywhere I could find, so if other differences are found they may require additional changes later. --- src/internal/libm.h | 11 +++++++++++ src/math/__fpclassifyl.c | 12 ++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/internal/libm.h b/src/internal/libm.h index df864111..a2505f7e 100644 --- a/src/internal/libm.h +++ b/src/internal/libm.h @@ -28,6 +28,17 @@ union ldshape { uint16_t se; } i; }; +#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN +/* This is the m68k variant of 80-bit long double, and this definition only works + * on archs where the alignment requirement of uint64_t is <= 4. */ +union ldshape { + long double f; + struct { + uint16_t se; + uint16_t pad; + uint64_t m; + } i; +}; #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN union ldshape { long double f; diff --git a/src/math/__fpclassifyl.c b/src/math/__fpclassifyl.c index 481c0b94..e41781b6 100644 --- a/src/math/__fpclassifyl.c +++ b/src/math/__fpclassifyl.c @@ -13,10 +13,18 @@ int __fpclassifyl(long double x) int msb = u.i.m>>63; if (!e && !msb) return u.i.m ? FP_SUBNORMAL : FP_ZERO; + if (e == 0x7fff) { + /* The x86 variant of 80-bit extended precision only admits + * one representation of each infinity, with the mantissa msb + * necessarily set. The version with it clear is invalid/nan. + * The m68k variant, however, allows either, and tooling uses + * the version with it clear. */ + if (__BYTE_ORDER == __LITTLE_ENDIAN && !msb) + return FP_NAN; + return u.i.m << 1 ? FP_NAN : FP_INFINITE; + } if (!msb) return FP_NAN; - if (e == 0x7fff) - return u.i.m << 1 ? FP_NAN : FP_INFINITE; return FP_NORMAL; } #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 From f81e44a0d96c88e052e51982f9fdd6fe0a212b46 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 14 Jun 2018 14:26:30 -0400 Subject: [PATCH 145/161] add m68k port three ABIs are supported: the default with 68881 80-bit fpu format and results returned in floating point registers, softfloat-only with the same format, and coldfire fpu with IEEE single/double only. only the first is tested at all, and only under qemu which has fpu emulation bugs. basic functionality smoke tests have been performed for the most common arch-specific breakage via libc-test and qemu user-level emulation. some sysvipc failures remain, but are shared with other big endian archs and will be fixed separately. --- arch/m68k/atomic_arch.h | 8 + arch/m68k/bits/alltypes.h.in | 31 +++ arch/m68k/bits/endian.h | 1 + arch/m68k/bits/fcntl.h | 40 ++++ arch/m68k/bits/fenv.h | 29 +++ arch/m68k/bits/float.h | 39 ++++ arch/m68k/bits/limits.h | 7 + arch/m68k/bits/posix.h | 2 + arch/m68k/bits/setjmp.h | 1 + arch/m68k/bits/signal.h | 140 ++++++++++++ arch/m68k/bits/stat.h | 21 ++ arch/m68k/bits/stdint.h | 20 ++ arch/m68k/bits/syscall.h.in | 361 +++++++++++++++++++++++++++++++ arch/m68k/crt_arch.h | 14 ++ arch/m68k/pthread_arch.h | 13 ++ arch/m68k/reloc.h | 30 +++ arch/m68k/syscall_arch.h | 90 ++++++++ configure | 8 + src/fenv/m68k/fenv.c | 84 +++++++ src/internal/m68k/syscall.s | 9 + src/ldso/m68k/dlsym.s | 12 + src/setjmp/m68k/longjmp.s | 14 ++ src/setjmp/m68k/setjmp.s | 18 ++ src/signal/m68k/sigsetjmp.s | 29 +++ src/thread/m68k/__m68k_read_tp.s | 8 + src/thread/m68k/clone.s | 24 ++ src/thread/m68k/syscall_cp.s | 26 +++ 27 files changed, 1079 insertions(+) create mode 100644 arch/m68k/atomic_arch.h create mode 100644 arch/m68k/bits/alltypes.h.in create mode 100644 arch/m68k/bits/endian.h create mode 100644 arch/m68k/bits/fcntl.h create mode 100644 arch/m68k/bits/fenv.h create mode 100644 arch/m68k/bits/float.h create mode 100644 arch/m68k/bits/limits.h create mode 100644 arch/m68k/bits/posix.h create mode 100644 arch/m68k/bits/setjmp.h create mode 100644 arch/m68k/bits/signal.h create mode 100644 arch/m68k/bits/stat.h create mode 100644 arch/m68k/bits/stdint.h create mode 100644 arch/m68k/bits/syscall.h.in create mode 100644 arch/m68k/crt_arch.h create mode 100644 arch/m68k/pthread_arch.h create mode 100644 arch/m68k/reloc.h create mode 100644 arch/m68k/syscall_arch.h create mode 100644 src/fenv/m68k/fenv.c create mode 100644 src/internal/m68k/syscall.s create mode 100644 src/ldso/m68k/dlsym.s create mode 100644 src/setjmp/m68k/longjmp.s create mode 100644 src/setjmp/m68k/setjmp.s create mode 100644 src/signal/m68k/sigsetjmp.s create mode 100644 src/thread/m68k/__m68k_read_tp.s create mode 100644 src/thread/m68k/clone.s create mode 100644 src/thread/m68k/syscall_cp.s diff --git a/arch/m68k/atomic_arch.h b/arch/m68k/atomic_arch.h new file mode 100644 index 00000000..b369649a --- /dev/null +++ b/arch/m68k/atomic_arch.h @@ -0,0 +1,8 @@ +#define a_cas a_cas +static inline int a_cas(volatile int *p, int t, int s) +{ + __asm__ __volatile__ ( + "cas.l %0, %2, (%1)" + : "+d"(t) : "a"(p), "d"(s) : "memory", "cc"); + return t; +} diff --git a/arch/m68k/bits/alltypes.h.in b/arch/m68k/bits/alltypes.h.in new file mode 100644 index 00000000..a4a8141f --- /dev/null +++ b/arch/m68k/bits/alltypes.h.in @@ -0,0 +1,31 @@ +#define _Addr int +#define _Int64 long long +#define _Reg int + +TYPEDEF __builtin_va_list va_list; +TYPEDEF __builtin_va_list __isoc_va_list; + +#ifndef __cplusplus +TYPEDEF long wchar_t; +#endif + +#if __mcffpu__ +TYPEDEF float float_t; +TYPEDEF double double_t; +#else +TYPEDEF long double float_t; +TYPEDEF long double double_t; +#endif + +TYPEDEF struct { long long __ll; long double __ld; } max_align_t; + +TYPEDEF long time_t; +TYPEDEF long suseconds_t; + +TYPEDEF struct { union { int __i[9]; volatile int __vi[9]; unsigned __s[9]; } __u; } pthread_attr_t; +TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } pthread_mutex_t; +TYPEDEF struct { union { int __i[6]; volatile int __vi[6]; volatile void *volatile __p[6]; } __u; } mtx_t; +TYPEDEF struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } pthread_cond_t; +TYPEDEF struct { union { int __i[12]; volatile int __vi[12]; void *__p[12]; } __u; } cnd_t; +TYPEDEF struct { union { int __i[8]; volatile int __vi[8]; void *__p[8]; } __u; } pthread_rwlock_t; +TYPEDEF struct { union { int __i[5]; volatile int __vi[5]; void *__p[5]; } __u; } pthread_barrier_t; diff --git a/arch/m68k/bits/endian.h b/arch/m68k/bits/endian.h new file mode 100644 index 00000000..ef074b77 --- /dev/null +++ b/arch/m68k/bits/endian.h @@ -0,0 +1 @@ +#define __BYTE_ORDER __BIG_ENDIAN diff --git a/arch/m68k/bits/fcntl.h b/arch/m68k/bits/fcntl.h new file mode 100644 index 00000000..f1c8400f --- /dev/null +++ b/arch/m68k/bits/fcntl.h @@ -0,0 +1,40 @@ +#define O_CREAT 0100 +#define O_EXCL 0200 +#define O_NOCTTY 0400 +#define O_TRUNC 01000 +#define O_APPEND 02000 +#define O_NONBLOCK 04000 +#define O_DSYNC 010000 +#define O_SYNC 04010000 +#define O_RSYNC 04010000 +#define O_DIRECTORY 040000 +#define O_NOFOLLOW 0100000 +#define O_CLOEXEC 02000000 + +#define O_ASYNC 020000 +#define O_DIRECT 0200000 +#define O_LARGEFILE 0400000 +#define O_NOATIME 01000000 +#define O_PATH 010000000 +#define O_TMPFILE 020200000 +#define O_NDELAY O_NONBLOCK + +#define F_DUPFD 0 +#define F_GETFD 1 +#define F_SETFD 2 +#define F_GETFL 3 +#define F_SETFL 4 + +#define F_SETOWN 8 +#define F_GETOWN 9 +#define F_SETSIG 10 +#define F_GETSIG 11 + +#define F_GETLK 12 +#define F_SETLK 13 +#define F_SETLKW 14 + +#define F_SETOWN_EX 15 +#define F_GETOWN_EX 16 + +#define F_GETOWNER_UIDS 17 diff --git a/arch/m68k/bits/fenv.h b/arch/m68k/bits/fenv.h new file mode 100644 index 00000000..c90a4a58 --- /dev/null +++ b/arch/m68k/bits/fenv.h @@ -0,0 +1,29 @@ +#if __HAVE_68881__ || __mcffpu__ + +#define FE_INEXACT 8 +#define FE_DIVBYZERO 16 +#define FE_UNDERFLOW 32 +#define FE_OVERFLOW 64 +#define FE_INVALID 128 + +#define FE_ALL_EXCEPT 0xf8 + +#define FE_TONEAREST 0 +#define FE_TOWARDZERO 16 +#define FE_DOWNWARD 32 +#define FE_UPWARD 48 + +#else + +#define FE_ALL_EXCEPT 0 +#define FE_TONEAREST 0 + +#endif + +typedef unsigned fexcept_t; + +typedef struct { + unsigned __control_register, __status_register, __instruction_address; +} fenv_t; + +#define FE_DFL_ENV ((const fenv_t *) -1) diff --git a/arch/m68k/bits/float.h b/arch/m68k/bits/float.h new file mode 100644 index 00000000..fd02a132 --- /dev/null +++ b/arch/m68k/bits/float.h @@ -0,0 +1,39 @@ +#if !__mcffpu__ + +#define FLT_EVAL_METHOD 2 + +#define LDBL_TRUE_MIN 3.6451995318824746025e-4951L +#define LDBL_MIN 3.3621031431120935063e-4932L +#define LDBL_MAX 1.1897314953572317650e+4932L +#define LDBL_EPSILON 1.0842021724855044340e-19L + +#define LDBL_MANT_DIG 64 +#define LDBL_MIN_EXP (-16381) +#define LDBL_MAX_EXP 16384 + +#define LDBL_DIG 18 +#define LDBL_MIN_10_EXP (-4931) +#define LDBL_MAX_10_EXP 4932 + +#define DECIMAL_DIG 21 + +#else + +#define FLT_EVAL_METHOD 0 + +#define LDBL_TRUE_MIN 4.94065645841246544177e-324L +#define LDBL_MIN 2.22507385850720138309e-308L +#define LDBL_MAX 1.79769313486231570815e+308L +#define LDBL_EPSILON 2.22044604925031308085e-16L + +#define LDBL_MANT_DIG 53 +#define LDBL_MIN_EXP (-1021) +#define LDBL_MAX_EXP 1024 + +#define LDBL_DIG 15 +#define LDBL_MIN_10_EXP (-307) +#define LDBL_MAX_10_EXP 308 + +#define DECIMAL_DIG 17 + +#endif diff --git a/arch/m68k/bits/limits.h b/arch/m68k/bits/limits.h new file mode 100644 index 00000000..fbc6d238 --- /dev/null +++ b/arch/m68k/bits/limits.h @@ -0,0 +1,7 @@ +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define LONG_BIT 32 +#endif + +#define LONG_MAX 0x7fffffffL +#define LLONG_MAX 0x7fffffffffffffffLL diff --git a/arch/m68k/bits/posix.h b/arch/m68k/bits/posix.h new file mode 100644 index 00000000..30a38714 --- /dev/null +++ b/arch/m68k/bits/posix.h @@ -0,0 +1,2 @@ +#define _POSIX_V6_ILP32_OFFBIG 1 +#define _POSIX_V7_ILP32_OFFBIG 1 diff --git a/arch/m68k/bits/setjmp.h b/arch/m68k/bits/setjmp.h new file mode 100644 index 00000000..5e091fb4 --- /dev/null +++ b/arch/m68k/bits/setjmp.h @@ -0,0 +1 @@ +typedef unsigned long __jmp_buf[39]; diff --git a/arch/m68k/bits/signal.h b/arch/m68k/bits/signal.h new file mode 100644 index 00000000..2c369ca3 --- /dev/null +++ b/arch/m68k/bits/signal.h @@ -0,0 +1,140 @@ +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) + +#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define MINSIGSTKSZ 2048 +#define SIGSTKSZ 8192 +#endif + +#ifdef _GNU_SOURCE +enum { R_D0 = 0 }; +#define R_D0 R_D0 +enum { R_D1 = 1 }; +#define R_D1 R_D1 +enum { R_D2 = 2 }; +#define R_D2 R_D2 +enum { R_D3 = 3 }; +#define R_D3 R_D3 +enum { R_D4 = 4 }; +#define R_D4 R_D4 +enum { R_D5 = 5 }; +#define R_D5 R_D5 +enum { R_D6 = 6 }; +#define R_D6 R_D6 +enum { R_D7 = 7 }; +#define R_D7 R_D7 +enum { R_A0 = 8 }; +#define R_A0 R_A0 +enum { R_A1 = 9 }; +#define R_A1 R_A1 +enum { R_A2 = 10 }; +#define R_A2 R_A2 +enum { R_A3 = 11 }; +#define R_A3 R_A3 +enum { R_A4 = 12 }; +#define R_A4 R_A4 +enum { R_A5 = 13 }; +#define R_A5 R_A5 +enum { R_A6 = 14 }; +#define R_A6 R_A6 +enum { R_A7 = 15 }; +#define R_A7 R_A7 +enum { R_SP = 15 }; +#define R_SP R_SP +enum { R_PC = 16 }; +#define R_PC R_PC +enum { R_PS = 17 }; +#define R_PS R_PS +#endif + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) + +struct sigcontext { + unsigned long sc_mask, sc_usp, sc_d0, sc_d1, sc_a0, sc_a1; + unsigned short sc_sr; + unsigned long sc_pc; + unsigned short sc_formatvec; + unsigned long sc_fpregs[6], sc_fpcntl[3]; + unsigned char sc_fpstate[216]; +}; + +typedef int greg_t, gregset_t[18]; +typedef struct { + int f_pcr, f_psr, f_fpiaddr, f_fpregs[8][3]; +} fpregset_t; + +typedef struct { + int version; + gregset_t gregs; + fpregset_t fpregs; +} mcontext_t; +#else +typedef struct { + int __version; + int __gregs[18]; + int __fpregs[27]; +} mcontext_t; +#endif + +struct sigaltstack { + void *ss_sp; + int ss_flags; + size_t ss_size; +}; + +typedef struct __ucontext { + unsigned long uc_flags; + struct __ucontext *uc_link; + stack_t uc_stack; + mcontext_t uc_mcontext; + long __reserved[80]; + sigset_t uc_sigmask; +} ucontext_t; + +#define SA_NOCLDSTOP 1 +#define SA_NOCLDWAIT 2 +#define SA_SIGINFO 4 +#define SA_ONSTACK 0x08000000 +#define SA_RESTART 0x10000000 +#define SA_NODEFER 0x40000000 +#define SA_RESETHAND 0x80000000 +#define SA_RESTORER 0x04000000 + +#endif + +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +#define SIGABRT 6 +#define SIGIOT SIGABRT +#define SIGBUS 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGUSR1 10 +#define SIGSEGV 11 +#define SIGUSR2 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGSTKFLT 16 +#define SIGCHLD 17 +#define SIGCONT 18 +#define SIGSTOP 19 +#define SIGTSTP 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGURG 23 +#define SIGXCPU 24 +#define SIGXFSZ 25 +#define SIGVTALRM 26 +#define SIGPROF 27 +#define SIGWINCH 28 +#define SIGIO 29 +#define SIGPOLL 29 +#define SIGPWR 30 +#define SIGSYS 31 +#define SIGUNUSED SIGSYS + +#define _NSIG 65 diff --git a/arch/m68k/bits/stat.h b/arch/m68k/bits/stat.h new file mode 100644 index 00000000..0f7b66a1 --- /dev/null +++ b/arch/m68k/bits/stat.h @@ -0,0 +1,21 @@ +/* copied from kernel definition, but with padding replaced + * by the corresponding correctly-sized userspace types. */ + +struct stat { + dev_t st_dev; + short __st_dev_padding; + long __st_ino_truncated; + mode_t st_mode; + nlink_t st_nlink; + uid_t st_uid; + gid_t st_gid; + dev_t st_rdev; + short __st_rdev_padding; + off_t st_size; + blksize_t st_blksize; + blkcnt_t st_blocks; + struct timespec st_atim; + struct timespec st_mtim; + struct timespec st_ctim; + ino_t st_ino; +}; diff --git a/arch/m68k/bits/stdint.h b/arch/m68k/bits/stdint.h new file mode 100644 index 00000000..d1b27121 --- /dev/null +++ b/arch/m68k/bits/stdint.h @@ -0,0 +1,20 @@ +typedef int32_t int_fast16_t; +typedef int32_t int_fast32_t; +typedef uint32_t uint_fast16_t; +typedef uint32_t uint_fast32_t; + +#define INT_FAST16_MIN INT32_MIN +#define INT_FAST32_MIN INT32_MIN + +#define INT_FAST16_MAX INT32_MAX +#define INT_FAST32_MAX INT32_MAX + +#define UINT_FAST16_MAX UINT32_MAX +#define UINT_FAST32_MAX UINT32_MAX + +#define INTPTR_MIN INT32_MIN +#define INTPTR_MAX INT32_MAX +#define UINTPTR_MAX UINT32_MAX +#define PTRDIFF_MIN INT32_MIN +#define PTRDIFF_MAX INT32_MAX +#define SIZE_MAX UINT32_MAX diff --git a/arch/m68k/bits/syscall.h.in b/arch/m68k/bits/syscall.h.in new file mode 100644 index 00000000..89cf114c --- /dev/null +++ b/arch/m68k/bits/syscall.h.in @@ -0,0 +1,361 @@ +#define __NR_restart_syscall 0 +#define __NR_exit 1 +#define __NR_fork 2 +#define __NR_read 3 +#define __NR_write 4 +#define __NR_open 5 +#define __NR_close 6 +#define __NR_waitpid 7 +#define __NR_creat 8 +#define __NR_link 9 +#define __NR_unlink 10 +#define __NR_execve 11 +#define __NR_chdir 12 +#define __NR_time 13 +#define __NR_mknod 14 +#define __NR_chmod 15 +#define __NR_chown 16 +#define __NR_oldstat 18 +#define __NR_lseek 19 +#define __NR_getpid 20 +#define __NR_mount 21 +#define __NR_umount 22 +#define __NR_setuid 23 +#define __NR_getuid 24 +#define __NR_stime 25 +#define __NR_ptrace 26 +#define __NR_alarm 27 +#define __NR_oldfstat 28 +#define __NR_pause 29 +#define __NR_utime 30 +#define __NR_access 33 +#define __NR_nice 34 +#define __NR_sync 36 +#define __NR_kill 37 +#define __NR_rename 38 +#define __NR_mkdir 39 +#define __NR_rmdir 40 +#define __NR_dup 41 +#define __NR_pipe 42 +#define __NR_times 43 +#define __NR_brk 45 +#define __NR_setgid 46 +#define __NR_getgid 47 +#define __NR_signal 48 +#define __NR_geteuid 49 +#define __NR_getegid 50 +#define __NR_acct 51 +#define __NR_umount2 52 +#define __NR_ioctl 54 +#define __NR_fcntl 55 +#define __NR_setpgid 57 +#define __NR_umask 60 +#define __NR_chroot 61 +#define __NR_ustat 62 +#define __NR_dup2 63 +#define __NR_getppid 64 +#define __NR_getpgrp 65 +#define __NR_setsid 66 +#define __NR_sigaction 67 +#define __NR_sgetmask 68 +#define __NR_ssetmask 69 +#define __NR_setreuid 70 +#define __NR_setregid 71 +#define __NR_sigsuspend 72 +#define __NR_sigpending 73 +#define __NR_sethostname 74 +#define __NR_setrlimit 75 +#define __NR_getrlimit 76 +#define __NR_getrusage 77 +#define __NR_gettimeofday 78 +#define __NR_settimeofday 79 +#define __NR_getgroups 80 +#define __NR_setgroups 81 +#define __NR_select 82 +#define __NR_symlink 83 +#define __NR_oldlstat 84 +#define __NR_readlink 85 +#define __NR_uselib 86 +#define __NR_swapon 87 +#define __NR_reboot 88 +#define __NR_readdir 89 +#define __NR_mmap 90 +#define __NR_munmap 91 +#define __NR_truncate 92 +#define __NR_ftruncate 93 +#define __NR_fchmod 94 +#define __NR_fchown 95 +#define __NR_getpriority 96 +#define __NR_setpriority 97 +#define __NR_statfs 99 +#define __NR_fstatfs 100 +#define __NR_socketcall 102 +#define __NR_syslog 103 +#define __NR_setitimer 104 +#define __NR_getitimer 105 +#define __NR_stat 106 +#define __NR_lstat 107 +#define __NR_fstat 108 +#define __NR_vhangup 111 +#define __NR_wait4 114 +#define __NR_swapoff 115 +#define __NR_sysinfo 116 +#define __NR_ipc 117 +#define __NR_fsync 118 +#define __NR_sigreturn 119 +#define __NR_clone 120 +#define __NR_setdomainname 121 +#define __NR_uname 122 +#define __NR_cacheflush 123 +#define __NR_adjtimex 124 +#define __NR_mprotect 125 +#define __NR_sigprocmask 126 +#define __NR_create_module 127 +#define __NR_init_module 128 +#define __NR_delete_module 129 +#define __NR_get_kernel_syms 130 +#define __NR_quotactl 131 +#define __NR_getpgid 132 +#define __NR_fchdir 133 +#define __NR_bdflush 134 +#define __NR_sysfs 135 +#define __NR_personality 136 +#define __NR_setfsuid 138 +#define __NR_setfsgid 139 +#define __NR__llseek 140 +#define __NR_getdents 141 +#define __NR__newselect 142 +#define __NR_flock 143 +#define __NR_msync 144 +#define __NR_readv 145 +#define __NR_writev 146 +#define __NR_getsid 147 +#define __NR_fdatasync 148 +#define __NR__sysctl 149 +#define __NR_mlock 150 +#define __NR_munlock 151 +#define __NR_mlockall 152 +#define __NR_munlockall 153 +#define __NR_sched_setparam 154 +#define __NR_sched_getparam 155 +#define __NR_sched_setscheduler 156 +#define __NR_sched_getscheduler 157 +#define __NR_sched_yield 158 +#define __NR_sched_get_priority_max 159 +#define __NR_sched_get_priority_min 160 +#define __NR_sched_rr_get_interval 161 +#define __NR_nanosleep 162 +#define __NR_mremap 163 +#define __NR_setresuid 164 +#define __NR_getresuid 165 +#define __NR_getpagesize 166 +#define __NR_query_module 167 +#define __NR_poll 168 +#define __NR_nfsservctl 169 +#define __NR_setresgid 170 +#define __NR_getresgid 171 +#define __NR_prctl 172 +#define __NR_rt_sigreturn 173 +#define __NR_rt_sigaction 174 +#define __NR_rt_sigprocmask 175 +#define __NR_rt_sigpending 176 +#define __NR_rt_sigtimedwait 177 +#define __NR_rt_sigqueueinfo 178 +#define __NR_rt_sigsuspend 179 +#define __NR_pread64 180 +#define __NR_pwrite64 181 +#define __NR_lchown 182 +#define __NR_getcwd 183 +#define __NR_capget 184 +#define __NR_capset 185 +#define __NR_sigaltstack 186 +#define __NR_sendfile 187 +#define __NR_getpmsg 188 +#define __NR_putpmsg 189 +#define __NR_vfork 190 +#define __NR_ugetrlimit 191 +#define __NR_mmap2 192 +#define __NR_truncate64 193 +#define __NR_ftruncate64 194 +#define __NR_stat64 195 +#define __NR_lstat64 196 +#define __NR_fstat64 197 +#define __NR_chown32 198 +#define __NR_getuid32 199 +#define __NR_getgid32 200 +#define __NR_geteuid32 201 +#define __NR_getegid32 202 +#define __NR_setreuid32 203 +#define __NR_setregid32 204 +#define __NR_getgroups32 205 +#define __NR_setgroups32 206 +#define __NR_fchown32 207 +#define __NR_setresuid32 208 +#define __NR_getresuid32 209 +#define __NR_setresgid32 210 +#define __NR_getresgid32 211 +#define __NR_lchown32 212 +#define __NR_setuid32 213 +#define __NR_setgid32 214 +#define __NR_setfsuid32 215 +#define __NR_setfsgid32 216 +#define __NR_pivot_root 217 +#define __NR_getdents64 220 +#define __NR_gettid 221 +#define __NR_tkill 222 +#define __NR_setxattr 223 +#define __NR_lsetxattr 224 +#define __NR_fsetxattr 225 +#define __NR_getxattr 226 +#define __NR_lgetxattr 227 +#define __NR_fgetxattr 228 +#define __NR_listxattr 229 +#define __NR_llistxattr 230 +#define __NR_flistxattr 231 +#define __NR_removexattr 232 +#define __NR_lremovexattr 233 +#define __NR_fremovexattr 234 +#define __NR_futex 235 +#define __NR_sendfile64 236 +#define __NR_mincore 237 +#define __NR_madvise 238 +#define __NR_fcntl64 239 +#define __NR_readahead 240 +#define __NR_io_setup 241 +#define __NR_io_destroy 242 +#define __NR_io_getevents 243 +#define __NR_io_submit 244 +#define __NR_io_cancel 245 +#define __NR_fadvise64 246 +#define __NR_exit_group 247 +#define __NR_lookup_dcookie 248 +#define __NR_epoll_create 249 +#define __NR_epoll_ctl 250 +#define __NR_epoll_wait 251 +#define __NR_remap_file_pages 252 +#define __NR_set_tid_address 253 +#define __NR_timer_create 254 +#define __NR_timer_settime 255 +#define __NR_timer_gettime 256 +#define __NR_timer_getoverrun 257 +#define __NR_timer_delete 258 +#define __NR_clock_settime 259 +#define __NR_clock_gettime 260 +#define __NR_clock_getres 261 +#define __NR_clock_nanosleep 262 +#define __NR_statfs64 263 +#define __NR_fstatfs64 264 +#define __NR_tgkill 265 +#define __NR_utimes 266 +#define __NR_fadvise64_64 267 +#define __NR_mbind 268 +#define __NR_get_mempolicy 269 +#define __NR_set_mempolicy 270 +#define __NR_mq_open 271 +#define __NR_mq_unlink 272 +#define __NR_mq_timedsend 273 +#define __NR_mq_timedreceive 274 +#define __NR_mq_notify 275 +#define __NR_mq_getsetattr 276 +#define __NR_waitid 277 +#define __NR_add_key 279 +#define __NR_request_key 280 +#define __NR_keyctl 281 +#define __NR_ioprio_set 282 +#define __NR_ioprio_get 283 +#define __NR_inotify_init 284 +#define __NR_inotify_add_watch 285 +#define __NR_inotify_rm_watch 286 +#define __NR_migrate_pages 287 +#define __NR_openat 288 +#define __NR_mkdirat 289 +#define __NR_mknodat 290 +#define __NR_fchownat 291 +#define __NR_futimesat 292 +#define __NR_fstatat64 293 +#define __NR_unlinkat 294 +#define __NR_renameat 295 +#define __NR_linkat 296 +#define __NR_symlinkat 297 +#define __NR_readlinkat 298 +#define __NR_fchmodat 299 +#define __NR_faccessat 300 +#define __NR_pselect6 301 +#define __NR_ppoll 302 +#define __NR_unshare 303 +#define __NR_set_robust_list 304 +#define __NR_get_robust_list 305 +#define __NR_splice 306 +#define __NR_sync_file_range 307 +#define __NR_tee 308 +#define __NR_vmsplice 309 +#define __NR_move_pages 310 +#define __NR_sched_setaffinity 311 +#define __NR_sched_getaffinity 312 +#define __NR_kexec_load 313 +#define __NR_getcpu 314 +#define __NR_epoll_pwait 315 +#define __NR_utimensat 316 +#define __NR_signalfd 317 +#define __NR_timerfd_create 318 +#define __NR_eventfd 319 +#define __NR_fallocate 320 +#define __NR_timerfd_settime 321 +#define __NR_timerfd_gettime 322 +#define __NR_signalfd4 323 +#define __NR_eventfd2 324 +#define __NR_epoll_create1 325 +#define __NR_dup3 326 +#define __NR_pipe2 327 +#define __NR_inotify_init1 328 +#define __NR_preadv 329 +#define __NR_pwritev 330 +#define __NR_rt_tgsigqueueinfo 331 +#define __NR_perf_event_open 332 +#define __NR_get_thread_area 333 +#define __NR_set_thread_area 334 +#define __NR_atomic_cmpxchg_32 335 +#define __NR_atomic_barrier 336 +#define __NR_fanotify_init 337 +#define __NR_fanotify_mark 338 +#define __NR_prlimit64 339 +#define __NR_name_to_handle_at 340 +#define __NR_open_by_handle_at 341 +#define __NR_clock_adjtime 342 +#define __NR_syncfs 343 +#define __NR_setns 344 +#define __NR_process_vm_readv 345 +#define __NR_process_vm_writev 346 +#define __NR_kcmp 347 +#define __NR_finit_module 348 +#define __NR_sched_setattr 349 +#define __NR_sched_getattr 350 +#define __NR_renameat2 351 +#define __NR_getrandom 352 +#define __NR_memfd_create 353 +#define __NR_bpf 354 +#define __NR_execveat 355 +#define __NR_socket 356 +#define __NR_socketpair 357 +#define __NR_bind 358 +#define __NR_connect 359 +#define __NR_listen 360 +#define __NR_accept4 361 +#define __NR_getsockopt 362 +#define __NR_setsockopt 363 +#define __NR_getsockname 364 +#define __NR_getpeername 365 +#define __NR_sendto 366 +#define __NR_sendmsg 367 +#define __NR_recvfrom 368 +#define __NR_recvmsg 369 +#define __NR_shutdown 370 +#define __NR_recvmmsg 371 +#define __NR_sendmmsg 372 +#define __NR_userfaultfd 373 +#define __NR_membarrier 374 +#define __NR_mlock2 375 +#define __NR_copy_file_range 376 +#define __NR_preadv2 377 +#define __NR_pwritev2 378 +#define __NR_statx 379 diff --git a/arch/m68k/crt_arch.h b/arch/m68k/crt_arch.h new file mode 100644 index 00000000..48a42f29 --- /dev/null +++ b/arch/m68k/crt_arch.h @@ -0,0 +1,14 @@ +__asm__( +".text\n" +".weak _DYNAMIC \n" +".hidden _DYNAMIC \n" +".global " START "\n" +START ":\n" +" suba.l %fp,%fp \n" +" movea.l %sp,%a0 \n" +" lea _DYNAMIC-.-8,%a1 \n" +" pea (%pc,%a1) \n" +" pea (%a0) \n" +" lea " START "_c-.-8,%a1 \n" +" jsr (%pc,%a1) \n" +); diff --git a/arch/m68k/pthread_arch.h b/arch/m68k/pthread_arch.h new file mode 100644 index 00000000..02d5b8a0 --- /dev/null +++ b/arch/m68k/pthread_arch.h @@ -0,0 +1,13 @@ +static inline struct pthread *__pthread_self() +{ + uintptr_t tp = __syscall(SYS_get_thread_area); + return (pthread_t)(tp - 0x7000 - sizeof(struct pthread)); +} + +#define TLS_ABOVE_TP +#define GAP_ABOVE_TP 0 +#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000) + +#define DTP_OFFSET 0x8000 + +#define MC_PC gregs[R_PC] diff --git a/arch/m68k/reloc.h b/arch/m68k/reloc.h new file mode 100644 index 00000000..f920b39e --- /dev/null +++ b/arch/m68k/reloc.h @@ -0,0 +1,30 @@ +#if __HAVE_68881__ +#define FP_SUFFIX "" +#elif __mcffpu__ +#define FP_SUFFIX "-fp64" +#else +#define FP_SUFFIX "-sf" +#endif + +#define LDSO_ARCH "m68k" FP_SUFFIX + +#define TPOFF_K (-0x7000) + +#define REL_SYMBOLIC R_68K_32 +#define REL_OFFSET R_68K_PC32 +#define REL_GOT R_68K_GLOB_DAT +#define REL_PLT R_68K_JMP_SLOT +#define REL_RELATIVE R_68K_RELATIVE +#define REL_COPY R_68K_COPY +#define REL_DTPMOD R_68K_TLS_DTPMOD32 +#define REL_DTPOFF R_68K_TLS_DTPREL32 +#define REL_TPOFF R_68K_TLS_TPREL32 + +#define CRTJMP(pc,sp) __asm__ __volatile__( \ + "move.l %1,%%sp ; jmp (%0)" : : "r"(pc), "r"(sp) : "memory" ) + +#define GETFUNCSYM(fp, sym, got) __asm__ ( \ + ".hidden " #sym "\n" \ + "lea " #sym "-.-8,%0 \n" \ + "lea (%%pc,%0),%0 \n" \ + : "=a"(*fp) : : "memory" ) diff --git a/arch/m68k/syscall_arch.h b/arch/m68k/syscall_arch.h new file mode 100644 index 00000000..53a4256f --- /dev/null +++ b/arch/m68k/syscall_arch.h @@ -0,0 +1,90 @@ +#define __SYSCALL_LL_E(x) \ +((union { long long ll; long l[2]; }){ .ll = x }).l[0], \ +((union { long long ll; long l[2]; }){ .ll = x }).l[1] +#define __SYSCALL_LL_O(x) __SYSCALL_LL_E((x)) + +static __inline long __syscall0(long n) +{ + register unsigned long d0 __asm__("d0") = n; + __asm__ __volatile__ ("trap #0" : "+r"(d0) + : + : "memory"); + return d0; +} + +static inline long __syscall1(long n, long a) +{ + register unsigned long d0 __asm__("d0") = n; + register unsigned long d1 __asm__("d1") = a; + __asm__ __volatile__ ("trap #0" : "+r"(d0) + : "r"(d1) + : "memory"); + return d0; +} + +static inline long __syscall2(long n, long a, long b) +{ + register unsigned long d0 __asm__("d0") = n; + register unsigned long d1 __asm__("d1") = a; + register unsigned long d2 __asm__("d2") = b; + __asm__ __volatile__ ("trap #0" : "+r"(d0) + : "r"(d1), "r"(d2) + : "memory"); + return d0; +} + +static inline long __syscall3(long n, long a, long b, long c) +{ + register unsigned long d0 __asm__("d0") = n; + register unsigned long d1 __asm__("d1") = a; + register unsigned long d2 __asm__("d2") = b; + register unsigned long d3 __asm__("d3") = c; + __asm__ __volatile__ ("trap #0" : "+r"(d0) + : "r"(d1), "r"(d2), "r"(d3) + : "memory"); + return d0; +} + +static inline long __syscall4(long n, long a, long b, long c, long d) +{ + register unsigned long d0 __asm__("d0") = n; + register unsigned long d1 __asm__("d1") = a; + register unsigned long d2 __asm__("d2") = b; + register unsigned long d3 __asm__("d3") = c; + register unsigned long d4 __asm__("d4") = d; + __asm__ __volatile__ ("trap #0" : "+r"(d0) + : "r"(d1), "r"(d2), "r"(d3), "r"(d4) + : "memory"); + return d0; +} + +static inline long __syscall5(long n, long a, long b, long c, long d, long e) +{ + register unsigned long d0 __asm__("d0") = n; + register unsigned long d1 __asm__("d1") = a; + register unsigned long d2 __asm__("d2") = b; + register unsigned long d3 __asm__("d3") = c; + register unsigned long d4 __asm__("d4") = d; + register unsigned long d5 __asm__("d5") = e; + __asm__ __volatile__ ("trap #0" : "+r"(d0) + : "r"(d1), "r"(d2), "r"(d3), "r"(d4), "r"(d5) + : "memory"); + return d0; +} + +static inline long __syscall6(long n, long a, long b, long c, long d, long e, long f) +{ + register unsigned long d0 __asm__("d0") = n; + register unsigned long d1 __asm__("d1") = a; + register unsigned long d2 __asm__("d2") = b; + register unsigned long d3 __asm__("d3") = c; + register unsigned long d4 __asm__("d4") = d; + register unsigned long d5 __asm__("d5") = e; + register unsigned long a0 __asm__("a0") = f; + __asm__ __volatile__ ("trap #0" : "+r"(d0) + : "r"(d1), "r"(d2), "r"(d3), "r"(d4), "r"(d5), "r"(a0) + : "memory"); + return d0; +} + +#define SYSCALL_USE_SOCKETCALL diff --git a/configure b/configure index 09a0c436..f940af9a 100755 --- a/configure +++ b/configure @@ -320,6 +320,7 @@ i?86*) ARCH=i386 ;; x86_64-x32*|x32*|x86_64*x32) ARCH=x32 ;; x86_64-nt64*) ARCH=nt64 ;; x86_64*) ARCH=x86_64 ;; +m68k*) ARCH=m68k ;; mips64*|mipsisa64*) ARCH=mips64 ;; mips*) ARCH=mips ;; microblaze*) ARCH=microblaze ;; @@ -641,6 +642,13 @@ if test "$ARCH" = "aarch64" ; then trycppif __AARCH64EB__ "$t" && SUBARCH=${SUBARCH}_be fi +if test "$ARCH" = "m68k" ; then +if trycppif "__HAVE_68881__" ; then : ; +elif trycppif "__mcffpu__" ; then SUBARCH="-fp64" +else SUBARCH="-sf" +fi +fi + if test "$ARCH" = "mips" ; then trycppif "__mips_isa_rev >= 6" "$t" && SUBARCH=${SUBARCH}r6 trycppif "_MIPSEL || __MIPSEL || __MIPSEL__" "$t" && SUBARCH=${SUBARCH}el diff --git a/src/fenv/m68k/fenv.c b/src/fenv/m68k/fenv.c new file mode 100644 index 00000000..e60949d1 --- /dev/null +++ b/src/fenv/m68k/fenv.c @@ -0,0 +1,84 @@ +#include + +#if __HAVE_68881__ || __mcffpu__ + +static unsigned getsr() +{ + unsigned v; + __asm__ __volatile__ ("fmove.l %%fpsr,%0" : "=dm"(v)); + return v; +} + +static void setsr(unsigned v) +{ + __asm__ __volatile__ ("fmove.l %0,%%fpsr" : : "dm"(v)); +} + +static unsigned getcr() +{ + unsigned v; + __asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=dm"(v)); + return v; +} + +static void setcr(unsigned v) +{ + __asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "dm"(v)); +} + +int feclearexcept(int mask) +{ + if (mask & ~FE_ALL_EXCEPT) return -1; + setsr(getsr() & ~mask); + return 0; +} + +int feraiseexcept(int mask) +{ + if (mask & ~FE_ALL_EXCEPT) return -1; + setsr(getsr() | mask); + return 0; +} + +int fetestexcept(int mask) +{ + return getsr() & mask; +} + +int fegetround(void) +{ + return getcr() & FE_UPWARD; +} + +int __fesetround(int r) +{ + setcr((getcr() & ~FE_UPWARD) | r); + return 0; +} + +int fegetenv(fenv_t *envp) +{ + envp->__control_register = getcr(); + envp->__status_register = getsr(); + __asm__ __volatile__ ("fmove.l %%fpiar,%0" + : "=dm"(envp->__instruction_address)); + return 0; +} + +int fesetenv(const fenv_t *envp) +{ + static const fenv_t default_env = { 0 }; + if (envp == FE_DFL_ENV) + envp = &default_env; + setcr(envp->__control_register); + setsr(envp->__status_register); + __asm__ __volatile__ ("fmove.l %0,%%fpiar" + : : "dm"(envp->__instruction_address)); + return 0; +} + +#else + +#include "../fenv.c" + +#endif diff --git a/src/internal/m68k/syscall.s b/src/internal/m68k/syscall.s new file mode 100644 index 00000000..9972a34d --- /dev/null +++ b/src/internal/m68k/syscall.s @@ -0,0 +1,9 @@ +.global __syscall +.hidden __syscall +.type __syscall,%function +__syscall: + movem.l %d2-%d5,-(%sp) + movem.l 20(%sp),%d0-%d5/%a0 + trap #0 + movem.l (%sp)+,%d2-%d5 + rts diff --git a/src/ldso/m68k/dlsym.s b/src/ldso/m68k/dlsym.s new file mode 100644 index 00000000..5209ae1b --- /dev/null +++ b/src/ldso/m68k/dlsym.s @@ -0,0 +1,12 @@ +.text +.global dlsym +.hidden __dlsym +.type dlsym,@function +dlsym: + move.l (%sp),-(%sp) + move.l 12(%sp),-(%sp) + move.l 12(%sp),-(%sp) + lea __dlsym-.-8,%a1 + jsr (%pc,%a1) + add.l #12,%sp + rts diff --git a/src/setjmp/m68k/longjmp.s b/src/setjmp/m68k/longjmp.s new file mode 100644 index 00000000..cdb05fb5 --- /dev/null +++ b/src/setjmp/m68k/longjmp.s @@ -0,0 +1,14 @@ +.global _longjmp +.global longjmp +.type _longjmp,@function +.type longjmp,@function +_longjmp: +longjmp: + movea.l 4(%sp),%a0 + move.l 8(%sp),%d0 + bne 1f + move.l #1,%d0 +1: movem.l (%a0),%d2-%d7/%a2-%a7 + fmovem.x 52(%a0),%fp2-%fp7 + move.l 48(%a0),(%sp) + rts diff --git a/src/setjmp/m68k/setjmp.s b/src/setjmp/m68k/setjmp.s new file mode 100644 index 00000000..15e549b0 --- /dev/null +++ b/src/setjmp/m68k/setjmp.s @@ -0,0 +1,18 @@ +.global ___setjmp +.hidden ___setjmp +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +___setjmp: +__setjmp: +_setjmp: +setjmp: + movea.l 4(%sp),%a0 + movem.l %d2-%d7/%a2-%a7,(%a0) + move.l (%sp),48(%a0) + fmovem.x %fp2-%fp7,52(%a0) + clr.l %d0 + rts diff --git a/src/signal/m68k/sigsetjmp.s b/src/signal/m68k/sigsetjmp.s new file mode 100644 index 00000000..09bfa646 --- /dev/null +++ b/src/signal/m68k/sigsetjmp.s @@ -0,0 +1,29 @@ +.global sigsetjmp +.global __sigsetjmp +.type sigsetjmp,@function +.type __sigsetjmp,@function +sigsetjmp: +__sigsetjmp: + move.l 8(%sp),%d0 + beq 1f + + movea.l 4(%sp),%a1 + move.l (%sp)+,156(%a1) + move.l %a2,156+4+8(%a1) + movea.l %a1,%a2 + +.hidden ___setjmp + lea ___setjmp-.-8,%a1 + jsr (%pc,%a1) + + move.l 156(%a2),-(%sp) + move.l %a2,4(%sp) + move.l %d0,8(%sp) + movea.l 156+4+8(%a2),%a2 + +.hidden __sigsetjmp_tail + lea __sigsetjmp_tail-.-8,%a1 + jmp (%pc,%a1) + +1: lea ___setjmp-.-8,%a1 + jmp (%pc,%a1) diff --git a/src/thread/m68k/__m68k_read_tp.s b/src/thread/m68k/__m68k_read_tp.s new file mode 100644 index 00000000..86886da8 --- /dev/null +++ b/src/thread/m68k/__m68k_read_tp.s @@ -0,0 +1,8 @@ +.text +.global __m68k_read_tp +.type __m68k_read_tp,@function +__m68k_read_tp: + move.l #333,%d0 + trap #0 + move.l %d0,%a0 + rts diff --git a/src/thread/m68k/clone.s b/src/thread/m68k/clone.s new file mode 100644 index 00000000..5b61b6fa --- /dev/null +++ b/src/thread/m68k/clone.s @@ -0,0 +1,24 @@ +.text +.global __clone +.type __clone,@function +__clone: + movem.l %d2-%d5,-(%sp) + move.l #120,%d0 + move.l 28(%sp),%d1 + move.l 24(%sp),%d2 + and.l #-16,%d2 + move.l 36(%sp),%d3 + move.l 44(%sp),%d4 + move.l 40(%sp),%d5 + move.l 20(%sp),%a0 + move.l 32(%sp),%a1 + trap #0 + tst.l %d0 + beq 1f + movem.l (%sp)+,%d2-%d5 + rts +1: move.l %a1,-(%sp) + jsr (%a0) + move.l #1,%d0 + trap #0 + clr.b 0 diff --git a/src/thread/m68k/syscall_cp.s b/src/thread/m68k/syscall_cp.s new file mode 100644 index 00000000..5628a896 --- /dev/null +++ b/src/thread/m68k/syscall_cp.s @@ -0,0 +1,26 @@ +.text +.global __cp_begin +.hidden __cp_begin +.global __cp_end +.hidden __cp_end +.global __cp_cancel +.hidden __cp_cancel +.hidden __cancel +.global __syscall_cp_asm +.hidden __syscall_cp_asm +.type __syscall_cp_asm,@function +__syscall_cp_asm: + movem.l %d2-%d5,-(%sp) + movea.l 20(%sp),%a0 +__cp_begin: + move.l (%a0),%d0 + bne __cp_cancel + movem.l 24(%sp),%d0-%d5/%a0 + trap #0 +__cp_end: + movem.l (%sp)+,%d2-%d5 + rts +__cp_cancel: + movem.l (%sp)+,%d2-%d5 + move.l __cancel-.-8,%a1 + jmp (%pc,%a1) From 29f3202b731185d993a399f04d2f3e3f78db5a81 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 28 Apr 2018 15:52:06 +0000 Subject: [PATCH 146/161] sys/epoll.h: add EPOLLNVAL from linux v4.16 added to uapi in commit 65aaf87b3aa2d049c6b9fd85221858a895df3393 used since commit a9a08845e9acbd224e4ee466f5c1275ed50054e8, which renamed POLL* to EPOLL* in the kernel. --- include/sys/epoll.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/sys/epoll.h b/include/sys/epoll.h index ffe2311f..ac81a841 100644 --- a/include/sys/epoll.h +++ b/include/sys/epoll.h @@ -21,6 +21,7 @@ enum EPOLL_EVENTS { __EPOLL_DUMMY }; #define EPOLLPRI 0x002 #define EPOLLOUT 0x004 #define EPOLLRDNORM 0x040 +#define EPOLLNVAL 0x020 #define EPOLLRDBAND 0x080 #define EPOLLWRNORM 0x100 #define EPOLLWRBAND 0x200 From 833df8675cbb51da193636828bb9a16c9c2ec5ad Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 28 Apr 2018 16:10:53 +0000 Subject: [PATCH 147/161] netinet/if_ether.h: add ETH_P_ERSPAN2 from linux v4.16 protocol number for erspan v2 support added in linux commit f551c91de262ba36b20c3ac19538afb4f4507441 --- include/netinet/if_ether.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h index 9007d609..33f08a31 100644 --- a/include/netinet/if_ether.h +++ b/include/netinet/if_ether.h @@ -17,6 +17,7 @@ #define ETH_P_PUP 0x0200 #define ETH_P_PUPAT 0x0201 #define ETH_P_TSN 0x22F0 +#define ETH_P_ERSPAN2 0x22EB #define ETH_P_IP 0x0800 #define ETH_P_X25 0x0805 #define ETH_P_ARP 0x0806 From 3a81cbe64320795d69f11fd2300947d2b56b2e17 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 28 Apr 2018 16:16:12 +0000 Subject: [PATCH 148/161] netinet/if_ether.h: add ETH_TLEN from linux v4.16 octets in ethernet type field added in linux commit 4bbb3e0e8239f9079bf1fe20b3c0cb598714ae61 --- include/netinet/if_ether.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h index 33f08a31..f7df5f7f 100644 --- a/include/netinet/if_ether.h +++ b/include/netinet/if_ether.h @@ -5,6 +5,7 @@ #include #define ETH_ALEN 6 +#define ETH_TLEN 2 #define ETH_HLEN 14 #define ETH_ZLEN 60 #define ETH_DATA_LEN 1500 From 0f7aa600f75205af243a67394fbb4fe41b5f679a Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 28 Apr 2018 16:23:23 +0000 Subject: [PATCH 149/161] sys/ptrace.h: add PTRACE_SECCOMP_GET_METADATA from linux v4.16 to get seccomp state for checkpoint restore. added in linux commit 26500475ac1b499d8636ff281311d633909f5d20 struct tag follows the glibc api and ptrace_peeksiginfo_args got changed too accordingly. --- include/sys/ptrace.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/sys/ptrace.h b/include/sys/ptrace.h index d9d45408..f501ff08 100644 --- a/include/sys/ptrace.h +++ b/include/sys/ptrace.h @@ -40,6 +40,7 @@ extern "C" { #define PTRACE_GETSIGMASK 0x420a #define PTRACE_SETSIGMASK 0x420b #define PTRACE_SECCOMP_GET_FILTER 0x420c +#define PTRACE_SECCOMP_GET_METADATA 0x420d #define PT_READ_I PTRACE_PEEKTEXT #define PT_READ_D PTRACE_PEEKDATA @@ -86,12 +87,17 @@ extern "C" { #define PTRACE_PEEKSIGINFO_SHARED 1 -struct ptrace_peeksiginfo_args { +struct __ptrace_peeksiginfo_args { uint64_t off; uint32_t flags; int32_t nr; }; +struct __ptrace_seccomp_metadata { + uint64_t filter_off; + uint64_t flags; +}; + long ptrace(int, ...); #ifdef __cplusplus From a697a1c9a561e2dd3ae64bcbe2cfe286feaff97e Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 28 Apr 2018 16:29:55 +0000 Subject: [PATCH 150/161] aarch64: add HWCAP_ASIMDFHM from linux v4.16 armv8.4 fp mul instructions. added in commit 3b3b681097fae73b7f5dcdd42db6cfdf32943d4c --- arch/aarch64/bits/hwcap.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/aarch64/bits/hwcap.h b/arch/aarch64/bits/hwcap.h index 1727a387..6fa64e8c 100644 --- a/arch/aarch64/bits/hwcap.h +++ b/arch/aarch64/bits/hwcap.h @@ -21,3 +21,4 @@ #define HWCAP_ASIMDDP (1 << 20) #define HWCAP_SHA512 (1 << 21) #define HWCAP_SVE (1 << 22) +#define HWCAP_ASIMDFHM (1 << 23) From 90ac71d853d4ed9786ef8bed4f6ef77703d681a3 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 28 Apr 2018 16:36:40 +0000 Subject: [PATCH 151/161] powerpc: add pkey syscall numbers from linux v4.16 add pkey_mprotect, pkey_alloc, pkey_free syscall numbers, new in linux commits 3350eb2ea127978319ced883523d828046af4045 and 9499ec1b5e82321829e1c1510bcc37edc20b6f38 --- arch/powerpc/bits/syscall.h.in | 3 +++ arch/powerpc64/bits/syscall.h.in | 3 +++ 2 files changed, 6 insertions(+) diff --git a/arch/powerpc/bits/syscall.h.in b/arch/powerpc/bits/syscall.h.in index 20833915..7ce94bbd 100644 --- a/arch/powerpc/bits/syscall.h.in +++ b/arch/powerpc/bits/syscall.h.in @@ -368,4 +368,7 @@ #define __NR_pwritev2 381 #define __NR_kexec_file_load 382 #define __NR_statx 383 +#define __NR_pkey_alloc 384 +#define __NR_pkey_free 385 +#define __NR_pkey_mprotect 386 diff --git a/arch/powerpc64/bits/syscall.h.in b/arch/powerpc64/bits/syscall.h.in index 936f43c0..1da1ecc0 100644 --- a/arch/powerpc64/bits/syscall.h.in +++ b/arch/powerpc64/bits/syscall.h.in @@ -359,4 +359,7 @@ #define __NR_pwritev2 381 #define __NR_kexec_file_load 382 #define __NR_statx 383 +#define __NR_pkey_alloc 384 +#define __NR_pkey_free 385 +#define __NR_pkey_mprotect 386 From 156a3bedb22b38bc771b755700dca0cab9d1a787 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 9 Jun 2018 20:39:35 +0000 Subject: [PATCH 152/161] add MAP_FIXED_NOREPLACE from linux v4.17 to map at a fixed address without unmapping underlying mappings (fails with EEXIST unlike MAP_FIXED), new in linux commits 4ed28639519c7bad5f518e70b3284c6e0763e650 and a4ff8e8620d3f4f50ac4b41e8067b7d395056843. --- include/sys/mman.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/sys/mman.h b/include/sys/mman.h index 302ad134..19dd844e 100644 --- a/include/sys/mman.h +++ b/include/sys/mman.h @@ -35,6 +35,7 @@ extern "C" { #define MAP_STACK 0x20000 #define MAP_HUGETLB 0x40000 #define MAP_SYNC 0x80000 +#define MAP_FIXED_NOREPLACE 0x100000 #define MAP_FILE 0 #define MAP_HUGE_SHIFT 26 From af55070eae5438476f921d827b7ae49e8141c3fe Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 9 Jun 2018 21:06:58 +0000 Subject: [PATCH 153/161] add {MSG,SEM,SHM}_STAT_ANY from linux v4.17 introduced to stat ipc objects without permission checks since the info is available in /proc/sysvipc anyway, new in linux commits 23c8cec8cf679b10997a512abb1e86f0cedc42ba a280d6dc77eb6002f269d58cd47c7c7e69b617b6 c21a6970ae727839a2f300cd8dd957de0d0238c3 --- include/sys/msg.h | 1 + include/sys/sem.h | 1 + include/sys/shm.h | 1 + 3 files changed, 3 insertions(+) diff --git a/include/sys/msg.h b/include/sys/msg.h index 139f22b7..be6afc34 100644 --- a/include/sys/msg.h +++ b/include/sys/msg.h @@ -27,6 +27,7 @@ typedef unsigned long msglen_t; #define MSG_STAT 11 #define MSG_INFO 12 +#define MSG_STAT_ANY 13 struct msginfo { int msgpool, msgmap, msgmax, msgmnb, msgmni, msgssz, msgtql; diff --git a/include/sys/sem.h b/include/sys/sem.h index e7c36980..61cdb83d 100644 --- a/include/sys/sem.h +++ b/include/sys/sem.h @@ -33,6 +33,7 @@ extern "C" { #define SEM_STAT 18 #define SEM_INFO 19 +#define SEM_STAT_ANY 20 struct seminfo { int semmap; diff --git a/include/sys/shm.h b/include/sys/shm.h index e7d39ff6..662fde59 100644 --- a/include/sys/shm.h +++ b/include/sys/shm.h @@ -35,6 +35,7 @@ extern "C" { #define SHM_UNLOCK 12 #define SHM_STAT 13 #define SHM_INFO 14 +#define SHM_STAT_ANY 15 #define SHM_DEST 01000 #define SHM_LOCKED 02000 #define SHM_HUGETLB 04000 From ebeb1de2887a7d11810106d9a408138541182cf2 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 9 Jun 2018 21:15:13 +0000 Subject: [PATCH 154/161] add TCP_NLA_* from linux v4.17 new and missing netlink attributes types for SCM_TIMESTAMPING_OPT_STATS, new ones were added in commits 7156d194a0772f733865267e7207e0b08f81b02b be631892948060f44b1ceee3132be1266932071e 87ecc95d81d951b0984f2eb9c5c118cb68d0dce8 --- include/netinet/tcp.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h index 2747f4ea..1e2acfbf 100644 --- a/include/netinet/tcp.h +++ b/include/netinet/tcp.h @@ -56,6 +56,16 @@ enum { TCP_NLA_SNDBUF_LIMITED, TCP_NLA_DATA_SEGS_OUT, TCP_NLA_TOTAL_RETRANS, + TCP_NLA_PACING_RATE, + TCP_NLA_DELIVERY_RATE, + TCP_NLA_SND_CWND, + TCP_NLA_REORDERING, + TCP_NLA_MIN_RTT, + TCP_NLA_RECUR_RETRANS, + TCP_NLA_DELIVERY_RATE_APP_LMT, + TCP_NLA_SNDQ_SIZE, + TCP_NLA_CA_STATE, + TCP_NLA_SND_SSTHRESH, }; #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) From 5b85ed5cec915a2f1c23170e59b0658986c0ade4 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 9 Jun 2018 21:20:45 +0000 Subject: [PATCH 155/161] add ETH_P_PREAUTH ethertype from linux v4.17 added in linux commit 4fe0de5b143762d327bfaf1d7be7c5b58041a18c --- include/netinet/if_ether.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/netinet/if_ether.h b/include/netinet/if_ether.h index f7df5f7f..ecd6c73c 100644 --- a/include/netinet/if_ether.h +++ b/include/netinet/if_ether.h @@ -56,6 +56,7 @@ #define ETH_P_8021AD 0x88A8 #define ETH_P_802_EX1 0x88B5 #define ETH_P_ERSPAN 0x88BE +#define ETH_P_PREAUTH 0x88C7 #define ETH_P_TIPC 0x88CA #define ETH_P_MACSEC 0x88E5 #define ETH_P_8021AH 0x88E7 From da9f2b2ac8d91e556125d5b0f94830f88f1bc487 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 9 Jun 2018 21:23:54 +0000 Subject: [PATCH 156/161] add speculation control prctls from linux v4.17 PR_{SET,GET}_SPECULATION_CTRL controls speculation related vulnerability mitigations, new in commits b617cfc858161140d69cc0b5cc211996b557a1c7 356e4bfff2c5489e016fdb925adbf12a1e3950ee --- include/sys/prctl.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/sys/prctl.h b/include/sys/prctl.h index aa0c7a88..af76408c 100644 --- a/include/sys/prctl.h +++ b/include/sys/prctl.h @@ -136,6 +136,15 @@ struct prctl_mm_map { #define PR_SVE_VL_LEN_MASK 0xffff #define PR_SVE_VL_INHERIT (1 << 17) +#define PR_GET_SPECULATION_CTRL 52 +#define PR_SET_SPECULATION_CTRL 53 +#define PR_SPEC_STORE_BYPASS 0 +#define PR_SPEC_NOT_AFFECTED 0 +#define PR_SPEC_PRCTL (1UL << 0) +#define PR_SPEC_ENABLE (1UL << 1) +#define PR_SPEC_DISABLE (1UL << 2) +#define PR_SPEC_FORCE_DISABLE (1UL << 3) + int prctl (int, ...); #ifdef __cplusplus From f3b6690a53c81a869173bbdce701972c952a4e82 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 9 Jun 2018 22:51:08 +0000 Subject: [PATCH 157/161] aarch64: add HWCAP_ flags from linux v4.17 hwcaps for armv8.4, new in linux commit 7206dc93a58fb76421c4411eefa3c003337bcb2d --- arch/aarch64/bits/hwcap.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/aarch64/bits/hwcap.h b/arch/aarch64/bits/hwcap.h index 6fa64e8c..8541e329 100644 --- a/arch/aarch64/bits/hwcap.h +++ b/arch/aarch64/bits/hwcap.h @@ -22,3 +22,7 @@ #define HWCAP_SHA512 (1 << 21) #define HWCAP_SVE (1 << 22) #define HWCAP_ASIMDFHM (1 << 23) +#define HWCAP_DIT (1 << 24) +#define HWCAP_USCAT (1 << 25) +#define HWCAP_ILRCPC (1 << 26) +#define HWCAP_FLAGM (1 << 27) From 1177f61d6e9eb3751014ef27fb3ce1b58c620b00 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 9 Jun 2018 22:58:19 +0000 Subject: [PATCH 158/161] mips: add HWCAP_ flags from linux v4.17 new in linux commit 256211f2b0b251e532d1899b115e374feb16fa7a --- arch/mips/bits/hwcap.h | 1 + arch/mips64/bits/hwcap.h | 1 + arch/mipsn32/bits/hwcap.h | 1 + 3 files changed, 3 insertions(+) diff --git a/arch/mips/bits/hwcap.h b/arch/mips/bits/hwcap.h index 05cffba4..13e86fe7 100644 --- a/arch/mips/bits/hwcap.h +++ b/arch/mips/bits/hwcap.h @@ -1,2 +1,3 @@ #define HWCAP_MIPS_R6 (1 << 0) #define HWCAP_MIPS_MSA (1 << 1) +#define HWCAP_MIPS_CRC32 (1 << 2) diff --git a/arch/mips64/bits/hwcap.h b/arch/mips64/bits/hwcap.h index 05cffba4..13e86fe7 100644 --- a/arch/mips64/bits/hwcap.h +++ b/arch/mips64/bits/hwcap.h @@ -1,2 +1,3 @@ #define HWCAP_MIPS_R6 (1 << 0) #define HWCAP_MIPS_MSA (1 << 1) +#define HWCAP_MIPS_CRC32 (1 << 2) diff --git a/arch/mipsn32/bits/hwcap.h b/arch/mipsn32/bits/hwcap.h index 05cffba4..13e86fe7 100644 --- a/arch/mipsn32/bits/hwcap.h +++ b/arch/mipsn32/bits/hwcap.h @@ -1,2 +1,3 @@ #define HWCAP_MIPS_R6 (1 << 0) #define HWCAP_MIPS_MSA (1 << 1) +#define HWCAP_MIPS_CRC32 (1 << 2) From 7ea235b1be38c57c49b164c9762cf90be02dbc05 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Sat, 9 Jun 2018 23:03:48 +0000 Subject: [PATCH 159/161] s390x: add kexec_file_load syscall number from linux v4.17 new in linux commit 71406883fd35794d573b3085433c41d0a3bf6c21 --- arch/s390x/bits/syscall.h.in | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/s390x/bits/syscall.h.in b/arch/s390x/bits/syscall.h.in index c965664c..409e9155 100644 --- a/arch/s390x/bits/syscall.h.in +++ b/arch/s390x/bits/syscall.h.in @@ -323,4 +323,5 @@ #define __NR_s390_guarded_storage 378 #define __NR_statx 379 #define __NR_s390_sthyi 380 +#define __NR_kexec_file_load 381 From 0cd2be231481d68d244662bde25ad9cadbd7221d Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 20 Jun 2018 00:07:09 -0400 Subject: [PATCH 160/161] work around broken kernel struct ipc_perm on some big endian archs the mode member of struct ipc_perm is specified by POSIX to have type mode_t, which is uniformly defined as unsigned int. however, Linux defines it with type __kernel_mode_t, and defines __kernel_mode_t as unsigned short on some archs. since there is a subsequent padding field, treating it as a 32-bit unsigned int works on little endian archs, but the order is backwards on big endian archs with the erroneous definition. since multiple archs are affected, remedy the situation with fixup code in the affected functions (shmctl, semctl, and msgctl) rather than repeating the same shims in syscall_arch.h for every affected arch. --- arch/arm/syscall_arch.h | 2 ++ arch/m68k/syscall_arch.h | 1 + arch/microblaze/syscall_arch.h | 2 ++ arch/sh/syscall_arch.h | 2 ++ src/ipc/msgctl.c | 30 ++++++++++++++++++++++++++---- src/ipc/semctl.c | 30 ++++++++++++++++++++++++++---- src/ipc/shmctl.c | 30 ++++++++++++++++++++++++++---- 7 files changed, 85 insertions(+), 12 deletions(-) diff --git a/arch/arm/syscall_arch.h b/arch/arm/syscall_arch.h index 4db7d152..53fb155c 100644 --- a/arch/arm/syscall_arch.h +++ b/arch/arm/syscall_arch.h @@ -103,3 +103,5 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo #define VDSO_CGT_VER "LINUX_2.6" #define SYSCALL_FADVISE_6_ARG + +#define SYSCALL_IPC_BROKEN_MODE diff --git a/arch/m68k/syscall_arch.h b/arch/m68k/syscall_arch.h index 53a4256f..af79c306 100644 --- a/arch/m68k/syscall_arch.h +++ b/arch/m68k/syscall_arch.h @@ -88,3 +88,4 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo } #define SYSCALL_USE_SOCKETCALL +#define SYSCALL_IPC_BROKEN_MODE diff --git a/arch/microblaze/syscall_arch.h b/arch/microblaze/syscall_arch.h index 8e2de7ea..6cf631ad 100644 --- a/arch/microblaze/syscall_arch.h +++ b/arch/microblaze/syscall_arch.h @@ -102,3 +102,5 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo #define SYSCALL_NO_INLINE #endif + +#define SYSCALL_IPC_BROKEN_MODE diff --git a/arch/sh/syscall_arch.h b/arch/sh/syscall_arch.h index 84758fe0..48f61d94 100644 --- a/arch/sh/syscall_arch.h +++ b/arch/sh/syscall_arch.h @@ -86,3 +86,5 @@ static inline long __syscall6(long n, long a, long b, long c, long d, long e, lo register long r1 __asm__("r1") = f; __asm_syscall(22, "r"(r3), "r"(r4), "r"(r5), "r"(r6), "r"(r7), "0"(r0), "r"(r1)); } + +#define SYSCALL_IPC_BROKEN_MODE diff --git a/src/ipc/msgctl.c b/src/ipc/msgctl.c index 4372c719..ea9b2337 100644 --- a/src/ipc/msgctl.c +++ b/src/ipc/msgctl.c @@ -1,12 +1,34 @@ #include +#include #include "syscall.h" #include "ipc.h" +#if __BYTE_ORDER != __BIG_ENDIAN +#undef SYSCALL_IPC_BROKEN_MODE +#endif + int msgctl(int q, int cmd, struct msqid_ds *buf) { -#ifdef SYS_msgctl - return syscall(SYS_msgctl, q, cmd | IPC_64, buf); -#else - return syscall(SYS_ipc, IPCOP_msgctl, q, cmd | IPC_64, 0, buf, 0); +#ifdef SYSCALL_IPC_BROKEN_MODE + struct msqid_ds tmp; + if (cmd == IPC_SET) { + tmp = *buf; + tmp.msg_perm.mode *= 0x10000U; + buf = &tmp; + } #endif +#ifdef SYS_msgctl + int r = __syscall(SYS_msgctl, q, cmd | IPC_64, buf); +#else + int r = __syscall(SYS_ipc, IPCOP_msgctl, q, cmd | IPC_64, 0, buf, 0); +#endif +#ifdef SYSCALL_IPC_BROKEN_MODE + if (r >= 0) switch (cmd) { + case IPC_STAT: + case MSG_STAT: + case MSG_STAT_ANY: + buf->msg_perm.mode >>= 16; + } +#endif + return __syscall_ret(r); } diff --git a/src/ipc/semctl.c b/src/ipc/semctl.c index 673a9a8c..941e2813 100644 --- a/src/ipc/semctl.c +++ b/src/ipc/semctl.c @@ -1,8 +1,13 @@ #include #include +#include #include "syscall.h" #include "ipc.h" +#if __BYTE_ORDER != __BIG_ENDIAN +#undef SYSCALL_IPC_BROKEN_MODE +#endif + union semun { int val; struct semid_ds *buf; @@ -20,9 +25,26 @@ int semctl(int id, int num, int cmd, ...) arg = va_arg(ap, union semun); va_end(ap); } -#ifdef SYS_semctl - return syscall(SYS_semctl, id, num, cmd | IPC_64, arg.buf); -#else - return syscall(SYS_ipc, IPCOP_semctl, id, num, cmd | IPC_64, &arg.buf); +#ifdef SYSCALL_IPC_BROKEN_MODE + struct semid_ds tmp; + if (cmd == IPC_SET) { + tmp = *arg.buf; + tmp.sem_perm.mode *= 0x10000U; + arg.buf = &tmp; + } #endif +#ifdef SYS_semctl + int r = __syscall(SYS_semctl, id, num, cmd | IPC_64, arg.buf); +#else + int r = __syscall(SYS_ipc, IPCOP_semctl, id, num, cmd | IPC_64, &arg.buf); +#endif +#ifdef SYSCALL_IPC_BROKEN_MODE + if (r >= 0) switch (cmd) { + case IPC_STAT: + case SEM_STAT: + case SEM_STAT_ANY: + arg.buf->sem_perm.mode >>= 16; + } +#endif + return __syscall_ret(r); } diff --git a/src/ipc/shmctl.c b/src/ipc/shmctl.c index e2879f20..c951a581 100644 --- a/src/ipc/shmctl.c +++ b/src/ipc/shmctl.c @@ -1,12 +1,34 @@ #include +#include #include "syscall.h" #include "ipc.h" +#if __BYTE_ORDER != __BIG_ENDIAN +#undef SYSCALL_IPC_BROKEN_MODE +#endif + int shmctl(int id, int cmd, struct shmid_ds *buf) { -#ifdef SYS_shmctl - return syscall(SYS_shmctl, id, cmd | IPC_64, buf); -#else - return syscall(SYS_ipc, IPCOP_shmctl, id, cmd | IPC_64, 0, buf, 0); +#ifdef SYSCALL_IPC_BROKEN_MODE + struct shmid_ds tmp; + if (cmd == IPC_SET) { + tmp = *buf; + tmp.shm_perm.mode *= 0x10000U; + buf = &tmp; + } #endif +#ifdef SYS_shmctl + int r = __syscall(SYS_shmctl, id, cmd | IPC_64, buf); +#else + int r = __syscall(SYS_ipc, IPCOP_shmctl, id, cmd | IPC_64, 0, buf, 0); +#endif +#ifdef SYSCALL_IPC_BROKEN_MODE + if (r >= 0) switch (cmd) { + case IPC_STAT: + case SHM_STAT: + case SHM_STAT_ANY: + buf->shm_perm.mode >>= 16; + } +#endif + return __syscall_ret(r); } From 84b25160e7e15e7531533a9a6b22d5431d1b7629 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Wed, 20 Jun 2018 15:28:49 -0400 Subject: [PATCH 161/161] fix m68k float.h long double exponent range unlike the x86 variant, the m68k ld80 format allows (biased) exponent zero with mantissa msb set, thereby extending the normal range. --- arch/m68k/bits/float.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/m68k/bits/float.h b/arch/m68k/bits/float.h index fd02a132..0e6899d5 100644 --- a/arch/m68k/bits/float.h +++ b/arch/m68k/bits/float.h @@ -3,12 +3,12 @@ #define FLT_EVAL_METHOD 2 #define LDBL_TRUE_MIN 3.6451995318824746025e-4951L -#define LDBL_MIN 3.3621031431120935063e-4932L +#define LDBL_MIN 1.68105157155604675313e-4932L #define LDBL_MAX 1.1897314953572317650e+4932L #define LDBL_EPSILON 1.0842021724855044340e-19L #define LDBL_MANT_DIG 64 -#define LDBL_MIN_EXP (-16381) +#define LDBL_MIN_EXP (-16382) #define LDBL_MAX_EXP 16384 #define LDBL_DIG 18