aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/gen
Commit message (Collapse)AuthorAgeFilesLines
* timespec_get(3): sort SEE ALSO correctlyEnji Cooper2020-12-111-1/+1
| | | | | | | | | | | clock_gettime(2) should be mentioned before gettimeofday(2). Reported by: make manlint MFC after: 1 week Sponsored by: DellEMC Isilon Notes: svn path=/head/; revision=368547
* posix_spawn(3): fix section that references `vfork`Enji Cooper2020-12-111-1/+3
| | | | | | | | | | | | | `vfork(2)` should be referenced in paragraphs as `.Fn vfork`, not `vfork()`. This change switches the reference to use `.Fn`, which in turn makes the manpage `make manlint` clean. MFC after: 1 week Reported by: make manlint Sponsored by: DellEMC Isilon Notes: svn path=/head/; revision=368534
* getentropy(3): sort SEE ALSO sectionsEnji Cooper2020-12-111-1/+1
| | | | | | | | | | | | Sorting order should be done by manpage section (2 vs 3), then alphabetically. This change fixes the order to sort by the manpage section, first. Reported by: make manlint MFC after: 1 week Sponsored by: DellEMC Isilon Notes: svn path=/head/; revision=368533
* arc4random(3): fix .Xr issuesEnji Cooper2020-12-111-2/+2
| | | | | | | | | | | | | - pthreads(3) should actually be pthread(3). - getentropy(2) should actually be getentropy(3). This makes the manpage `make manlint` clean. MFC after: 1 week Sponsored by: DellEMC Isilon Notes: svn path=/head/; revision=368532
* Remove trailing whitespace.Cy Schubert2020-12-031-4/+4
| | | | | | | MFC after: 1 week Notes: svn path=/head/; revision=368294
* libc: Add pthread_attr_get_np(3) stub, reporting ESRCH.Konstantin Belousov2020-11-282-0/+10
| | | | | | | | | | | | | | | This seems to be required by recent clang asan. I do not see other way than put the symbol under FBSD_1.0 version. PR: 251112 Reported by: Andrew Stitcher <astitcher@apache.org> Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D27389 Notes: svn path=/head/; revision=368125
* Remove stray column.Konstantin Belousov2020-11-261-1/+1
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 3 days Notes: svn path=/head/; revision=368083
* Use designated initializers for libc pthread stubs' jump table.Konstantin Belousov2020-11-251-67/+67
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=368023
* Add a missing Nm macroMateusz Piotrowski2020-11-131-0/+1
| | | | | | | | All functions documented in a manual page should be enumerated with the Nm macros. Notes: svn path=/head/; revision=367641
* Reference setprogname(3) in setproctitle(3)Mateusz Piotrowski2020-11-131-1/+2
| | | | | | | | | | The reference to setproctitle(3) in the setprogname(3) manual is already in place. MFC after: 3 days Notes: svn path=/head/; revision=367639
* Re-arrange some of the code to separate writable user tree variables fromStefan Eßer2020-11-021-28/+27
| | | | | | | | | | | R/O variables. While here fix some nearby style. No functional change intended. MFC after: 1 month Notes: svn path=/head/; revision=367280
* Make sysctl user.local a tunable that can be written at run-timeStefan Eßer2020-10-311-10/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | This sysctl value had been provided as a read-only variable that is compiled into the C library based on the value of _PATH_LOCALBASE in paths.h. After this change, the value is compiled into the kernel as an empty string, which is translated to _PATH_LOCALBASE by the C library. This empty string can be overridden at boot time or by a privileged user at run time and will then be returned by sysctl. When set to an empty string, the value returned by sysctl reverts to _PATH_LOCALBASE. This update does not change the behavior on any system that does not modify the default value of user.localbase. I consider this change as experimental and would prefer if the run-time write permission was reconsidered and the sysctl variable defined with CLFLAG_RDTUN instead to restrict it to be set at boot time. MFC after: 1 month Notes: svn path=/head/; revision=367243
* Fix reversed condition after attempted style fix in r367196Stefan Eßer2020-10-311-2/+2
| | | | | | | | Reported by: xtouqh@hotmail.com MFC after: 3 days Notes: svn path=/head/; revision=367199
* Fix style, no functional changeStefan Eßer2020-10-311-5/+5
| | | | | | | | Submitted by: kib MFC after: 3 days Notes: svn path=/head/; revision=367196
* Update man-pages to describe the user.localbase variable added in r367179.Stefan Eßer2020-10-301-1/+5
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=367184
* Add read only sysctl variable user.localbaseStefan Eßer2020-10-301-0/+9
| | | | | | | | | | | | The value is provided by the C library as for other sysctl variables in the user tree. It is compiled in and returns the value of _PATH_LOCALBASE defined in paths.h. Reviewed by: imp, scottl Differential Revision: https://reviews.freebsd.org/D27009 Notes: svn path=/head/; revision=367179
* warnx: fix needless staticWarner Losh2020-10-241-2/+2
| | | | | | | | | I noticed after the review that these shouldn't be static. Remove the 'static' from them, otherwise concurrent calls to warn* might see a similar but to the original. Notes: svn path=/head/; revision=366983
* warnx: Save errno across calls that might change it.Warner Losh2020-10-231-0/+8
| | | | | | | | | | | | | | | When warn() family of functions is being used after err_set_file() has been set to, for example, /dev/null, errno is being clobbered, rendering it unreliable after, for example, procstat_getpathname() when it is supposed to emit a warning. Then the errno is changed to Inappropriate ioctl for device, destroying the original value (via calls to fprintf()functions). Submitted by: Juraj Lutter Differential Revision: https://reviews.freebsd.org/D26871 Notes: svn path=/head/; revision=366982
* Fix building on Linux/macOS after r366622Alex Richardson2020-10-122-1/+13
| | | | | | | | | | | We have to bootstrap arc4random.c, so guard the FenestrasX code to avoid using it on Linux/macOS. Reviewed By: cem Differential Revision: https://reviews.freebsd.org/D26738 Notes: svn path=/head/; revision=366632
* random(4) FenestrasX: Push root seed version to arc4random(3)Conrad Meyer2020-10-103-0/+120
| | | | | | | | | | | | | | | | | | | | | | | | | | Push the root seed version to userspace through the VDSO page, if the RANDOM_FENESTRASX algorithm is enabled. Otherwise, there is no functional change. The mechanism can be disabled with debug.fxrng_vdso_enable=0. arc4random(3) obtains a pointer to the root seed version published by the kernel in the shared page at allocation time. Like arc4random(9), it maintains its own per-process copy of the seed version corresponding to the root seed version at the time it last rekeyed. On read requests, the process seed version is compared with the version published in the shared page; if they do not match, arc4random(3) reseeds from the kernel before providing generated output. This change does not implement the FenestrasX concept of PCPU userspace generators seeded from a per-process base generator. That change is left for future discussion/work. Reviewed by: kib (previous version) Approved by: csprng (me -- only touching FXRNG here) Differential Revision: https://reviews.freebsd.org/D22839 Notes: svn path=/head/; revision=366622
* auxv: partially revert r366207, cast buflen to unsigned int as neededKyle Evans2020-10-011-17/+15
| | | | | | | | | | | | | | | | | | | | | | | The warning generated pre-r366207 is actually a sign comparison warning: error: comparison of integers of different signs: 'unsigned long' and 'int' if (strlcpy(buf, execpath, buflen) >= buflen) Revert parts that affected other lines and just cast this to unsigned int. The buflen < 0 -> EINVAL has been kept despite no longer serving any purposes w.r.t. sign-extension because I do believe it's the right thing to do: "The provided buffer was not the right size for the requested item." The original warning is confirmed to still be gone with an: env WARNS=6 make WITHOUT_TESTS=yes. Reviewed by: asomers, kib X-MFC-With: r366207 Differential Revision: https://reviews.freebsd.org/D26631 Notes: svn path=/head/; revision=366342
* Eliminate duplicate `afterinstallconfigs` targetEnji Cooper2020-10-011-1/+2
| | | | | | | | | | | | | | | | | Define separate dependent targets which `afterinstallconfigs` relies on, in order to modify `${DESTDIR}/etc/master.passwd` and `${DESTDIR}/etc/nsswitch.conf`. Mark these targets .PHONY, since they manipulate configurations on the fly and the generation logic isn't 100% defined in terms of the source files/logic, and is variable, based on MK_foo flags. MFC after: 2 weeks Reviewed by: bapt, brd Differential Revision: https://reviews.freebsd.org/D20330 Notes: svn path=/head/; revision=366327
* Misc compiler warning fixes in lib/libcAlan Somers2020-09-277-17/+36
| | | | | | | | | Reviewed by: kevans, imp MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D26534 Notes: svn path=/head/; revision=366207
* fix integer underflow in getgrnam_r and getpwnam_rAlan Somers2020-09-192-4/+24
| | | | | | | | | | | | | | | | | | | Sometimes nscd(8) will return a 1-byte buffer for a nonexistent entry. This triggered an integer underflow in grp_unmarshal_func, causing getgrnam_r to return ERANGE instead of 0. Fix the user's buffer size check, and add a correct check for a too-small nscd buffer. PR: 248932 Event: September 2020 Bugathon Reviewed by: markj MFC after: 2 weeks Sponsored by: Axcient Differential Revision: https://reviews.freebsd.org/D26204 Notes: svn path=/head/; revision=365910
* getlogin_r: fix the type of lenKyle Evans2020-09-092-2/+12
| | | | | | | | | | | | | | | | | | | | | | getlogin_r is specified by POSIX to to take a size_t len, not int. Fix our version to do the same, bump the symbol version due to ABI change and provide compat. This was reported to break compilation of Ruby 2.8. Some discussion about the necessity of the ABI compat did take place in the review. While many 64-bit platforms would likely be passing it in a 64-bit register and zero-extended and thus, not notice ABI breakage, some do sign-extend (e.g. mips). PR: 247102 Submitted by: Bertram Scharpf <software@bertram-scharpf.de> (original) Submitted by: cem (ABI compat) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D26335 Notes: svn path=/head/; revision=365506
* Don't assume objects in program sections have a size of a pointer.John Baldwin2020-09-021-1/+1
| | | | | | | | | | | | | | | | | The size of the object at 'addr' is unknown and might be smaller than the size of a pointer (e.g. some x86 instructions are smaller than a pointer). Instead, just check that the address is in the bounds of the program header. Reported by: CHERI (indirectly) Reviewed by: kib, brooks Obtained from: CheriBSD MFC after: 1 week Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D26279 Notes: svn path=/head/; revision=365278
* Fix the build of scandir_b with GCC.John Baldwin2020-08-311-4/+7
| | | | | | | | | | | Use explicit typedefs for block thunk structures as in r264143. Reviewed by: kib, adrian MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D26256 Notes: svn path=/head/; revision=365012
* Add missing FreeBSD functions to -legacy when building on macOS/LinuxAlex Richardson2020-08-251-1/+3
| | | | | | | | | | | | | | | | In most cases this simply builds the file from lib/libc for missing functions (e.g. strlcpy on Linux etc.). In cases where this is not possible I've added an implementation to tools/build/cross-build. The fgetln.c/fgetwln.c/closefrom.c compatibility code was obtained from https://gitlab.freedesktop.org/libbsd/libbsd, but I'm not sure it makes sense to import it into to contrib just for these three bootstrap files. Reviewed By: brooks Differential Revision: https://reviews.freebsd.org/D25978 Notes: svn path=/head/; revision=364759
* libc: hide alphasort_thunk behind I_AM_SCANDIR_BMateusz Guzik2020-08-231-0/+2
| | | | | | | | Should unbreak gcc build as reported by tinderbox: lib/libc/gen/scandir.c:59:12: warning: 'alphasort_thunk' declared 'static' but never defined [-Wunused-function] Notes: svn path=/head/; revision=364500
* dl_iterate_phdr(3): provide exclusive locking for callback when statically ↵Konstantin Belousov2020-08-201-2/+8
| | | | | | | | | | | | | | | linked. Apparently llvm unwinder depends on the external locking for callback. Reviewed by: cem, emaste Tested by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D26109 Notes: svn path=/head/; revision=364423
* scandir-compat11.c: Remove unused declaration for qsort_b().Konstantin Belousov2020-08-171-2/+0
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 0 days Notes: svn path=/head/; revision=364322
* syslog(3): Send proper NILVALUE if gethostname(3) fails.Bryan Drewery2020-08-141-7/+16
| | | | | | | | | | | | RFC5424 defines NILVALUE as '-'. Replace its usage with a macro and separate out the fields to be more clear. fputs(3) is used in some places to avoid hiding possible format string problems in a macro. Reviewed by: cem, vangyzen (earlier version) Sponsored by: Dell EMC Notes: svn path=/head/; revision=364223
* Export scandir_b from libc.Konstantin Belousov2020-08-104-25/+14
| | | | | | | | | | | | | | | | | | Apparently it was not exported, because scandir_b.c was not included into libc SRCS. Export it with the CURRENT-13 version. Also, because it was not exported before ino64, clean up scandir-compat11.c. PR: 248572 Reported by: Alex S <iwtcex@gmail.com> Reviewed by: emaste Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D26020 Notes: svn path=/head/; revision=364091
* directory(3): Add an ERRORS sectionGordon Bergling2020-08-041-2/+72
| | | | | | | | | | | | | | | | | | - Add an ERRORS section for opendir(3) and closedir(3) - Document also the errors of readdir(3), readdir_r(3) and telldir(3) - Convert the code sample into an EXAMPLES section PR: 75711 Submitted by: abc <abc at ai1 dot anchorage dot mtaonline dot net> Reviewed by: 0mp, bcr, jilles Approved by: 0mp, bcr, jilles Obtained from: partial from OpenBSD MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25892 Notes: svn path=/head/; revision=363829
* Add SOL_LOCAL symbolic constant for unix socket option level.Konstantin Belousov2020-08-031-1/+1
| | | | | | | | | | | | | The constant seems to exists on MacOS X >= 10.8. Requested by: swills Reviewed by: allanjude, kevans Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D25933 Notes: svn path=/head/; revision=363813
* Allow building setmode.c on Linux/macOSAlex Richardson2020-08-031-4/+5
| | | | | | | | | | | | | | We bootstrap this file to allow compiling FreeBSD on Linux systems since some boostrap tools use setmode(). Unfortunately, glibc's sys/stat.h declares a non-static getumask() function (which is unimplemented!) and that conflicts with the local getumask() function. To work around this simply use a different name here. Reviewed By: brooks, emaste Differential Revision: https://reviews.freebsd.org/D25929 Notes: svn path=/head/; revision=363805
* Don't imply that all action values can be OR'd.Brooks Davis2020-07-151-10/+11
| | | | | | | | | | | | | | This is neither POSIX compliant nor what the implementation does. This could be allowed by changing the value of TCSAFLUSH from 2 to 3, but that doesn't seem worthwhile after 25+ years. Reviewed by: imp MFC after: 1 week Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D25659 Notes: svn path=/head/; revision=363228
* gethostname(3): Correct the reference of the undefined value HOST_NAME_MAXGordon Bergling2020-07-131-4/+4
| | | | | | | | | | | | | PR: 143472 Submitted by: bcran@ Reported by: Jeremy Huddleston <jeremyhu at apple dot com> Reviewed by: bcr (mentor) Approved by: bcr (mentor) MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25647 Notes: svn path=/head/; revision=363147
* Fix pointer name to match the name used in the function prototypeMarc Fonvieille2020-06-161-7/+7
| | | | | | | | | above (and in termios.c). Discussed with: Rodney W. Grimes <rgrimes@FreeBSD.org> Notes: svn path=/head/; revision=362232
* libcasper(3): Document HISTORY within the manpagesGordon Bergling2020-06-162-2/+11
| | | | | | | | | | Reviewed by: bcr (mentor) Approved by: bcr (mentor) MFC after: 7 days Differential Revision: https://reviews.freebsd.org/D24695 Notes: svn path=/head/; revision=362230
* posix_spawn: fix for some custom allocator setupsKyle Evans2020-06-121-1/+11
| | | | | | | | | | | | | | | | | | | | libc cannot assume that aligned_alloc and free come from jemalloc, or that any application providing its own malloc and free is actually providing aligned_alloc. Switch back to malloc and just make sure we're passing a properly aligned stack into rfork_thread, as an application perhaps can't reasonably replace just malloc or just free without headaches. This unbreaks ksh93 after r361996, which provides malloc/free but no aligned_alloc. Reported by: freqlabs Diagnosed by: Andrew Gierth <andrew_tao173.riddles.org.uk> X-MFC-With: r361996 Notes: svn path=/head/; revision=362111
* execvPe: obviate the need for potentially large stack allocationsKyle Evans2020-06-102-20/+59
| | | | | | | | | | | | | | | | | | | | | | | | | | | Some environments in which execvPe may be called have a limited amount of stack available. Currently, it avoidably allocates a segment on the stack large enough to hold PATH so that it may be mutated and use strsep() for easy parsing. This logic is now rewritten to just operate on the immutable string passed in and do the necessary math to extract individual paths, since it will be copying out those segments to another buffer anyways and piecing them together with the name for a full path. Additional size is also needed for the stack in posix_spawnp(), because it may need to push all of argv to the stack and rebuild the command with sh in front of it. We'll make sure it's properly aligned for the new thread, but future work should likely make rfork_thread a little easier to use by ensuring proper alignment. Some trivial cleanup has been done with a couple of error writes, moving strings into char arrays for use with the less fragile sizeof(). Reported by: Andrew Gierth <andrew_tao173.riddles.org.uk> Reviewed by: jilles, kib, Andrew Gierth MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D25038 Notes: svn path=/head/; revision=361996
* execvp: fix up the ENOEXEC fallbackKyle Evans2020-06-101-4/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If execve fails with ENOEXEC, execvp is expected to rebuild the command with /bin/sh instead and try again. The previous version did this, but overlooked two details: argv[0] can conceivably be NULL, in which case memp would never get terminated. We must allocate no less than three * sizeof(char *) so we can properly terminate at all times. For the non-NULL argv standard case, we count all the non-NULL elements and actually skip the first argument, so we end up capturing the NULL terminator in our bcopy(). The second detail is that the spec is actually worded such that we should have been preserving argv[0] as passed to execvp: "[...] executed command shall be as if the process invoked the sh utility using execl() as follows: execl(<shell path>, arg0, file, arg1, ..., (char *)0); where <shell path> is an unspecified pathname for the sh utility, file is the process image file, and for execvp(), where arg0, arg1, and so on correspond to the values passed to execvp() in argv[0], argv[1], and so on." So we make this change at this time as well, while we're already touching it. We decidedly can't preserve a NULL argv[0] as this would be incredibly, incredibly fragile, so we retain our legacy behavior of using "sh" for argv[] in this specific instance. Some light tests are added to try and detect some components of handling the ENOEXEC fallback; posix_spawnp_enoexec_fallback_null_argv0 is likely not 100% reliable, but it at least won't raise false-alarms and it did result in useful failures with pre-change libc on my machine. This is a secondary change in D25038. Reported by: Andrew Gierth <andrew_tao173.riddles.org.uk> Reviewed by: jilles, kib, Andrew Gierth MFC after: 1 week Notes: svn path=/head/; revision=361995
* Implement Solaris-like link_map l_refname member.Konstantin Belousov2020-05-221-1/+7
| | | | | | | | | | | The implementation is based on the public documentation, in particular dlinfo(3) from Solaris. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=361398
* Restore the binary compatibility for link_map l_addr.Konstantin Belousov2020-05-211-5/+8
| | | | | | | | | | | | | | | | | Keep link_map l_addr binary layout compatible, rename l_addr to l_base where rtld returns map base. Provide relocbase in newly added l_addr. This effectively reverts the patch to the initial version of D24918. Reported by: antoine (portmgr) Reviewed by: jhb, markj Tested by: markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D24946 Notes: svn path=/head/; revision=361349
* Change the samantic of struct link_map l_addr member.Konstantin Belousov2020-05-201-3/+5
| | | | | | | | | | | | | | | | | | | | It previously returned the object map base address, while all other ELF operating systems return load offset, i.e. the difference between map base and the link base. Explain the meaning of the field in the man page. Stop filling the mips-only l_offs member, which is apparently unused. PR: 246561 Requested by: Damjan Jovanovic <damjan.jov@gmail.com> Reviewed by: emaste, jhb, cem (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D24918 Notes: svn path=/head/; revision=361303
* Implement RTLD_DEEPBIND.Konstantin Belousov2020-05-151-1/+4
| | | | | | | | | | | PR: 246462 Tested by: Martin Birgmeier <d8zNeCFG@aon.at> Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D24841 Notes: svn path=/head/; revision=361073
* Add memalign(3), mostly for glibc compatibility.Konstantin Belousov2020-05-143-0/+42
| | | | | | | | | | Reviewed by: emaste, imp (previous version) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Differential revision: https://reviews.freebsd.org/D24307 Notes: svn path=/head/; revision=361060
* Remove the SYMVER build option.John Baldwin2020-04-301-12/+10
| | | | | | | | | | | | | | This option was added as a transition aide when symbol versioning was first added. It was enabled by default in 2007 and is supported even by the old GPLv2 binutils. Trying to disable it currently fails to build in libc and at this point it isn't worth fixing the build. Reported by: Michael Dexter Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D24637 Notes: svn path=/head/; revision=360511
* Attempt to use AT_PS_STRINGS to get the ps_strings pointer.Brooks Davis2020-04-151-0/+8
| | | | | | | | | | | | | | | | | | This saves a system call and avoids one of the (relatively rare) cases of the kernel exporting pointers via sysctl. As a temporary measure, keep the sysctl support to allow limited compatability with old kernels. Fail gracefully if ps_strings can't be found (should never happen). Reviewed by: kib Obtained from: CheriBSD Sponsored by: DARPA Differential Revision: https://reviews.freebsd.org/D24407 Notes: svn path=/head/; revision=359991