aboutsummaryrefslogtreecommitdiff
path: root/lib/libc
Commit message (Collapse)AuthorAgeFilesLines
* Improve size readability.Michael Reifenberger2021-02-151-3/+2
| | | | | | | | | | | Preserve more space for swap devise names. Prevent line overflow with long devise name. Don't draw a bar when swap is not used at all. Simplify and optimize code. Change the label to end at end of 100%. PR: 251655 MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D27496
* getdirentries.2: fix for NFS mountsRick Macklem2021-02-151-6/+8
| | | | | | | | | | | | | | | | | | | | It was reported that getdirentries(2) was returning dirents with d_off set to 0 for an NFS mount. This is believed to be correct behaviour at this time (it may change for some NFS mounts in the future), but is inconsistent with what the getdirentries(2) man page says. This patch fixes the man page. This is a content change. PR: 253428 Reviewed by: asomers MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D28664
* usleep(3): replace 'process' with 'calling thread'Konstantin Belousov2021-02-111-5/+5
| | | | | | | PR: 253395 Reported by: zegang.luo@qq.com MFC after: 3 days Sponsored by: The FreeBSD Foundation
* Revert "SO_RERROR indicates that receive buffer overflows should be handled ↵Alexander V. Chernikov2021-02-081-9/+1
| | | | | | | | as errors." Wrong version of the change was pushed inadvertenly. This reverts commit 4a01b854ca5c2e5124958363b3326708b913af71.
* SO_RERROR indicates that receive buffer overflows should be handled as errors.Alexander V. Chernikov2021-02-081-1/+9
| | | | | | | | | | | | Historically receive buffer overflows have been ignored and programs could not tell if they missed messages or messages had been truncated because of overflows. Since programs historically do not expect to get receive overflow errors, this behavior is not the default. This is really really important for programs that use route(4) to keep in sync with the system. If we loose a message then we need to reload the full system state, otherwise the behaviour from that point is undefined and can lead to chasing bogus bug reports.
* Restore the augmented strlen commentaryMateusz Guzik2021-02-081-11/+4
| | | | ... lost in revert
* Revert "Reimplement strlen"Mateusz Guzik2021-02-031-28/+54
| | | | | | | | | This reverts commit 710e45c4b8539d028877769f1a4ec088c48fb5f1. It breaks for some corner cases on big endian ppc64. Given the stage of the release process it is best to revert for now. Reported by: jhibbits
* libc: fix buffer overrun in getrpcport(3)Edward Tomasz Napierala2021-01-311-3/+3
| | | | | | | Reviewed By: markj Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D27332
* amd64: move memcmp checks upfrontMateusz Guzik2021-01-311-22/+28
| | | | | | | | | | | | | | | This is a tradeoff which saves jumps for smaller sizes while making the 8-16 range slower (roughly in line with the other cases). Tested with glibc test suite. For example size 3 (most common with vfs namecache) (ops/s): before: 407086026 after: 461391995 The regressed range of 8-16 (with 8 as example): before: 540850489 after: 461671032
* amd64: add a note about simd to libc memset, memmove and memcmpMateusz Guzik2021-01-313-0/+18
|
* Drop temporary compat in setproctitleMateusz Guzik2021-01-311-22/+2
|
* amd64: add missing ALIGN_TEXT to loops in memset and memmoveMateusz Guzik2021-01-302-0/+3
|
* Reimplement strlenMateusz Guzik2021-01-291-54/+28
| | | | | | | | | | | | | | | | | | | | | | | The previous code neglected to use primitives which can find the end of the string without having to branch on every character. While here augment the somewhat misleading commentary -- strlen as implemented here leaves performance on the table, especially so for userspace. Every arch should get a dedicated variant instead. In the meantime this commit lessens the problem. Tested with glibc test suite. Naive test just calling strlen in a loop on Haswell (ops/s): $(perl -e "print 'A' x 3"): before: 211198039 after: 338626619 $(perl -e "print 'A' x 100"): before: 83151997 after: 98285919
* Remove obsolete code gated on _ARM_ARCH_*Andrew Turner2021-01-282-69/+0
| | | | | | | This is all code only run on ARMv4 and ARMv5. Support for these have been dropped from FreeBSD. Differential Revision: https://reviews.freebsd.org/D28314
* Remove the old ARMv4 memcpyAndrew Turner2021-01-283-1652/+1371
| | | | | | | | | This was only used when building for ARMv4 or some ARMv5 or when _STANDALONE is defined. As ARMv4 and ARMv5 support has been removed, and we only define _STANDALONE in the bootloader where we don't use this version of memcpy we can remove it. Differential Revision: https://reviews.freebsd.org/D28313
* Remove leftover big-endian arm supportAndrew Turner2021-01-285-632/+0
| | | | | Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D28312
* libc: try to skip memcpy in _gettempMateusz Guzik2021-01-241-3/+8
|
* libc: remove open-coded strlen in _gettempMateusz Guzik2021-01-241-2/+1
|
* libc: skip spurious stat in _gettempMateusz Guzik2021-01-241-21/+0
| | | | | It was only done to catch ENOTDIR, but the kernel already returns the error where appropriate.
* libc/nss: Ensure that setgroupent(3) actually works as advertisedMark Johnston2021-01-211-0/+2
| | | | | | | | | | | Because the "files" and "compat" implementations failed to set the "stayopen", keyed lookups would close the database handle, contrary to the purpose of setgroupent(3). setpassent(3)'s implementation does not have this bug. PR: 165527 Submitted by: Andrey Simonenko MFC after: 1 month
* libc/nss tests: Add regression tests for commit 55444c823e1fMark Johnston2021-01-212-19/+93
| | | | | | PR: 252094 Sponsored by: The FreeBSD Foundation MFC after: 1 month
* libc/nss: Restore iterator state when doing passwd/group lookupsMark Johnston2021-01-212-26/+26
| | | | | | | | | | | | | | | | | | | | The getpwent(3) and getgrent(3) implementations maintain some internal iterator state. Interleaved calls to functions which do passwd/group lookups using a key, such as getpwnam(3), would in some cases clobber this state, causing a subsequent getpwent() or getgrent() call to restart iteration from the beginning of the database or to terminate early. This is particularly troublesome in programming environments where execution of green threads is interleaved within a single OS thread. Take care to restore any iterator state following a keyed lookup. The "files" provider for the passwd database was already handling this correctly, but "compat" was not, and both providers had this problem when accessing the group database. PR: 252094 Submitted by: Viktor Dukhovni <ietf-dane@dukhovni.org> MFC after: 1 month
* libc/nss tests: Fix getpw and getgr single-pass testsMark Johnston2021-01-212-32/+8
| | | | | | | | | Some NSS regression tests for getgrent(3) and getpwent(3) were not testing anything because the test incorrectly requested creation of a database snapshot. Sponsored by: The FreeBSD Foundation MFC after: 1 month
* libc/nss tests: StyleMark Johnston2021-01-213-36/+37
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 month
* x86: switch vdso TSC timecounter to RDTSCP on AMD Zen CPUsKonstantin Belousov2021-01-211-4/+1
| | | | | | | Reported by: many Tested by: gallatin, mikael, rhurlin MFC after: 1 week Sponsored by: The FreeBSD Foundation
* libc: Fix null pointer arithmetic warning in mergesortAlex Richardson2021-01-201-4/+2
| | | | | | | | | This file has other questionable code and "optimizations" (such as copying one int at a time) that are probably no longer useful, so it might make sense to replace it with a different implementation at some point. Reviewed By: jhb Differential Revision: https://reviews.freebsd.org/D28134
* Remove remaining uses of ${COMPILER_FEATURES:Mc++11}Alex Richardson2021-01-191-2/+0
| | | | | | | | | | All supported compilers have C++11 support so these checks can be replaced with MK_CXX guards. See also https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=252759 PR: 252759 Reviewed By: emaste Differential Revision: https://reviews.freebsd.org/D28234
* getopt: Fix conversion from string-literal to non-const char *Alex Richardson2021-01-192-4/+3
| | | | | | Define a non-const static char EMSG[] = "" to avoid having to add __DECONST() to all uses of EMSG. Also make current_dash a const char * to fix this warning.
* Save on getpid in setproctitle by supporting -1 as curproc.Mateusz Guzik2021-01-161-4/+24
|
* lio_listio: validate aio_lio_opcodeAlan Somers2021-01-121-1/+7
| | | | | | | | | | | | | | | Previously, we would accept any kind of LIO_* opcode, including ones that were intended for in-kernel use only like LIO_SYNC (which is not defined in userland). The situation became more serious with 022ca2fc7fe08d51f33a1d23a9be49e6d132914e. After that revision, setting aio_lio_opcode to LIO_WRITEV or LIO_READV would trigger an assertion. Note that POSIX does not specify what should happen if aio_lio_opcode is invalid. MFC-with: 022ca2fc7fe08d51f33a1d23a9be49e6d132914e Reviewed by: jhb, tmunro, 0mp Differential Revision: <https://reviews.freebsd.org/D28078
* libthr: wrap pdfork(2), same as fork(2).Konstantin Belousov2021-01-114-0/+50
| | | | | | | | | | Without wrapping, rtld services and malloc(3) are not guaranteed to operate correctly in the forked child. Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28088
* libc: implement rtld_get_stack_prot() for realKonstantin Belousov2021-01-101-1/+25
| | | | | | | | | | | | | | which makes stack prot correct for non-main threads created by binaries with statically linked libthr. Cache result, but do not engage into the full double-checked locking, since calculation of the return value is idempotent. PR: 252549 Reported and reviewed by: emaste MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28075
* x86 vdso gettc: Add RDTSCP supportKonstantin Belousov2021-01-101-0/+25
| | | | | | | | | | | Detect and use RDTSCP if available, instead of fence+RDTSC. For AMD Zens+, use LFENCE+RDTSC instead of RDTSCP (or MFENCE;RDTSC previously). Reviewed by: gallatin, markj Tested by: pho MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D27986
* x86 vdso gettc: eliminate duplicated code in ifunc selectors.Konstantin Belousov2021-01-101-22/+65
| | | | | | | | | | Create array of rdtsc selectors and provide helper that calculate the index into the selectors array. Reviewed by: gallatin, markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D27986
* x86 vdso gettc: reorganize ifunctions.Konstantin Belousov2021-01-101-21/+47
| | | | | | | | | | | Instead of providing ifuncs for each kind of fence, define ifuncs that combine fence and invocation of RDTSC. This refactoring makes introduction of RDTSCP use possible. Reviewed by: gallatin, markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D27986
* libc: regex: rework unsafe pointer arithmeticMiod Vallat2021-01-081-12/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | regcomp.c uses the "start + count < end" idiom to check that there are "count" bytes available in an array of char "start" and "end" both point to. This is fine, unless "start + count" goes beyond the last element of the array. In this case, pedantic interpretation of the C standard makes the comparison of such a pointer against "end" undefined, and optimizers from hell will happily remove as much code as possible because of this. An example of this occurs in regcomp.c's bothcases(), which defines bracket[3], sets "next" to "bracket" and "end" to "bracket + 2". Then it invokes p_bracket(), which starts with "if (p->next + 5 < p->end)"... Because bothcases() and p_bracket() are static functions in regcomp.c, there is a real risk of miscompilation if aggressive inlining happens. The following diff rewrites the "start + count < end" constructs into "end - start > count". Assuming "end" and "start" are always pointing in the array (such as "bracket[3]" above), "end - start" is well-defined and can be compared without trouble. As a bonus, MORE2() implies MORE() therefore SEETWO() can be simplified a bit. PR: 252403
* aio_fsync(2): Support O_DSYNC.Thomas Munro2021-01-081-4/+14
| | | | | | | aio_fsync(O_DSYNC, ...) is the asynchronous version of fdatasync(2). Reviewed by: kib, asomers, jhb Differential Review: https://reviews.freebsd.org/D25071
* open(2): Add O_DSYNC flag.Thomas Munro2021-01-082-9/+30
| | | | | | | | | | | | | | | POSIX O_DSYNC means that writes include an implicit fdatasync(2), just as O_SYNC implies fsync(2). VOP_WRITE() functions that understand the new IO_DATASYNC flag can act accordingly, but we'll still pass down IO_SYNC so that file systems that don't understand it will continue to provide the stronger O_SYNC behaviour. Flag also applies to fcntl(2). Reviewed by: kib, delphij Differential Revision: https://reviews.freebsd.org/D25090
* Rename NO_WERROR -> MK_WERROR=noAlex Richardson2021-01-071-1/+1
| | | | | | | | As suggested in D27598. This also supports MK_WERROR.clang=no and MK_WERROR.gcc=no to support the existing NO_WERROR.<compiler> uses. Reviewed By: brooks Differential Revision: https://reviews.freebsd.org/D27601
* Add aio_writev and aio_readvAlan Somers2021-01-036-24/+116
| | | | | | | | | | | | | | POSIX AIO is great, but it lacks vectored I/O functions. This commit fixes that shortcoming by adding aio_writev and aio_readv. They aren't part of the standard, but they're an obvious extension. They work just like their synchronous equivalents pwritev and preadv. It isn't yet possible to use vectored aiocbs with lio_listio, but that could be added in the future. Reviewed by: jhb, kib, bcr Relnotes: yes Differential Revision: https://reviews.freebsd.org/D27743
* copy_file_range(2): add recommendation to use large "len"Rick Macklem2021-01-031-1/+10
| | | | | | | | | | | | | PR#252358 reported a serious performance problem w.r.t. cp(1) when copying large non-sparse files. This problem appears to have been caused by cp(1) calling copy_file_range(2) with a small "len" argument. This patch adds a recommendation to use a large "len" value where possible, for performance reasons. Reviewed by: asomers Differential Revision: https://reviews.freebsd.org/D27935
* tcgetwinsize(3): provide man pageKonstantin Belousov2021-01-022-0/+166
| | | | | | | | The current POSIX.1-202x draft (1.1) was used as source material. Submitted by: Soumendra Ganguly <soumendraganguly@gmail.com> MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D27787
* libc: tests: add some tests for cpuset(2)Kyle Evans2020-12-312-0/+494
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The cpuset(2) tests should be run as root (require.user properly set) with >= 3 cpus for maximum coverage. All tests that want to modify the cpuset don't assume any particular cpu layout (i.e. the first cpu may not be 0, the last may not be first + count) and the following scenarios are tested: 1.) newset: basic execute cpuset() to grab a new cpuset, make sure the assigned cpuset then has a different ID. 2.) transient: create a new cpuset then assign the process its original cpuset, ensuring that the one we created is now gone. 3.) deadlk: test assigning an anonymous mask, then resetting the process base affinity with 1-cpu overlap w.r.t. the anonymous mask and with 0-cpu overlap w.r.t. the anonymous mask. 4.) jail_attach_newbase: process attaches to a jail with its own cpuset+mask (e.g. cpuset -c -l 1,2 jail -c path=/ command=/bin/sh) 5.) jail_attach_newbase_plain: process attaches to a jail with its own cpuset (e.g. cpuset -c jail -c path=/ command=/bin/sh) 6.) jail_attach_prevbase: process attaches to a jail with the containing jail's root cpuset (e.g. jail -c path=/ command=/bin/sh) 7.) jail_attach_plain: process attaches to a jail with the containing jail's root cpuset+mask. 8.) badparent: creates a new cpuset and modifies the anonymous thread mask, then setid's back to the original and checks that cpuset_getid() returns the expected set. Differential Revision: https://reviews.freebsd.org/D27307
* libc: tests: hook CPUSET(9) test up to the buildKyle Evans2020-12-311-1/+2
| | | | | | | | | Add shims to map NetBSD's API to CPUSET(9). Obviously the invalid input parts of these tests are relatively useless since we're just testing the shims that aren't used elsewhere, there's still some amount of value in the parts testing valid inputs. Differential Revision: https://reviews.freebsd.org/D27307
* eventfd.2: Add the mail address of the submitter into copyright.Konstantin Belousov2020-12-281-1/+1
| | | | | Requested by: rgrimes MFC after: 13 days
* Document eventfd().Konstantin Belousov2020-12-272-1/+219
| | | | | | | Submitted by: greg@unrelenting.technology Reviewed by: bcr, markj (previous version) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D26668
* kqueue(2): Use .Fo instead .FtKonstantin Belousov2020-12-271-1/+8
| | | | | MFC after: 3 days Sponsored by: The FreeBSD Foundation
* Add eventfd(3) wrappers to libc.Konstantin Belousov2020-12-275-0/+62
| | | | | | | | | eventfd_read/write one-liners are from musl libc. Submitted by: greg@unrelenting.technology Reviewed by: markj (previous version) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D26668
* Add tcgetwinsize(3) and tcsetwinsize(3) to termiosKonstantin Belousov2020-12-252-0/+16
| | | | | | | | | | | | | | These functions get/set tty winsize respectively, and are trivial wrappers around corresponding termio ioctls. The functions are expected to be a part of POSIX.1 issue 8: https://www.austingroupbugs.net/view.php?id=1151#c3856. They are currently available in NetBSD and in musl libc. PR: 251868 Submitted by: Soumendra Ganguly <soumendraganguly@gmail.com> MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D27650
* mmap(2): Update .Dd missed in the last commitGuangyuan Yang2020-12-241-1/+1
| | | | | PR: 252097 MFC after: 1 week