Commit Graph
67096 Commits
Author SHA1 Message Date
Andrew Kaster 49557c2e12 Ladybird+MacVideoPlayer: Align post_event with other event loop impls
After cherry-picking ladybird deferred invoke changes, the macOS event
loop implementations' post_event have diverged from everyone else's.

It tries to post the 'deferred invoke' event, but after all the changes
to how deferred invoke is dispatched, deferred invoke will never go
through post_event.

Restore the previous "wake if not my thread" behavior, and clean up the
unused atomic variable.
2026-06-29 10:07:38 -04:00
Andreas Kling 1d3f09aaec UI/AppKit: Override deferred_invoke() to signal CFRunLoopSource
The base class deferred_invoke() adds work to the thread event queue
and calls wake(), but that's not sufficient for CFRunLoop. We also
need to signal the deferred_source via CFRunLoopSourceSignal() so the
run loop knows to call its perform callback which processes the queue.

Without this signal, deferred invocations posted from other threads
(such as IPC I/O threads) would not be processed, causing deadlocks
when waiting for sync IPC responses.

(cherry-picked from commit 367296fce6cb0cc524c48730f74a24cc8adb3c40)
2026-06-29 10:07:38 -04:00
Andreas Kling b262ca13c9 UI/AppKit: Fix wake() to use the correct run loop
wake() was using CFRunLoopGetCurrent() which returns the calling
thread's run loop. When called from an I/O thread to wake the main
thread's event loop, this would wake the wrong run loop.

Fixed by using the stored m_impl->run_loop which is captured at
construction time and refers to the event loop's owning thread.

(cherry-picked from commit da77c803c17015fa87254f85ae2da8a48b9ab071)
2026-06-29 10:07:38 -04:00
Zaggy1024 ec7fe009d1 LibCore: Only wake the event loop in deferred_invoke from other threads
(cherry picked from commit fb2d9e3c85caaf0b9545857caf70cc7c7c866bd0)
2026-06-29 10:07:38 -04:00
Zaggy1024 ea0afb2c71 LibCore: Allow checking for a ThreadEventQueue without creating one
(cherry-picked from commit 87c305337065e2c7b5ab1be95cdb6f6798f0e7f7)
2026-06-29 10:07:38 -04:00
Zaggy1024 4b953da49e LibCore+LibThreading: Always wake the event loop when deferred invoking
(cherry-picked from commit 3742138cc3318842c795f3be8e41642702428af4)
2026-06-29 10:07:38 -04:00
Andreas Kling 8f88beb00c LibCore: Don't require heap-allocated event to hold deferred invocation
Instead of creating a DeferredInvocationEvent every time we
deferred_invoke, we now let the QueuedEvent store the invokee Function
object directly.

(cherry-picked from commit 2a1c5dc108697a5f3722432c0c1ec51a8e94a3e6)
2026-06-29 10:07:38 -04:00
Andreas Kling 3de118dc9d LibCore: Allow posting stateless events without heap-allocated Event
This patch adds an API for posting a Core::Event::Type to the thread
event queue without requiring a full Core::Event object.

We use this API to avoid heap allocations for every timer and notifier
activation event.

(cherry-picked from commit 69515f8c8548fe35f1bb08fcc5a1d9e851b6e675)
2026-06-29 10:07:38 -04:00
Zaggy1024 0aa569fcad LibCore+LibWeb: Remove the dummy EventReceiver from deferred_invoke()
The DeferredInvocationContext only existed to satisfy the requirement
in ThreadEventQueue that each event has an EventReceiver. However,
deferred_invoke() was not even using the EventReceiver to call its
callback. Therefore, we don't need to allocate one for every deferred
invocation.

This also prevents WeakPtr::strong_ref() from racing and leaking the
context object when invoking a function across threads.

(cherry-pick of commit b572ae95a91cfcd7189c1cd772c1e7d42a06afb2)
2026-06-29 10:07:38 -04:00
ayeteadoe 4bcedec3b4 LibCore: Remove unused NotifierActivationEvent fd() and type() methods
In 11b8bbe one thing that was claimed was that we now properly set the
Notifier's actual fd on the NotifierActivationEvent. It turns out that
claim was false because a crucial step was forgotten: actually set the
m_notifier_fd when registering. Despite that mistake, it ultimately was
irrelevant as the methods on NotifierActivationEvent are currently
unused code. We were posting the event to the correct Notifier receiver
so the on_activation was still getting invoked.

Given they are unused, NotifierActivationEvent can be defined the same
way as TimerEvent is, where we just pass the event type enum to the
Event base class. Additionally, NotificationType can be moved to
the Notifier header as this enum is now always used in the context of
creating or using a Notifier instance.

(cherry-picked from 4fb1ba0193c638246eb5db85423014a7c2c1d530)
2026-06-29 10:07:38 -04:00
Aliaksandr Kalenik abacdaec85 LibWebView: Add common source loop source for deferred_invoke() on macOS
Previously, `EventLoopImplementationMacOS` didn't process
`deferred_invoke()` callbacks during window resizing because they were
scheduled in the "default" run-loop mode, which isn't serviced while the
run loop is in "Event Tracking" mode.

Commit 3bbe1b0c changed socket notifiers to schedule in
`kCFRunLoopCommonModes`, which kept IPC reads responsive during resizing
(we process IPC messages in the notifier's read hook). This change does
the same for `deferred_invoke()`: it installs a `CFRunLoopSource` in
`kCFRunLoopCommonModes` and signals it whenever a deferred callback is
enqueued.

(cherry-picked from 6c7196042575a8a31e88afa0b1cb9b9e6baaf0e8)
2026-06-29 10:07:38 -04:00
Timothy FlynnandAndreas Kling 4a813ebf30 UI/AppKit: Register socket notifiers in the common run loop mode
When the user resizes the browser window, AppKit will spin the current
run loop in the common mode. This patch allows socket events from IPC to
be processed while the resize is ongoing. This includes the WebView hook
to repaint.

(cherry-picked from commit 3bbe1b0c62c3b71fbfdd1eeb2291677e9cba1bbf)

Co-Authored-By: Andreas Kling <[email protected]>
2026-06-29 10:07:38 -04:00
Andrew Kaster 984c42eab3 LibChess: Explicitly include NNOP header in UCICommand.h
This header was relying on LibCore/Event.h to include this.
2026-06-29 10:07:38 -04:00
Lucas Chollet 48fd052057 Kernel/Net: Prevent concurrent access to the E1000 hardware
AFAICT a lock in only required for the transmission path. During
initialization, only a single core accesses the hardware and receiving
is done in the IRQ so no concurrent access is done at this time.

The added lock prevents two processes from reading the same `tx_current`
from the hardware. It also removes a deadlock, that was easily
reproducible by having multiple clients connect to SSHServer at the same
time.
2026-06-28 15:40:43 +02:00
Lucas Chollet 9fddaff4a1 Kernel/Net: Remove unused helper functions in the E1000 driver 2026-06-28 15:40:43 +02:00
Lucas Chollet 69df83dcf7 AK: Include StdShim.h in NeverDestroyed.h
This provides the otherwise missing definition for `forward`.
2026-06-26 23:07:35 +02:00
Lucas Chollet 90d5e17f7a LibSSH+SSHServer: Always close subsystem sessions
Every subsystem needs to be closed by the server, otherwise clients hang
while waiting on the session's CLOSE packet. Each subsystem has a set of
pre-conditions that needs to be done before closing and a set of events
that might trigger the closing of the session.

For the exec subsystem, before closing, we need to drain the child's
stdout and stderr and also collect the child's exit status. Closing the
session might be done after any of these point in time (pipe reached
EOF or waitpid returned), whichever occurs last.

For the SFTP subsystem, it is quite more simple but very different. The
two pre-conditions are to have received an EOF message and to have
consumed all buffered packets that were received before the EOF. Again,
the session is closed after whichever of these events occurs last.
2026-06-26 14:51:49 +02:00
Lucas Chollet c00d4dffd8 SSHServer: Don't send multiple close messages per channel 2026-06-26 14:51:49 +02:00
Lucas Chollet 4656208bcc LibSSH+SSHServer: Make session closing more general
Other types of session need to be closed too, so let's make
`close_exec_session_if_needed` more general.
2026-06-26 14:51:49 +02:00
Lucas Chollet 62ff9afffe LibSSH/SFTP: Support closing files
While this allows to decode one more packet that the client sends, this
unfortunately makes the client hang as we still aren't doing a proper
closing procedure for the sftp subsystem.
2026-06-26 14:51:49 +02:00
Nico Weber c5af100c9e Everywhere: Use NaN<T> instead of __builtin_nan{f,,l}("")
No behavior change.
2026-06-26 13:15:59 +02:00
Nico Weber c793c2e626 Everywhere: Use Infinity<double> instead of __builtin_huge_val()
No behavior change.
2026-06-26 13:15:59 +02:00
Nico Weber 71199c1449 Everywhere: Use Infinity<float> instead of __builtin_huge_valf()
No behavior change.
2026-06-26 13:15:59 +02:00
Sönke Holz d144f1777c Base: Don't disable network adapter "ep1s0" by default
ddd4547e13 added this entry without any reason. Maybe we had multiple
network devices at that time?

None of our current default QEMU machines have a network adapter that
gets the name "ep1s0", so this went unnoticed.
However, the RP1 chip of the Raspberry Pi 5 has PCI address 1:0.0,
causing that network adapter to be disabled. (The RP1 ethernet driver
itself is not yet upstream.)
2026-06-26 13:11:01 +02:00
Nico Weber 341274075a LibC: Remove unused code from math.cpp
These have been dead since c5f6ba6e71 in #8743.

No behavior change.
2026-06-23 15:35:40 +02:00
Nico Weber afd64ca68e LibC: Remove unused code from math.cpp
These are dead after 92c6ae57fc in #4622.

No behavior change.
2026-06-23 15:35:40 +02:00
sideshowbarker 8031ce27bb LibCore: Don’t pass O_CLOEXEC to shm_open
Bug: Ladybird crashes on launch on macOS 26.4+ with “UNEXPECTED ERROR:
close: Bad file descriptor” in SharedVersion.cpp — because
AnonymousBuffer creation fails.

Cause: anon_create() passed O_CLOEXEC in the oflag argument to shm_open.
macOS 26.4+ rejects that with EINVAL. POSIX only specifies O_RDONLY,
O_RDWR, O_CREAT, O_EXCL, and O_TRUNC as valid shm_open flags; on earlier
macOS versions, O_CLOEXEC just happened to also be silently accepted.

Fix: Filter O_CLOEXEC from the oflag argument we pass to shm_open flags,
and instead set FD_CLOEXEC via fcntl — after opening.

(cherry-picked from commit d7053a8eb8780b293ec98304a1b17f0554d976cc)
2026-06-23 00:17:10 -04:00
Sönke Holz db7686eaf1 LibDebug: Don't continue the debuggee before detaching
Since 0b7dc6869e, all ptrace operations except PT_TRACE_ME and
PT_ATTACH are forbidden unless the tracee is stopped. This includes
PT_DETACH.
2026-06-22 01:35:57 +02:00
Nico Weber 38c474314f AK: Do not use recursion in asin()
Takes asinf() from 432.0M/s to 717.6M/s in `./bench-float-exhaustive`.
Takes asin() from 108.0M/s to 189.4M/s in `./ak-math-bench`.

(For reference, libc++ at 259.1M/s for asinf,
and macOS system libm is at 225.6M/s for asin.)

No behavior change.
2026-06-21 17:52:25 -04:00
Nico Weber a826321e87 AK: Replace asin() implementation with a lolremez-based one
Before:

float:

    % ./bench-float-exhaustive -f acosf -f asinf
    acosf  max ULP: 1267.00  mean ULP: 0.039223  CR: 96.1%  FR: 100.0%
           AK: 218.9M/s  ref: 211.2M/s
    asinf  max ULP: 8.00     mean ULP: 0.010256  CR: 99.1%  FR:  99.9%
           AK: 224.3M/s  ref: 259.1M/s

double:

    % ./ak-math-bench --format=wide -f acos -f asin
    Function     Max ULP       Mean ULP   % CR   % FR  Accuracy  Ops/sec
    --------------------------------------------------------------------
    acos()  184318822.00   2465877.8443  58.7%  82.7%       0.0    91.4M
    asin()  390846002.00  11969221.1695  51.3%  83.0%       0.0   113.6M

After:

float:

    % ./bench-float-exhaustive -f asinf -f acosf
    acosf  max ULP: 1267.00  mean ULP: 0.038492  CR: 96.2%  FR: 100.0%
           AK: 393.7M/s  ref: 211.2M/s  (2.3s)
    asinf  max ULP: 2.00     mean ULP: 0.002522  CR: 99.8%  FR: 100.0%
           AK: 432.0M/s  ref: 259.1M/s

double:

    % ./ak-math-bench -f acos -f asin
    Function     Max ULP    Mean ULP    % CR    % FR  Accuracy   Ops/sec
    --------------------------------------------------------------------
    acos()   25216051.00  20936.4458   70.3%   98.7%       0.0     88.9M
    asin()          1.00      0.0791   92.1%  100.0%      92.7    108.0M

With this, asin() is somewhat decent in accuracy, and the float version
is even pretty fast.

For reference, the double version of asin with macOS system libm:

    asin()          1.00      0.0318   96.8%  100.0%      96.9    225.6M

That is about twice as accurate and about twice as fast as ours.
2026-06-21 17:52:25 -04:00
Nico Weber e897b9d744 Everywhere: Use more granular AK/Math/ includes in a few headers
...and in a few cpp files too, and clean up missing includes.

Reduces number of files recompiled after touching AK/Math/Hyperbolic.h
from a couple thousand to a handful.

No behavior change.
2026-06-21 15:26:06 -04:00
Nico Weber c717b91897 AK: Granularize AK/Math.h
No behavior change.
2026-06-21 15:26:06 -04:00
Nico Weber 40b60fa7a5 AK: Make log{,2,10}(inf) return inf
Previously, e.g. log2(inf) = 0x1p+7, which was wrong.
2026-06-21 10:11:57 -04:00
Nico Weber 7a627a8f89 AK: Improve atan(), atan2() for doubles
Before:

    % ./ak-math-bench -v  --format=wide -f atan -f atan2
    Running libm benchmark...

    Function   Max ULP  Mean ULP    % CR Accuracy  Ops/sec
    ------------------------------------------------------
    atan()      194.00    6.7815   57.0%     12.9   180.0M
                   ^ input: 0x1.bf40883ce64c4p-4
                  expected: 0x1.bd7cb69f7eba8p-4
                       got: 0x1.bd7cb69f7ec6ap-4
    atan2()     193.00   15.4890    8.7%      6.1    89.2M
                   ^ input: 0x1.a9bbbb530b80ap+6, 0x1.e069d3ea5d36ap+9
                  expected: 0x1.c3e1ec33ee4ecp-4
                       got: 0x1.c3e1ec33ee5adp-4
    ======================================================

    Overall Score: 11.4

After:

    % ./ak-math-bench -v  --format=wide -f atan -f atan2
    Running libm benchmark...

    Function   Max ULP  Mean ULP    % CR Accuracy  Ops/sec
    ------------------------------------------------------
    atan()        1.00    0.2584   74.2%     79.5   176.7M
                   ^ input: 0x1.00e99e0bbf8d4p+7
                  expected: 0x1.9021897ae0934p+0
                       got: 0x1.9021897ae0933p+0
    atan2()       2.00    0.3205   68.2%     75.7    84.8M
                   ^ input: 0x1.9f673c81fbd1cp+51, 0x1.17c16d619e0dep+51
                  expected: 0x1.f4caa48ff62dap-1
                       got: 0x1.f4caa48ff62d8p-1
    ======================================================

    Overall Score: 80.2

The float version is already decent:

    % ./bench-float-exhaustive -f atanf -f atan2f
    atanf   max ULP: 2.00  mean ULP: 0.045692 CR: 95.4%
            AK: 316.4M/s  ref: 382.8M/s
               worst: atanf(0x1.2c00c2p+0)
                        = 0x1.ba8f64p-1,
                 expected 0x1.ba8f6p-1
    atan2f  max ULP: 2.00  mean ULP: 0.060975 CR: 93.9%
            AK: 154.6M/s  ref: 271.3M/s
               worst: atan2f(0x1.514008p-128, 0x1.500054p-125)
                        = 0x1.ff3b52p-4,
                 expected 0x1.ff3b4ep-4
2026-06-20 17:40:06 -04:00
Andrew Kaster cf6a6f8084 Toolchain: Remove noisy output from BuildJakt.sh in the happy path
If the toolchain already exists, let's not echo out every stage that
we're not actually going to do work for.
2026-06-20 13:09:28 -04:00
Andrew Kaster cfbe3cf966 Toolchain: Pass target-specific ar binary to runtime and main build
When building the runtime and main archives, we need to ensure that we
use the target-specific `ar` binary. Without this, the Clang aarch64
configuration on aarch64 macOS hosts would improperly use the host's
`ar`` binary, which assumes one is building Mach-O files and trips up
on the target's ELF files.
2026-06-19 22:06:41 -04:00
Andrew Kaster 2da0d939d6 CMake: Remove unnecessary linker commands when linking object libs
When linking an OBJECT library, it makes no sense to add flags for
--whole-archive or --no-whole-archive. When using the correct feature
flag in CMake for these, it spits out a warning.

This removes some unnecessary linker flags from every application's
link line.
2026-06-19 22:06:41 -04:00
Andrew Kaster d7c905dbb1 CMake: Add imported targets for jakt runtime and main 2026-06-19 22:06:41 -04:00
Nico Weber f9699604d8 LibC: Remove FE_TOMAXMAGNITUDE
It's non-standard (and a serenity-only extension, not something in
common use), unused, and riscv-only.
2026-06-19 06:09:59 +02:00
Nico Weber 3249f49b1e AK: Implement denormal handling in log2() 2026-06-18 19:04:41 -04:00
Nico Weber 56c65f576d LibC: Make internal_scalbn handle normal inputs better
It now correctly handles a normal input becoming +/-inf, and
it becoming a denormal.
2026-06-18 15:12:35 -04:00
Nico Weber ff722b30f5 LibC: Make internal_scalbn handle denormal inputs becoming inf 2026-06-18 15:12:35 -04:00
Nico Weber ba770b5444 LibC: Make internal_scalbn handle denormal inputs
We now handle negative shifts, and denormal -> normal transitions
for large-enough shifts.
2026-06-18 15:12:35 -04:00
Nico Weber 509b7692f0 LibC: Remove dead code form internal_scalbn()
We know that x != 0 and extractor.exponent == 0 at the bottom
of the function, meaning mantissa must be != 0.

And the `extractor.exponent = exponent + 1;` store overwrites
the store on the line above. (Presumably, the line above meant
to shift `mantissa` instead.)

No behavior change.
2026-06-18 15:12:35 -04:00
RiffPointer e5479fd52e Calendar: Add operator== to Event struct 2026-06-18 10:11:13 -04:00
RiffPointer 60ae77e22b Calendar: Allow editing of previously created events
This PR fixes #22622.
Added a nice Events dialog showing a list of
all events in a single day.
2026-06-18 10:11:13 -04:00
implicitfield d73edd67f3 Kernel: Dispatch signals in do_context_first_init
To make this possible, the initial trap frame has been made visible to
the Thread class. This removes a now-unneeded call to
`enter_trap_no_irq` in `ProcessorBase::init_context` on x86-64 as
calling this is no longer necessary in order to give the idle thread a
valid trap frame.

Fixes #26804.
2026-06-17 14:00:39 +02:00
Andrew Kaster db49c73222 Debugger: Implement backtrace command
This implementation steals code from both HackStudio's BacktraceModel
and CrashReporter. The code is massaged a bit to look nicer in the
terminal, and the standard status messages for the sdb command line
have been updated to include inlined function information from the
DWARF debug info for the current library.

There's some code reuse opportunities here, but for now it's nice that
``bt`` doesn't crash the debugger with a trap.
2026-06-16 18:48:27 +02:00
Andrew Kaster 570deb6261 Debugger: Add quit command
This is functionally equivalent to passing EOF to the command parser,
but in the form of a command. Notably, in both cases doing so while the
debugger is paused will give a PT_DETACH error while quitting.
2026-06-16 18:48:27 +02:00
Bastiaan van der Plaat 5171b67066 Meta: Fix BuildFuseExt2.sh with patch for linking with modern macFUSE
Patch from https://github.com/alperakcan/fuse-ext2/issues/149
2026-06-15 17:02:41 +02:00