Commit graph

9367 commits

Author SHA1 Message Date
Felix Johnson
c834258459 uuid(3): Document return values
PR:		204449
Reported by:	Michael Cress <michael.cress@cress.us>

(cherry picked from commit f6842865d3)
2021-11-21 19:43:31 -05:00
Konstantin Belousov
9de9a33050 fexecve(2): allow O_PATH file descriptors opened without O_EXEC
(cherry picked from commit be10c0a910)
2021-11-06 04:12:33 +02:00
Konstantin Belousov
c802b970a5 procctl: actually require debug privileges over target
(cherry picked from commit f5bb6e5a6d)
2021-10-26 05:26:27 +03:00
Konstantin Belousov
2e69ba48b9 procctl(2): add consistent shortcut P_ID:0 as curproc
(cherry picked from commit f833ab9dd1)
2021-10-26 05:26:26 +03:00
Mark Johnston
589daa05be Revert "libc/locale: Fix races between localeconv(3) and setlocale(3)"
This reverts commit f89204d6b9.

I didn't intend to push this commit yet, pending discussion on PR
258360.

PR:	258360
2021-10-19 21:13:12 -04:00
Mark Johnston
f89204d6b9 libc/locale: Fix races between localeconv(3) and setlocale(3)
Each locale embeds a lazily initialized lconv which is populated by
localeconv(3) and localeconv_l(3).  When setlocale(3) updates the global
locale, the lconv needs to be (lazily) reinitialized.  To signal this,
we set flag variables in the locale structure.  There are two problems:

- The flags are set before the locale is fully updated, so a concurrent
  localeconv() call can observe partially initialized locale data.
- No barriers ensure that localeconv() observes a fully initialized
  locale if a flag is set.

So, move the flag update appropriately, and use acq/rel barriers to
provide some synchronization.  Note that this is inadequate in the face
of multiple concurrent calls to setlocale(3), but this is not expected
to work regardless.

Thanks to Henry Hu <henry.hu.sh@gmail.com> for providing a test case
demonstrating the race.

PR:		258360
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 7eb138a9e5)
2021-10-19 20:53:33 -04:00
Greg V
1625e2db22 O_PATH: allow vfs_extattr syscalls
(cherry picked from commit 98dae405de)
2021-10-16 16:01:47 +03:00
Jessica Clarke
d7b3f3c84e libc: Fix build on case-insensitive file systems
On case-insensitive file systems (most likely to be seen on macOS, where
it is the default), _Fork.o for the new POSIX _Fork function conflicts
with _fork.o for the PSEUDO file. This results in non-determinsitic
behaviour in terms of which ends up being present; if _Fork.o wins then
the build fails to link libc.so due to missing __sys_fork, and if
_fork.o wins then libc silently fails to include the implementation of
_Fork. A similar issue occurred in the past for C99's _Exit conflicting
with exit(2) and was fixed in cb1cb6a2a8, so this adds a fix based on
that.

As a longer-term solution it might be better to instead make the
generated files use a different prefix that's less likely to conflict
with other things (such as __sys_foo.o given they always contain that)
but that's a rather more invasive change.

Fixes:	49ad342cc1 ("Add _Fork()")
Reviewed by:	kib
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31895

(cherry picked from commit 877175a17a)
2021-10-10 14:33:52 +01:00
Konstantin Belousov
156db35573 readlinkat(2): allow O_PATH fd
PR:	258856

(cherry picked from commit 5fb54d2fc8)
2021-10-10 12:22:58 +03:00
Konstantin Belousov
8c384596a8 Fix mistakes in link(2) and shm_open(2)
PR:	258957

(cherry picked from commit 8d3cd7767a)
2021-10-10 12:21:18 +03:00
Adam Fenn
2524e9bd82 libc: vDSO timekeeping: Add pvclock support
(cherry picked from commit a3d932dfef)
2021-10-10 12:21:17 +03:00
Kyle Evans
a663c839ff libc: ssp: sprinkle around some __dead2
This is consistent with, e.g., NetBSD's implementation, which declares
these as noreturn in ssp/ssp.h.

(cherry picked from commit 5487294d79)
2021-10-06 02:14:42 -05:00
Kyle Evans
b7e90b290a kqueue: document how timers with low/past timeouts are handled
(cherry picked from commit 4b5554cebb)
2021-10-06 02:04:00 -05:00
Konstantin Belousov
d4a478c270 procctl(2): Add PROC_WXMAP_CTL/STATUS
(cherry picked from commit 796a8e1ad1)
2021-09-24 03:26:59 +03:00
Edward Tomasz Napierala
e79a18dadf procctl(2): add PROC_NO_NEW_PRIVS_CTL, PROC_NO_NEW_PRIVS_STATUS
(cherry picked from commit db8d680ebe)
2021-09-24 03:26:59 +03:00
Mark Johnston
ad9f3a91d5 libc: Use the initial-exec TLS model
This permits more efficient accesses of thread-local variables, which
are heavily used at least by jemalloc and locale-aware code.  Note that
on amd64 and i386, jemalloc's thread-local variables already have their
TLS model overridden by defining JEMALLOC_TLS_MODEL.

For now the change is applied only to tested platforms, but should in
principle be enabled everywhere.

PR:		255840
Suggested by:	jrtc27
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 9c97062b62)
2021-09-14 08:50:53 -04:00
Mark Johnston
603c9bb029 kqueue.2: Document the fact that EVFILT_READ can be used on kqueues
Reviewed by:	bcr, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit f756c91168)
2021-09-14 08:50:31 -04:00
Warner Losh
5918f48652 clock_gettime: Add Linux aliases for CLOCK_*
Linux standardized what we call CLOCK_{REALTIME,MONOTONIC}_FAST as
CLOCK_{REALTIME,MONOTONIC}_COARSE. In addition, Linux spells
CLOCK_UPTIME as CLOCK_BOOTTIME.

Add aliases to time.h and document these new aliases in
clock_gettime(2).

Reviewed by:		vangyzen, kib (prior), dchagin (prior)
Sponsored by:		Netflix
Differential Revision:	https://reviews.freebsd.org/D30988

(cherry picked from commit 155f15118a)
2021-09-12 09:56:16 -06:00
Jessica Clarke
c69a739379 riscv: Implement non-stub __vdso_gettc and __vdso_gettimekeep
PR:	256905
Reviewed by:	arichardson, mhorne
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D30963

(cherry picked from commit 348c41d181)
2021-09-07 13:06:44 +01:00
Dimitry Andric
ef314cd4ba Fix null pointer subtraction in mergesort()
Clang 13 produces the following warning for this function:

lib/libc/stdlib/merge.c:137:41: error: performing pointer subtraction with a null pointer has undefined behavior [-Werror,-Wnull-pointer-subtraction]
        if (!(size % ISIZE) && !(((char *)base - (char *)0) % ISIZE))
                                               ^ ~~~~~~~~~

This is meant to check whether the size and base parameters are aligned
to the size of an int, so use our __is_aligned() macro instead.

Also remove the comment that indicated this "stupid subtraction" was
done to pacify some ancient and unknown Cray compiler, and which has
been there since the BSD 4.4 Lite Lib Sources were imported.

(cherry picked from commit 4e5d32a445)
2021-08-31 21:05:43 +02:00
Kyle Evans
d511b903b9 kenv: allow listing of static kernel environments
The early environment is typically cleared, so these new options
need the PRESERVE_EARLY_KENV kernel config(8) option. These environments
are reported as missing by kenv(1) if the option is not present in the
running kernel.

(cherry picked from commit db0f264393)
2021-08-26 01:35:33 -05:00
Gordon Bergling
a2d0f28a8e rpc(3): Correct a few common typos in source code comments
- s/therfore/therefor/
- s/activte/active/

Obtained from:	NetBSD

(cherry picked from commit 0d55bc8eb2)
2021-08-25 08:25:12 +02:00
Konstantin Belousov
6295883670 libc tls: use TLS_DTV_OFFSET defined by rtld.h
(cherry picked from commit 300e08933e)
2021-08-23 12:20:56 +03:00
Fangrui Song
2aa761055c rtld: Remove calculate_tls_end
(cherry picked from commit 8f63fa78e8)
2021-08-23 12:20:56 +03:00
Mark Johnston
acabc20906 kevent: Prohibit negative change and event list lengths
Previously, a negative change list length would be treated the same as
an empty change list.  A negative event list length would result in
bogus copyouts.  Make kevent(2) return EINVAL for both cases so that
application bugs are more easily found, and to be more robust against
future changes to kevent internals.

Reviewed by:	imp, kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit e00bae5c18)
2021-08-21 12:08:58 -04:00
Gordon Bergling
f296898fb7 Fix a common typo in source code comments
- s/aligment/alignment/

(cherry picked from commit a1581cd735)
2021-08-19 09:18:35 +02:00
Alexander Motin
09d4fe40e0 Fix race between first rand(3) calls with _once().
Before this patch there was a chance for thread that called rand(3)
slightly later to see rand3_state already allocated, but not yet
initialized.  While this API is not expected to be thread-safe, it
is not expected to crash.  ztest on 64-thread system reproduced it
reliably for me.

Submitted by:	avg@
MFC after:	1 month

(cherry picked from commit 3a57f08b50)
2021-08-18 21:11:51 -04:00
Mateusz Piotrowski
5cdee2441e getprogname.3: Add an example
It shows the difference between getprogname() and argv[0].

Reviewed by:	yuripv
Approved by:	yuripv (src)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D27204

(cherry picked from commit 1ffdcdadf6)
2021-08-15 23:19:09 +02:00
Konstantin Belousov
c4bb20a5ec _Exit(3): document implementation
(cherry picked from commit ee62fb2e1e)
2021-08-12 15:37:54 +03:00
Konstantin Belousov
5d7b612949 fork(2): comment about doubtful use of stdio and exit(3) in example
(cherry picked from commit 2a51e8823a)
2021-08-12 15:37:54 +03:00
Ceri Davies
f59374b69a fork.2: correct minor typo in manpage.
(cherry picked from commit 383dbdb2eb)
2021-08-12 15:37:54 +03:00
Konstantin Belousov
1c54a109d7 Add _Fork()
(cherry picked from commit 49ad342cc1)
2021-08-12 15:37:54 +03:00
Konstantin Belousov
8c51479a6e Style
(cherry picked from commit 2d319ebe5c)
2021-08-12 15:37:54 +03:00
Mateusz Piotrowski
3248a03c1a fork.2: Fix a typo in an example
(cherry picked from commit ca904beafd)
2021-08-12 15:37:54 +03:00
Mateusz Piotrowski
a9c0baa1d0 fork.2: Add a simple use pattern
(cherry picked from commit c4207d867c)
2021-08-12 15:37:54 +03:00
Roy Marples
f452713408 socket: Implement SO_RERROR
SO_RERROR indicates that receive buffer overflows should be handled as
errors. 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.

Reviewed by:	philip (network), kbowling (transport), gbe (manpages)
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D26652

(cherry picked from commit 7045b1603b)
2021-08-10 18:54:00 -07:00
Mark Johnston
d888157844 libc/locale: Use O_CLOEXEC when opening locale tables
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 98bfb9dac2)
2021-08-05 08:45:22 -04:00
Alex Richardson
85c76b4117 tools/build: Don't redefine open() for the linux bootstrap
This is needed to bootstrap llvm-tblgen on Linux since LLVM calls
`::open(...)` which does not work if open is a statement macro.
Also stop defining O_SHLOCK/O_EXLOCK and update the only bootstrap tools
user of those flags to deal with missing definitions.

Reviewed By:	jrtc27
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D31226

(cherry picked from commit 5f6c8ce245)
2021-08-05 10:00:45 +01:00
Konstantin Belousov
a1b0744399 x86 __vdso_gettc: add O_CLOEXEC flag to open
(cherry picked from commit cbf6f55e77)
2021-08-05 03:56:46 +03:00
Tom Jones
64a0116cd0 Correct section reference for examples in RFC3542
Reviewed by:	bz, network
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D26272

(cherry picked from commit 44752e92e1)
2021-08-04 09:15:27 +01:00
Konstantin Belousov
dba677d13b libc: add mempcpy(3) and wmempcpy(3)
(cherry picked from commit ee37f64cf8)
2021-07-22 13:33:10 +03:00
Konstantin Belousov
17658c8a6d Create namespace for the symbols added during 14-CURRENT cycle.
(cherry picked from commit 8c3ea3f4c4)
2021-07-22 13:33:10 +03:00
Konstantin Belousov
f027b4f41f vdso: lower precision of vdso implementation of CLOCK_MONOTONIC_FAST and CLOCK_UPTIME_FAST
(cherry picked from commit 60b0ad10dd)
2021-06-30 07:42:06 +03:00
Konstantin Belousov
af9521f635 vdso gettimeofday: minor restructuring
(cherry picked from commit e912fbe167)
2021-06-30 07:41:58 +03:00
Pedro F. Giffuni
62d555c4e8 fread: improve performance for unbuffered reads
We can use the buffer passed to fread(3) directly in the FILE *.
The buffer needs to be reset before each call to __srefill().
This preserves the expected behavior in all cases.

The change was found originally in OpenBSD and later adopted by NetBSD.

MFC after:	2 weeks
Obtained from:	OpenBSD (CVS 1.18)

Differential Revision:	https://reviews.freebsd.org/D30548
2021-06-15 16:26:31 -05:00
Konstantin Belousov
9c74a20681 ptrace: add an option to not kill debuggees on debugger exit
(cherry picked from commit fd3ac06f45)
2021-06-01 03:38:54 +03:00
Konstantin Belousov
824cca5934 openat(2): add O_EMPTY_PATH
(cherry picked from commit 5e7cdf1817)
2021-05-19 06:13:14 +03:00
Dmitry Wagin
2886c93d1b libc: Some enhancements to syslog(3)
- Defined MAXLINE constant (8192 octets by default instead 2048) for
  centralized limit setting up. It sets maximum number of characters of
  the syslog message. RFC5424 doesn't limit maximum size of the message.
  Named after MAXLINE in syslogd(8).
- Fixed size of fmt_cpy buffer up to MAXLINE for rendering formatted
  (%m) messages.
- Introduced autoexpansion of sending socket buffer up to MAXLINE.

Differential Revision:	https://reviews.freebsd.org/D27205

(cherry picked from commit 9bd7345212)
2021-05-14 09:56:46 -04:00
Alex Richardson
fc19e3cb4f libc/string/memset.c: Use unsigned long for stores
While most 64-bit architectures have an assembly implementation of this
file, RISC-V does not. As we now store 8 bytes instead of 4 it should speed
up RISC-V.

Reviewed By:	kib
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D29536

(cherry picked from commit ab147542b7)
2021-05-11 09:39:27 +01:00
Alex Richardson
0e1e71400a libc/string/bcopy.c: Use intptr_t as the copy type
While most 64-bit architectures have an assembly implementation of this
file RISC-V does not. As we now copy 8 bytes instead of 4 it should speed
up RISC-V. Using intptr_t instead of int also allows using this file for
CHERI pure-capability code since trying to copy pointers using integer
loads/stores will invalidate pointers.

Reviewed By:	kib
Obtained from:	CheriBSD (partially)
MFC after:	1 week
Differential Revision: https://reviews.freebsd.org/D29535

(cherry picked from commit 0b4ad01d91)
2021-05-11 09:39:26 +01:00