about summary refs log tree commit diff
path: root/src/internal
Commit message (Collapse)AuthorAgeFilesLines
* fix for broken kernel side RLIM_INFINITY on mipsSzabolcs Nagy2014-05-301-0/+4
| | | | | | | | | | | | | | | | | | | | 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).
* break down coarse-grained 64-bit-off_t syscall remappingsRich Felker2014-05-301-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.
* fix sendfile syscall to use 64-bit off_tRich Felker2014-05-301-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.
* fix sys_open macro for archs without the plain open syscallRich Felker2014-05-271-4/+4
|
* fix placement of multiple inclusion guard endif in internal syscall.hRich Felker2014-05-271-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.
* support kernels with no SYS_open syscall, only SYS_openatRich Felker2014-05-241-0/+18
| | | | | | | | | | 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.
* make socketcall types common as they are same for all architecturesTimo Teräs2014-04-171-0/+23
|
* add working vdso clock_gettime support, including static linkingRich Felker2014-04-161-0/+91
| | | | | | | | | | | | | | | | 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.
* use hidden visibility rather than protected for syscall internalsRich Felker2014-04-121-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.
* always initialize thread pointer at program startRich Felker2014-03-241-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | this is the first step in an overhaul aimed at greatly simplifying and optimizing everything dealing with thread-local state. previously, the thread pointer was initialized lazily on first access, or at program startup if stack protector was in use, or at certain random places where inconsistent state could be reached if it were not initialized early. while believed to be fully correct, the logic was fragile and non-obvious. in the first phase of the thread pointer overhaul, support is retained (and in some cases improved) for systems/situation where loading the thread pointer fails, e.g. old kernels. some notes on specific changes: - the confusing use of libc.main_thread as an indicator that the thread pointer is initialized is eliminated in favor of an explicit has_thread_pointer predicate. - sigaction no longer needs to ensure that the thread pointer is initialized before installing a signal handler (this was needed to prevent a situation where the signal handler caused the thread pointer to be initialized and the subsequent sigreturn cleared it again) but it still needs to ensure that implementation-internal thread-related signals are not blocked. - pthread tsd initialization for the main thread is deferred in a new manner to minimize bloat in the static-linked __init_tp code. - pthread_setcancelstate no longer needs special handling for the situation before the thread pointer is initialized. it simply fails on systems that cannot support a thread pointer, which are non-conforming anyway. - pthread_cleanup_push/pop now check for missing thread pointer and nop themselves out in this case, so stdio no longer needs to avoid the cancellable path when the thread pointer is not available. a number of cases remain where certain interfaces may crash if the system does not support a thread pointer. at this point, these should be limited to pthread interfaces, and the number of such cases should be fewer than before.
* include header that declares __syscall_ret where it's definedRich Felker2014-03-231-0/+1
| | | | | | | | | | | | in general, we aim to always include the header that's declaring a function before defining it so that the compiler can check that prototypes match. additionally, the internal syscall.h declares __syscall_ret with a visibility attribute to improve code generation for shared libc (to prevent gratuitous GOT-register loads). this declaration should be visible at the point where __syscall_ret is defined, too, or the inconsistency could theoretically lead to problems at link-time.
* rename superh port to "sh" for consistencyRich Felker2014-02-271-0/+0
| | | | | | | | | linux, gcc, etc. all use "sh" as the name for the superh arch. there was already some inconsistency internally in musl: the dynamic linker was searching for "ld-musl-sh.path" as its path file despite its own name being "ld-musl-superh.so.1". there was some sentiment in both directions as to how to resolve the inconsistency, but overall "sh" was favored.
* superh portBobby Bingham2014-02-231-0/+22
|
* mostly-cosmetic fixups to x32 port mergeRich Felker2014-02-231-5/+2
|
* import vanilla x86_64 code as x32rofl0r2014-02-231-0/+12
|
* internal/syscall.h: add syscall_arg_t macrorofl0r2014-02-221-6/+11
| | | | | | | some 32-on-64 archs require that the actual syscall args be long long. in that case syscall_arch.h can define syscall_arg_t to whatever it needs and syscall.h picks it up. all other archs just use long as usual.
* internal/syscall.h: use a macro for the syscall args castsrofl0r2014-02-221-13/+17
| | | | | | | this allows syscall_arch.h to define the macro __scc if special casting is needed, as is the case for x32, where the actual syscall arguments are 64bit, but, in case of pointers, would get sign-extended and thus become invalid.
* fix ftello result for append streams with unflushed outputRich Felker2014-02-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | when there is unflushed output, ftello (and ftell) compute the logical stream position as the underlying file descriptor's offset plus an adjustment for the amount of buffered data. however, this can give the wrong result for append-mode streams where the unflushed writes should adjust the logical position to be at the end of the file, as if a seek to end-of-file takes place before the write. the solution turns out to be a simple trick: when ftello (indirectly) calls lseek to determine the current file offset, use SEEK_END instead of SEEK_CUR if the stream is append-mode and there's unwritten buffered data. the ISO C rules regarding switching between reading and writing for a stream opened in an update mode, along with the POSIX rules regarding switching "active handles", conveniently leave undefined the hypothetical usage cases where this fix might lead to observably incorrect offsets. the bug being fixed was discovered via the test case for glibc issue
* include cleanups: remove unused headers and add feature test macrosSzabolcs Nagy2013-12-121-1/+0
|
* add infrastructure to record and report the version of libc.soRich Felker2013-12-011-0/+12
| | | | | | | this is still experimental and subject to change. for git checkouts, an attempt is made to record the exact revision to aid in bug reports and debugging. no version information is recorded in the static libc.a or binaries it's linked into.
* fix potential deadlock bug in libc-internal locking logicRich Felker2013-09-201-2/+2
| | | | | | | | | | | | | | | | | | | | if a multithreaded program became non-multithreaded (i.e. all other threads exited) while one thread held an internal lock, the remaining thread would fail to release the lock. the the program then became multithreaded again at a later time, any further attempts to obtain the lock would deadlock permanently. the underlying cause is that the value of libc.threads_minus_1 at unlock time might not match the value at lock time. one solution would be returning a flag to the caller indicating whether the lock was taken and needs to be unlocked, but there is a simpler solution: using the lock itself as such a flag. note that this flag is not needed anyway for correctness; if the lock is not held, the unlock code is harmless. however, the memory synchronization properties associated with a_store are costly on some archs, so it's best to avoid executing the unlock code when it is unnecessary.
* support configurable page size on mips, powerpc and microblazeSzabolcs Nagy2013-09-151-0/+6
| | | | | | | | | | | | | | | | PAGE_SIZE was hardcoded to 4096, which is historically what most systems use, but on several archs it is a kernel config parameter, user space can only know it at execution time from the aux vector. PAGE_SIZE and PAGESIZE are not defined on archs where page size is a runtime parameter, applications should use sysconf(_SC_PAGE_SIZE) to query it. Internally libc code defines PAGE_SIZE to libc.page_size, which is set to aux[AT_PAGESZ] in __init_libc and early in __dynlink as well. (Note that libc.page_size can be accessed without GOT, ie. before relocations are done) Some fpathconf settings are hardcoded to 4096, these should be actually queried from the filesystem using statfs.
* math: remove STRICT_ASSIGN macroSzabolcs Nagy2013-09-061-11/+0
| | | | | | | | | | | | | gcc did not always drop excess precision according to c99 at assignments before version 4.5 even if -std=c99 was requested which caused badly broken mathematical functions on i386 when FLT_EVAL_METHOD!=0 but STRICT_ASSIGN was not used consistently and it is worked around for old compilers with -ffloat-store so it is no longer needed the new convention is to get the compiler respect c99 semantics and when excess precision is not harmful use float_t or double_t or to specialize code using FLT_EVAL_METHOD
* math: remove libc.h include from libm.hSzabolcs Nagy2013-09-051-2/+0
| | | | libc.h is only for weak_alias so include it directly where it is used
* math: cosmetic cleanup (use explicit union instead of fshape and dshape)Szabolcs Nagy2013-09-051-66/+56
|
* math: remove *_WORD64 macros from libm.hSzabolcs Nagy2013-09-051-16/+0
| | | | only fma used these macros and the explicit union is clearer
* math: remove old longdbl.hSzabolcs Nagy2013-09-052-113/+0
|
* long double cleanup, initial commitSzabolcs Nagy2013-09-052-26/+28
| | | | | | | | new ldshape union, ld128 support is kept, code that used the old ldshape union was rewritten (IEEEl2bits union of freebsd libm is not touched yet) ld80 __fpclassifyl no longer tries to handle invalid representation
* fix multiple bugs in SIGEV_THREAD timersRich Felker2013-08-031-1/+1
| | | | | | | | | | | | | | | | | | 1. the thread result field was reused for storing a kernel timer id, but would be overwritten if the application code exited or cancelled the thread. 2. low pointer values were used as the indicator that the timer id is a kernel timer id rather than a thread id. this is not portable, as mmap may return low pointers on some conditions. instead, use the fact that pointers must be aligned and kernel timer ids must be non-negative to map pointers into the negative integer space. 3. signals were not blocked until after the timer thread started, so a race condition could allow a signal handler to run in the timer thread when it's not supposed to exist. this is mainly problematic if the calling thread was the only thread where the signal was unblocked and the signal handler assumes it runs in that thread.
* debloat code that depends on /proc/self/fd/%d with shared functionRich Felker2013-08-021-0/+13
| | | | | | | I intend to add more Linux workarounds that depend on using these pathnames, and some of them will be in "syscall" functions that, from an anti-bloat standpoint, should not depend on the whole snprintf framework.
* refactor headers, especially alltypes.h, and improve C++ ABI compatRich Felker2013-07-222-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the arch-specific bits/alltypes.h.sh has been replaced with a generic alltypes.h.in and minimal arch-specific bits/alltypes.h.in. this commit is intended to have no functional changes except: - exposing additional symbols that POSIX allows but does not require - changing the C++ name mangling for some types - fixing the signedness of blksize_t on powerpc (POSIX requires signed) - fixing the limit macros for sig_atomic_t on x86_64 - making dev_t an unsigned type (ABI matching goal, and more logical) in addition, some types that were wrongly defined with long on 32-bit archs were changed to int, and vice versa; this change is non-functional except for the possibility of making pointer types mismatch, and only affects programs that were using them incorrectly, and only at build-time, not runtime. the following changes were made in the interest of moving non-arch-specific types out of the alltypes system and into the headers they're associated with, and also will tend to improve application compatibility: - netdb.h now includes netinet/in.h (for socklen_t and uint32_t) - netinet/in.h now includes sys/socket.h and inttypes.h - sys/resource.h now includes sys/time.h (for struct timeval) - sys/wait.h now includes signal.h (for siginfo_t) - langinfo.h now includes nl_types.h (for nl_item) for the types in stdint.h: - types which are of no interest to other headers were moved out of the alltypes system. - fast types for 8- and 64-bit are hard-coded (at least for now); only the 16- and 32-bit ones have reason to vary by arch. and the following types have been changed for C++ ABI purposes; - mbstate_t now has a struct tag, __mbstate_t - FILE's struct tag has been changed to _IO_FILE - DIR's struct tag has been changed to __dirstream - locale_t's struct tag has been changed to __locale_struct - pthread_t is defined as unsigned long in C++ mode only - fpos_t now has a struct tag, _G_fpos64_t - fsid_t's struct tag has been changed to __fsid_t - idtype_t has been made an enum type (also required by POSIX) - nl_catd has been changed from long to void * - siginfo_t's struct tag has been removed - sigset_t's has been given a struct tag, __sigset_t - stack_t has been given a struct tag, sigaltstack - suseconds_t has been changed to long on 32-bit archs - [u]intptr_t have been changed from long to int rank on 32-bit archs - dev_t has been made unsigned summary of tests that have been performed against these changes: - nsz's libc-test (diff -u before and after) - C++ ABI check symbol dump (diff -u before, after, glibc) - grepped for __NEED, made sure types needed are still in alltypes - built gcc 3.4.6
* add support for init/fini array in main program, and greatly simplifyRich Felker2013-07-211-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | modern (4.7.x and later) gcc uses init/fini arrays, rather than the legacy _init/_fini function pasting and crtbegin/crtend ctors/dtors system, on most or all archs. some archs had already switched a long time ago. without following this change, global ctors/dtors will cease to work under musl when building with new gcc versions. the most surprising part of this patch is that it actually reduces the size of the init code, for both static and shared libc. this is achieved by (1) unifying the handling main program and shared libraries in the dynamic linker, and (2) eliminating the glibc-inspired rube goldberg machine for passing around init and fini function pointers. to clarify, some background: the function signature for __libc_start_main was based on glibc, as part of the original goal of being able to run some glibc-linked binaries. it worked by having the crt1 code, which is linked into every application, static or dynamic, obtain and pass pointers to the init and fini functions, which __libc_start_main is then responsible for using and recording for later use, as necessary. however, in neither the static-linked nor dynamic-linked case do we actually need crt1.o's help. with dynamic linking, all the pointers are available in the _DYNAMIC block. with static linking, it's safe to simply access the _init/_fini and __init_array_start, etc. symbols directly. obviously changing the __libc_start_main function signature in an incompatible way would break both old musl-linked programs and glibc-linked programs, so let's not do that. instead, the function can just ignore the information it doesn't need. new archs need not even provide the useless args in their versions of crt1.o. existing archs should continue to provide it as long as there is an interest in having newly-linked applications be able to run on old versions of musl; at some point in the future, this support can be removed.
* fix missing argument in variadic syscall macrosRich Felker2013-07-171-1/+1
| | | | | | for 0-argument syscalls (1 argument to the macro, the syscall number), the __SYSCALL_NARGS_X macro's ... argument was not satisfied. newer compilers seem to care about this.
* add some comments about the mips ksigaction structure weirdnessRich Felker2013-06-291-0/+3
|
* fix major scanf breakage with unbuffered streams, fmemopen, etc.Rich Felker2013-06-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | the shgetc api, used internally in scanf and int/float scanning code to handle field width limiting and pushback, was designed assuming that pushback could be achieved via a simple decrement on the file buffer pointer. this only worked by chance for regular FILE streams, due to the linux readv bug workaround in __stdio_read which moves the last requested byte through the buffer rather than directly back to the caller. for unbuffered streams and streams not using __stdio_read but some other underlying read function, the first character read could be completely lost, and replaced by whatever junk happened to be in the unget buffer. to fix this, simply have shgetc, when it performs an underlying read operation on the stream, store the character read at the -1 offset from the read buffer pointer. this is valid even for unbuffered streams, as they have an unget buffer located just below the start of the zero-length buffer. the check to avoid storing the character when it is already there is to handle the possibility of read-only buffers. no application-exposed FILE types are allowed to use read-only buffers, but sscanf and strto* may use them internally when calling functions which use the shgetc api.
* transition to using functions for internal signal blocking/restoringRich Felker2013-04-261-0/+4
| | | | | | | | | | there are several reasons for this change. one is getting rid of the repetition of the syscall signature all over the place. another is sharing the constant masks without costly GOT accesses in PIC. the main motivation, however, is accurately representing whether we want to block signals that might be handled by the application, or all signals.
* add support for program_invocation[_short]_nameRich Felker2013-04-061-0/+4
| | | | | | | | | | this is a bit ugly, and the motivation for supporting it is questionable. however the main factors were: 1. it will be useful to have this for certain internal purposes anyway -- things like syslog. 2. applications can just save argv[0] in main, but it's hard to fix non-portable library code that's depending on being able to get the invocation name without the main application's help.
* implement pthread_getattr_npRich Felker2013-03-311-0/+2
| | | | | | this function is mainly (purely?) for obtaining stack address information, but we also provide the detach state since it's easy to do anyway.
* remove __SYSCALL_SSLEN arch macro in favor of using public _NSIGRich Felker2013-03-261-3/+3
| | | | | | | | | | | | | | the issue at hand is that many syscalls require as an argument the kernel-ABI size of sigset_t, intended to allow the kernel to switch to a larger sigset_t in the future. previously, each arch was defining this size in syscall_arch.h, which was redundant with the definition of _NSIG in bits/signal.h. as it's used in some not-quite-portable application code as well, _NSIG is much more likely to be recognized and understood immediately by someone reading the code, and it's also shorter and less cluttered. note that _NSIG is actually 65/129, not 64/128, but the division takes care of throwing away the off-by-one part.
* consistently use the internal name __environ for environRich Felker2013-02-171-1/+0
| | | | | | | | | | | patch by Jens Gustedt. previously, the intended policy was to use __environ in code that must conform to the ISO C namespace requirements, and environ elsewhere. this policy was not followed in practice anyway, making things confusing. on top of that, Jens reported that certain combinations of link-time optimization options were breaking with the inconsistent references; this seems to be a compiler or linker bug, but having it go away is a nice side effect of the changes made here.
* replace __wake function with macro that performs direct syscallRich Felker2013-02-011-1/+2
| | | | | | | | | | | this should generate faster and smaller code, especially with inline syscalls. the conditional with cnt is ugly, but thankfully cnt is always a constant anyway so it gets evaluated at compile time. it may be preferable to make separate __wake and __wakeall macros without a count argument. priv flag is not used yet; private futex support still needs to be done at some point in the future.
* make CMPLX macros available in complex.h in non-c11 mode as wellSzabolcs Nagy2012-12-111-8/+0
|
* fix trailing whitespace issues that crept in here and thereRich Felker2012-12-071-1/+1
|
* Merge remote-tracking branch 'nsz/math'Rich Felker2012-11-151-23/+8
|\
| * math: turn off the STRICT_ASSIGN workaround by defaultSzabolcs Nagy2012-11-131-5/+3
| | | | | | | | | | | | | | | | | | the volatile hack in STRICT_ASSIGN is only needed if assignment is not respected and excess precision is kept. gcc -fexcess-precision=standard and -ffloat-store both respect assignment and musl use these flags by default. i kept the macro for now so the workaround may be used for bad compilers in the future.
| * complex: add C11 CMPLX macros and replace cpack with themSzabolcs Nagy2012-11-131-18/+5
| |
* | Merge remote-tracking branch 'ppc-port/ppc-squashed'Rich Felker2012-11-141-0/+18
|\ \ | |/ |/|
| * PPC port cleaned up, static linking works well now.rofl0r2012-11-132-24/+18
| |
| * import preliminary ppc work by rdp.Richard Pennington2012-11-131-0/+24
| |
* | add support for thread scheduling (POSIX TPS option)Rich Felker2012-11-111-0/+5
| | | | | | | | | | | | | | | | | | | | linux's sched_* syscalls actually implement the TPS (thread scheduling) functionality, not the PS (process scheduling) functionality which the sched_* functions are supposed to have. omitting support for the PS option (and having the sched_* interfaces fail with ENOSYS rather than omitting them, since some broken software assumes they exist) seems to be the only conforming way to do this on linux.