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.
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)
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)
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)
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)
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)
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)
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)
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]>
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.
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.
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.
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.)
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)
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.
...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.
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.
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.
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.
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.
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.
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.