summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)AuthorLines
2014-06-02implement new dns backend, res_send and other legacy resolver functionsRich Felker-18/+263
this is the second phase of the "resolver overhaul" project. the key additions in this commit are the __res_msend and __res_mkquery functions, which have been factored so as to provide a backend for both the legacy res_* functions and the standard getaddrinfo and getnameinfo functions. the latter however are still using the old backend code; there is code duplication which still needs to be removed, and this will be the next phase of the resolver overhaul. __res_msend is derived from the old __dns_doqueries function, but generalized to send arbitrary caller-provided packets in parallel rather than producing the parallel queries itself. this allows it to be used (completely trivially) as a backend for res_send. the factored-out query generation code, with slightly more generality, is now part of __res_mkquery.
2014-06-02add ipsec and tunneling protocols to getprotoent-family functionsTimo Teräs-0/+4
iptables and ipsec-tools among others require these to function properly.
2014-06-02fix off-by-one in checking hostname length in new resolver backendRich Felker-2/+2
this bug was introduced in the recent resolver overhaul commits. it likely had visible symptoms. these were probably limited to wrongly accepting truncated versions of over-long names (vs rejecting them), as opposed to stack-based overflows or anything more severe, but no extensive checks were made. there have been no releases where this bug was present.
2014-06-01improve getservbyname_r using new resolver backendRich Felker-22/+16
now that host and service lookup have been separated in the backend, there's no need for service lookup functions to pull in the host lookup code. moreover, dynamic allocation is no longer needed, so this function should now be async-signal-safe. it's also significantly smaller. one change in getservbyname is also made: knowing that getservbyname_r needs only two character pointers in the caller-provided buffer, some wasted bss can be avoided.
2014-06-01improve gethostbyname2_r using new resolver backendRich Felker-35/+22
these changes reduce the size of the function somewhat and remove many of its dependencies, including free. in principle it should now be async-signal-safe, but this has not been verified in detail. minor changes to error handling are also made.
2014-05-31refactor getaddrinfo and add support for most remaining featuresRich Felker-228/+360
this is the first phase of the "resolver overhaul" project. conceptually, the results of getaddrinfo are a direct product of a list of address results and a list of service results. the new code makes this explicit by computing these lists separately and combining the results. this adds support for services that have both tcp and udp versions, where the caller has not specified which it wants, and eliminates a number of duplicate code paths which were all producing the final output addrinfo structures, but in subtly different ways, making it difficult to implement any of the features which were missing. in addition to the above benefits, the refactoring allows for legacy functions like gethostbyname to be implemented without using the getaddrinfo function itself. such changes to the legacy functions have not yet been made, however. further improvements include matching of service alias names from /etc/services (previously only the primary name was supported), returning multiple results from /etc/hosts (previously only the first matching line was honored), and support for the AI_V4MAPPED and AI_ALL flags. features which remain unimplemented are IDN translations (encoding non-ASCII hostnames for DNS lookup) and the AI_ADDRCONFIG flag. at this point, the DNS-based name resolving code is still based on the old interfaces in __dns.c, albeit somewhat simpler in its use of them. there may be some dead code which could already be removed, but changes to this layer will be a later phase of the resolver overhaul.
2014-05-30use cleaner code for handling float rounding in vfprintfSzabolcs Nagy-3/+1
CONCAT(0x1p,LDBL_MANT_DIG) is not safe outside of libc, use 2/LDBL_EPSILON instead. fix was proposed by Morten Welinder.
2014-05-30fix breakage from recent syscall commits due to missing errno macrosRich Felker-0/+3
2014-05-30fix for broken kernel side RLIM_INFINITY on mipsSzabolcs Nagy-3/+38
On 32 bit mips the kernel uses -1UL/2 to mark RLIM_INFINITY (and this is the definition in the userspace api), but since it is in the middle of the valid range of limits and limits are often compared with relational operators, various kernel side logic is broken if larger than -1UL/2 limits are used. So we truncate the limits to -1UL/2 in get/setrlimit and prlimit. Even if the kernel side logic consistently treated -1UL/2 as greater than any other limit value, there wouldn't be any clean workaround that allowed using large limits: * using -1UL/2 as RLIM_INFINITY in userspace would mean different infinity value for get/setrlimt and prlimit (where infinity is always -1ULL) and userspace logic could break easily (just like the kernel is broken now) and more special case code would be needed for mips. * translating -1UL/2 kernel side value to -1ULL in userspace would mean that -1UL/2 limit cannot be set (eg. -1UL/2+1 had to be passed to the kernel instead).
2014-05-30break down coarse-grained 64-bit-off_t syscall remappingsRich Felker-4/+16
using the existence of SYS_stat64 as the condition for remapping other related syscalls is no longer valid, since new archs that omit the old syscalls will not have SYS_stat or SYS_stat64, but still potentially need SYS_fstat and others remapped. it would probably be possible to get by with just one or two extra conditionals, but just breaking them all down into separate conditions is robust and not significantly heavier for the preprocessor.
2014-05-30additional fixes for linux kernel apis with old syscalls removedRich Felker-0/+9
2014-05-30fix sendfile syscall to use 64-bit off_tRich Felker-0/+5
somehow the remapping of this syscall to the 64-bit version was overlooked. the issue was found, and patch provided, by Stefan Kristiansson. presumably the reason this bug was not caught earlier is that the syscall takes a pointer to off_t rather than a value, so on little-endian systems, everything appears to work as long as the offset value fits in the low 31 bits. on big-endian systems, though, sendfile was presumably completely non-functional.
2014-05-29support linux kernel apis (new archs) with old syscalls removedRich Felker-29/+267
such archs are expected to omit definitions of the SYS_* macros for syscalls their kernels lack from arch/$ARCH/bits/syscall.h. the preprocessor is then able to select the an appropriate implementation for affected functions. two basic strategies are used on a case-by-case basis: where the old syscalls correspond to deprecated library-level functions, the deprecated functions have been converted to wrappers for the modern function, and the modern function has fallback code (omitted at the preprocessor level on new archs) to make use of the old syscalls if the new syscall fails with ENOSYS. this also improves functionality on older kernels and eliminates the incentive to program with deprecated library-level functions for the sake of compatibility with older kernels. in other situations where the old syscalls correspond to library-level functions which are not deprecated but merely lack some new features, such as the *at functions, the old syscalls are still used on archs which support them. this may change at some point in the future if or when fallback code is added to the new functions to make them usable (possibly with reduced functionality) on old kernels.
2014-05-29remove useless synchronization in exit and quick_exitRich Felker-11/+0
calling exit more than once invokes undefined behavior. in some cases it's desirable to detect undefined behavior and diagnose it via a predictable crash, but the code here was silently covering up an uncommon case (exit from more than one thread) and turning a much more common case (recursive calls to exit) into a permanent hang.
2014-05-27fix missing declaration of strcpy in implementation of tmpnamRich Felker-0/+1
2014-05-27overhaul tmpfile, tmpnam, and tempnam functionsRich Felker-55/+48
these all now use the shared __randname function internally, rather than duplicating logic for producing a random name. incorrect usage of the access syscall (which works with real uid/gid, not effective) has been removed, along with unnecessary heavy dependencies like snprintf.
2014-05-27fix sys_open macro for archs without the plain open syscallRich Felker-4/+4
2014-05-27fix placement of multiple inclusion guard endif in internal syscall.hRich Felker-2/+2
this was messed up during a recent commit when the socketcall macros were moved to the common internal/syscall.h, and the following commit expanded the problem by adding more new content outside the guard.
2014-05-26fix type of extended argument array to pselect6 syscallRich Felker-1/+2
this only matters on x32 (and perhaps future 32-on-64 abis for other archs); otherwise the type is long anyway. the cast through uintptr_t prevents nonsensical "sign extension" of pointers, and follows the principle that uintptr_t is the canonical integer type to which pointer conversion is safe.
2014-05-24support kernels with no SYS_open syscall, only SYS_openatRich Felker-10/+26
open is handled specially because it is used from so many places, in so many variants (2 or 3 arguments, setting errno or not, and cancellable or not). trying to do it as a function would not only increase bloat, but would also risk subtle breakage. this is the first step towards supporting "new" archs where linux lacks "old" syscalls.
2014-05-19fix unhandled cases in strptimeRich Felker-5/+16
%C, %U, %W, and %y handling were completely missing; %C wrongly fell-through to unrelated cases, and the rest returned failure. for now, they all parse numbers in the proper forms and range-check the values, but they do not store the value anywhere. it's not clear to me whether, as "derived" fields, %U and %W should produce any result. they certainly cannot produce a result unless the year and weekday are also converted, but in this case it might be desirable for them to do so. clarification is needed on the intended behavior of strptime in cases like this. %C and %y have well-defined behavior as long as they are used together (and %y is defined by itself but may change in the future). implementing them (including their correct interaction) is left as a later change to be made. finally, strptime now rejects unknown/invalid format characters instead of ignoring them.
2014-05-19remove unsupported nonstandard sysconf macros and their table entriesRich Felker-60/+0
some of these may have been from ancient (pre-SUSv2) POSIX versions; more likely, they were from POSIX drafts or glibc interpretations of what ancient versions of POSIX should have added (instead they made they described functionality mandatory and/or dropped it completely). others are purely glibc-isms, many of them ill-thought-out, like providing ways to lookup the min/max values of types at runtime (despite the impossibility of them changing at runtime and the impossibility of representing ULONG_MAX in a return value of type long). since our sysconf implementation does not support or return meaningful values for any of these, it's harmful to have the macros around; applications' build scripts may detect and attempt to use them, only to get -1/EINVAL as a result. if removing them does break some applications, and it's determined that the usage was reasonable, some of these could be added back on an as-needed basis, but they should return actual meaningful values, not junk like they were returning before.
2014-05-19rework sysconf table to treat zero entries as invalidRich Felker-10/+13
based on patch by Timo Teräs. previously, the value zero was used as a literal zero, meaning that all invalid sysconf "names", which should result in sysconf returning -1, had to be explicitly listed. (in addition, it was not possible for sysconf to set errno to EINVAL, as there was no distinction between -1 as an error and -1 as a valid result.) now, the value 0 is used for invalid/undefined slots in the table and a new switch table entry is used for returning literal zeros. in addition, an off-by-one error in checking against the table size is fixed.
2014-05-13add cp437 and cp850 to available iconv conversionsRich Felker-177/+206
perhaps some additional legacy DOS-era codepages would also be useful to have, but these are the ones for which there has been demand. the size of the diff is due to the fact that legacychars.h is updated in such a way that new characters are inserted into the table in unicode codepoint order; thus other mappings in codepages.h have changed to reflect the new table indices of their characters.
2014-05-08fix strftime %s not to zero pad with default width=2Szabolcs Nagy-0/+1
2014-05-04remove useless __yield alias for sched_yieldRich Felker-4/+1
this is no longer used for anything, and reportedly clashed with a builtin on certain compilers.
2014-04-22perform minimal sanity checks on zoneinfo files loaded via TZ variableRich Felker-0/+5
previously, setting TZ to the pathname of a file which was not a valid zoneinfo file would usually cause programs using local time zone based operations to crash. the new code checks the file size and magic at the beginning of the file, which seems sufficient to prevent accidental misconfiguration from causing crashes. attempting to make fully-robust validation would be futile unless we wanted to drop use of mmap (shared zoneinfo) and instead read it into a local buffer, since such validation would be subject to race conditions with modification of the file.
2014-04-22do not try to interpret implementation specific strings as tz definitionTimo Teräs-0/+1
2014-04-21make __init_libc static for non-shared libcRich Felker-0/+3
being static allows it to be inlined in __libc_start_main; inlining should take place at all levels since the function is called exactly once. this further reduces mandatory startup code size for static binaries.
2014-04-21further micro-optimize startup code for sizeRich Felker-23/+14
there is no reason (and seemingly there never was any) for __init_security to be its own function. it's linked unconditionally so it can just be placed inline in __init_libc.
2014-04-21micro-optimize some startup code for sizeRich Felker-7/+4
moving the call to __init_ssp from __init_security to __init_libc makes __init_security a leaf function, which allows the compiler to make it smaller. __init_libc is already non-leaf, and the additional call makes no difference to the amount of register spillage. in addition, it really made no sense for the call to __init_ssp to be buried inside __init_security rather than parallel with other init functions.
2014-04-21allow zoneinfo-path-relative filenames with no slashes in TZ variableRich Felker-12/+8
since the form TZ=name is reserved for POSIX-form time zone strings, TZ=:name needs to be used when the zoneinfo filename is in the top-level zoneinfo directory and therefore does not contain a slash. previously the leading colon was merely dropped, making it impossible to access such zones without a full absolute pathname. changes based on patch by Timo Teräs.
2014-04-20expose public execvpe interfaceM Farkas-Dyck-0/+3
2014-04-18fix false negatives with periodic needles in strstr, wcsstr, and memmemRich Felker-3/+3
in cases where the memorized match range from the right factor exceeded the length of the left factor, it was wrongly treated as a mismatch rather than a match. issue reported by Yves Bastide.
2014-04-17make socketcall types common as they are same for all architecturesTimo Teräs-0/+23
2014-04-16add options when explicitly invoking dynamic loaderRich Felker-2/+21
so far the options are --library-path and --preload which override the corresponding environment variables, and --list which forces the behavior of ldd even if the invocation name is not ldd. both the two-arg form and the one-arg form using an equals sign are supported. based loosely on a patch proposed by Rune.
2014-04-16add working vdso clock_gettime support, including static linkingRich Felker-5/+104
the vdso symbol lookup code is based on the original 2011 patch by Nicholas J. Kain, with some streamlining, pointer arithmetic fixes, and one symbol version matching fix. on the consumer side (clock_gettime), per-arch macros for the particular symbol name and version to lookup are added in syscall_arch.h, and no vdso code is pulled in on archs which do not define these macros. at this time, vdso is enabled only on x86_64. the vdso support at the dynamic linker level is no longer useful to libc, but is left in place for the sake of debuggers (which may need the vdso in the link map to find its functions) and possibly use with dlsym.
2014-04-15fix deadlock race in pthread_onceRich Felker-2/+1
at the end of successful pthread_once, there was a race window during which another thread calling pthread_once would momentarily change the state back from 2 (finished) to 1 (in-progress). in this case, the status was immediately changed back, but with no wake call, meaning that waiters which arrived during this short window could block forever. there are two possible fixes. one would be adding the wake to the code path where it was missing. but it's better just to avoid reverting the status at all, by using compare-and-swap instead of swap.
2014-04-15add _SC_PHYS_PAGES and _SC_AVPHYS_PAGES extentions to sysconfRich Felker-2/+17
2014-04-15add namespace-protected name for sysinfo functionRich Felker-6/+5
it will be needed to implement some things in sysconf, and the syscall can't easily be used directly because the x32 syscall uses the wrong structure layout. the l (uncreative, for "linux") prefix is used since the symbol name __sysinfo is already taken for AT_SYSINFO from the aux vector. the way the x32 override of this function works is also changed to be simpler and avoid the useless jump instruction.
2014-04-15in sysconf, use getrlimit function rather than raw syscall for rlimitsRich Felker-3/+3
the syscall is deprecated (replaced by prlimit64) and does not work correctly on x32. this change mildly increases size, but is likely needed anyway for newer archs that might omit deprecated syscalls.
2014-04-15avoid linear-time if/else special cases in sysconfRich Felker-20/+35
the previous handling of cases that could not fit in the 16-bit table or which required non-constant results was extremely ugly and could not scale. the new code remaps these keys into a contiguous range that's efficient for a switch statement.
2014-04-14fix fallback code for old kernels in clock_gettimeRich Felker-1/+1
2014-04-12use hidden visibility rather than protected for syscall internalsRich Felker-1/+1
the use of visibility at all is purely an optimization to avoid the need for the caller to load the GOT register or similar to prepare for a call via the PLT. there is no reason for these symbols to be externally visible, so hidden works just as well as protected, and using protected visibility is undesirable due to toolchain bugs and the lack of testing it receives. in particular, GCC's microblaze target is known to generate symbolic relocations in the GOT for functions with protected visibility. this in turn results in a dynamic linker which crashes under any nontrivial usage that requires making a syscall before symbolic relocations are processed.
2014-04-11math: fix aliasing violation in long double wrappersSzabolcs Nagy-2/+10
modfl and sincosl were passing long double* instead of double* to the wrapped double precision functions (on archs where long double and double have the same size). This is fixed now by using temporaries (this is not optimized to a single branch so the generated code is a bit bigger). Found by Morten Welinder.
2014-04-09fix search past the end of haystack in memmemTimo Teräs-0/+1
to optimize the search, memchr is used to find the first occurrence of the first character of the needle in the haystack before switching to a search for the full needle. however, the number of characters skipped by this first step were not subtracted from the haystack length, causing memmem to search past the end of the haystack.
2014-04-07fix printf rounding with %g for some corner case midpointsRich Felker-1/+1
the subsequent rounding code assumes the end pointer (z) accurately reflects the end of significance in the decimal expansion, but for certain large integers, spurious trailing zero slots were left behind when applying the binary exponent. issue reported by Morten Welinder; the analysis of the cause was performed by nsz, who also proposed this change.
2014-04-07add getauxval functionRich Felker-0/+12
in a sense this implementation is incomplete since it doesn't provide the HWCAP_* macros for use with AT_HWCAP, which is perhaps the most important intended usage case for getauxval. they will be added at a later time.
2014-04-07fix failure of printf %g to strip trailing zeros in some casesRich Felker-1/+1
the code to strip trailing zeros was only looking in the last slot for up to 9 zeros, assuming that the rounding code had already removed fully-zero slots from the end. however, this ignored cases where the rounding code did not run at all, which occur when the value being printed is exactly representable in the requested precision. the simplest solution is to move the code that strips trailing zero slots to run unconditionally, immediately after rounding, rather than as the last step of rounding.
2014-04-07fix carry into uninitialized slots during printf floating point roundingRich Felker-1/+1
in cases where rounding caused a carry, the slot into which the carry was taking place was unconditionally treated as valid, despite the possibility that it could be a new slot prior to the beginning of the existing non-rounded number. in theory this could lead to unbounded runaway carry, but in order for that to happen, the whole uninitialized buffer would need to have been pre-filled with 32-bit integer values greater than or equal to 999999999. patch based on proposed fix by Morten Welinder, who also discovered and reported the bug.