Commit graph

25380 commits

Author SHA1 Message Date
Andreas Kling a425f421ac Kernel: Port the scheduler's ready queues to SpinLockProtectedValue 2021-08-08 14:24:54 +02:00
Andreas Kling a1c82041a6 Kernel: Simplify the per-CPU SchedulerData struct 2021-08-08 14:24:54 +02:00
Andreas Kling 5712e46ddc Kernel: Remove unused "VGA font" memory region in GraphicsManagement 2021-08-08 14:24:54 +02:00
Andreas Kling 2c1788e2e4 FileOperation: Don't follow symlinks
Deleting a symlink via "FileOperation Delete" should not recursively
delete whatever the symlink is pointing to. Same basic idea applies to
the Copy and Move operations.
2021-08-08 14:24:54 +02:00
sin-ack 8c9c2f46c7 LibGUI: Implement granular updates for FileSystemModel
FileSystemModel will now react to specific events from Core::FileWatcher
in order to granularly update its data based on addition or removal of
files from the tree. Metadata changes are currently not handled, but in
the future they can be used to re-stat() a file to get its updated
statistics.
2021-08-08 14:13:37 +02:00
sin-ack e377b508b7 LibGUI: Prefix some private FileSystemModel::Node members with m_
This commit has no functional changes.
2021-08-08 14:13:37 +02:00
sin-ack 265e2832ef LibGUI: Resize the mapping rows during sort
SortingProxyModel always expected the source model to have the same
number of rows as long as it has not been invalidated. Now that we have
granular updates, this assumption is no longer true, and we need to
resize the source/proxy_rows vectors to the new size. This is safe since
the values in the vector are overwritten right afterwards.
2021-08-08 14:13:37 +02:00
sin-ack 7ba321c91b LibGUI: Implement granular operations for Model subclasses
These can be used by Model subclasses to signal the exact operations
that happened to a model, so that persistent model indices in that
area are not invalidated.
2021-08-08 14:13:37 +02:00
sin-ack d73116e5d5 LibGUI: Implement persistent indices for models
This patch adds persistent indices to models.  A PersistentModelIndex is
a ModelIndex that will survive most model updates (provided that the
data the PersistentModelIndex points to has not been removed by the
model's data store).  PersistentModelIndex objects can be safely held
by objects outside the model they originated from.
2021-08-08 14:13:37 +02:00
sin-ack 1408aa1295 LibGUI: Do not allow tree column to shrink beyond indent and icon
We always display the tree indent and the icon, so we shouldn't allow
the tree column to shrink beyond that size.
2021-08-08 14:12:45 +02:00
sin-ack ab2719fd53 LibGUI: Let the table view tell HeaderView about the min. section size
Previously HeaderView would just assume that each column or row could
have a minimum size of 2. This makes it so that AbstractTableView
subclasses can provide a new minimum value for a specific column.
2021-08-08 14:12:45 +02:00
Marcus Nilsson 854e16797e PixelPaint: Tighten update rects for Tools
This tightens the update rects for EraseTool, BrushTool And the marching
ants update in Selection. Inflate Selection update rect by 10x10 to
avoid misalignment when zoomed out.
2021-08-08 13:55:39 +02:00
Marcus Nilsson 8c81d195c7 PixelPaint: Inflate update rect for PenTool
Previously using PenTool while zoomed in could cause rendering glitches
since the update rect was misaligned with the image, most likely because
of rounding errors.
Loosening the rect with 1 pixel on either side takes care of this.
2021-08-08 13:55:39 +02:00
sin-ack 99dfab08c9 LibGUI: Correctly call update() in ProcessChooser
After the update -> invalidate change a couple places broke when
update() was supposed to be manually called. This instance was not
marked virtual or override, which made it hard to detect. This commit
makes sure that update() on the original model is called when the
RunningProcessesModel needs an update.
2021-08-08 13:46:27 +02:00
Linus Groh 16c38788c3 LibJS: Add missing spec links 2021-08-08 11:04:30 +01:00
Daniel Bertalan 0e21bf0f23 LibJS: Don't overflow size_t in Value::to_length()
Although this is not spec-compliant, we don't have a way to represent
objects larger than `NumericLimits<size_t>::max()`. Since this abstract
operation is only used when dealing with object size, we don't lose any
functionality by taking that limit into account too.

This fixes a UBSAN error when compiling with Clang.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 78e7ff008b LibC: Fix negation overflow UB in sys/mman.cpp
When the system calls return `NumericLimits<ptrdiff_t>::min()`, negating
the return code would produce `NumericLimits<ptrdiff_t>::max() + 1`
since we are on a two's complement architecture. Because this value
cannot be stored, signed overflow occurs which is UB. This can be fixed
by applying the negation to `EMAXERRNO` since that's known to contain a
relatively small value.

Found when running tests with Clang.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 146dcf4856 Tests: Disable UserspaceEmulator tests for Clang builds
There seems to be more incorrect assumptions about Clang-built
executables' memory layout than expected. These make the CI fail even
though the system is functional in all other aspects. While this is
being fixed, let's just disable tests for UserspaceEmulator.
2021-08-08 10:55:36 +02:00
Daniel Bertalan d000ca1ec3 AK: Add typename keyword for dependent types
This was made optional in C++20 in most cases, but Clang doesn't support
omitting it yet. See P0634R3.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 1472f6d986 AK: Add formatting for infinity and NaN
Without this patch, we would end up printing garbage values when we
encountered floating point infinity or NaN values, and also triggered
UBSAN with Clang. This added code models `std::format`'s behavior: the
sign is added the same way as with normal values and the strings 'nan'
and 'inf' are printed.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 12dc2c2079 LibJS: Fix wraparound UB in Value::to_u{8,16}
If we call these two functions on a negative value, undefined behavior
occurs due to casting a negative double to an unsigned integer. These
functions are defined to perform modular arithmetic, so negative values
can be fixed up by adding 2^8/2^16.

The reason why this step is not mentioned in ECMA-262 is that it defines
modular arithmetic so that `x mod m` had the same sign as `m`, while
LibM's `fmod(x, m)` copies `x`'s sign.

This issue was found by UBSAN with the Clang toolchain.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 0a05f04d1b LibJS: Fix UB in Number.IsSafeInteger
Casting a floating point number to an integer and comparing that against
the original value is not a good way to test if it is a whole number. It
may cause unnecessary narrowing conversion issues and UB. This was the
case, which was caught be Clang's `-fsanitize=float-cast-overflow`.

This commit changes the code to use `is_integral_number`, as suggested
in ECMA-262.
2021-08-08 10:55:36 +02:00
Daniel Bertalan fd76e71934 LibJS: Fix UB in Math.clz32
If the argument to this function is greater then or equal to 2^32, the
`double` => `u32` cast produces undefined behavior, which Clang catches.
To fix this, we now use `ToUint32` for getting the integer argument, as
specified by ECMA-262.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 5d32f543ec AK: Handle partial remainders
On x86, the `fprem` and `fmprem1` instructions may produce a 'partial
remainder', for which we should check by reading a FPU flag. If we don't
check for it, we may end up using values that are outside the expected
range of values.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 653d22e21f LibSanitizer+AK: Add float cast overflow handler
This is not enabled by default in GCC, but is in Clang.
2021-08-08 10:55:36 +02:00
Daniel Bertalan e04d20ec20 CI: Try building Serenity with Clang 2021-08-08 10:55:36 +02:00
Daniel Bertalan 9809e685c1 Toolchain: Add caching to BuildClang.sh for CI 2021-08-08 10:55:36 +02:00
Daniel Bertalan 301cab188c AK: Use explode_byte in BumpAllocator.h
When compiling this code with Clang, both branches of the ternary
operator get evaluated at compile-time, triggering a warning about a
narrowing implicit conversion. We can use `explode_byte` instead.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 3a8b8d8a0b SystemMonitor: Remove unused this lambda captures
This fixes an `unused-lambda-capture` warning emitted by Clang, and
reduces the size of the produced lambda object.
2021-08-08 10:55:36 +02:00
Daniel Bertalan fa8507d1ce Kernel: Fix UB caused by taking a reference to a packed struct's member
Taking a reference or a pointer to a value that's not aligned properly
is undefined behavior. While `[[gnu::packed]]` ensures that reads from
and writes to fields of packed structs is a safe operation, the
information about the reduced alignment is lost when creating pointers
to these values.

Weirdly enough, GCC's undefined behavior sanitizer doesn't flag these,
even though the doc of `-Waddress-of-packed-member` says that it usually
leads to UB. In contrast, x86_64 Clang does flag these, which renders
the 64-bit kernel unable to boot.

For now, the `address-of-packed-member` warning will only be enabled in
the kernel, as it is absolutely crucial there because of KUBSAN, but
might get excessively noisy for the userland in the future.

Also note that we can't append to `CMAKE_CXX_FLAGS` like we do for other
flags in the kernel, because flags added via `add_compile_options` come
after these, so the `-Wno-address-of-packed-member` in the root would
cancel it out.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 90caebe96a Documentation: Add explanation for the Clang-based toolchain 2021-08-08 10:55:36 +02:00
Daniel Bertalan 13e3df41de Meta: Add Clang support to the CMake build scripts 2021-08-08 10:55:36 +02:00
Daniel Bertalan 15e217ea68 Toolchain: Add LLVM patch and script for building it
This contains all the bits and pieces necessary to build a Clang binary
that will correctly compile SerenityOS.

I had some trouble with getting LLVM building with a single command, so
for now, I decided to build each LLVM component in a separate command
invocation. In the future, we can also make the main llvm build step
architecture-independent, but that would come with extra work to make
library and include paths work.

The binutils build invocation and related boilerplate is duplicated
because we only use `objdump` from GNU binutils in the Clang toolchain,
so most features can be disabled.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 5d617be462 Kernel: Bump eternal kmalloc range to 4 MiB
Kernels built with Clang seem to be quite allocation-heavy compared to
their GCC counterparts. We would sometimes end up crashing during boot
because the eternal ranges had no free capacity.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 6de392e120 LibWeb: Add missing typeinfo include
Not having this header only causes an issue on Clang builds, since in
libc++, `std::type_info` is only forward-declared in `cxxabi.h`.
2021-08-08 10:55:36 +02:00
Daniel Bertalan e9dd9d1f2c UserspaceEmulator: Use for_each_region_of_type in find_text_region
Since we now have this helper template, we can make our code cleaner.
2021-08-08 10:55:36 +02:00
Daniel Bertalan c1d6637dc7 UserspaceEmulator: Make symbolication work when .text isn't the first
... segment

This happens with binaries build with Clang or with a custom linker
script. If this is the case, offsets should be calculated not from the
base address of `.text`, but from the first section loaded for the
library.

This commit moves all UserspaceEmulator symbolication into a common
helper function and fixes a FIXME.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 980f314a03 UserspaceEmulator: Fix typo in a method name
Changes `load_library_from_adress` to `load_library_from_address`.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 7396e4aedc LibDebug: Store 64-bit numbers in AttributeValue
This helps us avoid weird truncation issues and fixes a bug on Clang
builds where truncation while reading caused the DIE offsets following
large LEB128 numbers to be incorrect. This removes the need for the
separate `LongUnsignedNumber` type.
2021-08-08 10:55:36 +02:00
Daniel Bertalan efd1aea969 AK: Make InputMemoryStream::read_LEB128_* templated
On i686, reading integers larger than `2^32 - 1` would fail as the
32-bit `size_t` parameter would overflow. This caused us to read too few
bytes in LibDebug's DWARF parser. Making this method templated solves
this issue, as we now can call this API with a `u64` parameter.
2021-08-08 10:55:36 +02:00
Daniel Bertalan a59b9357e3 LibDebug: Keep track of 'prologue end'
This LineProgram instruction is emitted by Clang. Although we currently
have no use for it (it's mostly a debugger feature), we need to handle
this opcode, as otherwise CrashReporter wouldn't work.
2021-08-08 10:55:36 +02:00
Daniel Bertalan f94532ea4e WindowServer: Fix Clang crash when compiling Compositor.cpp
Due to a bug in Clang 12, the compilation would fail with an 'unexpected
end-of-file' error when it encounters some of the nested generic lambdas
in `Compositor.cpp`.

Co-authored-by: Peter Bindels <dascandy@gmail.com>
2021-08-08 10:55:36 +02:00
Daniel Bertalan 347c3361ee Kernel: Fix deprecated array comparison
The Clang error message reads like this (`-Wdeprecated-array-compare`):

> error: comparison between two arrays is deprecated; to compare
> array addresses, use unary '+' to decay operands to pointers.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 9265f24816 LibCoreDump: Make narrowing uint64_t => FlatPtr conversion explicit
This fixes a build issue on Clang which returns an error if narrowing is
performed in a list-initialization.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 5f2f460cc8 Tests: Add Clang pragma for turning off optimizations
Clang does not accept `GCC optimize("O0")`, so it fails to build the
system with it.
2021-08-08 10:55:36 +02:00
Daniel Bertalan 7fb41d6250 WindowServer: Fix 'use of GNU old-style field designator'
Since C99 and C++20 have a standardized syntax for designated
initializer, we should use that instead of this GCC-specific extension.
While this currently works both in Clang and GCC, the former emits a
warning for it, while the latter has an [issue] open that plans to
deprecate it.

[issue]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88144
2021-08-08 10:55:36 +02:00
Daniel Bertalan db840aaacd LibGUI: Add break even before empty default label
Clang is a bit more pedantic than GCC when diagnosing implicit
fallthroughs, and doesn't care if the succeeding label only contains a
single break statement.
2021-08-08 10:55:36 +02:00
hstde 7d22713a72 Terminal: Save settings to config file
When exiting the terminal settings window, the opacity, bell and
maximum history size will be saved to the application config file.
Because the color scheme is neither configurable nor
will it be loaded on startup, it will not get saved for now.
2021-08-08 10:53:57 +02:00
Gunnar Beutner 2fec891d8e Meta: Allow attaching GDB to the QEMU instance on the WSL2 host 2021-08-08 01:46:41 +02:00
Gunnar Beutner 45f2e9f3cf Meta: Don't use x86_64 QEMU for the i686 kernel
This seemed like a good idea at the time to avoid an unnecessary
dependency on qemu-system-i386. However this makes debugging the
kernel with GDB more difficult because GDB assumes that the QEMU
architectures matches the kernel architecture.
2021-08-08 01:46:41 +02:00