devel
Threads by month
- ----- 2026 -----
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- 1 participants
- 1176 discussions
uClibc-ng - small C library for embedded systems branch master updated. 49b3d8569a8c8cb724ba6eadb34dea2df9b5ec4d
by wbx@helium.waldemar-brodkorb.de 26 Dec '15
by wbx@helium.waldemar-brodkorb.de 26 Dec '15
26 Dec '15
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "uClibc-ng - small C library for embedded systems".
The branch, master has been updated
via 49b3d8569a8c8cb724ba6eadb34dea2df9b5ec4d (commit)
via b778f37b8395a3258925e13a706dbc7d43c7c0ed (commit)
via e6555c6f15da4545496c02ba569f3bc61e2a0210 (commit)
via a312047276043f460d796ed7b38ca52791eef386 (commit)
via de234fb71b8847e00007dd951e22091d8e954c7b (commit)
via 2ffb76519c1369c239364bd5bc11e6a92937b7e9 (commit)
via 382c1c583cd55486c654cd9e1d429e2b1256acda (commit)
via 990f2ce7da5ee67599d6d8a12b681713776275e0 (commit)
via 5659e2a1c763a51957c3e9bd13737534a1d894c6 (commit)
via 7807bd3ada8b488167f1e5ab486ef0feb560eab8 (commit)
from 6c718953a5d42a1a815af39f276aa0fa47e75e4b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 49b3d8569a8c8cb724ba6eadb34dea2df9b5ec4d
Author: Steve Ellcey <sellcey(a)imgtec.com>
Date: Wed Dec 23 08:38:41 2015 -0800
Replace bltzal with lapc for MIPS R6 builds.
The R6 version of MIPS does not support the bltzal instruction. This
patch changes dl-startup.h and dl-sysdep.h to use lapc on R6 instead.
lapc is a new R6 insruction so older systems need to continue to use
bltzal in order to load register $31.
Signed-off-by: Steve Ellcey <sellcey(a)imgtec.com>
commit b778f37b8395a3258925e13a706dbc7d43c7c0ed
Author: Steve Ellcey <sellcey(a)imgtec.com>
Date: Mon Dec 21 13:22:07 2015 -0800
Replace MIPS specific memcpy.S/memset.S with version from glibc/newlib.
These MIPS specific versions of memcpy.S and memset.S are faster than
the current ones and match what is in newlib and glibc. They also have
support for the mips32r6 and mips64r6 architectures.
Signed-off-by: Steve Ellcey <sellcey(a)imgtec.com>
commit e6555c6f15da4545496c02ba569f3bc61e2a0210
Author: Nicolas S. Dade <nic.dade(a)gmail.com>
Date: Fri Dec 18 19:39:19 2015 -0800
pselect: Use linux pselect syscall when available
Linux has a pselect syscall since 2.6.something. Using it
rather than emulating it with sigprocmask+select+sigprocmask
is smaller code, and works properly. (The emulation has
race conditions when unblocked signals arrive before or
after the select)
The tv.nsec >= 1E9 handling comes from uclibc's linux select()
implementation, which itself uses pselect() internally if the
pselect syscall exists. I though it would be good to do the
same here.
Note that although the libc pselect() API has 6 arguments,
the linux kernel syscall as 7 arguments. There is an extra,
somewhat vestigial, sizeof the signal mask argument.
Signed-off-by: Nicolas S. Dade <nic.dade(a)gmail.com>
commit a312047276043f460d796ed7b38ca52791eef386
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:58:08 2015 +0100
libc/pwd_grp: Create template for non-reentrant functions
Avoid a lot of copy'n'paste code, no functionality change
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
commit de234fb71b8847e00007dd951e22091d8e954c7b
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:56:08 2015 +0100
Use gcc's __builtin_mempcpy() as __mempcpy(), if possible
Patch from OpenWrt.
Reported-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
commit 2ffb76519c1369c239364bd5bc11e6a92937b7e9
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:51:13 2015 +0100
use arch specific thread stack size for nptl
Use the arch specific thread stack size for nptl if the size
returned by getrlimits exceeds it - fixes threads on systems
with only 16 MB RAM.
Patch from OpenWRT
Reported-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
commit 382c1c583cd55486c654cd9e1d429e2b1256acda
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:52:55 2015 +0100
Do define some IPv6 related symbols even with IPv6 disabled
Fixes compilation of some faulty applictions.
Patch from Freetz.org
Reported-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
commit 990f2ce7da5ee67599d6d8a12b681713776275e0
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:47:56 2015 +0100
resolv: fix gethostbyname2_r to match gethostbyname_r, fixing bugs with AAAA lookups
The latter half of gethostbyname2_r (doing AAAA queries) is rather dramatically different
from the corresponding portion of gethostbyname_r (doing A queries). This leads to problems
like calls to getaddrinfo only returning one IPv6 address, even when multiple exist.
Seems to be entirely a case of divergent evolution -- a half-decade of fixes for the IPv4
code but no love for IPv6. Until now. ;)
DNS behaviour for IPv6 is really no different than for IPv4 -- beyond the difference in
address sizes, there's no need for the functions to be so different.
Consequently, this patch really is almost just a cut-and-paste of gethostbyname_r, with
the appropriate substitutions of in6_addr, AF_INET6, etc; while holding on to the few
extra bits that actually belong in there (eg #ifdef __UCLIBC_HAS_IPV6__).
Signed-off-by: Wes Campaigne <westacular(a)gmail.com>
commit 5659e2a1c763a51957c3e9bd13737534a1d894c6
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:45:51 2015 +0100
inet/resolv: Fix broken h_aliases list terminator after 2dab3f5
Commit 2dab3f5a "resolv: tiny shrinkage in /etc/hosts handling" leads to
that read_etc_hosts_r() provide garbage pointer at the end of h_aliases
list if more than four hostnames follow a dotted quad in /etc/hosts
Test-case:
Add following line to /etc/hosts
63.63.0.2 host1 alias2 alias3 alias4 alias5
#include <stdio.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main (void)
{
int i;
char *a;
struct hostent *he;
struct in_addr ipv4addr;
inet_pton(AF_INET, "63.63.0.2", &ipv4addr);
he = gethostbyaddr(&ipv4addr, sizeof ipv4addr, AF_INET);
if (he == NULL)
exit(1);
printf("Host name: '%s'\n", he->h_name);
i = 0;
while ((a = he->h_aliases[i]) != NULL) {
printf("Host alias: '%s'\n", a);
++i;
}
return 0;
}
Wrong output:
Host name: 'host1'
Host alias: 'alias2'
Host alias: 'alias3'
Host alias: 'alias4'
Host alias: 'alias5'
Host alias: '??'
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 7807bd3ada8b488167f1e5ab486ef0feb560eab8
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Thu Dec 17 21:07:07 2015 +0100
Revert "glibc compat: bump glibc minor version"
This reverts commit 4a05ed87ceb946608100642121c32e642b58cd0d.
This breaks SSP detection for gcc, which might be problematic
for some projects. Revert it after some discussion with
buildroot and openembedded people.
-----------------------------------------------------------------------
Summary of changes:
include/features.h | 2 +-
include/string.h | 4 +-
ldso/ldso/mips/dl-startup.h | 5 +
ldso/ldso/mips/dl-sysdep.h | 5 +
libc/inet/resolv.c | 165 ++++--
libc/pwd_grp/fgetgrent.c | 12 +-
libc/pwd_grp/fgetpwent.c | 12 +-
libc/pwd_grp/fgetspent.c | 6 +-
libc/pwd_grp/getgrent.c | 5 +-
libc/pwd_grp/getgrgid.c | 6 +-
libc/pwd_grp/getgrgid_r.c | 7 +-
libc/pwd_grp/getgrnam.c | 6 +-
libc/pwd_grp/getgrnam_r.c | 7 +-
libc/pwd_grp/getpwent.c | 5 +-
libc/pwd_grp/getpwnam.c | 7 +-
libc/pwd_grp/getpwnam_r.c | 7 +-
libc/pwd_grp/getpwuid.c | 6 +-
libc/pwd_grp/getpwuid_r.c | 7 +-
libc/pwd_grp/getspent.c | 5 +-
libc/pwd_grp/getspnam.c | 6 +-
libc/pwd_grp/getspnam_r.c | 7 +-
libc/pwd_grp/pwd_grp.c | 263 +--------
libc/pwd_grp/pwd_grp_internal.c | 49 +-
libc/pwd_grp/sgetspent.c | 6 +-
libc/string/generic/mempcpy.c | 1 +
libc/string/mips/memcpy.S | 1051 +++++++++++++++++++++++++++--------
libc/string/mips/memset.S | 516 +++++++++++++----
libc/sysdeps/linux/common/bits/in.h | 2 +-
libc/sysdeps/linux/common/pselect.c | 52 ++
libpthread/nptl/init.c | 4 +
30 files changed, 1549 insertions(+), 687 deletions(-)
diff --git a/include/features.h b/include/features.h
index f6fbbf4..dcf1348 100644
--- a/include/features.h
+++ b/include/features.h
@@ -393,7 +393,7 @@ uClibc was built without large file support enabled.
these macros to test for features in specific releases. */
/* Don't do it, if you want to keep uClibc happy. */
#define __GLIBC__ 2
-#define __GLIBC_MINOR__ 10
+#define __GLIBC_MINOR__ 2
#endif
#define __GLIBC_PREREQ(maj, min) \
diff --git a/include/string.h b/include/string.h
index 1d75f44..80585ef 100644
--- a/include/string.h
+++ b/include/string.h
@@ -258,7 +258,9 @@ extern void *memmem (const void *__haystack, size_t __haystacklen,
/* Copy N bytes of SRC to DEST, return pointer to bytes after the
last written byte. */
-#if 0 /* uClibc: disabled */
+#if __GNUC_PREREQ (3, 4)
+# define __mempcpy(dest, src, n) __builtin_mempcpy(dest, src, n)
+#else /* uClibc: disabled */
extern void *__mempcpy (void *__restrict __dest,
const void *__restrict __src, size_t __n)
__THROW __nonnull ((1, 2));
diff --git a/ldso/ldso/mips/dl-startup.h b/ldso/ldso/mips/dl-startup.h
index 4d9918d..0cab7be 100644
--- a/ldso/ldso/mips/dl-startup.h
+++ b/ldso/ldso/mips/dl-startup.h
@@ -37,6 +37,7 @@ __asm__(""
#if _MIPS_SIM == _MIPS_SIM_ABI32
" subu $29, 16\n"
#endif
+# if !defined __mips_isa_rev || __mips_isa_rev < 6
#if _MIPS_SIM == _MIPS_SIM_ABI64
" dla $8, .coff\n"
#else /* O32 || N32 */
@@ -44,6 +45,10 @@ __asm__(""
#endif /* O32 || N32 */
" bltzal $8, .coff\n"
".coff:\n"
+# else
+ ".coff:\n"
+ " lapc $31, .coff\n"
+# endif
#if _MIPS_SIM == _MIPS_SIM_ABI64
" dsubu $8, $31, $8\n"
" dla $25, _dl_start\n"
diff --git a/ldso/ldso/mips/dl-sysdep.h b/ldso/ldso/mips/dl-sysdep.h
index 6041245..b2caa7f 100644
--- a/ldso/ldso/mips/dl-sysdep.h
+++ b/ldso/ldso/mips/dl-sysdep.h
@@ -225,10 +225,15 @@ elf_machine_load_address (void)
{
ElfW(Addr) addr;
__asm__ (" .set noreorder\n"
+# if !defined __mips_isa_rev || __mips_isa_rev < 6
" " STRINGXP (PTR_LA) " %0, 0f\n"
" bltzal $0, 0f\n"
" nop\n"
"0: " STRINGXP (PTR_SUBU) " %0, $31, %0\n"
+#else
+ "0: lapc $31, 0\n"
+ " " STRINGXP (PTR_SUBU) " %0, $31, %0\n"
+#endif
" .set reorder\n"
: "=r" (addr)
: /* No inputs */
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index bd2c6fc..c7487a6 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -1596,7 +1596,7 @@ parser_t * __open_etc_hosts(void)
#define MINTOKENS 2 /* ip address + canonical name */
#define MAXTOKENS (MINTOKENS + MAXALIASES)
-#define HALISTOFF (sizeof(char*) * MAXTOKENS)
+#define HALISTOFF (sizeof(char*) * (MAXTOKENS + 1)) /* reserve space for list terminator */
#define INADDROFF (HALISTOFF + 2 * sizeof(char*))
int __read_etc_hosts_r(
@@ -2197,12 +2197,13 @@ int gethostbyname2_r(const char *name,
? gethostbyname_r(name, result_buf, buf, buflen, result, h_errnop)
: HOST_NOT_FOUND;
#else
- struct in6_addr *in;
struct in6_addr **addr_list;
+ char **alias;
+ char *alias0;
unsigned char *packet;
struct resolv_answer a;
int i;
- int nest = 0;
+ int packet_len;
int wrong_af = 0;
if (family == AF_INET)
@@ -2217,9 +2218,8 @@ int gethostbyname2_r(const char *name,
/* do /etc/hosts first */
{
- int old_errno = errno; /* Save the old errno and reset errno */
- __set_errno(0); /* to check for missing /etc/hosts. */
-
+ int old_errno = errno; /* save the old errno and reset errno */
+ __set_errno(0); /* to check for missing /etc/hosts. */
i = __get_hosts_byname_r(name, AF_INET6 /*family*/, result_buf,
buf, buflen, result, h_errnop);
if (i == NETDB_SUCCESS) {
@@ -2241,42 +2241,58 @@ int gethostbyname2_r(const char *name,
}
__set_errno(old_errno);
}
+
DPRINTF("Nothing found in /etc/hosts\n");
*h_errnop = NETDB_INTERNAL;
+ /* prepare future h_aliases[0] */
+ i = strlen(name) + 1;
+ if ((ssize_t)buflen <= i)
+ return ERANGE;
+ memcpy(buf, name, i); /* paranoia: name might change */
+ alias0 = buf;
+ buf += i;
+ buflen -= i;
/* make sure pointer is aligned */
i = ALIGN_BUFFER_OFFSET(buf);
buf += i;
buflen -= i;
/* Layout in buf:
- * struct in6_addr* in;
- * struct in6_addr* addr_list[2];
- * char scratch_buf[256];
+ * char *alias[2];
+ * struct in6_addr* addr_list[NN+1];
+ * struct in6_addr* in[NN];
*/
- in = (struct in6_addr*)buf;
- buf += sizeof(*in);
- buflen -= sizeof(*in);
- addr_list = (struct in6_addr**)buf;
- buf += sizeof(*addr_list) * 2;
- buflen -= sizeof(*addr_list) * 2;
+ alias = (char **)buf;
+ buf += sizeof(alias[0]) * 2;
+ buflen -= sizeof(alias[0]) * 2;
+ addr_list = (struct in6_addr **)buf;
+ /* buflen may be < 0, must do signed compare */
if ((ssize_t)buflen < 256)
return ERANGE;
- addr_list[0] = in;
- addr_list[1] = NULL;
- strncpy(buf, name, buflen);
- buf[buflen] = '\0';
+
+ /* we store only one "alias" - the name itself */
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO -- generate the full list
+#endif
+ alias[0] = alias0;
+ alias[1] = NULL;
/* maybe it is already an address? */
- if (inet_pton(AF_INET6, name, in)) {
- result_buf->h_name = buf;
- result_buf->h_addrtype = AF_INET6;
- result_buf->h_length = sizeof(*in);
- result_buf->h_addr_list = (char **) addr_list;
- /* result_buf->h_aliases = ??? */
- *result = result_buf;
- *h_errnop = NETDB_SUCCESS;
- return NETDB_SUCCESS;
+ {
+ struct in6_addr *in = (struct in6_addr *)(buf + sizeof(addr_list[0]) * 2);
+ if (inet_pton(AF_INET6, name, in)) {
+ addr_list[0] = in;
+ addr_list[1] = NULL;
+ result_buf->h_name = alias0;
+ result_buf->h_aliases = alias;
+ result_buf->h_addrtype = AF_INET6;
+ result_buf->h_length = sizeof(struct in6_addr);
+ result_buf->h_addr_list = (char **) addr_list;
+ *result = result_buf;
+ *h_errnop = NETDB_SUCCESS;
+ return NETDB_SUCCESS;
+ }
}
/* what if /etc/hosts has it but it's not IPv6?
@@ -2288,51 +2304,80 @@ int gethostbyname2_r(const char *name,
}
/* talk to DNS servers */
-/* TODO: why it's so different from gethostbyname_r (IPv4 case)? */
- memset(&a, '\0', sizeof(a));
- for (;;) {
- int packet_len;
+ a.buf = buf;
+ /* take into account that at least one address will be there,
+ * we'll need space of one in6_addr + two addr_list[] elems */
+ a.buflen = buflen - ((sizeof(addr_list[0]) * 2 + sizeof(struct in6_addr)));
+ a.add_count = 0;
+ packet_len = __dns_lookup(name, T_AAAA, &packet, &a);
+ if (packet_len < 0) {
+ *h_errnop = HOST_NOT_FOUND;
+ DPRINTF("__dns_lookup returned < 0\n");
+ return TRY_AGAIN;
+ }
-/* Hmm why we memset(a) to zeros only once? */
- packet_len = __dns_lookup(buf, T_AAAA, &packet, &a);
- if (packet_len < 0) {
- *h_errnop = HOST_NOT_FOUND;
- return TRY_AGAIN;
+ if (a.atype == T_AAAA) { /* ADDRESS */
+ /* we need space for addr_list[] and one IPv6 address */
+ /* + 1 accounting for 1st addr (it's in a.rdata),
+ * another + 1 for NULL in last addr_list[]: */
+ int need_bytes = sizeof(addr_list[0]) * (a.add_count + 1 + 1)
+ /* for 1st addr (it's in a.rdata): */
+ + sizeof(struct in6_addr);
+ /* how many bytes will 2nd and following addresses take? */
+ int ips_len = a.add_count * a.rdlength;
+
+ buflen -= (need_bytes + ips_len);
+ if ((ssize_t)buflen < 0) {
+ DPRINTF("buffer too small for all addresses\n");
+ /* *h_errnop = NETDB_INTERNAL; - already is */
+ i = ERANGE;
+ goto free_and_ret;
}
- strncpy(buf, a.dotted, buflen);
- free(a.dotted);
- if (a.atype != T_CNAME)
- break;
+ /* if there are additional addresses in buf,
+ * move them forward so that they are not destroyed */
+ DPRINTF("a.add_count:%d a.rdlength:%d a.rdata:%p\n", a.add_count, a.rdlength, a.rdata);
+ memmove(buf + need_bytes, buf, ips_len);
- DPRINTF("Got a CNAME in gethostbyname()\n");
- if (++nest > MAX_RECURSE) {
- *h_errnop = NO_RECOVERY;
- return -1;
+ /* 1st address is in a.rdata, insert it */
+ buf += need_bytes - sizeof(struct in6_addr);
+ memcpy(buf, a.rdata, sizeof(struct in6_addr));
+
+ /* fill addr_list[] */
+ for (i = 0; i <= a.add_count; i++) {
+ addr_list[i] = (struct in6_addr*)buf;
+ buf += sizeof(struct in6_addr);
}
- i = __decode_dotted(packet, a.rdoffset, packet_len, buf, buflen);
- free(packet);
- if (i < 0) {
- *h_errnop = NO_RECOVERY;
- return -1;
+ addr_list[i] = NULL;
+
+ /* if we have enough space, we can report "better" name
+ * (it may contain search domains attached by __dns_lookup,
+ * or CNAME of the host if it is different from the name
+ * we used to find it) */
+ if (a.dotted && buflen > strlen(a.dotted)) {
+ strcpy(buf, a.dotted);
+ alias0 = buf;
}
- }
- if (a.atype == T_AAAA) { /* ADDRESS */
- memcpy(in, a.rdata, sizeof(*in));
- result_buf->h_name = buf;
+
+ result_buf->h_name = alias0;
+ result_buf->h_aliases = alias;
result_buf->h_addrtype = AF_INET6;
- result_buf->h_length = sizeof(*in);
+ result_buf->h_length = sizeof(struct in6_addr);
result_buf->h_addr_list = (char **) addr_list;
- /* result_buf->h_aliases = ??? */
- free(packet);
*result = result_buf;
*h_errnop = NETDB_SUCCESS;
- return NETDB_SUCCESS;
+ i = NETDB_SUCCESS;
+ goto free_and_ret;
}
- free(packet);
+
*h_errnop = HOST_NOT_FOUND;
- return TRY_AGAIN;
+ __set_h_errno(HOST_NOT_FOUND);
+ i = TRY_AGAIN;
+ free_and_ret:
+ free(a.dotted);
+ free(packet);
+ return i;
#endif /* __UCLIBC_HAS_IPV6__ */
}
libc_hidden_def(gethostbyname2_r)
diff --git a/libc/pwd_grp/fgetgrent.c b/libc/pwd_grp/fgetgrent.c
index 695aee1..6a45799 100644
--- a/libc/pwd_grp/fgetgrent.c
+++ b/libc/pwd_grp/fgetgrent.c
@@ -4,5 +4,15 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_fgetgrent
+#include <features.h>
+
+#ifdef __USE_SVID
+
+#define GETXXKEY_FUNC fgetgrent
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS FILE *stream
+#define GETXXKEY_ADD_VARIABLES stream
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
+
+#endif
diff --git a/libc/pwd_grp/fgetpwent.c b/libc/pwd_grp/fgetpwent.c
index ddcc7ff..6f65cf6 100644
--- a/libc/pwd_grp/fgetpwent.c
+++ b/libc/pwd_grp/fgetpwent.c
@@ -4,5 +4,15 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_fgetpwent
+#include <features.h>
+
+#ifdef __USE_SVID
+
+#define GETXXKEY_FUNC fgetpwent
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS FILE *stream
+#define GETXXKEY_ADD_VARIABLES stream
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
+
+#endif
diff --git a/libc/pwd_grp/fgetspent.c b/libc/pwd_grp/fgetspent.c
index b7c1ef2..77ca0b8 100644
--- a/libc/pwd_grp/fgetspent.c
+++ b/libc/pwd_grp/fgetspent.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_fgetspent
+#define GETXXKEY_FUNC fgetspent
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS FILE *stream
+#define GETXXKEY_ADD_VARIABLES stream
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrent.c b/libc/pwd_grp/getgrent.c
index 808e4e8..5b03b31 100644
--- a/libc/pwd_grp/getgrent.c
+++ b/libc/pwd_grp/getgrent.c
@@ -4,5 +4,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrent
+#define GETXXKEY_FUNC getgrent
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS void
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrgid.c b/libc/pwd_grp/getgrgid.c
index 96ce903..2988452 100644
--- a/libc/pwd_grp/getgrgid.c
+++ b/libc/pwd_grp/getgrgid.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrgid
+#define GETXXKEY_FUNC getgrgid
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS gid_t git
+#define GETXXKEY_ADD_VARIABLES git
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrgid_r.c b/libc/pwd_grp/getgrgid_r.c
index a962f4c..b0f0c9a 100644
--- a/libc/pwd_grp/getgrgid_r.c
+++ b/libc/pwd_grp/getgrgid_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrgid_r
+#define GETXXKEY_R_FUNC getgrgid_r
+#define GETXXKEY_R_PARSER __parsegrent
+#define GETXXKEY_R_ENTTYPE struct group
+#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
+#define DO_GETXXKEY_R_KEYTYPE gid_t
+#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrnam.c b/libc/pwd_grp/getgrnam.c
index 3b47d9a..f6ce459 100644
--- a/libc/pwd_grp/getgrnam.c
+++ b/libc/pwd_grp/getgrnam.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrnam
+#define GETXXKEY_FUNC getgrnam
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS const char *name
+#define GETXXKEY_ADD_VARIABLES name
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrnam_r.c b/libc/pwd_grp/getgrnam_r.c
index 592a66c..35121e7 100644
--- a/libc/pwd_grp/getgrnam_r.c
+++ b/libc/pwd_grp/getgrnam_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrnam_r
+#define GETXXKEY_R_FUNC getgrnam_r
+#define GETXXKEY_R_PARSER __parsegrent
+#define GETXXKEY_R_ENTTYPE struct group
+#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key))
+#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
+#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwent.c b/libc/pwd_grp/getpwent.c
index a617bc8..7ddc8ee 100644
--- a/libc/pwd_grp/getpwent.c
+++ b/libc/pwd_grp/getpwent.c
@@ -4,5 +4,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwent
+#define GETXXKEY_FUNC getpwent
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS void
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwnam.c b/libc/pwd_grp/getpwnam.c
index d00640b..e3e8c02 100644
--- a/libc/pwd_grp/getpwnam.c
+++ b/libc/pwd_grp/getpwnam.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwnam
+#define GETXXKEY_FUNC getpwnam
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS const char *name
+#define GETXXKEY_ADD_VARIABLES name
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
+#define GETXXKEY_FUNC_HIDDEN
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwnam_r.c b/libc/pwd_grp/getpwnam_r.c
index a4440e7..bc5e3d5 100644
--- a/libc/pwd_grp/getpwnam_r.c
+++ b/libc/pwd_grp/getpwnam_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwnam_r
+#define GETXXKEY_R_FUNC getpwnam_r
+#define GETXXKEY_R_PARSER __parsepwent
+#define GETXXKEY_R_ENTTYPE struct passwd
+#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key))
+#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
+#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwuid.c b/libc/pwd_grp/getpwuid.c
index 16ac50f..1ad2688 100644
--- a/libc/pwd_grp/getpwuid.c
+++ b/libc/pwd_grp/getpwuid.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwuid
+#define GETXXKEY_FUNC getpwuid
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS uid_t uid
+#define GETXXKEY_ADD_VARIABLES uid
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwuid_r.c b/libc/pwd_grp/getpwuid_r.c
index 21d39ed..0a5aa96 100644
--- a/libc/pwd_grp/getpwuid_r.c
+++ b/libc/pwd_grp/getpwuid_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwuid_r
+#define GETXXKEY_R_FUNC getpwuid_r
+#define GETXXKEY_R_PARSER __parsepwent
+#define GETXXKEY_R_ENTTYPE struct passwd
+#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
+#define DO_GETXXKEY_R_KEYTYPE uid_t
+#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getspent.c b/libc/pwd_grp/getspent.c
index 5699b67..4feb9f9 100644
--- a/libc/pwd_grp/getspent.c
+++ b/libc/pwd_grp/getspent.c
@@ -4,5 +4,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getspent
+#define GETXXKEY_FUNC getspent
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS void
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getspnam.c b/libc/pwd_grp/getspnam.c
index 19e40c7..a0a01ec 100644
--- a/libc/pwd_grp/getspnam.c
+++ b/libc/pwd_grp/getspnam.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getspnam
+#define GETXXKEY_FUNC getspnam
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS const char *name
+#define GETXXKEY_ADD_VARIABLES name
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getspnam_r.c b/libc/pwd_grp/getspnam_r.c
index 053b697..ea23848 100644
--- a/libc/pwd_grp/getspnam_r.c
+++ b/libc/pwd_grp/getspnam_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getspnam_r
+#define GETXXKEY_R_FUNC getspnam_r
+#define GETXXKEY_R_PARSER __parsespent
+#define GETXXKEY_R_ENTTYPE struct spwd
+#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key))
+#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
+#define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/pwd_grp.c b/libc/pwd_grp/pwd_grp.c
index 0e7c7f7..acdb08d 100644
--- a/libc/pwd_grp/pwd_grp.c
+++ b/libc/pwd_grp/pwd_grp.c
@@ -127,59 +127,6 @@ libc_hidden_def(fgetspent_r)
#endif
/**********************************************************************/
-/* For the various fget??ent funcs, return NULL on failure and a
- * pointer to the appropriate struct (statically allocated) on success.
- */
-/**********************************************************************/
-#ifdef L_fgetpwent
-
-#ifdef __USE_SVID
-
-struct passwd *fgetpwent(FILE *stream)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd resultbuf;
- struct passwd *result;
-
- fgetpwent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-#endif
-
-#endif
-/**********************************************************************/
-#ifdef L_fgetgrent
-
-#ifdef __USE_SVID
-
-struct group *fgetgrent(FILE *stream)
-{
- static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group resultbuf;
- struct group *result;
-
- fgetgrent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-#endif
-
-#endif
-/**********************************************************************/
-#ifdef L_fgetspent
-
-
-struct spwd *fgetspent(FILE *stream)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd resultbuf;
- struct spwd *result;
-
- fgetspent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
#ifdef L_sgetspent_r
int sgetspent_r(const char *string, struct spwd *result_buf,
@@ -213,92 +160,6 @@ libc_hidden_def(sgetspent_r)
#endif
/**********************************************************************/
-
-#ifdef GETXXKEY_R_FUNC
-#error GETXXKEY_R_FUNC is already defined!
-#endif
-
-#ifdef L_getpwnam_r
-#define GETXXKEY_R_FUNC getpwnam_r
-#define GETXXKEY_R_PARSER __parsepwent
-#define GETXXKEY_R_ENTTYPE struct passwd
-#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key))
-#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
-#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getgrnam_r
-#define GETXXKEY_R_FUNC getgrnam_r
-#define GETXXKEY_R_PARSER __parsegrent
-#define GETXXKEY_R_ENTTYPE struct group
-#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key))
-#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
-#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getspnam_r
-#define GETXXKEY_R_FUNC getspnam_r
-#define GETXXKEY_R_PARSER __parsespent
-#define GETXXKEY_R_ENTTYPE struct spwd
-#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key))
-#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
-#define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getpwuid_r
-#define GETXXKEY_R_FUNC getpwuid_r
-#define GETXXKEY_R_PARSER __parsepwent
-#define GETXXKEY_R_ENTTYPE struct passwd
-#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
-#define DO_GETXXKEY_R_KEYTYPE uid_t
-#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getgrgid_r
-#define GETXXKEY_R_FUNC getgrgid_r
-#define GETXXKEY_R_PARSER __parsegrent
-#define GETXXKEY_R_ENTTYPE struct group
-#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
-#define DO_GETXXKEY_R_KEYTYPE gid_t
-#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
-#include "pwd_grp_internal.c"
-#endif
-
-/**********************************************************************/
-#ifdef L_getpwuid
-
-
-struct passwd *getpwuid(uid_t uid)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd resultbuf;
- struct passwd *result;
-
- getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getgrgid
-
-
-struct group *getgrgid(gid_t gid)
-{
- static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group resultbuf;
- struct group *result;
-
- getgrgid_r(gid, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
#ifdef L_getspuid_r
/* This function is non-standard and is currently not built. It seems
@@ -325,69 +186,6 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
#endif
/**********************************************************************/
-#ifdef L_getspuid
-
-/* This function is non-standard and is currently not built.
- * Why it was added, I do not know. */
-
-struct spwd *getspuid(uid_t uid)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd resultbuf;
- struct spwd *result;
-
- getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getpwnam
-
-
-struct passwd *getpwnam(const char *name)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd resultbuf;
- struct passwd *result;
-
- getpwnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-libc_hidden_def(getpwnam)
-
-#endif
-/**********************************************************************/
-#ifdef L_getgrnam
-
-
-struct group *getgrnam(const char *name)
-{
- static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group resultbuf;
- struct group *result;
-
- getgrnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getspnam
-
-
-struct spwd *getspnam(const char *name)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd resultbuf;
- struct spwd *result;
-
- getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
#ifdef L_getpw
@@ -585,65 +383,14 @@ libc_hidden_def(getspent_r)
#endif
/**********************************************************************/
-#ifdef L_getpwent
-
-
-struct passwd *getpwent(void)
-{
- static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd pwd;
- struct passwd *result;
-
- getpwent_r(&pwd, line_buff, sizeof(line_buff), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getgrent
-
-
-struct group *getgrent(void)
-{
- static char line_buff[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group gr;
- struct group *result;
-
- getgrent_r(&gr, line_buff, sizeof(line_buff), &result);
- return result;
-}
-
-#endif
+/* For the various fget??ent funcs, return NULL on failure and a
+ * pointer to the appropriate struct (statically allocated) on success.
+ */
/**********************************************************************/
-#ifdef L_getspent
-
-
-struct spwd *getspent(void)
-{
- static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd spwd;
- struct spwd *result;
-
- getspent_r(&spwd, line_buff, sizeof(line_buff), &result);
- return result;
-}
-
+#if defined(GETXXKEY_FUNC) || defined(GETXXKEY_R_FUNC)
+#include "pwd_grp_internal.c"
#endif
-/**********************************************************************/
-#ifdef L_sgetspent
-
-
-struct spwd *sgetspent(const char *string)
-{
- static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd spwd;
- struct spwd *result;
-
- sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result);
- return result;
-}
-#endif
/**********************************************************************/
#ifdef L___getgrouplist_internal
diff --git a/libc/pwd_grp/pwd_grp_internal.c b/libc/pwd_grp/pwd_grp_internal.c
index d2fde11..104f532 100644
--- a/libc/pwd_grp/pwd_grp_internal.c
+++ b/libc/pwd_grp/pwd_grp_internal.c
@@ -36,18 +36,10 @@
#endif
/**********************************************************************/
-/* Sizes for statically allocated buffers. */
-
-/* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
- * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
-
-/**********************************************************************/
/* Prototypes for internal functions. */
-#ifndef GETXXKEY_R_FUNC
-#error GETXXKEY_R_FUNC is not defined!
+#if !defined(GETXXKEY_R_FUNC) && !defined(GETXXKEY_FUNC)
+#error GETXXKEY_R_FUNC/GETXXKEY_FUNC are not defined!
#endif
/**********************************************************************/
#ifdef GETXXKEY_R_FUNC
@@ -89,9 +81,44 @@ int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
}
libc_hidden_def(GETXXKEY_R_FUNC)
+#endif /* GETXXKEY_R_FUNC */
+
+/**********************************************************************/
+#ifdef GETXXKEY_FUNC
+
+#define REENTRANT_NAME APPEND_R(GETXXKEY_FUNC)
+#define APPEND_R(name) APPEND_R1(name)
+#define APPEND_R1(name) name##_r
+
+GETXXKEY_ENTTYPE *GETXXKEY_FUNC(GETXXKEY_ADD_PARAMS)
+{
+ static char buffer[GETXXKEY_BUFLEN];
+ static GETXXKEY_ENTTYPE resultbuf;
+ GETXXKEY_ENTTYPE *result;
+
+# ifdef GETXXKEY_ADD_VARIABLES
+ REENTRANT_NAME(GETXXKEY_ADD_VARIABLES, &resultbuf, buffer, sizeof(buffer), &result);
+# else
+ REENTRANT_NAME(&resultbuf, buffer, sizeof(buffer), &result);
+# endif
+ return result;
+}
+#ifdef GETXXKEY_FUNC_HIDDEN
+libc_hidden_def(GETXXKEY_FUNC)
#endif
+
+#undef REENTRANT_NAME
+#undef APPEND_R
+#undef APPEND_R1
+#endif /* GETXXKEY_FUNC */
+
/**********************************************************************/
-#undef GETXXKEY_R_FUNC_HIDDEN
+#undef GETXXKEY_FUNC
+#undef GETXXKEY_ENTTYPE
+#undef GETXXKEY_BUFLEN
+#undef GETXXKEY_FUNC_HIDDEN
+#undef GETXXKEY_ADD_PARAMS
+#undef GETXXKEY_ADD_VARIABLES
#undef GETXXKEY_R_FUNC
#undef GETXXKEY_R_PARSER
#undef GETXXKEY_R_ENTTYPE
diff --git a/libc/pwd_grp/sgetspent.c b/libc/pwd_grp/sgetspent.c
index 877a247..990c0b6 100644
--- a/libc/pwd_grp/sgetspent.c
+++ b/libc/pwd_grp/sgetspent.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_sgetspent
+#define GETXXKEY_FUNC sgetspent
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS const char *string
+#define GETXXKEY_ADD_VARIABLES string
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/string/generic/mempcpy.c b/libc/string/generic/mempcpy.c
index d7fa79e..bb5563a 100644
--- a/libc/string/generic/mempcpy.c
+++ b/libc/string/generic/mempcpy.c
@@ -16,4 +16,5 @@ void *mempcpy (void *dstpp, const void *srcpp, size_t len)
return (void *)(((char *)dstpp) + len);
}
libc_hidden_weak(mempcpy)
+strong_alias(mempcpy,__mempcpy)
#endif
diff --git a/libc/string/mips/memcpy.S b/libc/string/mips/memcpy.S
index 48c4f2a..2a187ef 100644
--- a/libc/string/mips/memcpy.S
+++ b/libc/string/mips/memcpy.S
@@ -1,6 +1,5 @@
-/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2012-2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
- Contributed by Hartvig Ekner <hartvige(a)mips.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -13,243 +12,861 @@
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
+ License along with the GNU C Library. If not, see
<http://www.gnu.org/licenses/>. */
-#include <features.h>
-#include <sysdep.h>
-#include <endian.h>
+#ifdef ANDROID_CHANGES
+# include "machine/asm.h"
+# include "machine/regdef.h"
+# define USE_MEMMOVE_FOR_OVERLAP
+# define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD_STREAMED
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#elif _LIBC
+# include <sysdep.h>
+# include <regdef.h>
+# include <sys/asm.h>
+# define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD_STREAMED
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#elif defined _COMPILING_NEWLIB
+# include "machine/asm.h"
+# include "machine/regdef.h"
+# define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD_STREAMED
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#else
+# include <regdef.h>
+# include <sys/asm.h>
+#endif
+
+#if (_MIPS_ISA == _MIPS_ISA_MIPS4) || (_MIPS_ISA == _MIPS_ISA_MIPS5) || \
+ (_MIPS_ISA == _MIPS_ISA_MIPS32) || (_MIPS_ISA == _MIPS_ISA_MIPS64)
+# ifndef DISABLE_PREFETCH
+# define USE_PREFETCH
+# endif
+#endif
+
+#if defined(_MIPS_SIM) && ((_MIPS_SIM == _ABI64) || (_MIPS_SIM == _ABIN32))
+# ifndef DISABLE_DOUBLE
+# define USE_DOUBLE
+# endif
+#endif
+
+/* Some asm.h files do not have the L macro definition. */
+#ifndef L
+# if _MIPS_SIM == _ABIO32
+# define L(label) $L ## label
+# else
+# define L(label) .L ## label
+# endif
+#endif
+
+/* Some asm.h files do not have the PTR_ADDIU macro definition. */
+#ifndef PTR_ADDIU
+# ifdef USE_DOUBLE
+# define PTR_ADDIU daddiu
+# else
+# define PTR_ADDIU addiu
+# endif
+#endif
+
+/* Some asm.h files do not have the PTR_SRA macro definition. */
+#ifndef PTR_SRA
+# ifdef USE_DOUBLE
+# define PTR_SRA dsra
+# else
+# define PTR_SRA sra
+# endif
+#endif
+
+/* New R6 instructions that may not be in asm.h. */
+#ifndef PTR_LSA
+# if _MIPS_SIM == _ABI64
+# define PTR_LSA dlsa
+# else
+# define PTR_LSA lsa
+# endif
+#endif
+
+/*
+ * Using PREFETCH_HINT_LOAD_STREAMED instead of PREFETCH_LOAD on load
+ * prefetches appears to offer a slight preformance advantage.
+ *
+ * Using PREFETCH_HINT_PREPAREFORSTORE instead of PREFETCH_STORE
+ * or PREFETCH_STORE_STREAMED offers a large performance advantage
+ * but PREPAREFORSTORE has some special restrictions to consider.
+ *
+ * Prefetch with the 'prepare for store' hint does not copy a memory
+ * location into the cache, it just allocates a cache line and zeros
+ * it out. This means that if you do not write to the entire cache
+ * line before writing it out to memory some data will get zero'ed out
+ * when the cache line is written back to memory and data will be lost.
+ *
+ * Also if you are using this memcpy to copy overlapping buffers it may
+ * not behave correctly when using the 'prepare for store' hint. If you
+ * use the 'prepare for store' prefetch on a memory area that is in the
+ * memcpy source (as well as the memcpy destination), then you will get
+ * some data zero'ed out before you have a chance to read it and data will
+ * be lost.
+ *
+ * If you are going to use this memcpy routine with the 'prepare for store'
+ * prefetch you may want to set USE_MEMMOVE_FOR_OVERLAP in order to avoid
+ * the problem of running memcpy on overlapping buffers.
+ *
+ * There are ifdef'ed sections of this memcpy to make sure that it does not
+ * do prefetches on cache lines that are not going to be completely written.
+ * This code is only needed and only used when PREFETCH_STORE_HINT is set to
+ * PREFETCH_HINT_PREPAREFORSTORE. This code assumes that cache lines are
+ * 32 bytes and if the cache line is larger it will not work correctly.
+ */
+
+#ifdef USE_PREFETCH
+# define PREFETCH_HINT_LOAD 0
+# define PREFETCH_HINT_STORE 1
+# define PREFETCH_HINT_LOAD_STREAMED 4
+# define PREFETCH_HINT_STORE_STREAMED 5
+# define PREFETCH_HINT_LOAD_RETAINED 6
+# define PREFETCH_HINT_STORE_RETAINED 7
+# define PREFETCH_HINT_WRITEBACK_INVAL 25
+# define PREFETCH_HINT_PREPAREFORSTORE 30
+
+/*
+ * If we have not picked out what hints to use at this point use the
+ * standard load and store prefetch hints.
+ */
+# ifndef PREFETCH_STORE_HINT
+# define PREFETCH_STORE_HINT PREFETCH_HINT_STORE
+# endif
+# ifndef PREFETCH_LOAD_HINT
+# define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD
+# endif
+
+/*
+ * We double everything when USE_DOUBLE is true so we do 2 prefetches to
+ * get 64 bytes in that case. The assumption is that each individual
+ * prefetch brings in 32 bytes.
+ */
+
+# ifdef USE_DOUBLE
+# define PREFETCH_CHUNK 64
+# define PREFETCH_FOR_LOAD(chunk, reg) \
+ pref PREFETCH_LOAD_HINT, (chunk)*64(reg); \
+ pref PREFETCH_LOAD_HINT, ((chunk)*64)+32(reg)
+# define PREFETCH_FOR_STORE(chunk, reg) \
+ pref PREFETCH_STORE_HINT, (chunk)*64(reg); \
+ pref PREFETCH_STORE_HINT, ((chunk)*64)+32(reg)
+# else
+# define PREFETCH_CHUNK 32
+# define PREFETCH_FOR_LOAD(chunk, reg) \
+ pref PREFETCH_LOAD_HINT, (chunk)*32(reg)
+# define PREFETCH_FOR_STORE(chunk, reg) \
+ pref PREFETCH_STORE_HINT, (chunk)*32(reg)
+# endif
+/* MAX_PREFETCH_SIZE is the maximum size of a prefetch, it must not be less
+ * than PREFETCH_CHUNK, the assumed size of each prefetch. If the real size
+ * of a prefetch is greater than MAX_PREFETCH_SIZE and the PREPAREFORSTORE
+ * hint is used, the code will not work correctly. If PREPAREFORSTORE is not
+ * used then MAX_PREFETCH_SIZE does not matter. */
+# define MAX_PREFETCH_SIZE 128
+/* PREFETCH_LIMIT is set based on the fact that we never use an offset greater
+ * than 5 on a STORE prefetch and that a single prefetch can never be larger
+ * than MAX_PREFETCH_SIZE. We add the extra 32 when USE_DOUBLE is set because
+ * we actually do two prefetches in that case, one 32 bytes after the other. */
+# ifdef USE_DOUBLE
+# define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + 32 + MAX_PREFETCH_SIZE
+# else
+# define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + MAX_PREFETCH_SIZE
+# endif
+# if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) \
+ && ((PREFETCH_CHUNK * 4) < MAX_PREFETCH_SIZE)
+/* We cannot handle this because the initial prefetches may fetch bytes that
+ * are before the buffer being copied. We start copies with an offset
+ * of 4 so avoid this situation when using PREPAREFORSTORE. */
+#error "PREFETCH_CHUNK is too large and/or MAX_PREFETCH_SIZE is too small."
+# endif
+#else /* USE_PREFETCH not defined */
+# define PREFETCH_FOR_LOAD(offset, reg)
+# define PREFETCH_FOR_STORE(offset, reg)
+#endif
+
+#if __mips_isa_rev > 5
+# if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+# undef PREFETCH_STORE_HINT
+# define PREFETCH_STORE_HINT PREFETCH_HINT_STORE_STREAMED
+# endif
+# define R6_CODE
+#endif
-/* void *memcpy(void *s1, const void *s2, size_t n); */
+/* Allow the routine to be named something else if desired. */
+#ifndef MEMCPY_NAME
+# define MEMCPY_NAME memcpy
+#endif
+
+/* We use these 32/64 bit registers as temporaries to do the copying. */
+#define REG0 t0
+#define REG1 t1
+#define REG2 t2
+#define REG3 t3
+#if defined(_MIPS_SIM) && ((_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABIO64))
+# define REG4 t4
+# define REG5 t5
+# define REG6 t6
+# define REG7 t7
+#else
+# define REG4 ta0
+# define REG5 ta1
+# define REG6 ta2
+# define REG7 ta3
+#endif
-#ifdef __mips64
+/* We load/store 64 bits at a time when USE_DOUBLE is true.
+ * The C_ prefix stands for CHUNK and is used to avoid macro name
+ * conflicts with system header files. */
-#include <sys/asm.h>
+#ifdef USE_DOUBLE
+# define C_ST sd
+# define C_LD ld
+# ifdef __MIPSEB
+# define C_LDHI ldl /* high part is left in big-endian */
+# define C_STHI sdl /* high part is left in big-endian */
+# define C_LDLO ldr /* low part is right in big-endian */
+# define C_STLO sdr /* low part is right in big-endian */
+# else
+# define C_LDHI ldr /* high part is right in little-endian */
+# define C_STHI sdr /* high part is right in little-endian */
+# define C_LDLO ldl /* low part is left in little-endian */
+# define C_STLO sdl /* low part is left in little-endian */
+# endif
+# define C_ALIGN dalign /* r6 align instruction */
+#else
+# define C_ST sw
+# define C_LD lw
+# ifdef __MIPSEB
+# define C_LDHI lwl /* high part is left in big-endian */
+# define C_STHI swl /* high part is left in big-endian */
+# define C_LDLO lwr /* low part is right in big-endian */
+# define C_STLO swr /* low part is right in big-endian */
+# else
+# define C_LDHI lwr /* high part is right in little-endian */
+# define C_STHI swr /* high part is right in little-endian */
+# define C_LDLO lwl /* low part is left in little-endian */
+# define C_STLO swl /* low part is left in little-endian */
+# endif
+# define C_ALIGN align /* r6 align instruction */
+#endif
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define LDHI ldl /* high part is left in big-endian */
-# define SDHI sdl /* high part is left in big-endian */
-# define LDLO ldr /* low part is right in big-endian */
-# define SDLO sdr /* low part is right in big-endian */
+/* Bookkeeping values for 32 vs. 64 bit mode. */
+#ifdef USE_DOUBLE
+# define NSIZE 8
+# define NSIZEMASK 0x3f
+# define NSIZEDMASK 0x7f
#else
-# define LDHI ldr /* high part is right in little-endian */
-# define SDHI sdr /* high part is right in little-endian */
-# define LDLO ldl /* low part is left in little-endian */
-# define SDLO sdl /* low part is left in little-endian */
+# define NSIZE 4
+# define NSIZEMASK 0x1f
+# define NSIZEDMASK 0x3f
#endif
+#define UNIT(unit) ((unit)*NSIZE)
+#define UNITM1(unit) (((unit)*NSIZE)-1)
-ENTRY (memcpy)
+#ifdef ANDROID_CHANGES
+LEAF(MEMCPY_NAME, 0)
+#else
+LEAF(MEMCPY_NAME)
+#endif
+ .set nomips16
.set noreorder
+/*
+ * Below we handle the case where memcpy is called with overlapping src and dst.
+ * Although memcpy is not required to handle this case, some parts of Android
+ * like Skia rely on such usage. We call memmove to handle such cases.
+ */
+#ifdef USE_MEMMOVE_FOR_OVERLAP
+ PTR_SUBU t0,a0,a1
+ PTR_SRA t2,t0,31
+ xor t1,t0,t2
+ PTR_SUBU t0,t1,t2
+ sltu t2,t0,a2
+ beq t2,zero,L(memcpy)
+ la t9,memmove
+ jr t9
+ nop
+L(memcpy):
+#endif
+/*
+ * If the size is less than 2*NSIZE (8 or 16), go to L(lastb). Regardless of
+ * size, copy dst pointer to v0 for the return value.
+ */
+ slti t2,a2,(2 * NSIZE)
+ bne t2,zero,L(lasts)
+#if defined(RETURN_FIRST_PREFETCH) || defined(RETURN_LAST_PREFETCH)
+ move v0,zero
+#else
+ move v0,a0
+#endif
- slti t0, a2, 16 # Less than 16?
- bne t0, zero, L(last16)
- move v0, a0 # Setup exit value before too late
-
- xor t0, a1, a0 # Find a0/a1 displacement
- andi t0, 0x7
- bne t0, zero, L(shift) # Go handle the unaligned case
- PTR_SUBU t1, zero, a1
- andi t1, 0x7 # a0/a1 are aligned, but are we
- beq t1, zero, L(chk8w) # starting in the middle of a word?
- PTR_SUBU a2, t1
- LDHI t0, 0(a1) # Yes we are... take care of that
- PTR_ADDU a1, t1
- SDHI t0, 0(a0)
- PTR_ADDU a0, t1
-
-L(chk8w):
- andi t0, a2, 0x3f # 64 or more bytes left?
- beq t0, a2, L(chk1w)
- PTR_SUBU a3, a2, t0 # Yes
- PTR_ADDU a3, a1 # a3 = end address of loop
- move a2, t0 # a2 = what will be left after loop
-L(lop8w):
- ld t0, 0(a1) # Loop taking 8 words at a time
- ld t1, 8(a1)
- ld t2, 16(a1)
- ld t3, 24(a1)
- ld ta0, 32(a1)
- ld ta1, 40(a1)
- ld ta2, 48(a1)
- ld ta3, 56(a1)
- PTR_ADDIU a0, 64
- PTR_ADDIU a1, 64
- sd t0, -64(a0)
- sd t1, -56(a0)
- sd t2, -48(a0)
- sd t3, -40(a0)
- sd ta0, -32(a0)
- sd ta1, -24(a0)
- sd ta2, -16(a0)
- bne a1, a3, L(lop8w)
- sd ta3, -8(a0)
+#ifndef R6_CODE
-L(chk1w):
- andi t0, a2, 0x7 # 8 or more bytes left?
- beq t0, a2, L(last16)
- PTR_SUBU a3, a2, t0 # Yes, handle them one dword at a time
- PTR_ADDU a3, a1 # a3 again end address
- move a2, t0
-L(lop1w):
- ld t0, 0(a1)
- PTR_ADDIU a0, 8
- PTR_ADDIU a1, 8
- bne a1, a3, L(lop1w)
- sd t0, -8(a0)
-
-L(last16):
- blez a2, L(lst16e) # Handle last 16 bytes, one at a time
- PTR_ADDU a3, a2, a1
-L(lst16l):
- lb t0, 0(a1)
- PTR_ADDIU a0, 1
- PTR_ADDIU a1, 1
- bne a1, a3, L(lst16l)
- sb t0, -1(a0)
-L(lst16e):
- jr ra # Bye, bye
- nop
+/*
+ * If src and dst have different alignments, go to L(unaligned), if they
+ * have the same alignment (but are not actually aligned) do a partial
+ * load/store to make them aligned. If they are both already aligned
+ * we can start copying at L(aligned).
+ */
+ xor t8,a1,a0
+ andi t8,t8,(NSIZE-1) /* t8 is a0/a1 word-displacement */
+ bne t8,zero,L(unaligned)
+ PTR_SUBU a3, zero, a0
-L(shift):
- PTR_SUBU a3, zero, a0 # Src and Dest unaligned
- andi a3, 0x7 # (unoptimized case...)
- beq a3, zero, L(shft1)
- PTR_SUBU a2, a3 # a2 = bytes left
- LDHI t0, 0(a1) # Take care of first odd part
- LDLO t0, 7(a1)
- PTR_ADDU a1, a3
- SDHI t0, 0(a0)
- PTR_ADDU a0, a3
-L(shft1):
- andi t0, a2, 0x7
- PTR_SUBU a3, a2, t0
- PTR_ADDU a3, a1
-L(shfth):
- LDHI t1, 0(a1) # Limp through, dword by dword
- LDLO t1, 7(a1)
- PTR_ADDIU a0, 8
- PTR_ADDIU a1, 8
- bne a1, a3, L(shfth)
- sd t1, -8(a0)
- b L(last16) # Handle anything which may be left
- move a2, t0
+ andi a3,a3,(NSIZE-1) /* copy a3 bytes to align a0/a1 */
+ beq a3,zero,L(aligned) /* if a3=0, it is already aligned */
+ PTR_SUBU a2,a2,a3 /* a2 is the remining bytes count */
- .set reorder
-END (memcpy)
+ C_LDHI t8,0(a1)
+ PTR_ADDU a1,a1,a3
+ C_STHI t8,0(a0)
+ PTR_ADDU a0,a0,a3
+
+#else /* R6_CODE */
+
+/*
+ * Align the destination and hope that the source gets aligned too. If it
+ * doesn't we jump to L(r6_unaligned*) to do unaligned copies using the r6
+ * align instruction.
+ */
+ andi t8,a0,7
+ lapc t9,L(atable)
+ PTR_LSA t9,t8,t9,2
+ jrc t9
+L(atable):
+ bc L(lb0)
+ bc L(lb7)
+ bc L(lb6)
+ bc L(lb5)
+ bc L(lb4)
+ bc L(lb3)
+ bc L(lb2)
+ bc L(lb1)
+L(lb7):
+ lb a3, 6(a1)
+ sb a3, 6(a0)
+L(lb6):
+ lb a3, 5(a1)
+ sb a3, 5(a0)
+L(lb5):
+ lb a3, 4(a1)
+ sb a3, 4(a0)
+L(lb4):
+ lb a3, 3(a1)
+ sb a3, 3(a0)
+L(lb3):
+ lb a3, 2(a1)
+ sb a3, 2(a0)
+L(lb2):
+ lb a3, 1(a1)
+ sb a3, 1(a0)
+L(lb1):
+ lb a3, 0(a1)
+ sb a3, 0(a0)
+
+ li t9,8
+ subu t8,t9,t8
+ PTR_SUBU a2,a2,t8
+ PTR_ADDU a0,a0,t8
+ PTR_ADDU a1,a1,t8
+L(lb0):
-#else /* !__mips64 */
+ andi t8,a1,(NSIZE-1)
+ lapc t9,L(jtable)
+ PTR_LSA t9,t8,t9,2
+ jrc t9
+L(jtable):
+ bc L(aligned)
+ bc L(r6_unaligned1)
+ bc L(r6_unaligned2)
+ bc L(r6_unaligned3)
+# ifdef USE_DOUBLE
+ bc L(r6_unaligned4)
+ bc L(r6_unaligned5)
+ bc L(r6_unaligned6)
+ bc L(r6_unaligned7)
+# endif
+#endif /* R6_CODE */
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define LWHI lwl /* high part is left in big-endian */
-# define SWHI swl /* high part is left in big-endian */
-# define LWLO lwr /* low part is right in big-endian */
-# define SWLO swr /* low part is right in big-endian */
+L(aligned):
+
+/*
+ * Now dst/src are both aligned to (word or double word) aligned addresses
+ * Set a2 to count how many bytes we have to copy after all the 64/128 byte
+ * chunks are copied and a3 to the dst pointer after all the 64/128 byte
+ * chunks have been copied. We will loop, incrementing a0 and a1 until a0
+ * equals a3.
+ */
+
+ andi t8,a2,NSIZEDMASK /* any whole 64-byte/128-byte chunks? */
+ beq a2,t8,L(chkw) /* if a2==t8, no 64-byte/128-byte chunks */
+ PTR_SUBU a3,a2,t8 /* subtract from a2 the reminder */
+ PTR_ADDU a3,a0,a3 /* Now a3 is the final dst after loop */
+
+/* When in the loop we may prefetch with the 'prepare to store' hint,
+ * in this case the a0+x should not be past the "t0-32" address. This
+ * means: for x=128 the last "safe" a0 address is "t0-160". Alternatively,
+ * for x=64 the last "safe" a0 address is "t0-96" In the current version we
+ * will use "prefetch hint,128(a0)", so "t0-160" is the limit.
+ */
+#if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ PTR_ADDU t0,a0,a2 /* t0 is the "past the end" address */
+ PTR_SUBU t9,t0,PREFETCH_LIMIT /* t9 is the "last safe pref" address */
+#endif
+ PREFETCH_FOR_LOAD (0, a1)
+ PREFETCH_FOR_LOAD (1, a1)
+ PREFETCH_FOR_LOAD (2, a1)
+ PREFETCH_FOR_LOAD (3, a1)
+#if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE)
+ PREFETCH_FOR_STORE (1, a0)
+ PREFETCH_FOR_STORE (2, a0)
+ PREFETCH_FOR_STORE (3, a0)
+#endif
+#if defined(RETURN_FIRST_PREFETCH) && defined(USE_PREFETCH)
+# if PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE
+ sltu v1,t9,a0
+ bgtz v1,L(skip_set)
+ nop
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*4)
+L(skip_set):
+# else
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*1)
+# endif
+#endif
+#if defined(RETURN_LAST_PREFETCH) && defined(USE_PREFETCH) \
+ && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE)
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*3)
+# ifdef USE_DOUBLE
+ PTR_ADDIU v0,v0,32
+# endif
+#endif
+L(loop16w):
+ C_LD t0,UNIT(0)(a1)
+#if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ sltu v1,t9,a0 /* If a0 > t9 don't use next prefetch */
+ bgtz v1,L(skip_pref)
+#endif
+ C_LD t1,UNIT(1)(a1)
+#ifdef R6_CODE
+ PREFETCH_FOR_STORE (2, a0)
#else
-# define LWHI lwr /* high part is right in little-endian */
-# define SWHI swr /* high part is right in little-endian */
-# define LWLO lwl /* low part is left in little-endian */
-# define SWLO swl /* low part is left in little-endian */
+ PREFETCH_FOR_STORE (4, a0)
+ PREFETCH_FOR_STORE (5, a0)
+#endif
+#if defined(RETURN_LAST_PREFETCH) && defined(USE_PREFETCH)
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*5)
+# ifdef USE_DOUBLE
+ PTR_ADDIU v0,v0,32
+# endif
#endif
+L(skip_pref):
+ C_LD REG2,UNIT(2)(a1)
+ C_LD REG3,UNIT(3)(a1)
+ C_LD REG4,UNIT(4)(a1)
+ C_LD REG5,UNIT(5)(a1)
+ C_LD REG6,UNIT(6)(a1)
+ C_LD REG7,UNIT(7)(a1)
+#ifdef R6_CODE
+ PREFETCH_FOR_LOAD (3, a1)
+#else
+ PREFETCH_FOR_LOAD (4, a1)
+#endif
+ C_ST t0,UNIT(0)(a0)
+ C_ST t1,UNIT(1)(a0)
+ C_ST REG2,UNIT(2)(a0)
+ C_ST REG3,UNIT(3)(a0)
+ C_ST REG4,UNIT(4)(a0)
+ C_ST REG5,UNIT(5)(a0)
+ C_ST REG6,UNIT(6)(a0)
+ C_ST REG7,UNIT(7)(a0)
-ENTRY (memcpy)
- .set noreorder
+ C_LD t0,UNIT(8)(a1)
+ C_LD t1,UNIT(9)(a1)
+ C_LD REG2,UNIT(10)(a1)
+ C_LD REG3,UNIT(11)(a1)
+ C_LD REG4,UNIT(12)(a1)
+ C_LD REG5,UNIT(13)(a1)
+ C_LD REG6,UNIT(14)(a1)
+ C_LD REG7,UNIT(15)(a1)
+#ifndef R6_CODE
+ PREFETCH_FOR_LOAD (5, a1)
+#endif
+ C_ST t0,UNIT(8)(a0)
+ C_ST t1,UNIT(9)(a0)
+ C_ST REG2,UNIT(10)(a0)
+ C_ST REG3,UNIT(11)(a0)
+ C_ST REG4,UNIT(12)(a0)
+ C_ST REG5,UNIT(13)(a0)
+ C_ST REG6,UNIT(14)(a0)
+ C_ST REG7,UNIT(15)(a0)
+ PTR_ADDIU a0,a0,UNIT(16) /* adding 64/128 to dest */
+ bne a0,a3,L(loop16w)
+ PTR_ADDIU a1,a1,UNIT(16) /* adding 64/128 to src */
+ move a2,t8
+
+/* Here we have src and dest word-aligned but less than 64-bytes or
+ * 128 bytes to go. Check for a 32(64) byte chunk and copy if if there
+ * is one. Otherwise jump down to L(chk1w) to handle the tail end of
+ * the copy.
+ */
+
+L(chkw):
+ PREFETCH_FOR_LOAD (0, a1)
+ andi t8,a2,NSIZEMASK /* Is there a 32-byte/64-byte chunk. */
+ /* The t8 is the reminder count past 32-bytes */
+ beq a2,t8,L(chk1w) /* When a2=t8, no 32-byte chunk */
+ nop
+ C_LD t0,UNIT(0)(a1)
+ C_LD t1,UNIT(1)(a1)
+ C_LD REG2,UNIT(2)(a1)
+ C_LD REG3,UNIT(3)(a1)
+ C_LD REG4,UNIT(4)(a1)
+ C_LD REG5,UNIT(5)(a1)
+ C_LD REG6,UNIT(6)(a1)
+ C_LD REG7,UNIT(7)(a1)
+ PTR_ADDIU a1,a1,UNIT(8)
+ C_ST t0,UNIT(0)(a0)
+ C_ST t1,UNIT(1)(a0)
+ C_ST REG2,UNIT(2)(a0)
+ C_ST REG3,UNIT(3)(a0)
+ C_ST REG4,UNIT(4)(a0)
+ C_ST REG5,UNIT(5)(a0)
+ C_ST REG6,UNIT(6)(a0)
+ C_ST REG7,UNIT(7)(a0)
+ PTR_ADDIU a0,a0,UNIT(8)
+
+/*
+ * Here we have less than 32(64) bytes to copy. Set up for a loop to
+ * copy one word (or double word) at a time. Set a2 to count how many
+ * bytes we have to copy after all the word (or double word) chunks are
+ * copied and a3 to the dst pointer after all the (d)word chunks have
+ * been copied. We will loop, incrementing a0 and a1 until a0 equals a3.
+ */
+L(chk1w):
+ andi a2,t8,(NSIZE-1) /* a2 is the reminder past one (d)word chunks */
+ beq a2,t8,L(lastw)
+ PTR_SUBU a3,t8,a2 /* a3 is count of bytes in one (d)word chunks */
+ PTR_ADDU a3,a0,a3 /* a3 is the dst address after loop */
- slti t0, a2, 8 # Less than 8?
- bne t0, zero, L(last8)
- move v0, a0 # Setup exit value before too late
-
- xor t0, a1, a0 # Find a0/a1 displacement
- andi t0, 0x3
- bne t0, zero, L(shift) # Go handle the unaligned case
- subu t1, zero, a1
- andi t1, 0x3 # a0/a1 are aligned, but are we
- beq t1, zero, L(chk8w) # starting in the middle of a word?
- subu a2, t1
- LWHI t0, 0(a1) # Yes we are... take care of that
- addu a1, t1
- SWHI t0, 0(a0)
- addu a0, t1
-
-L(chk8w):
- andi t0, a2, 0x1f # 32 or more bytes left?
- beq t0, a2, L(chk1w)
- subu a3, a2, t0 # Yes
- addu a3, a1 # a3 = end address of loop
- move a2, t0 # a2 = what will be left after loop
-L(lop8w):
- lw t0, 0(a1) # Loop taking 8 words at a time
- lw t1, 4(a1)
- lw t2, 8(a1)
- lw t3, 12(a1)
- lw t4, 16(a1)
- lw t5, 20(a1)
- lw t6, 24(a1)
- lw t7, 28(a1)
- addiu a0, 32
- addiu a1, 32
- sw t0, -32(a0)
- sw t1, -28(a0)
- sw t2, -24(a0)
- sw t3, -20(a0)
- sw t4, -16(a0)
- sw t5, -12(a0)
- sw t6, -8(a0)
- bne a1, a3, L(lop8w)
- sw t7, -4(a0)
-
-L(chk1w):
- andi t0, a2, 0x3 # 4 or more bytes left?
- beq t0, a2, L(last8)
- subu a3, a2, t0 # Yes, handle them one word at a time
- addu a3, a1 # a3 again end address
- move a2, t0
-L(lop1w):
- lw t0, 0(a1)
- addiu a0, 4
- addiu a1, 4
- bne a1, a3, L(lop1w)
- sw t0, -4(a0)
-
-L(last8):
- blez a2, L(lst8e) # Handle last 8 bytes, one at a time
- addu a3, a2, a1
-L(lst8l):
- lb t0, 0(a1)
- addiu a0, 1
- addiu a1, 1
- bne a1, a3, L(lst8l)
- sb t0, -1(a0)
-L(lst8e):
- jr ra # Bye, bye
+/* copying in words (4-byte or 8-byte chunks) */
+L(wordCopy_loop):
+ C_LD REG3,UNIT(0)(a1)
+ PTR_ADDIU a0,a0,UNIT(1)
+ PTR_ADDIU a1,a1,UNIT(1)
+ bne a0,a3,L(wordCopy_loop)
+ C_ST REG3,UNIT(-1)(a0)
+
+/* If we have been copying double words, see if we can copy a single word
+ before doing byte copies. We can have, at most, one word to copy. */
+
+L(lastw):
+#ifdef USE_DOUBLE
+ andi t8,a2,3 /* a2 is the remainder past 4 byte chunks. */
+ beq t8,a2,L(lastb)
+ lw REG3,0(a1)
+ sw REG3,0(a0)
+ PTR_ADDIU a0,a0,4
+ PTR_ADDIU a1,a1,4
+ move a2,t8
+#endif
+
+/* Copy the last 8 (or 16) bytes */
+L(lastb):
+ blez a2,L(leave)
+ PTR_ADDU a3,a0,a2 /* a3 is the last dst address */
+L(lastbloop):
+ lb v1,0(a1)
+ PTR_ADDIU a0,a0,1
+ PTR_ADDIU a1,a1,1
+ bne a0,a3,L(lastbloop)
+ sb v1,-1(a0)
+L(leave):
+ j ra
nop
-L(shift):
- subu a3, zero, a0 # Src and Dest unaligned
- andi a3, 0x3 # (unoptimized case...)
- beq a3, zero, L(shft1)
- subu a2, a3 # a2 = bytes left
- LWHI t0, 0(a1) # Take care of first odd part
- LWLO t0, 3(a1)
- addu a1, a3
- SWHI t0, 0(a0)
- addu a0, a3
-L(shft1):
- andi t0, a2, 0x3
- subu a3, a2, t0
- addu a3, a1
-L(shfth):
- LWHI t1, 0(a1) # Limp through, word by word
- LWLO t1, 3(a1)
- addiu a0, 4
- addiu a1, 4
- bne a1, a3, L(shfth)
- sw t1, -4(a0)
- b L(last8) # Handle anything which may be left
- move a2, t0
+/* We jump here with a memcpy of less than 8 or 16 bytes, depending on
+ whether or not USE_DOUBLE is defined. Instead of just doing byte
+ copies, check the alignment and size and use lw/sw if possible.
+ Otherwise, do byte copies. */
- .set reorder
-END (memcpy)
+L(lasts):
+ andi t8,a2,3
+ beq t8,a2,L(lastb)
+
+ andi t9,a0,3
+ bne t9,zero,L(lastb)
+ andi t9,a1,3
+ bne t9,zero,L(lastb)
+
+ PTR_SUBU a3,a2,t8
+ PTR_ADDU a3,a0,a3
+
+L(wcopy_loop):
+ lw REG3,0(a1)
+ PTR_ADDIU a0,a0,4
+ PTR_ADDIU a1,a1,4
+ bne a0,a3,L(wcopy_loop)
+ sw REG3,-4(a0)
-#endif /* !__mips64 */
+ b L(lastb)
+ move a2,t8
-libc_hidden_def(memcpy)
+#ifndef R6_CODE
+/*
+ * UNALIGNED case, got here with a3 = "negu a0"
+ * This code is nearly identical to the aligned code above
+ * but only the destination (not the source) gets aligned
+ * so we need to do partial loads of the source followed
+ * by normal stores to the destination (once we have aligned
+ * the destination).
+ */
+
+L(unaligned):
+ andi a3,a3,(NSIZE-1) /* copy a3 bytes to align a0/a1 */
+ beqz a3,L(ua_chk16w) /* if a3=0, it is already aligned */
+ PTR_SUBU a2,a2,a3 /* a2 is the remining bytes count */
+
+ C_LDHI v1,UNIT(0)(a1)
+ C_LDLO v1,UNITM1(1)(a1)
+ PTR_ADDU a1,a1,a3
+ C_STHI v1,UNIT(0)(a0)
+ PTR_ADDU a0,a0,a3
+
+/*
+ * Now the destination (but not the source) is aligned
+ * Set a2 to count how many bytes we have to copy after all the 64/128 byte
+ * chunks are copied and a3 to the dst pointer after all the 64/128 byte
+ * chunks have been copied. We will loop, incrementing a0 and a1 until a0
+ * equals a3.
+ */
+
+L(ua_chk16w):
+ andi t8,a2,NSIZEDMASK /* any whole 64-byte/128-byte chunks? */
+ beq a2,t8,L(ua_chkw) /* if a2==t8, no 64-byte/128-byte chunks */
+ PTR_SUBU a3,a2,t8 /* subtract from a2 the reminder */
+ PTR_ADDU a3,a0,a3 /* Now a3 is the final dst after loop */
+
+# if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ PTR_ADDU t0,a0,a2 /* t0 is the "past the end" address */
+ PTR_SUBU t9,t0,PREFETCH_LIMIT /* t9 is the "last safe pref" address */
+# endif
+ PREFETCH_FOR_LOAD (0, a1)
+ PREFETCH_FOR_LOAD (1, a1)
+ PREFETCH_FOR_LOAD (2, a1)
+# if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE)
+ PREFETCH_FOR_STORE (1, a0)
+ PREFETCH_FOR_STORE (2, a0)
+ PREFETCH_FOR_STORE (3, a0)
+# endif
+# if defined(RETURN_FIRST_PREFETCH) && defined(USE_PREFETCH)
+# if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ sltu v1,t9,a0
+ bgtz v1,L(ua_skip_set)
+ nop
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*4)
+L(ua_skip_set):
+# else
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*1)
+# endif
+# endif
+L(ua_loop16w):
+ PREFETCH_FOR_LOAD (3, a1)
+ C_LDHI t0,UNIT(0)(a1)
+ C_LDHI t1,UNIT(1)(a1)
+ C_LDHI REG2,UNIT(2)(a1)
+# if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ sltu v1,t9,a0
+ bgtz v1,L(ua_skip_pref)
+# endif
+ C_LDHI REG3,UNIT(3)(a1)
+ PREFETCH_FOR_STORE (4, a0)
+ PREFETCH_FOR_STORE (5, a0)
+L(ua_skip_pref):
+ C_LDHI REG4,UNIT(4)(a1)
+ C_LDHI REG5,UNIT(5)(a1)
+ C_LDHI REG6,UNIT(6)(a1)
+ C_LDHI REG7,UNIT(7)(a1)
+ C_LDLO t0,UNITM1(1)(a1)
+ C_LDLO t1,UNITM1(2)(a1)
+ C_LDLO REG2,UNITM1(3)(a1)
+ C_LDLO REG3,UNITM1(4)(a1)
+ C_LDLO REG4,UNITM1(5)(a1)
+ C_LDLO REG5,UNITM1(6)(a1)
+ C_LDLO REG6,UNITM1(7)(a1)
+ C_LDLO REG7,UNITM1(8)(a1)
+ PREFETCH_FOR_LOAD (4, a1)
+ C_ST t0,UNIT(0)(a0)
+ C_ST t1,UNIT(1)(a0)
+ C_ST REG2,UNIT(2)(a0)
+ C_ST REG3,UNIT(3)(a0)
+ C_ST REG4,UNIT(4)(a0)
+ C_ST REG5,UNIT(5)(a0)
+ C_ST REG6,UNIT(6)(a0)
+ C_ST REG7,UNIT(7)(a0)
+ C_LDHI t0,UNIT(8)(a1)
+ C_LDHI t1,UNIT(9)(a1)
+ C_LDHI REG2,UNIT(10)(a1)
+ C_LDHI REG3,UNIT(11)(a1)
+ C_LDHI REG4,UNIT(12)(a1)
+ C_LDHI REG5,UNIT(13)(a1)
+ C_LDHI REG6,UNIT(14)(a1)
+ C_LDHI REG7,UNIT(15)(a1)
+ C_LDLO t0,UNITM1(9)(a1)
+ C_LDLO t1,UNITM1(10)(a1)
+ C_LDLO REG2,UNITM1(11)(a1)
+ C_LDLO REG3,UNITM1(12)(a1)
+ C_LDLO REG4,UNITM1(13)(a1)
+ C_LDLO REG5,UNITM1(14)(a1)
+ C_LDLO REG6,UNITM1(15)(a1)
+ C_LDLO REG7,UNITM1(16)(a1)
+ PREFETCH_FOR_LOAD (5, a1)
+ C_ST t0,UNIT(8)(a0)
+ C_ST t1,UNIT(9)(a0)
+ C_ST REG2,UNIT(10)(a0)
+ C_ST REG3,UNIT(11)(a0)
+ C_ST REG4,UNIT(12)(a0)
+ C_ST REG5,UNIT(13)(a0)
+ C_ST REG6,UNIT(14)(a0)
+ C_ST REG7,UNIT(15)(a0)
+ PTR_ADDIU a0,a0,UNIT(16) /* adding 64/128 to dest */
+ bne a0,a3,L(ua_loop16w)
+ PTR_ADDIU a1,a1,UNIT(16) /* adding 64/128 to src */
+ move a2,t8
+
+/* Here we have src and dest word-aligned but less than 64-bytes or
+ * 128 bytes to go. Check for a 32(64) byte chunk and copy if if there
+ * is one. Otherwise jump down to L(ua_chk1w) to handle the tail end of
+ * the copy. */
+
+L(ua_chkw):
+ PREFETCH_FOR_LOAD (0, a1)
+ andi t8,a2,NSIZEMASK /* Is there a 32-byte/64-byte chunk. */
+ /* t8 is the reminder count past 32-bytes */
+ beq a2,t8,L(ua_chk1w) /* When a2=t8, no 32-byte chunk */
+ nop
+ C_LDHI t0,UNIT(0)(a1)
+ C_LDHI t1,UNIT(1)(a1)
+ C_LDHI REG2,UNIT(2)(a1)
+ C_LDHI REG3,UNIT(3)(a1)
+ C_LDHI REG4,UNIT(4)(a1)
+ C_LDHI REG5,UNIT(5)(a1)
+ C_LDHI REG6,UNIT(6)(a1)
+ C_LDHI REG7,UNIT(7)(a1)
+ C_LDLO t0,UNITM1(1)(a1)
+ C_LDLO t1,UNITM1(2)(a1)
+ C_LDLO REG2,UNITM1(3)(a1)
+ C_LDLO REG3,UNITM1(4)(a1)
+ C_LDLO REG4,UNITM1(5)(a1)
+ C_LDLO REG5,UNITM1(6)(a1)
+ C_LDLO REG6,UNITM1(7)(a1)
+ C_LDLO REG7,UNITM1(8)(a1)
+ PTR_ADDIU a1,a1,UNIT(8)
+ C_ST t0,UNIT(0)(a0)
+ C_ST t1,UNIT(1)(a0)
+ C_ST REG2,UNIT(2)(a0)
+ C_ST REG3,UNIT(3)(a0)
+ C_ST REG4,UNIT(4)(a0)
+ C_ST REG5,UNIT(5)(a0)
+ C_ST REG6,UNIT(6)(a0)
+ C_ST REG7,UNIT(7)(a0)
+ PTR_ADDIU a0,a0,UNIT(8)
+/*
+ * Here we have less than 32(64) bytes to copy. Set up for a loop to
+ * copy one word (or double word) at a time.
+ */
+L(ua_chk1w):
+ andi a2,t8,(NSIZE-1) /* a2 is the reminder past one (d)word chunks */
+ beq a2,t8,L(ua_smallCopy)
+ PTR_SUBU a3,t8,a2 /* a3 is count of bytes in one (d)word chunks */
+ PTR_ADDU a3,a0,a3 /* a3 is the dst address after loop */
+
+/* copying in words (4-byte or 8-byte chunks) */
+L(ua_wordCopy_loop):
+ C_LDHI v1,UNIT(0)(a1)
+ C_LDLO v1,UNITM1(1)(a1)
+ PTR_ADDIU a0,a0,UNIT(1)
+ PTR_ADDIU a1,a1,UNIT(1)
+ bne a0,a3,L(ua_wordCopy_loop)
+ C_ST v1,UNIT(-1)(a0)
+
+/* Copy the last 8 (or 16) bytes */
+L(ua_smallCopy):
+ beqz a2,L(leave)
+ PTR_ADDU a3,a0,a2 /* a3 is the last dst address */
+L(ua_smallCopy_loop):
+ lb v1,0(a1)
+ PTR_ADDIU a0,a0,1
+ PTR_ADDIU a1,a1,1
+ bne a0,a3,L(ua_smallCopy_loop)
+ sb v1,-1(a0)
+
+ j ra
+ nop
+
+#else /* R6_CODE */
+
+# ifdef __MIPSEB
+# define SWAP_REGS(X,Y) X, Y
+# define ALIGN_OFFSET(N) (N)
+# else
+# define SWAP_REGS(X,Y) Y, X
+# define ALIGN_OFFSET(N) (NSIZE-N)
+# endif
+# define R6_UNALIGNED_WORD_COPY(BYTEOFFSET) \
+ andi REG7, a2, (NSIZE-1);/* REG7 is # of bytes to by bytes. */ \
+ beq REG7, a2, L(lastb); /* Check for bytes to copy by word */ \
+ PTR_SUBU a3, a2, REG7; /* a3 is number of bytes to be copied in */ \
+ /* (d)word chunks. */ \
+ move a2, REG7; /* a2 is # of bytes to copy byte by byte */ \
+ /* after word loop is finished. */ \
+ PTR_ADDU REG6, a0, a3; /* REG6 is the dst address after loop. */ \
+ PTR_SUBU REG2, a1, t8; /* REG2 is the aligned src address. */ \
+ PTR_ADDU a1, a1, a3; /* a1 is addr of source after word loop. */ \
+ C_LD t0, UNIT(0)(REG2); /* Load first part of source. */ \
+L(r6_ua_wordcopy##BYTEOFFSET): \
+ C_LD t1, UNIT(1)(REG2); /* Load second part of source. */ \
+ C_ALIGN REG3, SWAP_REGS(t1,t0), ALIGN_OFFSET(BYTEOFFSET); \
+ PTR_ADDIU a0, a0, UNIT(1); /* Increment destination pointer. */ \
+ PTR_ADDIU REG2, REG2, UNIT(1); /* Increment aligned source pointer.*/ \
+ move t0, t1; /* Move second part of source to first. */ \
+ bne a0, REG6,L(r6_ua_wordcopy##BYTEOFFSET); \
+ C_ST REG3, UNIT(-1)(a0); \
+ j L(lastb); \
+ nop
+
+ /* We are generating R6 code, the destination is 4 byte aligned and
+ the source is not 4 byte aligned. t8 is 1, 2, or 3 depending on the
+ alignment of the source. */
+
+L(r6_unaligned1):
+ R6_UNALIGNED_WORD_COPY(1)
+L(r6_unaligned2):
+ R6_UNALIGNED_WORD_COPY(2)
+L(r6_unaligned3):
+ R6_UNALIGNED_WORD_COPY(3)
+# ifdef USE_DOUBLE
+L(r6_unaligned4):
+ R6_UNALIGNED_WORD_COPY(4)
+L(r6_unaligned5):
+ R6_UNALIGNED_WORD_COPY(5)
+L(r6_unaligned6):
+ R6_UNALIGNED_WORD_COPY(6)
+L(r6_unaligned7):
+ R6_UNALIGNED_WORD_COPY(7)
+# endif
+#endif /* R6_CODE */
+
+ .set at
+ .set reorder
+END(MEMCPY_NAME)
+#ifndef ANDROID_CHANGES
+# ifdef _LIBC
+# ifdef __UCLIBC__
+libc_hidden_def(MEMCPY_NAME)
+# else
+libc_hidden_builtin_def (MEMCPY_NAME)
+# endif
+# endif
+#endif
diff --git a/libc/string/mips/memset.S b/libc/string/mips/memset.S
index 26b2598..ef8ab0b 100644
--- a/libc/string/mips/memset.S
+++ b/libc/string/mips/memset.S
@@ -1,6 +1,5 @@
-/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2013-2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
- Contributed by Hartvig Ekner <hartvige(a)mips.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -13,145 +12,420 @@
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
+ License along with the GNU C Library. If not, see
<http://www.gnu.org/licenses/>. */
-#include <features.h>
-#include <sysdep.h>
-#include <endian.h>
+#ifdef ANDROID_CHANGES
+# include "machine/asm.h"
+# include "machine/regdef.h"
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#elif _LIBC
+# include <sysdep.h>
+# include <regdef.h>
+# include <sys/asm.h>
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#elif defined _COMPILING_NEWLIB
+# include "machine/asm.h"
+# include "machine/regdef.h"
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#else
+# include <regdef.h>
+# include <sys/asm.h>
+#endif
+
+/* Check to see if the MIPS architecture we are compiling for supports
+ prefetching. */
+
+#if (__mips == 4) || (__mips == 5) || (__mips == 32) || (__mips == 64)
+# ifndef DISABLE_PREFETCH
+# define USE_PREFETCH
+# endif
+#endif
+
+#if defined(_MIPS_SIM) && ((_MIPS_SIM == _ABI64) || (_MIPS_SIM == _ABIN32))
+# ifndef DISABLE_DOUBLE
+# define USE_DOUBLE
+# endif
+#endif
+
+#ifndef USE_DOUBLE
+# ifndef DISABLE_DOUBLE_ALIGN
+# define DOUBLE_ALIGN
+# endif
+#endif
+
+
+/* Some asm.h files do not have the L macro definition. */
+#ifndef L
+# if _MIPS_SIM == _ABIO32
+# define L(label) $L ## label
+# else
+# define L(label) .L ## label
+# endif
+#endif
+
+/* Some asm.h files do not have the PTR_ADDIU macro definition. */
+#ifndef PTR_ADDIU
+# ifdef USE_DOUBLE
+# define PTR_ADDIU daddiu
+# else
+# define PTR_ADDIU addiu
+# endif
+#endif
-/* void *memset(void *s, int c, size_t n). */
+/* New R6 instructions that may not be in asm.h. */
+#ifndef PTR_LSA
+# if _MIPS_SIM == _ABI64
+# define PTR_LSA dlsa
+# else
+# define PTR_LSA lsa
+# endif
+#endif
+
+/* Using PREFETCH_HINT_PREPAREFORSTORE instead of PREFETCH_STORE
+ or PREFETCH_STORE_STREAMED offers a large performance advantage
+ but PREPAREFORSTORE has some special restrictions to consider.
+
+ Prefetch with the 'prepare for store' hint does not copy a memory
+ location into the cache, it just allocates a cache line and zeros
+ it out. This means that if you do not write to the entire cache
+ line before writing it out to memory some data will get zero'ed out
+ when the cache line is written back to memory and data will be lost.
+
+ There are ifdef'ed sections of this memcpy to make sure that it does not
+ do prefetches on cache lines that are not going to be completely written.
+ This code is only needed and only used when PREFETCH_STORE_HINT is set to
+ PREFETCH_HINT_PREPAREFORSTORE. This code assumes that cache lines are
+ less than MAX_PREFETCH_SIZE bytes and if the cache line is larger it will
+ not work correctly. */
+
+#ifdef USE_PREFETCH
+# define PREFETCH_HINT_STORE 1
+# define PREFETCH_HINT_STORE_STREAMED 5
+# define PREFETCH_HINT_STORE_RETAINED 7
+# define PREFETCH_HINT_PREPAREFORSTORE 30
+
+/* If we have not picked out what hints to use at this point use the
+ standard load and store prefetch hints. */
+# ifndef PREFETCH_STORE_HINT
+# define PREFETCH_STORE_HINT PREFETCH_HINT_STORE
+# endif
+
+/* We double everything when USE_DOUBLE is true so we do 2 prefetches to
+ get 64 bytes in that case. The assumption is that each individual
+ prefetch brings in 32 bytes. */
+# ifdef USE_DOUBLE
+# define PREFETCH_CHUNK 64
+# define PREFETCH_FOR_STORE(chunk, reg) \
+ pref PREFETCH_STORE_HINT, (chunk)*64(reg); \
+ pref PREFETCH_STORE_HINT, ((chunk)*64)+32(reg)
+# else
+# define PREFETCH_CHUNK 32
+# define PREFETCH_FOR_STORE(chunk, reg) \
+ pref PREFETCH_STORE_HINT, (chunk)*32(reg)
+# endif
-#ifdef __mips64
+/* MAX_PREFETCH_SIZE is the maximum size of a prefetch, it must not be less
+ than PREFETCH_CHUNK, the assumed size of each prefetch. If the real size
+ of a prefetch is greater than MAX_PREFETCH_SIZE and the PREPAREFORSTORE
+ hint is used, the code will not work correctly. If PREPAREFORSTORE is not
+ used than MAX_PREFETCH_SIZE does not matter. */
+# define MAX_PREFETCH_SIZE 128
+/* PREFETCH_LIMIT is set based on the fact that we never use an offset greater
+ than 5 on a STORE prefetch and that a single prefetch can never be larger
+ than MAX_PREFETCH_SIZE. We add the extra 32 when USE_DOUBLE is set because
+ we actually do two prefetches in that case, one 32 bytes after the other. */
+# ifdef USE_DOUBLE
+# define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + 32 + MAX_PREFETCH_SIZE
+# else
+# define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + MAX_PREFETCH_SIZE
+# endif
-#include <sys/asm.h>
+# if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) \
+ && ((PREFETCH_CHUNK * 4) < MAX_PREFETCH_SIZE)
+/* We cannot handle this because the initial prefetches may fetch bytes that
+ are before the buffer being copied. We start copies with an offset
+ of 4 so avoid this situation when using PREPAREFORSTORE. */
+# error "PREFETCH_CHUNK is too large and/or MAX_PREFETCH_SIZE is too small."
+# endif
+#else /* USE_PREFETCH not defined */
+# define PREFETCH_FOR_STORE(offset, reg)
+#endif
+
+#if __mips_isa_rev > 5
+# if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+# undef PREFETCH_STORE_HINT
+# define PREFETCH_STORE_HINT PREFETCH_HINT_STORE_STREAMED
+# endif
+# define R6_CODE
+#endif
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define SDHI sdl /* high part is left in big-endian */
+/* Allow the routine to be named something else if desired. */
+#ifndef MEMSET_NAME
+# define MEMSET_NAME memset
+#endif
+
+/* We load/store 64 bits at a time when USE_DOUBLE is true.
+ The C_ prefix stands for CHUNK and is used to avoid macro name
+ conflicts with system header files. */
+
+#ifdef USE_DOUBLE
+# define C_ST sd
+# ifdef __MIPSEB
+# define C_STHI sdl /* high part is left in big-endian */
+# else
+# define C_STHI sdr /* high part is right in little-endian */
+# endif
#else
-# define SDHI sdr /* high part is right in little-endian */
+# define C_ST sw
+# ifdef __MIPSEB
+# define C_STHI swl /* high part is left in big-endian */
+# else
+# define C_STHI swr /* high part is right in little-endian */
+# endif
#endif
-ENTRY (memset)
- .set noreorder
+/* Bookkeeping values for 32 vs. 64 bit mode. */
+#ifdef USE_DOUBLE
+# define NSIZE 8
+# define NSIZEMASK 0x3f
+# define NSIZEDMASK 0x7f
+#else
+# define NSIZE 4
+# define NSIZEMASK 0x1f
+# define NSIZEDMASK 0x3f
+#endif
+#define UNIT(unit) ((unit)*NSIZE)
+#define UNITM1(unit) (((unit)*NSIZE)-1)
- slti ta1, a2, 16 # Less than 16?
- bne ta1, zero, L(last16)
- move v0, a0 # Setup exit value before too late
-
- beq a1, zero, L(ueven) # If zero pattern, no need to extend
- andi a1, 0xff # Avoid problems with bogus arguments
- dsll ta0, a1, 8
- or a1, ta0
- dsll ta0, a1, 16
- or a1, ta0 # a1 is now pattern in full word
- dsll ta0, a1, 32
- or a1, ta0 # a1 is now pattern in double word
-
-L(ueven):
- PTR_SUBU ta0, zero, a0 # Unaligned address?
- andi ta0, 0x7
- beq ta0, zero, L(chkw)
- PTR_SUBU a2, ta0
- SDHI a1, 0(a0) # Yes, handle first unaligned part
- PTR_ADDU a0, ta0 # Now both a0 and a2 are updated
+#ifdef ANDROID_CHANGES
+LEAF(MEMSET_NAME,0)
+#else
+LEAF(MEMSET_NAME)
+#endif
-L(chkw):
- andi ta0, a2, 0xf # Enough left for one loop iteration?
- beq ta0, a2, L(chkl)
- PTR_SUBU a3, a2, ta0
- PTR_ADDU a3, a0 # a3 is last loop address +1
- move a2, ta0 # a2 is now # of bytes left after loop
-L(loopw):
- PTR_ADDIU a0, 16 # Handle 2 dwords pr. iteration
- sd a1, -16(a0)
- bne a0, a3, L(loopw)
- sd a1, -8(a0)
-
-L(chkl):
- andi ta0, a2, 0x8 # Check if there is at least a double
- beq ta0, zero, L(last16) # word remaining after the loop
- PTR_SUBU a2, ta0
- sd a1, 0(a0) # Yes...
- PTR_ADDIU a0, 8
-
-L(last16):
- blez a2, L(exit) # Handle last 16 bytes (if cnt>0)
- PTR_ADDU a3, a2, a0 # a3 is last address +1
-L(lst16l):
- PTR_ADDIU a0, 1
- bne a0, a3, L(lst16l)
- sb a1, -1(a0)
-L(exit):
- j ra # Bye, bye
+ .set nomips16
+ .set noreorder
+/* If the size is less than 2*NSIZE (8 or 16), go to L(lastb). Regardless of
+ size, copy dst pointer to v0 for the return value. */
+ slti t2,a2,(2 * NSIZE)
+ bne t2,zero,L(lastb)
+ move v0,a0
+
+/* If memset value is not zero, we copy it to all the bytes in a 32 or 64
+ bit word. */
+ beq a1,zero,L(set0) /* If memset value is zero no smear */
+ PTR_SUBU a3,zero,a0
nop
- .set reorder
-END (memset)
+ /* smear byte into 32 or 64 bit word */
+#if ((__mips == 64) || (__mips == 32)) && (__mips_isa_rev >= 2)
+# ifdef USE_DOUBLE
+ dins a1, a1, 8, 8 /* Replicate fill byte into half-word. */
+ dins a1, a1, 16, 16 /* Replicate fill byte into word. */
+ dins a1, a1, 32, 32 /* Replicate fill byte into dbl word. */
+# else
+ ins a1, a1, 8, 8 /* Replicate fill byte into half-word. */
+ ins a1, a1, 16, 16 /* Replicate fill byte into word. */
+# endif
+#else
+# ifdef USE_DOUBLE
+ and a1,0xff
+ dsll t2,a1,8
+ or a1,t2
+ dsll t2,a1,16
+ or a1,t2
+ dsll t2,a1,32
+ or a1,t2
+# else
+ and a1,0xff
+ sll t2,a1,8
+ or a1,t2
+ sll t2,a1,16
+ or a1,t2
+# endif
+#endif
+
+/* If the destination address is not aligned do a partial store to get it
+ aligned. If it is already aligned just jump to L(aligned). */
+L(set0):
+#ifndef R6_CODE
+ andi t2,a3,(NSIZE-1) /* word-unaligned address? */
+ beq t2,zero,L(aligned) /* t2 is the unalignment count */
+ PTR_SUBU a2,a2,t2
+ C_STHI a1,0(a0)
+ PTR_ADDU a0,a0,t2
+#else /* R6_CODE */
+ andi t2,a0,(NSIZE-1)
+ lapc t9,L(atable)
+ PTR_LSA t9,t2,t9,2
+ jrc t9
+L(atable):
+ bc L(aligned)
+# ifdef USE_DOUBLE
+ bc L(lb7)
+ bc L(lb6)
+ bc L(lb5)
+ bc L(lb4)
+# endif
+ bc L(lb3)
+ bc L(lb2)
+ bc L(lb1)
+L(lb7):
+ sb a1,6(a0)
+L(lb6):
+ sb a1,5(a0)
+L(lb5):
+ sb a1,4(a0)
+L(lb4):
+ sb a1,3(a0)
+L(lb3):
+ sb a1,2(a0)
+L(lb2):
+ sb a1,1(a0)
+L(lb1):
+ sb a1,0(a0)
+
+ li t9,NSIZE
+ subu t2,t9,t2
+ PTR_SUBU a2,a2,t2
+ PTR_ADDU a0,a0,t2
+#endif /* R6_CODE */
+
+L(aligned):
+/* If USE_DOUBLE is not set we may still want to align the data on a 16
+ byte boundry instead of an 8 byte boundry to maximize the opportunity
+ of proAptiv chips to do memory bonding (combining two sequential 4
+ byte stores into one 8 byte store). We know there are at least 4 bytes
+ left to store or we would have jumped to L(lastb) earlier in the code. */
+#ifdef DOUBLE_ALIGN
+ andi t2,a3,4
+ beq t2,zero,L(double_aligned)
+ PTR_SUBU a2,a2,t2
+ sw a1,0(a0)
+ PTR_ADDU a0,a0,t2
+L(double_aligned):
+#endif
-#else /* !__mips64 */
+/* Now the destination is aligned to (word or double word) aligned address
+ Set a2 to count how many bytes we have to copy after all the 64/128 byte
+ chunks are copied and a3 to the dest pointer after all the 64/128 byte
+ chunks have been copied. We will loop, incrementing a0 until it equals
+ a3. */
+ andi t8,a2,NSIZEDMASK /* any whole 64-byte/128-byte chunks? */
+ beq a2,t8,L(chkw) /* if a2==t8, no 64-byte/128-byte chunks */
+ PTR_SUBU a3,a2,t8 /* subtract from a2 the reminder */
+ PTR_ADDU a3,a0,a3 /* Now a3 is the final dst after loop */
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define SWHI swl /* high part is left in big-endian */
+/* When in the loop we may prefetch with the 'prepare to store' hint,
+ in this case the a0+x should not be past the "t0-32" address. This
+ means: for x=128 the last "safe" a0 address is "t0-160". Alternatively,
+ for x=64 the last "safe" a0 address is "t0-96" In the current version we
+ will use "prefetch hint,128(a0)", so "t0-160" is the limit. */
+#if defined(USE_PREFETCH) \
+ && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ PTR_ADDU t0,a0,a2 /* t0 is the "past the end" address */
+ PTR_SUBU t9,t0,PREFETCH_LIMIT /* t9 is the "last safe pref" address */
+#endif
+#if defined(USE_PREFETCH) \
+ && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE)
+ PREFETCH_FOR_STORE (1, a0)
+ PREFETCH_FOR_STORE (2, a0)
+ PREFETCH_FOR_STORE (3, a0)
+#endif
+
+L(loop16w):
+#if defined(USE_PREFETCH) \
+ && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ sltu v1,t9,a0 /* If a0 > t9 don't use next prefetch */
+ bgtz v1,L(skip_pref)
+ nop
+#endif
+#ifdef R6_CODE
+ PREFETCH_FOR_STORE (2, a0)
#else
-# define SWHI swr /* high part is right in little-endian */
+ PREFETCH_FOR_STORE (4, a0)
+ PREFETCH_FOR_STORE (5, a0)
#endif
+L(skip_pref):
+ C_ST a1,UNIT(0)(a0)
+ C_ST a1,UNIT(1)(a0)
+ C_ST a1,UNIT(2)(a0)
+ C_ST a1,UNIT(3)(a0)
+ C_ST a1,UNIT(4)(a0)
+ C_ST a1,UNIT(5)(a0)
+ C_ST a1,UNIT(6)(a0)
+ C_ST a1,UNIT(7)(a0)
+ C_ST a1,UNIT(8)(a0)
+ C_ST a1,UNIT(9)(a0)
+ C_ST a1,UNIT(10)(a0)
+ C_ST a1,UNIT(11)(a0)
+ C_ST a1,UNIT(12)(a0)
+ C_ST a1,UNIT(13)(a0)
+ C_ST a1,UNIT(14)(a0)
+ C_ST a1,UNIT(15)(a0)
+ PTR_ADDIU a0,a0,UNIT(16) /* adding 64/128 to dest */
+ bne a0,a3,L(loop16w)
+ nop
+ move a2,t8
-ENTRY (memset)
- .set noreorder
+/* Here we have dest word-aligned but less than 64-bytes or 128 bytes to go.
+ Check for a 32(64) byte chunk and copy if if there is one. Otherwise
+ jump down to L(chk1w) to handle the tail end of the copy. */
+L(chkw):
+ andi t8,a2,NSIZEMASK /* is there a 32-byte/64-byte chunk. */
+ /* the t8 is the reminder count past 32-bytes */
+ beq a2,t8,L(chk1w)/* when a2==t8, no 32-byte chunk */
+ nop
+ C_ST a1,UNIT(0)(a0)
+ C_ST a1,UNIT(1)(a0)
+ C_ST a1,UNIT(2)(a0)
+ C_ST a1,UNIT(3)(a0)
+ C_ST a1,UNIT(4)(a0)
+ C_ST a1,UNIT(5)(a0)
+ C_ST a1,UNIT(6)(a0)
+ C_ST a1,UNIT(7)(a0)
+ PTR_ADDIU a0,a0,UNIT(8)
+
+/* Here we have less than 32(64) bytes to set. Set up for a loop to
+ copy one word (or double word) at a time. Set a2 to count how many
+ bytes we have to copy after all the word (or double word) chunks are
+ copied and a3 to the dest pointer after all the (d)word chunks have
+ been copied. We will loop, incrementing a0 until a0 equals a3. */
+L(chk1w):
+ andi a2,t8,(NSIZE-1) /* a2 is the reminder past one (d)word chunks */
+ beq a2,t8,L(lastb)
+ PTR_SUBU a3,t8,a2 /* a3 is count of bytes in one (d)word chunks */
+ PTR_ADDU a3,a0,a3 /* a3 is the dst address after loop */
- slti t1, a2, 8 # Less than 8?
- bne t1, zero, L(last8)
- move v0, a0 # Setup exit value before too late
-
- beq a1, zero, L(ueven) # If zero pattern, no need to extend
- andi a1, 0xff # Avoid problems with bogus arguments
- sll t0, a1, 8
- or a1, t0
- sll t0, a1, 16
- or a1, t0 # a1 is now pattern in full word
-
-L(ueven):
- subu t0, zero, a0 # Unaligned address?
- andi t0, 0x3
- beq t0, zero, L(chkw)
- subu a2, t0
- SWHI a1, 0(a0) # Yes, handle first unaligned part
- addu a0, t0 # Now both a0 and a2 are updated
-
-L(chkw):
- andi t0, a2, 0x7 # Enough left for one loop iteration?
- beq t0, a2, L(chkl)
- subu a3, a2, t0
- addu a3, a0 # a3 is last loop address +1
- move a2, t0 # a2 is now # of bytes left after loop
-L(loopw):
- addiu a0, 8 # Handle 2 words pr. iteration
- sw a1, -8(a0)
- bne a0, a3, L(loopw)
- sw a1, -4(a0)
-
-L(chkl):
- andi t0, a2, 0x4 # Check if there is at least a full
- beq t0, zero, L(last8) # word remaining after the loop
- subu a2, t0
- sw a1, 0(a0) # Yes...
- addiu a0, 4
-
-L(last8):
- blez a2, L(exit) # Handle last 8 bytes (if cnt>0)
- addu a3, a2, a0 # a3 is last address +1
-L(lst8l):
- addiu a0, 1
- bne a0, a3, L(lst8l)
- sb a1, -1(a0)
-L(exit):
- j ra # Bye, bye
+/* copying in words (4-byte or 8 byte chunks) */
+L(wordCopy_loop):
+ PTR_ADDIU a0,a0,UNIT(1)
+ bne a0,a3,L(wordCopy_loop)
+ C_ST a1,UNIT(-1)(a0)
+
+/* Copy the last 8 (or 16) bytes */
+L(lastb):
+ blez a2,L(leave)
+ PTR_ADDU a3,a0,a2 /* a3 is the last dst address */
+L(lastbloop):
+ PTR_ADDIU a0,a0,1
+ bne a0,a3,L(lastbloop)
+ sb a1,-1(a0)
+L(leave):
+ j ra
nop
+ .set at
.set reorder
-END (memset)
-
-#endif /* !__mips64 */
+END(MEMSET_NAME)
+#ifndef ANDROID_CHANGES
+# ifdef _LIBC
+# ifdef __UCLIBC__
+libc_hidden_def(MEMSET_NAME)
+# else
+libc_hidden_builtin_def (MEMSET_NAME)
+# endif
+# endif
+#endif
-libc_hidden_def(memset)
diff --git a/libc/sysdeps/linux/common/bits/in.h b/libc/sysdeps/linux/common/bits/in.h
index f4a340b..c67fbf8 100644
--- a/libc/sysdeps/linux/common/bits/in.h
+++ b/libc/sysdeps/linux/common/bits/in.h
@@ -120,7 +120,7 @@ struct in_pktinfo
};
#endif
-#ifdef __UCLIBC_HAS_IPV6__
+#if defined __UCLIBC_HAS_IPV6__ || !defined __UCLIBC_STRICT_HEADERS__
/* Options for use with `getsockopt' and `setsockopt' at the IPv6 level.
The first word in the comment at the right is the data type used;
"bool" means a boolean value stored in an `int'. */
diff --git a/libc/sysdeps/linux/common/pselect.c b/libc/sysdeps/linux/common/pselect.c
index bf19ce3..3f1dd28 100644
--- a/libc/sysdeps/linux/common/pselect.c
+++ b/libc/sysdeps/linux/common/pselect.c
@@ -30,6 +30,57 @@ static int __NC(pselect)(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const struct timespec *timeout,
const sigset_t *sigmask)
{
+#ifdef __NR_pselect6
+#define NSEC_PER_SEC 1000000000L
+ struct timespec _ts, *ts = 0;
+ if (timeout) {
+ /* The Linux kernel can in some situations update the timeout value.
+ * We do not want that so use a local variable.
+ */
+ _ts = *timeout;
+
+ /* GNU extension: allow for timespec values where the sub-sec
+ * field is equal to or more than 1 second. The kernel will
+ * reject this on us, so take care of the time shift ourself.
+ * Some applications (like readline and linphone) do this.
+ * See 'clarification on select() type calls and invalid timeouts'
+ * on the POSIX general list for more information.
+ */
+ if (_ts.tv_nsec >= NSEC_PER_SEC) {
+ _ts.tv_sec += _ts.tv_nsec / NSEC_PER_SEC;
+ _ts.tv_nsec %= NSEC_PER_SEC;
+ }
+
+ ts = &_ts;
+ }
+
+ /* The pselect6 syscall API is strange. It wants a 7th arg to be
+ * the sizeof(*sigmask). However syscalls with > 6 arguments aren't
+ * supported on linux. So arguments 6 and 7 are stuffed in a struct
+ * and a pointer to that struct is passed as the 6th argument to
+ * the syscall.
+ * Glibc stuffs arguments 6 and 7 in a ulong[2]. Linux reads
+ * them as if there were a struct { sigset_t*; size_t } in
+ * userspace. There woudl be trouble if userspace and the kernel are
+ * compiled differently enough that size_t isn't the same as ulong,
+ * but not enough to trigger the compat layer in linux. I can't
+ * think of such a case, so I'm using linux's struct.
+ * Furthermore Glibc sets the sigsetsize to _NSIG/8. However linux
+ * checks for sizeof(sigset_t), which internally is a ulong array.
+ * This means that if _NSIG isn't a multiple of BITS_PER_LONG then
+ * linux will refuse glibc's value. So I prefer sizeof(sigset_t) for
+ * the value of sigsetsize.
+ */
+ struct {
+ const sigset_t *sigmask;
+ size_t sigsetsize;
+ } args67 = {
+ sigmask,
+ sizeof(sigset_t),
+ };
+
+ return INLINE_SYSCALL(pselect6, 6, nfds, readfds, writefds, exceptfds, ts, &args67);
+#else
struct timeval tval;
int retval;
sigset_t savemask;
@@ -57,6 +108,7 @@ static int __NC(pselect)(int nfds, fd_set *readfds, fd_set *writefds,
sigprocmask (SIG_SETMASK, &savemask, NULL);
return retval;
+#endif
}
CANCELLABLE_SYSCALL(int, pselect, (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timespec *timeout, const sigset_t *sigmask),
diff --git a/libpthread/nptl/init.c b/libpthread/nptl/init.c
index bcd49ed..776bec7 100644
--- a/libpthread/nptl/init.c
+++ b/libpthread/nptl/init.c
@@ -382,6 +382,10 @@ __pthread_initialize_minimal_internal (void)
Use the minimal size acceptable. */
limit.rlim_cur = PTHREAD_STACK_MIN;
+ /* Do not exceed architecture specific default */
+ if (limit.rlim_cur > ARCH_STACK_DEFAULT_SIZE)
+ limit.rlim_cur = ARCH_STACK_DEFAULT_SIZE;
+
/* Make sure it meets the minimum size that allocate_stack
(allocatestack.c) will demand, which depends on the page size. */
const uintptr_t pagesz = sysconf (_SC_PAGESIZE);
hooks/post-receive
--
uClibc-ng - small C library for embedded systems
1
0
uClibc-ng - small C library for embedded systems annotated tag v1.0.10 created. v1.0.10
by wbx@helium.waldemar-brodkorb.de 23 Dec '15
by wbx@helium.waldemar-brodkorb.de 23 Dec '15
23 Dec '15
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "uClibc-ng - small C library for embedded systems".
The annotated tag, v1.0.10 has been created
at b59543b5b75c405c7f30410bcc098dec5a666fd9 (tag)
tagging 0ad73077c230093ae004829da44418597f330c6a (commit)
replaces v1.0.9
tagged by Waldemar Brodkorb
on Thu Dec 24 00:49:56 2015 +0100
- Log -----------------------------------------------------------------
release 1.0.10 - Tongerlo Brune
Khem Raj (2):
Do not support localised optimizations this helps to have a global -O level
Add implementation for copysignl for ppc
Markus Mayer (1):
config: allow config to handle longer path names
Nicolas S. Dade (1):
pselect: Use linux pselect syscall when available
Steve Ellcey (3):
mips: fix definition.
Replace MIPS specific memcpy.S/memset.S with version from glibc/newlib.
Replace bltzal with lapc for MIPS R6 builds.
Vladislav Grishenko (2):
Fix syslog messages lost after syslogd restarts
Fix syslog messages lost if syslogd is temporary busy
Waldemar Brodkorb (47):
mips: remove ISA choice
xtensa: remove ldso workaround by real pointer check
xtensa: avoid some compiler warnings
bfin: use vfork.S again
bfin: fix clashing with newer gcc
remove __UCLIBC_HAVE_ASM_GLOBAL_DOT_NAME__
remove __UCLIBC_ASM_GLOBAL_DIRECTIVE__
remove sh64 support
good bye vax
good by e1
good by nios
add definitions for O_PATH
sync with glibc, add some missing defines
Avoid unnecessary rebuilds due to compiler flag changes
Define __attribute_const__
Make malloc_stats() GNU libc compatible
Reduce the initial buffer size for open_memstream
bsd supports the same floating point classification functions as c99
new test is only for MALLOC_STANDARD
allow linuxthreads for superh (sh2 noMMU)
sh: add back sh2 specific assembly for clone()
do not hardcode path to perl
arc: add ulps file for math tests
disable always failing tst-tls16, until someone unbreak it
fix tst-signal7 failure
Revert "fix tst-signal7 failure"
fix readdir_r returns success code while it in fact failed
libc/stdio: Rework custom streams interface similar to glibc.
test needs -fPIC for m68k
only strip test binaries when DOSTRIP is enabled
svc.c: svc_getreqset() buffer overflow
dynamically allocate ahostbuf buffer
resolv: __dns_lookup - immediately switch to next server in case of poll() set error events
resolv: NI_IDN unimplemented
dlclose fix
test/tls: tls-macros*.h fixes from glibc
utlis/ldd: Fix host ldd in case of target wordsize differs from host one
testsuite subdir fix
reduce stack cache size to save memory space
Revert "glibc compat: bump glibc minor version"
inet/resolv: Fix broken h_aliases list terminator after 2dab3f5
resolv: fix gethostbyname2_r to match gethostbyname_r, fixing bugs with AAAA lookups
Do define some IPv6 related symbols even with IPv6 disabled
use arch specific thread stack size for nptl
Use gcc's __builtin_mempcpy() as __mempcpy(), if possible
libc/pwd_grp: Create template for non-reentrant functions
prepare for release of 1.0.10
Wojciech Nizinski (1):
libc/stdlib: canonicalize_file_name() memory leak
-----------------------------------------------------------------------
hooks/post-receive
--
uClibc-ng - small C library for embedded systems
1
0
uClibc-ng - small C library for embedded systems branch 1.0 updated. v1.0.9-57-g0ad7307
by wbx@helium.waldemar-brodkorb.de 23 Dec '15
by wbx@helium.waldemar-brodkorb.de 23 Dec '15
23 Dec '15
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "uClibc-ng - small C library for embedded systems".
The branch, 1.0 has been updated
via 0ad73077c230093ae004829da44418597f330c6a (commit)
via cc82a850a0ebfbacb7fb62ea2c5b7dd6aebb005d (commit)
via 2636b17616a19d628c3dbc373ebae67ef6e2b1f6 (commit)
via e3c3bf2b5801d0cc544e732fcee1ba51121051b3 (commit)
via f5bdd8ff82607e55a1c511e13e37a984408c8094 (commit)
via 2a3ffa836a3a9f94f19ee2671f41c1851221a105 (commit)
via 74b17c7956b8f0bd109b0fd26a8a9869441d09bf (commit)
via 73491f469c244ec077e8448d41c4e193b6a3599b (commit)
via 6b4bcce3cbb89442f96e2e47a507b5983f27a191 (commit)
via 6994bbf289dc098d38b27521da3a7431e17736db (commit)
from 836c1a7baa9421c1222e022cdc263d8c1a5a2b14 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0ad73077c230093ae004829da44418597f330c6a
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Thu Dec 24 00:46:18 2015 +0100
prepare for release of 1.0.10
commit cc82a850a0ebfbacb7fb62ea2c5b7dd6aebb005d
Author: Steve Ellcey <sellcey(a)imgtec.com>
Date: Wed Dec 23 08:38:41 2015 -0800
Replace bltzal with lapc for MIPS R6 builds.
The R6 version of MIPS does not support the bltzal instruction. This
patch changes dl-startup.h and dl-sysdep.h to use lapc on R6 instead.
lapc is a new R6 insruction so older systems need to continue to use
bltzal in order to load register $31.
Signed-off-by: Steve Ellcey <sellcey(a)imgtec.com>
commit 2636b17616a19d628c3dbc373ebae67ef6e2b1f6
Author: Steve Ellcey <sellcey(a)imgtec.com>
Date: Mon Dec 21 13:22:07 2015 -0800
Replace MIPS specific memcpy.S/memset.S with version from glibc/newlib.
These MIPS specific versions of memcpy.S and memset.S are faster than
the current ones and match what is in newlib and glibc. They also have
support for the mips32r6 and mips64r6 architectures.
Signed-off-by: Steve Ellcey <sellcey(a)imgtec.com>
commit e3c3bf2b5801d0cc544e732fcee1ba51121051b3
Author: Nicolas S. Dade <nic.dade(a)gmail.com>
Date: Fri Dec 18 19:39:19 2015 -0800
pselect: Use linux pselect syscall when available
Linux has a pselect syscall since 2.6.something. Using it
rather than emulating it with sigprocmask+select+sigprocmask
is smaller code, and works properly. (The emulation has
race conditions when unblocked signals arrive before or
after the select)
The tv.nsec >= 1E9 handling comes from uclibc's linux select()
implementation, which itself uses pselect() internally if the
pselect syscall exists. I though it would be good to do the
same here.
Note that although the libc pselect() API has 6 arguments,
the linux kernel syscall as 7 arguments. There is an extra,
somewhat vestigial, sizeof the signal mask argument.
Signed-off-by: Nicolas S. Dade <nic.dade(a)gmail.com>
commit f5bdd8ff82607e55a1c511e13e37a984408c8094
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:58:08 2015 +0100
libc/pwd_grp: Create template for non-reentrant functions
Avoid a lot of copy'n'paste code, no functionality change
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
commit 2a3ffa836a3a9f94f19ee2671f41c1851221a105
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:56:08 2015 +0100
Use gcc's __builtin_mempcpy() as __mempcpy(), if possible
Patch from OpenWrt.
Reported-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
commit 74b17c7956b8f0bd109b0fd26a8a9869441d09bf
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:51:13 2015 +0100
use arch specific thread stack size for nptl
Use the arch specific thread stack size for nptl if the size
returned by getrlimits exceeds it - fixes threads on systems
with only 16 MB RAM.
Patch from OpenWRT
Reported-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
commit 73491f469c244ec077e8448d41c4e193b6a3599b
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:52:55 2015 +0100
Do define some IPv6 related symbols even with IPv6 disabled
Fixes compilation of some faulty applictions.
Patch from Freetz.org
Reported-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
commit 6b4bcce3cbb89442f96e2e47a507b5983f27a191
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:47:56 2015 +0100
resolv: fix gethostbyname2_r to match gethostbyname_r, fixing bugs with AAAA lookups
The latter half of gethostbyname2_r (doing AAAA queries) is rather dramatically different
from the corresponding portion of gethostbyname_r (doing A queries). This leads to problems
like calls to getaddrinfo only returning one IPv6 address, even when multiple exist.
Seems to be entirely a case of divergent evolution -- a half-decade of fixes for the IPv4
code but no love for IPv6. Until now. ;)
DNS behaviour for IPv6 is really no different than for IPv4 -- beyond the difference in
address sizes, there's no need for the functions to be so different.
Consequently, this patch really is almost just a cut-and-paste of gethostbyname_r, with
the appropriate substitutions of in6_addr, AF_INET6, etc; while holding on to the few
extra bits that actually belong in there (eg #ifdef __UCLIBC_HAS_IPV6__).
Signed-off-by: Wes Campaigne <westacular(a)gmail.com>
commit 6994bbf289dc098d38b27521da3a7431e17736db
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Tue Dec 22 10:45:51 2015 +0100
inet/resolv: Fix broken h_aliases list terminator after 2dab3f5
Commit 2dab3f5a "resolv: tiny shrinkage in /etc/hosts handling" leads to
that read_etc_hosts_r() provide garbage pointer at the end of h_aliases
list if more than four hostnames follow a dotted quad in /etc/hosts
Test-case:
Add following line to /etc/hosts
63.63.0.2 host1 alias2 alias3 alias4 alias5
#include <stdio.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
int main (void)
{
int i;
char *a;
struct hostent *he;
struct in_addr ipv4addr;
inet_pton(AF_INET, "63.63.0.2", &ipv4addr);
he = gethostbyaddr(&ipv4addr, sizeof ipv4addr, AF_INET);
if (he == NULL)
exit(1);
printf("Host name: '%s'\n", he->h_name);
i = 0;
while ((a = he->h_aliases[i]) != NULL) {
printf("Host alias: '%s'\n", a);
++i;
}
return 0;
}
Wrong output:
Host name: 'host1'
Host alias: 'alias2'
Host alias: 'alias3'
Host alias: 'alias4'
Host alias: 'alias5'
Host alias: '??'
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
-----------------------------------------------------------------------
Summary of changes:
Rules.mak | 2 +-
include/string.h | 4 +-
ldso/ldso/mips/dl-startup.h | 5 +
ldso/ldso/mips/dl-sysdep.h | 5 +
libc/inet/resolv.c | 165 ++++--
libc/pwd_grp/fgetgrent.c | 12 +-
libc/pwd_grp/fgetpwent.c | 12 +-
libc/pwd_grp/fgetspent.c | 6 +-
libc/pwd_grp/getgrent.c | 5 +-
libc/pwd_grp/getgrgid.c | 6 +-
libc/pwd_grp/getgrgid_r.c | 7 +-
libc/pwd_grp/getgrnam.c | 6 +-
libc/pwd_grp/getgrnam_r.c | 7 +-
libc/pwd_grp/getpwent.c | 5 +-
libc/pwd_grp/getpwnam.c | 7 +-
libc/pwd_grp/getpwnam_r.c | 7 +-
libc/pwd_grp/getpwuid.c | 6 +-
libc/pwd_grp/getpwuid_r.c | 7 +-
libc/pwd_grp/getspent.c | 5 +-
libc/pwd_grp/getspnam.c | 6 +-
libc/pwd_grp/getspnam_r.c | 7 +-
libc/pwd_grp/pwd_grp.c | 263 +--------
libc/pwd_grp/pwd_grp_internal.c | 49 +-
libc/pwd_grp/sgetspent.c | 6 +-
libc/string/generic/mempcpy.c | 1 +
libc/string/mips/memcpy.S | 1051 +++++++++++++++++++++++++++--------
libc/string/mips/memset.S | 516 +++++++++++++----
libc/sysdeps/linux/common/bits/in.h | 2 +-
libc/sysdeps/linux/common/pselect.c | 52 ++
libpthread/nptl/init.c | 4 +
30 files changed, 1549 insertions(+), 687 deletions(-)
diff --git a/Rules.mak b/Rules.mak
index 7652aab..7f244b4 100644
--- a/Rules.mak
+++ b/Rules.mak
@@ -126,7 +126,7 @@ export RUNTIME_PREFIX DEVEL_PREFIX KERNEL_HEADERS MULTILIB_DIR
# Now config hard core
MAJOR_VERSION := 1
MINOR_VERSION := 0
-SUBLEVEL := 9
+SUBLEVEL := 10
EXTRAVERSION :=
VERSION := $(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL)
ABI_VERSION := $(MAJOR_VERSION)
diff --git a/include/string.h b/include/string.h
index 1d75f44..80585ef 100644
--- a/include/string.h
+++ b/include/string.h
@@ -258,7 +258,9 @@ extern void *memmem (const void *__haystack, size_t __haystacklen,
/* Copy N bytes of SRC to DEST, return pointer to bytes after the
last written byte. */
-#if 0 /* uClibc: disabled */
+#if __GNUC_PREREQ (3, 4)
+# define __mempcpy(dest, src, n) __builtin_mempcpy(dest, src, n)
+#else /* uClibc: disabled */
extern void *__mempcpy (void *__restrict __dest,
const void *__restrict __src, size_t __n)
__THROW __nonnull ((1, 2));
diff --git a/ldso/ldso/mips/dl-startup.h b/ldso/ldso/mips/dl-startup.h
index 4d9918d..0cab7be 100644
--- a/ldso/ldso/mips/dl-startup.h
+++ b/ldso/ldso/mips/dl-startup.h
@@ -37,6 +37,7 @@ __asm__(""
#if _MIPS_SIM == _MIPS_SIM_ABI32
" subu $29, 16\n"
#endif
+# if !defined __mips_isa_rev || __mips_isa_rev < 6
#if _MIPS_SIM == _MIPS_SIM_ABI64
" dla $8, .coff\n"
#else /* O32 || N32 */
@@ -44,6 +45,10 @@ __asm__(""
#endif /* O32 || N32 */
" bltzal $8, .coff\n"
".coff:\n"
+# else
+ ".coff:\n"
+ " lapc $31, .coff\n"
+# endif
#if _MIPS_SIM == _MIPS_SIM_ABI64
" dsubu $8, $31, $8\n"
" dla $25, _dl_start\n"
diff --git a/ldso/ldso/mips/dl-sysdep.h b/ldso/ldso/mips/dl-sysdep.h
index 6041245..b2caa7f 100644
--- a/ldso/ldso/mips/dl-sysdep.h
+++ b/ldso/ldso/mips/dl-sysdep.h
@@ -225,10 +225,15 @@ elf_machine_load_address (void)
{
ElfW(Addr) addr;
__asm__ (" .set noreorder\n"
+# if !defined __mips_isa_rev || __mips_isa_rev < 6
" " STRINGXP (PTR_LA) " %0, 0f\n"
" bltzal $0, 0f\n"
" nop\n"
"0: " STRINGXP (PTR_SUBU) " %0, $31, %0\n"
+#else
+ "0: lapc $31, 0\n"
+ " " STRINGXP (PTR_SUBU) " %0, $31, %0\n"
+#endif
" .set reorder\n"
: "=r" (addr)
: /* No inputs */
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index 8e5a97d..3851b2a 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -1596,7 +1596,7 @@ parser_t * __open_etc_hosts(void)
#define MINTOKENS 2 /* ip address + canonical name */
#define MAXTOKENS (MINTOKENS + MAXALIASES)
-#define HALISTOFF (sizeof(char*) * MAXTOKENS)
+#define HALISTOFF (sizeof(char*) * (MAXTOKENS + 1)) /* reserve space for list terminator */
#define INADDROFF (HALISTOFF + 2 * sizeof(char*))
int __read_etc_hosts_r(
@@ -2200,12 +2200,13 @@ int gethostbyname2_r(const char *name,
? gethostbyname_r(name, result_buf, buf, buflen, result, h_errnop)
: HOST_NOT_FOUND;
#else
- struct in6_addr *in;
struct in6_addr **addr_list;
+ char **alias;
+ char *alias0;
unsigned char *packet;
struct resolv_answer a;
int i;
- int nest = 0;
+ int packet_len;
int wrong_af = 0;
if (family == AF_INET)
@@ -2220,9 +2221,8 @@ int gethostbyname2_r(const char *name,
/* do /etc/hosts first */
{
- int old_errno = errno; /* Save the old errno and reset errno */
- __set_errno(0); /* to check for missing /etc/hosts. */
-
+ int old_errno = errno; /* save the old errno and reset errno */
+ __set_errno(0); /* to check for missing /etc/hosts. */
i = __get_hosts_byname_r(name, AF_INET6 /*family*/, result_buf,
buf, buflen, result, h_errnop);
if (i == NETDB_SUCCESS) {
@@ -2244,42 +2244,58 @@ int gethostbyname2_r(const char *name,
}
__set_errno(old_errno);
}
+
DPRINTF("Nothing found in /etc/hosts\n");
*h_errnop = NETDB_INTERNAL;
+ /* prepare future h_aliases[0] */
+ i = strlen(name) + 1;
+ if ((ssize_t)buflen <= i)
+ return ERANGE;
+ memcpy(buf, name, i); /* paranoia: name might change */
+ alias0 = buf;
+ buf += i;
+ buflen -= i;
/* make sure pointer is aligned */
i = ALIGN_BUFFER_OFFSET(buf);
buf += i;
buflen -= i;
/* Layout in buf:
- * struct in6_addr* in;
- * struct in6_addr* addr_list[2];
- * char scratch_buf[256];
+ * char *alias[2];
+ * struct in6_addr* addr_list[NN+1];
+ * struct in6_addr* in[NN];
*/
- in = (struct in6_addr*)buf;
- buf += sizeof(*in);
- buflen -= sizeof(*in);
- addr_list = (struct in6_addr**)buf;
- buf += sizeof(*addr_list) * 2;
- buflen -= sizeof(*addr_list) * 2;
+ alias = (char **)buf;
+ buf += sizeof(alias[0]) * 2;
+ buflen -= sizeof(alias[0]) * 2;
+ addr_list = (struct in6_addr **)buf;
+ /* buflen may be < 0, must do signed compare */
if ((ssize_t)buflen < 256)
return ERANGE;
- addr_list[0] = in;
- addr_list[1] = NULL;
- strncpy(buf, name, buflen);
- buf[buflen] = '\0';
+
+ /* we store only one "alias" - the name itself */
+#ifdef __UCLIBC_MJN3_ONLY__
+#warning TODO -- generate the full list
+#endif
+ alias[0] = alias0;
+ alias[1] = NULL;
/* maybe it is already an address? */
- if (inet_pton(AF_INET6, name, in)) {
- result_buf->h_name = buf;
- result_buf->h_addrtype = AF_INET6;
- result_buf->h_length = sizeof(*in);
- result_buf->h_addr_list = (char **) addr_list;
- /* result_buf->h_aliases = ??? */
- *result = result_buf;
- *h_errnop = NETDB_SUCCESS;
- return NETDB_SUCCESS;
+ {
+ struct in6_addr *in = (struct in6_addr *)(buf + sizeof(addr_list[0]) * 2);
+ if (inet_pton(AF_INET6, name, in)) {
+ addr_list[0] = in;
+ addr_list[1] = NULL;
+ result_buf->h_name = alias0;
+ result_buf->h_aliases = alias;
+ result_buf->h_addrtype = AF_INET6;
+ result_buf->h_length = sizeof(struct in6_addr);
+ result_buf->h_addr_list = (char **) addr_list;
+ *result = result_buf;
+ *h_errnop = NETDB_SUCCESS;
+ return NETDB_SUCCESS;
+ }
}
/* what if /etc/hosts has it but it's not IPv6?
@@ -2291,51 +2307,80 @@ int gethostbyname2_r(const char *name,
}
/* talk to DNS servers */
-/* TODO: why it's so different from gethostbyname_r (IPv4 case)? */
- memset(&a, '\0', sizeof(a));
- for (;;) {
- int packet_len;
+ a.buf = buf;
+ /* take into account that at least one address will be there,
+ * we'll need space of one in6_addr + two addr_list[] elems */
+ a.buflen = buflen - ((sizeof(addr_list[0]) * 2 + sizeof(struct in6_addr)));
+ a.add_count = 0;
+ packet_len = __dns_lookup(name, T_AAAA, &packet, &a);
+ if (packet_len < 0) {
+ *h_errnop = HOST_NOT_FOUND;
+ DPRINTF("__dns_lookup returned < 0\n");
+ return TRY_AGAIN;
+ }
-/* Hmm why we memset(a) to zeros only once? */
- packet_len = __dns_lookup(buf, T_AAAA, &packet, &a);
- if (packet_len < 0) {
- *h_errnop = HOST_NOT_FOUND;
- return TRY_AGAIN;
+ if (a.atype == T_AAAA) { /* ADDRESS */
+ /* we need space for addr_list[] and one IPv6 address */
+ /* + 1 accounting for 1st addr (it's in a.rdata),
+ * another + 1 for NULL in last addr_list[]: */
+ int need_bytes = sizeof(addr_list[0]) * (a.add_count + 1 + 1)
+ /* for 1st addr (it's in a.rdata): */
+ + sizeof(struct in6_addr);
+ /* how many bytes will 2nd and following addresses take? */
+ int ips_len = a.add_count * a.rdlength;
+
+ buflen -= (need_bytes + ips_len);
+ if ((ssize_t)buflen < 0) {
+ DPRINTF("buffer too small for all addresses\n");
+ /* *h_errnop = NETDB_INTERNAL; - already is */
+ i = ERANGE;
+ goto free_and_ret;
}
- strncpy(buf, a.dotted, buflen);
- free(a.dotted);
- if (a.atype != T_CNAME)
- break;
+ /* if there are additional addresses in buf,
+ * move them forward so that they are not destroyed */
+ DPRINTF("a.add_count:%d a.rdlength:%d a.rdata:%p\n", a.add_count, a.rdlength, a.rdata);
+ memmove(buf + need_bytes, buf, ips_len);
- DPRINTF("Got a CNAME in gethostbyname()\n");
- if (++nest > MAX_RECURSE) {
- *h_errnop = NO_RECOVERY;
- return -1;
+ /* 1st address is in a.rdata, insert it */
+ buf += need_bytes - sizeof(struct in6_addr);
+ memcpy(buf, a.rdata, sizeof(struct in6_addr));
+
+ /* fill addr_list[] */
+ for (i = 0; i <= a.add_count; i++) {
+ addr_list[i] = (struct in6_addr*)buf;
+ buf += sizeof(struct in6_addr);
}
- i = __decode_dotted(packet, a.rdoffset, packet_len, buf, buflen);
- free(packet);
- if (i < 0) {
- *h_errnop = NO_RECOVERY;
- return -1;
+ addr_list[i] = NULL;
+
+ /* if we have enough space, we can report "better" name
+ * (it may contain search domains attached by __dns_lookup,
+ * or CNAME of the host if it is different from the name
+ * we used to find it) */
+ if (a.dotted && buflen > strlen(a.dotted)) {
+ strcpy(buf, a.dotted);
+ alias0 = buf;
}
- }
- if (a.atype == T_AAAA) { /* ADDRESS */
- memcpy(in, a.rdata, sizeof(*in));
- result_buf->h_name = buf;
+
+ result_buf->h_name = alias0;
+ result_buf->h_aliases = alias;
result_buf->h_addrtype = AF_INET6;
- result_buf->h_length = sizeof(*in);
+ result_buf->h_length = sizeof(struct in6_addr);
result_buf->h_addr_list = (char **) addr_list;
- /* result_buf->h_aliases = ??? */
- free(packet);
*result = result_buf;
*h_errnop = NETDB_SUCCESS;
- return NETDB_SUCCESS;
+ i = NETDB_SUCCESS;
+ goto free_and_ret;
}
- free(packet);
+
*h_errnop = HOST_NOT_FOUND;
- return TRY_AGAIN;
+ __set_h_errno(HOST_NOT_FOUND);
+ i = TRY_AGAIN;
+ free_and_ret:
+ free(a.dotted);
+ free(packet);
+ return i;
#endif /* __UCLIBC_HAS_IPV6__ */
}
libc_hidden_def(gethostbyname2_r)
diff --git a/libc/pwd_grp/fgetgrent.c b/libc/pwd_grp/fgetgrent.c
index 695aee1..6a45799 100644
--- a/libc/pwd_grp/fgetgrent.c
+++ b/libc/pwd_grp/fgetgrent.c
@@ -4,5 +4,15 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_fgetgrent
+#include <features.h>
+
+#ifdef __USE_SVID
+
+#define GETXXKEY_FUNC fgetgrent
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS FILE *stream
+#define GETXXKEY_ADD_VARIABLES stream
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
+
+#endif
diff --git a/libc/pwd_grp/fgetpwent.c b/libc/pwd_grp/fgetpwent.c
index ddcc7ff..6f65cf6 100644
--- a/libc/pwd_grp/fgetpwent.c
+++ b/libc/pwd_grp/fgetpwent.c
@@ -4,5 +4,15 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_fgetpwent
+#include <features.h>
+
+#ifdef __USE_SVID
+
+#define GETXXKEY_FUNC fgetpwent
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS FILE *stream
+#define GETXXKEY_ADD_VARIABLES stream
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
+
+#endif
diff --git a/libc/pwd_grp/fgetspent.c b/libc/pwd_grp/fgetspent.c
index b7c1ef2..77ca0b8 100644
--- a/libc/pwd_grp/fgetspent.c
+++ b/libc/pwd_grp/fgetspent.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_fgetspent
+#define GETXXKEY_FUNC fgetspent
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS FILE *stream
+#define GETXXKEY_ADD_VARIABLES stream
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrent.c b/libc/pwd_grp/getgrent.c
index 808e4e8..5b03b31 100644
--- a/libc/pwd_grp/getgrent.c
+++ b/libc/pwd_grp/getgrent.c
@@ -4,5 +4,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrent
+#define GETXXKEY_FUNC getgrent
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS void
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrgid.c b/libc/pwd_grp/getgrgid.c
index 96ce903..2988452 100644
--- a/libc/pwd_grp/getgrgid.c
+++ b/libc/pwd_grp/getgrgid.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrgid
+#define GETXXKEY_FUNC getgrgid
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS gid_t git
+#define GETXXKEY_ADD_VARIABLES git
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrgid_r.c b/libc/pwd_grp/getgrgid_r.c
index a962f4c..b0f0c9a 100644
--- a/libc/pwd_grp/getgrgid_r.c
+++ b/libc/pwd_grp/getgrgid_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrgid_r
+#define GETXXKEY_R_FUNC getgrgid_r
+#define GETXXKEY_R_PARSER __parsegrent
+#define GETXXKEY_R_ENTTYPE struct group
+#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
+#define DO_GETXXKEY_R_KEYTYPE gid_t
+#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrnam.c b/libc/pwd_grp/getgrnam.c
index 3b47d9a..f6ce459 100644
--- a/libc/pwd_grp/getgrnam.c
+++ b/libc/pwd_grp/getgrnam.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrnam
+#define GETXXKEY_FUNC getgrnam
+#define GETXXKEY_ENTTYPE struct group
+#define GETXXKEY_ADD_PARAMS const char *name
+#define GETXXKEY_ADD_VARIABLES name
+#define GETXXKEY_BUFLEN __UCLIBC_GRP_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getgrnam_r.c b/libc/pwd_grp/getgrnam_r.c
index 592a66c..35121e7 100644
--- a/libc/pwd_grp/getgrnam_r.c
+++ b/libc/pwd_grp/getgrnam_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getgrnam_r
+#define GETXXKEY_R_FUNC getgrnam_r
+#define GETXXKEY_R_PARSER __parsegrent
+#define GETXXKEY_R_ENTTYPE struct group
+#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key))
+#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
+#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwent.c b/libc/pwd_grp/getpwent.c
index a617bc8..7ddc8ee 100644
--- a/libc/pwd_grp/getpwent.c
+++ b/libc/pwd_grp/getpwent.c
@@ -4,5 +4,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwent
+#define GETXXKEY_FUNC getpwent
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS void
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwnam.c b/libc/pwd_grp/getpwnam.c
index d00640b..e3e8c02 100644
--- a/libc/pwd_grp/getpwnam.c
+++ b/libc/pwd_grp/getpwnam.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwnam
+#define GETXXKEY_FUNC getpwnam
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS const char *name
+#define GETXXKEY_ADD_VARIABLES name
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
+#define GETXXKEY_FUNC_HIDDEN
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwnam_r.c b/libc/pwd_grp/getpwnam_r.c
index a4440e7..bc5e3d5 100644
--- a/libc/pwd_grp/getpwnam_r.c
+++ b/libc/pwd_grp/getpwnam_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwnam_r
+#define GETXXKEY_R_FUNC getpwnam_r
+#define GETXXKEY_R_PARSER __parsepwent
+#define GETXXKEY_R_ENTTYPE struct passwd
+#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key))
+#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
+#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwuid.c b/libc/pwd_grp/getpwuid.c
index 16ac50f..1ad2688 100644
--- a/libc/pwd_grp/getpwuid.c
+++ b/libc/pwd_grp/getpwuid.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwuid
+#define GETXXKEY_FUNC getpwuid
+#define GETXXKEY_ENTTYPE struct passwd
+#define GETXXKEY_ADD_PARAMS uid_t uid
+#define GETXXKEY_ADD_VARIABLES uid
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getpwuid_r.c b/libc/pwd_grp/getpwuid_r.c
index 21d39ed..0a5aa96 100644
--- a/libc/pwd_grp/getpwuid_r.c
+++ b/libc/pwd_grp/getpwuid_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getpwuid_r
+#define GETXXKEY_R_FUNC getpwuid_r
+#define GETXXKEY_R_PARSER __parsepwent
+#define GETXXKEY_R_ENTTYPE struct passwd
+#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
+#define DO_GETXXKEY_R_KEYTYPE uid_t
+#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getspent.c b/libc/pwd_grp/getspent.c
index 5699b67..4feb9f9 100644
--- a/libc/pwd_grp/getspent.c
+++ b/libc/pwd_grp/getspent.c
@@ -4,5 +4,8 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getspent
+#define GETXXKEY_FUNC getspent
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS void
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getspnam.c b/libc/pwd_grp/getspnam.c
index 19e40c7..a0a01ec 100644
--- a/libc/pwd_grp/getspnam.c
+++ b/libc/pwd_grp/getspnam.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getspnam
+#define GETXXKEY_FUNC getspnam
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS const char *name
+#define GETXXKEY_ADD_VARIABLES name
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/getspnam_r.c b/libc/pwd_grp/getspnam_r.c
index 053b697..ea23848 100644
--- a/libc/pwd_grp/getspnam_r.c
+++ b/libc/pwd_grp/getspnam_r.c
@@ -4,5 +4,10 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_getspnam_r
+#define GETXXKEY_R_FUNC getspnam_r
+#define GETXXKEY_R_PARSER __parsespent
+#define GETXXKEY_R_ENTTYPE struct spwd
+#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key))
+#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
+#define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW
#include "pwd_grp.c"
diff --git a/libc/pwd_grp/pwd_grp.c b/libc/pwd_grp/pwd_grp.c
index 0e7c7f7..acdb08d 100644
--- a/libc/pwd_grp/pwd_grp.c
+++ b/libc/pwd_grp/pwd_grp.c
@@ -127,59 +127,6 @@ libc_hidden_def(fgetspent_r)
#endif
/**********************************************************************/
-/* For the various fget??ent funcs, return NULL on failure and a
- * pointer to the appropriate struct (statically allocated) on success.
- */
-/**********************************************************************/
-#ifdef L_fgetpwent
-
-#ifdef __USE_SVID
-
-struct passwd *fgetpwent(FILE *stream)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd resultbuf;
- struct passwd *result;
-
- fgetpwent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-#endif
-
-#endif
-/**********************************************************************/
-#ifdef L_fgetgrent
-
-#ifdef __USE_SVID
-
-struct group *fgetgrent(FILE *stream)
-{
- static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group resultbuf;
- struct group *result;
-
- fgetgrent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-#endif
-
-#endif
-/**********************************************************************/
-#ifdef L_fgetspent
-
-
-struct spwd *fgetspent(FILE *stream)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd resultbuf;
- struct spwd *result;
-
- fgetspent_r(stream, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
#ifdef L_sgetspent_r
int sgetspent_r(const char *string, struct spwd *result_buf,
@@ -213,92 +160,6 @@ libc_hidden_def(sgetspent_r)
#endif
/**********************************************************************/
-
-#ifdef GETXXKEY_R_FUNC
-#error GETXXKEY_R_FUNC is already defined!
-#endif
-
-#ifdef L_getpwnam_r
-#define GETXXKEY_R_FUNC getpwnam_r
-#define GETXXKEY_R_PARSER __parsepwent
-#define GETXXKEY_R_ENTTYPE struct passwd
-#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->pw_name, key))
-#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
-#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getgrnam_r
-#define GETXXKEY_R_FUNC getgrnam_r
-#define GETXXKEY_R_PARSER __parsegrent
-#define GETXXKEY_R_ENTTYPE struct group
-#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->gr_name, key))
-#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
-#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getspnam_r
-#define GETXXKEY_R_FUNC getspnam_r
-#define GETXXKEY_R_PARSER __parsespent
-#define GETXXKEY_R_ENTTYPE struct spwd
-#define GETXXKEY_R_TEST(ENT) (!strcmp((ENT)->sp_namp, key))
-#define DO_GETXXKEY_R_KEYTYPE const char *__restrict
-#define DO_GETXXKEY_R_PATHNAME _PATH_SHADOW
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getpwuid_r
-#define GETXXKEY_R_FUNC getpwuid_r
-#define GETXXKEY_R_PARSER __parsepwent
-#define GETXXKEY_R_ENTTYPE struct passwd
-#define GETXXKEY_R_TEST(ENT) ((ENT)->pw_uid == key)
-#define DO_GETXXKEY_R_KEYTYPE uid_t
-#define DO_GETXXKEY_R_PATHNAME _PATH_PASSWD
-#include "pwd_grp_internal.c"
-#endif
-
-#ifdef L_getgrgid_r
-#define GETXXKEY_R_FUNC getgrgid_r
-#define GETXXKEY_R_PARSER __parsegrent
-#define GETXXKEY_R_ENTTYPE struct group
-#define GETXXKEY_R_TEST(ENT) ((ENT)->gr_gid == key)
-#define DO_GETXXKEY_R_KEYTYPE gid_t
-#define DO_GETXXKEY_R_PATHNAME _PATH_GROUP
-#include "pwd_grp_internal.c"
-#endif
-
-/**********************************************************************/
-#ifdef L_getpwuid
-
-
-struct passwd *getpwuid(uid_t uid)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd resultbuf;
- struct passwd *result;
-
- getpwuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getgrgid
-
-
-struct group *getgrgid(gid_t gid)
-{
- static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group resultbuf;
- struct group *result;
-
- getgrgid_r(gid, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
#ifdef L_getspuid_r
/* This function is non-standard and is currently not built. It seems
@@ -325,69 +186,6 @@ int getspuid_r(uid_t uid, struct spwd *__restrict resultbuf,
#endif
/**********************************************************************/
-#ifdef L_getspuid
-
-/* This function is non-standard and is currently not built.
- * Why it was added, I do not know. */
-
-struct spwd *getspuid(uid_t uid)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd resultbuf;
- struct spwd *result;
-
- getspuid_r(uid, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getpwnam
-
-
-struct passwd *getpwnam(const char *name)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd resultbuf;
- struct passwd *result;
-
- getpwnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-libc_hidden_def(getpwnam)
-
-#endif
-/**********************************************************************/
-#ifdef L_getgrnam
-
-
-struct group *getgrnam(const char *name)
-{
- static char buffer[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group resultbuf;
- struct group *result;
-
- getgrnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getspnam
-
-
-struct spwd *getspnam(const char *name)
-{
- static char buffer[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd resultbuf;
- struct spwd *result;
-
- getspnam_r(name, &resultbuf, buffer, sizeof(buffer), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
#ifdef L_getpw
@@ -585,65 +383,14 @@ libc_hidden_def(getspent_r)
#endif
/**********************************************************************/
-#ifdef L_getpwent
-
-
-struct passwd *getpwent(void)
-{
- static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct passwd pwd;
- struct passwd *result;
-
- getpwent_r(&pwd, line_buff, sizeof(line_buff), &result);
- return result;
-}
-
-#endif
-/**********************************************************************/
-#ifdef L_getgrent
-
-
-struct group *getgrent(void)
-{
- static char line_buff[__UCLIBC_GRP_BUFFER_SIZE__];
- static struct group gr;
- struct group *result;
-
- getgrent_r(&gr, line_buff, sizeof(line_buff), &result);
- return result;
-}
-
-#endif
+/* For the various fget??ent funcs, return NULL on failure and a
+ * pointer to the appropriate struct (statically allocated) on success.
+ */
/**********************************************************************/
-#ifdef L_getspent
-
-
-struct spwd *getspent(void)
-{
- static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd spwd;
- struct spwd *result;
-
- getspent_r(&spwd, line_buff, sizeof(line_buff), &result);
- return result;
-}
-
+#if defined(GETXXKEY_FUNC) || defined(GETXXKEY_R_FUNC)
+#include "pwd_grp_internal.c"
#endif
-/**********************************************************************/
-#ifdef L_sgetspent
-
-
-struct spwd *sgetspent(const char *string)
-{
- static char line_buff[__UCLIBC_PWD_BUFFER_SIZE__];
- static struct spwd spwd;
- struct spwd *result;
-
- sgetspent_r(string, &spwd, line_buff, sizeof(line_buff), &result);
- return result;
-}
-#endif
/**********************************************************************/
#ifdef L___getgrouplist_internal
diff --git a/libc/pwd_grp/pwd_grp_internal.c b/libc/pwd_grp/pwd_grp_internal.c
index d2fde11..104f532 100644
--- a/libc/pwd_grp/pwd_grp_internal.c
+++ b/libc/pwd_grp/pwd_grp_internal.c
@@ -36,18 +36,10 @@
#endif
/**********************************************************************/
-/* Sizes for statically allocated buffers. */
-
-/* If you change these values, also change _SC_GETPW_R_SIZE_MAX and
- * _SC_GETGR_R_SIZE_MAX in libc/unistd/sysconf.c to match */
-#define PWD_BUFFER_SIZE 256
-#define GRP_BUFFER_SIZE 256
-
-/**********************************************************************/
/* Prototypes for internal functions. */
-#ifndef GETXXKEY_R_FUNC
-#error GETXXKEY_R_FUNC is not defined!
+#if !defined(GETXXKEY_R_FUNC) && !defined(GETXXKEY_FUNC)
+#error GETXXKEY_R_FUNC/GETXXKEY_FUNC are not defined!
#endif
/**********************************************************************/
#ifdef GETXXKEY_R_FUNC
@@ -89,9 +81,44 @@ int GETXXKEY_R_FUNC(DO_GETXXKEY_R_KEYTYPE key,
}
libc_hidden_def(GETXXKEY_R_FUNC)
+#endif /* GETXXKEY_R_FUNC */
+
+/**********************************************************************/
+#ifdef GETXXKEY_FUNC
+
+#define REENTRANT_NAME APPEND_R(GETXXKEY_FUNC)
+#define APPEND_R(name) APPEND_R1(name)
+#define APPEND_R1(name) name##_r
+
+GETXXKEY_ENTTYPE *GETXXKEY_FUNC(GETXXKEY_ADD_PARAMS)
+{
+ static char buffer[GETXXKEY_BUFLEN];
+ static GETXXKEY_ENTTYPE resultbuf;
+ GETXXKEY_ENTTYPE *result;
+
+# ifdef GETXXKEY_ADD_VARIABLES
+ REENTRANT_NAME(GETXXKEY_ADD_VARIABLES, &resultbuf, buffer, sizeof(buffer), &result);
+# else
+ REENTRANT_NAME(&resultbuf, buffer, sizeof(buffer), &result);
+# endif
+ return result;
+}
+#ifdef GETXXKEY_FUNC_HIDDEN
+libc_hidden_def(GETXXKEY_FUNC)
#endif
+
+#undef REENTRANT_NAME
+#undef APPEND_R
+#undef APPEND_R1
+#endif /* GETXXKEY_FUNC */
+
/**********************************************************************/
-#undef GETXXKEY_R_FUNC_HIDDEN
+#undef GETXXKEY_FUNC
+#undef GETXXKEY_ENTTYPE
+#undef GETXXKEY_BUFLEN
+#undef GETXXKEY_FUNC_HIDDEN
+#undef GETXXKEY_ADD_PARAMS
+#undef GETXXKEY_ADD_VARIABLES
#undef GETXXKEY_R_FUNC
#undef GETXXKEY_R_PARSER
#undef GETXXKEY_R_ENTTYPE
diff --git a/libc/pwd_grp/sgetspent.c b/libc/pwd_grp/sgetspent.c
index 877a247..990c0b6 100644
--- a/libc/pwd_grp/sgetspent.c
+++ b/libc/pwd_grp/sgetspent.c
@@ -4,5 +4,9 @@
* Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
*/
-#define L_sgetspent
+#define GETXXKEY_FUNC sgetspent
+#define GETXXKEY_ENTTYPE struct spwd
+#define GETXXKEY_ADD_PARAMS const char *string
+#define GETXXKEY_ADD_VARIABLES string
+#define GETXXKEY_BUFLEN __UCLIBC_PWD_BUFFER_SIZE__
#include "pwd_grp.c"
diff --git a/libc/string/generic/mempcpy.c b/libc/string/generic/mempcpy.c
index d7fa79e..bb5563a 100644
--- a/libc/string/generic/mempcpy.c
+++ b/libc/string/generic/mempcpy.c
@@ -16,4 +16,5 @@ void *mempcpy (void *dstpp, const void *srcpp, size_t len)
return (void *)(((char *)dstpp) + len);
}
libc_hidden_weak(mempcpy)
+strong_alias(mempcpy,__mempcpy)
#endif
diff --git a/libc/string/mips/memcpy.S b/libc/string/mips/memcpy.S
index 48c4f2a..2a187ef 100644
--- a/libc/string/mips/memcpy.S
+++ b/libc/string/mips/memcpy.S
@@ -1,6 +1,5 @@
-/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2012-2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
- Contributed by Hartvig Ekner <hartvige(a)mips.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -13,243 +12,861 @@
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
+ License along with the GNU C Library. If not, see
<http://www.gnu.org/licenses/>. */
-#include <features.h>
-#include <sysdep.h>
-#include <endian.h>
+#ifdef ANDROID_CHANGES
+# include "machine/asm.h"
+# include "machine/regdef.h"
+# define USE_MEMMOVE_FOR_OVERLAP
+# define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD_STREAMED
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#elif _LIBC
+# include <sysdep.h>
+# include <regdef.h>
+# include <sys/asm.h>
+# define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD_STREAMED
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#elif defined _COMPILING_NEWLIB
+# include "machine/asm.h"
+# include "machine/regdef.h"
+# define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD_STREAMED
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#else
+# include <regdef.h>
+# include <sys/asm.h>
+#endif
+
+#if (_MIPS_ISA == _MIPS_ISA_MIPS4) || (_MIPS_ISA == _MIPS_ISA_MIPS5) || \
+ (_MIPS_ISA == _MIPS_ISA_MIPS32) || (_MIPS_ISA == _MIPS_ISA_MIPS64)
+# ifndef DISABLE_PREFETCH
+# define USE_PREFETCH
+# endif
+#endif
+
+#if defined(_MIPS_SIM) && ((_MIPS_SIM == _ABI64) || (_MIPS_SIM == _ABIN32))
+# ifndef DISABLE_DOUBLE
+# define USE_DOUBLE
+# endif
+#endif
+
+/* Some asm.h files do not have the L macro definition. */
+#ifndef L
+# if _MIPS_SIM == _ABIO32
+# define L(label) $L ## label
+# else
+# define L(label) .L ## label
+# endif
+#endif
+
+/* Some asm.h files do not have the PTR_ADDIU macro definition. */
+#ifndef PTR_ADDIU
+# ifdef USE_DOUBLE
+# define PTR_ADDIU daddiu
+# else
+# define PTR_ADDIU addiu
+# endif
+#endif
+
+/* Some asm.h files do not have the PTR_SRA macro definition. */
+#ifndef PTR_SRA
+# ifdef USE_DOUBLE
+# define PTR_SRA dsra
+# else
+# define PTR_SRA sra
+# endif
+#endif
+
+/* New R6 instructions that may not be in asm.h. */
+#ifndef PTR_LSA
+# if _MIPS_SIM == _ABI64
+# define PTR_LSA dlsa
+# else
+# define PTR_LSA lsa
+# endif
+#endif
+
+/*
+ * Using PREFETCH_HINT_LOAD_STREAMED instead of PREFETCH_LOAD on load
+ * prefetches appears to offer a slight preformance advantage.
+ *
+ * Using PREFETCH_HINT_PREPAREFORSTORE instead of PREFETCH_STORE
+ * or PREFETCH_STORE_STREAMED offers a large performance advantage
+ * but PREPAREFORSTORE has some special restrictions to consider.
+ *
+ * Prefetch with the 'prepare for store' hint does not copy a memory
+ * location into the cache, it just allocates a cache line and zeros
+ * it out. This means that if you do not write to the entire cache
+ * line before writing it out to memory some data will get zero'ed out
+ * when the cache line is written back to memory and data will be lost.
+ *
+ * Also if you are using this memcpy to copy overlapping buffers it may
+ * not behave correctly when using the 'prepare for store' hint. If you
+ * use the 'prepare for store' prefetch on a memory area that is in the
+ * memcpy source (as well as the memcpy destination), then you will get
+ * some data zero'ed out before you have a chance to read it and data will
+ * be lost.
+ *
+ * If you are going to use this memcpy routine with the 'prepare for store'
+ * prefetch you may want to set USE_MEMMOVE_FOR_OVERLAP in order to avoid
+ * the problem of running memcpy on overlapping buffers.
+ *
+ * There are ifdef'ed sections of this memcpy to make sure that it does not
+ * do prefetches on cache lines that are not going to be completely written.
+ * This code is only needed and only used when PREFETCH_STORE_HINT is set to
+ * PREFETCH_HINT_PREPAREFORSTORE. This code assumes that cache lines are
+ * 32 bytes and if the cache line is larger it will not work correctly.
+ */
+
+#ifdef USE_PREFETCH
+# define PREFETCH_HINT_LOAD 0
+# define PREFETCH_HINT_STORE 1
+# define PREFETCH_HINT_LOAD_STREAMED 4
+# define PREFETCH_HINT_STORE_STREAMED 5
+# define PREFETCH_HINT_LOAD_RETAINED 6
+# define PREFETCH_HINT_STORE_RETAINED 7
+# define PREFETCH_HINT_WRITEBACK_INVAL 25
+# define PREFETCH_HINT_PREPAREFORSTORE 30
+
+/*
+ * If we have not picked out what hints to use at this point use the
+ * standard load and store prefetch hints.
+ */
+# ifndef PREFETCH_STORE_HINT
+# define PREFETCH_STORE_HINT PREFETCH_HINT_STORE
+# endif
+# ifndef PREFETCH_LOAD_HINT
+# define PREFETCH_LOAD_HINT PREFETCH_HINT_LOAD
+# endif
+
+/*
+ * We double everything when USE_DOUBLE is true so we do 2 prefetches to
+ * get 64 bytes in that case. The assumption is that each individual
+ * prefetch brings in 32 bytes.
+ */
+
+# ifdef USE_DOUBLE
+# define PREFETCH_CHUNK 64
+# define PREFETCH_FOR_LOAD(chunk, reg) \
+ pref PREFETCH_LOAD_HINT, (chunk)*64(reg); \
+ pref PREFETCH_LOAD_HINT, ((chunk)*64)+32(reg)
+# define PREFETCH_FOR_STORE(chunk, reg) \
+ pref PREFETCH_STORE_HINT, (chunk)*64(reg); \
+ pref PREFETCH_STORE_HINT, ((chunk)*64)+32(reg)
+# else
+# define PREFETCH_CHUNK 32
+# define PREFETCH_FOR_LOAD(chunk, reg) \
+ pref PREFETCH_LOAD_HINT, (chunk)*32(reg)
+# define PREFETCH_FOR_STORE(chunk, reg) \
+ pref PREFETCH_STORE_HINT, (chunk)*32(reg)
+# endif
+/* MAX_PREFETCH_SIZE is the maximum size of a prefetch, it must not be less
+ * than PREFETCH_CHUNK, the assumed size of each prefetch. If the real size
+ * of a prefetch is greater than MAX_PREFETCH_SIZE and the PREPAREFORSTORE
+ * hint is used, the code will not work correctly. If PREPAREFORSTORE is not
+ * used then MAX_PREFETCH_SIZE does not matter. */
+# define MAX_PREFETCH_SIZE 128
+/* PREFETCH_LIMIT is set based on the fact that we never use an offset greater
+ * than 5 on a STORE prefetch and that a single prefetch can never be larger
+ * than MAX_PREFETCH_SIZE. We add the extra 32 when USE_DOUBLE is set because
+ * we actually do two prefetches in that case, one 32 bytes after the other. */
+# ifdef USE_DOUBLE
+# define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + 32 + MAX_PREFETCH_SIZE
+# else
+# define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + MAX_PREFETCH_SIZE
+# endif
+# if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) \
+ && ((PREFETCH_CHUNK * 4) < MAX_PREFETCH_SIZE)
+/* We cannot handle this because the initial prefetches may fetch bytes that
+ * are before the buffer being copied. We start copies with an offset
+ * of 4 so avoid this situation when using PREPAREFORSTORE. */
+#error "PREFETCH_CHUNK is too large and/or MAX_PREFETCH_SIZE is too small."
+# endif
+#else /* USE_PREFETCH not defined */
+# define PREFETCH_FOR_LOAD(offset, reg)
+# define PREFETCH_FOR_STORE(offset, reg)
+#endif
+
+#if __mips_isa_rev > 5
+# if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+# undef PREFETCH_STORE_HINT
+# define PREFETCH_STORE_HINT PREFETCH_HINT_STORE_STREAMED
+# endif
+# define R6_CODE
+#endif
-/* void *memcpy(void *s1, const void *s2, size_t n); */
+/* Allow the routine to be named something else if desired. */
+#ifndef MEMCPY_NAME
+# define MEMCPY_NAME memcpy
+#endif
+
+/* We use these 32/64 bit registers as temporaries to do the copying. */
+#define REG0 t0
+#define REG1 t1
+#define REG2 t2
+#define REG3 t3
+#if defined(_MIPS_SIM) && ((_MIPS_SIM == _ABIO32) || (_MIPS_SIM == _ABIO64))
+# define REG4 t4
+# define REG5 t5
+# define REG6 t6
+# define REG7 t7
+#else
+# define REG4 ta0
+# define REG5 ta1
+# define REG6 ta2
+# define REG7 ta3
+#endif
-#ifdef __mips64
+/* We load/store 64 bits at a time when USE_DOUBLE is true.
+ * The C_ prefix stands for CHUNK and is used to avoid macro name
+ * conflicts with system header files. */
-#include <sys/asm.h>
+#ifdef USE_DOUBLE
+# define C_ST sd
+# define C_LD ld
+# ifdef __MIPSEB
+# define C_LDHI ldl /* high part is left in big-endian */
+# define C_STHI sdl /* high part is left in big-endian */
+# define C_LDLO ldr /* low part is right in big-endian */
+# define C_STLO sdr /* low part is right in big-endian */
+# else
+# define C_LDHI ldr /* high part is right in little-endian */
+# define C_STHI sdr /* high part is right in little-endian */
+# define C_LDLO ldl /* low part is left in little-endian */
+# define C_STLO sdl /* low part is left in little-endian */
+# endif
+# define C_ALIGN dalign /* r6 align instruction */
+#else
+# define C_ST sw
+# define C_LD lw
+# ifdef __MIPSEB
+# define C_LDHI lwl /* high part is left in big-endian */
+# define C_STHI swl /* high part is left in big-endian */
+# define C_LDLO lwr /* low part is right in big-endian */
+# define C_STLO swr /* low part is right in big-endian */
+# else
+# define C_LDHI lwr /* high part is right in little-endian */
+# define C_STHI swr /* high part is right in little-endian */
+# define C_LDLO lwl /* low part is left in little-endian */
+# define C_STLO swl /* low part is left in little-endian */
+# endif
+# define C_ALIGN align /* r6 align instruction */
+#endif
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define LDHI ldl /* high part is left in big-endian */
-# define SDHI sdl /* high part is left in big-endian */
-# define LDLO ldr /* low part is right in big-endian */
-# define SDLO sdr /* low part is right in big-endian */
+/* Bookkeeping values for 32 vs. 64 bit mode. */
+#ifdef USE_DOUBLE
+# define NSIZE 8
+# define NSIZEMASK 0x3f
+# define NSIZEDMASK 0x7f
#else
-# define LDHI ldr /* high part is right in little-endian */
-# define SDHI sdr /* high part is right in little-endian */
-# define LDLO ldl /* low part is left in little-endian */
-# define SDLO sdl /* low part is left in little-endian */
+# define NSIZE 4
+# define NSIZEMASK 0x1f
+# define NSIZEDMASK 0x3f
#endif
+#define UNIT(unit) ((unit)*NSIZE)
+#define UNITM1(unit) (((unit)*NSIZE)-1)
-ENTRY (memcpy)
+#ifdef ANDROID_CHANGES
+LEAF(MEMCPY_NAME, 0)
+#else
+LEAF(MEMCPY_NAME)
+#endif
+ .set nomips16
.set noreorder
+/*
+ * Below we handle the case where memcpy is called with overlapping src and dst.
+ * Although memcpy is not required to handle this case, some parts of Android
+ * like Skia rely on such usage. We call memmove to handle such cases.
+ */
+#ifdef USE_MEMMOVE_FOR_OVERLAP
+ PTR_SUBU t0,a0,a1
+ PTR_SRA t2,t0,31
+ xor t1,t0,t2
+ PTR_SUBU t0,t1,t2
+ sltu t2,t0,a2
+ beq t2,zero,L(memcpy)
+ la t9,memmove
+ jr t9
+ nop
+L(memcpy):
+#endif
+/*
+ * If the size is less than 2*NSIZE (8 or 16), go to L(lastb). Regardless of
+ * size, copy dst pointer to v0 for the return value.
+ */
+ slti t2,a2,(2 * NSIZE)
+ bne t2,zero,L(lasts)
+#if defined(RETURN_FIRST_PREFETCH) || defined(RETURN_LAST_PREFETCH)
+ move v0,zero
+#else
+ move v0,a0
+#endif
- slti t0, a2, 16 # Less than 16?
- bne t0, zero, L(last16)
- move v0, a0 # Setup exit value before too late
-
- xor t0, a1, a0 # Find a0/a1 displacement
- andi t0, 0x7
- bne t0, zero, L(shift) # Go handle the unaligned case
- PTR_SUBU t1, zero, a1
- andi t1, 0x7 # a0/a1 are aligned, but are we
- beq t1, zero, L(chk8w) # starting in the middle of a word?
- PTR_SUBU a2, t1
- LDHI t0, 0(a1) # Yes we are... take care of that
- PTR_ADDU a1, t1
- SDHI t0, 0(a0)
- PTR_ADDU a0, t1
-
-L(chk8w):
- andi t0, a2, 0x3f # 64 or more bytes left?
- beq t0, a2, L(chk1w)
- PTR_SUBU a3, a2, t0 # Yes
- PTR_ADDU a3, a1 # a3 = end address of loop
- move a2, t0 # a2 = what will be left after loop
-L(lop8w):
- ld t0, 0(a1) # Loop taking 8 words at a time
- ld t1, 8(a1)
- ld t2, 16(a1)
- ld t3, 24(a1)
- ld ta0, 32(a1)
- ld ta1, 40(a1)
- ld ta2, 48(a1)
- ld ta3, 56(a1)
- PTR_ADDIU a0, 64
- PTR_ADDIU a1, 64
- sd t0, -64(a0)
- sd t1, -56(a0)
- sd t2, -48(a0)
- sd t3, -40(a0)
- sd ta0, -32(a0)
- sd ta1, -24(a0)
- sd ta2, -16(a0)
- bne a1, a3, L(lop8w)
- sd ta3, -8(a0)
+#ifndef R6_CODE
-L(chk1w):
- andi t0, a2, 0x7 # 8 or more bytes left?
- beq t0, a2, L(last16)
- PTR_SUBU a3, a2, t0 # Yes, handle them one dword at a time
- PTR_ADDU a3, a1 # a3 again end address
- move a2, t0
-L(lop1w):
- ld t0, 0(a1)
- PTR_ADDIU a0, 8
- PTR_ADDIU a1, 8
- bne a1, a3, L(lop1w)
- sd t0, -8(a0)
-
-L(last16):
- blez a2, L(lst16e) # Handle last 16 bytes, one at a time
- PTR_ADDU a3, a2, a1
-L(lst16l):
- lb t0, 0(a1)
- PTR_ADDIU a0, 1
- PTR_ADDIU a1, 1
- bne a1, a3, L(lst16l)
- sb t0, -1(a0)
-L(lst16e):
- jr ra # Bye, bye
- nop
+/*
+ * If src and dst have different alignments, go to L(unaligned), if they
+ * have the same alignment (but are not actually aligned) do a partial
+ * load/store to make them aligned. If they are both already aligned
+ * we can start copying at L(aligned).
+ */
+ xor t8,a1,a0
+ andi t8,t8,(NSIZE-1) /* t8 is a0/a1 word-displacement */
+ bne t8,zero,L(unaligned)
+ PTR_SUBU a3, zero, a0
-L(shift):
- PTR_SUBU a3, zero, a0 # Src and Dest unaligned
- andi a3, 0x7 # (unoptimized case...)
- beq a3, zero, L(shft1)
- PTR_SUBU a2, a3 # a2 = bytes left
- LDHI t0, 0(a1) # Take care of first odd part
- LDLO t0, 7(a1)
- PTR_ADDU a1, a3
- SDHI t0, 0(a0)
- PTR_ADDU a0, a3
-L(shft1):
- andi t0, a2, 0x7
- PTR_SUBU a3, a2, t0
- PTR_ADDU a3, a1
-L(shfth):
- LDHI t1, 0(a1) # Limp through, dword by dword
- LDLO t1, 7(a1)
- PTR_ADDIU a0, 8
- PTR_ADDIU a1, 8
- bne a1, a3, L(shfth)
- sd t1, -8(a0)
- b L(last16) # Handle anything which may be left
- move a2, t0
+ andi a3,a3,(NSIZE-1) /* copy a3 bytes to align a0/a1 */
+ beq a3,zero,L(aligned) /* if a3=0, it is already aligned */
+ PTR_SUBU a2,a2,a3 /* a2 is the remining bytes count */
- .set reorder
-END (memcpy)
+ C_LDHI t8,0(a1)
+ PTR_ADDU a1,a1,a3
+ C_STHI t8,0(a0)
+ PTR_ADDU a0,a0,a3
+
+#else /* R6_CODE */
+
+/*
+ * Align the destination and hope that the source gets aligned too. If it
+ * doesn't we jump to L(r6_unaligned*) to do unaligned copies using the r6
+ * align instruction.
+ */
+ andi t8,a0,7
+ lapc t9,L(atable)
+ PTR_LSA t9,t8,t9,2
+ jrc t9
+L(atable):
+ bc L(lb0)
+ bc L(lb7)
+ bc L(lb6)
+ bc L(lb5)
+ bc L(lb4)
+ bc L(lb3)
+ bc L(lb2)
+ bc L(lb1)
+L(lb7):
+ lb a3, 6(a1)
+ sb a3, 6(a0)
+L(lb6):
+ lb a3, 5(a1)
+ sb a3, 5(a0)
+L(lb5):
+ lb a3, 4(a1)
+ sb a3, 4(a0)
+L(lb4):
+ lb a3, 3(a1)
+ sb a3, 3(a0)
+L(lb3):
+ lb a3, 2(a1)
+ sb a3, 2(a0)
+L(lb2):
+ lb a3, 1(a1)
+ sb a3, 1(a0)
+L(lb1):
+ lb a3, 0(a1)
+ sb a3, 0(a0)
+
+ li t9,8
+ subu t8,t9,t8
+ PTR_SUBU a2,a2,t8
+ PTR_ADDU a0,a0,t8
+ PTR_ADDU a1,a1,t8
+L(lb0):
-#else /* !__mips64 */
+ andi t8,a1,(NSIZE-1)
+ lapc t9,L(jtable)
+ PTR_LSA t9,t8,t9,2
+ jrc t9
+L(jtable):
+ bc L(aligned)
+ bc L(r6_unaligned1)
+ bc L(r6_unaligned2)
+ bc L(r6_unaligned3)
+# ifdef USE_DOUBLE
+ bc L(r6_unaligned4)
+ bc L(r6_unaligned5)
+ bc L(r6_unaligned6)
+ bc L(r6_unaligned7)
+# endif
+#endif /* R6_CODE */
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define LWHI lwl /* high part is left in big-endian */
-# define SWHI swl /* high part is left in big-endian */
-# define LWLO lwr /* low part is right in big-endian */
-# define SWLO swr /* low part is right in big-endian */
+L(aligned):
+
+/*
+ * Now dst/src are both aligned to (word or double word) aligned addresses
+ * Set a2 to count how many bytes we have to copy after all the 64/128 byte
+ * chunks are copied and a3 to the dst pointer after all the 64/128 byte
+ * chunks have been copied. We will loop, incrementing a0 and a1 until a0
+ * equals a3.
+ */
+
+ andi t8,a2,NSIZEDMASK /* any whole 64-byte/128-byte chunks? */
+ beq a2,t8,L(chkw) /* if a2==t8, no 64-byte/128-byte chunks */
+ PTR_SUBU a3,a2,t8 /* subtract from a2 the reminder */
+ PTR_ADDU a3,a0,a3 /* Now a3 is the final dst after loop */
+
+/* When in the loop we may prefetch with the 'prepare to store' hint,
+ * in this case the a0+x should not be past the "t0-32" address. This
+ * means: for x=128 the last "safe" a0 address is "t0-160". Alternatively,
+ * for x=64 the last "safe" a0 address is "t0-96" In the current version we
+ * will use "prefetch hint,128(a0)", so "t0-160" is the limit.
+ */
+#if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ PTR_ADDU t0,a0,a2 /* t0 is the "past the end" address */
+ PTR_SUBU t9,t0,PREFETCH_LIMIT /* t9 is the "last safe pref" address */
+#endif
+ PREFETCH_FOR_LOAD (0, a1)
+ PREFETCH_FOR_LOAD (1, a1)
+ PREFETCH_FOR_LOAD (2, a1)
+ PREFETCH_FOR_LOAD (3, a1)
+#if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE)
+ PREFETCH_FOR_STORE (1, a0)
+ PREFETCH_FOR_STORE (2, a0)
+ PREFETCH_FOR_STORE (3, a0)
+#endif
+#if defined(RETURN_FIRST_PREFETCH) && defined(USE_PREFETCH)
+# if PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE
+ sltu v1,t9,a0
+ bgtz v1,L(skip_set)
+ nop
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*4)
+L(skip_set):
+# else
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*1)
+# endif
+#endif
+#if defined(RETURN_LAST_PREFETCH) && defined(USE_PREFETCH) \
+ && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE)
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*3)
+# ifdef USE_DOUBLE
+ PTR_ADDIU v0,v0,32
+# endif
+#endif
+L(loop16w):
+ C_LD t0,UNIT(0)(a1)
+#if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ sltu v1,t9,a0 /* If a0 > t9 don't use next prefetch */
+ bgtz v1,L(skip_pref)
+#endif
+ C_LD t1,UNIT(1)(a1)
+#ifdef R6_CODE
+ PREFETCH_FOR_STORE (2, a0)
#else
-# define LWHI lwr /* high part is right in little-endian */
-# define SWHI swr /* high part is right in little-endian */
-# define LWLO lwl /* low part is left in little-endian */
-# define SWLO swl /* low part is left in little-endian */
+ PREFETCH_FOR_STORE (4, a0)
+ PREFETCH_FOR_STORE (5, a0)
+#endif
+#if defined(RETURN_LAST_PREFETCH) && defined(USE_PREFETCH)
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*5)
+# ifdef USE_DOUBLE
+ PTR_ADDIU v0,v0,32
+# endif
#endif
+L(skip_pref):
+ C_LD REG2,UNIT(2)(a1)
+ C_LD REG3,UNIT(3)(a1)
+ C_LD REG4,UNIT(4)(a1)
+ C_LD REG5,UNIT(5)(a1)
+ C_LD REG6,UNIT(6)(a1)
+ C_LD REG7,UNIT(7)(a1)
+#ifdef R6_CODE
+ PREFETCH_FOR_LOAD (3, a1)
+#else
+ PREFETCH_FOR_LOAD (4, a1)
+#endif
+ C_ST t0,UNIT(0)(a0)
+ C_ST t1,UNIT(1)(a0)
+ C_ST REG2,UNIT(2)(a0)
+ C_ST REG3,UNIT(3)(a0)
+ C_ST REG4,UNIT(4)(a0)
+ C_ST REG5,UNIT(5)(a0)
+ C_ST REG6,UNIT(6)(a0)
+ C_ST REG7,UNIT(7)(a0)
-ENTRY (memcpy)
- .set noreorder
+ C_LD t0,UNIT(8)(a1)
+ C_LD t1,UNIT(9)(a1)
+ C_LD REG2,UNIT(10)(a1)
+ C_LD REG3,UNIT(11)(a1)
+ C_LD REG4,UNIT(12)(a1)
+ C_LD REG5,UNIT(13)(a1)
+ C_LD REG6,UNIT(14)(a1)
+ C_LD REG7,UNIT(15)(a1)
+#ifndef R6_CODE
+ PREFETCH_FOR_LOAD (5, a1)
+#endif
+ C_ST t0,UNIT(8)(a0)
+ C_ST t1,UNIT(9)(a0)
+ C_ST REG2,UNIT(10)(a0)
+ C_ST REG3,UNIT(11)(a0)
+ C_ST REG4,UNIT(12)(a0)
+ C_ST REG5,UNIT(13)(a0)
+ C_ST REG6,UNIT(14)(a0)
+ C_ST REG7,UNIT(15)(a0)
+ PTR_ADDIU a0,a0,UNIT(16) /* adding 64/128 to dest */
+ bne a0,a3,L(loop16w)
+ PTR_ADDIU a1,a1,UNIT(16) /* adding 64/128 to src */
+ move a2,t8
+
+/* Here we have src and dest word-aligned but less than 64-bytes or
+ * 128 bytes to go. Check for a 32(64) byte chunk and copy if if there
+ * is one. Otherwise jump down to L(chk1w) to handle the tail end of
+ * the copy.
+ */
+
+L(chkw):
+ PREFETCH_FOR_LOAD (0, a1)
+ andi t8,a2,NSIZEMASK /* Is there a 32-byte/64-byte chunk. */
+ /* The t8 is the reminder count past 32-bytes */
+ beq a2,t8,L(chk1w) /* When a2=t8, no 32-byte chunk */
+ nop
+ C_LD t0,UNIT(0)(a1)
+ C_LD t1,UNIT(1)(a1)
+ C_LD REG2,UNIT(2)(a1)
+ C_LD REG3,UNIT(3)(a1)
+ C_LD REG4,UNIT(4)(a1)
+ C_LD REG5,UNIT(5)(a1)
+ C_LD REG6,UNIT(6)(a1)
+ C_LD REG7,UNIT(7)(a1)
+ PTR_ADDIU a1,a1,UNIT(8)
+ C_ST t0,UNIT(0)(a0)
+ C_ST t1,UNIT(1)(a0)
+ C_ST REG2,UNIT(2)(a0)
+ C_ST REG3,UNIT(3)(a0)
+ C_ST REG4,UNIT(4)(a0)
+ C_ST REG5,UNIT(5)(a0)
+ C_ST REG6,UNIT(6)(a0)
+ C_ST REG7,UNIT(7)(a0)
+ PTR_ADDIU a0,a0,UNIT(8)
+
+/*
+ * Here we have less than 32(64) bytes to copy. Set up for a loop to
+ * copy one word (or double word) at a time. Set a2 to count how many
+ * bytes we have to copy after all the word (or double word) chunks are
+ * copied and a3 to the dst pointer after all the (d)word chunks have
+ * been copied. We will loop, incrementing a0 and a1 until a0 equals a3.
+ */
+L(chk1w):
+ andi a2,t8,(NSIZE-1) /* a2 is the reminder past one (d)word chunks */
+ beq a2,t8,L(lastw)
+ PTR_SUBU a3,t8,a2 /* a3 is count of bytes in one (d)word chunks */
+ PTR_ADDU a3,a0,a3 /* a3 is the dst address after loop */
- slti t0, a2, 8 # Less than 8?
- bne t0, zero, L(last8)
- move v0, a0 # Setup exit value before too late
-
- xor t0, a1, a0 # Find a0/a1 displacement
- andi t0, 0x3
- bne t0, zero, L(shift) # Go handle the unaligned case
- subu t1, zero, a1
- andi t1, 0x3 # a0/a1 are aligned, but are we
- beq t1, zero, L(chk8w) # starting in the middle of a word?
- subu a2, t1
- LWHI t0, 0(a1) # Yes we are... take care of that
- addu a1, t1
- SWHI t0, 0(a0)
- addu a0, t1
-
-L(chk8w):
- andi t0, a2, 0x1f # 32 or more bytes left?
- beq t0, a2, L(chk1w)
- subu a3, a2, t0 # Yes
- addu a3, a1 # a3 = end address of loop
- move a2, t0 # a2 = what will be left after loop
-L(lop8w):
- lw t0, 0(a1) # Loop taking 8 words at a time
- lw t1, 4(a1)
- lw t2, 8(a1)
- lw t3, 12(a1)
- lw t4, 16(a1)
- lw t5, 20(a1)
- lw t6, 24(a1)
- lw t7, 28(a1)
- addiu a0, 32
- addiu a1, 32
- sw t0, -32(a0)
- sw t1, -28(a0)
- sw t2, -24(a0)
- sw t3, -20(a0)
- sw t4, -16(a0)
- sw t5, -12(a0)
- sw t6, -8(a0)
- bne a1, a3, L(lop8w)
- sw t7, -4(a0)
-
-L(chk1w):
- andi t0, a2, 0x3 # 4 or more bytes left?
- beq t0, a2, L(last8)
- subu a3, a2, t0 # Yes, handle them one word at a time
- addu a3, a1 # a3 again end address
- move a2, t0
-L(lop1w):
- lw t0, 0(a1)
- addiu a0, 4
- addiu a1, 4
- bne a1, a3, L(lop1w)
- sw t0, -4(a0)
-
-L(last8):
- blez a2, L(lst8e) # Handle last 8 bytes, one at a time
- addu a3, a2, a1
-L(lst8l):
- lb t0, 0(a1)
- addiu a0, 1
- addiu a1, 1
- bne a1, a3, L(lst8l)
- sb t0, -1(a0)
-L(lst8e):
- jr ra # Bye, bye
+/* copying in words (4-byte or 8-byte chunks) */
+L(wordCopy_loop):
+ C_LD REG3,UNIT(0)(a1)
+ PTR_ADDIU a0,a0,UNIT(1)
+ PTR_ADDIU a1,a1,UNIT(1)
+ bne a0,a3,L(wordCopy_loop)
+ C_ST REG3,UNIT(-1)(a0)
+
+/* If we have been copying double words, see if we can copy a single word
+ before doing byte copies. We can have, at most, one word to copy. */
+
+L(lastw):
+#ifdef USE_DOUBLE
+ andi t8,a2,3 /* a2 is the remainder past 4 byte chunks. */
+ beq t8,a2,L(lastb)
+ lw REG3,0(a1)
+ sw REG3,0(a0)
+ PTR_ADDIU a0,a0,4
+ PTR_ADDIU a1,a1,4
+ move a2,t8
+#endif
+
+/* Copy the last 8 (or 16) bytes */
+L(lastb):
+ blez a2,L(leave)
+ PTR_ADDU a3,a0,a2 /* a3 is the last dst address */
+L(lastbloop):
+ lb v1,0(a1)
+ PTR_ADDIU a0,a0,1
+ PTR_ADDIU a1,a1,1
+ bne a0,a3,L(lastbloop)
+ sb v1,-1(a0)
+L(leave):
+ j ra
nop
-L(shift):
- subu a3, zero, a0 # Src and Dest unaligned
- andi a3, 0x3 # (unoptimized case...)
- beq a3, zero, L(shft1)
- subu a2, a3 # a2 = bytes left
- LWHI t0, 0(a1) # Take care of first odd part
- LWLO t0, 3(a1)
- addu a1, a3
- SWHI t0, 0(a0)
- addu a0, a3
-L(shft1):
- andi t0, a2, 0x3
- subu a3, a2, t0
- addu a3, a1
-L(shfth):
- LWHI t1, 0(a1) # Limp through, word by word
- LWLO t1, 3(a1)
- addiu a0, 4
- addiu a1, 4
- bne a1, a3, L(shfth)
- sw t1, -4(a0)
- b L(last8) # Handle anything which may be left
- move a2, t0
+/* We jump here with a memcpy of less than 8 or 16 bytes, depending on
+ whether or not USE_DOUBLE is defined. Instead of just doing byte
+ copies, check the alignment and size and use lw/sw if possible.
+ Otherwise, do byte copies. */
- .set reorder
-END (memcpy)
+L(lasts):
+ andi t8,a2,3
+ beq t8,a2,L(lastb)
+
+ andi t9,a0,3
+ bne t9,zero,L(lastb)
+ andi t9,a1,3
+ bne t9,zero,L(lastb)
+
+ PTR_SUBU a3,a2,t8
+ PTR_ADDU a3,a0,a3
+
+L(wcopy_loop):
+ lw REG3,0(a1)
+ PTR_ADDIU a0,a0,4
+ PTR_ADDIU a1,a1,4
+ bne a0,a3,L(wcopy_loop)
+ sw REG3,-4(a0)
-#endif /* !__mips64 */
+ b L(lastb)
+ move a2,t8
-libc_hidden_def(memcpy)
+#ifndef R6_CODE
+/*
+ * UNALIGNED case, got here with a3 = "negu a0"
+ * This code is nearly identical to the aligned code above
+ * but only the destination (not the source) gets aligned
+ * so we need to do partial loads of the source followed
+ * by normal stores to the destination (once we have aligned
+ * the destination).
+ */
+
+L(unaligned):
+ andi a3,a3,(NSIZE-1) /* copy a3 bytes to align a0/a1 */
+ beqz a3,L(ua_chk16w) /* if a3=0, it is already aligned */
+ PTR_SUBU a2,a2,a3 /* a2 is the remining bytes count */
+
+ C_LDHI v1,UNIT(0)(a1)
+ C_LDLO v1,UNITM1(1)(a1)
+ PTR_ADDU a1,a1,a3
+ C_STHI v1,UNIT(0)(a0)
+ PTR_ADDU a0,a0,a3
+
+/*
+ * Now the destination (but not the source) is aligned
+ * Set a2 to count how many bytes we have to copy after all the 64/128 byte
+ * chunks are copied and a3 to the dst pointer after all the 64/128 byte
+ * chunks have been copied. We will loop, incrementing a0 and a1 until a0
+ * equals a3.
+ */
+
+L(ua_chk16w):
+ andi t8,a2,NSIZEDMASK /* any whole 64-byte/128-byte chunks? */
+ beq a2,t8,L(ua_chkw) /* if a2==t8, no 64-byte/128-byte chunks */
+ PTR_SUBU a3,a2,t8 /* subtract from a2 the reminder */
+ PTR_ADDU a3,a0,a3 /* Now a3 is the final dst after loop */
+
+# if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ PTR_ADDU t0,a0,a2 /* t0 is the "past the end" address */
+ PTR_SUBU t9,t0,PREFETCH_LIMIT /* t9 is the "last safe pref" address */
+# endif
+ PREFETCH_FOR_LOAD (0, a1)
+ PREFETCH_FOR_LOAD (1, a1)
+ PREFETCH_FOR_LOAD (2, a1)
+# if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE)
+ PREFETCH_FOR_STORE (1, a0)
+ PREFETCH_FOR_STORE (2, a0)
+ PREFETCH_FOR_STORE (3, a0)
+# endif
+# if defined(RETURN_FIRST_PREFETCH) && defined(USE_PREFETCH)
+# if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ sltu v1,t9,a0
+ bgtz v1,L(ua_skip_set)
+ nop
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*4)
+L(ua_skip_set):
+# else
+ PTR_ADDIU v0,a0,(PREFETCH_CHUNK*1)
+# endif
+# endif
+L(ua_loop16w):
+ PREFETCH_FOR_LOAD (3, a1)
+ C_LDHI t0,UNIT(0)(a1)
+ C_LDHI t1,UNIT(1)(a1)
+ C_LDHI REG2,UNIT(2)(a1)
+# if defined(USE_PREFETCH) && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ sltu v1,t9,a0
+ bgtz v1,L(ua_skip_pref)
+# endif
+ C_LDHI REG3,UNIT(3)(a1)
+ PREFETCH_FOR_STORE (4, a0)
+ PREFETCH_FOR_STORE (5, a0)
+L(ua_skip_pref):
+ C_LDHI REG4,UNIT(4)(a1)
+ C_LDHI REG5,UNIT(5)(a1)
+ C_LDHI REG6,UNIT(6)(a1)
+ C_LDHI REG7,UNIT(7)(a1)
+ C_LDLO t0,UNITM1(1)(a1)
+ C_LDLO t1,UNITM1(2)(a1)
+ C_LDLO REG2,UNITM1(3)(a1)
+ C_LDLO REG3,UNITM1(4)(a1)
+ C_LDLO REG4,UNITM1(5)(a1)
+ C_LDLO REG5,UNITM1(6)(a1)
+ C_LDLO REG6,UNITM1(7)(a1)
+ C_LDLO REG7,UNITM1(8)(a1)
+ PREFETCH_FOR_LOAD (4, a1)
+ C_ST t0,UNIT(0)(a0)
+ C_ST t1,UNIT(1)(a0)
+ C_ST REG2,UNIT(2)(a0)
+ C_ST REG3,UNIT(3)(a0)
+ C_ST REG4,UNIT(4)(a0)
+ C_ST REG5,UNIT(5)(a0)
+ C_ST REG6,UNIT(6)(a0)
+ C_ST REG7,UNIT(7)(a0)
+ C_LDHI t0,UNIT(8)(a1)
+ C_LDHI t1,UNIT(9)(a1)
+ C_LDHI REG2,UNIT(10)(a1)
+ C_LDHI REG3,UNIT(11)(a1)
+ C_LDHI REG4,UNIT(12)(a1)
+ C_LDHI REG5,UNIT(13)(a1)
+ C_LDHI REG6,UNIT(14)(a1)
+ C_LDHI REG7,UNIT(15)(a1)
+ C_LDLO t0,UNITM1(9)(a1)
+ C_LDLO t1,UNITM1(10)(a1)
+ C_LDLO REG2,UNITM1(11)(a1)
+ C_LDLO REG3,UNITM1(12)(a1)
+ C_LDLO REG4,UNITM1(13)(a1)
+ C_LDLO REG5,UNITM1(14)(a1)
+ C_LDLO REG6,UNITM1(15)(a1)
+ C_LDLO REG7,UNITM1(16)(a1)
+ PREFETCH_FOR_LOAD (5, a1)
+ C_ST t0,UNIT(8)(a0)
+ C_ST t1,UNIT(9)(a0)
+ C_ST REG2,UNIT(10)(a0)
+ C_ST REG3,UNIT(11)(a0)
+ C_ST REG4,UNIT(12)(a0)
+ C_ST REG5,UNIT(13)(a0)
+ C_ST REG6,UNIT(14)(a0)
+ C_ST REG7,UNIT(15)(a0)
+ PTR_ADDIU a0,a0,UNIT(16) /* adding 64/128 to dest */
+ bne a0,a3,L(ua_loop16w)
+ PTR_ADDIU a1,a1,UNIT(16) /* adding 64/128 to src */
+ move a2,t8
+
+/* Here we have src and dest word-aligned but less than 64-bytes or
+ * 128 bytes to go. Check for a 32(64) byte chunk and copy if if there
+ * is one. Otherwise jump down to L(ua_chk1w) to handle the tail end of
+ * the copy. */
+
+L(ua_chkw):
+ PREFETCH_FOR_LOAD (0, a1)
+ andi t8,a2,NSIZEMASK /* Is there a 32-byte/64-byte chunk. */
+ /* t8 is the reminder count past 32-bytes */
+ beq a2,t8,L(ua_chk1w) /* When a2=t8, no 32-byte chunk */
+ nop
+ C_LDHI t0,UNIT(0)(a1)
+ C_LDHI t1,UNIT(1)(a1)
+ C_LDHI REG2,UNIT(2)(a1)
+ C_LDHI REG3,UNIT(3)(a1)
+ C_LDHI REG4,UNIT(4)(a1)
+ C_LDHI REG5,UNIT(5)(a1)
+ C_LDHI REG6,UNIT(6)(a1)
+ C_LDHI REG7,UNIT(7)(a1)
+ C_LDLO t0,UNITM1(1)(a1)
+ C_LDLO t1,UNITM1(2)(a1)
+ C_LDLO REG2,UNITM1(3)(a1)
+ C_LDLO REG3,UNITM1(4)(a1)
+ C_LDLO REG4,UNITM1(5)(a1)
+ C_LDLO REG5,UNITM1(6)(a1)
+ C_LDLO REG6,UNITM1(7)(a1)
+ C_LDLO REG7,UNITM1(8)(a1)
+ PTR_ADDIU a1,a1,UNIT(8)
+ C_ST t0,UNIT(0)(a0)
+ C_ST t1,UNIT(1)(a0)
+ C_ST REG2,UNIT(2)(a0)
+ C_ST REG3,UNIT(3)(a0)
+ C_ST REG4,UNIT(4)(a0)
+ C_ST REG5,UNIT(5)(a0)
+ C_ST REG6,UNIT(6)(a0)
+ C_ST REG7,UNIT(7)(a0)
+ PTR_ADDIU a0,a0,UNIT(8)
+/*
+ * Here we have less than 32(64) bytes to copy. Set up for a loop to
+ * copy one word (or double word) at a time.
+ */
+L(ua_chk1w):
+ andi a2,t8,(NSIZE-1) /* a2 is the reminder past one (d)word chunks */
+ beq a2,t8,L(ua_smallCopy)
+ PTR_SUBU a3,t8,a2 /* a3 is count of bytes in one (d)word chunks */
+ PTR_ADDU a3,a0,a3 /* a3 is the dst address after loop */
+
+/* copying in words (4-byte or 8-byte chunks) */
+L(ua_wordCopy_loop):
+ C_LDHI v1,UNIT(0)(a1)
+ C_LDLO v1,UNITM1(1)(a1)
+ PTR_ADDIU a0,a0,UNIT(1)
+ PTR_ADDIU a1,a1,UNIT(1)
+ bne a0,a3,L(ua_wordCopy_loop)
+ C_ST v1,UNIT(-1)(a0)
+
+/* Copy the last 8 (or 16) bytes */
+L(ua_smallCopy):
+ beqz a2,L(leave)
+ PTR_ADDU a3,a0,a2 /* a3 is the last dst address */
+L(ua_smallCopy_loop):
+ lb v1,0(a1)
+ PTR_ADDIU a0,a0,1
+ PTR_ADDIU a1,a1,1
+ bne a0,a3,L(ua_smallCopy_loop)
+ sb v1,-1(a0)
+
+ j ra
+ nop
+
+#else /* R6_CODE */
+
+# ifdef __MIPSEB
+# define SWAP_REGS(X,Y) X, Y
+# define ALIGN_OFFSET(N) (N)
+# else
+# define SWAP_REGS(X,Y) Y, X
+# define ALIGN_OFFSET(N) (NSIZE-N)
+# endif
+# define R6_UNALIGNED_WORD_COPY(BYTEOFFSET) \
+ andi REG7, a2, (NSIZE-1);/* REG7 is # of bytes to by bytes. */ \
+ beq REG7, a2, L(lastb); /* Check for bytes to copy by word */ \
+ PTR_SUBU a3, a2, REG7; /* a3 is number of bytes to be copied in */ \
+ /* (d)word chunks. */ \
+ move a2, REG7; /* a2 is # of bytes to copy byte by byte */ \
+ /* after word loop is finished. */ \
+ PTR_ADDU REG6, a0, a3; /* REG6 is the dst address after loop. */ \
+ PTR_SUBU REG2, a1, t8; /* REG2 is the aligned src address. */ \
+ PTR_ADDU a1, a1, a3; /* a1 is addr of source after word loop. */ \
+ C_LD t0, UNIT(0)(REG2); /* Load first part of source. */ \
+L(r6_ua_wordcopy##BYTEOFFSET): \
+ C_LD t1, UNIT(1)(REG2); /* Load second part of source. */ \
+ C_ALIGN REG3, SWAP_REGS(t1,t0), ALIGN_OFFSET(BYTEOFFSET); \
+ PTR_ADDIU a0, a0, UNIT(1); /* Increment destination pointer. */ \
+ PTR_ADDIU REG2, REG2, UNIT(1); /* Increment aligned source pointer.*/ \
+ move t0, t1; /* Move second part of source to first. */ \
+ bne a0, REG6,L(r6_ua_wordcopy##BYTEOFFSET); \
+ C_ST REG3, UNIT(-1)(a0); \
+ j L(lastb); \
+ nop
+
+ /* We are generating R6 code, the destination is 4 byte aligned and
+ the source is not 4 byte aligned. t8 is 1, 2, or 3 depending on the
+ alignment of the source. */
+
+L(r6_unaligned1):
+ R6_UNALIGNED_WORD_COPY(1)
+L(r6_unaligned2):
+ R6_UNALIGNED_WORD_COPY(2)
+L(r6_unaligned3):
+ R6_UNALIGNED_WORD_COPY(3)
+# ifdef USE_DOUBLE
+L(r6_unaligned4):
+ R6_UNALIGNED_WORD_COPY(4)
+L(r6_unaligned5):
+ R6_UNALIGNED_WORD_COPY(5)
+L(r6_unaligned6):
+ R6_UNALIGNED_WORD_COPY(6)
+L(r6_unaligned7):
+ R6_UNALIGNED_WORD_COPY(7)
+# endif
+#endif /* R6_CODE */
+
+ .set at
+ .set reorder
+END(MEMCPY_NAME)
+#ifndef ANDROID_CHANGES
+# ifdef _LIBC
+# ifdef __UCLIBC__
+libc_hidden_def(MEMCPY_NAME)
+# else
+libc_hidden_builtin_def (MEMCPY_NAME)
+# endif
+# endif
+#endif
diff --git a/libc/string/mips/memset.S b/libc/string/mips/memset.S
index 26b2598..ef8ab0b 100644
--- a/libc/string/mips/memset.S
+++ b/libc/string/mips/memset.S
@@ -1,6 +1,5 @@
-/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 2013-2015 Free Software Foundation, Inc.
This file is part of the GNU C Library.
- Contributed by Hartvig Ekner <hartvige(a)mips.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -13,145 +12,420 @@
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
+ License along with the GNU C Library. If not, see
<http://www.gnu.org/licenses/>. */
-#include <features.h>
-#include <sysdep.h>
-#include <endian.h>
+#ifdef ANDROID_CHANGES
+# include "machine/asm.h"
+# include "machine/regdef.h"
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#elif _LIBC
+# include <sysdep.h>
+# include <regdef.h>
+# include <sys/asm.h>
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#elif defined _COMPILING_NEWLIB
+# include "machine/asm.h"
+# include "machine/regdef.h"
+# define PREFETCH_STORE_HINT PREFETCH_HINT_PREPAREFORSTORE
+#else
+# include <regdef.h>
+# include <sys/asm.h>
+#endif
+
+/* Check to see if the MIPS architecture we are compiling for supports
+ prefetching. */
+
+#if (__mips == 4) || (__mips == 5) || (__mips == 32) || (__mips == 64)
+# ifndef DISABLE_PREFETCH
+# define USE_PREFETCH
+# endif
+#endif
+
+#if defined(_MIPS_SIM) && ((_MIPS_SIM == _ABI64) || (_MIPS_SIM == _ABIN32))
+# ifndef DISABLE_DOUBLE
+# define USE_DOUBLE
+# endif
+#endif
+
+#ifndef USE_DOUBLE
+# ifndef DISABLE_DOUBLE_ALIGN
+# define DOUBLE_ALIGN
+# endif
+#endif
+
+
+/* Some asm.h files do not have the L macro definition. */
+#ifndef L
+# if _MIPS_SIM == _ABIO32
+# define L(label) $L ## label
+# else
+# define L(label) .L ## label
+# endif
+#endif
+
+/* Some asm.h files do not have the PTR_ADDIU macro definition. */
+#ifndef PTR_ADDIU
+# ifdef USE_DOUBLE
+# define PTR_ADDIU daddiu
+# else
+# define PTR_ADDIU addiu
+# endif
+#endif
-/* void *memset(void *s, int c, size_t n). */
+/* New R6 instructions that may not be in asm.h. */
+#ifndef PTR_LSA
+# if _MIPS_SIM == _ABI64
+# define PTR_LSA dlsa
+# else
+# define PTR_LSA lsa
+# endif
+#endif
+
+/* Using PREFETCH_HINT_PREPAREFORSTORE instead of PREFETCH_STORE
+ or PREFETCH_STORE_STREAMED offers a large performance advantage
+ but PREPAREFORSTORE has some special restrictions to consider.
+
+ Prefetch with the 'prepare for store' hint does not copy a memory
+ location into the cache, it just allocates a cache line and zeros
+ it out. This means that if you do not write to the entire cache
+ line before writing it out to memory some data will get zero'ed out
+ when the cache line is written back to memory and data will be lost.
+
+ There are ifdef'ed sections of this memcpy to make sure that it does not
+ do prefetches on cache lines that are not going to be completely written.
+ This code is only needed and only used when PREFETCH_STORE_HINT is set to
+ PREFETCH_HINT_PREPAREFORSTORE. This code assumes that cache lines are
+ less than MAX_PREFETCH_SIZE bytes and if the cache line is larger it will
+ not work correctly. */
+
+#ifdef USE_PREFETCH
+# define PREFETCH_HINT_STORE 1
+# define PREFETCH_HINT_STORE_STREAMED 5
+# define PREFETCH_HINT_STORE_RETAINED 7
+# define PREFETCH_HINT_PREPAREFORSTORE 30
+
+/* If we have not picked out what hints to use at this point use the
+ standard load and store prefetch hints. */
+# ifndef PREFETCH_STORE_HINT
+# define PREFETCH_STORE_HINT PREFETCH_HINT_STORE
+# endif
+
+/* We double everything when USE_DOUBLE is true so we do 2 prefetches to
+ get 64 bytes in that case. The assumption is that each individual
+ prefetch brings in 32 bytes. */
+# ifdef USE_DOUBLE
+# define PREFETCH_CHUNK 64
+# define PREFETCH_FOR_STORE(chunk, reg) \
+ pref PREFETCH_STORE_HINT, (chunk)*64(reg); \
+ pref PREFETCH_STORE_HINT, ((chunk)*64)+32(reg)
+# else
+# define PREFETCH_CHUNK 32
+# define PREFETCH_FOR_STORE(chunk, reg) \
+ pref PREFETCH_STORE_HINT, (chunk)*32(reg)
+# endif
-#ifdef __mips64
+/* MAX_PREFETCH_SIZE is the maximum size of a prefetch, it must not be less
+ than PREFETCH_CHUNK, the assumed size of each prefetch. If the real size
+ of a prefetch is greater than MAX_PREFETCH_SIZE and the PREPAREFORSTORE
+ hint is used, the code will not work correctly. If PREPAREFORSTORE is not
+ used than MAX_PREFETCH_SIZE does not matter. */
+# define MAX_PREFETCH_SIZE 128
+/* PREFETCH_LIMIT is set based on the fact that we never use an offset greater
+ than 5 on a STORE prefetch and that a single prefetch can never be larger
+ than MAX_PREFETCH_SIZE. We add the extra 32 when USE_DOUBLE is set because
+ we actually do two prefetches in that case, one 32 bytes after the other. */
+# ifdef USE_DOUBLE
+# define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + 32 + MAX_PREFETCH_SIZE
+# else
+# define PREFETCH_LIMIT (5 * PREFETCH_CHUNK) + MAX_PREFETCH_SIZE
+# endif
-#include <sys/asm.h>
+# if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE) \
+ && ((PREFETCH_CHUNK * 4) < MAX_PREFETCH_SIZE)
+/* We cannot handle this because the initial prefetches may fetch bytes that
+ are before the buffer being copied. We start copies with an offset
+ of 4 so avoid this situation when using PREPAREFORSTORE. */
+# error "PREFETCH_CHUNK is too large and/or MAX_PREFETCH_SIZE is too small."
+# endif
+#else /* USE_PREFETCH not defined */
+# define PREFETCH_FOR_STORE(offset, reg)
+#endif
+
+#if __mips_isa_rev > 5
+# if (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+# undef PREFETCH_STORE_HINT
+# define PREFETCH_STORE_HINT PREFETCH_HINT_STORE_STREAMED
+# endif
+# define R6_CODE
+#endif
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define SDHI sdl /* high part is left in big-endian */
+/* Allow the routine to be named something else if desired. */
+#ifndef MEMSET_NAME
+# define MEMSET_NAME memset
+#endif
+
+/* We load/store 64 bits at a time when USE_DOUBLE is true.
+ The C_ prefix stands for CHUNK and is used to avoid macro name
+ conflicts with system header files. */
+
+#ifdef USE_DOUBLE
+# define C_ST sd
+# ifdef __MIPSEB
+# define C_STHI sdl /* high part is left in big-endian */
+# else
+# define C_STHI sdr /* high part is right in little-endian */
+# endif
#else
-# define SDHI sdr /* high part is right in little-endian */
+# define C_ST sw
+# ifdef __MIPSEB
+# define C_STHI swl /* high part is left in big-endian */
+# else
+# define C_STHI swr /* high part is right in little-endian */
+# endif
#endif
-ENTRY (memset)
- .set noreorder
+/* Bookkeeping values for 32 vs. 64 bit mode. */
+#ifdef USE_DOUBLE
+# define NSIZE 8
+# define NSIZEMASK 0x3f
+# define NSIZEDMASK 0x7f
+#else
+# define NSIZE 4
+# define NSIZEMASK 0x1f
+# define NSIZEDMASK 0x3f
+#endif
+#define UNIT(unit) ((unit)*NSIZE)
+#define UNITM1(unit) (((unit)*NSIZE)-1)
- slti ta1, a2, 16 # Less than 16?
- bne ta1, zero, L(last16)
- move v0, a0 # Setup exit value before too late
-
- beq a1, zero, L(ueven) # If zero pattern, no need to extend
- andi a1, 0xff # Avoid problems with bogus arguments
- dsll ta0, a1, 8
- or a1, ta0
- dsll ta0, a1, 16
- or a1, ta0 # a1 is now pattern in full word
- dsll ta0, a1, 32
- or a1, ta0 # a1 is now pattern in double word
-
-L(ueven):
- PTR_SUBU ta0, zero, a0 # Unaligned address?
- andi ta0, 0x7
- beq ta0, zero, L(chkw)
- PTR_SUBU a2, ta0
- SDHI a1, 0(a0) # Yes, handle first unaligned part
- PTR_ADDU a0, ta0 # Now both a0 and a2 are updated
+#ifdef ANDROID_CHANGES
+LEAF(MEMSET_NAME,0)
+#else
+LEAF(MEMSET_NAME)
+#endif
-L(chkw):
- andi ta0, a2, 0xf # Enough left for one loop iteration?
- beq ta0, a2, L(chkl)
- PTR_SUBU a3, a2, ta0
- PTR_ADDU a3, a0 # a3 is last loop address +1
- move a2, ta0 # a2 is now # of bytes left after loop
-L(loopw):
- PTR_ADDIU a0, 16 # Handle 2 dwords pr. iteration
- sd a1, -16(a0)
- bne a0, a3, L(loopw)
- sd a1, -8(a0)
-
-L(chkl):
- andi ta0, a2, 0x8 # Check if there is at least a double
- beq ta0, zero, L(last16) # word remaining after the loop
- PTR_SUBU a2, ta0
- sd a1, 0(a0) # Yes...
- PTR_ADDIU a0, 8
-
-L(last16):
- blez a2, L(exit) # Handle last 16 bytes (if cnt>0)
- PTR_ADDU a3, a2, a0 # a3 is last address +1
-L(lst16l):
- PTR_ADDIU a0, 1
- bne a0, a3, L(lst16l)
- sb a1, -1(a0)
-L(exit):
- j ra # Bye, bye
+ .set nomips16
+ .set noreorder
+/* If the size is less than 2*NSIZE (8 or 16), go to L(lastb). Regardless of
+ size, copy dst pointer to v0 for the return value. */
+ slti t2,a2,(2 * NSIZE)
+ bne t2,zero,L(lastb)
+ move v0,a0
+
+/* If memset value is not zero, we copy it to all the bytes in a 32 or 64
+ bit word. */
+ beq a1,zero,L(set0) /* If memset value is zero no smear */
+ PTR_SUBU a3,zero,a0
nop
- .set reorder
-END (memset)
+ /* smear byte into 32 or 64 bit word */
+#if ((__mips == 64) || (__mips == 32)) && (__mips_isa_rev >= 2)
+# ifdef USE_DOUBLE
+ dins a1, a1, 8, 8 /* Replicate fill byte into half-word. */
+ dins a1, a1, 16, 16 /* Replicate fill byte into word. */
+ dins a1, a1, 32, 32 /* Replicate fill byte into dbl word. */
+# else
+ ins a1, a1, 8, 8 /* Replicate fill byte into half-word. */
+ ins a1, a1, 16, 16 /* Replicate fill byte into word. */
+# endif
+#else
+# ifdef USE_DOUBLE
+ and a1,0xff
+ dsll t2,a1,8
+ or a1,t2
+ dsll t2,a1,16
+ or a1,t2
+ dsll t2,a1,32
+ or a1,t2
+# else
+ and a1,0xff
+ sll t2,a1,8
+ or a1,t2
+ sll t2,a1,16
+ or a1,t2
+# endif
+#endif
+
+/* If the destination address is not aligned do a partial store to get it
+ aligned. If it is already aligned just jump to L(aligned). */
+L(set0):
+#ifndef R6_CODE
+ andi t2,a3,(NSIZE-1) /* word-unaligned address? */
+ beq t2,zero,L(aligned) /* t2 is the unalignment count */
+ PTR_SUBU a2,a2,t2
+ C_STHI a1,0(a0)
+ PTR_ADDU a0,a0,t2
+#else /* R6_CODE */
+ andi t2,a0,(NSIZE-1)
+ lapc t9,L(atable)
+ PTR_LSA t9,t2,t9,2
+ jrc t9
+L(atable):
+ bc L(aligned)
+# ifdef USE_DOUBLE
+ bc L(lb7)
+ bc L(lb6)
+ bc L(lb5)
+ bc L(lb4)
+# endif
+ bc L(lb3)
+ bc L(lb2)
+ bc L(lb1)
+L(lb7):
+ sb a1,6(a0)
+L(lb6):
+ sb a1,5(a0)
+L(lb5):
+ sb a1,4(a0)
+L(lb4):
+ sb a1,3(a0)
+L(lb3):
+ sb a1,2(a0)
+L(lb2):
+ sb a1,1(a0)
+L(lb1):
+ sb a1,0(a0)
+
+ li t9,NSIZE
+ subu t2,t9,t2
+ PTR_SUBU a2,a2,t2
+ PTR_ADDU a0,a0,t2
+#endif /* R6_CODE */
+
+L(aligned):
+/* If USE_DOUBLE is not set we may still want to align the data on a 16
+ byte boundry instead of an 8 byte boundry to maximize the opportunity
+ of proAptiv chips to do memory bonding (combining two sequential 4
+ byte stores into one 8 byte store). We know there are at least 4 bytes
+ left to store or we would have jumped to L(lastb) earlier in the code. */
+#ifdef DOUBLE_ALIGN
+ andi t2,a3,4
+ beq t2,zero,L(double_aligned)
+ PTR_SUBU a2,a2,t2
+ sw a1,0(a0)
+ PTR_ADDU a0,a0,t2
+L(double_aligned):
+#endif
-#else /* !__mips64 */
+/* Now the destination is aligned to (word or double word) aligned address
+ Set a2 to count how many bytes we have to copy after all the 64/128 byte
+ chunks are copied and a3 to the dest pointer after all the 64/128 byte
+ chunks have been copied. We will loop, incrementing a0 until it equals
+ a3. */
+ andi t8,a2,NSIZEDMASK /* any whole 64-byte/128-byte chunks? */
+ beq a2,t8,L(chkw) /* if a2==t8, no 64-byte/128-byte chunks */
+ PTR_SUBU a3,a2,t8 /* subtract from a2 the reminder */
+ PTR_ADDU a3,a0,a3 /* Now a3 is the final dst after loop */
-#if __BYTE_ORDER == __BIG_ENDIAN
-# define SWHI swl /* high part is left in big-endian */
+/* When in the loop we may prefetch with the 'prepare to store' hint,
+ in this case the a0+x should not be past the "t0-32" address. This
+ means: for x=128 the last "safe" a0 address is "t0-160". Alternatively,
+ for x=64 the last "safe" a0 address is "t0-96" In the current version we
+ will use "prefetch hint,128(a0)", so "t0-160" is the limit. */
+#if defined(USE_PREFETCH) \
+ && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ PTR_ADDU t0,a0,a2 /* t0 is the "past the end" address */
+ PTR_SUBU t9,t0,PREFETCH_LIMIT /* t9 is the "last safe pref" address */
+#endif
+#if defined(USE_PREFETCH) \
+ && (PREFETCH_STORE_HINT != PREFETCH_HINT_PREPAREFORSTORE)
+ PREFETCH_FOR_STORE (1, a0)
+ PREFETCH_FOR_STORE (2, a0)
+ PREFETCH_FOR_STORE (3, a0)
+#endif
+
+L(loop16w):
+#if defined(USE_PREFETCH) \
+ && (PREFETCH_STORE_HINT == PREFETCH_HINT_PREPAREFORSTORE)
+ sltu v1,t9,a0 /* If a0 > t9 don't use next prefetch */
+ bgtz v1,L(skip_pref)
+ nop
+#endif
+#ifdef R6_CODE
+ PREFETCH_FOR_STORE (2, a0)
#else
-# define SWHI swr /* high part is right in little-endian */
+ PREFETCH_FOR_STORE (4, a0)
+ PREFETCH_FOR_STORE (5, a0)
#endif
+L(skip_pref):
+ C_ST a1,UNIT(0)(a0)
+ C_ST a1,UNIT(1)(a0)
+ C_ST a1,UNIT(2)(a0)
+ C_ST a1,UNIT(3)(a0)
+ C_ST a1,UNIT(4)(a0)
+ C_ST a1,UNIT(5)(a0)
+ C_ST a1,UNIT(6)(a0)
+ C_ST a1,UNIT(7)(a0)
+ C_ST a1,UNIT(8)(a0)
+ C_ST a1,UNIT(9)(a0)
+ C_ST a1,UNIT(10)(a0)
+ C_ST a1,UNIT(11)(a0)
+ C_ST a1,UNIT(12)(a0)
+ C_ST a1,UNIT(13)(a0)
+ C_ST a1,UNIT(14)(a0)
+ C_ST a1,UNIT(15)(a0)
+ PTR_ADDIU a0,a0,UNIT(16) /* adding 64/128 to dest */
+ bne a0,a3,L(loop16w)
+ nop
+ move a2,t8
-ENTRY (memset)
- .set noreorder
+/* Here we have dest word-aligned but less than 64-bytes or 128 bytes to go.
+ Check for a 32(64) byte chunk and copy if if there is one. Otherwise
+ jump down to L(chk1w) to handle the tail end of the copy. */
+L(chkw):
+ andi t8,a2,NSIZEMASK /* is there a 32-byte/64-byte chunk. */
+ /* the t8 is the reminder count past 32-bytes */
+ beq a2,t8,L(chk1w)/* when a2==t8, no 32-byte chunk */
+ nop
+ C_ST a1,UNIT(0)(a0)
+ C_ST a1,UNIT(1)(a0)
+ C_ST a1,UNIT(2)(a0)
+ C_ST a1,UNIT(3)(a0)
+ C_ST a1,UNIT(4)(a0)
+ C_ST a1,UNIT(5)(a0)
+ C_ST a1,UNIT(6)(a0)
+ C_ST a1,UNIT(7)(a0)
+ PTR_ADDIU a0,a0,UNIT(8)
+
+/* Here we have less than 32(64) bytes to set. Set up for a loop to
+ copy one word (or double word) at a time. Set a2 to count how many
+ bytes we have to copy after all the word (or double word) chunks are
+ copied and a3 to the dest pointer after all the (d)word chunks have
+ been copied. We will loop, incrementing a0 until a0 equals a3. */
+L(chk1w):
+ andi a2,t8,(NSIZE-1) /* a2 is the reminder past one (d)word chunks */
+ beq a2,t8,L(lastb)
+ PTR_SUBU a3,t8,a2 /* a3 is count of bytes in one (d)word chunks */
+ PTR_ADDU a3,a0,a3 /* a3 is the dst address after loop */
- slti t1, a2, 8 # Less than 8?
- bne t1, zero, L(last8)
- move v0, a0 # Setup exit value before too late
-
- beq a1, zero, L(ueven) # If zero pattern, no need to extend
- andi a1, 0xff # Avoid problems with bogus arguments
- sll t0, a1, 8
- or a1, t0
- sll t0, a1, 16
- or a1, t0 # a1 is now pattern in full word
-
-L(ueven):
- subu t0, zero, a0 # Unaligned address?
- andi t0, 0x3
- beq t0, zero, L(chkw)
- subu a2, t0
- SWHI a1, 0(a0) # Yes, handle first unaligned part
- addu a0, t0 # Now both a0 and a2 are updated
-
-L(chkw):
- andi t0, a2, 0x7 # Enough left for one loop iteration?
- beq t0, a2, L(chkl)
- subu a3, a2, t0
- addu a3, a0 # a3 is last loop address +1
- move a2, t0 # a2 is now # of bytes left after loop
-L(loopw):
- addiu a0, 8 # Handle 2 words pr. iteration
- sw a1, -8(a0)
- bne a0, a3, L(loopw)
- sw a1, -4(a0)
-
-L(chkl):
- andi t0, a2, 0x4 # Check if there is at least a full
- beq t0, zero, L(last8) # word remaining after the loop
- subu a2, t0
- sw a1, 0(a0) # Yes...
- addiu a0, 4
-
-L(last8):
- blez a2, L(exit) # Handle last 8 bytes (if cnt>0)
- addu a3, a2, a0 # a3 is last address +1
-L(lst8l):
- addiu a0, 1
- bne a0, a3, L(lst8l)
- sb a1, -1(a0)
-L(exit):
- j ra # Bye, bye
+/* copying in words (4-byte or 8 byte chunks) */
+L(wordCopy_loop):
+ PTR_ADDIU a0,a0,UNIT(1)
+ bne a0,a3,L(wordCopy_loop)
+ C_ST a1,UNIT(-1)(a0)
+
+/* Copy the last 8 (or 16) bytes */
+L(lastb):
+ blez a2,L(leave)
+ PTR_ADDU a3,a0,a2 /* a3 is the last dst address */
+L(lastbloop):
+ PTR_ADDIU a0,a0,1
+ bne a0,a3,L(lastbloop)
+ sb a1,-1(a0)
+L(leave):
+ j ra
nop
+ .set at
.set reorder
-END (memset)
-
-#endif /* !__mips64 */
+END(MEMSET_NAME)
+#ifndef ANDROID_CHANGES
+# ifdef _LIBC
+# ifdef __UCLIBC__
+libc_hidden_def(MEMSET_NAME)
+# else
+libc_hidden_builtin_def (MEMSET_NAME)
+# endif
+# endif
+#endif
-libc_hidden_def(memset)
diff --git a/libc/sysdeps/linux/common/bits/in.h b/libc/sysdeps/linux/common/bits/in.h
index f4a340b..c67fbf8 100644
--- a/libc/sysdeps/linux/common/bits/in.h
+++ b/libc/sysdeps/linux/common/bits/in.h
@@ -120,7 +120,7 @@ struct in_pktinfo
};
#endif
-#ifdef __UCLIBC_HAS_IPV6__
+#if defined __UCLIBC_HAS_IPV6__ || !defined __UCLIBC_STRICT_HEADERS__
/* Options for use with `getsockopt' and `setsockopt' at the IPv6 level.
The first word in the comment at the right is the data type used;
"bool" means a boolean value stored in an `int'. */
diff --git a/libc/sysdeps/linux/common/pselect.c b/libc/sysdeps/linux/common/pselect.c
index bf19ce3..3f1dd28 100644
--- a/libc/sysdeps/linux/common/pselect.c
+++ b/libc/sysdeps/linux/common/pselect.c
@@ -30,6 +30,57 @@ static int __NC(pselect)(int nfds, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, const struct timespec *timeout,
const sigset_t *sigmask)
{
+#ifdef __NR_pselect6
+#define NSEC_PER_SEC 1000000000L
+ struct timespec _ts, *ts = 0;
+ if (timeout) {
+ /* The Linux kernel can in some situations update the timeout value.
+ * We do not want that so use a local variable.
+ */
+ _ts = *timeout;
+
+ /* GNU extension: allow for timespec values where the sub-sec
+ * field is equal to or more than 1 second. The kernel will
+ * reject this on us, so take care of the time shift ourself.
+ * Some applications (like readline and linphone) do this.
+ * See 'clarification on select() type calls and invalid timeouts'
+ * on the POSIX general list for more information.
+ */
+ if (_ts.tv_nsec >= NSEC_PER_SEC) {
+ _ts.tv_sec += _ts.tv_nsec / NSEC_PER_SEC;
+ _ts.tv_nsec %= NSEC_PER_SEC;
+ }
+
+ ts = &_ts;
+ }
+
+ /* The pselect6 syscall API is strange. It wants a 7th arg to be
+ * the sizeof(*sigmask). However syscalls with > 6 arguments aren't
+ * supported on linux. So arguments 6 and 7 are stuffed in a struct
+ * and a pointer to that struct is passed as the 6th argument to
+ * the syscall.
+ * Glibc stuffs arguments 6 and 7 in a ulong[2]. Linux reads
+ * them as if there were a struct { sigset_t*; size_t } in
+ * userspace. There woudl be trouble if userspace and the kernel are
+ * compiled differently enough that size_t isn't the same as ulong,
+ * but not enough to trigger the compat layer in linux. I can't
+ * think of such a case, so I'm using linux's struct.
+ * Furthermore Glibc sets the sigsetsize to _NSIG/8. However linux
+ * checks for sizeof(sigset_t), which internally is a ulong array.
+ * This means that if _NSIG isn't a multiple of BITS_PER_LONG then
+ * linux will refuse glibc's value. So I prefer sizeof(sigset_t) for
+ * the value of sigsetsize.
+ */
+ struct {
+ const sigset_t *sigmask;
+ size_t sigsetsize;
+ } args67 = {
+ sigmask,
+ sizeof(sigset_t),
+ };
+
+ return INLINE_SYSCALL(pselect6, 6, nfds, readfds, writefds, exceptfds, ts, &args67);
+#else
struct timeval tval;
int retval;
sigset_t savemask;
@@ -57,6 +108,7 @@ static int __NC(pselect)(int nfds, fd_set *readfds, fd_set *writefds,
sigprocmask (SIG_SETMASK, &savemask, NULL);
return retval;
+#endif
}
CANCELLABLE_SYSCALL(int, pselect, (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
const struct timespec *timeout, const sigset_t *sigmask),
diff --git a/libpthread/nptl/init.c b/libpthread/nptl/init.c
index bcd49ed..776bec7 100644
--- a/libpthread/nptl/init.c
+++ b/libpthread/nptl/init.c
@@ -382,6 +382,10 @@ __pthread_initialize_minimal_internal (void)
Use the minimal size acceptable. */
limit.rlim_cur = PTHREAD_STACK_MIN;
+ /* Do not exceed architecture specific default */
+ if (limit.rlim_cur > ARCH_STACK_DEFAULT_SIZE)
+ limit.rlim_cur = ARCH_STACK_DEFAULT_SIZE;
+
/* Make sure it meets the minimum size that allocate_stack
(allocatestack.c) will demand, which depends on the page size. */
const uintptr_t pagesz = sysconf (_SC_PAGESIZE);
hooks/post-receive
--
uClibc-ng - small C library for embedded systems
1
0
Hi,
Assorted fixes for ARC, please consider applying.
Thx,
-Vineet
Vineet Gupta (3):
NPTL/ARCv2: Implement full memory barrier for NPTL
NPTL/ARC: fix __lll_lock_wait_private redefinition for static links
ARC: With NPTL support, GP is no longer used for PIC
ldso/ldso/arc/dl-sysdep.h | 6 ------
libc/sysdeps/linux/arc/bits/atomic.h | 7 +++++--
libpthread/nptl/sysdeps/unix/sysv/linux/arc/lowlevellock.c | 4 +++-
3 files changed, 8 insertions(+), 9 deletions(-)
--
1.9.1
3
6
uClibc-ng - small C library for embedded systems branch master updated. 6c718953a5d42a1a815af39f276aa0fa47e75e4b
by wbx@helium.waldemar-brodkorb.de 17 Dec '15
by wbx@helium.waldemar-brodkorb.de 17 Dec '15
17 Dec '15
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "uClibc-ng - small C library for embedded systems".
The branch, master has been updated
via 6c718953a5d42a1a815af39f276aa0fa47e75e4b (commit)
via 5caa0427cfcd53d9f479b5fe44b0fdfa16bb4e25 (commit)
via cd71b2f504b412d30bf39a34986b7ff0d80e51ef (commit)
via f5f83a9fa86a9d59300854077a8b127ad6622ebe (commit)
via 5ec4477584b69fe5f1410649b2eb3a63835fb649 (commit)
via 73e297159f20f73ee7bfb47cec8d74c20b010c2c (commit)
via 4b44f69a3592aaa3d7269a96990e006872edf6e1 (commit)
via b59b369dd19e8dedbcf43a3dce5559c2caf6152a (commit)
via 21c68223055e21a34802d348b9f9dd6e3f2e310b (commit)
via ed8ee01706e52580964f27a47d0004339687dfaa (commit)
via b074a41efd0a77a1786b4e2f3c14a952de523eff (commit)
via 4961a766808ba042908bd1c571b7dfe8e9ebf6e6 (commit)
via 683b4d3c053abc28557b692907d9ea83e56ebb7f (commit)
via 5f64b05652e82cc41a216fb828b3d23073dd19cd (commit)
via 8fb6b2e8f69a536e6b1e7e52ba279b92b69556a7 (commit)
via 6fd4a1a04133213815fdb240a9d1c059d1a5de9f (commit)
via 8fb67ff51617206c7095735c03dc31a6cd3a7b96 (commit)
via 5a303de7d093673d39de4e45f687a43d4a174c28 (commit)
from a4b3f4863e5904fef296538fdf71e7e806bf77e9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 6c718953a5d42a1a815af39f276aa0fa47e75e4b
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Thu Dec 17 20:21:18 2015 +0100
reduce stack cache size to save memory space
Idea from different projects as OpenWrt and others.
https://lists.openwrt.org/pipermail/openwrt-devel/2013-November/022299.html
https://github.com/wl500g/toolchain/blob/master/toolchain/uClibc/patches/0.…
commit 5caa0427cfcd53d9f479b5fe44b0fdfa16bb4e25
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Thu Dec 17 07:59:05 2015 +0100
testsuite subdir fix
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit cd71b2f504b412d30bf39a34986b7ff0d80e51ef
Author: Khem Raj <raj.khem(a)gmail.com>
Date: Sat Oct 31 18:32:54 2015 +0000
Add implementation for copysignl for ppc
Signed-off-by: Khem Raj <raj.khem(a)gmail.com>
commit f5f83a9fa86a9d59300854077a8b127ad6622ebe
Author: Wojciech Nizinski <w.nizinski at grinn-global.com>
Date: Tue Oct 20 14:08:09 2015 +0200
libc/stdlib: canonicalize_file_name() memory leak
Uclibc's canonicalize_file_name() is allocating temprary buffer of 4kB
(PATH_MAX), and passing it to realpath() as second argument. Function is
not checking if realpath() fails and memory is lost.
commit 5ec4477584b69fe5f1410649b2eb3a63835fb649
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:52:24 2015 +0100
utlis/ldd: Fix host ldd in case of target wordsize differs from host one
improved solution from http://freetz.org/ticket/842
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 73e297159f20f73ee7bfb47cec8d74c20b010c2c
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:51:12 2015 +0100
test/tls: tls-macros*.h fixes from glibc
glibc commits
4822a2a520 Add x32 support to TLS_LE/TLS_IE/TLS_GD
63fb881a04 tls-macros-mips.h: Load $gp as required.
Merge 32-bit and 64-bit versions.
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 4b44f69a3592aaa3d7269a96990e006872edf6e1
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:49:06 2015 +0100
dlclose fix
Patch is from Timo Teras
Refs.:
http://lists.uclibc.org/pipermail/uclibc/2012-October/047059.html
http://git.alpinelinux.org/cgit/aports/tree/main/libc0.9.32/uclibc-dlclose-…
commit b59b369dd19e8dedbcf43a3dce5559c2caf6152a
Author: Vladislav Grishenko <themiron(a)mail.ru>
Date: Wed Sep 12 18:04:48 2012 +0600
Fix syslog messages lost if syslogd is temporary busy
Commit 4139fe5aec935ba3f462dcaf6aafb6e5eadf1ab9 fixes SIGSTOPed syslogd issue.
but introduced new one - messages will be lost when socket buffer gets full,
not only if syslogd is stalled, but even if it accepts message slower than
someone sends and possibly leads to security hole, when important messages get
lost as result of attacker flooding.
Patch adds 1 second waiting for socket buffer can accept the message, helps
when syslogd is working hard. If it's stalled/SIGSTOPed, message will be sent
to errout as before. After that, further non-blocking /dev/log connect attempts
will fail immediately with EAGAIN error until syslogd reads some from it.
function old new delta
openlog_intern 259 355 +96
static.tv - 8 +8
.rodata 151 159 +8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 112/0) Total: 112 bytes
Signed-off-by: Vladislav Grishenko <themiron(a)mail.ru>
commit 21c68223055e21a34802d348b9f9dd6e3f2e310b
Author: Vladislav Grishenko <themiron(a)mail.ru>
Date: Wed Sep 12 17:13:55 2012 +0600
Fix syslog messages lost after syslogd restarts
If syslogd is stopped and restarted while a process has the log open, the next
message that process produces will be logged to the console and not to the new
instance of syslogd. Further messages will be routed correctly, but not the
first one.
Based on original patch
Bug 3889 - syslog loses messages when syslogd restarted
https://bugs.busybox.net/show_bug.cgi?id=3889
function old new delta
openlog 33 68 +35
__vsyslog 851 848 -3
openlog_intern 318 259 -59
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 35/-62) Total: -27 bytes
Signed-off-by: Vladislav Grishenko <themiron(a)mail.ru>
commit ed8ee01706e52580964f27a47d0004339687dfaa
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:44:54 2015 +0100
resolv: NI_IDN unimplemented
Some programs trying to use NI_IDN flag in case of it defined in netdb.h,
so hide it to suppress bad values for ai_flags.
Inspired by OpenWRT issue #12323
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit b074a41efd0a77a1786b4e2f3c14a952de523eff
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:42:34 2015 +0100
resolv: __dns_lookup - immediately switch to next server in case of poll() set error events
https://bugs.busybox.net/show_bug.cgi?id=3211
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 4961a766808ba042908bd1c571b7dfe8e9ebf6e6
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:40:36 2015 +0100
dynamically allocate ahostbuf buffer
Free 1k of static data (.bss)
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 683b4d3c053abc28557b692907d9ea83e56ebb7f
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:38:30 2015 +0100
svc.c: svc_getreqset() buffer overflow
http://bugs.busybox.net/show_bug.cgi?id=5588
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 5f64b05652e82cc41a216fb828b3d23073dd19cd
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:36:46 2015 +0100
only strip test binaries when DOSTRIP is enabled
commit 8fb6b2e8f69a536e6b1e7e52ba279b92b69556a7
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Thu Dec 10 11:14:41 2015 +0100
test needs -fPIC for m68k
commit 6fd4a1a04133213815fdb240a9d1c059d1a5de9f
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Wed Dec 9 08:05:10 2015 +0100
libc/stdio: Rework custom streams interface similar to glibc.
Save 20 bytes per FILE structure, avoid indirect call for
read/write/seek/close operations for normal streams.
Additionally, custom streams has fileno = -2 now, like in glibc.
bloat-o-meter report (UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y):
function old new delta
fopencookie 69 131 +62
ftello64 233 260 +27
fseeko64 298 319 +21
fclose 423 442 +19
.rodata 16696 16708 +12
fileno_unlocked 53 45 -8
__ns_name_pack 859 851 -8
vswscanf 184 144 -40
vdprintf 231 187 -44
vsscanf 210 151 -59
vswprintf 269 201 -68
vsnprintf 249 181 -68
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/7 up/down: 141/-295) Total: -154 bytes
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 8fb67ff51617206c7095735c03dc31a6cd3a7b96
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Wed Dec 9 08:07:09 2015 +0100
fix readdir_r returns success code while it in fact failed
Taken from Freetz.org.
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 5a303de7d093673d39de4e45f687a43d4a174c28
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Thu Dec 10 11:04:57 2015 +0100
disable always failing tst-tls16, until someone unbreak it
-----------------------------------------------------------------------
Summary of changes:
include/netdb.h | 3 +-
ldso/libdl/libdl.c | 4 +-
libc/inet/resolv.c | 4 +
libc/inet/rpc/rexec.c | 9 ++-
libc/inet/rpc/svc.c | 2 +
libc/misc/dirent/readdir_r.c | 2 +-
libc/misc/syslog/syslog.c | 46 +++++++----
libc/stdio/_READ.c | 2 +-
libc/stdio/_WRITE.c | 2 +-
libc/stdio/_cs_funcs.c | 42 ----------
libc/stdio/_fopen.c | 2 -
libc/stdio/_rfill.c | 2 +-
libc/stdio/_scanf.c | 27 -------
libc/stdio/_stdio.c | 23 +-----
libc/stdio/_stdio.h | 102 ++++++++++++++-----------
libc/stdio/fclose.c | 2 -
libc/stdio/fopencookie.c | 29 +++++--
libc/stdio/fread.c | 2 +-
libc/stdio/vdprintf.c | 9 ---
libc/stdio/vsnprintf.c | 46 ++++-------
libc/stdio/vswprintf.c | 9 ---
libc/stdlib/canonicalize.c | 21 +----
libc/sysdeps/linux/common/bits/uClibc_stdio.h | 4 -
libc/sysdeps/linux/powerpc/Makefile.arch | 2 +-
libc/sysdeps/linux/powerpc/copysignl.c | 89 +++++++++++++++++++++
libpthread/nptl/allocatestack.c | 8 +-
test/Rules.mak | 4 +-
test/Test.mak | 4 +
test/stdio/Makefile.in | 6 ++
test/stdio/tst-fmemopen.c | 53 +++++++++++++
test/tls/Makefile.in | 4 +
test/tls/tls-macros-mips.h | 94 +++++++++--------------
test/tls/tls-macros.h | 16 ++--
utils/Makefile.in | 1 +
utils/ldd.c | 13 +++-
utils/porting.h | 10 +++
36 files changed, 379 insertions(+), 319 deletions(-)
create mode 100644 libc/sysdeps/linux/powerpc/copysignl.c
create mode 100644 test/stdio/tst-fmemopen.c
diff --git a/include/netdb.h b/include/netdb.h
index 7ce01c2..a636b5f 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -671,7 +671,8 @@ struct addrinfo
# define NI_NOFQDN 4 /* Only return nodename portion. */
# define NI_NAMEREQD 8 /* Don't return numeric addresses. */
# define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
-# ifdef __USE_GNU
+#if 0 /* uClibc: not implemented */
+/* # ifdef __USE_GNU */
# define NI_IDN 32 /* Convert name from IDN format. */
# define NI_IDN_ALLOW_UNASSIGNED 64 /* Don't reject unassigned Unicode
code points. */
diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c
index 388e3c7..2c4b064 100644
--- a/ldso/libdl/libdl.c
+++ b/ldso/libdl/libdl.c
@@ -964,8 +964,8 @@ static int do_dlclose(void *vhandle, int need_fini)
dtv_t *dtv = THREAD_DTV ();
- _dl_assert(!(dtv[tls_lmap->l_tls_modid].pointer.is_static));
- if (dtv[tls_lmap->l_tls_modid].pointer.val != TLS_DTV_UNALLOCATED) {
+ if (!(dtv[tls_lmap->l_tls_modid].pointer.is_static) &&
+ dtv[tls_lmap->l_tls_modid].pointer.val != TLS_DTV_UNALLOCATED) {
/* Note that free is called for NULL is well. We
deallocate even if it is this dtv entry we are
supposed to load. The reason is that we call
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index 724c311..bd2c6fc 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -1410,6 +1410,10 @@ int __dns_lookup(const char *name,
* to next nameserver */
goto try_next_server;
}
+ if (fds.revents & (POLLERR | POLLHUP | POLLNVAL)) {
+ DPRINTF("Bad event\n");
+ goto try_next_server;
+ }
/*TODO: better timeout accounting?*/
reply_timeout -= 1000;
#endif /* USE_SELECT */
diff --git a/libc/inet/rpc/rexec.c b/libc/inet/rpc/rexec.c
index 9f7cc80..e17be50 100644
--- a/libc/inet/rpc/rexec.c
+++ b/libc/inet/rpc/rexec.c
@@ -39,12 +39,13 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <malloc.h>
#define SA_LEN(_x) __libc_sa_len((_x)->sa_family)
extern int __libc_sa_len(sa_family_t __af) __THROW attribute_hidden;
/* int rexecoptions; - google does not know it */
-static char ahostbuf[NI_MAXHOST];
+static char *ahostbuf = NULL;
int
rexec_af(char **ahost, int rport, const char *name, const char *pass, const char *cmd, int *fd2p, sa_family_t af)
@@ -77,8 +78,10 @@ rexec_af(char **ahost, int rport, const char *name, const char *pass, const char
}
if (res0->ai_canonname) {
- strncpy(ahostbuf, res0->ai_canonname, sizeof(ahostbuf));
- ahostbuf[sizeof(ahostbuf)-1] = '\0';
+ if (!ahostbuf)
+ ahostbuf = __uc_malloc(NI_MAXHOST);
+ strncpy(ahostbuf, res0->ai_canonname, NI_MAXHOST);
+ ahostbuf[NI_MAXHOST-1] = '\0';
*ahost = ahostbuf;
}
else {
diff --git a/libc/inet/rpc/svc.c b/libc/inet/rpc/svc.c
index 6d7253a..c3d5518 100644
--- a/libc/inet/rpc/svc.c
+++ b/libc/inet/rpc/svc.c
@@ -448,6 +448,8 @@ svc_getreqset (fd_set *readfds)
register int bit;
setsize = _rpc_dtablesize ();
+ if (setsize > FD_SETSIZE)
+ setsize = FD_SETSIZE;
maskp = (u_int32_t *) readfds->fds_bits;
for (sock = 0; sock < setsize; sock += 32)
for (mask = *maskp++; (bit = ffs (mask)); mask ^= (1 << (bit - 1)))
diff --git a/libc/misc/dirent/readdir_r.c b/libc/misc/dirent/readdir_r.c
index 7cdc0ab..5beebfe 100644
--- a/libc/misc/dirent/readdir_r.c
+++ b/libc/misc/dirent/readdir_r.c
@@ -27,7 +27,6 @@ int __READDIR_R(DIR *dir, __DIRENT_TYPE *entry, __DIRENT_TYPE **result)
__set_errno(EBADF);
return(EBADF);
}
- de = NULL;
__UCLIBC_MUTEX_LOCK(dir->dd_lock);
@@ -36,6 +35,7 @@ int __READDIR_R(DIR *dir, __DIRENT_TYPE *entry, __DIRENT_TYPE **result)
/* read dir->dd_max bytes of directory entries. */
bytes = __GETDENTS(dir->dd_fd, dir->dd_buf, dir->dd_max);
if (bytes <= 0) {
+ de = NULL;
*result = NULL;
ret = (bytes==0)? 0 : errno;
goto all_done;
diff --git a/libc/misc/syslog/syslog.c b/libc/misc/syslog/syslog.c
index 1ab4707..1df0d1a 100644
--- a/libc/misc/syslog/syslog.c
+++ b/libc/misc/syslog/syslog.c
@@ -122,23 +122,16 @@ closelog_intern(int sig)
}
static void
-openlog_intern(const char *ident, int logstat, int logfac)
+openlog_intern(void)
{
int fd;
int logType = SOCK_DGRAM;
-
- if (ident != NULL)
- LogTag = ident;
- LogStat = logstat;
- /* (we were checking also for logfac != 0, but it breaks
- * openlog(xx, LOG_KERN) since LOG_KERN == 0) */
- if ((logfac & ~LOG_FACMASK) == 0) /* if we don't have invalid bits */
- LogFacility = (unsigned)logfac >> 3;
+ static const struct timeval tv = { 1, 0 };
fd = LogFile;
if (fd == -1) {
retry:
- if (logstat & LOG_NDELAY) {
+ if (1) { /* if statement left in to make .diff cleaner */
LogFile = fd = socket(AF_UNIX, logType, 0);
if (fd == -1) {
return;
@@ -151,6 +144,9 @@ openlog_intern(const char *ident, int logstat, int logfac)
if (fd != -1 && !connected) {
if (connect(fd, &SyslogAddr, sizeof(SyslogAddr)) != -1) {
+ /* We want to block send if e.g. syslogd is SIGSTOPed */
+ fcntl(fd, F_SETFL, ~O_NONBLOCK & fcntl(fd, F_GETFL));
+ setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
connected = 1;
} else {
if (fd != -1) {
@@ -172,7 +168,18 @@ void
openlog(const char *ident, int logstat, int logfac)
{
__UCLIBC_MUTEX_LOCK(mylock);
- openlog_intern(ident, logstat, logfac);
+
+ if (ident != NULL)
+ LogTag = ident;
+ LogStat = logstat;
+ /* (we were checking also for logfac != 0, but it breaks
+ * openlog(xx, LOG_KERN) since LOG_KERN == 0) */
+ if ((logfac & ~LOG_FACMASK) == 0) /* if we don't have invalid bits */
+ LogFacility = (unsigned)logfac >> 3;
+
+ if (logstat & LOG_NDELAY)
+ openlog_intern();
+
__UCLIBC_MUTEX_UNLOCK(mylock);
}
@@ -206,7 +213,7 @@ __vsyslog(int pri, const char *fmt, va_list ap)
if ((LogMask & LOG_MASK(LOG_PRI(pri))) == 0)
goto getout;
if (LogFile < 0 || !connected)
- openlog_intern(NULL, LogStat | LOG_NDELAY, (int)LogFacility << 3);
+ openlog_intern();
/* Set default facility if none specified. */
if ((pri & LOG_FACMASK) == 0)
@@ -266,14 +273,23 @@ __vsyslog(int pri, const char *fmt, va_list ap)
/* Output the message to the local logger using NUL as a message delimiter. */
p = tbuf;
*last_chr = '\0';
+ retry:
if (LogFile >= 0) {
do {
/* can't just use write, it can result in SIGPIPE */
rc = send(LogFile, p, last_chr + 1 - p, MSG_NOSIGNAL);
if (rc < 0) {
- /* I don't think looping forever on EAGAIN is a good idea.
- * Imagine that syslogd is SIGSTOPed... */
- if (/* (errno != EAGAIN) && */ (errno != EINTR)) {
+ switch (errno) {
+ case EINTR:
+ break;
+ case ECONNRESET:
+ /* syslogd restarted, reopen log */
+ closelog_intern(1);
+ openlog_intern();
+ goto retry;
+ case EAGAIN:
+ /* syslogd stalled, noting we can do */
+ default:
closelog_intern(1); /* 1: do not reset LogXXX globals to default */
goto write_err;
}
diff --git a/libc/stdio/_READ.c b/libc/stdio/_READ.c
index dfd0f43..a3c1413 100644
--- a/libc/stdio/_READ.c
+++ b/libc/stdio/_READ.c
@@ -27,7 +27,7 @@ size_t attribute_hidden __stdio_READ(register FILE *stream,
ssize_t rv = 0;
__STDIO_STREAM_VALIDATE(stream);
- assert(stream->__filedes >= -1);
+ assert(stream->__filedes >= -2);
assert(__STDIO_STREAM_IS_READING(stream));
assert(!__STDIO_STREAM_BUFFER_RAVAIL(stream)); /* Buffer must be empty. */
assert(!(stream->__modeflags & __FLAG_UNGOT));
diff --git a/libc/stdio/_WRITE.c b/libc/stdio/_WRITE.c
index b3e6ecb..113f0eb 100644
--- a/libc/stdio/_WRITE.c
+++ b/libc/stdio/_WRITE.c
@@ -36,7 +36,7 @@ size_t attribute_hidden __stdio_WRITE(register FILE *stream,
ssize_t rv, stodo;
__STDIO_STREAM_VALIDATE(stream);
- assert(stream->__filedes >= -1);
+ assert(stream->__filedes >= -2);
assert(__STDIO_STREAM_IS_WRITING(stream));
assert(!__STDIO_STREAM_BUFFER_WUSED(stream)); /* Buffer must be empty. */
diff --git a/libc/stdio/_cs_funcs.c b/libc/stdio/_cs_funcs.c
index 9df93f2..be416a4 100644
--- a/libc/stdio/_cs_funcs.c
+++ b/libc/stdio/_cs_funcs.c
@@ -8,46 +8,6 @@
#include "_stdio.h"
/**********************************************************************/
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
-/**********************************************************************/
-
-ssize_t attribute_hidden _cs_read(void *cookie, char *buf, size_t bufsize)
-{
- return read(*((int *) cookie), buf, bufsize);
-}
-
-/**********************************************************************/
-
-ssize_t attribute_hidden _cs_write(void *cookie, const char *buf, size_t bufsize)
-{
- return write(*((int *) cookie), (char *) buf, bufsize);
-}
-
-/**********************************************************************/
-
-int attribute_hidden _cs_seek(void *cookie, register __offmax_t *pos, int whence)
-{
- __offmax_t res;
-
-#ifdef __UCLIBC_HAS_LFS__
- res = lseek64(*((int *) cookie), *pos, whence);
-#else
- res = lseek(*((int *) cookie), *pos, whence);
-#endif
-
- return (res >= 0) ? ((*pos = res), 0) : ((int) res);
-}
-
-/**********************************************************************/
-
-int attribute_hidden _cs_close(void *cookie)
-{
- return close(*((int *) cookie));
-}
-
-/**********************************************************************/
-#else
-/**********************************************************************/
int attribute_hidden __stdio_seek(FILE *stream, register __offmax_t *pos, int whence)
{
@@ -63,5 +23,3 @@ int attribute_hidden __stdio_seek(FILE *stream, register __offmax_t *pos, int wh
}
/**********************************************************************/
-#endif
-/**********************************************************************/
diff --git a/libc/stdio/_fopen.c b/libc/stdio/_fopen.c
index 0788260..ddad158 100644
--- a/libc/stdio/_fopen.c
+++ b/libc/stdio/_fopen.c
@@ -183,8 +183,6 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
__STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
#endif
- __STDIO_STREAM_RESET_GCS(stream);
-
#ifdef __UCLIBC_HAS_WCHAR__
stream->__ungot_width[0] = 0;
#endif
diff --git a/libc/stdio/_rfill.c b/libc/stdio/_rfill.c
index 943d66c..d2b3de5 100644
--- a/libc/stdio/_rfill.c
+++ b/libc/stdio/_rfill.c
@@ -20,7 +20,7 @@ size_t attribute_hidden __stdio_rfill(register FILE *__restrict stream)
size_t rv;
__STDIO_STREAM_VALIDATE(stream);
- assert(stream->__filedes >= -1);
+ assert(stream->__filedes >= -2);
assert(__STDIO_STREAM_IS_READING(stream));
assert(!__STDIO_STREAM_BUFFER_RAVAIL(stream)); /* Buffer must be empty. */
assert(__STDIO_STREAM_BUFFER_SIZE(stream)); /* Must have a buffer. */
diff --git a/libc/stdio/_scanf.c b/libc/stdio/_scanf.c
index d697aed..9fe2bb2 100644
--- a/libc/stdio/_scanf.c
+++ b/libc/stdio/_scanf.c
@@ -198,15 +198,6 @@ int vsscanf(const char *sp, const char *fmt, va_list ap)
{
FILE f;
-/* __STDIO_STREAM_RESET_GCS(&f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.__cookie = &(f.__filedes);
- f.__gcs.read = NULL;
- f.__gcs.write = NULL;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
-#endif
-
f.__filedes = __STDIO_STREAM_FAKE_VSSCANF_FILEDES;
f.__modeflags = (__FLAG_NARROW|__FLAG_READONLY|__FLAG_READING);
@@ -245,15 +236,6 @@ int vsscanf(const char *sp, const char *fmt, va_list ap)
f.bufpos = (unsigned char *) ((void *) sp);
f.bufread = f.bufpos + strlen(sp);
-/* __STDIO_STREAM_RESET_GCS(&f.f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.f.__cookie = &(f.f.__filedes);
- f.f.__gcs.read = NULL;
- f.f.__gcs.write = NULL;
- f.f.__gcs.seek = NULL;
- f.f.__gcs.close = NULL;
-#endif
-
f.f.__filedes = __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB;
f.f.__modeflags = (__FLAG_NARROW|__FLAG_READONLY|__FLAG_READING);
@@ -379,15 +361,6 @@ int vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict format,
__STDIO_STREAM_DISABLE_GETC(&f);
__STDIO_STREAM_DISABLE_PUTC(&f);
-/* __STDIO_STREAM_RESET_GCS(&f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.__cookie = &(f.__filedes);
- f.__gcs.read = NULL;
- f.__gcs.write = NULL;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
-#endif
-
f.__filedes = __STDIO_STREAM_FAKE_VSWSCANF_FILEDES;
f.__modeflags = (__FLAG_WIDE|__FLAG_READONLY|__FLAG_READING);
diff --git a/libc/stdio/_stdio.c b/libc/stdio/_stdio.c
index ee247a5..2a10546 100644
--- a/libc/stdio/_stdio.c
+++ b/libc/stdio/_stdio.c
@@ -51,13 +51,6 @@
#define __STDIO_FILE_INIT_BUFFERS(buf,bufsize)
#endif
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
-#define __STDIO_FILE_INIT_CUSTOM_STREAM(stream) \
- &((stream).__filedes), { _cs_read, _cs_write, _cs_seek, _cs_close },
-#else
-#define __STDIO_FILE_INIT_CUSTOM_STREAM(stream)
-#endif
-
#ifdef __STDIO_MBSTATE
#define __STDIO_FILE_INIT_MBSTATE \
{ 0, 0 },
@@ -92,7 +85,6 @@
__STDIO_FILE_INIT_BUFGETC((buf)) \
__STDIO_FILE_INIT_BUFPUTC((buf)) \
__STDIO_FILE_INIT_NEXT(next) \
- __STDIO_FILE_INIT_CUSTOM_STREAM(stream) \
__STDIO_FILE_INIT_WUNGOT \
__STDIO_FILE_INIT_MBSTATE \
__STDIO_FILE_INIT_UNUSED \
@@ -240,7 +232,7 @@ void _stdio_term(void)
#endif
#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
/* Actually close all custom streams to perform any special cleanup. */
- if (ptr->__cookie != &ptr->__filedes) {
+ if (__STDIO_STREAM_IS_CUSTOM(ptr)) {
__CLOSE(ptr);
}
#endif
@@ -284,14 +276,9 @@ void attribute_hidden _stdio_validate_FILE(const FILE *stream)
#endif
#warning Define a constant for minimum possible valid __filedes?
- assert(stream->__filedes >= -3);
+ assert(stream->__filedes >= -4);
if (stream->__filedes < 0) {
-/* assert((stream->__filedes != -1) */
-/* #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
-/* || (stream->__cookie == &stream->__filedes) /\* custom *\/ */
-/* #endif */
-/* ); */
/* assert((stream->__filedes == -1) || __STDIO_STREAM_IS_FBF(stream)); */
assert(!__STDIO_STREAM_IS_FAKE_VSNPRINTF(stream)
@@ -308,12 +295,6 @@ void attribute_hidden _stdio_validate_FILE(const FILE *stream)
#endif
}
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- if (stream->__cookie != &stream->__filedes) { /* custom */
- assert(stream->__filedes == -1);
- }
-#endif
-
/* Can not be both narrow and wide oriented at the same time. */
assert(!(__STDIO_STREAM_IS_NARROW(stream)
&& __STDIO_STREAM_IS_WIDE(stream)));
diff --git a/libc/stdio/_stdio.h b/libc/stdio/_stdio.h
index 94557c2..310510d 100644
--- a/libc/stdio/_stdio.h
+++ b/libc/stdio/_stdio.h
@@ -4,6 +4,8 @@
*
* Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
*/
+#ifndef __STDIO_H_I
+#define __STDIO_H_I 1
#include <features.h>
#include <assert.h>
@@ -96,48 +98,61 @@ do { \
/**********************************************************************/
#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
-extern __ssize_t _cs_read(void *cookie, char *buf, size_t bufsize) attribute_hidden;
-extern __ssize_t _cs_write(void *cookie, const char *buf, size_t bufsize) attribute_hidden;
-extern int _cs_seek(void *cookie, __offmax_t *pos, int whence) attribute_hidden;
-extern int _cs_close(void *cookie) attribute_hidden;
-
-#define __STDIO_STREAM_RESET_GCS(S) \
- (S)->__cookie = &((S)->__filedes); \
- (S)->__gcs.read = _cs_read; \
- (S)->__gcs.write = _cs_write; \
- (S)->__gcs.seek = _cs_seek; \
- (S)->__gcs.close = _cs_close
-
-
-#define __READ(STREAMPTR,BUF,SIZE) \
- ((((STREAMPTR)->__gcs.read) == NULL) ? -1 : \
- (((STREAMPTR)->__gcs.read)((STREAMPTR)->__cookie,(BUF),(SIZE))))
-#define __WRITE(STREAMPTR,BUF,SIZE) \
- ((((STREAMPTR)->__gcs.write) == NULL) ? -1 : \
- (((STREAMPTR)->__gcs.write)((STREAMPTR)->__cookie,(BUF),(SIZE))))
-#define __SEEK(STREAMPTR,PPOS,WHENCE) \
- ((((STREAMPTR)->__gcs.seek) == NULL) ? -1 : \
- (((STREAMPTR)->__gcs.seek)((STREAMPTR)->__cookie,(PPOS),(WHENCE))))
-#define __CLOSE(STREAMPTR) \
- ((((STREAMPTR)->__gcs.close) == NULL) ? 0 : \
- (((STREAMPTR)->__gcs.close)((STREAMPTR)->__cookie)))
+#define __STDIO_STREAM_GLIBC_CUSTOM_FILEDES (-2)
+
+#define __STDIO_STREAM_IS_CUSTOM(S) \
+ ((S)->__filedes == __STDIO_STREAM_GLIBC_CUSTOM_FILEDES)
+
+#define __STDIO_STREAM_CUSTOM_IO_FUNC(S, NAME, RC, ARGS...) \
+ if (__STDIO_STREAM_IS_CUSTOM((S))) { \
+ _IO_cookie_file_t *cfile = (_IO_cookie_file_t *) (S); \
+ return (cfile->__gcs.NAME == NULL) ? (RC) : \
+ cfile->__gcs.NAME(cfile->__cookie, ##ARGS); \
+ }
+
+typedef struct {
+ struct __STDIO_FILE_STRUCT __fp;
+ void *__cookie;
+ _IO_cookie_io_functions_t __gcs;
+} _IO_cookie_file_t;
#else /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+#undef __STDIO_STREAM_GLIBC_CUSTOM_FILEDES
+#define __STDIO_STREAM_IS_CUSTOM(S) (0)
+#define __STDIO_STREAM_CUSTOM_IO_FUNC(S, NAME, RC, ARGS...)
+
+#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+
extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attribute_hidden;
-#define __STDIO_STREAM_RESET_GCS(S) ((void)0)
+static inline ssize_t __READ(FILE *stream, char *buf, size_t bufsize)
+{
+ __STDIO_STREAM_CUSTOM_IO_FUNC(stream, read, -1, buf, bufsize);
-#define __READ(STREAMPTR,BUF,SIZE) \
- (read((STREAMPTR)->__filedes,(BUF),(SIZE)))
-#define __WRITE(STREAMPTR,BUF,SIZE) \
- (write((STREAMPTR)->__filedes,(BUF),(SIZE)))
-#define __SEEK(STREAMPTR,PPOS,WHENCE) \
- (__stdio_seek((STREAMPTR),(PPOS),(WHENCE)))
-#define __CLOSE(STREAMPTR) \
- (close((STREAMPTR)->__filedes))
+ return read(stream->__filedes, buf, bufsize);
+}
-#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+static inline ssize_t __WRITE(FILE *stream, const char *buf, size_t bufsize)
+{
+ __STDIO_STREAM_CUSTOM_IO_FUNC(stream, write, -1, buf, bufsize);
+
+ return write(stream->__filedes, buf, bufsize);
+}
+
+static inline int __SEEK(FILE *stream, register __offmax_t *pos, int whence)
+{
+ __STDIO_STREAM_CUSTOM_IO_FUNC(stream, seek, -1, pos, whence);
+
+ return __stdio_seek(stream, pos, whence);
+}
+
+static inline int __CLOSE(FILE *stream)
+{
+ __STDIO_STREAM_CUSTOM_IO_FUNC(stream, close, 0);
+
+ return close(stream->__filedes);
+}
/**********************************************************************/
#ifdef __UCLIBC_HAS_WCHAR__
@@ -254,12 +269,6 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr
# define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) (0)
#endif
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
-#define __STDIO_STREAM_IS_CUSTOM(S) ((S)->__cookie != &((S)->__filedes))
-#else
-#define __STDIO_STREAM_IS_CUSTOM(S) (0)
-#endif
-
/**********************************************************************/
#ifdef __STDIO_BUFFERS
@@ -346,10 +355,10 @@ extern void _store_inttype(void *dest, int desttype, uintmax_t val) attribute_hi
(S)->__bufread = (S)->__bufpos = (S)->__bufstart
-#define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES (-2)
-#define __STDIO_STREAM_FAKE_VSSCANF_FILEDES (-2)
-#define __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES (-3)
-#define __STDIO_STREAM_FAKE_VSWSCANF_FILEDES (-3)
+#define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES (-3)
+#define __STDIO_STREAM_FAKE_VSSCANF_FILEDES (-3)
+#define __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES (-4)
+#define __STDIO_STREAM_FAKE_VSWSCANF_FILEDES (-4)
#define __STDIO_STREAM_IS_FAKE_VSNPRINTF(S) \
((S)->__filedes == __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES)
@@ -386,6 +395,7 @@ extern void _store_inttype(void *dest, int desttype, uintmax_t val) attribute_hi
#define __STDIO_STREAM_IS_FAKE_VSNPRINTF(S) (0)
#define __STDIO_STREAM_IS_FAKE_VSSCANF(S) (0)
#undef __STDIO_STREAM_IS_FAKE_VSWPRINTF
+#undef __STDIO_STREAM_IS_FAKE_VSWSCANF
# ifdef __USE_OLD_VFPRINTF__
# define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB (-2)
@@ -461,3 +471,5 @@ extern int _vfwprintf_internal (FILE * __restrict stream,
#if defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
#define __STDIO_HAS_VSNPRINTF 1
#endif
+
+#endif /* __STDIO_H_I */
diff --git a/libc/stdio/fclose.c b/libc/stdio/fclose.c
index 9631ebb..26b27c8 100644
--- a/libc/stdio/fclose.c
+++ b/libc/stdio/fclose.c
@@ -69,8 +69,6 @@ int fclose(register FILE *stream)
stream->__modeflags |= (__FLAG_READONLY|__FLAG_WRITEONLY);
#ifndef NDEBUG
- __STDIO_STREAM_RESET_GCS(stream);
-
/* Reinitialize everything (including putc since fflush could fail). */
__STDIO_STREAM_DISABLE_GETC(stream);
__STDIO_STREAM_DISABLE_PUTC(stream);
diff --git a/libc/stdio/fopencookie.c b/libc/stdio/fopencookie.c
index c4927e0..216dac3 100644
--- a/libc/stdio/fopencookie.c
+++ b/libc/stdio/fopencookie.c
@@ -39,21 +39,34 @@ FILE *_fopencookie(void * __restrict cookie, const char * __restrict mode,
#endif
{
FILE *stream;
+ _IO_cookie_file_t *new_f;
+ new_f = malloc(sizeof(_IO_cookie_file_t));
+ if (new_f == NULL) {
+ return NULL;
+ }
+ new_f->__fp.__modeflags = __FLAG_FREEFILE;
+#ifdef __STDIO_BUFFERS
+ new_f->__fp.__bufstart = NULL; /* We allocate a buffer below. */
+#endif
+#ifdef __UCLIBC_HAS_THREADS__
+ /* We only initialize the mutex in the non-freopen case. */
+ STDIO_INIT_MUTEX(new_f->__fp.__lock);
+#endif
/* Fake an fdopen guaranteed to pass the _stdio_fopen basic agreement
* check without an fcntl call. */
- stream = _stdio_fopen(((intptr_t)(INT_MAX-1)), mode, NULL, INT_MAX);
+ stream = _stdio_fopen(((intptr_t)(INT_MAX-1)), mode, &new_f->__fp, INT_MAX);
if (stream) {
- stream->__filedes = -1;
+ stream->__filedes = __STDIO_STREAM_GLIBC_CUSTOM_FILEDES;
#ifndef __BCC__
- stream->__gcs = io_functions;
+ new_f->__gcs = io_functions;
#else
- stream->__gcs.read = io_functions->read;
- stream->__gcs.write = io_functions->write;
- stream->__gcs.seek = io_functions->seek;
- stream->__gcs.close = io_functions->close;
+ new_f->__gcs.read = io_functions->read;
+ new_f->__gcs.write = io_functions->write;
+ new_f->__gcs.seek = io_functions->seek;
+ new_f->__gcs.close = io_functions->close;
#endif
- stream->__cookie = cookie;
+ new_f->__cookie = cookie;
__STDIO_STREAM_VALIDATE(stream);
}
diff --git a/libc/stdio/fread.c b/libc/stdio/fread.c
index f8bea5a..2a8de6d 100644
--- a/libc/stdio/fread.c
+++ b/libc/stdio/fread.c
@@ -15,7 +15,7 @@ size_t fread_unlocked(void * __restrict ptr, size_t size, size_t nmemb,
FILE * __restrict stream)
{
__STDIO_STREAM_VALIDATE(stream);
- assert(stream->__filedes >= -1);
+ assert(stream->__filedes >= -2);
/* Note: If nmbem * size > SIZE_MAX then there is an application
* bug since no array can be larger than SIZE_MAX in size. */
diff --git a/libc/stdio/vdprintf.c b/libc/stdio/vdprintf.c
index 457018b..46b8dfe 100644
--- a/libc/stdio/vdprintf.c
+++ b/libc/stdio/vdprintf.c
@@ -26,15 +26,6 @@ int vdprintf(int filedes, const char * __restrict format, va_list arg)
__STDIO_STREAM_INIT_BUFREAD_BUFPOS(&f);
#endif
-/* __STDIO_STREAM_RESET_GCS(&f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.__cookie = &(f.__filedes);
- f.__gcs.read = NULL;
- f.__gcs.write = _cs_write;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
-#endif
-
f.__filedes = filedes;
f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
diff --git a/libc/stdio/vsnprintf.c b/libc/stdio/vsnprintf.c
index 4dbf6f0..9e1bed1 100644
--- a/libc/stdio/vsnprintf.c
+++ b/libc/stdio/vsnprintf.c
@@ -17,15 +17,6 @@ int vsnprintf(char *__restrict buf, size_t size,
FILE f;
int rv;
-/* __STDIO_STREAM_RESET_GCS(&f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.__cookie = &(f.__filedes);
- f.__gcs.read = NULL;
- f.__gcs.write = NULL;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
-#endif
-
f.__filedes = __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES;
f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
@@ -91,15 +82,6 @@ int vsnprintf(char *__restrict buf, size_t size,
}
f.bufend = buf + size;
-/* __STDIO_STREAM_RESET_GCS(&f.f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.f.__cookie = &(f.f.__filedes);
- f.f.__gcs.read = NULL;
- f.f.__gcs.write = NULL;
- f.f.__gcs.seek = NULL;
- f.f.__gcs.close = NULL;
-#endif
-
f.f.__filedes = __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB;
f.f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
@@ -132,7 +114,7 @@ libc_hidden_def(vsnprintf)
typedef struct {
size_t pos;
size_t len;
- unsigned char *buf;
+ char *buf;
FILE *fp;
} __snpf_cookie;
@@ -170,34 +152,34 @@ static ssize_t snpf_write(register void *cookie, const char *buf,
int vsnprintf(char *__restrict buf, size_t size,
const char * __restrict format, va_list arg)
{
- FILE f;
+ _IO_cookie_file_t cf;
__snpf_cookie cookie;
int rv;
cookie.buf = buf;
cookie.len = size;
cookie.pos = 0;
- cookie.fp = &f;
+ cookie.fp = &cf.__fp;
- f.__cookie = &cookie;
- f.__gcs.write = snpf_write;
- f.__gcs.read = NULL;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
+ cf.__cookie = &cookie;
+ cf.__gcs.write = snpf_write;
+ cf.__gcs.read = NULL;
+ cf.__gcs.seek = NULL;
+ cf.__gcs.close = NULL;
- f.__filedes = -1; /* For debugging. */
- f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
+ cf.__fp.__filedes = __STDIO_STREAM_GLIBC_CUSTOM_FILEDES;
+ cf.__fp.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
#ifdef __UCLIBC_HAS_WCHAR__
- f.__ungot_width[0] = 0;
+ cf.__fp.__ungot_width[0] = 0;
#endif /* __UCLIBC_HAS_WCHAR__ */
#ifdef __STDIO_MBSTATE
- __INIT_MBSTATE(&(f.__state));
+ __INIT_MBSTATE(&(cf.__fp.__state));
#endif /* __STDIO_MBSTATE */
- f.__nextopen = NULL;
+ cf.__fp.__nextopen = NULL;
- rv = _vfprintf_internal(&f, format, arg);
+ rv = _vfprintf_internal(&cf.__fp, format, arg);
return rv;
}
diff --git a/libc/stdio/vswprintf.c b/libc/stdio/vswprintf.c
index 2195248..58a06a7 100644
--- a/libc/stdio/vswprintf.c
+++ b/libc/stdio/vswprintf.c
@@ -22,15 +22,6 @@ int vswprintf(wchar_t *__restrict buf, size_t size,
FILE f;
int rv;
-/* __STDIO_STREAM_RESET_GCS(&f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.__cookie = &(f.__filedes);
- f.__gcs.read = NULL;
- f.__gcs.write = NULL;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
-#endif
-
f.__filedes = __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES;
f.__modeflags = (__FLAG_WIDE|__FLAG_WRITEONLY|__FLAG_WRITING);
diff --git a/libc/stdlib/canonicalize.c b/libc/stdlib/canonicalize.c
index 06e710a..da09d58 100644
--- a/libc/stdlib/canonicalize.c
+++ b/libc/stdlib/canonicalize.c
@@ -9,30 +9,11 @@
*/
#include <stdlib.h>
-#include <limits.h>
#ifdef __USE_GNU
-#ifndef PATH_MAX
-# ifdef _POSIX_VERSION
-# define PATH_MAX _POSIX_PATH_MAX
-# else
-# ifdef MAXPATHLEN
-# define PATH_MAX MAXPATHLEN
-# else
-# define PATH_MAX 1024
-# endif
-# endif
-#endif
-
char * canonicalize_file_name (const char *name)
{
- char *buf = (char *) malloc(PATH_MAX);
-
- if(unlikely(buf == NULL))
- return NULL;
-
- *buf='\0';
- return realpath (name, buf);
+ return realpath (name, NULL);
}
#endif
diff --git a/libc/sysdeps/linux/common/bits/uClibc_stdio.h b/libc/sysdeps/linux/common/bits/uClibc_stdio.h
index 5b3a1b3..efd8a6c 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_stdio.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_stdio.h
@@ -245,10 +245,6 @@ struct __STDIO_FILE_STRUCT {
#ifdef __STDIO_HAS_OPENLIST
struct __STDIO_FILE_STRUCT *__nextopen;
#endif
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- void *__cookie;
- _IO_cookie_io_functions_t __gcs;
-#endif
#ifdef __UCLIBC_HAS_WCHAR__
wchar_t __ungot[2];
#endif
diff --git a/libc/sysdeps/linux/powerpc/Makefile.arch b/libc/sysdeps/linux/powerpc/Makefile.arch
index 4fbcb11..7c09c87 100644
--- a/libc/sysdeps/linux/powerpc/Makefile.arch
+++ b/libc/sysdeps/linux/powerpc/Makefile.arch
@@ -5,7 +5,7 @@
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
-CSRC-y := __syscall_error.c ioctl.c
+CSRC-y := __syscall_error.c ioctl.c copysignl.c
SSRC-y := \
__longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S brk.S \
diff --git a/libc/sysdeps/linux/powerpc/copysignl.c b/libc/sysdeps/linux/powerpc/copysignl.c
new file mode 100644
index 0000000..000f653
--- /dev/null
+++ b/libc/sysdeps/linux/powerpc/copysignl.c
@@ -0,0 +1,89 @@
+/* s_copysignl.c -- long double version of s_copysign.c.
+ * Conversion to long double by Ulrich Drepper,
+ * Cygnus Support, drepper(a)cygnus.com.
+ */
+
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * copysignl(long double x, long double y)
+ * copysignl(x,y) returns a value with the magnitude of x and
+ * with the sign bit of y.
+ */
+
+#include <endian.h>
+#include <stdint.h>
+
+#if __FLOAT_WORD_ORDER == BIG_ENDIAN
+
+typedef union
+{
+ long double value;
+ struct
+ {
+ int sign_exponent:16;
+ unsigned int empty:16;
+ uint32_t msw;
+ uint32_t lsw;
+ } parts;
+} ieee_long_double_shape_type;
+
+#endif
+
+#if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
+
+typedef union
+{
+ long double value;
+ struct
+ {
+ uint32_t lsw;
+ uint32_t msw;
+ int sign_exponent:16;
+ unsigned int empty:16;
+ } parts;
+} ieee_long_double_shape_type;
+
+#endif
+
+/* Get int from the exponent of a long double. */
+
+#define GET_LDOUBLE_EXP(exp,d) \
+do { \
+ ieee_long_double_shape_type ge_u; \
+ ge_u.value = (d); \
+ (exp) = ge_u.parts.sign_exponent; \
+} while (0)
+
+/* Set exponent of a long double from an int. */
+
+#define SET_LDOUBLE_EXP(d,exp) \
+do { \
+ ieee_long_double_shape_type se_u; \
+ se_u.value = (d); \
+ se_u.parts.sign_exponent = (exp); \
+ (d) = se_u.value; \
+} while (0)
+
+long double copysignl(long double x, long double y);
+libc_hidden_proto(copysignl);
+
+long double copysignl(long double x, long double y)
+{
+ uint32_t es1,es2;
+ GET_LDOUBLE_EXP(es1,x);
+ GET_LDOUBLE_EXP(es2,y);
+ SET_LDOUBLE_EXP(x,(es1&0x7fff)|(es2&0x8000));
+ return x;
+}
+
+libc_hidden_def(copysignl);
diff --git a/libpthread/nptl/allocatestack.c b/libpthread/nptl/allocatestack.c
index 118820a..bf99252 100644
--- a/libpthread/nptl/allocatestack.c
+++ b/libpthread/nptl/allocatestack.c
@@ -98,8 +98,12 @@
/* Cache handling for not-yet free stacks. */
-/* Maximum size in kB of cache. */
-static size_t stack_cache_maxsize = 40 * 1024 * 1024; /* 40MiBi by default. */
+/*
+ Maximum size in kB of cache. GNU libc default is 40MiB
+ embedded systems don't have enough ram for big dirty stack caches,
+ reduce it to 16MiB. 4 does not work, f.e. tst-kill4 segfaults.
+*/
+static size_t stack_cache_maxsize = 16 * 1024 * 1024;
static size_t stack_cache_actsize;
/* Mutex protecting this variable. */
diff --git a/test/Rules.mak b/test/Rules.mak
index c5d1d63..86ea855 100644
--- a/test/Rules.mak
+++ b/test/Rules.mak
@@ -91,7 +91,9 @@ ifeq ($(DODEBUG),y)
HOST_CFLAGS += -g
LDFLAGS += -Wl,-g
HOST_LDFLAGS += -Wl,-g
-else
+endif
+
+ifeq ($(DOSTRIP),y)
LDFLAGS += -Wl,-s
HOST_LDFLAGS += -Wl,-s
endif
diff --git a/test/Test.mak b/test/Test.mak
index 52992a7..a82505f 100644
--- a/test/Test.mak
+++ b/test/Test.mak
@@ -45,6 +45,9 @@ U_TARGETS += $(TESTS_DISABLED)
G_TARGETS += $(addsuffix _glibc,$(TESTS_DISABLED)) $(GLIBC_TESTS_DISABLED)
TARGETS += $(SHELL_TESTS)
CFLAGS += $(CFLAGS_$(notdir $(CURDIR)))
+ifeq (1,$(UCLIBCNG_GENERATE_TESTRUNNER))
+UCLIBCNG_TEST_SUBDIR ?= $(patsubst $(realpath $(TESTDIR))/%,%,$(CURDIR))
+endif
define binary_name
$(patsubst %.exe,%,$@)
@@ -92,6 +95,7 @@ $(addsuffix .exe,$(U_TARGETS)): SIMULATOR:=$(SIMULATOR_uclibc)
$(addsuffix .exe,$(G_TARGETS)): SIMULATOR:=$(SIMULATOR_glibc)
$(RUN_TARGETS):
ifeq (1,$(UCLIBCNG_GENERATE_TESTRUNNER))
+ $(Q)\
expected_ret="$(RET_$(tst_src_name))"; echo \
"$${expected_ret:-0}" \
$(call shellescape,$(tst_src_name)) \
diff --git a/test/stdio/Makefile.in b/test/stdio/Makefile.in
index 0bfbd13..3e60b40 100644
--- a/test/stdio/Makefile.in
+++ b/test/stdio/Makefile.in
@@ -2,3 +2,9 @@
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
DODIFF_64bit := 1
+
+ifeq ($(UCLIBC_HAS_GLIBC_CUSTOM_STREAMS),)
+TESTS_DISABLED += tst-fmemopen
+endif
+
+CFLAGS_tst-fmemopen = -fPIC
diff --git a/test/stdio/tst-fmemopen.c b/test/stdio/tst-fmemopen.c
new file mode 100644
index 0000000..384faa1
--- /dev/null
+++ b/test/stdio/tst-fmemopen.c
@@ -0,0 +1,53 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static char *text_input = "1 23 43";
+
+static const char *good_answer = "1 529 1849 ";
+
+
+static int
+do_test (void)
+{
+ FILE *out, *in;
+ int v, s;
+ size_t size;
+ char *ptr;
+
+ in = fmemopen(text_input, strlen(text_input), "r");
+ if (in == NULL) {
+ perror("fmemopen");
+ return 1;
+ }
+
+ out = open_memstream(&ptr, &size);
+ if (out == NULL) {
+ perror("open_memstream");
+ return 1;
+ }
+
+ for (;;) {
+ s = fscanf(in, "%d", &v);
+ if (s <= 0)
+ break;
+
+ s = fprintf(out, "%d ", v * v);
+ if (s == -1) {
+ puts("fprintf failed");
+ exit(1);
+ }
+ }
+ fclose(in);
+ fclose(out);
+
+ if (size != strlen(good_answer) || strcmp(good_answer, ptr) != 0) {
+ printf("failed: size=%zu; ptr=%s\n", size, ptr);
+ exit(1);
+ }
+ free(ptr);
+ exit(0);
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/tls/Makefile.in b/test/tls/Makefile.in
index bbb4216..6e193a9 100644
--- a/test/tls/Makefile.in
+++ b/test/tls/Makefile.in
@@ -7,6 +7,10 @@ TESTS := tst-tls1 tst-tls2 tst-tls3 tst-tls4 tst-tls5 tst-tls6 tst-tls7 \
tst-tls1-static tst-tls2-static tst-tls9-static
TESTS_DISABLED := tst-tls1-static tst-tls2-static tst-tls9-static
+# test always fails for every architecture,
+# guessing some unimplemented check or feature
+TESTS_DISABLED += tst-tls16
+
#all these tests require shared libraries
ifeq ($(HAVE_SHARED),)
TESTS_DISABLED := $(TESTS)
diff --git a/test/tls/tls-macros-mips.h b/test/tls/tls-macros-mips.h
index 0db3830..eed0938 100644
--- a/test/tls/tls-macros-mips.h
+++ b/test/tls/tls-macros-mips.h
@@ -1,44 +1,56 @@
/* Macros to support TLS testing in times of missing compiler support. */
-#if _MIPS_SIM != _ABI64
+#include <sys/cdefs.h>
+#include <sys/asm.h>
-/* These versions are for o32 and n32. */
+#define __STRING2(X) __STRING(X)
+#define ADDU __STRING2(PTR_ADDU)
+#define ADDIU __STRING2(PTR_ADDIU)
+#define LW __STRING2(PTR_L)
-# define TLS_GD(x) \
- ({ void *__result; \
- extern void *__tls_get_addr (void *); \
- __asm__ ("addiu %0, $28, %%tlsgd(" #x ")" \
- : "=r" (__result)); \
- (int *)__tls_get_addr (__result); })
+/* Load the GOT pointer, which may not be in $28 in a non-PIC
+ (abicalls pic0) function. */
+#ifndef __PIC__
+# if _MIPS_SIM != _ABI64
+# define LOAD_GP "move %[tmp], $28\n\tla $28, __gnu_local_gp\n\t"
+# else
+# define LOAD_GP "move %[tmp], $28\n\tdla $28, __gnu_local_gp\n\t"
+# endif
+# define UNLOAD_GP "\n\tmove $28, %[tmp]"
#else
+# define LOAD_GP
+# define UNLOAD_GP
+#endif
+
# define TLS_GD(x) \
- ({ void *__result; \
+ ({ void *__result, *__tmp; \
extern void *__tls_get_addr (void *); \
- __asm__ ("daddiu %0, $28, %%tlsgd(" #x ")" \
- : "=r" (__result)); \
+ __asm__ (LOAD_GP ADDIU " %0, $28, %%tlsgd(" #x ")" \
+ UNLOAD_GP \
+ : "=r" (__result), [tmp] "=&r" (__tmp)); \
(int *)__tls_get_addr (__result); })
-#endif
-
-#if _MIPS_SIM != _ABI64
# define TLS_LD(x) \
- ({ void *__result; \
+ ({ void *__result, *__tmp; \
extern void *__tls_get_addr (void *); \
- __asm__ ("addiu %0, $28, %%tlsldm(" #x ")" \
- : "=r" (__result)); \
+ __asm__ (LOAD_GP ADDIU " %0, $28, %%tlsldm(" #x ")" \
+ UNLOAD_GP \
+ : "=r" (__result), [tmp] "=&r" (__tmp)); \
__result = __tls_get_addr (__result); \
__asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \
"addiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
- "addu %0,%0,$3" \
+ ADDU " %0,%0,$3" \
: "+r" (__result) : : "$3"); \
__result; })
# define TLS_IE(x) \
- ({ void *__result; \
+ ({ void *__result, *__tmp; \
__asm__ (".set push\n\t.set mips32r2\n\t" \
"rdhwr\t%0,$29\n\t.set pop" \
: "=v" (__result)); \
- __asm__ ("lw $3,%%gottprel(" #x ")($28)\n\t" \
- "addu %0,%0,$3" \
- : "+r" (__result) : : "$3"); \
+ __asm__ (LOAD_GP LW " $3,%%gottprel(" #x ")($28)\n\t" \
+ ADDU " %0,%0,$3" \
+ UNLOAD_GP \
+ : "+r" (__result), [tmp] "=&r" (__tmp) \
+ : : "$3"); \
__result; })
# define TLS_LE(x) \
({ void *__result; \
@@ -47,42 +59,6 @@
: "=v" (__result)); \
__asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \
"addiu $3,$3,%%tprel_lo(" #x ")\n\t" \
- "addu %0,%0,$3" \
+ ADDU " %0,%0,$3" \
: "+r" (__result) : : "$3"); \
__result; })
-
-#else
-
-/* These versions are for n64. */
-
-# define TLS_LD(x) \
- ({ void *__result; \
- extern void *__tls_get_addr (void *); \
- __asm__ ("daddiu %0, $28, %%tlsldm(" #x ")" \
- : "=r" (__result)); \
- __result = __tls_get_addr (__result); \
- __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \
- "daddiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
- "daddu %0,%0,$3" \
- : "+r" (__result) : : "$3"); \
- __result; })
-# define TLS_IE(x) \
- ({ void *__result; \
- __asm__ (".set push\n\t.set mips32r2\n\t" \
- "rdhwr\t%0,$29\n\t.set pop" \
- : "=v" (__result)); \
- __asm__ ("ld $3,%%gottprel(" #x ")($28)\n\t" \
- "daddu %0,%0,$3" \
- : "+r" (__result) : : "$3"); \
- __result; })
-# define TLS_LE(x) \
- ({ void *__result; \
- __asm__ (".set push\n\t.set mips32r2\n\t" \
- "rdhwr\t%0,$29\n\t.set pop" \
- : "=v" (__result)); \
- __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \
- "daddiu $3,$3,%%tprel_lo(" #x ")\n\t" \
- "daddu %0,%0,$3" \
- : "+r" (__result) : : "$3"); \
- __result; })
-#endif
diff --git a/test/tls/tls-macros.h b/test/tls/tls-macros.h
index d243743..e4d87f2 100644
--- a/test/tls/tls-macros.h
+++ b/test/tls/tls-macros.h
@@ -111,15 +111,15 @@
# define TLS_LE(x) \
({ int *__l; \
- __asm__ ("movq %%fs:0,%0\n\t" \
- "leaq " #x "@tpoff(%0), %0" \
+ __asm__ ("mov %%fs:0,%0\n\t" \
+ "lea " #x "@tpoff(%0), %0" \
: "=r" (__l)); \
__l; })
# define TLS_IE(x) \
({ int *__l; \
- __asm__ ("movq %%fs:0,%0\n\t" \
- "addq " #x "@gottpoff(%%rip),%0" \
+ __asm__ ("mov %%fs:0,%0\n\t" \
+ "add " #x "@gottpoff(%%rip),%0" \
: "=r" (__l)); \
__l; })
@@ -132,9 +132,15 @@
: : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
__l; })
+# ifdef __ILP32__
+# define TLS_GD_PREFIX
+# else
+# define TLS_GD_PREFIX ".byte 0x66\n\t"
+# endif
+
# define TLS_GD(x) \
({ int *__l, __c, __d; \
- __asm__ (".byte 0x66\n\t" \
+ __asm__ (TLS_GD_PREFIX \
"leaq " #x "@tlsgd(%%rip),%%rdi\n\t" \
".word 0x6666\n\t" \
"rex64\n\t" \
diff --git a/utils/Makefile.in b/utils/Makefile.in
index d725282..a601721 100644
--- a/utils/Makefile.in
+++ b/utils/Makefile.in
@@ -14,6 +14,7 @@ CFLAGS-utils := \
-I$(top_srcdir)ldso/include \
-DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
-DUCLIBC_LDSO=\"$(UCLIBC_LDSO)\" \
+ -DARCH_NATIVE_BIT=$(ARCH_NATIVE_BIT) \
-I$(top_srcdir)/$(KERNEL_HEADERS) \
-DNOT_IN_libc \
-B$(top_builddir)lib \
diff --git a/utils/ldd.c b/utils/ldd.c
index a12acd2..7e1c314 100644
--- a/utils/ldd.c
+++ b/utils/ldd.c
@@ -174,10 +174,10 @@ static __inline__ uint64_t byteswap64_to_host(uint64_t value)
}
}
-#if ELFCLASSM == ELFCLASS32
-# define byteswap_to_host(x) byteswap32_to_host(x)
-#else
+#if __WORDSIZE == 64
# define byteswap_to_host(x) byteswap64_to_host(x)
+#else
+# define byteswap_to_host(x) byteswap32_to_host(x)
#endif
static ElfW(Shdr) *elf_find_section_type(uint32_t key, ElfW(Ehdr) *ehdr)
@@ -239,7 +239,8 @@ static char *elf_find_rpath(ElfW(Ehdr) *ehdr, ElfW(Dyn) *dynamic)
static int check_elf_header(ElfW(Ehdr) *const ehdr)
{
if (!ehdr || *(uint32_t*)ehdr != ELFMAG_U32
- || ehdr->e_ident[EI_CLASS] != ELFCLASSM
+ /* Use __WORDSIZE, not ELFCLASSM which depends on the host */
+ || ehdr->e_ident[EI_CLASS] != (__WORDSIZE >> 5)
|| ehdr->e_ident[EI_VERSION] != EV_CURRENT
) {
return 1;
@@ -506,6 +507,8 @@ static int add_library(ElfW(Ehdr) *ehdr, ElfW(Dyn) *dynamic, int is_setuid, char
for (cur = lib_list; cur; cur = cur->next) {
/* Check if this library is already in the list */
tmp1 = tmp2 = cur->name;
+ if (!cur->name)
+ continue;
while (*tmp1) {
if (*tmp1 == '/')
tmp2 = tmp1 + 1;
@@ -583,6 +586,8 @@ static struct library *find_elf_interpreter(ElfW(Ehdr) *ehdr)
}
for (cur = lib_list; cur; cur = cur->next) {
/* Check if this library is already in the list */
+ if (!tmp1 || !cur->name)
+ return NULL;
if (strcmp(cur->name, tmp1) == 0) {
/*printf("find_elf_interpreter is replacing '%s' (already in list)\n", cur->name); */
newlib = cur;
diff --git a/utils/porting.h b/utils/porting.h
index f1fdc70..f830741 100644
--- a/utils/porting.h
+++ b/utils/porting.h
@@ -41,6 +41,16 @@
#include "dl-defs.h"
#endif
+/* __WORDSIZE ist used for __ELF_NATIVE_CLASS, which is used for ElfW().
+ We want to provide the wordsize of the target, not of the host, when
+ compiling readelf.host
+ */
+#include <link.h>
+#ifdef ARCH_NATIVE_BIT
+#undef __WORDSIZE
+#define __WORDSIZE ARCH_NATIVE_BIT
+#endif
+
#ifdef DMALLOC
#include <dmalloc.h>
#endif
hooks/post-receive
--
uClibc-ng - small C library for embedded systems
1
0
uClibc-ng - small C library for embedded systems branch 1.0 updated. v1.0.9-47-g836c1a7
by wbx@helium.waldemar-brodkorb.de 17 Dec '15
by wbx@helium.waldemar-brodkorb.de 17 Dec '15
17 Dec '15
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "uClibc-ng - small C library for embedded systems".
The branch, 1.0 has been updated
via 836c1a7baa9421c1222e022cdc263d8c1a5a2b14 (commit)
from 73490b63e659336596420a263c3a7133ccfd914b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 836c1a7baa9421c1222e022cdc263d8c1a5a2b14
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Thu Dec 17 21:07:07 2015 +0100
Revert "glibc compat: bump glibc minor version"
This reverts commit 4a05ed87ceb946608100642121c32e642b58cd0d.
This breaks SSP detection for gcc, which might be problematic
for some projects. Revert it after some discussion with
buildroot and openembedded people.
-----------------------------------------------------------------------
Summary of changes:
include/features.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/features.h b/include/features.h
index f6fbbf4..dcf1348 100644
--- a/include/features.h
+++ b/include/features.h
@@ -393,7 +393,7 @@ uClibc was built without large file support enabled.
these macros to test for features in specific releases. */
/* Don't do it, if you want to keep uClibc happy. */
#define __GLIBC__ 2
-#define __GLIBC_MINOR__ 10
+#define __GLIBC_MINOR__ 2
#endif
#define __GLIBC_PREREQ(maj, min) \
hooks/post-receive
--
uClibc-ng - small C library for embedded systems
1
0
uClibc-ng - small C library for embedded systems branch 1.0 updated. v1.0.9-46-g73490b6
by wbx@helium.waldemar-brodkorb.de 17 Dec '15
by wbx@helium.waldemar-brodkorb.de 17 Dec '15
17 Dec '15
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "uClibc-ng - small C library for embedded systems".
The branch, 1.0 has been updated
via 73490b63e659336596420a263c3a7133ccfd914b (commit)
via 7ccac5e8a4a0fd123eb8c035225ee12d30c0bb00 (commit)
via ce64875415e7d50da86379b48f04f96d633b4e9d (commit)
via 5178df3e156a436c4888a1a95996aea55525e7b6 (commit)
via 3aabb58d126445092dca953223c1730d975491dc (commit)
via 8340ffd2997feaca9074e0272e3c4663793baf77 (commit)
via cc04ab27ba6341f46bbe094478c9af3e3706f411 (commit)
via eaedbdaa0877ec6d0501b8c19ad5175c80764c67 (commit)
via 64917add7f4aeec8720d2fba5e96ea39aac35623 (commit)
via 8a992d6715c8149f7efc0553eeaf31f3e27de60c (commit)
via e83b4786d78b97f1657e96c0dfd13f0e9298e55f (commit)
via a574f01947321cfc4dc746db90c2291f3e9f10c2 (commit)
via 8a783f5440817b8db8d27b6a3fb14c301ffa9ad7 (commit)
via f72e003a5f168a32a77ee9248b2169b1e11d5198 (commit)
via 78443c6a541b807f912f33ef01857acd079559c4 (commit)
via 219b69d72e878094f3ce03a9e70719709a9b4c43 (commit)
via 2e116b2eeea5f47ca26458b1962783baced2784c (commit)
from d1b81113b43a6d26dec4e0e58a380895d121006e (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 73490b63e659336596420a263c3a7133ccfd914b
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Thu Dec 17 20:21:18 2015 +0100
reduce stack cache size to save memory space
Idea from different projects as OpenWrt and others.
https://lists.openwrt.org/pipermail/openwrt-devel/2013-November/022299.html
https://github.com/wl500g/toolchain/blob/master/toolchain/uClibc/patches/0.…
commit 7ccac5e8a4a0fd123eb8c035225ee12d30c0bb00
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Thu Dec 17 07:59:05 2015 +0100
testsuite subdir fix
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit ce64875415e7d50da86379b48f04f96d633b4e9d
Author: Khem Raj <raj.khem(a)gmail.com>
Date: Sat Oct 31 18:32:54 2015 +0000
Add implementation for copysignl for ppc
Signed-off-by: Khem Raj <raj.khem(a)gmail.com>
commit 5178df3e156a436c4888a1a95996aea55525e7b6
Author: Wojciech Nizinski <w.nizinski at grinn-global.com>
Date: Tue Oct 20 14:08:09 2015 +0200
libc/stdlib: canonicalize_file_name() memory leak
Uclibc's canonicalize_file_name() is allocating temprary buffer of 4kB
(PATH_MAX), and passing it to realpath() as second argument. Function is
not checking if realpath() fails and memory is lost.
commit 3aabb58d126445092dca953223c1730d975491dc
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:52:24 2015 +0100
utlis/ldd: Fix host ldd in case of target wordsize differs from host one
improved solution from http://freetz.org/ticket/842
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 8340ffd2997feaca9074e0272e3c4663793baf77
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:51:12 2015 +0100
test/tls: tls-macros*.h fixes from glibc
glibc commits
4822a2a520 Add x32 support to TLS_LE/TLS_IE/TLS_GD
63fb881a04 tls-macros-mips.h: Load $gp as required.
Merge 32-bit and 64-bit versions.
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit cc04ab27ba6341f46bbe094478c9af3e3706f411
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:49:06 2015 +0100
dlclose fix
Patch is from Timo Teras
Refs.:
http://lists.uclibc.org/pipermail/uclibc/2012-October/047059.html
http://git.alpinelinux.org/cgit/aports/tree/main/libc0.9.32/uclibc-dlclose-…
commit eaedbdaa0877ec6d0501b8c19ad5175c80764c67
Author: Vladislav Grishenko <themiron(a)mail.ru>
Date: Wed Sep 12 18:04:48 2012 +0600
Fix syslog messages lost if syslogd is temporary busy
Commit 4139fe5aec935ba3f462dcaf6aafb6e5eadf1ab9 fixes SIGSTOPed syslogd issue.
but introduced new one - messages will be lost when socket buffer gets full,
not only if syslogd is stalled, but even if it accepts message slower than
someone sends and possibly leads to security hole, when important messages get
lost as result of attacker flooding.
Patch adds 1 second waiting for socket buffer can accept the message, helps
when syslogd is working hard. If it's stalled/SIGSTOPed, message will be sent
to errout as before. After that, further non-blocking /dev/log connect attempts
will fail immediately with EAGAIN error until syslogd reads some from it.
function old new delta
openlog_intern 259 355 +96
static.tv - 8 +8
.rodata 151 159 +8
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 2/0 up/down: 112/0) Total: 112 bytes
Signed-off-by: Vladislav Grishenko <themiron(a)mail.ru>
commit 64917add7f4aeec8720d2fba5e96ea39aac35623
Author: Vladislav Grishenko <themiron(a)mail.ru>
Date: Wed Sep 12 17:13:55 2012 +0600
Fix syslog messages lost after syslogd restarts
If syslogd is stopped and restarted while a process has the log open, the next
message that process produces will be logged to the console and not to the new
instance of syslogd. Further messages will be routed correctly, but not the
first one.
Based on original patch
Bug 3889 - syslog loses messages when syslogd restarted
https://bugs.busybox.net/show_bug.cgi?id=3889
function old new delta
openlog 33 68 +35
__vsyslog 851 848 -3
openlog_intern 318 259 -59
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 35/-62) Total: -27 bytes
Signed-off-by: Vladislav Grishenko <themiron(a)mail.ru>
commit 8a992d6715c8149f7efc0553eeaf31f3e27de60c
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:44:54 2015 +0100
resolv: NI_IDN unimplemented
Some programs trying to use NI_IDN flag in case of it defined in netdb.h,
so hide it to suppress bad values for ai_flags.
Inspired by OpenWRT issue #12323
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit e83b4786d78b97f1657e96c0dfd13f0e9298e55f
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:42:34 2015 +0100
resolv: __dns_lookup - immediately switch to next server in case of poll() set error events
https://bugs.busybox.net/show_bug.cgi?id=3211
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit a574f01947321cfc4dc746db90c2291f3e9f10c2
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:40:36 2015 +0100
dynamically allocate ahostbuf buffer
Free 1k of static data (.bss)
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 8a783f5440817b8db8d27b6a3fb14c301ffa9ad7
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:38:30 2015 +0100
svc.c: svc_getreqset() buffer overflow
http://bugs.busybox.net/show_bug.cgi?id=5588
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit f72e003a5f168a32a77ee9248b2169b1e11d5198
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Sun Dec 13 23:36:46 2015 +0100
only strip test binaries when DOSTRIP is enabled
commit 78443c6a541b807f912f33ef01857acd079559c4
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Thu Dec 10 11:14:41 2015 +0100
test needs -fPIC for m68k
commit 219b69d72e878094f3ce03a9e70719709a9b4c43
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Wed Dec 9 08:05:10 2015 +0100
libc/stdio: Rework custom streams interface similar to glibc.
Save 20 bytes per FILE structure, avoid indirect call for
read/write/seek/close operations for normal streams.
Additionally, custom streams has fileno = -2 now, like in glibc.
bloat-o-meter report (UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y):
function old new delta
fopencookie 69 131 +62
ftello64 233 260 +27
fseeko64 298 319 +21
fclose 423 442 +19
.rodata 16696 16708 +12
fileno_unlocked 53 45 -8
__ns_name_pack 859 851 -8
vswscanf 184 144 -40
vdprintf 231 187 -44
vsscanf 210 151 -59
vswprintf 269 201 -68
vsnprintf 249 181 -68
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/7 up/down: 141/-295) Total: -154 bytes
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
commit 2e116b2eeea5f47ca26458b1962783baced2784c
Author: Waldemar Brodkorb <wbx(a)openadk.org>
Date: Wed Dec 9 08:07:09 2015 +0100
fix readdir_r returns success code while it in fact failed
Taken from Freetz.org.
Signed-off-by: Leonid Lisovskiy <lly.dev(a)gmail.com>
Signed-off-by: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
-----------------------------------------------------------------------
Summary of changes:
include/netdb.h | 3 +-
ldso/libdl/libdl.c | 4 +-
libc/inet/resolv.c | 4 +
libc/inet/rpc/rexec.c | 9 ++-
libc/inet/rpc/svc.c | 2 +
libc/misc/dirent/readdir_r.c | 2 +-
libc/misc/syslog/syslog.c | 46 +++++++----
libc/stdio/_READ.c | 2 +-
libc/stdio/_WRITE.c | 2 +-
libc/stdio/_cs_funcs.c | 42 ----------
libc/stdio/_fopen.c | 2 -
libc/stdio/_rfill.c | 2 +-
libc/stdio/_scanf.c | 27 -------
libc/stdio/_stdio.c | 23 +-----
libc/stdio/_stdio.h | 102 ++++++++++++++-----------
libc/stdio/fclose.c | 2 -
libc/stdio/fopencookie.c | 29 +++++--
libc/stdio/fread.c | 2 +-
libc/stdio/vdprintf.c | 9 ---
libc/stdio/vsnprintf.c | 46 ++++-------
libc/stdio/vswprintf.c | 9 ---
libc/stdlib/canonicalize.c | 21 +----
libc/sysdeps/linux/common/bits/uClibc_stdio.h | 4 -
libc/sysdeps/linux/powerpc/Makefile.arch | 2 +-
libc/sysdeps/linux/powerpc/copysignl.c | 89 +++++++++++++++++++++
libpthread/nptl/allocatestack.c | 8 +-
test/Rules.mak | 4 +-
test/Test.mak | 4 +
test/stdio/Makefile.in | 6 ++
test/stdio/tst-fmemopen.c | 53 +++++++++++++
test/tls/tls-macros-mips.h | 94 +++++++++--------------
test/tls/tls-macros.h | 16 ++--
utils/Makefile.in | 1 +
utils/ldd.c | 13 +++-
utils/porting.h | 10 +++
35 files changed, 375 insertions(+), 319 deletions(-)
create mode 100644 libc/sysdeps/linux/powerpc/copysignl.c
create mode 100644 test/stdio/tst-fmemopen.c
diff --git a/include/netdb.h b/include/netdb.h
index 7ce01c2..a636b5f 100644
--- a/include/netdb.h
+++ b/include/netdb.h
@@ -671,7 +671,8 @@ struct addrinfo
# define NI_NOFQDN 4 /* Only return nodename portion. */
# define NI_NAMEREQD 8 /* Don't return numeric addresses. */
# define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
-# ifdef __USE_GNU
+#if 0 /* uClibc: not implemented */
+/* # ifdef __USE_GNU */
# define NI_IDN 32 /* Convert name from IDN format. */
# define NI_IDN_ALLOW_UNASSIGNED 64 /* Don't reject unassigned Unicode
code points. */
diff --git a/ldso/libdl/libdl.c b/ldso/libdl/libdl.c
index 388e3c7..2c4b064 100644
--- a/ldso/libdl/libdl.c
+++ b/ldso/libdl/libdl.c
@@ -964,8 +964,8 @@ static int do_dlclose(void *vhandle, int need_fini)
dtv_t *dtv = THREAD_DTV ();
- _dl_assert(!(dtv[tls_lmap->l_tls_modid].pointer.is_static));
- if (dtv[tls_lmap->l_tls_modid].pointer.val != TLS_DTV_UNALLOCATED) {
+ if (!(dtv[tls_lmap->l_tls_modid].pointer.is_static) &&
+ dtv[tls_lmap->l_tls_modid].pointer.val != TLS_DTV_UNALLOCATED) {
/* Note that free is called for NULL is well. We
deallocate even if it is this dtv entry we are
supposed to load. The reason is that we call
diff --git a/libc/inet/resolv.c b/libc/inet/resolv.c
index fffe428..8e5a97d 100644
--- a/libc/inet/resolv.c
+++ b/libc/inet/resolv.c
@@ -1410,6 +1410,10 @@ int __dns_lookup(const char *name,
* to next nameserver */
goto try_next_server;
}
+ if (fds.revents & (POLLERR | POLLHUP | POLLNVAL)) {
+ DPRINTF("Bad event\n");
+ goto try_next_server;
+ }
/*TODO: better timeout accounting?*/
reply_timeout -= 1000;
#endif /* USE_SELECT */
diff --git a/libc/inet/rpc/rexec.c b/libc/inet/rpc/rexec.c
index 9f7cc80..e17be50 100644
--- a/libc/inet/rpc/rexec.c
+++ b/libc/inet/rpc/rexec.c
@@ -39,12 +39,13 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <malloc.h>
#define SA_LEN(_x) __libc_sa_len((_x)->sa_family)
extern int __libc_sa_len(sa_family_t __af) __THROW attribute_hidden;
/* int rexecoptions; - google does not know it */
-static char ahostbuf[NI_MAXHOST];
+static char *ahostbuf = NULL;
int
rexec_af(char **ahost, int rport, const char *name, const char *pass, const char *cmd, int *fd2p, sa_family_t af)
@@ -77,8 +78,10 @@ rexec_af(char **ahost, int rport, const char *name, const char *pass, const char
}
if (res0->ai_canonname) {
- strncpy(ahostbuf, res0->ai_canonname, sizeof(ahostbuf));
- ahostbuf[sizeof(ahostbuf)-1] = '\0';
+ if (!ahostbuf)
+ ahostbuf = __uc_malloc(NI_MAXHOST);
+ strncpy(ahostbuf, res0->ai_canonname, NI_MAXHOST);
+ ahostbuf[NI_MAXHOST-1] = '\0';
*ahost = ahostbuf;
}
else {
diff --git a/libc/inet/rpc/svc.c b/libc/inet/rpc/svc.c
index 6d7253a..c3d5518 100644
--- a/libc/inet/rpc/svc.c
+++ b/libc/inet/rpc/svc.c
@@ -448,6 +448,8 @@ svc_getreqset (fd_set *readfds)
register int bit;
setsize = _rpc_dtablesize ();
+ if (setsize > FD_SETSIZE)
+ setsize = FD_SETSIZE;
maskp = (u_int32_t *) readfds->fds_bits;
for (sock = 0; sock < setsize; sock += 32)
for (mask = *maskp++; (bit = ffs (mask)); mask ^= (1 << (bit - 1)))
diff --git a/libc/misc/dirent/readdir_r.c b/libc/misc/dirent/readdir_r.c
index 7cdc0ab..5beebfe 100644
--- a/libc/misc/dirent/readdir_r.c
+++ b/libc/misc/dirent/readdir_r.c
@@ -27,7 +27,6 @@ int __READDIR_R(DIR *dir, __DIRENT_TYPE *entry, __DIRENT_TYPE **result)
__set_errno(EBADF);
return(EBADF);
}
- de = NULL;
__UCLIBC_MUTEX_LOCK(dir->dd_lock);
@@ -36,6 +35,7 @@ int __READDIR_R(DIR *dir, __DIRENT_TYPE *entry, __DIRENT_TYPE **result)
/* read dir->dd_max bytes of directory entries. */
bytes = __GETDENTS(dir->dd_fd, dir->dd_buf, dir->dd_max);
if (bytes <= 0) {
+ de = NULL;
*result = NULL;
ret = (bytes==0)? 0 : errno;
goto all_done;
diff --git a/libc/misc/syslog/syslog.c b/libc/misc/syslog/syslog.c
index 1ab4707..1df0d1a 100644
--- a/libc/misc/syslog/syslog.c
+++ b/libc/misc/syslog/syslog.c
@@ -122,23 +122,16 @@ closelog_intern(int sig)
}
static void
-openlog_intern(const char *ident, int logstat, int logfac)
+openlog_intern(void)
{
int fd;
int logType = SOCK_DGRAM;
-
- if (ident != NULL)
- LogTag = ident;
- LogStat = logstat;
- /* (we were checking also for logfac != 0, but it breaks
- * openlog(xx, LOG_KERN) since LOG_KERN == 0) */
- if ((logfac & ~LOG_FACMASK) == 0) /* if we don't have invalid bits */
- LogFacility = (unsigned)logfac >> 3;
+ static const struct timeval tv = { 1, 0 };
fd = LogFile;
if (fd == -1) {
retry:
- if (logstat & LOG_NDELAY) {
+ if (1) { /* if statement left in to make .diff cleaner */
LogFile = fd = socket(AF_UNIX, logType, 0);
if (fd == -1) {
return;
@@ -151,6 +144,9 @@ openlog_intern(const char *ident, int logstat, int logfac)
if (fd != -1 && !connected) {
if (connect(fd, &SyslogAddr, sizeof(SyslogAddr)) != -1) {
+ /* We want to block send if e.g. syslogd is SIGSTOPed */
+ fcntl(fd, F_SETFL, ~O_NONBLOCK & fcntl(fd, F_GETFL));
+ setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
connected = 1;
} else {
if (fd != -1) {
@@ -172,7 +168,18 @@ void
openlog(const char *ident, int logstat, int logfac)
{
__UCLIBC_MUTEX_LOCK(mylock);
- openlog_intern(ident, logstat, logfac);
+
+ if (ident != NULL)
+ LogTag = ident;
+ LogStat = logstat;
+ /* (we were checking also for logfac != 0, but it breaks
+ * openlog(xx, LOG_KERN) since LOG_KERN == 0) */
+ if ((logfac & ~LOG_FACMASK) == 0) /* if we don't have invalid bits */
+ LogFacility = (unsigned)logfac >> 3;
+
+ if (logstat & LOG_NDELAY)
+ openlog_intern();
+
__UCLIBC_MUTEX_UNLOCK(mylock);
}
@@ -206,7 +213,7 @@ __vsyslog(int pri, const char *fmt, va_list ap)
if ((LogMask & LOG_MASK(LOG_PRI(pri))) == 0)
goto getout;
if (LogFile < 0 || !connected)
- openlog_intern(NULL, LogStat | LOG_NDELAY, (int)LogFacility << 3);
+ openlog_intern();
/* Set default facility if none specified. */
if ((pri & LOG_FACMASK) == 0)
@@ -266,14 +273,23 @@ __vsyslog(int pri, const char *fmt, va_list ap)
/* Output the message to the local logger using NUL as a message delimiter. */
p = tbuf;
*last_chr = '\0';
+ retry:
if (LogFile >= 0) {
do {
/* can't just use write, it can result in SIGPIPE */
rc = send(LogFile, p, last_chr + 1 - p, MSG_NOSIGNAL);
if (rc < 0) {
- /* I don't think looping forever on EAGAIN is a good idea.
- * Imagine that syslogd is SIGSTOPed... */
- if (/* (errno != EAGAIN) && */ (errno != EINTR)) {
+ switch (errno) {
+ case EINTR:
+ break;
+ case ECONNRESET:
+ /* syslogd restarted, reopen log */
+ closelog_intern(1);
+ openlog_intern();
+ goto retry;
+ case EAGAIN:
+ /* syslogd stalled, noting we can do */
+ default:
closelog_intern(1); /* 1: do not reset LogXXX globals to default */
goto write_err;
}
diff --git a/libc/stdio/_READ.c b/libc/stdio/_READ.c
index 02601c0..a548dbb 100644
--- a/libc/stdio/_READ.c
+++ b/libc/stdio/_READ.c
@@ -27,7 +27,7 @@ size_t attribute_hidden __stdio_READ(register FILE *stream,
ssize_t rv = 0;
__STDIO_STREAM_VALIDATE(stream);
- assert(stream->__filedes >= -1);
+ assert(stream->__filedes >= -2);
assert(__STDIO_STREAM_IS_READING(stream));
assert(!__STDIO_STREAM_BUFFER_RAVAIL(stream)); /* Buffer must be empty. */
assert(!(stream->__modeflags & __FLAG_UNGOT));
diff --git a/libc/stdio/_WRITE.c b/libc/stdio/_WRITE.c
index 6af5da8..712236f 100644
--- a/libc/stdio/_WRITE.c
+++ b/libc/stdio/_WRITE.c
@@ -36,7 +36,7 @@ size_t attribute_hidden __stdio_WRITE(register FILE *stream,
ssize_t rv, stodo;
__STDIO_STREAM_VALIDATE(stream);
- assert(stream->__filedes >= -1);
+ assert(stream->__filedes >= -2);
assert(__STDIO_STREAM_IS_WRITING(stream));
assert(!__STDIO_STREAM_BUFFER_WUSED(stream)); /* Buffer must be empty. */
diff --git a/libc/stdio/_cs_funcs.c b/libc/stdio/_cs_funcs.c
index 9df93f2..be416a4 100644
--- a/libc/stdio/_cs_funcs.c
+++ b/libc/stdio/_cs_funcs.c
@@ -8,46 +8,6 @@
#include "_stdio.h"
/**********************************************************************/
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
-/**********************************************************************/
-
-ssize_t attribute_hidden _cs_read(void *cookie, char *buf, size_t bufsize)
-{
- return read(*((int *) cookie), buf, bufsize);
-}
-
-/**********************************************************************/
-
-ssize_t attribute_hidden _cs_write(void *cookie, const char *buf, size_t bufsize)
-{
- return write(*((int *) cookie), (char *) buf, bufsize);
-}
-
-/**********************************************************************/
-
-int attribute_hidden _cs_seek(void *cookie, register __offmax_t *pos, int whence)
-{
- __offmax_t res;
-
-#ifdef __UCLIBC_HAS_LFS__
- res = lseek64(*((int *) cookie), *pos, whence);
-#else
- res = lseek(*((int *) cookie), *pos, whence);
-#endif
-
- return (res >= 0) ? ((*pos = res), 0) : ((int) res);
-}
-
-/**********************************************************************/
-
-int attribute_hidden _cs_close(void *cookie)
-{
- return close(*((int *) cookie));
-}
-
-/**********************************************************************/
-#else
-/**********************************************************************/
int attribute_hidden __stdio_seek(FILE *stream, register __offmax_t *pos, int whence)
{
@@ -63,5 +23,3 @@ int attribute_hidden __stdio_seek(FILE *stream, register __offmax_t *pos, int wh
}
/**********************************************************************/
-#endif
-/**********************************************************************/
diff --git a/libc/stdio/_fopen.c b/libc/stdio/_fopen.c
index 5bc61cf..be05c48 100644
--- a/libc/stdio/_fopen.c
+++ b/libc/stdio/_fopen.c
@@ -192,8 +192,6 @@ FILE attribute_hidden *_stdio_fopen(intptr_t fname_or_mode,
__STDIO_STREAM_INIT_BUFREAD_BUFPOS(stream);
#endif
- __STDIO_STREAM_RESET_GCS(stream);
-
#ifdef __UCLIBC_HAS_WCHAR__
stream->__ungot_width[0] = 0;
#endif
diff --git a/libc/stdio/_rfill.c b/libc/stdio/_rfill.c
index d61b1a9..e9d2fa6 100644
--- a/libc/stdio/_rfill.c
+++ b/libc/stdio/_rfill.c
@@ -24,7 +24,7 @@ size_t attribute_hidden __stdio_rfill(register FILE *__restrict stream)
size_t rv;
__STDIO_STREAM_VALIDATE(stream);
- assert(stream->__filedes >= -1);
+ assert(stream->__filedes >= -2);
assert(__STDIO_STREAM_IS_READING(stream));
assert(!__STDIO_STREAM_BUFFER_RAVAIL(stream)); /* Buffer must be empty. */
assert(__STDIO_STREAM_BUFFER_SIZE(stream)); /* Must have a buffer. */
diff --git a/libc/stdio/_scanf.c b/libc/stdio/_scanf.c
index f2a9670..80e4956 100644
--- a/libc/stdio/_scanf.c
+++ b/libc/stdio/_scanf.c
@@ -202,15 +202,6 @@ int vsscanf(const char *sp, const char *fmt, va_list ap)
{
FILE f;
-/* __STDIO_STREAM_RESET_GCS(&f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.__cookie = &(f.__filedes);
- f.__gcs.read = NULL;
- f.__gcs.write = NULL;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
-#endif
-
f.__filedes = __STDIO_STREAM_FAKE_VSSCANF_FILEDES;
f.__modeflags = (__FLAG_NARROW|__FLAG_READONLY|__FLAG_READING);
@@ -249,15 +240,6 @@ int vsscanf(const char *sp, const char *fmt, va_list ap)
f.bufpos = (unsigned char *) ((void *) sp);
f.bufread = f.bufpos + strlen(sp);
-/* __STDIO_STREAM_RESET_GCS(&f.f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.f.__cookie = &(f.f.__filedes);
- f.f.__gcs.read = NULL;
- f.f.__gcs.write = NULL;
- f.f.__gcs.seek = NULL;
- f.f.__gcs.close = NULL;
-#endif
-
f.f.__filedes = __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB;
f.f.__modeflags = (__FLAG_NARROW|__FLAG_READONLY|__FLAG_READING);
@@ -383,15 +365,6 @@ int vswscanf(const wchar_t * __restrict str, const wchar_t * __restrict format,
__STDIO_STREAM_DISABLE_GETC(&f);
__STDIO_STREAM_DISABLE_PUTC(&f);
-/* __STDIO_STREAM_RESET_GCS(&f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.__cookie = &(f.__filedes);
- f.__gcs.read = NULL;
- f.__gcs.write = NULL;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
-#endif
-
f.__filedes = __STDIO_STREAM_FAKE_VSWSCANF_FILEDES;
f.__modeflags = (__FLAG_WIDE|__FLAG_READONLY|__FLAG_READING);
diff --git a/libc/stdio/_stdio.c b/libc/stdio/_stdio.c
index ee247a5..2a10546 100644
--- a/libc/stdio/_stdio.c
+++ b/libc/stdio/_stdio.c
@@ -51,13 +51,6 @@
#define __STDIO_FILE_INIT_BUFFERS(buf,bufsize)
#endif
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
-#define __STDIO_FILE_INIT_CUSTOM_STREAM(stream) \
- &((stream).__filedes), { _cs_read, _cs_write, _cs_seek, _cs_close },
-#else
-#define __STDIO_FILE_INIT_CUSTOM_STREAM(stream)
-#endif
-
#ifdef __STDIO_MBSTATE
#define __STDIO_FILE_INIT_MBSTATE \
{ 0, 0 },
@@ -92,7 +85,6 @@
__STDIO_FILE_INIT_BUFGETC((buf)) \
__STDIO_FILE_INIT_BUFPUTC((buf)) \
__STDIO_FILE_INIT_NEXT(next) \
- __STDIO_FILE_INIT_CUSTOM_STREAM(stream) \
__STDIO_FILE_INIT_WUNGOT \
__STDIO_FILE_INIT_MBSTATE \
__STDIO_FILE_INIT_UNUSED \
@@ -240,7 +232,7 @@ void _stdio_term(void)
#endif
#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
/* Actually close all custom streams to perform any special cleanup. */
- if (ptr->__cookie != &ptr->__filedes) {
+ if (__STDIO_STREAM_IS_CUSTOM(ptr)) {
__CLOSE(ptr);
}
#endif
@@ -284,14 +276,9 @@ void attribute_hidden _stdio_validate_FILE(const FILE *stream)
#endif
#warning Define a constant for minimum possible valid __filedes?
- assert(stream->__filedes >= -3);
+ assert(stream->__filedes >= -4);
if (stream->__filedes < 0) {
-/* assert((stream->__filedes != -1) */
-/* #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
-/* || (stream->__cookie == &stream->__filedes) /\* custom *\/ */
-/* #endif */
-/* ); */
/* assert((stream->__filedes == -1) || __STDIO_STREAM_IS_FBF(stream)); */
assert(!__STDIO_STREAM_IS_FAKE_VSNPRINTF(stream)
@@ -308,12 +295,6 @@ void attribute_hidden _stdio_validate_FILE(const FILE *stream)
#endif
}
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- if (stream->__cookie != &stream->__filedes) { /* custom */
- assert(stream->__filedes == -1);
- }
-#endif
-
/* Can not be both narrow and wide oriented at the same time. */
assert(!(__STDIO_STREAM_IS_NARROW(stream)
&& __STDIO_STREAM_IS_WIDE(stream)));
diff --git a/libc/stdio/_stdio.h b/libc/stdio/_stdio.h
index 94557c2..310510d 100644
--- a/libc/stdio/_stdio.h
+++ b/libc/stdio/_stdio.h
@@ -4,6 +4,8 @@
*
* Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
*/
+#ifndef __STDIO_H_I
+#define __STDIO_H_I 1
#include <features.h>
#include <assert.h>
@@ -96,48 +98,61 @@ do { \
/**********************************************************************/
#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
-extern __ssize_t _cs_read(void *cookie, char *buf, size_t bufsize) attribute_hidden;
-extern __ssize_t _cs_write(void *cookie, const char *buf, size_t bufsize) attribute_hidden;
-extern int _cs_seek(void *cookie, __offmax_t *pos, int whence) attribute_hidden;
-extern int _cs_close(void *cookie) attribute_hidden;
-
-#define __STDIO_STREAM_RESET_GCS(S) \
- (S)->__cookie = &((S)->__filedes); \
- (S)->__gcs.read = _cs_read; \
- (S)->__gcs.write = _cs_write; \
- (S)->__gcs.seek = _cs_seek; \
- (S)->__gcs.close = _cs_close
-
-
-#define __READ(STREAMPTR,BUF,SIZE) \
- ((((STREAMPTR)->__gcs.read) == NULL) ? -1 : \
- (((STREAMPTR)->__gcs.read)((STREAMPTR)->__cookie,(BUF),(SIZE))))
-#define __WRITE(STREAMPTR,BUF,SIZE) \
- ((((STREAMPTR)->__gcs.write) == NULL) ? -1 : \
- (((STREAMPTR)->__gcs.write)((STREAMPTR)->__cookie,(BUF),(SIZE))))
-#define __SEEK(STREAMPTR,PPOS,WHENCE) \
- ((((STREAMPTR)->__gcs.seek) == NULL) ? -1 : \
- (((STREAMPTR)->__gcs.seek)((STREAMPTR)->__cookie,(PPOS),(WHENCE))))
-#define __CLOSE(STREAMPTR) \
- ((((STREAMPTR)->__gcs.close) == NULL) ? 0 : \
- (((STREAMPTR)->__gcs.close)((STREAMPTR)->__cookie)))
+#define __STDIO_STREAM_GLIBC_CUSTOM_FILEDES (-2)
+
+#define __STDIO_STREAM_IS_CUSTOM(S) \
+ ((S)->__filedes == __STDIO_STREAM_GLIBC_CUSTOM_FILEDES)
+
+#define __STDIO_STREAM_CUSTOM_IO_FUNC(S, NAME, RC, ARGS...) \
+ if (__STDIO_STREAM_IS_CUSTOM((S))) { \
+ _IO_cookie_file_t *cfile = (_IO_cookie_file_t *) (S); \
+ return (cfile->__gcs.NAME == NULL) ? (RC) : \
+ cfile->__gcs.NAME(cfile->__cookie, ##ARGS); \
+ }
+
+typedef struct {
+ struct __STDIO_FILE_STRUCT __fp;
+ void *__cookie;
+ _IO_cookie_io_functions_t __gcs;
+} _IO_cookie_file_t;
#else /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+#undef __STDIO_STREAM_GLIBC_CUSTOM_FILEDES
+#define __STDIO_STREAM_IS_CUSTOM(S) (0)
+#define __STDIO_STREAM_CUSTOM_IO_FUNC(S, NAME, RC, ARGS...)
+
+#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+
extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attribute_hidden;
-#define __STDIO_STREAM_RESET_GCS(S) ((void)0)
+static inline ssize_t __READ(FILE *stream, char *buf, size_t bufsize)
+{
+ __STDIO_STREAM_CUSTOM_IO_FUNC(stream, read, -1, buf, bufsize);
-#define __READ(STREAMPTR,BUF,SIZE) \
- (read((STREAMPTR)->__filedes,(BUF),(SIZE)))
-#define __WRITE(STREAMPTR,BUF,SIZE) \
- (write((STREAMPTR)->__filedes,(BUF),(SIZE)))
-#define __SEEK(STREAMPTR,PPOS,WHENCE) \
- (__stdio_seek((STREAMPTR),(PPOS),(WHENCE)))
-#define __CLOSE(STREAMPTR) \
- (close((STREAMPTR)->__filedes))
+ return read(stream->__filedes, buf, bufsize);
+}
-#endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
+static inline ssize_t __WRITE(FILE *stream, const char *buf, size_t bufsize)
+{
+ __STDIO_STREAM_CUSTOM_IO_FUNC(stream, write, -1, buf, bufsize);
+
+ return write(stream->__filedes, buf, bufsize);
+}
+
+static inline int __SEEK(FILE *stream, register __offmax_t *pos, int whence)
+{
+ __STDIO_STREAM_CUSTOM_IO_FUNC(stream, seek, -1, pos, whence);
+
+ return __stdio_seek(stream, pos, whence);
+}
+
+static inline int __CLOSE(FILE *stream)
+{
+ __STDIO_STREAM_CUSTOM_IO_FUNC(stream, close, 0);
+
+ return close(stream->__filedes);
+}
/**********************************************************************/
#ifdef __UCLIBC_HAS_WCHAR__
@@ -254,12 +269,6 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr
# define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) (0)
#endif
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
-#define __STDIO_STREAM_IS_CUSTOM(S) ((S)->__cookie != &((S)->__filedes))
-#else
-#define __STDIO_STREAM_IS_CUSTOM(S) (0)
-#endif
-
/**********************************************************************/
#ifdef __STDIO_BUFFERS
@@ -346,10 +355,10 @@ extern void _store_inttype(void *dest, int desttype, uintmax_t val) attribute_hi
(S)->__bufread = (S)->__bufpos = (S)->__bufstart
-#define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES (-2)
-#define __STDIO_STREAM_FAKE_VSSCANF_FILEDES (-2)
-#define __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES (-3)
-#define __STDIO_STREAM_FAKE_VSWSCANF_FILEDES (-3)
+#define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES (-3)
+#define __STDIO_STREAM_FAKE_VSSCANF_FILEDES (-3)
+#define __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES (-4)
+#define __STDIO_STREAM_FAKE_VSWSCANF_FILEDES (-4)
#define __STDIO_STREAM_IS_FAKE_VSNPRINTF(S) \
((S)->__filedes == __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES)
@@ -386,6 +395,7 @@ extern void _store_inttype(void *dest, int desttype, uintmax_t val) attribute_hi
#define __STDIO_STREAM_IS_FAKE_VSNPRINTF(S) (0)
#define __STDIO_STREAM_IS_FAKE_VSSCANF(S) (0)
#undef __STDIO_STREAM_IS_FAKE_VSWPRINTF
+#undef __STDIO_STREAM_IS_FAKE_VSWSCANF
# ifdef __USE_OLD_VFPRINTF__
# define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB (-2)
@@ -461,3 +471,5 @@ extern int _vfwprintf_internal (FILE * __restrict stream,
#if defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
#define __STDIO_HAS_VSNPRINTF 1
#endif
+
+#endif /* __STDIO_H_I */
diff --git a/libc/stdio/fclose.c b/libc/stdio/fclose.c
index 3417b26..7e7bc3b 100644
--- a/libc/stdio/fclose.c
+++ b/libc/stdio/fclose.c
@@ -69,8 +69,6 @@ int fclose(register FILE *stream)
stream->__modeflags |= (__FLAG_READONLY|__FLAG_WRITEONLY);
#ifndef NDEBUG
- __STDIO_STREAM_RESET_GCS(stream);
-
/* Reinitialize everything (including putc since fflush could fail). */
__STDIO_STREAM_DISABLE_GETC(stream);
__STDIO_STREAM_DISABLE_PUTC(stream);
diff --git a/libc/stdio/fopencookie.c b/libc/stdio/fopencookie.c
index c4927e0..216dac3 100644
--- a/libc/stdio/fopencookie.c
+++ b/libc/stdio/fopencookie.c
@@ -39,21 +39,34 @@ FILE *_fopencookie(void * __restrict cookie, const char * __restrict mode,
#endif
{
FILE *stream;
+ _IO_cookie_file_t *new_f;
+ new_f = malloc(sizeof(_IO_cookie_file_t));
+ if (new_f == NULL) {
+ return NULL;
+ }
+ new_f->__fp.__modeflags = __FLAG_FREEFILE;
+#ifdef __STDIO_BUFFERS
+ new_f->__fp.__bufstart = NULL; /* We allocate a buffer below. */
+#endif
+#ifdef __UCLIBC_HAS_THREADS__
+ /* We only initialize the mutex in the non-freopen case. */
+ STDIO_INIT_MUTEX(new_f->__fp.__lock);
+#endif
/* Fake an fdopen guaranteed to pass the _stdio_fopen basic agreement
* check without an fcntl call. */
- stream = _stdio_fopen(((intptr_t)(INT_MAX-1)), mode, NULL, INT_MAX);
+ stream = _stdio_fopen(((intptr_t)(INT_MAX-1)), mode, &new_f->__fp, INT_MAX);
if (stream) {
- stream->__filedes = -1;
+ stream->__filedes = __STDIO_STREAM_GLIBC_CUSTOM_FILEDES;
#ifndef __BCC__
- stream->__gcs = io_functions;
+ new_f->__gcs = io_functions;
#else
- stream->__gcs.read = io_functions->read;
- stream->__gcs.write = io_functions->write;
- stream->__gcs.seek = io_functions->seek;
- stream->__gcs.close = io_functions->close;
+ new_f->__gcs.read = io_functions->read;
+ new_f->__gcs.write = io_functions->write;
+ new_f->__gcs.seek = io_functions->seek;
+ new_f->__gcs.close = io_functions->close;
#endif
- stream->__cookie = cookie;
+ new_f->__cookie = cookie;
__STDIO_STREAM_VALIDATE(stream);
}
diff --git a/libc/stdio/fread.c b/libc/stdio/fread.c
index d2fcc70..5df33b4 100644
--- a/libc/stdio/fread.c
+++ b/libc/stdio/fread.c
@@ -15,7 +15,7 @@ size_t fread_unlocked(void * __restrict ptr, size_t size, size_t nmemb,
FILE * __restrict stream)
{
__STDIO_STREAM_VALIDATE(stream);
- assert(stream->__filedes >= -1);
+ assert(stream->__filedes >= -2);
/* Note: If nmbem * size > SIZE_MAX then there is an application
* bug since no array can be larger than SIZE_MAX in size. */
diff --git a/libc/stdio/vdprintf.c b/libc/stdio/vdprintf.c
index 457018b..46b8dfe 100644
--- a/libc/stdio/vdprintf.c
+++ b/libc/stdio/vdprintf.c
@@ -26,15 +26,6 @@ int vdprintf(int filedes, const char * __restrict format, va_list arg)
__STDIO_STREAM_INIT_BUFREAD_BUFPOS(&f);
#endif
-/* __STDIO_STREAM_RESET_GCS(&f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.__cookie = &(f.__filedes);
- f.__gcs.read = NULL;
- f.__gcs.write = _cs_write;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
-#endif
-
f.__filedes = filedes;
f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
diff --git a/libc/stdio/vsnprintf.c b/libc/stdio/vsnprintf.c
index 31adc52..3a4c607 100644
--- a/libc/stdio/vsnprintf.c
+++ b/libc/stdio/vsnprintf.c
@@ -22,15 +22,6 @@ int vsnprintf(char *__restrict buf, size_t size,
FILE f;
int rv;
-/* __STDIO_STREAM_RESET_GCS(&f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.__cookie = &(f.__filedes);
- f.__gcs.read = NULL;
- f.__gcs.write = NULL;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
-#endif
-
f.__filedes = __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES;
f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
@@ -96,15 +87,6 @@ int vsnprintf(char *__restrict buf, size_t size,
}
f.bufend = buf + size;
-/* __STDIO_STREAM_RESET_GCS(&f.f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.f.__cookie = &(f.f.__filedes);
- f.f.__gcs.read = NULL;
- f.f.__gcs.write = NULL;
- f.f.__gcs.seek = NULL;
- f.f.__gcs.close = NULL;
-#endif
-
f.f.__filedes = __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB;
f.f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
@@ -137,7 +119,7 @@ libc_hidden_def(vsnprintf)
typedef struct {
size_t pos;
size_t len;
- unsigned char *buf;
+ char *buf;
FILE *fp;
} __snpf_cookie;
@@ -175,34 +157,34 @@ static ssize_t snpf_write(register void *cookie, const char *buf,
int vsnprintf(char *__restrict buf, size_t size,
const char * __restrict format, va_list arg)
{
- FILE f;
+ _IO_cookie_file_t cf;
__snpf_cookie cookie;
int rv;
cookie.buf = buf;
cookie.len = size;
cookie.pos = 0;
- cookie.fp = &f;
+ cookie.fp = &cf.__fp;
- f.__cookie = &cookie;
- f.__gcs.write = snpf_write;
- f.__gcs.read = NULL;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
+ cf.__cookie = &cookie;
+ cf.__gcs.write = snpf_write;
+ cf.__gcs.read = NULL;
+ cf.__gcs.seek = NULL;
+ cf.__gcs.close = NULL;
- f.__filedes = -1; /* For debugging. */
- f.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
+ cf.__fp.__filedes = __STDIO_STREAM_GLIBC_CUSTOM_FILEDES;
+ cf.__fp.__modeflags = (__FLAG_NARROW|__FLAG_WRITEONLY|__FLAG_WRITING);
#ifdef __UCLIBC_HAS_WCHAR__
- f.__ungot_width[0] = 0;
+ cf.__fp.__ungot_width[0] = 0;
#endif /* __UCLIBC_HAS_WCHAR__ */
#ifdef __STDIO_MBSTATE
- __INIT_MBSTATE(&(f.__state));
+ __INIT_MBSTATE(&(cf.__fp.__state));
#endif /* __STDIO_MBSTATE */
- f.__nextopen = NULL;
+ cf.__fp.__nextopen = NULL;
- rv = _vfprintf_internal(&f, format, arg);
+ rv = _vfprintf_internal(&cf.__fp, format, arg);
return rv;
}
diff --git a/libc/stdio/vswprintf.c b/libc/stdio/vswprintf.c
index 2195248..58a06a7 100644
--- a/libc/stdio/vswprintf.c
+++ b/libc/stdio/vswprintf.c
@@ -22,15 +22,6 @@ int vswprintf(wchar_t *__restrict buf, size_t size,
FILE f;
int rv;
-/* __STDIO_STREAM_RESET_GCS(&f); */
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- f.__cookie = &(f.__filedes);
- f.__gcs.read = NULL;
- f.__gcs.write = NULL;
- f.__gcs.seek = NULL;
- f.__gcs.close = NULL;
-#endif
-
f.__filedes = __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES;
f.__modeflags = (__FLAG_WIDE|__FLAG_WRITEONLY|__FLAG_WRITING);
diff --git a/libc/stdlib/canonicalize.c b/libc/stdlib/canonicalize.c
index 06e710a..da09d58 100644
--- a/libc/stdlib/canonicalize.c
+++ b/libc/stdlib/canonicalize.c
@@ -9,30 +9,11 @@
*/
#include <stdlib.h>
-#include <limits.h>
#ifdef __USE_GNU
-#ifndef PATH_MAX
-# ifdef _POSIX_VERSION
-# define PATH_MAX _POSIX_PATH_MAX
-# else
-# ifdef MAXPATHLEN
-# define PATH_MAX MAXPATHLEN
-# else
-# define PATH_MAX 1024
-# endif
-# endif
-#endif
-
char * canonicalize_file_name (const char *name)
{
- char *buf = (char *) malloc(PATH_MAX);
-
- if(unlikely(buf == NULL))
- return NULL;
-
- *buf='\0';
- return realpath (name, buf);
+ return realpath (name, NULL);
}
#endif
diff --git a/libc/sysdeps/linux/common/bits/uClibc_stdio.h b/libc/sysdeps/linux/common/bits/uClibc_stdio.h
index 5b3a1b3..efd8a6c 100644
--- a/libc/sysdeps/linux/common/bits/uClibc_stdio.h
+++ b/libc/sysdeps/linux/common/bits/uClibc_stdio.h
@@ -245,10 +245,6 @@ struct __STDIO_FILE_STRUCT {
#ifdef __STDIO_HAS_OPENLIST
struct __STDIO_FILE_STRUCT *__nextopen;
#endif
-#ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- void *__cookie;
- _IO_cookie_io_functions_t __gcs;
-#endif
#ifdef __UCLIBC_HAS_WCHAR__
wchar_t __ungot[2];
#endif
diff --git a/libc/sysdeps/linux/powerpc/Makefile.arch b/libc/sysdeps/linux/powerpc/Makefile.arch
index 4fbcb11..7c09c87 100644
--- a/libc/sysdeps/linux/powerpc/Makefile.arch
+++ b/libc/sysdeps/linux/powerpc/Makefile.arch
@@ -5,7 +5,7 @@
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
#
-CSRC-y := __syscall_error.c ioctl.c
+CSRC-y := __syscall_error.c ioctl.c copysignl.c
SSRC-y := \
__longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S brk.S \
diff --git a/libc/sysdeps/linux/powerpc/copysignl.c b/libc/sysdeps/linux/powerpc/copysignl.c
new file mode 100644
index 0000000..000f653
--- /dev/null
+++ b/libc/sysdeps/linux/powerpc/copysignl.c
@@ -0,0 +1,89 @@
+/* s_copysignl.c -- long double version of s_copysign.c.
+ * Conversion to long double by Ulrich Drepper,
+ * Cygnus Support, drepper(a)cygnus.com.
+ */
+
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * copysignl(long double x, long double y)
+ * copysignl(x,y) returns a value with the magnitude of x and
+ * with the sign bit of y.
+ */
+
+#include <endian.h>
+#include <stdint.h>
+
+#if __FLOAT_WORD_ORDER == BIG_ENDIAN
+
+typedef union
+{
+ long double value;
+ struct
+ {
+ int sign_exponent:16;
+ unsigned int empty:16;
+ uint32_t msw;
+ uint32_t lsw;
+ } parts;
+} ieee_long_double_shape_type;
+
+#endif
+
+#if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
+
+typedef union
+{
+ long double value;
+ struct
+ {
+ uint32_t lsw;
+ uint32_t msw;
+ int sign_exponent:16;
+ unsigned int empty:16;
+ } parts;
+} ieee_long_double_shape_type;
+
+#endif
+
+/* Get int from the exponent of a long double. */
+
+#define GET_LDOUBLE_EXP(exp,d) \
+do { \
+ ieee_long_double_shape_type ge_u; \
+ ge_u.value = (d); \
+ (exp) = ge_u.parts.sign_exponent; \
+} while (0)
+
+/* Set exponent of a long double from an int. */
+
+#define SET_LDOUBLE_EXP(d,exp) \
+do { \
+ ieee_long_double_shape_type se_u; \
+ se_u.value = (d); \
+ se_u.parts.sign_exponent = (exp); \
+ (d) = se_u.value; \
+} while (0)
+
+long double copysignl(long double x, long double y);
+libc_hidden_proto(copysignl);
+
+long double copysignl(long double x, long double y)
+{
+ uint32_t es1,es2;
+ GET_LDOUBLE_EXP(es1,x);
+ GET_LDOUBLE_EXP(es2,y);
+ SET_LDOUBLE_EXP(x,(es1&0x7fff)|(es2&0x8000));
+ return x;
+}
+
+libc_hidden_def(copysignl);
diff --git a/libpthread/nptl/allocatestack.c b/libpthread/nptl/allocatestack.c
index 118820a..bf99252 100644
--- a/libpthread/nptl/allocatestack.c
+++ b/libpthread/nptl/allocatestack.c
@@ -98,8 +98,12 @@
/* Cache handling for not-yet free stacks. */
-/* Maximum size in kB of cache. */
-static size_t stack_cache_maxsize = 40 * 1024 * 1024; /* 40MiBi by default. */
+/*
+ Maximum size in kB of cache. GNU libc default is 40MiB
+ embedded systems don't have enough ram for big dirty stack caches,
+ reduce it to 16MiB. 4 does not work, f.e. tst-kill4 segfaults.
+*/
+static size_t stack_cache_maxsize = 16 * 1024 * 1024;
static size_t stack_cache_actsize;
/* Mutex protecting this variable. */
diff --git a/test/Rules.mak b/test/Rules.mak
index c5d1d63..86ea855 100644
--- a/test/Rules.mak
+++ b/test/Rules.mak
@@ -91,7 +91,9 @@ ifeq ($(DODEBUG),y)
HOST_CFLAGS += -g
LDFLAGS += -Wl,-g
HOST_LDFLAGS += -Wl,-g
-else
+endif
+
+ifeq ($(DOSTRIP),y)
LDFLAGS += -Wl,-s
HOST_LDFLAGS += -Wl,-s
endif
diff --git a/test/Test.mak b/test/Test.mak
index 52992a7..a82505f 100644
--- a/test/Test.mak
+++ b/test/Test.mak
@@ -45,6 +45,9 @@ U_TARGETS += $(TESTS_DISABLED)
G_TARGETS += $(addsuffix _glibc,$(TESTS_DISABLED)) $(GLIBC_TESTS_DISABLED)
TARGETS += $(SHELL_TESTS)
CFLAGS += $(CFLAGS_$(notdir $(CURDIR)))
+ifeq (1,$(UCLIBCNG_GENERATE_TESTRUNNER))
+UCLIBCNG_TEST_SUBDIR ?= $(patsubst $(realpath $(TESTDIR))/%,%,$(CURDIR))
+endif
define binary_name
$(patsubst %.exe,%,$@)
@@ -92,6 +95,7 @@ $(addsuffix .exe,$(U_TARGETS)): SIMULATOR:=$(SIMULATOR_uclibc)
$(addsuffix .exe,$(G_TARGETS)): SIMULATOR:=$(SIMULATOR_glibc)
$(RUN_TARGETS):
ifeq (1,$(UCLIBCNG_GENERATE_TESTRUNNER))
+ $(Q)\
expected_ret="$(RET_$(tst_src_name))"; echo \
"$${expected_ret:-0}" \
$(call shellescape,$(tst_src_name)) \
diff --git a/test/stdio/Makefile.in b/test/stdio/Makefile.in
index 0bfbd13..3e60b40 100644
--- a/test/stdio/Makefile.in
+++ b/test/stdio/Makefile.in
@@ -2,3 +2,9 @@
# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
DODIFF_64bit := 1
+
+ifeq ($(UCLIBC_HAS_GLIBC_CUSTOM_STREAMS),)
+TESTS_DISABLED += tst-fmemopen
+endif
+
+CFLAGS_tst-fmemopen = -fPIC
diff --git a/test/stdio/tst-fmemopen.c b/test/stdio/tst-fmemopen.c
new file mode 100644
index 0000000..384faa1
--- /dev/null
+++ b/test/stdio/tst-fmemopen.c
@@ -0,0 +1,53 @@
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static char *text_input = "1 23 43";
+
+static const char *good_answer = "1 529 1849 ";
+
+
+static int
+do_test (void)
+{
+ FILE *out, *in;
+ int v, s;
+ size_t size;
+ char *ptr;
+
+ in = fmemopen(text_input, strlen(text_input), "r");
+ if (in == NULL) {
+ perror("fmemopen");
+ return 1;
+ }
+
+ out = open_memstream(&ptr, &size);
+ if (out == NULL) {
+ perror("open_memstream");
+ return 1;
+ }
+
+ for (;;) {
+ s = fscanf(in, "%d", &v);
+ if (s <= 0)
+ break;
+
+ s = fprintf(out, "%d ", v * v);
+ if (s == -1) {
+ puts("fprintf failed");
+ exit(1);
+ }
+ }
+ fclose(in);
+ fclose(out);
+
+ if (size != strlen(good_answer) || strcmp(good_answer, ptr) != 0) {
+ printf("failed: size=%zu; ptr=%s\n", size, ptr);
+ exit(1);
+ }
+ free(ptr);
+ exit(0);
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/test/tls/tls-macros-mips.h b/test/tls/tls-macros-mips.h
index 0db3830..eed0938 100644
--- a/test/tls/tls-macros-mips.h
+++ b/test/tls/tls-macros-mips.h
@@ -1,44 +1,56 @@
/* Macros to support TLS testing in times of missing compiler support. */
-#if _MIPS_SIM != _ABI64
+#include <sys/cdefs.h>
+#include <sys/asm.h>
-/* These versions are for o32 and n32. */
+#define __STRING2(X) __STRING(X)
+#define ADDU __STRING2(PTR_ADDU)
+#define ADDIU __STRING2(PTR_ADDIU)
+#define LW __STRING2(PTR_L)
-# define TLS_GD(x) \
- ({ void *__result; \
- extern void *__tls_get_addr (void *); \
- __asm__ ("addiu %0, $28, %%tlsgd(" #x ")" \
- : "=r" (__result)); \
- (int *)__tls_get_addr (__result); })
+/* Load the GOT pointer, which may not be in $28 in a non-PIC
+ (abicalls pic0) function. */
+#ifndef __PIC__
+# if _MIPS_SIM != _ABI64
+# define LOAD_GP "move %[tmp], $28\n\tla $28, __gnu_local_gp\n\t"
+# else
+# define LOAD_GP "move %[tmp], $28\n\tdla $28, __gnu_local_gp\n\t"
+# endif
+# define UNLOAD_GP "\n\tmove $28, %[tmp]"
#else
+# define LOAD_GP
+# define UNLOAD_GP
+#endif
+
# define TLS_GD(x) \
- ({ void *__result; \
+ ({ void *__result, *__tmp; \
extern void *__tls_get_addr (void *); \
- __asm__ ("daddiu %0, $28, %%tlsgd(" #x ")" \
- : "=r" (__result)); \
+ __asm__ (LOAD_GP ADDIU " %0, $28, %%tlsgd(" #x ")" \
+ UNLOAD_GP \
+ : "=r" (__result), [tmp] "=&r" (__tmp)); \
(int *)__tls_get_addr (__result); })
-#endif
-
-#if _MIPS_SIM != _ABI64
# define TLS_LD(x) \
- ({ void *__result; \
+ ({ void *__result, *__tmp; \
extern void *__tls_get_addr (void *); \
- __asm__ ("addiu %0, $28, %%tlsldm(" #x ")" \
- : "=r" (__result)); \
+ __asm__ (LOAD_GP ADDIU " %0, $28, %%tlsldm(" #x ")" \
+ UNLOAD_GP \
+ : "=r" (__result), [tmp] "=&r" (__tmp)); \
__result = __tls_get_addr (__result); \
__asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \
"addiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
- "addu %0,%0,$3" \
+ ADDU " %0,%0,$3" \
: "+r" (__result) : : "$3"); \
__result; })
# define TLS_IE(x) \
- ({ void *__result; \
+ ({ void *__result, *__tmp; \
__asm__ (".set push\n\t.set mips32r2\n\t" \
"rdhwr\t%0,$29\n\t.set pop" \
: "=v" (__result)); \
- __asm__ ("lw $3,%%gottprel(" #x ")($28)\n\t" \
- "addu %0,%0,$3" \
- : "+r" (__result) : : "$3"); \
+ __asm__ (LOAD_GP LW " $3,%%gottprel(" #x ")($28)\n\t" \
+ ADDU " %0,%0,$3" \
+ UNLOAD_GP \
+ : "+r" (__result), [tmp] "=&r" (__tmp) \
+ : : "$3"); \
__result; })
# define TLS_LE(x) \
({ void *__result; \
@@ -47,42 +59,6 @@
: "=v" (__result)); \
__asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \
"addiu $3,$3,%%tprel_lo(" #x ")\n\t" \
- "addu %0,%0,$3" \
+ ADDU " %0,%0,$3" \
: "+r" (__result) : : "$3"); \
__result; })
-
-#else
-
-/* These versions are for n64. */
-
-# define TLS_LD(x) \
- ({ void *__result; \
- extern void *__tls_get_addr (void *); \
- __asm__ ("daddiu %0, $28, %%tlsldm(" #x ")" \
- : "=r" (__result)); \
- __result = __tls_get_addr (__result); \
- __asm__ ("lui $3,%%dtprel_hi(" #x ")\n\t" \
- "daddiu $3,$3,%%dtprel_lo(" #x ")\n\t" \
- "daddu %0,%0,$3" \
- : "+r" (__result) : : "$3"); \
- __result; })
-# define TLS_IE(x) \
- ({ void *__result; \
- __asm__ (".set push\n\t.set mips32r2\n\t" \
- "rdhwr\t%0,$29\n\t.set pop" \
- : "=v" (__result)); \
- __asm__ ("ld $3,%%gottprel(" #x ")($28)\n\t" \
- "daddu %0,%0,$3" \
- : "+r" (__result) : : "$3"); \
- __result; })
-# define TLS_LE(x) \
- ({ void *__result; \
- __asm__ (".set push\n\t.set mips32r2\n\t" \
- "rdhwr\t%0,$29\n\t.set pop" \
- : "=v" (__result)); \
- __asm__ ("lui $3,%%tprel_hi(" #x ")\n\t" \
- "daddiu $3,$3,%%tprel_lo(" #x ")\n\t" \
- "daddu %0,%0,$3" \
- : "+r" (__result) : : "$3"); \
- __result; })
-#endif
diff --git a/test/tls/tls-macros.h b/test/tls/tls-macros.h
index d243743..e4d87f2 100644
--- a/test/tls/tls-macros.h
+++ b/test/tls/tls-macros.h
@@ -111,15 +111,15 @@
# define TLS_LE(x) \
({ int *__l; \
- __asm__ ("movq %%fs:0,%0\n\t" \
- "leaq " #x "@tpoff(%0), %0" \
+ __asm__ ("mov %%fs:0,%0\n\t" \
+ "lea " #x "@tpoff(%0), %0" \
: "=r" (__l)); \
__l; })
# define TLS_IE(x) \
({ int *__l; \
- __asm__ ("movq %%fs:0,%0\n\t" \
- "addq " #x "@gottpoff(%%rip),%0" \
+ __asm__ ("mov %%fs:0,%0\n\t" \
+ "add " #x "@gottpoff(%%rip),%0" \
: "=r" (__l)); \
__l; })
@@ -132,9 +132,15 @@
: : "rdi", "rsi", "r8", "r9", "r10", "r11"); \
__l; })
+# ifdef __ILP32__
+# define TLS_GD_PREFIX
+# else
+# define TLS_GD_PREFIX ".byte 0x66\n\t"
+# endif
+
# define TLS_GD(x) \
({ int *__l, __c, __d; \
- __asm__ (".byte 0x66\n\t" \
+ __asm__ (TLS_GD_PREFIX \
"leaq " #x "@tlsgd(%%rip),%%rdi\n\t" \
".word 0x6666\n\t" \
"rex64\n\t" \
diff --git a/utils/Makefile.in b/utils/Makefile.in
index d725282..a601721 100644
--- a/utils/Makefile.in
+++ b/utils/Makefile.in
@@ -14,6 +14,7 @@ CFLAGS-utils := \
-I$(top_srcdir)ldso/include \
-DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
-DUCLIBC_LDSO=\"$(UCLIBC_LDSO)\" \
+ -DARCH_NATIVE_BIT=$(ARCH_NATIVE_BIT) \
-I$(top_srcdir)/$(KERNEL_HEADERS) \
-DNOT_IN_libc \
-B$(top_builddir)lib \
diff --git a/utils/ldd.c b/utils/ldd.c
index a12acd2..7e1c314 100644
--- a/utils/ldd.c
+++ b/utils/ldd.c
@@ -174,10 +174,10 @@ static __inline__ uint64_t byteswap64_to_host(uint64_t value)
}
}
-#if ELFCLASSM == ELFCLASS32
-# define byteswap_to_host(x) byteswap32_to_host(x)
-#else
+#if __WORDSIZE == 64
# define byteswap_to_host(x) byteswap64_to_host(x)
+#else
+# define byteswap_to_host(x) byteswap32_to_host(x)
#endif
static ElfW(Shdr) *elf_find_section_type(uint32_t key, ElfW(Ehdr) *ehdr)
@@ -239,7 +239,8 @@ static char *elf_find_rpath(ElfW(Ehdr) *ehdr, ElfW(Dyn) *dynamic)
static int check_elf_header(ElfW(Ehdr) *const ehdr)
{
if (!ehdr || *(uint32_t*)ehdr != ELFMAG_U32
- || ehdr->e_ident[EI_CLASS] != ELFCLASSM
+ /* Use __WORDSIZE, not ELFCLASSM which depends on the host */
+ || ehdr->e_ident[EI_CLASS] != (__WORDSIZE >> 5)
|| ehdr->e_ident[EI_VERSION] != EV_CURRENT
) {
return 1;
@@ -506,6 +507,8 @@ static int add_library(ElfW(Ehdr) *ehdr, ElfW(Dyn) *dynamic, int is_setuid, char
for (cur = lib_list; cur; cur = cur->next) {
/* Check if this library is already in the list */
tmp1 = tmp2 = cur->name;
+ if (!cur->name)
+ continue;
while (*tmp1) {
if (*tmp1 == '/')
tmp2 = tmp1 + 1;
@@ -583,6 +586,8 @@ static struct library *find_elf_interpreter(ElfW(Ehdr) *ehdr)
}
for (cur = lib_list; cur; cur = cur->next) {
/* Check if this library is already in the list */
+ if (!tmp1 || !cur->name)
+ return NULL;
if (strcmp(cur->name, tmp1) == 0) {
/*printf("find_elf_interpreter is replacing '%s' (already in list)\n", cur->name); */
newlib = cur;
diff --git a/utils/porting.h b/utils/porting.h
index f1fdc70..f830741 100644
--- a/utils/porting.h
+++ b/utils/porting.h
@@ -41,6 +41,16 @@
#include "dl-defs.h"
#endif
+/* __WORDSIZE ist used for __ELF_NATIVE_CLASS, which is used for ElfW().
+ We want to provide the wordsize of the target, not of the host, when
+ compiling readelf.host
+ */
+#include <link.h>
+#ifdef ARCH_NATIVE_BIT
+#undef __WORDSIZE
+#define __WORDSIZE ARCH_NATIVE_BIT
+#endif
+
#ifdef DMALLOC
#include <dmalloc.h>
#endif
hooks/post-receive
--
uClibc-ng - small C library for embedded systems
1
0
Hi Thomas, Khem, Alexey,
recently Khem tried to use systemd with openembedded and uClibc-ng.
Most of the needed stuff is ready and will be committed soon.
There is one open issue I want to discuss with you.
The GLIBC_MINOR bump in commit
4a05ed87ceb946608100642121c32e642b58cd0d is breaking SSP detection
in GCC. This was discovered in Buildroot and fixed.
It seems there is a major problem to fix it in OpenEmbedded, so
Khem is asking for revert of this commit for the next release.
What do you think about it?
Isn't the boost problem solved anyway in another way?
May be we just learned what it means to bump this number and
can revert it back to the old value. We should still try
to get a patch into gcc to avoid any misdetection regarding
SSP for the next major gcc release.
Thanks for any opinion,
best regards
Waldemar
2
1
The current (arbitrary) limit of 128 characters for path names has
proven too short for Android builds, as longer path names are used
there.
Change conf.c, so it can handle path lengths up to PATH_MAX characters.
Signed-off-by: Markus Mayer <mmayer(a)broadcom.com>
---
This change was also submitted to the Linux community and has been
accepted.
https://git.kernel.org/cgit/linux/kernel/git/mmarek/kbuild.git/commit/?h=kc…
extra/config/conf.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/extra/config/conf.c b/extra/config/conf.c
index b24c1c3..34bb4f5 100644
--- a/extra/config/conf.c
+++ b/extra/config/conf.c
@@ -5,6 +5,7 @@
#include <locale.h>
#include <ctype.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -40,7 +41,7 @@ static int tty_stdio;
static int valid_stdin = 1;
static int sync_kconfig;
static int conf_cnt;
-static char line[128];
+static char line[PATH_MAX];
static struct menu *rootEntry;
static void print_help(struct menu *menu)
@@ -108,7 +109,7 @@ static int conf_askvalue(struct symbol *sym, const char *def)
/* fall through */
case oldaskconfig:
fflush(stdout);
- xfgets(line, 128, stdin);
+ xfgets(line, sizeof(line), stdin);
if (!tty_stdio)
printf("\n");
return 1;
@@ -310,7 +311,7 @@ static int conf_choice(struct menu *menu)
/* fall through */
case oldaskconfig:
fflush(stdout);
- xfgets(line, 128, stdin);
+ xfgets(line, sizeof(line), stdin);
strip(line);
if (line[0] == '?') {
print_help(menu);
--
1.9.1
2
1
uClibc-ng - small C library for embedded systems branch 1.0 updated. v1.0.9-29-gd1b8111
by wbx@helium.waldemar-brodkorb.de 11 Dec '15
by wbx@helium.waldemar-brodkorb.de 11 Dec '15
11 Dec '15
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "uClibc-ng - small C library for embedded systems".
The branch, 1.0 has been updated
via d1b81113b43a6d26dec4e0e58a380895d121006e (commit)
from 507f795a5969fcba5196236e706aecab5ee91dd9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d1b81113b43a6d26dec4e0e58a380895d121006e
Author: Waldemar Brodkorb <wbx(a)uclibc-ng.org>
Date: Fri Dec 11 09:02:22 2015 +0100
Revert "fix tst-signal7 failure"
This reverts commit ea21c7610aa1131b37a4533cf13dd89f727fb83f.
This was accidently pushed, before first coffee.
Sorry this is a bad commit.
-----------------------------------------------------------------------
Summary of changes:
libc/signal/sigaction.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/libc/signal/sigaction.c b/libc/signal/sigaction.c
index 0a02998..2560647 100644
--- a/libc/signal/sigaction.c
+++ b/libc/signal/sigaction.c
@@ -25,11 +25,6 @@
int
__libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
{
- if (unlikely (sig == SIGCANCEL || sig == SIGSETXID)) {
- __set_errno (EINVAL);
- return -1;
- }
-
/* NB: kernel (as of 2.6.25) will return EINVAL
* if sizeof(act->sa_mask) does not match kernel's sizeof(sigset_t).
* Try to catch this problem at uclibc build time: */
@@ -53,11 +48,6 @@ __libc_sigaction(int sig, const struct sigaction *act, struct sigaction *oact)
int result;
struct old_kernel_sigaction kact, koact;
- if (unlikely (sig == SIGCANCEL || sig == SIGSETXID)) {
- __set_errno (EINVAL);
- return -1;
- }
-
if (act) {
kact.k_sa_handler = act->sa_handler;
kact.sa_mask = act->sa_mask.__val[0];
hooks/post-receive
--
uClibc-ng - small C library for embedded systems
1
0