Commit Graph

2944 Commits

Author SHA1 Message Date
Konstantin Belousov
feaae6ba1a rtld: switch from malloc_aligned() to __crt_aligned_alloc()
Use regular free(), since it works now.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-08-21 17:16:42 +03:00
Konstantin Belousov
c29ee08204 rtld_malloc: add __crt_aligned_alloc_offset()
It is modelled after aligned_alloc(3).  Most importantly, to free the
allocation, __crt_free() can be used.  Additionally, caller may specify
offset into the aligned allocation, so that we return offset-ed from
alignment pointer.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-08-21 17:16:42 +03:00
Konstantin Belousov
d60130bf32 rtld_malloc: increase overhead index to uint16
Reorder it with magic, to keep alignment.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-08-21 17:16:42 +03:00
Konstantin Belousov
6bb7f05850 rtld_malloc.c: change return type of cp2op() to void
for it to be useful to return unaligned pointer.

Reviewed by:	markj
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-08-21 17:16:42 +03:00
Konstantin Belousov
b1d3e2b771 rtld: unlock bind lock when calling into crt __pthread_distribute_static_tls method
The method might require resolving and binding symbols, which means
recursing on the bind lock. It is safe to unlock the bind lock,
since we operate on the private object list, and user attempting to
unload an object from the list of not yet fully loaded objects caused
self-inflicted race.

It is similar to how we treat user' init/fini methods.

Reported by:	stevek
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-08-20 15:30:13 +03:00
Ed Maste
4722ceb7d5 Use 115200 bps by default for serial communication
9600 was a standard baud rate decades ago, but 115200 is now more common
so choose defaults that are useful to the largest number of users.

Note that boot0sio does not support rates above 9600 so it remains
unchanged.

Reviewed by:	bz, imp, manu
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D36295
2023-08-17 13:31:38 -04:00
Warner Losh
ddb5480ec6 Fix partially removed comment by removing the rest
Fixes: 2a63c3be15
2023-08-16 14:17:33 -06:00
Warner Losh
05248206f7 Remove $FreeBSD$: one-line bare tag
Remove /^\s*\$FreeBSD\$$\n/
2023-08-16 11:55:20 -06:00
Warner Losh
b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh
fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh
d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh
1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh
2a63c3be15 Remove $FreeBSD$: one-line .c comment pattern
Remove /^/[*/]\s*\$FreeBSD\$.*\n/
2023-08-16 11:54:29 -06:00
Warner Losh
42b388439b Remove $FreeBSD$: one-line .h pattern
Remove /^\s*\*+\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:23 -06:00
Warner Losh
b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Enji Cooper
f05948d4e9 cpuset(8): move to /bin/
Summary:
This change moves /usr/bin/cpuset to /bin/cpuset so it is more readily
available on hosts where the /usr partition might not be mounted at the
time / has been mounted.

Remove some complexity from rc.subr(8) since /bin is assumed to always
be present if/when / is mounted.

MFC after:	2 weeks
MFC with:	0661f93892, 271d552379af

Test Plan:
- Test out rc.subr change.
- Confirm that the installation logic does what's needed.

Relnotes:	yes (moving cpuset may impact strict file permissions/mode checking)
Reviewers:	kevans
Subscribers:	imp
Differential Revision: https://reviews.freebsd.org/D40057
2023-08-11 00:49:02 -07:00
Mike Karels
6f15b7e199 ldconfig script: enable 32-bit compat on aarch64
Add aarch64 to set of architectures that support 32-bit compat
libraries.
2023-08-05 07:37:39 -05:00
Jessica Clarke
195e50541e libexec: Automatically generate rtld-elf list and generalise TAGS
Note that the pattern for matching is made slightly more specific, so as
to permit libcompats where one is a prefix of another (e.g. CheriBSD has
lib64 and lib64c).

Reviewed by:	brooks, jhb, emaste, imp, kib
Differential Revision:	https://reviews.freebsd.org/D41183
2023-07-27 05:10:45 +01:00
Konstantin Belousov
86c7368f2b rtld_malloc: add cp2op() helper
converting user allocation address into overhead pointer

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-07-26 17:24:18 +03:00
Konstantin Belousov
bc7e86106d rtld_malloc: only include internal rtld headers when building for rtld
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-07-26 17:24:17 +03:00
Konstantin Belousov
cf6dbdd135 rtld: remove dup __crt_malloc prototypes
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-07-26 17:24:17 +03:00
Konstantin Belousov
a24726a6f3 rtld_malloc: remove outdated comments
The ovu_magic is not neccessary overlaps with low byte of the ov_next,
for the big endian machines.

There is no range checking in the allocator.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
Differential revision:	https://reviews.freebsd.org/D41150
2023-07-26 17:24:17 +03:00
Kristof Provost
9f23cbd6ca atf_pytest_wrapper: fix use with pytest-7.4
As of pytest 7.4 it no longer walks all the way to the root directory
of the file system to find conftest files. As a result we don't find /
usr/tests/conftest.py, and don't load atf_python. That in turn causes
atf_python tests to fail.

Explicitly set the confcutdir, as advised by the pytest changelog.

See also:	https://github.com/pytest-dev/pytest/pull/11043
MFC after:	3 weeks
Sponsored by:	Orange Business Services
Differential Revision:	https://reviews.freebsd.org/D41064
2023-07-21 11:23:21 +02:00
Dmitry Morozovsky
615d167cb8 Revert "tftpd: fix double-colon typo in option string"
It was not a typo: -d takes an optional argument, which is indicated with
a double colon.

This reverts commit 3cbc8e752b.

Spotted by:	kevans
2023-07-21 00:38:30 +03:00
Dmitry Morozovsky
3cbc8e752b tftpd: fix double-colon typo in option string
MFC after:	1 month
X-MFC-With:	273a307d0b
X-MFC-With:	03c2616dc5
2023-07-21 00:24:28 +03:00
Eugene Grosbein
03c2616dc5 tftpd: unbreak getopt()
Unbreak getopt() broken by recent commit.

Fixes:		273a307d0b
MFC after:	1 month
2023-07-21 03:26:32 +07:00
Eugene Grosbein
273a307d0b tftpd: introduce new option -S
Historically, tftpd disallowed write requests to existing files
that are not publicly writable. Such requirement is questionable at least.
Let us make it possible to run tftpd in chrooted environment
keeping files non-world writable.

New option -S enables write requests to existing files
for chrooted run according to generic file permissions.
It is ignored unless tftpd runs chrooted.

MFC after:	1 month
Requested by:	marck
Differential:	https://reviews.freebsd.org/D41090 (based on)
2023-07-21 03:23:35 +07:00
Robert Clausecker
c1e63e352e libexec/rtld-elf/rtld-libc/Makefile.inc: do not use machdep string functions
With ifunc based SIMD dispatch, we cannot use the amd64 assembly
implementations of string functions.  Modify rtld to instead use
the generic functions.  To avoid an architecture-specific special
case, this change is applied to all architectures.

This change is a prerequisite to and formerly part of D40693.

Sponsored by:	FreeBSD Foundation
Approved by:	kib
See also:	D40693
Differential Revision: https://reviews.freebsd.org/D41050
2023-07-16 18:41:55 +03:00
Konstantin Belousov
1005d3d053 rtld: fix dlopen() for an object that is already mapped but not yet initialized
For instance, dso might be mapped as needed but not yet initialized from
the other subtree of needed objects, while current object' constructor
does dlopen() for the dso.  Right now rtld does relocations and other
processing based on the arrival of new objects in the global list, which
is not happens there.  Directly check for the initialization state of
the object, for which we would return the handle.

One practical use case of this support is e.g. dlopen("libthr.so",
RTLD_NOLOAD) by libraries that are threading-aware but happy to live
with libc pthread shims if the program is not multithreaded.

Reviewed by:	tijl
Sponsored by:	The FreeBSD Foundation
MFC after:	2 weeks
2023-07-16 15:34:34 +03:00
Doug Rabson
5ac2a874d0 /etc/rc.subr: rename sysctl.conf.d to sysctl.kld.d
This better reflects the intent that this directory is indexed by kld
name and removes a conflict with D32128 which aims to split sysctl.conf.

Reviewed by:	kevans imp
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D41043
2023-07-15 14:16:08 +01:00
Doug Rabson
09267cc152 /etc/rc.subr: add support for kld sysctl variables
For kernel modules loaded by scripts in /etc/rc.d and
/usr/local/etc/rc.d, if there is a file in /etc/sysctl.conf.d named <kld
name>.conf, then this will be loaded using the sysctl(8) utility. For
instance, sysctl variable changes for the pf kernel module would be
placed in the file /etc/sysctl.conf.d/pf.conf.

PR:		272129
Reviewed by:	imp freebsd_igalic.co
MFC after:	2 weeks
Differential Revision: https://reviews.freebsd.org/D40886
2023-07-14 10:49:47 +01:00
Dmitry Chagin
e541cf8316 rtld: Annotate .rtld_start on i386
Add a stop indicator to rtld_start to satisfy unwinders:
The right unwinding stop indicator should be CFI-undefined PC.
https://dwarfstd.org/doc/Dwarf3.pdf - page 118:
If a Return Address register is defined in the virtual unwind table,
and its rule is undefined (for example, by DW_CFA_undefined), then
there is no return address and no call address, and the virtual
unwind of stack activations is complete.

That is allows gdb and libunwind successfully stop when unwinding stack
from global constructors and destructors.

Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D40949
2023-07-11 15:10:32 +03:00
Dmitry Chagin
86c63225ea rtld: Microoptimize rtld_start on i386
Initial stack pointer is preserved in calle-saved %esi,
use it bellow to pass initial stack pointer to _rtld().

Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D40950
2023-07-11 15:10:08 +03:00
Jessica Clarke
076a4dc59b rtld-elf: Remove _PATH_ELF32_HINTS and _COMPAT32_PATH_RTLD
These are no longer referenced, with the one user of each now using the
double-underscore version with "32" as an argument instead.

Reviewed by:	kib, brooks, jhb
Differential Revision:	https://reviews.freebsd.org/D40935
2023-07-09 18:50:30 +01:00
Jessica Clarke
f940929d41 rtld-elf: Migrate from COMPAT_32BIT to generic COMPAT_libcompat/LIBCOMPAT
We still have a tiny amount of libcompat-specific code in rtld_paths.h,
but it's been deduplicated as much as possible, and in future we may
wish to just push these variables down to the few consumers of them and
make them use the double-underscore variants with a libcompat argument
rather than give them names here.

See commit 8fad2cda93 ("bsd.compat.mk: Provide new CPP and sub-make
variables") for the context behind this change.

Reviewed by:	kib, brooks, jhb
Differential Revision:	https://reviews.freebsd.org/D40925
2023-07-09 18:49:07 +01:00
Jessica Clarke
5181fe24b2 rtld-elf: Reuse _BASENAME_RTLD for debug.h rather than duplicating logic
Reviewed by:	kib, brooks, jhb
Differential Revision:	https://reviews.freebsd.org/D40919
2023-07-09 18:45:49 +01:00
Brooks Davis
f55ef85748 etc/rc.d/routing: use find_system_scripts
In 3693d9140e /etc/rc switched to using
find_system_scripts rather than directly including /etc/rc.d/* in the
list of scripts to run in order to skip .pkgsave files.  Follow suit
in etc/rc.d/routing.

Sponsored by:	DARPA
2023-07-07 23:25:11 +01:00
Dmitry Chagin
ac7759f545 rtld: Annotate .rtld_start on aarch64
1. Add a stop indicator to rtld_start to satisfy unwinders on aarch64:
The right unwinding stop indicator should be CFI-undefined PC.
https://dwarfstd.org/doc/Dwarf3.pdf - page 118:
If a Return Address register is defined in the virtual unwind table,
and its rule is undefined (for example, by DW_CFA_undefined), then
there is no return address and no call address, and the virtual
unwind of stack activations is complete.

2. Add a proper annotations for CFA.

That is allows gdb and libunwind successfully stop when unwinding stack
from global constructors and destructors.

Reviewed by:
Differential Revision:	https://reviews.freebsd.org/D40844
2023-07-07 19:55:28 +03:00
Dmitry Chagin
5645dfb41a rtld: Sligtly optimizing .rtld_start on aarch64
Use the LDP (load pair registers) instruction to load entry point
arguments from the stack.

Reviewed by:
Differential Revision:	https://reviews.freebsd.org/D40843
2023-07-07 19:55:08 +03:00
Alfonso Gregory
69c0fb2a7a Mark usage function as __dead2 in programs where it does not return
In most cases, usage does not return, so mark them as __dead2. For the
cases where they do return, they have not been marked __dead2.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/735
2023-07-07 10:45:17 -06:00
Eugene Grosbein
ccc806a049 dumpdev: respect kenv for stable branches
We have somewhat twisted logic to determine actions for dumpdev
considering three sources of information:

* kenv "dumpdev" tunnable supposed to point to specific device;
* /etc/defaults/rc.conf "dumpdev" variable;
* /etc/rc.conf that may be unset or set to "NO", "AUTO" or device name.

For CURRENT without any setting in kenv or /etc/rc.conf
the default is "AUTO". For STABLE branches the default is "NO".

Current implementation breaks for STABLE branches if kenv points
to specific device but /etc/rc.conf does not set "dumpdev" at all.

Let us fix it commenting out "dumpdev" in /etc/defaults/rc.conf
for STABLE branches and making the code to consult kenv
if "dumpdev" is not set elsewhere.

MFC-after:	1 month
2023-07-02 14:54:57 +07:00
Dmitry Chagin
3bdf68086d rtld: Add a stop indicator to rtld_start to satisfy unwinders on x86_64
The right unwinding stop indicator should be CFI-undefined PC.
https://dwarfstd.org/doc/Dwarf3.pdf - page 118:
If a Return Address register is defined in the virtual unwind table,
and its rule is undefined (for example, by DW_CFA_undefined), then
there is no return address and no call address, and the virtual
unwind of stack activations is complete.

That is allows gdb and libunwind successfully stop when unwinding stack
from global constructors and destructors.

Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D40794
2023-07-01 10:51:35 +03:00
Andrew Fengler
f81be7a831 rc.d/routing: Correct setting default gateway for each FIB
There was a mistake in the previous commit, it used the incorrect
spelling of the FIB variable name and was not functional

Also corrects an issue with the IPv6 default route variable name.

Fixes:	30659d1dcb ("Add support for adding default routes for other FIBs")
Sponsored-by:	ScaleEngine Inc.
Differential Revision:	https://reviews.freebsd.org/D37685
2023-06-26 18:43:46 +00:00
John Baldwin
38efd4df23 rtld-elf: Mark tls_init_align __unused in free_tls for Variant I TLS.
Some architectures (powerpc and RISC-V) always use 0 for the post TLS
size in which case tls_init_align isn't used by
calculate_tls_post_size.  Use __unused to quiet the warning for these
platforms.

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D40673
2023-06-20 12:38:48 -07:00
John Baldwin
1c3424b0d2 rtld-elf: Remove set but unused variable on 32-bit arm. 2023-06-20 09:29:00 -07:00
Eugene Grosbein
79a96e294c motd: unbreak for source upgrade
In case of source upgrade path from 12.x proper merge of new /etc
installs /etc/motd.template. Becase of that, the system in left
without symlink /etc/motd -> /var/run/motd but with stale /etc/motd contents.

Fix it creating symlink despite of presence of /etc/motd.template.

MFC after:	1 week
2023-06-19 14:49:35 +07:00
Konstantin Belousov
a254f67102 rtld: fix typo in comment
Sponsored by:	The FreeBSD Foundation
MFC after:	3 days
2023-06-10 04:35:14 +03:00
Konstantin Belousov
e9a38ed2fa rtld: fix allocate_module_tls() variant I fallback to static allocation
Submitted by:	Joerg Sonnenberger
Fixes:	91880e07f605edb90339685bc934699a4344de3bESC
MFC after:	1 week
2023-06-09 15:13:46 +03:00
Konstantin Belousov
91880e07f6 rtld: do not allow both dynamic DTV index and static TLS offset
If we are allocating static offset for an object with dynamic index,
return failure.  In the opposite case, if dynamic index is requested for
statically allocated TLS area, directly use the offset instead of
setting the index.

Taken from NetBSD Joerg Sonnenberger change for src/libexec/ld.elf_so/tls.c
rev. 1.18.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-06-05 22:33:18 +03:00
Konstantin Belousov
283a4f4097 rtld: rename tls_done to tls_static
The meaning of the flag is that static TLS allocation was done.

Taken from NetBSD Joerg Sonnenberger change for src/libexec/ld.elf_so/tls.c
rev. 1.18.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
2023-06-05 22:33:17 +03:00