Commit graph

574 commits

Author SHA1 Message Date
ayeteadoe
4fb1ba0193 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.
2025-11-22 09:47:25 +01:00
ayeteadoe
fa262d2db5 LibCore: Add VERIFY checks for all wait completion packet nt.dll calls 2025-11-18 18:49:37 +01:00
ayeteadoe
d5e5dbdf3d LibCore: Signal an event to queue a wake completion packet on Windows
The initial IOCP event loop implementation adjusted wake() to manually
queue a completion packet onto the current threads IOCP. This caused
us to now be dependent on the current threads IOCP, when the previous
behaviour did not depend on any data from the thread that was waking
the event loop.

Restoring that old behaviour allows https://hardwaretester.com/gamepad
to be loaded again.
2025-11-18 18:49:37 +01:00
ayeteadoe
540bbae480 LibCore: Restore single-shot timer objects manual reset on Windows
The initial IOCP event loop implementation removed the single shot
timer fix added in 0005207 was removed.

Adding this back allowed simple web pages like https://ladybird.org/ to
be loaded again.
2025-11-18 18:49:37 +01:00
ayeteadoe
11b8bbeadf LibCore: Use correct fd for NotifierActivationEvent on Windows
The initial IOCP event loop implementation had a fd() method for the
EventLoopNotifier packet that did not actually return the fd for the
notifier, but a to_fd() call on an object HANDLE that was always NULL.
This meant we were always posting NotifierActivationEvents with a fd of
0.

This rendered all of our WinSock2 I/O invalid, meaning no IPC messages
would ever be successfully sent or received.
2025-11-18 18:49:37 +01:00
Timothy Flynn
1c2c9a859a LibCore: Do not require rvalue references to resolve/reject promises
The way these methods were previously defined, we would have to `move`
values into these functions. This was pretty awkward for plain types.
For example, doing a `move` here really doesn't make sense:

    int resolution = 123;
    promise->resolve(move(resolution));

Let's declare these methods in a manner that allows callers to choose
whether values are moved or copied, using perfect forwarding.
2025-11-12 09:06:21 -05:00
Tim Ledbetter
1df94c4513 LibCore: Introduce REPORT_TIME() for per call timing information
This macro outputs the time taken to reach the end of the current scope
to the debug console. It also shows the average time, total cumulative
time and the total number of calls.

It is also possible to limit the amount of debug output using
`REPORT_TIME_EVERY(name, n)` to only print every `n` calls.
2025-11-11 11:47:59 +01:00
Undefine
6fa705c730 LibCore: Mark Process::wait_for_termination as const
After removal of the of the disown mechanism this can be marked as
const, which in my opinion makes sense for this API.
2025-11-07 11:27:51 +01:00
Undefine
769bbe6021 LibCore: Remove unused KeepAsChild and disown mechanisms
Those went unused and did nothing on systems other than SerenityOS.
2025-11-07 11:27:51 +01:00
Undefine
7a9dd46a39 LibCore: Remove unused Process::set_name
It went unused and was a no-op on systems other than SerenityOS.
2025-11-07 11:27:51 +01:00
Undefine
3c0d787c53 LibCore: Remove unused working_directory parameter
This was unused and a no-op on systems other than SerenityOS.
2025-11-07 11:27:51 +01:00
Undefine
41d04de1f2 LibCore: Remove unused System::uname
This went unused.
2025-11-07 11:27:51 +01:00
Undefine
17d3b881d3 AK+Everywhere: Remove ifdefs for WASM and Emscripten
Building the Ladybird code for Emscripten doesn't really make sense
and I doubt it is even possible with all the dependencies now.
2025-11-07 11:27:51 +01:00
R-Goc
86b95b1d7a LibCore: Use IOCP for the event loop on Windows
This commit changes the event loop to use IOCPs instead of
WaitForMultipleObjects to wait on events. This is done through the Nt
kernel api NtAssociateWaitCompletionPacket which associates an event
with a completion packet. Each completion packet notifies only once, as
they are normally used to signal completion of an operation so to use
them for notifiers they are associated again after each time they are
triggered.
There are more optimizations that can be done, such as reusing the
EventLoopNotifier and EventLoopTimer structures to reduce the number of
allocations and context switches for timer and notifier registration.
2025-11-07 08:42:43 +01:00
Aliaksandr Kalenik
b7cd606ff4 LibCore: Protect ThreadData with a mutex in EventLoopImplementationUnix
`register_notifier()` and `unregister_notifier()` could be called from
different threads modifying the same `ThreadData`.
2025-11-02 22:43:10 +01:00
Aliaksandr Kalenik
bf0884c4ec LibCore: Use RWLock in EventLoopManagerUnix
...instead of directly using pthread APIs.
2025-11-02 22:43:10 +01:00
ayeteadoe
5e529fc603 LibCore: Use WinSock2 closesocket() in PosixSocketHelper::close()
Our Core::System::is_socket() helper is not very robust, as it was
incorrectly marking m_fd as a non-socket fd. This meant we were trying
to call CLoseHandle() on a socket which fails. We can just call
closesocket() directly given we are in an explicit socket-only context.
2025-10-29 21:07:52 -06:00
ayeteadoe
7683f1285f AK: Expose helpers to invoke Windows runtime config directly in main()
When shutting down helper processes, PosixSocketHelper::close() in
SocketWindows when trying to close the socket fd with
WSANOTINITIALISED. This was due to us initiating WinSock2 during static
initialization and presumably also not terminating WinSock2 properly.

Similar to WinSock2 initiation, calling CRT during static
initialization is considered dangerous given the CRT DLL itself may not
yet be initialized.

Because of the above, we move to perform this Windows-specific
runtime setup/teardown calls into the main() functions.
2025-10-29 21:07:52 -06:00
Zaggy1024
e0a75d5084 LibCore: Implement polling for events on Windows 2025-10-22 17:32:45 -05:00
Undefine
abe536652f Meta+LibCore: Disable --no-undefined on FreeBSD and remove LibCore hack
It turns out it's much cleaner to just allow undefined symbols like we
already do for sanitizer Clang and remove the weak symbol definition.
2025-10-22 13:54:54 +02:00
Timothy Flynn
e433dee543 LibCore: Add a system wrapper to pipe a file
This uses splice on Linux and mmap+write elsewhere to transfer a file to
a pipe. Note we cannot use sendfile because (at least on macOS) the
receiving fd must be a socket.
2025-10-14 13:40:33 +02:00
Timothy Flynn
62e52640d0 LibCore: Add a standard path for cache data 2025-10-14 13:40:33 +02:00
ayeteadoe
f4c8fd4bef LibCore+LibWebView+UI/Qt: Support TimeZoneWatcher on Windows
To detect system time zone changes on Windows, the event we need to look
for is WM_TIMECHANGE. The problem is how the callback with said message
actually gets invoked is very particular. (1) We must have an active
message pump (event loop) for the message to ever be processed. (2) We
must be a GUI application as WM_TIMECHANGE messages are seemingly sent
to top level windows only. It doesn't say that in the docs for the
event, but attempts of creating a LibTest-based application with a
message pump and a message only window and never receiving the event
point to that probably being true.

This workaround is built off the fact that Qt's message pump defined
internally in QEventDispatcherWin32::processEvents does in fact receive
WM_TIMECHANGE events, even though it is not exposed as a QEvent::Type.
Given the requirements stated above it makes sense that it works here as
the message pump is executing in a QGuiApplication context. So we use a
native event filter to hook into the unexposed WM_TIMECHANGE event and
forward it along to the on_time_zone_changed() callback.

Note that if a Windows GUI framework is done in the future, we'll have
to re-add support to ensure the TimeZoneWatcher still gets invoked.
2025-10-05 15:46:15 +02:00
ayeteadoe
ba9c8b8462 LibCore: Remove unused macOS FileWatcher implementation 2025-10-05 15:46:15 +02:00
Andreas Kling
1ec72de0a6 AK: Remove unnecessary StringBuilder::create() factory 2025-10-05 11:24:46 +02:00
Zaggy1024
592be4ecad LibCore: Allow Promise to be resolved if it has a non-Error error type 2025-10-02 14:50:04 +02:00
Tomasz Strejczek
a010557205 LibCore: Remove DateTime
Remove DateTime and its dependencies as it's not longer used.
2025-09-30 12:39:01 +02:00
Rocco Corsi
892e75ddfb LibCore: Fix ThreadedPromise issues found with ThreadSanitizer 2025-09-24 21:05:54 -05:00
Aliaksandr Kalenik
de3f32a5c9 LibCore: Make timer firing order stable for equal deadlines
Timers scheduled with identical `fire_time` could fire out of order
because the heap is not stable. This change assigns a monotonically
increasing `sequence_id` when a timer is scheduled and extend the heap
comparator to order by (`fire_time`, `sequence_id`). This guarantees
FIFO among timers with the same deadline.

This matches the HTML "run steps after a timeout" ordering requirement:
older invocations with <= delay complete before newer ones.
https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#run-steps-after-a-timeout
2025-09-22 12:34:32 +01:00
ayeteadoe
69e92f69a7 LibCore: Implement SIGTERM-based kill() on Windows
There is no direct Win32 API equivalent, but calling WM_CLOSE on
the top-level windows allows for a graceful shutdown where resources
are able to clean themselves up properly
2025-09-15 09:19:52 +02:00
Nico Weber
9272df7a86 Everywhere: Fix a few unreachable-return / unreachable-break warnings
I was playing with clang's -Wunreachable-code-aggressive a bit.
This fixes a handful uncontroversial things it flags.

No behavior change.
2025-09-12 14:33:14 +01:00
Ali Mohammad Pur
4462348916 Everywhere: Slap some [[clang::lifetimebound]] where appropriate
This first pass only applies to the following two cases:
- Public functions returning a view type into an object they own
- Public ctors storing a view type

This catches a grand total of one (1) issue, which is fixed in
the previous commit.
2025-09-01 11:11:38 +02:00
Luke Wilde
b17783bb10 Everywhere: Change west consts caught by clang-format-21 to east consts 2025-08-29 18:18:55 +01:00
ayeteadoe
ff71efebb6 LibCore: Fix WSAEMSGSIZE error in pending_bytes with proper zero-init
In SocketWindows, the return value for the ioctl call was not
initialized to zero. This was causing test_udp in TesDNSResolver
to fail as UDPSocket::read_some() was incorrectly failing with
WSAEMSGSIZE due the result of pending_bytes being some
unspecified default value for an uninitialized unsigned long
2025-08-23 18:35:45 -06:00
ayeteadoe
84690f432e test-web: Allow help command to succeed
These are required for test-web runtime to actually work
2025-08-23 16:04:36 -06:00
zac
b8f95a091c LibCore: Add AVIF to registered types in MimeData 2025-08-22 08:03:28 -04:00
Jelle Raaijmakers
bc7658d3d3 LibCore: Don't send SIGTRAP when debugger attaches
Both gdb and lldb interrupt execution after attaching to the process, so
no need to send a SIGTRAP immediately after which would require typing
`continue` in the debugger twice.
2025-08-19 06:24:57 -04:00
Jelle Raaijmakers
afda3aba14 LibCore: Remove Command
This went unused.
2025-08-17 16:44:14 -04:00
Andreas Kling
bd7599ccfc LibCore: Remove macro-generated EventReceiver::try_create(...) factories
We can just use the infallible factory everywhere instead.
2025-08-11 16:55:25 +02:00
Andreas Kling
aec1f6aa7e LibCore: Remove unused CustomEvent 2025-08-11 16:55:25 +02:00
Andreas Kling
c47e253c60 LibCore: Remove unused "visible for timer purposes" concept
This was a long-unused leftover from SerenityOS.
2025-08-11 16:55:25 +02:00
Andreas Kling
0037df88d5 LibCore: Remove unused ChildEvent 2025-08-11 16:55:25 +02:00
Andreas Kling
75091016d7 LibCore: Remove parent/child concept from EventReceiver
This ownership model is no longer used.
2025-08-11 16:55:25 +02:00
Andreas Kling
134fd8e413 LibCore: Don't have Promise inherit from EventReceiver
This was only used for parenting promises to each other, but we can do
that with a simple vector of children.
2025-08-11 16:55:25 +02:00
Andreas Kling
b8357bc190 LibCore: Remove unused LocalServer constructor parameter 2025-08-11 16:55:25 +02:00
Andreas Kling
cfcb63239d LibCore: Remove unused ThreadedPromise constructor 2025-08-11 16:55:25 +02:00
Andreas Kling
fa8592b4a9 LibCore: Remove unused UDPServer constructor parameter 2025-08-11 16:55:25 +02:00
Andreas Kling
036aa43a41 LibCore: Remove unused TCPServer constructor parameter 2025-08-11 16:55:25 +02:00
Andreas Kling
d13884e933 LibCore: Remove unused Timer APIs for constructing with a parent 2025-08-11 16:55:25 +02:00
Andreas Kling
4d285d6dce LibCore: Remove an unused Promise constructor 2025-08-11 16:55:25 +02:00