Commit Graph

2161 Commits

Author SHA1 Message Date
John Baldwin
8bcdb144eb TLS: Use <machine/tls.h> for libc and rtld.
- Include <machine/tls.h> in MD rtld_machdep.h headers.

- Remove local definitions of TLS_* constants from rtld_machdep.h
  headers and libc using the values from <machine/tls.h> instead.

- Use _tcb_set() instead of inlined versions in MD
  allocate_initial_tls() routines in rtld.  The one exception is amd64
  whose _tcb_set() invokes the amd64_set_fsbase ifunc.  rtld cannot
  use ifuncs, so amd64 inlines the logic to optionally write to fsbase
  directly.

- Use _tcb_set() instead of _set_tp() in libc.

- Use '&_tcb_get()->tcb_dtv' instead of _get_tp() in both rtld and libc.
  This permits removing _get_tp.c from rtld.

- Use TLS_TCB_SIZE and TLS_TCB_ALIGN with allocate_tls() in MD
  allocate_initial_tls() routines in rtld.

Reviewed by:	kib, jrtc27 (earlier version)
Differential Revision:	https://reviews.freebsd.org/D33353
2021-12-09 13:23:05 -08:00
John Baldwin
4c2f5bfbfa libc: Fix the alignment of the TCB to match rtld for several architectures.
- Use 16 byte alignment rather than 8 for aarch64, powerpc64, and RISC-V.

- Use 8 byte alignment rather than 4 for 32-bit arm, mips, and powerpc.

I suspect that mips64 should be using 16 byte alignment, but both libc
and rtld currently use 8 byte alignment.

Reviewed by:	kib, jrtc27
Sponsored by:	The University of Cambridge, Google Inc.
Differential Revision:	https://reviews.freebsd.org/D33350
2021-12-09 13:16:57 -08:00
Alan Somers
943c446629 Revert "libc: Some enhancements to syslog(3)"
This reverts commit 2886c93d1b.
The original commit has two problems:

* It sets SO_SNDBUF to be as large as MAXLINE.  But for unix domain
  sockets, the send buffer is bypassed.  Packets go directly to the
  peer's receive buffer, so setting and querying SO_SNDBUF is
  ineffective.  To ensure that the socket can accept messages of a
  certain size, it would be necessary to add a SO_PEERRCVBUF socket
  option that could query the connected peer's receive buffer size.

* It sets MAXLINE to 8 kB, which is larger than the default sockbuf size
  of 4 kB.  That's ok for the builtin syslogd, which sets its recvbuf
  to 80 kB, but not ok for alternative sysloggers, like rsyslogd, which
  use the default size.

As a consequence, writing messages of more than 4 kB with syslog() as a
non-root user while running rsyslogd would cause the logging application
to spin indefinitely within syslog().

PR:		260126
MFC:		2 weeks
Sponsored by:	Axcient
Reviewed by:	markj
Differential Revision: https://reviews.freebsd.org/D33199
2021-11-30 11:11:43 -07:00
Konstantin Belousov
78963d796d Document posix_spawn_file_actions_addclosefrom_np(3)
Reviewed by:    kevans, ngie (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D33143
2021-11-30 03:43:54 +02:00
Konstantin Belousov
a18ddf7757 posix_spawn: add closefrom non-portable action
Namely posix_spawn_file_actions_addclosefrom_np, in the form it is
provided by glibc.

Reviewed by:	kevans, ngie (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D33143
2021-11-30 03:43:54 +02:00
Konstantin Belousov
bd44dce5b3 Document posix_spawn_file_actions_addchdir_np(3)
Reviewed by:	kevans, ngie (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D33143
2021-11-30 03:43:54 +02:00
Konstantin Belousov
25cda42a49 posix_spawn: add chdir-related non-portable actions
Namely posix_spawn_file_actions_addchdir_np and
posix_spawn_file_actions_addfchdir_np.

Reviewed by:	kevans, ngie (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D33143
2021-11-30 03:43:54 +02:00
Konstantin Belousov
8ed1e4a5c1 posix_spawn(3), posix_spawn_file_actions_addopen(3): use .Fo/.Fc
to wrap too long lines with function prototypes.

Reviewed by:	kevans, ngie (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D33143
2021-11-30 03:43:54 +02:00
Konstantin Belousov
b239cc204a posix_spawn: style, use return ()
Reviewed by:	kevans, ngie (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D33143
2021-11-30 03:43:54 +02:00
Konstantin Belousov
adbaf1b443 posix_spawn.c: format fae_action anon enum more stylish
Reviewed by:	kevans, ngie (previous version)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D33143
2021-11-30 03:43:54 +02:00
Konstantin Belousov
412fd7a34c setproctitle_internal(): remove kbuf local, it is write-only
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-11-29 17:39:51 +02:00
Konstantin Belousov
701473ef94 libc/gen/getpwent.c: plug warnings about write-only variables
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-11-29 17:39:50 +02:00
Konstantin Belousov
075fa5a9a8 libc/gen/getgrent.c: plug warnings about write-only variables
The variables clang13 complains about take the results of var_arg() calls.
I decided to kept variables around, annotating their definitions with
__unused, to keep clear expected types of the varargs.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-11-29 17:39:50 +02:00
Konstantin Belousov
90fa9705d5 sched.h: Hide all Linux compat sched_* functions under _WITH_CPU_SET_T
Instead of only hiding cpu_set_t compat typedef itself.

Too many software packages assume that sched_getaffinity() presence
implies full source compatibility with glibc.  We can (and should)
handle missing CPU_* macros, but then there are incompatible BIT_* uses
which cannot be fixed in src/.

So hide everything under _WITH_CPU_SET_T, in particular, do not expose
sched_getcpu(), sched_get/setaffinity(), as well as CPU_* and BIT_*
macros.  Consumers that want sched* functions must opt-in.

Reported by:	portmgr (antoine)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-11-13 19:27:54 +02:00
Konstantin Belousov
77b2c2f814 Add sched_getcpu()
for compatibility with Linux.

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32901
2021-11-10 21:18:54 +02:00
Konstantin Belousov
43736b71dd Add sched_get/setaffinity(3)
for compatibility with Linux.

Reviewed by:	jhb
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D32901
2021-11-10 21:18:54 +02:00
Mark Johnston
0ac2a64983 sysctl.3: sys/types.h no longer needs to be explicitly included
Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D32562
2021-10-19 21:22:57 -04:00
Konstantin Belousov
300e08933e libc tls: use TLS_DTV_OFFSET defined by rtld.h
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D31541
2021-08-16 13:55:35 +03:00
Fangrui Song
8f63fa78e8 rtld: Remove calculate_tls_end
Variant I architectures use off and Variant II ones use size + off.
Define TLS_VARIANT_I/TLS_VARIANT_II symbols similarly to how libc
handles it.

Reviewed by:	kib
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D31539
Differential revision:	https://reviews.freebsd.org/D31541
2021-08-16 13:55:35 +03:00
Gordon Bergling
a1581cd735 Fix a common typo in source code comments
- s/aligment/alignment/

MFC after:	5 days
2021-08-14 14:17:48 +02:00
Fernando Apesteguía
94eb6c42ab syslog.3 - Add detail about LOG_PID
Document that LOG_PID is ignored and can not be disabled.
This change was made along with the move from RFC 3164 to RFC 5424 log messages.

PR:	255664
Reported by:	des.gaufres@gmail.com
Reviewed by:	gbe, jilles
Approved by:	gbe (mentor, manpages), jilles
2021-05-13 16:23:44 +02:00
Mateusz Piotrowski
1ffdcdadf6 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
2021-04-18 10:20:11 +02:00
Konstantin Belousov
dbd2053026 libc dl_iterate_phdr(): dlpi_tls_data is wrong
This is the same change as d36d681615, but for libc static implementaion
of dl_iterate_phdr().

Reported by:	emacsray@gmail.com
PR:	254774
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29623
2021-04-09 23:46:24 +03:00
Konstantin Belousov
ca46b5698e libc: implement __tls_get_addr() for static binaries
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29623
2021-04-09 23:46:24 +03:00
Konstantin Belousov
7f7489eba3 libc: include rtld.h into static implementations of rtld interface
and resolve naming conficts

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29623
2021-04-09 23:46:24 +03:00
Konstantin Belousov
93c14c55ec libc: constify dummy error message string for dlfcn
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D29623
2021-04-09 23:46:23 +03:00
Konstantin Belousov
d36d681615 rtld dl_iterate_phdr(): dlpi_tls_data is wrong
dl_iterate_phdr() dlpi_tls_data should provide the TLS module segment
address, and not the TLS init segment address as it does now.

Reported by:	emacsray@gmail.com
PR:	254774
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2021-04-06 03:23:08 +03:00
Mark Johnston
3b666932d4 libc: Fix the WITH_HESIOD build
Reported by:	Daniel Braniss <danny@cs.huji.ac.il>
MFC after:	1 week
2021-04-05 16:30:00 -04:00
Dmitry Wagin
9bd7345212 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.

MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D27205
2021-03-23 12:49:58 -04:00
Alex Richardson
f5542795b9 s_scalbn.c: Add missing float.h include
This caused LDBL_MANT_DIG to not be defined and therefore the scalbnl
alias was not being emitted for double==long double platforms.

Fixes:		760b2ffc ("Update scalbn* functions to the musl versions")
Reported by:	Jenkins
2021-03-01 14:22:47 +00:00
Alex Richardson
aac21e66f9 Also use the musl scalbn code for ldexp()
Instead of copying the code as 00646ca204
did, include the implementation with the function name re-defined.
2021-03-01 12:53:46 +00:00
Konstantin Belousov
3ae8d83d04 Remove __NO_TLS.
All supported platforms support thread-local vars and __thread.

Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D28796
2021-02-23 20:08:10 +02:00
Michael Reifenberger
8d06c3e7a4 Improve size readability.
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
2021-02-15 20:23:32 +01:00
Konstantin Belousov
4956af2a8f usleep(3): replace 'process' with 'calling thread'
PR:	253395
Reported by:	zegang.luo@qq.com
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
2021-02-11 05:52:55 +02:00
Mateusz Guzik
46f168bc66 Drop temporary compat in setproctitle 2021-01-31 16:07:19 +00:00
Mark Johnston
48a1868634 libc/nss: Ensure that setgroupent(3) actually works as advertised
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
2021-01-21 14:30:19 -05:00
Mark Johnston
5619d49e07 libc/nss: Restore iterator state when doing passwd/group lookups
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
2021-01-21 14:30:19 -05:00
Mateusz Guzik
fe258f23ef Save on getpid in setproctitle by supporting -1 as curproc. 2021-01-16 09:36:54 +01:00
Konstantin Belousov
81b3a0a341 libc: implement rtld_get_stack_prot() for real
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
2021-01-10 08:25:43 +02:00
Konstantin Belousov
4e0c81c5fa tcgetwinsize(3): provide man page
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
2021-01-02 04:43:32 +02:00
Konstantin Belousov
44c5db52e2 Add eventfd(3) wrappers to libc.
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
2020-12-27 12:57:26 +02:00
Konstantin Belousov
7d7fad7bd9 Add tcgetwinsize(3) and tcsetwinsize(3) to termios
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
2020-12-25 20:43:09 +02:00
Enji Cooper
d03bd62f31 timespec_get(3): sort SEE ALSO correctly
clock_gettime(2) should be mentioned before gettimeofday(2).

Reported by:	make manlint
MFC after:	1 week
Sponsored by:	DellEMC Isilon
2020-12-11 02:22:42 +00:00
Enji Cooper
2c96ea9ca0 posix_spawn(3): fix section that references vfork
`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
2020-12-11 00:20:04 +00:00
Enji Cooper
eca1933a55 getentropy(3): sort SEE ALSO sections
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
2020-12-11 00:15:57 +00:00
Enji Cooper
c80d36d0e0 arc4random(3): fix .Xr issues
- 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
2020-12-11 00:13:39 +00:00
Cy Schubert
feb01b72ef Remove trailing whitespace.
MFC after:	1 week
2020-12-03 05:49:59 +00:00
Konstantin Belousov
412ef5da8a libc: Add pthread_attr_get_np(3) stub, reporting ESRCH.
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
2020-11-28 12:19:20 +00:00
Konstantin Belousov
1a1b8b1cb3 Remove stray column.
Sponsored by:	The FreeBSD Foundation
MFC after: 3 days
2020-11-26 20:27:23 +00:00
Konstantin Belousov
f2148ee019 Use designated initializers for libc pthread stubs' jump table.
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2020-11-25 17:04:26 +00:00