1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00
Commit graph

491 commits

Author SHA1 Message Date
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
Timothy Flynn
bc54c0cdfb AK+Everywhere: Store JSON strings as String 2025-02-20 19:27:51 -05:00
Timothy Flynn
e591636419 AK+Everywhere: Store JSON object keys as String 2025-02-20 19:27:51 -05:00
Timothy Flynn
70eb0ba1cd AK+Everywhere: Remove the char const* JSON value constructor 2025-02-20 19:27:51 -05:00
Shannon Booth
d62cf0a807 Everywhere: Remove some use of the URL constructors
These make it too easy to construct an invalid URL, which makes it
difficult to remove the valid state of URL - which this API relies
on.
2025-02-19 08:01:35 -05:00
devgianlu
d6e9d2cdbb LibCore: Expose TCPSocket file descriptor 2025-02-17 19:52:43 +01:00
stasoid
4ae3522b10 LibCore: Implement System::socketpair on Windows 2025-02-14 09:38:59 -07:00
Timothy Flynn
9a4bb958ac LibCore: Remove ErrorOr return type from read_long_version_string
Nothing in this function is fallible.
2025-02-13 08:27:02 -05:00
stasoid
fe43712e72 LibCore: Add S_ISDIR, S_ISREG to System.h on Windows
Before this commit, LibCore/System.h exposed only part of
System::stat API on Windows. Namely, users of Core::System::stat
had to #include <dirent.h> in order to check the return value of stat.
It is OK for low-level libs like LibCore/LibFileSystem, but
S_ISDIR is also used in LibWeb\Loader\GeneratedPagesLoader.cpp.
We want to avoid platform #ifdefs in LibWeb.
2025-02-12 18:42:05 -07:00
stasoid
6b86d8a44d LibCore: Implement System::physical_memory_bytes on Windows 2025-02-12 18:42:05 -07:00
stasoid
f143a9b971 LibCore: Implement System::hardware_concurrency on Windows 2025-02-11 04:07:24 -07:00
Andrew Kaster
0dd23e43e3 LibCore: Add helper to convert Bytes/ReadonlyBytes to WSABUF 2025-02-11 01:41:46 -07:00
Andrew Kaster
25f00b2486 LibCore: Add missing HashMap include to Windows EventLoop 2025-02-11 01:41:46 -07:00
Andrew Kaster
6ebba0d847 LibCore: Skip Command, UDPServer and TCPServer on Windows 2025-02-11 01:41:46 -07:00
stasoid
26825b5865 LibCore: Properly shutdown a socket on Windows
It fixes a bug in which ImageDecoder and RequestServer
do not exit because their connections don't close.

This makes the shutdown behavior match the Linux version,
which receives FD_READ | FD_HANGUP on socket close, and
TransportSocket::read_as_much_as_possible_without_blocking calls
schedule_shutdown when read from a socket returns 0 bytes.

On Windows, we have to explicitly call WIN32 shutdown to receive
notification FD_CLOSE.
2025-02-10 12:46:25 -07:00
stasoid
e1f70d532c LibCore: Implement LocalSocket on Windows
Windows flavor of non-blocking IO, overlapped IO, differs from that on
Linux. On Windows, the OS handles writing to overlapped buffer, while
on Linux user must do it manually.

Additionally, we can only have overlapped sockets because it is the
requirement to be able to wait on them - WSAEventSelect automatically
sets socket to nonblocking mode.

So we end up emulating Linux-nonblocking sockets with
Windows-nonblocking sockets.

Pending IO state (ERROR_IO_PENDING) must not escape read/write
functions. If that happens, all synchronization like WSAPoll and
WaitForMultipleObjects stops working (WaitForMultipleObjects stops
working because with overlapped IO you are supposed to wait on an event
in OVERLAPPED structure, while we are waiting on WSA Event, see
EventLoopImplementationWindows.cpp).
2025-02-10 12:46:25 -07:00
stasoid
f696f20cd8 LibCore: Port SystemServerTakeover.cpp to Windows 2025-02-06 15:25:14 -07:00
stasoid
a291a7f770 LibCore: Add System::sleep_ms 2025-02-06 15:16:50 -07:00
stasoid
e6e233fd64 LibCore: Correctly pass arguments with spaces to Process on Windows 2025-02-06 15:15:16 -07:00
stasoid
1173b14c43 LibCore: Pass correct number of arguments to the Process on Windows
Incorrect behavior of CreateProcess:
CreateProcess("a.exe", "b c", ...) ->
    a.exe::main::argv == ["b", "c"] (wrong)
CreateProcess(0, "a.exe b c", ...) ->
    a.exe::main::argv == ["a.exe", "b", "c"] (right)

https://learn.microsoft.com/en-us/cpp/cpp/main-function-command-line-args
"If you use both the first and second arguments (lpApplicationName and
lpCommandLine), argv[0] may not be the executable name."

This means first argument of CreateProcess should never be used.
-----------------------------------------------------------------------

Searching for executable in path is suppressed now by prepending "./"

Additional bonus of the new code: .exe extension does not need to be
specified.
2025-02-06 15:15:16 -07:00