Commit graph

510 commits

Author SHA1 Message Date
Undefine
2aa8c950ca LibCore+Meta: Workaround some symbols not being exported on FreeBSD
On FreeBSD some symbols like `environ` or `__progname` are not exported
anywhere and are filled in by the dynamic loader. `environ` is
a special case because we make use of it explicitly so we need to mark
it a weak symbol so the linker doesn't complain.
2025-07-15 13:44:54 -06:00
Jelle Raaijmakers
4c88c7445c LibCore: Remove EventReceiver's event filter
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This went unused.
2025-07-14 11:54:57 +01:00
Timothy Flynn
af671f58ed LibCore: Revert change to simplify tracking of notifers and poll structs
The issue with that refactor was that the same fd can be used in more
than one notifier. This reverts us back to using 2 members to track the
notifiers in play.
2025-07-08 13:53:27 +01:00
Timothy Flynn
a9f7579738 LibCore: Awaken read notifiers when we receive POLLHUP events
POLLHUP is set when the remote end of the monitored fd is closed. There
may still be some buffered data to read from the socket, however. Some
systems do not set POLLIN in these cases. So we should just always try
to read from fds when we receive this event.
2025-07-07 15:53:15 -06:00
Timothy Flynn
f46b721c57 LibCore: Always reset the polled revents field back to 0
One benefit of using `poll` over `select` is that we can re-use the poll
structure list. But there's no guarantee that the underlying system will
reset the `revents` field back to 0. So let's explicitly do so.
2025-07-07 15:53:15 -06:00
Timothy Flynn
0499d216b8 LibCore: Simplify tracking of notifiers and poll structures
We don't need 2 vectors and a hash map to track these structures. We can
store the poll structures in a list and just track notifiers by the fd.
2025-07-07 15:53:15 -06:00
ayeteadoe
25f5936dee CMake: Rename serenity_* helper functions/macros to ladybird_* 2025-07-03 23:19:41 +02:00
Timothy Flynn
86b1c78c1a AK+Everywhere: Prepare Utf16View for integration with a UTF-16 string
To prepare for an upcoming Utf16String, this migrates Utf16View to store
its data as a char16_t. Most function definitions are moved inline and
made constexpr.

This also adds a UDL to construct a Utf16View from a string literal:

    auto string = u"hello"sv;

This let's us remove the NTTP Utf16View constructor, as we have found
that such constructors bloat binary size quite a bit.
2025-07-03 09:51:56 -04:00
Rocco Corsi
cdb623b663 LibCore: Remove .xht from common_extensions in MimeType text/html
Extension .xht was part of common_extensions for two MimeType Array
entries: application/xhtml+xml and text/html. Should only be part of
one.
2025-06-25 18:49:43 -06:00
Ali Mohammad Pur
e47b1cc1a2 LibCore: Accept any Promise<T> in Promise::after() 2025-06-25 08:20:40 +02:00
stasoid
6be0816172 LibCore: Add Windows implementation of TCPSocket::connect 2025-06-23 18:58:01 -06:00
stasoid
c14e6473d6 LibCore: Add Windows impl of System::socket, getaddrinfo, connect 2025-06-23 18:58:01 -06:00
Tomasz Strejczek
7278a17e87 LibCore: Remove DateTime::to_string() and to_byte_string()
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
2025-06-19 18:42:45 -06:00
stasoid
75b0e9a199 LibCore: Fix race condition in PosixSocketHelper::read on Windows
CancelIo introduces a race condition: if data arrives between calls to
WSARecv and CancelIo it will be lost.
See also: https://vstinner.github.io/asyncio-proactor-wsarecv-cancellation-data-loss.html
2025-06-17 20:56:32 +02:00
Viktor Szépe
19f88f96dc Everywhere: Fix typos - act III
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
2025-06-16 14:20:48 +01:00
rmg-x
a4d931d14a LibCore+LibIPC: Move various encode/decode specializations to LibIPC
This removes a dependency on LibIPC from LibCore.
2025-06-14 16:03:26 -04:00
rmg-x
18f28f398b LibCore+LibIPC: Remove badge on File::leak_fd
This removes a dependency on LibIPC from LibCore.
2025-06-14 16:03:26 -04:00
Timothy Flynn
911ea2b379 LibCore: Ensure we don't replace an already-installed event loop manager
Once an event loop manager is installed, we want to be sure we only use
that manager in the current process going forward. Mixing event loop
implementations can only cause problems.

More to the point, this ensures that we have installed the AppKit or Qt
event loop managers before the first time EventLoopManager::the() is
invoked. Now that we defer this installation until we know whether we
are running headlessly, we want to be extra sure that we have done so
before any services using the event loop have started.
2025-06-13 17:06:16 +02:00
Ali Mohammad Pur
59b6293182 LibCore: Add a Promise::after(promises) API
This is equivalent to Promise.all() in js, more or less.
2025-06-11 18:16:29 +02:00
R-Goc
6c8623320f LibCore: Implement chdir on Windows
This commit adds a wrapper around chdir in LibCore.

Co-authored-by: Andrew Kaster <andrew@ladybird.org>
2025-06-05 22:00:55 -06:00
Rocco Corsi
9281baffd8 LibCore: Recognize filenames .shellrc and CMakeLists.txt as text
There was a missing comma in the array, so these two entries were
concatenated accidentally.
2025-05-26 14:23:43 -06:00
blukai
4b3691ff39 LibCore+LibGfx: Move font_directories from LibCore to LibGfx
the goal is to rely on fontconfig for font directory resolution. it
doesn't seem like it would be appropritate to call to fontconfig funcs
from within the LibCore.

i'm not 100% confident that FontDatabase is the correct place.. seems
okay?
2025-05-26 12:14:29 -06:00
Andrew Kaster
087cbf2b0a LibCore: Expose Unix socket fd transfer limit publicly 2025-05-24 19:15:06 +03:00
Andrew Kaster
228211205a LibCore: Atomically ref-count SharedSingleProducerCircularQueue guts
This fixes two race conditions and ASAN crashes in the test for the
same.

The first comes from destroying the internals struct, which was
previously using the standard, thread-unsafe RefCounted CRTP. The
second is from destroying the name, which is secretly another
RefCounted object, in a thread-unsafe manner.
2025-05-24 06:52:25 -06:00
Tim Ledbetter
fe99c1fa7c LibCore: Increase MAX_LOCAL_SOCKET_TRANSFER_FDS
It is currently possible to hit this limit on pages with large numbers
of images. This temporary workaround prevents some WPT tests with large
numbers of images from failing.
2025-05-22 08:00:01 -04:00
Tim Ledbetter
1c5881c44a LibCore: Remove LADYBIRD_GIT_VERSION environment variable usage
This was previously used by the WPT runner to determine the git hash
of a particular WPT run. This mechanism is no longer used, since it
doesn't work with chunked WPT runs.
2025-05-15 14:02:48 +02:00
ayeteadoe
8864b3e9d1 CMake: Build LibCore tests in Tests/LibCore not Meta/Lagom
As LibCore was not specified in TEST_DIRECTORIES, the existing
Tests/LibCore subdirectory was not actually included during
configuration.
2025-05-14 02:05:12 -06:00
Timothy Flynn
7280ed6312 Meta: Enforce newlines around namespaces
This has come up several times during code review, so let's just enforce
it using a new clang-format 20 option.
2025-05-14 02:01:59 -06:00
Timothy Flynn
dceed08058 AK+LibCore: Avoid double-negation of syscall error values
This is a remnant from SerenityOS. Let's avoid confusion as to why we
negate errno when we call Error::from_syscall just to negate it again
when we store the error code.
2025-05-10 21:19:46 -04:00
Timothy Flynn
24ac5e2eee AK+LibCore: Remove SerenityOS handling from Error and Core::System
This is just to make some syscall error handling changes simpler.
2025-05-10 21:19:46 -04:00
Andrew Kaster
b50d03f42e LibCore+LibWebView: Restore was_exit_requested to EventLoop
This method was removed in e015a43b51

However, it was not exactly *unused* as the commit message would say.
This method was the only thing that allowed spin_until to exit when
the event loop was cancelled. This happens normally when IPC connections
are closed, but also when the process is killed.

The logic to properly handle process exit from event loop spins needs to
actually notify the caller that their goal condition was not met though.
That will be handled in a later commit.
2025-04-30 11:12:23 -04:00
Shannon Booth
8ab541b3f6 LibCore: Remove URL validity check for parsing URL's
Now that URL does not implicitly construct from a String, it is
safe to rely on always being passed a valid URL.
2025-04-19 07:18:43 -04:00
stasoid
2ac53794c3 LibCore: Implement System::isatty on Windows
Also fixes a bug introduced in 642b7b6a5e: Core::System functions
expect a handle now, so we have to use _get_osfhandle in STD*_FILENO.
2025-04-13 10:19:23 -06:00
stasoid
17fcbce324 LibCore: Make single-shot timer objects manually reset on Windows
This fixes a really nasty EventLoop bug which I debugged for 2 weeks.

The spin_until([&]{return completed_tasks == total_tasks;}) in
TraversableNavigable::check_if_unloading_is_canceled spins forever.

Cause of the bug:

check_if_unloading_is_canceled is called deferred

check_if_unloading_is_canceled creates a task:

        queue_global_task(..., [&] {
            ...
            completed_tasks++;
        }));

This task is never executed.

queue_global_task calls TaskQueue::add

void TaskQueue::add(task)
{
    m_tasks.append(task);
    m_event_loop->schedule();
}

void HTML::EventLoop::schedule()
{
    if (!m_system_event_loop_timer)
        m_system_event_loop_timer = Timer::create_single_shot(
            0, // delay
            [&] { process(); });

    if (!m_system_event_loop_timer->is_active())
        m_system_event_loop_timer->restart();
}

EventLoop::process executes one task from task queue and calls
schedule again if there are more tasks.

So task processing relies on one single-shot zero-delay timer,
m_system_event_loop_timer.

Timers and other notification events are handled by Core::EventLoop
and Core::ThreadEventQueue, these are different from HTML::EventLoop
and HTML::TaskQueue mentioned above.

check_if_unloading_is_canceled is called using deferred_invoke
mechanism, different from m_system_event_loop_timer,
see Navigable::navigate and Core::EventLoop::deferred_invoke.

The core of the problem is that Core::EventLoop::pump is called again
(from spin_until) after timer fired but before its handler is executed.

In ThreadEventQueue::process events are moved into local variable before
executing. The first of those events is check_if_unloading_is_canceled.
One of the rest events is Web::HTML::EventLoop::process sheduled in
EventLoop::schedule using m_system_event_loop_timer.
When check_if_unloading_is_canceled calls queue_global_task its
m_system_event_loop_timer is still active because Timer::timer_event
was not yet called, so the timer is not restarted.
But Timer::timer_event (and hence EventLoop::process) will never execute
because check_if_unloading_is_canceled calls spin_until after
queue_global_task, and EventLoop::process is no longer in
event_queue.m_private->queued_events.

By making a single-shot timer manually-reset we are allowing it to fire
several times. So when spin_until is executed m_system_event_loop_timer
is fired again. Not an ideal solution, but this is the best I could
come up with. This commit makes the behavior match EventLoopImplUnix,
in which single-shot timer can also fire several times.

Adding event_queue.process(); at the start of pump like in EvtLoopImplQt
doesn't fix the problem.

Note: Timer::start calls EventReceiver::start_timer, which calls
EventLoop::register_timer with should_reload always set to true
(single-shot vs periodic are handled in Timer::timer_event instead),
so I use static_cast<Timer&>(object).is_single_shot() instead of
!should_reload.
2025-04-10 19:02:03 -06:00
stasoid
2bfed2e417 LibCore: Check for all events in EventLoopImplementationWindows::pump
This fixes the problem when none of the timers or notifiers get
executed if wake() is called frequently.

Note that calling WaitForMultipleObjects repeatedly until it fails
will not work because rapidly firing timer can get all the attention.
That's why I check every event individually with WaitForSingleObject.

This behavior matches EventLoopImplementationUnix.
2025-04-10 19:02:03 -06:00
stasoid
5ea4d26458 LibCore: Don't wait in WaitForMultipleObjects if thread event queue
has pending events in EventLoopImplementationWindows

This matches the behavior of the Linux version:
911cd4aefd/Libraries/LibCore/EventLoopImplementationUnix.cpp (L371)
2025-04-10 19:02:03 -06:00
stasoid
33457f389d LibCore: Check for null ThreadData in unregister_notifier
and unregister_timer in EventLoopManagerWindows

Destructors for thread local objects are called before destructors of
global not thread local objects.

This is a partial stack of the problem, thread_data is already
destroyed at this point:

>WebContent.exe!Core::ThreadData::the
 WebContent.exe!Core::EventLoopManagerWindows::unregister_notifier
 WebContent.exe!Core::EventLoop::unregister_notifier
 WebContent.exe!Core::Notifier::set_enabled
 WebContent.exe!Core::LocalSocket::~LocalSocket
 WebContent.exe!Requests::RequestClient::~RequestClient
 WebContent.exe!Web::`dynamic atexit destructor for 's_resource_loader'
2025-04-10 19:02:03 -06:00
Timothy Flynn
f070264800 Everywhere: Remove sv suffix from format string literals
This prevents the compile-time checks that would catch errors in the
format invocation (which would usually lead to a runtime crash).
2025-04-08 20:00:18 -04:00
Timothy Flynn
64d290447c LibCore+LibJS+LibWasm: Always use a real format string
It's generally considered a security issue to use non-format string
literals. We would likely just crash in practice, but let's avoid the
issue altogether.
2025-04-08 20:00:18 -04:00
rmg-x
514233008b Meta+LibCore: Stop linking against LibCrypt
This was only be used by "Account.cpp" which was removed in:
d8c36ed458
2025-04-08 09:13:33 +02:00
rmg-x
37998895d8 AK+Meta+LibCore+Tests: Remove unused SipHash implementation
This is a homegrown implementation that wasn't actually used in
dependent classes. If this is needed in the future, using OpenSSL would
probably be a better option.
2025-04-06 01:47:50 +02:00
stasoid
2abc792938 LibCore: Implement System::set_close_on_exec 2025-03-19 20:25:24 -06:00
stasoid
2e200489c8 LibCore: Implement StandardPaths::user_data_directory on Windows 2025-03-19 20:25:24 -06:00
stasoid
10db20a537 LibCore: Implement System::current_executable_path on Windows 2025-03-19 20:25:24 -06:00
Andrew Kaster
89ecc75ed8 LibCore+Meta: Un-break Swift build on Linux
LibCore's list of ignored header files for Swift was missing the Apple
only files on non-Apple platforms. Additionally, any generic glue code
cannot use -fobjc-arc, so we need to rely on -fblocks only.
2025-03-18 17:15:08 -06:00
Andrew Kaster
c8787e6a9f LibCore: Add swift bindings for EventLoop as an Executor and Actor 2025-03-15 21:51:22 -06:00
Timothy Flynn
0f05aac290 LibCore: Mark the lambda in Promise::when_resolved as mutable
This allows the handler passed into this function to also be mutable.
2025-03-09 11:14:20 -04:00
Luke Wilde
08246bfa8c LibCore: Don't discard subsequent results in Socket::resolve_host
Previously, we only returned the first result that looked like an IPv6
or IPv4 address.

This cropped up when attempting to connect to https://cxbyte.me/ whilst
IPv6 on the server wasn't working. Since we only returned the first
result, which happened to be the IPv6 address, we wasn't able to
connect.

Returning all results allows curl to attempt to connect to a different
IP if one of them isn't working, and potentially make a successful
connection.
2025-02-28 15:14:35 +01:00
Timothy Flynn
fe2dff4944 AK+Everywhere: Convert JSON value serialization to String
This removes the use of StringBuilder::OutputType (which was ByteString,
and only used by the JSON classes). And it removes the StringBuilder
template parameter from the serialization methods; this was only ever
used with StringBuilder, so a template is pretty overkill here.
2025-02-20 19:27:51 -05:00
Timothy Flynn
2c03de60da AK+Everywhere: Remove now-unecessary use of ByteString with JSON types
This removes JsonObject::get_byte_string and JsonObject::to_byte_string.
2025-02-20 19:27:51 -05:00