Commit Graph

57561 Commits

Author SHA1 Message Date
Idan Horowitz
f7a1f28d7f Kernel: Add initial basic support for KASAN
This commit adds minimal support for compiler-instrumentation based
memory access sanitization.
Currently we only support detection of kmalloc redzone accesses, and
kmalloc use-after-free accesses.

Support for inline checks (for improved performance), and for stack
use-after-return and use-after-return detection is left for future PRs.
2023-12-30 13:57:10 +01:00
Andreas Kling
7ad7ae7000 AK: Check URL parser input for invalid (tabs or spaces) in 1 pass
Combine 2 passes into 1 by iterating over the input once and checking
for both '\t' and '\n'.
2023-12-30 13:49:50 +01:00
Andreas Kling
7e2d9bfd53 LibWeb: Avoid String<->ByteString src conversion in HTMLImageElement
We already have the src attribute stored as a String, so it's completely
wasteful to convert it to a ByteString. We were even doing it twice when
loading each image.
2023-12-30 13:49:50 +01:00
Andreas Kling
a19d8a4a37 AK: Add ASCII fast path to Utf8CodePointIterator
Much of the UTF-8 data that we'll iterate over will be ASCII only,
and we can get a significant speed-up by simply having a fast path
when the iterator points at a byte that is obviously an ASCII character
(<= 0x7F).
2023-12-30 13:49:50 +01:00
Andreas Kling
75cecd19a5 AK: Skip UTF-8 validation inside URL parser
Since we're already building up a percent-encoded ASCII-only string
in the internal parser buffer, there's no need to do a second UTF-8
validation pass before assigning each part of the parsed URL.

This makes URL parsing signficantly faster.
2023-12-30 13:49:50 +01:00
Andreas Kling
f045a877b4 AK: Implement StringBuilder::append_code_point() more efficiently
Instead of do a wrappy MUST(try_append_code_point()), we now inline
the UTF-8 encoding logic. This allows us to grow the buffer by the
right increment up front, and also removes a bunch of ErrorOr ceremony
that we don't care about.
2023-12-30 13:49:50 +01:00
Andreas Kling
bacbc376a0 AK: Make StringView::contains(StringView) faster for 1-byte needles
If we're looking for a 1-byte string, we can do the much simpler byte
scan by simply forwarding the call to StringView::contains(char).
2023-12-30 13:49:50 +01:00
Andreas Kling
6c51ba27a2 AK: Make URL percent encoding faster by exploiting ASCII knowledge
Once we know that a code point must be a valid ASCII character,
we now cast it to `char` and avoid the expensive generic
StringView::contains(u32 code_point) checks.

This dramatically speeds up URL parsing.
2023-12-30 13:49:50 +01:00
Andreas Kling
0ad4be3d78 LibJS: Skip redundant UTF-8 validation in rope string resolution
When resolving a rope, we've already taken care to resolve it to
a UTF-8 byte stream. There's no need to do a separate pass just for
validating the data again.

This was noticeable in some profiles. I made a simple microbenchmark
that gets a 30% speed-up:

    ("x" + "y".repeat(100_000_000)).trimStart()
2023-12-30 13:49:50 +01:00
Andreas Kling
3c039903fb LibTextCodec+AK: Don't validate UTF-8 strings twice
UTF8Decoder was already converting invalid data into replacement
characters while converting, so we know for sure we have valid UTF-8
by the time conversion is finished.

This patch adds a new StringBuilder::to_string_without_validation()
and uses it to make UTF8Decoder avoid half the work it was doing.
2023-12-30 13:49:50 +01:00
Andreas Kling
a285e36041 LibJS+AK: Make String.prototype.repeat() way faster
Instead of using a StringBuilder, add a String::repeated(String, N)
overload that takes advantage of knowing it's already all UTF-8.

This makes the following microbenchmark go 4x faster:

    "foo".repeat(100_000_000)

And for single character strings, we can even go 10x faster:

    "x".repeat(100_000_000)
2023-12-30 13:49:50 +01:00
Andreas Kling
9ce267944c LibWeb: Fix crash in HTML encoding detection when handling non-ASCII
The fix here was to stop using StringBuilder::append(char) when told to
append a code point, and switch to StringBuilder::append_code_point(u32)

There's probably a bunch more issues like this, and we should stop using
append(char) in general since it allows building of garbage strings.
2023-12-30 13:49:50 +01:00
Andreas Kling
83f43310fa LibWeb: Add spec comments and fixups to "get an attribute" prescan algo
In particular, make some minor adjustments so it flows a little more
like the spec.
2023-12-30 13:49:50 +01:00
Andreas Kling
bf5ad56085 LibWeb: Ignore preconnect requests for file: and data: URLs
I noticed while debugging a fully downloaded page that it was trying
to preconnect to a file:// host. That doesn't make any sense, so let's
add a tiny bit of logic to ignore preconnect requests for file: and
data: URLs.
2023-12-30 13:49:50 +01:00
Aliaksandr Kalenik
ac6b3c989d LibWeb: Apply scroll boxes offsets after painting commands recording
With this change, instead of applying scroll offsets during the
recording of the painting command list, we do the following:
1. Collect all boxes with scrollable overflow into a PaintContext,
   each with an id and the total amount of scrolling offset accumulated
   from ancestor scrollable boxes.
2. During the recording phase assign a corresponding scroll_frame_id to
   each command that paints content within a scrollable box.
3. Before executing the recorded commands, translate each command that
   has a scroll_frame_id by the accumulated scroll offset.

This approach has following advantages:
- Implementing nested scrollables becomes much simpler, as the
  recording phase only requires the correct assignment of the nearest
  scrollable's scroll_frame_id, while the accumulated offset from
  ancestors is applied subsequently.
- The recording of painting commands is not tied to a specific offset
  within scrollable boxes, which means in the future, it will be
  possible to update the scrolling offset and repaint without the need
  to re-record painting commands.
2023-12-30 11:10:24 +01:00
Andrew Kaster
d3025668a4 Revert "Kernel+Userland: Implement support for PS2 scan code set 2"
This reverts commit 61a385fc01.

The commit broke the shift and caps lock key from working.
2023-12-29 22:02:19 +01:00
Andrew Kaster
68b0826107 Revert "Kernel: Add boot parameter to determine i8042 first port translation"
This reverts commit 0379742d7e.

Commit 61a385fc01 breaks the shift and
caps lock key, but depends on this one.
2023-12-29 22:02:19 +01:00
Lucas CHOLLET
73c8b4865e LibGfx/TIFF: Add AdobeDeflate compression support
This new compression is quite popular and uses a basic Zlib compression
to compress strips. Note that this is not part of the original TIFF
specification but in the Technical Notes from 2002:
https://web.archive.org/web/20160305055905/http://partners.adobe.com/public/developer/en/tiff/TIFFphotoshop.pdf

The test case was generated with GIMP.
2023-12-29 20:12:07 +01:00
Nico Weber
9c5a75067f LibGfx/JPEG: Reject ycck or cmyk jpegs with k subsampled for now
The decoder assumes that k's sampling factor matches y's at the moment.
Better to error out than to silently render something broken.

For ycck, covered by ycck-2111.jpg in the tests.
2023-12-29 18:55:57 +01:00
Andrew Kaster
3c7abe22ca LibWeb: Skip window-scrollTo test that keeps timing out on macOS 2023-12-29 17:03:51 +01:00
Sönke Holz
28a3089dc3 Kernel/riscv64: Return correct range in kernel_virtual_range on RISC-V
riscv64 doesn't use a prekernel, so use the same code as aarch64 for
determining the kernel virtual address range.
2023-12-29 16:45:08 +01:00
Liav A
0379742d7e Kernel: Add boot parameter to determine i8042 first port translation
This can be used mainly for bare metal hardware, if the user experiences
problems with output from the PS2 keyboard.
2023-12-29 16:40:59 +01:00
Liav A
61a385fc01 Kernel+Userland: Implement support for PS2 scan code set 2
This scan code set is more advanced than the basic scan code set 1, and
is required to be supported for some bare metal hardware that might not
properly enable the PS2 first port translation in the i8042 controller.

LibWeb can now also generate bindings for keyboard events like the Pause
key, as well as other function keys (such as Right Alt, etc).

The logic for handling scan code sets is implemented by the PS2 keyboard
driver and is abstracted from the main HID KeyboardDevice code which
only handles "standard" KeyEvent(s).
2023-12-29 16:40:59 +01:00
Liav A
60a96b3786 Userland: Actually use the correct character map index from KeyEvent
Instead of using a scan code, which for scan code set 2 will not
represent the expected character mapping index, we could just use
another variable in the KeyEvent structure that correctly points to the
character index.

This change is mostly relevant to the KeyboardMapper application, and
also to the WindowServer code, as both handle KeyEvents and need to
use the character mapping index in various situations.
2023-12-29 16:40:59 +01:00
Liav A
b89cc81674 Kernel/HID: Expose character map index in the KeyEvent structure
This will be used later on by WindowServer so it will not use the
scancode, which will represent the actual character index in the
keyboard mapping when using scan code set 2.
2023-12-29 16:40:59 +01:00
Linus Groh
9a5bba2ba4 Kernel: Enable MULTIBOOT_VIDEO_MODE by default
This is required for pretty much every bare metal install and doesn't
seem to have any effect on running in QEMU, so let's enable it by
default.
2023-12-29 16:17:07 +01:00
Timothy Flynn
c4e2c725ec Ladybird/Qt: Ensure the Inspector widget is deleted before the WebView
According to Qt documentation, destruction of a QObject's children may
happen in any order. In our case, the Tab's WebContentView is deleted
before its InspectorWidget. The InspectorWidget performs cleanup on that
WebContentView in its destructor; this causes use-after-free since it
has already been destroyed.

From reading Qt threads, if a particular destruction order is required,
it is okay to enforce that order with manual `delete`s. This patch does
so with the InspectorWidget to ensure it is deleted before the
WebContentView. Qt's object ownership is okay with this - it will remove
the InspectorWidget from the Tab's children, preventing any double
deletion.
2023-12-29 15:48:06 +01:00
Nico Weber
a2bd19fdac LibGfx/JPEG: Make ycck jpegs with just cc subsampled decode correctly
We currently assume that the K (black) channel uses the same sampling
as the Y channel already, so this already works as long as we don't
error out on it.
2023-12-29 09:45:31 -05:00
Nico Weber
4236798244 Tests/LibGfx: Add automated tests for ycck jpegs
Only one of the three test cases pass at the moment.
2023-12-29 09:45:31 -05:00
kleines Filmröllchen
c5a6214a3b Tests: Don't include LibWebView test if LibWeb is disabled
This unbreaks ENABLE_LAGOM_LIBWEB=OFF again.
2023-12-29 09:44:22 -05:00
Mr.UNIX
09af16f6ed Ports: Bump gawk to 5.3.0 2023-12-29 12:00:01 +01:00
Mr.UNIX
ae7d0f18ec Ports: Bump libssh2 to 1.11.0 2023-12-29 11:58:21 +01:00
Mr.UNIX
c382db351a Ports: Bump gettext to 0.22.4 2023-12-29 11:58:21 +01:00
Mr.UNIX
deb3e1eb7a Ports: Bump byacc to 20230521 2023-12-29 11:58:21 +01:00
Andrew Kaster
0c025c7d7e LibCore: Default to a temp directory for runtime directory on non-Linux
/run/user/$uid is a systemd-ism, and is not present on other platforms.
2023-12-29 09:46:50 +01:00
Andrew Kaster
053e4d5e64 AK: Only try to print gettid() in dbgln on Linux and Serenity
On every other Unix, the relationship between thread id and process id
is not nearly as direct.
2023-12-29 09:46:50 +01:00
Timothy Flynn
3f3686cf7b LibJS: Implement missing steps from the ArrayBuffer transfer proposal
We can now implement steps related to resizable ArrayBuffer objects. We
can also implement a couple of missing SharedArrayBuffer checks.

The original implementation of this proposal did not have any tests, so
tests are added here for the whole implementation.
2023-12-29 09:25:41 +01:00
Timothy Flynn
526a74f2f1 LibJS: Implement missing checks for SharedArrayBuffer values 2023-12-29 09:25:41 +01:00
Timothy Flynn
299c86db20 LibJS: Change error message for values that can't be a SharedArrayBuffer
This error will be used in contexts that apply to more than than the
|this| object.
2023-12-29 09:25:41 +01:00
Timothy Flynn
834ced9ef8 LibJS: Change error message for values that must be a SharedArrayBuffer
This error will be used in contexts that apply to more than TypedArrays.
2023-12-29 09:25:41 +01:00
Aliaksandr Kalenik
d4a6564e5a LibWeb: Do not use Optional for aa_translation in RecordingPainter
This allows to remove checks whether translation has value, as it does
not change anything because default value for point is zero.
2023-12-29 09:23:27 +01:00
Nico Weber
e735ee5251 Tests/LibGfx: Add YCCK jpeg test files
Obtained by running:

    convert rgb_components.jpg -colorspace cmyk \
        -sampling-factor 1 ycck-1111.jpg
    convert rgb_components.jpg -colorspace cmyk \
        -sampling-factor 2 ycck-2111.jpg
    convert rgb_components.jpg -colorspace cmyk ycck-2112.jpg

where rgb_components.jpg is the file in Tests/LibGfx/test-inputs/jpg.

(I used the web version of `convert` at
https://cancerberosgx.github.io/magic/playground/index.html)

While this does indeed produce a cmyk jpg (using the YCCK encoding
internally), it uses the mathematical rgb->cmyk conversion and does
not embed an cmyk color space in the output jpg.

Normally, cmyk images are for printing and hence converting them
from cmyk to rgb using a color profile like SWOP leads to better
results. So if a cmyk image does not contain color space information,
applications might use something like SWOP instead of the simple
math transform to convert to RGB. Programs doing that will show
these images as fairly muted (and would arguably be correct doing
so).

Hence, tests using these images shouldn't check their RGB values.
Ideally, we'd add a way to get the raw cmyk data from a cmyk jpeg,
and then tests could test color values against that.

The -1111 image uses no subsampling, meaning each channel's sampling
factor is 1.

The -2111 image uses subsampling for the non-Y channels, meaning the
sampling factors are 2 for Y and 1 each for YYK.

The -2112 image uses subsampling for the two C channels, meaning the
sampling factors are 2 for Y and K and 1 each for YY.

We correctly render the -1111 variant (using e.g.
`Build/lagom/bin/image -o out.png .../ycck-1111.jpg).

We render the -2111 variant, but it looks pretty broken.

We refuse to decode the -2112 variant. This is #21259.

Manual tests for now, but having these in tree will make it easier
to write unit tests later, once things work better.
2023-12-29 08:17:10 +00:00
Lucas CHOLLET
97ded2dc61 FileManager: Conditionally display the "ICC profile:" line
If the "ICC Profile" group is shown, no need to include the related line
in the "Image" group.
2023-12-29 07:57:12 +00:00
Hendiadyoin1
16b14b0688 Meta: Add an isa-debugcon to the q35 machine
Otherwise we would not print debug output to the host console, which we
did in the old run.sh
2023-12-28 17:08:34 +01:00
Hendiadyoin1
5d7ce0343f Meta: Hook up the UHCI HCs up to the EHCI HCs in the q35 machine
Now devices connected to the EHCI controllers show up on the hooked up
UHCI companion controllers.
2023-12-28 17:08:34 +01:00
Hendiadyoin1
f4bfd0468b Kernel/USB: Add a rudimentary interrogation only EHCI driver
This adds a simple EHCI driver that currently only interrogates the
device and checks if all ports are addressable via associated legacy
controllers (companion controllers), and warns if this is not the case.

This also adds a lot of the other data structures needed for actually
driving the controller, but these are currently not hooked up to
anything.

To test this run with `SERENITY_EXTRA_QEMU_ARGS="--device usb-ehci"`
or the q35 machine type
2023-12-28 17:08:34 +01:00
Jami Kettunen
a768685d16 Meta: Add support for QEMU 8.2 audio
Still try parsing the now gone "-audio-help" output first, then attempt
the new "-audiodev help" if stdout was empty. This fixes support for
QEMU 8.2+ audio since "-audio-help" is now an invalid option.
2023-12-28 16:52:20 +01:00
Andreas Kling
6fe6166607 LibWeb: Put a cap on how many image loads we'll batch up before flushing
The BatchingDispatcher mechanism is used by HTMLImageElement to avoid
decoding one image at a time, since interleaving decode/layout/repaint
over and over takes way more time than doing many decodes followed by
a single layout/repaint pair.

Before this change, we didn't have a limit on how many batched loads
we'd allow ourselves to queue up, which could lead to situations where
more and more images kept being added to the queue, and never getting
processed.

This fixes the issue by putting an arbitrary limit (16) on the number
of batched image loads, and then allowing the flush to happen after
that instead of re-deferring processing.
2023-12-28 14:39:15 +01:00
Andreas Kling
473f3a0931 LibWeb: Stop rendering the src (URL) as image alt attribute fallback
If an image element has no alt attribute, other browsers don't fall back
to using the src attribute like we did.

This gave us a janky look while loading pages that other browsers don't
have, and it's not like seeing a partial URL is really helpful to the
user anyway.
2023-12-28 14:39:15 +01:00
Timothy Flynn
f1e01a681e LibJS: Implement missing conditional when creating a TypedArray subarray 2023-12-28 08:19:02 -05:00