Commit graph

456 commits

Author SHA1 Message Date
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
stasoid
b77016cc34 LibCore: Consistently treat file descriptors as handles on Windows
Also:
 * implement dup and is_socket
 * implement and call init_crt_and_wsa
2025-02-05 19:27:47 -07:00
stasoid
259cd70c1b LibCore: Simplify System::open
_O_OBTAIN_DIR flag makes _open use FILE_FLAG_BACKUP_SEMANTICS in
CreateFile call.

FILE_FLAG_BACKUP_SEMANTICS is required to open directory handles.

For ordinary files FILE_FLAG_BACKUP_SEMANTICS overrides file security
checks when the process has SE_BACKUP_NAME and SE_RESTORE_NAME
privileges, see https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
2025-02-05 19:27:47 -07:00
stasoid
870cce9d11 AK: Add Error::from_windows_error(void)
Also slightly improve Error::from_windows_error(int)
2025-02-05 19:27:47 -07:00
stasoid
e0576f4790 LibCore: Add definitions for socketpair in SocketAddressWindows.h 2025-02-05 16:07:39 -07:00
stasoid
a274a50bb3 LibCore: Add declarations for getaddrinfo in SocketAddressWindows.h 2025-02-05 16:07:39 -07:00
stasoid
170f056805 LibCore: Allow winsock2.h to be included after SocketAddressWindows.h 2025-02-05 16:07:39 -07:00
stasoid
eb650798d0 LibCore: Fix SocketAddress.h compilation errors on Windows 2025-02-05 16:07:39 -07:00
Tim Ledbetter
c67035b9c1 LibCore/ArgsParser: Treat multi-use arguments as required 2025-02-05 06:58:52 -05:00
Lucas CHOLLET
e015a43b51 LibCore: Remove unused methods from EventLoop 2025-01-30 15:34:02 -07:00
stasoid
c580763743 LibCore: Don't search fonts in system_data_directories() on Windows
Fonts on Windows are stored only in %WINDIR%\Fonts and
%LOCALAPPDATA%\Microsoft\Windows\Fonts, see https://stackoverflow.com/a/67078786

And system_data_directories() is not implemented on Windows yet.
2025-01-27 09:25:17 +00:00
Timothy Flynn
85b424464a AK+Everywhere: Rename verify_cast to as
Follow-up to fc20e61e72.
2025-01-21 11:34:06 -05:00
Arhcout
aa82ff8044 LibWeb: Add documentation to the date parser format
So we don't have to dig in the parser's code
2025-01-03 11:26:01 +00:00
stasoid
49bdda1475 AK: Simplify usage of windows.h and winsock2.h
Use <AK/Windows.h> instead of windows.h/winsock2.h
to avoid timeval-related errors.

Note: winsock2.h includes windows.h
2025-01-02 10:17:51 -07:00
Timothy Flynn
27478ec7d4 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-19 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")
2024-12-28 05:39:32 -08:00
Andreas Kling
4eda7b5646 LibCore: Make EventReceiver ref counting use atomics
This removes a race in ImageDecoder's make_decode_image_job(), where the
ref count of `this` is mutated from separate threads in the callbacks.
2024-12-26 13:45:10 +01:00
Tim Ledbetter
a450d64ffa LibCore: Return correct error code from Process::wait_for_termination 2024-12-20 14:59:56 +01:00
R-Goc
579484e065 LibCore: Fix compilation of EventLoopImplementationWindows.cpp 2024-12-20 13:57:43 +01:00
stasoid
15a96e841b Meta: Make pthread and mman available for all libraries on Windows
by default
2024-12-18 05:55:58 +01:00
stasoid
212cea4535 LibCore: Add System::getpid 2024-12-17 11:07:53 +01:00
Pavel Shliak
6f81b80114 Everywhere: Include HashMap only where it's actually used 2024-12-09 12:31:16 +01:00
R-Goc
c66eb5db11 LibCore: Add includes for S_ISDIR on Windows 2024-12-08 17:29:22 -07:00
stasoid
777dcdf6d0 LibCore: Port SharedCircularQueue to Windows 2024-12-08 17:25:40 -07:00
Pavel Shliak
6ec06a01a2 LibCore: Do not include math.h in ArgsParser 2024-12-08 16:38:13 +00:00
R-Goc
bebf787c36 LibCore: Add ProcessWindows.cpp to CMakeLists 2024-12-06 13:11:44 +00:00
rmg-x
aa4dcca0b2 LibCore/Process: Add DupFd file action
This commit provides a new file action allowing callers to provide a
`write_fd` that Process will "redirect" the child's stdin/stdout to.
2024-12-05 17:02:57 -07:00
stasoid
163ec18593 LibCore: Fix link error in EventLoopImplementationWindows.cpp 2024-12-02 10:12:57 +01:00
Sam Atkins
90e763de4c LibURL: Replace Host's Empty state with making Url's Host optional
A couple of reasons:
- Origin's Host (when in the tuple state) can't be null
- There's an "empty host" concept in the spec which is NOT the same as a
  null Host, and that was confusing me.
2024-11-30 12:07:39 +01:00
stasoid
67db10f26e LibCore/System: Do not translate \n <-> \r\n when reading/writing files
on Windows
2024-11-29 10:50:59 +01:00
stasoid
d224d1f22c LibCore: Fix pthread-related errors on Windows
Fixes compilation error in Notifier.h and
link errors in ThreadEventQueue.cpp
2024-11-29 10:50:00 +01:00
Andrew Kaster
0075048206 LibCore: Remove SessionManagement utilities
We don't need these, they are only relevant for SerenityOS system
builds of LibCore.
2024-11-26 11:00:48 +01:00
stasoid
b3464d0645 LibCore: Port MappedFile to Windows 2024-11-26 10:00:11 +01:00
stasoid
153dc6686c LibCore/MappedFile: Remove unnecessary fcntl call 2024-11-26 10:00:11 +01:00
stasoid
3f7affa825 LibCore/System: Add mmap, munmap for Windows 2024-11-26 10:00:11 +01:00
Pavel Shliak
442629064b LibCore: Remove deprecated ElapsedTimer::elapsed()
This follows FIXME in the code.
2024-11-23 19:20:03 +01:00
Ali Mohammad Pur
d704b61066 LibCore+LibTLS: Add an API for connect()'ing 'with hostname
This just unifies the API for all three sockets (UDP, TCP and TLS)
2024-11-20 21:37:58 +01:00