From 8eda26c5cfdbc0101e0c54ac1678d49d49f11a92 Mon Sep 17 00:00:00 2001 From: Zaggy1024 Date: Thu, 15 Jan 2026 01:13:51 -0600 Subject: [PATCH] LibCore+Everywhere: Make Windows's System::ioctl consistent with POSIX Passing the option by value on Windows where it's a pointer on all other platforms seems like it may cause some unnecessary ifdef soup. --- Libraries/LibCore/LocalServerWindows.cpp | 2 +- Libraries/LibCore/SystemWindows.cpp | 5 +++-- Libraries/LibCore/TCPServerWindows.cpp | 5 +++-- Libraries/LibCore/UDPServerWindows.cpp | 2 +- Libraries/LibWebView/Process.cpp | 2 +- Services/RequestServer/RequestPipe.cpp | 4 ++-- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Libraries/LibCore/LocalServerWindows.cpp b/Libraries/LibCore/LocalServerWindows.cpp index b9cb4ecd0c..232aa03b5e 100644 --- a/Libraries/LibCore/LocalServerWindows.cpp +++ b/Libraries/LibCore/LocalServerWindows.cpp @@ -59,7 +59,7 @@ bool LocalServer::listen(ByteString const& address) m_fd = MUST(Core::System::socket(AF_LOCAL, SOCK_STREAM, 0)); int option = 1; - MUST(Core::System::ioctl(m_fd, FIONBIO, option)); + MUST(Core::System::ioctl(m_fd, FIONBIO, &option)); auto const ret = SetHandleInformation(to_handle(m_fd), HANDLE_FLAG_INHERIT, 0); VERIFY(ret != 0); diff --git a/Libraries/LibCore/SystemWindows.cpp b/Libraries/LibCore/SystemWindows.cpp index ca3372f3d0..0de7845038 100644 --- a/Libraries/LibCore/SystemWindows.cpp +++ b/Libraries/LibCore/SystemWindows.cpp @@ -6,6 +6,7 @@ * Copyright (c) 2023, Cameron Youell * Copyright (c) 2024-2025, stasoid * Copyright (c) 2025, ayeteadoe + * Copyright (c) 2026, Gregory Bertilson * * SPDX-License-Identifier: BSD-2-Clause */ @@ -99,9 +100,9 @@ ErrorOr ioctl(int fd, unsigned request, ...) { va_list ap; va_start(ap, request); - u_long arg = va_arg(ap, FlatPtr); + u_long* arg = va_arg(ap, u_long*); va_end(ap); - if (::ioctlsocket(fd, request, &arg) == SOCKET_ERROR) + if (::ioctlsocket(fd, request, arg) == SOCKET_ERROR) return Error::from_windows_error(); return {}; } diff --git a/Libraries/LibCore/TCPServerWindows.cpp b/Libraries/LibCore/TCPServerWindows.cpp index 3ef982e83a..5bb46528a7 100644 --- a/Libraries/LibCore/TCPServerWindows.cpp +++ b/Libraries/LibCore/TCPServerWindows.cpp @@ -23,7 +23,7 @@ ErrorOr> TCPServer::try_create() } }; int option = 1; - TRY(Core::System::ioctl(fd, FIONBIO, option)); + TRY(Core::System::ioctl(fd, FIONBIO, &option)); TRY(Core::System::setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &option, sizeof(option))); if (SetHandleInformation(to_handle(fd), HANDLE_FLAG_INHERIT, 0) == 0) return Error::from_windows_error(); @@ -72,7 +72,8 @@ ErrorOr TCPServer::set_blocking(bool const blocking) // NOTE: Blocking does not seem to be supported. Error code returned is WSAEINVAL if (!blocking) return Error::from_string_literal("Core::TCPServer: WinSock2 does not support blocking"); - TRY(Core::System::ioctl(m_fd, FIONBIO, 1)); + int option = 1; + TRY(Core::System::ioctl(m_fd, FIONBIO, &option)); return {}; } diff --git a/Libraries/LibCore/UDPServerWindows.cpp b/Libraries/LibCore/UDPServerWindows.cpp index 69cf2ac28c..6f2fcf6a58 100644 --- a/Libraries/LibCore/UDPServerWindows.cpp +++ b/Libraries/LibCore/UDPServerWindows.cpp @@ -19,7 +19,7 @@ UDPServer::UDPServer() { m_fd = MUST(Core::System::socket(AF_INET, SOCK_DGRAM, 0)); int option = 1; - MUST(Core::System::ioctl(m_fd, FIONBIO, option)); + MUST(Core::System::ioctl(m_fd, FIONBIO, &option)); auto const ret = SetHandleInformation(to_handle(m_fd), HANDLE_FLAG_INHERIT, 0); VERIFY(ret != 0); } diff --git a/Libraries/LibWebView/Process.cpp b/Libraries/LibWebView/Process.cpp index a812b9de7c..fdd361b367 100644 --- a/Libraries/LibWebView/Process.cpp +++ b/Libraries/LibWebView/Process.cpp @@ -156,7 +156,7 @@ ErrorOr Process::create_ipc_socket(ByteString const& socket_path) #if defined(AK_OS_WINDOWS) auto socket_fd = TRY(Core::System::socket(AF_LOCAL, SOCK_STREAM, 0)); int option = 1; - TRY(Core::System::ioctl(socket_fd, FIONBIO, option)); + TRY(Core::System::ioctl(socket_fd, FIONBIO, &option)); if (SetHandleInformation(to_handle(socket_fd), HANDLE_FLAG_INHERIT, 0) == 0) return Error::from_windows_error(); #else diff --git a/Services/RequestServer/RequestPipe.cpp b/Services/RequestServer/RequestPipe.cpp index 07223fd5cb..9e44bdad00 100644 --- a/Services/RequestServer/RequestPipe.cpp +++ b/Services/RequestServer/RequestPipe.cpp @@ -47,8 +47,8 @@ ErrorOr RequestPipe::create() int socket_fds[2] {}; TRY(Core::System::socketpair(AF_LOCAL, SOCK_STREAM, 0, socket_fds)); int option = 1; - TRY(Core::System::ioctl(socket_fds[0], FIONBIO, option)); - TRY(Core::System::ioctl(socket_fds[1], FIONBIO, option)); + TRY(Core::System::ioctl(socket_fds[0], FIONBIO, &option)); + TRY(Core::System::ioctl(socket_fds[1], FIONBIO, &option)); return RequestPipe(socket_fds[0], socket_fds[1]); #else auto fds = TRY(Core::System::pipe2(O_NONBLOCK));