Commit graph

10391 commits

Author SHA1 Message Date
kleines Filmröllchen
fc7d231b00 LibIPC: Allow transporting a SharedCircularQueue over IPC 2022-04-21 13:55:00 +02:00
kleines Filmröllchen
6b13436ef6 LibCore: Introduce SharedSingleProducerCircularQueue
This new class with an admittedly long OOP-y name provides a circular
queue in shared memory. The queue is a lock-free synchronous queue
implemented with atomics, and its implementation is significantly
simplified by only accounting for one producer (and multiple consumers).
It is intended to be used as a producer-consumer communication
datastructure across processes. The original motivation behind this
class is efficient short-period transfer of audio data in userspace.

This class includes formal proofs of several correctness properties of
the main queue operations `enqueue` and `dequeue`. These proofs are not
100% complete in their existing form as the invariants they depend on
are "handwaved". This seems fine to me right now, as any proof is better
than no proof :^). Anyways, the proofs should build confidence that the
implemented algorithms, which are only roughly based on existing work,
operate correctly in even the worst-case concurrency scenarios.
2022-04-21 13:55:00 +02:00
Andreas Kling
02c18bf6de LibC: Stub out posix_memalign() 2022-04-21 11:50:38 +02:00
Andreas Kling
ab878576bb LibC: Make nameinfo (NI_*) constants bitfield-friendly
These are supposed to be used as flags in a bitfield, so let's make
them powers of two.
2022-04-21 11:50:38 +02:00
Andreas Kling
a353ceecf1 LibC: Implement errno via a __errno_location() function
This matches how some other systems implement errno, and makes 3rd party
software that expect us to have __errno_location() work.
2022-04-21 11:49:48 +02:00
Linus Groh
95541d7064 LibWeb: Fix various spec comment inconsistencies
- Don't add multiple numbers to nested steps, just the innermost one
  (as rendered in the HTML document)
- "Otherwise" comments go before the else, not after it
- "FIXME:" goes before step number, not between it and the comment text
- Always add a period between number and comment text

The majority of these were introduced in #13756, but some unrelated ones
have been updated as well.
2022-04-20 19:49:01 +02:00
Michael Manganiello
56081cdb6e LibGUI: Remove Tile.date_time member from Calendar
Currently, navigating through different years in the Year view of the
Calendar app or the taskbar is very slow.
Profiling results show that almost all the time is spent in
`Calendar::update_tiles`, and specifically, in `DateTime::create` and
`DateTime::set_time`.

Performance can improve substantially if the `TZ` environment variable
is set [0], but we can improve the current code to perform better
nevertheless :^)

This diff focuses on removing the need of the `Tile` struct to require
the instantiation of a `DateTime` object, which avoids _at least_ 365
object instantiations in the Year view, on each `update_tiles` call.
Instead, as the `date_time` isn't used often, we can instantiate it on
demand when a particular date is selected.

[0] https://blog.packagecloud.io/set-environment-variable-save-thousands-of-system-calls/
2022-04-20 18:37:56 +02:00
faxe1008
9e323241f8 LibGUI: Use fuzzy matching in CommandPalette
This patch changes the previously used contains method for matching the
user search term with all available commands to use the fuzzy match
algorithm, which makes it more typo tolerant.
2022-04-20 18:34:09 +02:00
faxe1008
1074c399f3 LibGUI: Close CommandPalette on active window change
This patch makes CommandPalette be closed whenever the focus shifts from
the dialog. It is closer to other non-serenity implementations of the
CommandPalette and other modal dialogs in the system.
2022-04-20 18:34:09 +02:00
Leonardo Duarte
62baf25f0b LibGfx: Avoid signed comparison in find_largest_image
I believe the issue was caused by the product of two u16s being promoted
to (signed) int, which can cause unwanted overflow behaviour when
comparing to size_t. Casting each term to size_t before the
multiplication makes the comparison unsigned.
2022-04-20 16:01:09 +03:00
Jelle Raaijmakers
65d4fb7649 LibGL: Set W-coordinate to 1 in glRect*
According to the spec, these calls should be identical to an invocation
of `glVertex2*`, which sets the W-coordinate to 1 by default.

This fixes the credits sequence rendering of Tux Racer.
2022-04-20 14:12:56 +02:00
Jelle Raaijmakers
e1a6966863 LibSoftGPU: Check for bottom edge in top-left rule in Device
If a triangle edge is completely horizontal and moving in a positive X
direction, we were erroneously treating it as a top edge. This adds
a better check that accounts for those edges. :^)
2022-04-20 14:12:56 +02:00
Jelle Raaijmakers
838cee37a2 LibSoftGPU: Simplify Clipper interpolation
By setting the clip plane normals' W coordinate to 1, we can skip two
coordinate retrievals and three additions. This works because the
Vector `.dot()` operation multiplies the W coordinates of both vectors.
2022-04-20 14:12:56 +02:00
Jelle Raaijmakers
f680d82086 LibSoftGPU: Reuse edge function for front/back culling
We sat on a throne of lies: our `edge_function()` returned positive
values for _clockwise_ vertex rotation instead of _counter-clockwise_,
which was hidden by the fact that we were forcing everything into CW
rotation by an erroneous area comparison (`> 0` instead of `< 0`).

This simplifies our culling code significantly.
2022-04-20 14:12:56 +02:00
Jelle Raaijmakers
26a463506e LibSoftGPU: Use AK::abs directly instead of fabsf
Let's not go through LibC.
2022-04-20 14:12:56 +02:00
stelar7
1c0d29b8da LibWeb: Add spec comments to Node
This also implements a few more steps of compare_document_position,
and removes an invalid step from clone_node
2022-04-20 14:07:38 +02:00
stelar7
62bd88dc14 LibWeb: Add spec comments to EventTarget 2022-04-20 14:07:38 +02:00
stelar7
8055b0a9b9 LibWeb: Add spec comments to Event 2022-04-20 14:07:38 +02:00
stelar7
6b859db2e0 LibWeb: Add spec comments to EventDispatcher 2022-04-20 14:07:38 +02:00
Linus Groh
e815d3f9ce LibJS: De-duplicate ClassFieldDefinition Records
This was defined twice, despite being the very same thing:
- ClassElement::ClassFieldDefinition
- ECMAScriptFunctionObject::InstanceField

Move the former to a new header and use it everywhere. Also update the
define_field() AO to take a single field instead of separate name and
initializer arguments.
2022-04-20 00:08:32 +02:00
Ali Mohammad Pur
7a02d33cd5 LibGUI: Make GUI::Variant an actual Variant
Previously this had its own massive tagged union implementation with
some POD types to represent non-POD types that could be put in the
variant; implement it via a Variant and get rid of the manual
pointer/ref handling.

This commit does not change any semantics on the type, just the
underlying implementation (and removes an unused ::clear() method).
2022-04-20 00:15:23 +04:30
Leonardo Duarte
335fae9a71 LibC: Return early in time_to_tm for large time_t
POSIX says that localtime should fail with EOVERFLOW if the result
cannot be represented, which is the case for most large (in absolute
value) time_t inputs, since they overflow (or underflow) tm_year, which
is an int. This patch introduces this functionality. Previously, tm_year
just overflowed (or underflowed) silently.

Incidentally, this partially fixes #12729 without solving the root
problem, which is that time_to_tm is linear in its input to determine
the number of years since epoch.

This means that the bash port mktime test no longer times-out in 60s,
but it still fails (faster) in some other place. Due to underlying issue
in the algorithm, the worst case inputs still take a couple of seconds
on my machine.
2022-04-19 10:06:23 -04:00
Sam Atkins
9272c3283b LibWeb: Add missing StyleValue::equals() methods
Every StyleValue type now has its own `equals()` method, rather than
relying on the default "compare the to_string() output" method, which
has now been removed. This logic is still used by UnresolvedSV and
CalculatedSV, because it's probably the best option for them unless
performance becomes a real issue.

Also took this opportunity to move all the `equals()` implementations
into the .cpp file, which may or may not actually help with compile
times but StyleValue.h is huge and included everywhere, so it can't
hurt.
2022-04-18 21:30:51 +02:00
Sam Atkins
ce5914230f LibWeb: Actually use BorderRadiusShorthandStyleValue
Somehow we were never actually using this before, but parsing the
property as a StyleValueList instead.
2022-04-18 21:30:51 +02:00
Sam Atkins
025ee02144 LibWeb: Add missing [as/is]_border_radius_shorthand() methods 2022-04-18 21:30:51 +02:00
Sam Atkins
d9afc2d6f2 LibWeb: Rename CombinedBorderRadiusSV -> BorderRadiusShorthandSV 2022-04-18 21:30:51 +02:00
Ali Mohammad Pur
e1cd36559d LibJS: Make the BC generator.next(value) work
This used to put the value in the previous frame's accumulator register,
which is only correct for the first invocation of the generator.
2022-04-18 23:59:30 +04:30
Ali Mohammad Pur
d5791c85b4 LibJS: Avoid copying the frame into the interpreter in BC generators 2022-04-18 23:59:30 +04:30
Ali Mohammad Pur
dd5fb7b32a LibLine: Reset next suggestion index when resetting suggestions
Otherwise we'd end up starting at the previous index on another
suggestion list.
2022-04-18 19:53:10 +04:30
Ali Mohammad Pur
1699ddc186 LibLine: Make it possible to avoid autocompletion if requested
Setting 'allow_commit_without_listing' to false will now make LibLine
show the suggestion before actually committing to it; this is useful for
completions that will replace all the user input, where mistakes can go
unnoticed without some visual cue.
2022-04-18 19:53:10 +04:30
Ali Mohammad Pur
d5b3998d23 LibLine: Respect the provided completion static offset
Now that we can resolve these correctly and they're per-suggestion, we
can finally use them for their intended purpose of letting suggestions
overwrite stuff in the buffer.
2022-04-18 19:53:10 +04:30
Ali Mohammad Pur
6aceec4535 LibLine: Don't use fdopen() for stream in edit_in_external_editor()
We would have to fclose() it to be clean and nice, but that would close
the fd; instead just duplicate it and write through that, this makes it
actually write to the file.
2022-04-18 19:53:10 +04:30
Sam Atkins
00782d9a59 LibWeb: Disallow trailing commas in transform function arguments 2022-04-18 14:16:28 +02:00
Sam Atkins
b3a6044fd8 LibWeb: Disallow non-whitespace tokens after "none" in transform
Before this, a declaration like `transform: none yellow 20;` would be
parsed as `transform: none;`. Now it's correctly rejected as invalid.
2022-04-18 14:16:28 +02:00
Sam Atkins
a52f6fb5b0 LibWeb: Use TransformFunctionMetadata when parsing their arguments
Now, the parser will reject a transform function if:
- There are too many arguments.
- There are too few arguments.
- An argument is the wrong type.
2022-04-18 14:16:28 +02:00
Sam Atkins
61ad39b110 LibWeb: Use generated TransformFunction enum and functions 2022-04-18 14:16:28 +02:00
Sam Atkins
5f3498d50f LibWeb: Add code generator for CSS transform functions
This first step just generates the TransformFunction enum, but more will
follow.
2022-04-18 14:16:28 +02:00
Sam Atkins
f240def414 LibCore: Allow inspecting any process launched with MAKE_INSPECTABLE=1
For now, EventLoop and Application still have a make_inspectable
parameter, so that when working on an application you can temporarily
hard-code it to be inspectable rather than having to set the env var
each time.
2022-04-18 12:57:34 +02:00
Linus Groh
472ff7a6d4 LibJS: Don't coerce this value in %IteratorPrototype%[@@iterator]
Another day, another mistake that's been there for a long time but
would've been immediately obvious when adding spec comments. :^)
2022-04-18 00:24:02 +02:00
Linus Groh
ee1379520a LibJS: Add missing whitespace around namespace curly braces 2022-04-17 23:00:35 +02:00
stelar7
196dada7e2 LibWeb: Dont abort when parsing data- properties that contain dashes 2022-04-17 20:08:27 +03:00
Michiel Visser
fa18c283dc LibTLS: Cleanup of verify_chain and verify_certificate_pair 2022-04-17 10:10:19 +04:30
Michiel Visser
be654dad8a LibCrypto: Certificate parse IP address SAN
Subject alternative name entries containing IP addresses will now be
parsed and added to the list of SANs. This should allow for certificate
verification when accessing IP addresses directly.
2022-04-17 10:10:19 +04:30
Michiel Visser
7bc3b193c0 LibTLS: Add option to allow self-signed certificates
With this option enabled self-signed certificates will be accepted,
eventhough they cannot be verified.
2022-04-17 10:10:19 +04:30
Michiel Visser
804af863b4 LibCrypto+LibTLS: Implement Key Usage and Basic Constraints extensions
Root and intermediate CA certificates should have these extensions set
to indicate that they are allowed to sign other certificates. The values
reported in these extensions is now also checked by `verify_chain` to
make sure no non-CA certificates are used to sign another certificate.

The certificate parser now also aborts when a critical extension is
detected which is unsupported, as is required by the specification.
2022-04-17 10:10:19 +04:30
Michiel Visser
a6e465fba2 LibCrypto: Implement custom BitStringView for ASN.1 decoder
The ASN.1 decoder was originally using AK::BitmapView for decoded
BitStrings, however the specification requires that the bits are stored
in a byte from the most significant to the least significant.

Storing three bits '110' would result in a byte '1100 0000', i.e. 0xC0.
However, AK::BitmapView expects the bits to be stored at the bottom like
'0000 0110', i.e. 0x06. For the current uses the data was always a
multiple of eight bits, resulting in complete bytes, which could
directly be interpreted correctly.

For the implementation of the key usage extension of certificates the
correct implementation of the BitString is required.
2022-04-17 10:10:19 +04:30
Michiel Visser
b16b61f6bc LibCrypto: Fix inverted boolean decoded error in ASN.1
ASN.1 encodes booleans as false is zero and true is non-zero. The
decoder currently returned true when the boolean was zero.

Since this decoder was barely used it did not cause any problems,
however for support of other certificate extensions the correct version
is required.
2022-04-17 10:10:19 +04:30
Michiel Visser
976bb715e0 LibTLS: Correct matching hostname with certificate subject
The wildcard specified in a certificates subject can only match a single
level of subdomains. Originally, this function could match multiple
levels of subdomains with a single "*.".

As an example, https://wrong.host.badssl.com/ should fail to load, as
the certificate provided by the server only specifies "*.badssl.com".
However this was correctly matching anyway. With this change this page
now correctly fails to load.
2022-04-17 10:10:19 +04:30
Michiel Visser
331092d25a LibTLS: Add references to RFC5246 for the verify procedure 2022-04-17 10:10:19 +04:30
Michiel Visser
d78813d902 LibTLS: Simplify the way verify_chain is called
The `build_rsa_pre_master_secret` function originally called
`verify_chain_and_get_matching_certificate`, which verified the chain
and returned a certificate matching the specified hostname.

Since the first certificate in the chain should always be the one
matching with the hostname, we can simply use that one instead. This
means we can completely remove this method and just use `verify_chain`.

To make sure the hostname is still verified, `verify_chain` now also
checks that the first certificate in the chain matches the specified
hostname. If the hostname is empty, we currently fail the verification,
however this basically never happen, as the server name indication
extension is always used.
2022-04-17 10:10:19 +04:30