summaryrefslogtreecommitdiffstats
path: root/lib/libc/gen
Commit message (Collapse)AuthorAgeFilesLines
* MFC r320570 MFS r320822:kib2017-07-091-4/+5
| | | | | | Correct signatures of several pthreads stubs. Approved by: re (gjb)
* MFC r320052:kib2017-06-241-21/+25
| | | | | | Do not leak syslog_mutex on cancellation. Approved by: re (marius)
* MFC r318582vangyzen2017-06-012-3/+0
| | | | | | | | | | | Remove old spinlock_debug code from libc This no longer seems useful. Remove it. This was prompted by a "cast discards volatile qualifier" warning in libthr when WARNS=6. Sponsored by: Dell EMC
* MFC r318794, r318795:gjb2017-05-271-2/+2
| | | | | | Update the "first appeared in" version in several manual pages. Sponsored by: The FreeBSD Foundation
* MFC r317611:kib2017-05-071-5/+1
| | | | Make semaphore names list mutex non-recursive.
* MFC r317610:kib2017-05-071-12/+10
| | | | Restructure normal (non-error) control flow in sem_close().
* MFC r317606:kib2017-05-071-22/+25
| | | | Style.
* MFC r317436:kib2017-05-031-1/+1
| | | | getpagesize(3) cannot fail.
* MFC r317064: Optimize pathologic case of telldir() for Samba.mav2017-05-011-4/+14
| | | | | | | | | | When application reads large directory, calling telldir() for each entry, like Samba does, it creates exponential performance drop as number of entries reach tenths to hundreds of thousands. It is caused by full search through the internal list, that never finds matches in that scenario, but creates O(n^2) delays. This patch optimizes that search, limiting it to entries of the same buffer, turning time closer to O(n) in case of linear directory scan.
* MFC r317372:pfg2017-05-011-2/+1
| | | | | | | | | scandir(3): promote arraysz to size_t to match numitems. The internal array size goes through a loop and is compared with numitems which at its limits makes can be unreachably higher than arraysz. Prevent an hypothetical overflow, and signed/unsigned comparison, by matching the types.
* MFC r316768:brooks2017-04-241-0/+4
| | | | | | | | | | Fix an out-of-bounds write when a zero-length buffer is passed. Found with ttyname_test and CHERI bounds checking. Reviewed by: emaste Obtained from: CheriBSD Sponsored by: DARPA, AFRL
* MFC r316739:kib2017-04-191-6/+3
| | | | Fix reporting of _SC_SEM_NSEMS_MAX and _SC_SEM_VALUE_MAX.
* MFC r315162:pfg2017-04-074-9/+9
| | | | | | | | libc: provide some bounds-checking through reallocarray(3). reallocarray(3) is a non portable extension that originated in OpenBSD. Given that it is already in FreeBSD's libc it is useful for the cases where reallocation involves a multiplication.
* MFC r315734:ngie2017-03-301-5/+5
| | | | style(9): sort #includes
* MFC r315720 (from cem@)pfg2017-03-221-1/+1
| | | | | | | | | | | scandir: Fix NULL dereference, uninitialized value use in error case This bug was introduced in r315095. Given that it obviously is a bug and we can't afford to have such creatures in libc, do an early merge, Reported by: Coverity CIDs: 1329566, 1372625 Sponsored by: Dell EMC Isilon
* MFC r315095, r315096, r315097, r315187:pfg2017-03-152-11/+12
| | | | | | | | | | | | | | | | libc: small cleanups. Rename nitems to numitems: it shares the anme with an existing macro in sys/params.h. Also initialize the value later which avoids asigning the value if we exit early. Unsign setlen: it is local and will never be negative. Having one more bit for growth is beneficial and it avoids a cast when it's going to be used for allocation. Remove unused initialization: "num" is properly defined before use. Let calloc(3) do the multiplication.
* MFC r314179 r314206 r314424vangyzen2017-03-144-25/+95
| | | | | | | | | | | | | | | | | Add sem_clockwait_np() This function allows the caller to specify the reference clock and choose between absolute and relative mode. In relative mode, the remaining time can be returned. The API is similar to clock_nanosleep(3). Thanks to Ed Schouten for that suggestion. While I'm here, reduce the sleep time in the semaphore "child" test to greatly reduce its runtime. Also add a reasonable timeout. Relnotes: yes Sponsored by: Dell EMC
* MFC r315225:delphij2017-03-141-1/+1
| | | | | | | | Discard first 3072 bytes of RC4 keystream, this is a bandaid that allows us to work on switching to a more modern PRNG. Submitted by: Steven Chamberlain <steven pyro eu org> Approved by: so
* MFC r311954, r311996, r312077, r312080:ian2017-03-021-3/+30
| | | | | | | | | | | | | | | | | | | | | | | | | Rework tty_drain() to poll the hardware for completion, and restore drain timeout handling to historical freebsd behavior. The primary reason for these changes is the need to have tty_drain() call ttydevsw_busy() at some reasonable sub-second rate, to poll hardware that doesn't signal an interrupt when the transmit shift register becomes empty (which includes virtually all USB serial hardware). Such hardware hangs in a ttyout wait, because it never gets an opportunity to trigger a wakeup from the sleep in tty_drain() by calling ttydisc_getc() again, after handing the last of the buffered data to the hardware. Restructure the tty_drain loop so that device-busy is checked one more time after tty_timedwait() returns an error only if the error is EWOULDBLOCK; other errors cause an immediate return. This fixes the case of the tty disappearing while in tty_drain(). Check tty_gone() after allocating IO buffers. The tty lock has to be dropped then reacquired due to using M_WAITOK, which opens a window in which the tty device can disappear. Check for this and return ENXIO back up the call chain so that callers can cope. Correct the comments about how much buffer is allocated.
* MFC 310638:jhb2017-02-082-6/+6
| | | | | | | | | | Rename the 'flags' argument to getfsstat() to 'mode' and validate it. This argument is not a bitmask of flags, but only accepts a single value. Fail with EINVAL if an invalid value is passed to 'flag'. Rename the 'flags' argument to getmntinfo(3) to 'mode' as well to match. This is a followup to r308088.
* MFC r312332,r312446,r312451:ngie2017-02-041-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | r312332: Use SRCTOP where possible and use :H to manipulate .CURDIR to get rid of unnecessarily long relative path .PATH values with make r312446 (by emaste): libc: remove reference to nonexistent lib/locale directory As far as I can tell this was introduced in r72406 and updated in several subsequent revisions, but the lib/locale directory it referenced never existed. r312451: Replace dot-dot relative pathing with SRCTOP-relative paths where possible This reduces build output, need for recalculating paths, and makes it clearer which paths are relative to what areas in the source tree. The change in performance over a locally mounted UFS filesystem was negligible in my testing, but this may more positively impact other filesystems like NFS. LIBC_SRCTOP was left alone so Juniper (and other users) can continue to manipulate lib/libc/Makefile (and other Makefile.inc's under lib/libc) as include Makefiles with custom options. Discussed with: marcel, sjg
* MFC r309650:ed2016-12-202-2/+9
| | | | | | | | | Properly sign extend the result of jrand48() and mrand48(). These functions are supposed to return a value between [-2^31, 2^31). This doesn't seem to work on 64-bit systems, where we return a value between [0, 3^32). Patch up the function to use proper casts to int32_t. While there, fix some other style bugs.
* MFC r309006: remove unnecessary vm includes from setproctitleemaste2016-11-291-4/+0
| | | | | vm headers were needed only for the PS_STRINGS fallback, which was removed in r297888.
* MFC 308056: Fix formatting of tables.jhb2016-11-231-121/+121
| | | | | | | | | | | Specifically, use .Ta instead of tabs to separate column entries. While here fix a few other things: - Use .Sy for all column headers (previously only the first column header was bold) - Use .Dv to markup constants used for MIB names. - Use "1234" and "4321" for the byte order descriptions without thousands separators. - Mark up header files in the first table with .In.
* MFC r307037:kib2016-10-141-4/+3
| | | | Correct indent.
* MFC r307036:kib2016-10-141-0/+2
| | | | Fill msg_len for the initial element of msgvec.
* MFC r305154: directory(3): Deprecate readdir_r(). Clarify dirent buffers.jilles2016-09-071-2/+24
| | | | | | | | | | | | | | | In existing implementations including FreeBSD, there is no reason to use readdir_r() in the common case where potentially multiple threads each list their own directory. Code using readdir() is simpler. What's more, although readdir_r() can safely be used on FreeBSD because NAME_MAX is forced to 255, it cannot be used safely on systems where {NAME_MAX} is not fixed. As a concrete example, FAT/NTFS filenames can be up to 255 UTF-16 code units long, which can be up to 765 UTF-8 bytes. Deprecating readdir_r() in POSIX has been proposed in http://www.austingroupbugs.net/view.php?id=696 and glibc wants to deprecate it as well.
* MFC r305090: getvfsbyname(3): Remove [EFAULT] error.jilles2016-09-071-6/+1
| | | | | Since r101651 in 2002, getvfsbyname() has written *vfc using userland memcpy(), so the [EFAULT] error no longer occurs.
* MFC r302943,r302944,r303004,r303010,r303011,r303013,r303014,r303074,ache2016-08-172-203/+329
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | r303088,r303142,r303208,r303210,r303530,r303536,r303564,r303565, r303706 In short: 1) All situations with glob(3) error return codes are well defined by POSIX, so rewrite old sporadic errors processing to match those definitions. Including subcases: Both C99 and POSIX directly prohibits any standard function to set errno to 0. Breaking this rule in 2001 NetBSD hack was imported which attempts to workaround very limited glob(3) return codes amount. Use POSIX-compatible workaround now with E2BIG which can't comes from other functions used instead of prohibited 0. Process errors happpens in (*readdirfunc)() too, as POSIX requires. Per POSIX GLOB_NOCHECK should return original pattern, unmodified, if no matches found. But our code strips all '\' returning it. Rewrite the code to allow to return original pattern. GLOB_ERR and gl_errfunc are supposed to work only for real directories per POSIX, so don't act on missing or plain files for ENOENT or ENOTDIR (as TODO in the code suggested). Remove the hack in the manpage describing how to skip ENOENT and ENOTDIR in gl_errfunc, it is unneeded now. Per POSIX GLOB_ERR must be considered even if gl_errfunc is not set, old code skips it in that case. 2) For near MAXPATHLEN long pathes old glob(3) code can operate on truncated results, prevent it in several places. 3) Results was not sorted according to collate as POSIX requires. 4) globtilde() forget to convert expanded user home dir from multibyte to wide chars. Moreover, those chars are addded as not protected, so can be treated as special chars. 5) Backward hack for EILSEQ in g_Ctoc() was not implemented, so all pathes with illegal byte sequences are skipped as result, implement it now. 6) GLOB_BRACE was somehow broken. First it repeatedly calls glob0() in globexp1() recursive calls, but glob0() was not supposed to be called repeatedly in the original code. It finalize results by possible adding original pattern for no match case, may return GLOB_NOMATCH error and by sorting all things. Original pattern adding or GLOB_NOMATCH error can happens each time glob0() called repeatedly, and sorting happens for one item only, all things are never sorted. Second, f.e. "a{a" pattern does not match "a{a" file but match "a" file instead. Third, some errors (f.e. for limits or overflow) can be ignored by GLOB_BRACE code because it forces return (0). Add non-finalizing flag to glob0() and make globexp0() wrapper around recursively called globexp1() to finalize things like glob0() does. Reorganize braces code to work correctly. 7) Don't allow MB_CUR_MAX * strlen overallocation hits GLOB_LIMIT_STRING (ARG_MAX) limit, use final string length, not malloced space for it.
* MFC r302824ache2016-08-172-4/+4
| | | | | | | | | | | | | 1) Eliminate possibility to call __*collate_range_cmp() with inclomplete locale (which cause core dump) by removing whole 'table' argument by which it passed. 2) Restore __collate_range_cmp() in __sccl(). 3) Collating [a-z] range in regcomp() work only for single bytes locales (we can't do it now for other ones). In previous code only first 256 wchars are considered and all others are just silently dropped from the range.
* MFC r303687:bdrewery2016-08-081-0/+1
| | | | | | Add link for getnetgrent_r(3). Approved by: re (kib)
* MFC r303486:ed2016-08-052-7/+16
| | | | | | | | | | Mention that basename(3) and dirname(3) will change in the future. Update the existing manual pages for basename(3) and dirname(3) to mention that in future versions of FreeBSD, these functions will no longer use internal buffers for storing the results. Approved by: re@
* utimes(2),utime(3): Add deprecation in favour of utimensat(2) and futimens(2).jilles2016-06-091-2/+4
| | | | | | | Setting time by seconds or microseconds may cause unexpected effects especially if sysctl vfs.timestamp_precision=3 (not default). Calling the obsolete functions with NULL timestamps is acceptable.
* Implement an NSS backend for netgroups and add getnetgrent_r(3).markj2016-06-093-115/+470
| | | | | | | | | | | | | | | | | | This support appears to have been documented in nsswitch.conf(5) for some time. The implementation adds two NSS netgroup providers to libc. The default, compat, provides the behaviour documented in netgroup(5), so this change does not make any user-visible behaviour changes. A files provider is also implemented. innetgr(3) is implemented as an optional NSS method so that providers such as NIS which are able to implement efficient reverse lookup can do so. A fallback implementation is used otherwise. getnetgrent_r(3) is added for convenience and to provide compatibility with glibc and Solaris. With a small patch to net/nss_ldap, it's possible to specify an ldap netgroup provider, allowing one to query nisNetgroupTriple entries. Sponsored by: EMC / Isilon Storage Division
* Fix an infinite loop in setnetgrent(3) with NIS netgroups.markj2016-06-091-0/+4
| | | | | | | | | | Handle an empty result from yp_match() by returning NULL, which is consistent with the handling of an empty netgroup in /etc/netgroup. setnetgrent(3) has no return value, so there is no particular need to distinguish this case from an error. PR: 26486 MFC after: 2 weeks
* Use a more common spelling for "(char *)0" in the getnetgrent man page.markj2016-06-091-2/+2
| | | | MFC after: 3 days
* Update to a June 8th snapshot of (un)vis form NetBSD.brooks2016-06-081-0/+1
| | | | | | | | | | This adds stravis() and some new encoding flags VIS_SHELL, VIS_META, and VIS_NOLOCALE. Assorted cleanups and fixes includeing a manpage typo[0]. PR: 210013 [0] Submitted by: pi [0]
* Don't leak olinep if malloc() fails.truckman2016-06-081-0/+2
| | | | | | | | | | | If malloc() fails to allocate linep, then free olinep (if it exists) before returning to avoid a memory leak. Reported by: Coverity CID: 1016716 Reviewed by: kib MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D6755
* libc/locale: Fix type breakage in __collate_range_cmp().pfg2016-06-052-4/+4
| | | | | | | | | | | | | | | | When collation support was brought in, the second and third arguments in __collate_range_cmp() were changed from int to wchar_t, breaking the ABI. Change them to a "char" type which makes more sense and keeps the ABI compatible. Also introduce __wcollate_range_cmp() which does work with wide characters. This function is used only internally in libc so we don't export it. Use the new function in glob(3), fnmatch(3), and regexec(3). PR: 179721 Suggested by: ache. jilles MFC after: 3 weeks (perhaps partial only)
* Fix the signature of the psignal() function.ed2016-05-302-4/+4
| | | | | | | | POSIX 2008 added the psignal() function which has already been part of the BSDs for a long time. The only difference is, the POSIX version uses an 'int' for the signal number, unlike our version which uses an 'unsigned int'. Fix up the function to use an 'int'. This should not affect the ABI.
* Fix Coverity CID 1016714 Resource leak in process_file_actions_entry()truckman2016-05-251-3/+6
| | | | | | | | Don't leak a file descriptor of _dup2() fails (shouldn't happen). Reported by: Coverity CID: 1016714 MFC after: 1 week
* Fix 1016718 Resource leak.truckman2016-05-251-1/+3
| | | | | | | | Don't leak a file descriptor if fchdir() fails. Reported by: Coverity CID: 1016718 MFC after: 1 week
* FTS: Remove stale reference to nfs4 fs which was removed in r192578.bdrewery2016-05-212-2/+0
| | | | MFC after: 2 weeks
* Add implementation of robust mutexes, hopefully close enough to thekib2016-05-172-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013. A robust mutex is guaranteed to be cleared by the system upon either thread or process owner termination while the mutex is held. The next mutex locker is then notified about inconsistent mutex state and can execute (or abandon) corrective actions. The patch mostly consists of small changes here and there, adding neccessary checks for the inconsistent and abandoned conditions into existing paths. Additionally, the thread exit handler was extended to iterate over the userspace-maintained list of owned robust mutexes, unlocking and marking as terminated each of them. The list of owned robust mutexes cannot be maintained atomically synchronous with the mutex lock state (it is possible in kernel, but is too expensive). Instead, for the duration of lock or unlock operation, the current mutex is remembered in a special slot that is also checked by the kernel at thread termination. Kernel must be aware about the per-thread location of the heads of robust mutex lists and the current active mutex slot. When a thread touches a robust mutex for the first time, a new umtx op syscall is issued which informs about location of lists heads. The umtx sleep queues for PP and PI mutexes are split between non-robust and robust. Somewhat unrelated changes in the patch: 1. Style. 2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared pi mutexes. 3. Removal of the userspace struct pthread_mutex m_owner field. 4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls the lifetime of the shared mutex associated with a vnode' page. Reviewed by: jilles (previous version, supposedly the objection was fixed) Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects) Tested by: pho Sponsored by: The FreeBSD Foundation
* Remove trailing whitespace and use `nitems(mib)` instead of `2` whenngie2016-04-191-2/+2
| | | | | | | calling sysctl(3) MFC after: 3 days Sponsored by: EMC / Isilon Storage Division
* libc: do not include <sys/types.h> where <sys/param.h> was already includedavos2016-04-185-7/+2
| | | | | | According to style(9): > normally, include <sys/types.h> OR <sys/param.h>, but not both. (<sys/param.h> already includes <sys/types.h> when LOCORE is not defined).
* Re-use our roundup2() macro instead of reinventing the wheel.pfg2016-04-181-6/+4
| | | | Obtained from: DragonflyBSD
* libc: make some more use of the nitems() macro.pfg2016-04-162-2/+2
| | | | | | | | We have an nitems() macro in the <sys/param.h> header that is convenient to re-use as it makes things easier to read. Given that it is available already without adding additional headers and other parts of libc already use it, extend a bit more its use.
* Remove PS_STRINGS fallback from setproctitleemaste2016-04-121-1/+1
| | | | | | | | In r103767 the kern.ps_strings sysctl was added as the preferred way to locate the ps_strings struct and is available in any FreeBSD release supported within the last decade. Reviewed by: kib
* libc: replace 0 with NULL for pointers.pfg2016-04-104-8/+8
| | | | | | | | | While here also cleanup some surrounding code; particularly drop some malloc() casts. Found with devel/coccinelle. Reviewed by: bde (previous version - all new bugs are mine)
OpenPOWER on IntegriCloud