Commit graph

60624 commits

Author SHA1 Message Date
Undefine
92d58a91a6 Kernel/FATFS: Read the FAT32 FSInfo structure
This structure contains information about free clusters which
is going to be useful when allocating clusters.
2024-04-21 15:34:33 +02:00
Undefine
7e251c3b4f Kernel/FATFS: Return ENOTSUP on chown and chmod 2024-04-21 15:34:33 +02:00
Undefine
eb2721d650 Kernel/FATFS: Pass the FATEntry location to FATInode constructor
This is going to be necessary to flush the metadata later on.
2024-04-21 15:34:33 +02:00
Undefine
de574b9ed9 Kernel/FATFS: Improve error propagation in FATInode 2024-04-21 15:34:33 +02:00
implicitfield
0f828768bb Kernel/FATFS: Implement fat_write 2024-04-21 15:34:33 +02:00
implicitfield
a6a1508601 Kernel/FATFS: Fix reading from large 12-bit FATs
12-bit FATs aren't necessarily block-aligned, so in the worst case
we'll have to reach into the next block to perform the read properly.
2024-04-21 15:34:33 +02:00
Undefine
1350c555f6 Kernel/FATFS: Factor out the FAT reading to a function
Move the FAT reading code to a fat_read function in FATFS and move the
required functions to FATFS too.
2024-04-21 15:34:33 +02:00
implicitfield
b9d7e2db93 Kernel/FATFS: Prefer read_block() over raw_read()
`raw_read()` has proven to be a source of subtle bugs that occur as a
result of the cache and disk contents being out of sync.
2024-04-21 15:34:33 +02:00
implicitfield
b1af97810e Kernel/FATFS: Avoid creating reference bindings to packed struct members
dbgln() will always take its arguments by reference when possible, which
causes UB when dealing with packed structs. To avoid this, we now
explicitly copy all members whose alignment requirements aren't met.
2024-04-21 15:34:33 +02:00
Aliaksandr Kalenik
23d683cf6b LibWeb: Update document url after same-document back/forward navigation
Seems like a specification bug, but other browsers update url before
popstate event is fired and so should we.

Fixes back/forward navigation on GitHub.
2024-04-21 12:41:36 +02:00
dgaston
08aaf4fb07 AK: Add methods to BufferedStream to resize the user supplied buffer
These changes allow lines of arbitrary length to be read with
BufferedStream. When the user supplied buffer is smaller than
the line, it will be resized to fit the line. When the internal
buffer in BufferedStream is smaller than the line, it will be
read into the user supplied buffer chunk by chunk with the
buffer growing accordingly.

Other behaviors match the behavior of the existing read_line method.
2024-04-21 11:46:55 +02:00
Andreas Kling
4db1712f90 LibJS+LibWeb: Make Console, ConsoleClient & subclasses GC-allocated
These objects had confusing ownership semantics. Let's just throw them
all on the GC heap and stop worrying about it.
2024-04-21 09:12:25 +02:00
Andreas Kling
44659f2f2a LibWeb+WebContent: Don't let PageClient keep documents alive
We were inadvertently keeping all documents alive by installing a
console client for them. This patch fixes the issue by adding a
finalizer to Document, and having that be the way we detach console
clients. This breaks the cycle.

With this change, we can spam set .innerHTML in a loop and memory
usage remains stable.

Fixes #14612
2024-04-21 09:12:25 +02:00
Andreas Kling
cd6a458e83 headless-browser: Add -G option to dump GC graph on exit
This will be useful in tracking down the list of GC leaks that occur
across a run of our test suite.
2024-04-21 09:12:25 +02:00
Andreas Kling
e993fb53d5 LibJS: Simplify iteration in GC heap dumping code 2024-04-21 09:12:25 +02:00
Jess
ecb7d4b40f LibJS: Throw RangeError in StringPrototype::repeat if OOM
currently crashes with an assertion failure in `String::repeated` if
malloc can't serve a `count * input_size` sized request, so add
`String::repeated_with_error` to propagate the error.
2024-04-20 19:23:46 -04:00
Jess
f4c8f1a346 Meta: Add ASAN option allocator_may_return_null=1 to CI
This stops ASAN from complaining about massive allocations.
2024-04-20 19:23:46 -04:00
Daniel Bertalan
cc92c3f551 LibCrypto+LibGfx: Fix GCC 14 compile errors
The C++ standard does not allow specifying the template parameters in
constructor declarations, see
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97202#c8.

Converting constructors have a higher priority that user-defined
conversion functions; let's constrain `Gfx::Size<T>(Gfx::Size<U>)` to
only be considered when `U` is convertible to `T`. This lets us fall
back to conversion operators in the case of `UISize` -> `IntSize`, for
instance. Clang is still okay without this, but MSVC would error out
similarly: https://godbolt.org/z/PTbeYPM7s

Note that a not-yet-committed patch is required for full compilation:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114784#c3
2024-04-20 15:52:29 -06:00
Kenneth Myhra
291d0e5de8 LibWeb: Let queue_fetch_task() take a JS::HeapFunction
Changes the signature of queue_fetch_task() from AK:Function to
JS::HeapFunction to be more clear to the user of the function that this
is what it uses internally.
2024-04-20 18:11:01 +02:00
Kenneth Myhra
a3661fd7f2 LibWeb: Let queue_global_task() take a JS::HeapFunction
Changes the signature of queue_global_task() from AK:Function to
JS::HeapFunction to be more clear to the user of the function that this
is what it uses internally.
2024-04-20 18:11:01 +02:00
Aliaksandr Kalenik
9540af6489 LibWeb: Fix nodesToRemove collecting traversal in Range::delete_contents
With this change children are no longer skipped in tree traversal when
start node of range equals to end node of range.

Fixes https://github.com/SerenityOS/serenity/issues/24036
2024-04-20 13:32:24 +02:00
Aliaksandr Kalenik
cedf6dd2c3 LibWeb: Remove unused blend mode param in FillEllipse painting command 2024-04-20 12:42:02 +02:00
Aliaksandr Kalenik
d3cfe35fbd LibWeb: Do not destroy document until whole subtree completed unloading
Fixes crashing when "unload" event handler tries to access active
document that has already been destroyed.
2024-04-20 10:22:14 +02:00
Sönke Holz
9881d10e38 LibELF: Add a small local-exec TLS test
Part 1 of this test uses a large array so we are more likely getting
segfaults when using an incorrect TLS layout.

The `volatile`s and `taint_for_optimiter`s should hopefully prevent the
compiler from optimizing the tests out.
2024-04-19 16:46:47 -06:00
Sönke Holz
9437b29b43 LibELF+LibC: Add support for Variant I of the TLS data structures
We currently only supported Variant II which is used by x86-64.
Variant I is used by both AArch64 (when using the traditional
non-TLSDESC model) and RISC-V, although with small differences.

The TLS layout for Variant I is essentially flipped. The static TLS
blocks are after the thread pointer for Variant I, while on Variant II
they are before it.

Some code using ELF TLS already worked on AArch64 and RISC-V even though
we only support Variant II. This is because only the local-exec model
directly uses TLS offsets, other models use relocations or
__tls_get_addr().
2024-04-19 16:46:47 -06:00
Sönke Holz
3af793abfd LibELF: Correct the comment at the top of AArch64's tls.S 2024-04-19 16:46:47 -06:00
Sönke Holz
74a51505f0 LibELF: Add headers describing the TLS layout of each architecture
All of our architectures sadly use a slightly different TLS layout.
These headers try to abstract the differences in a nice way.
2024-04-19 16:46:47 -06:00
Sönke Holz
243d7003a2 Kernel+LibC+LibELF: Move TLS handling to userspace
This removes the allocate_tls syscall and adds an archctl option to set
the fs_base for the current thread on x86-64, since you can't set that
register from userspace. enter_thread_context loads the fs_base for the
next thread on each context switch.
This also moves tpidr_el0 (the thread pointer register on AArch64) to
the register state, so it gets properly saved/restored on context
switches.

The userspace TLS allocation code is kept pretty similar to the original
kernel TLS code, aside from a couple of style changes.

We also have to add a new argument "tls_pointer" to
SC_create_thread_params, as we otherwise can't prevent race conditions
between setting the thread pointer register and signal handling code
that might be triggered before the thread pointer was set, which could
use TLS.
2024-04-19 16:46:47 -06:00
Sönke Holz
aa44fe860d LibELF: Change copy_initial_tls_data_into argument type to Bytes 2024-04-19 16:46:47 -06:00
Sönke Holz
8f0ebce404 LibELF: Reorganize TLS-related variables in DynamicLinker.cpp 2024-04-19 16:46:47 -06:00
Sönke Holz
cb48f31d79 LibELF: Add helpers for setting the thread pointer register 2024-04-19 16:46:47 -06:00
Sönke Holz
216089c7a1 Kernel: Add a Thread member for arch-specific data
This will be used to store the fs_base value on x86-64, which is needed
for thread-local storage.
2024-04-19 16:46:47 -06:00
Sönke Holz
57f4f8caf8 Kernel+LibC: Introduce new archctl syscall
This syscall will be used for architecture-specific operations.
2024-04-19 16:46:47 -06:00
Andrew Kaster
5e1d678bae Ladybird+Userland: Remove use of unnecessary fd passing socket concept
Now that LibIPC is using SCM_RIGHTS properly, we can go back to only
having one socket laying around when needing to transfer fds to peers.
2024-04-19 16:38:55 -04:00
Andrew Kaster
cb87725ec8 LibIPC+LibWeb: Transfer IPC::Files using sendmsg/recvmsg directly
This refactor eliminates the need for a second "fd passing socket" on
Lagom, as it uses SCM_RIGHTS in the expected fashion, to send fds along
with the data of our Unix socket message.
2024-04-19 16:38:55 -04:00
Andrew Kaster
a18c7c4405 LibCore: Let LocalSocket send and receive messages with SCM_RIGHTS
These new methods combine send/receive with send_fd/receive_fd.

This is the 'correct' way to use SCM_RIGHTS, rather than trying to
emulate the Serenity behavior on other Unixes.
2024-04-19 16:38:55 -04:00
Andrew Kaster
0e699743c4 LibCore: Move PosixSocketHelper's read EOF handling to a helper
We'll call this from upcoming LocalSocket methods directly
2024-04-19 16:38:55 -04:00
Andrew Kaster
1e749d023a AK: Add fallible dequeue method to Queue 2024-04-19 16:38:55 -04:00
Andrew Kaster
a65c385057 Kernel: Don't try to copy empty Vector in sys$recvmsg
If there's no fds to copy in a message with proper space for an
SCM_RIGHTS set of cmsg headers, then don't try to copy them.

This avoids a Kernel panic when recvmsg-ing, as copy_to_user(p, 0, 0)
hits a VERIFY.
2024-04-19 16:38:55 -04:00
Nico Weber
3568215790 Tests/JPEG2000: Add spec example as test case
This tests reading JPEG2000 codestreams that aren't embedded in
the ISOBMFF wrapper. It's also useful for debugging bitstream
internals, since the spec lists expected output for many internal
intermediate results.
2024-04-19 12:42:34 -04:00
Nico Weber
0c935f8f42 LibGfx/JPEG2000: Support reading raw jpeg2000 codestreams
Most JPEG2000 files put the codestream in an ISOBMFF box structure
(which is useful for including metadata that's bigger than the
~65k marker segment data limit, such as large ICC profiles), but
some files just store the codestream directly, for example
https://sembiance.com/fileFormatSamples/image/jpeg2000/balloon.j2c

See https://www.iana.org/assignments/media-types/image/j2c for the
mime type.

The main motivation is to be able to use the test data in J.10 in
the spec as a test case.
2024-04-19 12:42:34 -04:00
Nico Weber
5695acf328 LibGfx/JPEG2000: Add comment mentioning J.10 2024-04-19 12:42:34 -04:00
Nico Weber
1a232ba2a6 LibGfx/JPEG2000: Check SIZ marker (w, h) against JP2 header (w, h) 2024-04-19 12:42:34 -04:00
Nico Weber
f2e381ae19 LibCore: Add ".jpf" as a JPEG2000 extension
This is what Photoshop uses for JPEG2000 outputs.
2024-04-19 12:42:34 -04:00
Nico Weber
2467374ea9 LibCore: Add comment with link to mime registry to MimeData.cpp 2024-04-19 12:42:34 -04:00
Andrew Kaster
6d4ba21832 LibIPC+Userland: Make IPC::File always own its file descriptor
Add factory functions to distinguish between when the owner of the File
wants to transfer ownership to the new IPC object (adopt) or to send a
copy of the same fd to the IPC peer (clone).

This behavior is more intuitive than the previous behavior. Previously,
an IPC::File would default to a shallow clone of the file descriptor,
only *actually* calling dup(2) for the fd when encoding or it into an
IPC MessageBuffer. Now the dup(2) for the fd is explicit in the clone_fd
factory function.
2024-04-19 06:34:07 -04:00
Andrew Kaster
26ce8ad40f LibWeb: Stop leaking socket fds when sending them over IPC
The implicit constructor for IPC::File does not take ownership of the
file, which is surprising.
2024-04-19 06:34:07 -04:00
Alex
13abb1b2c7 LibWeb: Add name validation and document check to setAttribute
Co-authored-by: Rayyan Hamid <rayyanbwp@gmail.com>
Co-authored-by: Christian Ewing <u1273549@utah.edu>
Co-authored-by: Austin Fashimpaur <austin.fashimpaur@gmail.com>
2024-04-19 06:32:41 -04:00
Dan Klishch
5ed7cd6e32 Everywhere: Use east const in more places
These changes are compatible with clang-format 16 and will be mandatory
when we eventually bump clang-format version. So, since there are no
real downsides, let's commit them now.
2024-04-19 06:31:19 -04:00
Andreas Kling
5ef6df79ed LibWeb: Generate a simple error page when XML decode/parse fails
This fixes a regression on Acid3, since we are not expected to "best
effort" parse XML. The test specifically checks that you don't create an
incomplete, incorrect DOM.
2024-04-19 11:44:32 +02:00