Before this patch, exec commands were inheriting the environment of the
SSHServer instance while interactive shell spawned with an almost empty
env. Now, both paths start with the same basic environment and also
include modifications requested by the ssh client.
This should improve compatibility in a lot of situations but most
visibly it makes syntax highlighting and autocompletion work in
interactive shells.
The list of default environment variables is heavily inspired by what
OpenSSH is doing. Compared to what it produces on my system, we only
lack XDG_*, SSH_* and DBUS_SESSION_BUS_ADDRESS variables. As noted in
the FIXME the value of PATH also differs.
Now that SSHServer sets us in the user's home directory, there is no
need to block them as they will resolve correctly according to the spec:
"File names starting with a slash are "absolute", and are relative to
the root of the file system. Names starting with any other character
are relative to the user's default directory (home directory)."
Also note that we were only refusing relative paths in the OPEN command,
but STAT was already accepting them (and resolving them incorrectly).
We were already changing the home directory for interactive shells, but
with this change single commands also get executed from the user's home
and SFTP relative paths will also resolve from the correct directory.
(Relative paths are still not allowed in the SFTP layer, but everything
will fall in place once we remove that restriction.)
We now report the actual value instead of simply returning 0/-1. We're
now using the conventional representation for signal-terminated
processes and return an exit-status of 128 + signal number.
This aligns the behavior with both Linux and OpenBSD (and probably all
other implementations of openpty).
This bug was visible in SSHServer, indeed when using an interactive
shell, the start pty size was always the default (80x25) instead of
whatever the client's window is using. It is quite visible with `top`,
which now fills the whole window :^)
With this patch, SSHServer is able to update the pty on the server when
the size of the client's window is updated.
Resizing your terminal emulator's window while being connected to
SSHServer no longer make you disconnect.
While the implementation is functional, it seems to have quite more
latency than with a regular SSH server, so visual artifacts may appear
when aggressively resizing the window.
On Serenity, this uses the equivalent LibC function, otherwise it
defaults to the pretty standard ioctl equivalent.
At the time of writing, it seems that only musl, BSDs and Serenity have
the standardized POSIX function.
Until now, we could only use SSHServer to remotely run single commands
(e.g. `ssh remote command_to_run`). With this patch, we now support
using ssh in the most usual way: starting a remote interactive shell and
then running commands on the host.
This parent will contain the data used for streaming stdin/stdout, the
pid of the child process and a few basic methods required for
subsystems. This refactoring will allow us to easily introduce another
kind of child-managing subsystem, used for interactive shells.
This is a step towards supporting interactive shells with SSHServer.
This request includes the options to create the pty associated with the
shell.
Note that we don't validate or do anything else with the options
themselves. We just store them, and any issues with the values will be
discovered when we actually create the pty during the handling of the
"shell" request.
We already use 8-bytes types for the statvfs syscall, so this change
allows filesystems that support massive sizes to be able to report them
to userspace without being truncated.
The rest of the plumbing already used 64-bits types, making
FileSystemSpecificOption silently truncate the arguments.
With this patch, we can now create RAMFS filesystems with a size above
4 GiB.
For the moment, this only considers the size of files' content without
counting the inodes' cost. While being imprecise, this should already
give a pretty good estimate of the RAM usage caused by these
filesystems.
The value for LOGICAL_BLOCK_SIZE is quite arbitrary as the filesystem
doesn't have blocks, so it's only used as a unit (counting in KiB
instead of bytes).
For the moment, the default maximum size is set to zero (disabled), so
no limits are enforced, it just reports the number of used blocks.
When using the default iterator, the region tree is traversed in
ascending order. This mean that as soon as we find a region that is
above the tested range, we can safely exit the loop.
This was a major bottleneck in test-js, with this patch the runtime goes
from 6.761s to 4.680 (using a best-of-five).
Per POSIX:
If either the old or new argument names a symbolic link, rename() shall
operate on the symbolic link itself, and shall not resolve the last
component of the argument.
Per POSIX:
If path names a symbolic link, mkdir() shall fail and set errno to
[EEXIST].
The test needs to be done in a subfolder of /tmp, I suppose that it
comes from the custom branch for mounted folders in
`resolve_path_without_veil`. Otherwise, the behavior is quite different
and seems to involve other bugs too.
The singleton class has the side effect of not calling the destructor of
the class, so ~SignalHandlers() was never called and the signal handlers
were never restored.
While restoring the signal handlers at exit is useless in most cases,
this patch fixes a hang at exit when running Shell in a configuration
using GCC and LSan. The sanitizers create a child process to be able
to monitor the parent. Then, when this child exits, the SIGCHLD signal
tried to run the handler installed by Shell, this caused ASan to trip
while LSan was running which causes the hang.
Note that the current implementation of lgamma doesn't work for negative
values of x. But given that Stirling's approximation is also only
defined for positive values of x, this patch don't change anything in
that regard.
On some platforms, like macOS on ARM, long double is a different type
but has the exact same characteristics as a normal double. When it is
the case, define FloatExtractor<long double> as an alias to
FloatExtractor<double>.
By zeroing registers when returning from crypto functions, we prevent
attackers from accessing sensitive information that could otherwise be
left in these registers.
Note that we currently have no safety regarding the same kind of
leakage but with stack or heap memory.
From some small experiments, the performance cost should be under 5%.
This could probably be optimized by only applying it to the public API.
This allows us to see the coverage of each library without transitive
usages. As an example, Vector::clone() is never tested directly in
Tests/AK, and it's coverage depends on an external test or library. This
means that its coverage is fragile as the code using it in tests might
be dropped in the future.
This will allow everything defined in headers to be instrumented. As an
example, the function `AK::any_of` isn't instantiated inside AK, that
means that no coverage is reported if we don't consider the
instantiation in the test binary itself.
Max ULP Mean ULP
Before: inf 998274894113382.2500
After: 7352987.00 18.7027
While this is already a lot better, the error is still significant. This
is mainly due to the areas around the roots of lgamma(x) (x=1 and x=2)
where the results are close to zero and thus requires tiny absolute
errors. On (0, 0.7] ∪ [2.3, 8) the maximum error is 20 ULP.
This introduces a lot of polynomials, but I don't think we have another
choice here (CORE-MATH uses even more on the same interval). To find the
subdivisions, I simply searched for x so that a degree 12 polynomial
would have a small error (~1e-18) on [x, 8] and then repeated the
process until the full [0, 8] interval was filled.
This is done by using a polynomial to compensate the mathematical error
term of the stirling approximation.
Max ULP Mean ULP
Before: 6697252309907.00 725249701724.2207
After: 2.00 0.4674
With this change, when we're done with our test the SIGCHLD handler is
set back to the default one. This fixes an issue when running the test
under LSan with libsanitizers. LSan works by forking and then using
ptrace on the parent to inspect its address space, when this child exits
it was triggering our handler and caused a crash. Restoring the default
handler solves the issue. For some reason, this only happens with GCC's
implementation of LSan while this works fine with Clang's.
The tool depends on MPFR, which is not listed as a required dependency
on all platforms (e.g. macOS). So let's disable CompareAKMathAgainstMPFR
by default instead of adding a new dependency.
To build the tool, set ENABLE_COMPARE_AK_MATH_AGAINST_MPFR to ON in your
Lagom directory.
In the CORE-MATH codebase, not all mpfr-based math functions set the
exponents limits, some assume it is done before calling them. So let's
set it globally and remove the call to mpfr_set_emin code in exp().
This tool runs a bunch of accuracy and performance tests on standard
math functions. The accuracy is measured against the MPFR library, which
provides results precise enough to be correctly rounded to double
precision floating points.
By default, the tool test the math functions from AK but a runtime flag
can be used to instead test the system's libm.
A few test cases are internally generated, but to get more precise
results the tool is capable of reading worst-cases files from the
CORE-MATH project. The location of the repository should be given with
the --core-math PATH option.
Heavily inspired by https://github.com/nico/js-math-bench.
It's wasteful to compute everything with long double precision when we
don't need it, so this change will be required down the road when we get
to make erf precise and fast. For the time being, this is more a
cosmetic change to align this implementation with others.
Before this commit, you could either use the inlinable function by
using the macro or have the externally-linked version by first
undefining the macro and then using the function.
This commit makes all the ctype functions both inlinable and have
external linkage at the same time. To pull this trick, we provide
inlinable definitions in ctype.h and use a dedicated C feature that
forces the symbol to be emitted in the TU of ctype.c.
This could also have been achieved by using some #ifdef to hide the
inline definition in ctype.h so a C++ compiler would still emit a normal
symbol for the functions in ctype.cpp.
This only affect the output if the current locale has alternative
representations. Given that on Serenity we only use the POSIX/C locale,
and it doesn't have any alternative representations, these modifiers are
basically useless.
"If the alternative format or specification does not exist for the
current locale [...], the behavior shall be as if the unmodified
conversion specification were used."
According to POSIX:
"In the POSIX locale the value of {MB_CUR_MAX} shall be 1."
As we only support "POSIX"-compatible locales, let's make MB_CUR_MAX
equal to 1. Note that if we start to support other locales, this macro
will need to defer to a runtime function.
The C++ standard defines strchr, strrchr, strpbrk, strstr and memchr
differently than POSIX. To be conformant, we need to provide a different
signature when __cplusplus is defined.
This is the same logic as 73d178af, but applied to string.h.
Two functional changes were also applied:
- We no longer check for errno, as mandated by POSIX,
pthread_cond_timedwait returns the error directly.
- I reduced the wait time so the test run in ~2s rather than ~75s.
This will allow Toolchain's scripts to use the same logic. Note that we
use a symlink in the Ports directory so Meta/install-ports-tree.sh can
just copy the link's destination to have a working and self-contained
copy.
For symlinks targeting directories, `git ls-files` only lists the
symlink file and not the content of the targeted directory, so let
`rsync` go recursive on these.
This allows us to also install patches for binutils, gcc and llvm.
Co-authored-by: Eduardo Casadei <[email protected]>
This class should be used instead of Error in code paths shared between
kernel and user processes that cannot fail, but may be interrupted while
running in a user process. This generally includes code that may block
on a WaitQueue or a Mutex.
AFAICT, this is what most syscalls specify:
[ENOENT]
A component of the path prefix specified by path does not name an
existing directory or path is an empty string.